File: soundness.lisp

package info (click to toggle)
acl2 8.6%2Bdfsg-2
  • links: PTS
  • area: main
  • in suites: trixie
  • size: 1,111,420 kB
  • sloc: lisp: 17,818,294; java: 125,359; python: 28,122; javascript: 23,458; cpp: 18,851; ansic: 11,569; perl: 7,678; xml: 5,591; sh: 3,976; makefile: 3,833; ruby: 2,633; yacc: 1,126; ml: 763; awk: 295; csh: 233; lex: 197; php: 178; tcl: 49; asm: 23; haskell: 17
file content (225 lines) | stat: -rw-r--r-- 8,974 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
; Copyright (C) 2016, Regents of the University of Texas
; Marijn Heule, Warren A. Hunt, Jr., and Matt Kaufmann
; License: A 3-clause BSD license.  See the LICENSE file distributed with ACL2.

; See ../README.

(in-package "LRAT")

(include-book "lrat-checker")
(include-book "satisfiable-maybe-shrink-formula")

(defun extend-with-proof (ncls ndel formula proof)

; This function is essentially verify-proof, except that instead of returning a
; Boolean, it returns the extended formula.  And there is one other difference:
; We stop if/when we hit the empty clause in proof, since we want to prove that
; the empty clause gives us an unsat formula, but later steps might delete the
; empty clause!

  (cond
   ((atom proof) formula)
   (t
    (let* ((entry (car proof))
           (delete-flg (proof-entry-deletion-p entry)))
      (cond
       (delete-flg
        (let* ((indices (proof-entry-deletion-indices entry))
               (new-formula (delete-clauses indices formula))
               (len (length indices))
               (ncls

; We expect that (<= len ncls).  It is tempting to assert that here (with
; assert$), but it's not necessary so we avoid the overhead (mostly in proof,
; but perhaps also a bit in execution).

                (- ncls len))
               (ndel (+ ndel len)))
          (extend-with-proof ncls ndel new-formula (cdr proof))))
       (t ; addition
        (let ((clause (access add-step entry :clause)))
          (mv-let (ncls ndel formula)
            (verify-clause formula entry ncls ndel)
            (let* ((index (access add-step entry :index))
                   (new-formula (add-proof-clause index clause formula)))
              (if (null clause)
                  new-formula ; see comment above
                (extend-with-proof
                 (1+ ncls)
                 ndel
                 new-formula
                 (cdr proof))))))))))))

(defthm formula-p-delete-clauses
  (implies (and (formula-p fal)
                (index-listp index-list))
           (formula-p (delete-clauses index-list fal))))

(defthm formula-p-add-proof-clause
  (implies (and (posp index)
                (clause-or-assignment-p clause)
                (formula-p formula))
           (formula-p (add-proof-clause index clause formula))))

(encapsulate
  ()

  (local
   (defthm hons-assoc-equal-delete-clauses-member-equal-case
     (implies (equal (hons-assoc-equal index fal)
                     (cons index *deleted-clause*))
              (equal (hons-assoc-equal index (delete-clauses index-list fal))
                     (cons index *deleted-clause*)))))

  (local
   (defthm hons-assoc-equal-delete-clauses
     (equal (hons-assoc-equal index (delete-clauses index-list fal))
            (if (member-equal index index-list)
                (cons index *deleted-clause*)
              (hons-assoc-equal index fal)))))

  (local
   (defthm delete-clauses-preserves-formula-truep
     (implies (and (formula-p formula)
                   (clause-or-assignment-p assignment)
                   (formula-truep formula assignment))
              (formula-truep (delete-clauses index-list formula)
                             assignment))
     :hints (("Goal"
              :in-theory (disable formula-truep)
              :expand ((formula-truep (delete-clauses index-list formula)
                                      assignment))
              :restrict ((formula-truep-necc
                          ((index (formula-truep-witness
                                   (delete-clauses index-list formula)
                                   assignment)))))))))

  (defthm delete-clauses-preserves-satisfiable
    (implies (and (formula-p formula)
                  (satisfiable formula))
             (satisfiable (delete-clauses index-list formula)))
    :hints (("Goal"
             :in-theory (disable satisfiable formula-truep)
             :expand ((satisfiable formula))
             :restrict ((satisfiable-suff
                         ((assignment (satisfiable-witness formula)))))))))

(encapsulate
  ()
  (local (include-book "satisfiable-add-proof-clause"))

  (defthm satisfiable-add-proof-clause
    (mv-let (ncls ndel new-formula)
      (verify-clause formula entry ncls ndel)
      (declare (ignore ndel))
      (implies (and ncls
                    (proof-entry-p entry)
                    (not (proof-entry-deletion-p entry))
                    (formula-p formula)
                    (satisfiable formula))
               (satisfiable (add-proof-clause
                             (access add-step entry :index)
                             (access add-step entry :clause)
                             new-formula))))))

(in-theory (disable add-proof-clause verify-clause))

(defthm formula-truep-cons-shrink-formula
  (implies (and (formula-p formula)
                (clause-or-assignment-p assignment)
                (formula-truep (cons pair (shrink-formula formula))
                               assignment))
           (formula-truep (cons pair formula)
                          assignment))
  :hints (("Goal"
           :expand ((formula-truep (cons pair formula)
                                   assignment))
           :restrict ((formula-truep-necc
                       ((index (formula-truep-witness (cons pair formula)
                                                      assignment))))))))

(defthm satisfiable-cons-shrink-formula
  (implies (formula-p formula)
           (implies (satisfiable (cons pair (shrink-formula formula)))
                    (satisfiable (cons pair formula))))
  :hints (("Goal"
           :expand ((satisfiable (cons pair (shrink-formula formula))))
           :restrict
           ((satisfiable-suff
             ((assignment
               (satisfiable-witness (cons pair
                                          (shrink-formula formula))))))))))

(encapsulate
  ()

  (local
   (defthm not-satisfiable-add-proof-clause-nil
     (implies (and (formula-p formula)
                   (posp index))
              (not (satisfiable (add-proof-clause index nil formula))))
     :hints (("Goal"
              :in-theory (enable add-proof-clause satisfiable)
              :restrict ((formula-truep-necc ((index index))))))
     :rule-classes nil))

  (defthm verify-clause-implies-unsatisfiable
    (implies (and (formula-p formula)
                  (proof-entry-p entry)
                  (equal (access add-step entry :clause) nil)
                  (satisfiable formula))
             (not (car (verify-clause formula entry ncls ndel))))
    :hints (("Goal"
             :in-theory (enable verify-clause add-proof-clause
                                maybe-shrink-formula)
             :use ((:instance not-satisfiable-add-proof-clause-nil
                              (index (access add-step entry :index)))
                   (:instance satisfiable-add-proof-clause
                              (entry (change add-step entry
                                             :clause nil))))))))

(defthm formula-p-mv-nth-2-verify-clause
  (implies (formula-p formula)
           (formula-p (mv-nth 2
                              (verify-clause formula entry ncls ndel))))
  :hints (("Goal" :in-theory (enable verify-clause maybe-shrink-formula))))

(defthm extend-with-proof-preserves-satisfiable
  (implies (and (formula-p formula)
                (proofp proof)
                (verify-proof-rec ncls ndel formula proof)
                (satisfiable formula))
           (satisfiable (extend-with-proof ncls ndel formula proof)))
  :rule-classes nil)

(defthm not-formula-truep-add-nil-clause
  (not (formula-truep (cons (list (car (car (car proof))))
                            fal)
                      assignment))
  :hints (("Goal" :restrict ((formula-truep-necc
                              ((index (car (car (car proof))))))))))

(defthm proof-contradiction-p-implies-false
  (implies (and (formula-p formula)
                (proofp proof)
                (proof-contradiction-p proof))
           (equal (formula-truep (extend-with-proof ncls ndel formula proof)
                                 assignment)
                  nil))
  :hints (("Goal" :in-theory (enable verify-clause add-proof-clause
                                     maybe-shrink-formula))))

(defthm proof-contradiction-p-implies-not-satisfiable
  (implies (and (formula-p formula)
                (proofp proof)
                (proof-contradiction-p proof))
           (not (satisfiable (extend-with-proof ncls ndel formula proof))))
  :hints (("Goal" :in-theory (e/d (satisfiable) (extend-with-proof)))))

(defthm main-theorem-list-based
  (implies (and (formula-p formula)
                (refutation-p proof formula))
           (not (satisfiable formula)))
  :hints (("Goal" :use ((:instance extend-with-proof-preserves-satisfiable
                                   (ncls (len (fast-alist-fork formula nil)))
                                   (ndel 0))))))