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 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325
|
; Copyright (C) 2017, 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")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Preliminaries
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(include-book "transform")
(include-book "verify-for-cube-soundness")
(include-book "../incremental/print-formula")
(include-book "../incremental/soundness")
(program)
(set-state-ok t)
(defun my-getenv (string state)
(mv-let (erp s state)
(getenv$ string state)
(mv (and (not erp)
(let ((s1 (string-upcase s)))
(cond ((equal s1 "T")
t)
((equal s1 "NIL")
nil)
(t s))))
state)))
(defun get-defaults (chunk-size debug timep exitp state)
(mv-let (chunk-size state)
(cond
((eq chunk-size :none)
(mv-let (s state)
(my-getenv "LRAT_CHUNK_SIZE" state)
(mv (if (stringp s)
(acl2::decimal-string-to-number s (length s) 0)
1000000)
state)))
(t (mv chunk-size state)))
(mv-let (debug state)
(cond ((eq debug :none)
(my-getenv "LRAT_DEBUG" state))
(t (mv debug state)))
(mv-let (timep state)
(cond ((eq timep :none)
(my-getenv "LRAT_TIMEP" state))
(t (mv timep state)))
(mv-let (exitp state)
(cond ((eq exitp :none)
(my-getenv "LRAT_EXITP" state))
(t (mv exitp state)))
(mv chunk-size debug timep exitp state))))))
(defun maybe-print-success-and-exit (exitp state)
(cond ((null exitp) (value nil))
(t (pprogn (princ$ "s VERIFIED" (standard-co state) state)
(newline (standard-co state) state)
(prog2$ (exit 0)
(value nil))))))
(defun maybe-print-failure-and-exit (exitp state)
(cond ((null exitp) (value nil))
(t (pprogn (princ$ "FAILED" (standard-co state) state)
(prog2$ (exit 1)
(value nil))))))
(defmacro maybe-time$ (timep form)
`(cond (,timep (time$ ,form))
(t ,form)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Transform
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; See (1) in README.
(defun transform-check-fn (cnf-file clrat-file chunk-size
debug
old-formula-outfile
new-formula-outfile
timep
exitp
ctx
state)
(declare (xargs :stobjs state :mode :program))
(mv-let (chunk-size debug timep exitp state)
(get-defaults chunk-size debug timep exitp state)
(mv-let (erp result state)
(maybe-time$ timep (transform cnf-file clrat-file chunk-size debug state))
(cond
((and (null erp)
result)
(let ((old-formula (car result))
(new-formula (cdr result)))
(er-progn
(cond ((null old-formula-outfile) (value nil))
(t (pprogn (cond ((eq old-formula-outfile t)
(fms "~s0 Input formula ~s0~|"
(list (cons #\0 "==============="))
(standard-co state) state nil))
(t state))
(print-formula (reverse old-formula)
:filename old-formula-outfile))))
(cond ((null new-formula-outfile) (value nil))
(t (pprogn (cond ((eq new-formula-outfile t)
(fms "~s0 Output formula ~s0~|"
(list (cons #\0 "==============="))
(standard-co state) state nil))
(t state))
(print-formula new-formula
:filename new-formula-outfile))))
(maybe-print-success-and-exit exitp state)
(value `(:SUCCESS
,@(and (stringp old-formula-outfile)
(list :input-formula-printed-to
old-formula-outfile))
,@(and (stringp new-formula-outfile)
(list :output-formula-printed-to
new-formula-outfile)))))))
(t (er-progn (maybe-print-failure-and-exit exitp state)
(er soft ctx "Transform FAILED.")))))))
(defmacro transform-check (cnf-file clrat-file
&key
old-formula-outfile
new-formula-outfile
(chunk-size ':none)
(debug ':none)
(timep ':none)
(exitp ':none))
`(transform-check-fn ,cnf-file ,clrat-file
,chunk-size ,debug
,old-formula-outfile ,new-formula-outfile ,timep ,exitp
'transform-check state))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Verify-for-cube
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; See (2) in README.
(defun verify-for-cube-check-fn (cnf-file clrat-file cube-file chunk-size debug
old-formula-outfile new-clause-outfile
timep exitp ctx state)
(declare (xargs :stobjs state :mode :program))
(mv-let (chunk-size debug timep exitp state)
(get-defaults chunk-size debug timep exitp state)
(mv-let (erp formula/clause state)
(maybe-time$ timep
(verify-for-cube cnf-file clrat-file cube-file chunk-size
debug ctx state))
(assert$
(null erp)
(cond
(formula/clause
(let ((formula (reverse (car formula/clause)))
(clause (cdr formula/clause)))
(er-progn
(cond ((null old-formula-outfile) (value nil))
(t (pprogn (cond ((eq old-formula-outfile t)
(fms "~s0 Formula ~s0~|"
(list (cons #\0 "==============="))
(standard-co state) state nil))
(t state))
(print-formula formula
:filename old-formula-outfile))))
(cond ((null new-clause-outfile) (value nil))
(t (pprogn (cond ((eq new-clause-outfile t)
(fms "~s0 Clause ~s0~|"
(list (cons #\0 "==============="))
(standard-co state) state nil))
(t state))
(print-formula ; turn clause into a formula
(list (cons 1 clause))
:filename new-clause-outfile
:header-p nil))))
(maybe-print-success-and-exit exitp state)
(value `(:SUCCESS
,@(and (stringp old-formula-outfile)
(list :formula-printed-to old-formula-outfile))
,@(and (stringp new-clause-outfile)
(list :clause-printed-to new-clause-outfile)))))))
(t (er-progn (maybe-print-failure-and-exit exitp state)
(er soft ctx "Verify-for-cube FAILED."))))))))
(defmacro verify-for-cube-check (cnf-file clrat-file cube-file
&key
old-formula-outfile
new-clause-outfile
(chunk-size ':none)
(debug ':none)
(timep ':none)
(exitp ':none))
`(verify-for-cube-check-fn ,cnf-file ,clrat-file ,cube-file
,chunk-size ,debug
,old-formula-outfile ,new-clause-outfile ,timep
,exitp 'verify-for-cube-check state))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Cubes-unsat-check
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; See (3) in README.
(defun cubes-unsat-check-fn (cnf-file clrat-file chunk-size debug outfile
timep exitp ctx state)
(mv-let (chunk-size debug timep exitp state)
(get-defaults chunk-size debug timep exitp state)
(mv-let (erp formula state)
(maybe-time$ timep
(proved-formula cnf-file clrat-file
chunk-size
debug
nil ; incomplete-okp
'cubes-unsat-check state))
(cond ((and (null erp) ; always true
formula)
(pprogn (cond ((eq outfile t)
(fms "~s0 Input formula ~s0~|"
(list (cons #\0 "==============="))
(standard-co state) state nil))
(t state))
(er-progn
(cond (outfile (print-formula formula
:filename outfile))
(t (value nil)))
(maybe-print-success-and-exit exitp state)
(value `(:SUCCESS
,@(and (stringp outfile)
(list :input-formula-printed-to
outfile)))))))
(t
(er-progn (maybe-print-failure-and-exit exitp state)
(er soft ctx "Cubes-unsat-check FAILED.")))))))
(defmacro cubes-unsat-check (cnf-file clrat-file
&key
outfile
(chunk-size ':none)
(debug ':none)
(timep ':none)
(exitp ':none))
`(cubes-unsat-check-fn ,cnf-file ,clrat-file ,chunk-size ,debug ,outfile
,timep ,exitp 'cubes-unsat-check state))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Single interface
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defmacro cube-check (cnf-infile clrat-infile cnf-outfile
&optional cube-infile produced-outfile)
(cond (cube-infile ; (2)
`(verify-for-cube-check ,cnf-infile ,clrat-infile ,cube-infile
:old-formula-outfile ,cnf-outfile
:new-clause-outfile ,produced-outfile))
(produced-outfile ; (1)
`(transform-check ,cnf-infile ,clrat-infile
:old-formula-outfile ,cnf-outfile
:new-formula-outfile ,produced-outfile))
(t ; (3)
`(cubes-unsat-check ,cnf-infile ,clrat-infile
:outfile ,cnf-outfile))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Examples
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Some environment variable settings to try:
; (setenv$ "LRAT_TIMEP" "t")
; (setenv$ "LRAT_TIMEP" "nil")
; (setenv$ "LRAT_CHUNK_SIZE" "200")
#||
(transform-check "../tests/uuf-100-5.cnf" "../tests/uuf-100-5-partial.clrat"
:old-formula-outfile "my-old"
:new-formula-outfile "my-new")
% diff ../tests/uuf-100-5.cnf my-old
; equivalently
(cube-check "../tests/uuf-100-5.cnf" "../tests/uuf-100-5-partial.clrat"
"my-old2" nil "my-new2")
; equivalently
./run.sh ../tests/uuf-100-5.cnf ../tests/uuf-100-5-partial.clrat my-old2 nil my-new2
% diff my-old my-old2
% diff my-new my-new2
(let ((cnf-file "../tests/uuf-30-1.cnf")
(clrat-file "../tests/uuf-30-1-cube.clrat")
(cube-file "../tests/uuf-30-1.cube"))
(verify-for-cube-check cnf-file clrat-file cube-file
:old-formula-outfile "my-old"
:new-clause-outfile "my-new"))
% diff ../tests/uuf-30-1.cnf my-old
% # should be just -25 0:
% cat my-new
; equivalently
(cube-check "../tests/uuf-30-1.cnf" "../tests/uuf-30-1-cube.clrat"
"my-old2" "../tests/uuf-30-1.cube" "my-new2")
% diff my-old my-old2
% diff my-new my-new2
; equivalently
./run.sh ../tests/uuf-30-1.cnf ../tests/uuf-30-1-cube.clrat my-old2 \
../tests/uuf-30-1.cube my-new2
(let ((cnf-file "../tests/uuf-30-1.cnf")
(clrat-file "../tests/uuf-30-1.clrat"))
(cubes-unsat-check cnf-file clrat-file
:outfile t))
; equivalently:
(cube-check "../tests/uuf-30-1.cnf" "../tests/uuf-30-1.clrat" t)
; File version:
(let ((cnf-file "../tests/uuf-30-1.cnf")
(clrat-file "../tests/uuf-30-1.clrat"))
(cubes-unsat-check cnf-file clrat-file
:outfile "my-old"))
; equivalently:
./run.sh ../tests/uuf-30-1.cnf ../tests/uuf-30-1.clrat my-old2
% diff my-old my-old2
||#
|