Writer to translate cnf formulas into DIMACS files.
The basic idea here is that
Function:
(defun dimacs-write-lit$inline (lit acc) (declare (xargs :guard (and (litp lit) (character-listp acc)))) (let ((__function__ 'dimacs-write-lit)) (declare (ignorable __function__)) (b* ((negatedp (int= (lit->neg lit) 1)) (id+1 (+ 1 (lit->var lit))) (acc (if negatedp (cons #\- acc) acc))) (str::revappend-nat-to-dec-chars id+1 acc))))
Theorem:
(defthm character-listp-of-dimacs-write-lit (implies (and (litp lit) (character-listp acc)) (b* ((acc (dimacs-write-lit$inline lit acc))) (character-listp acc))) :rule-classes :rewrite)
Function:
(defun dimacs-write-clause (clause acc) (declare (xargs :guard (and (lit-listp clause) (character-listp acc)))) (let ((__function__ 'dimacs-write-clause)) (declare (ignorable __function__)) (b* (((when (atom clause)) (cons #\Newline (cons #\0 acc))) (acc (dimacs-write-lit (car clause) acc)) (acc (cons #\Space acc))) (dimacs-write-clause (cdr clause) acc))))
Theorem:
(defthm character-listp-of-dimacs-write-clause (implies (and (lit-listp clause) (character-listp acc)) (b* ((acc (dimacs-write-clause clause acc))) (character-listp acc))) :rule-classes :rewrite)
Function:
(defun dimacs-write-clauses (clauses acc) (declare (xargs :guard (and (lit-list-listp clauses) (character-listp acc)))) (let ((__function__ 'dimacs-write-clauses)) (declare (ignorable __function__)) (b* (((when (atom clauses)) acc) (acc (dimacs-write-clause (car clauses) acc))) (dimacs-write-clauses (cdr clauses) acc))))
Theorem:
(defthm character-listp-of-dimacs-write-clauses (implies (and (lit-list-listp clauses) (character-listp acc)) (b* ((acc (dimacs-write-clauses clauses acc))) (character-listp acc))) :rule-classes :rewrite)
Function:
(defun dimacs-write-formula (formula) (declare (xargs :guard (lit-list-listp formula))) (let ((__function__ 'dimacs-write-formula)) (declare (ignorable __function__)) (b* ((max-index (max-index-formula formula)) (dimacs-num-vars (+ 1 max-index)) (acc nil) (acc (str::revappend-chars "p cnf " acc)) (acc (str::revappend-nat-to-dec-chars dimacs-num-vars acc)) (acc (cons #\Space acc)) (acc (str::revappend-nat-to-dec-chars (len formula) acc)) (acc (cons #\Newline acc)) (acc (dimacs-write-clauses formula acc))) (mv (str::rchars-to-string acc) max-index))))
Theorem:
(defthm stringp-of-dimacs-write-formula.dimacs-text (implies (and (lit-list-listp formula)) (b* (((mv ?dimacs-text ?max-index) (dimacs-write-formula formula))) (stringp dimacs-text))) :rule-classes :rewrite)
Theorem:
(defthm return-type-of-dimacs-write-formula.max-index (b* (((mv ?dimacs-text ?max-index) (dimacs-write-formula formula))) (equal max-index (max-index-formula formula))) :rule-classes :rewrite)
Function:
(defun dimacs-export-fn (formula filename state) (declare (xargs :stobjs (state))) (declare (xargs :guard (and (lit-list-listp formula) (stringp filename)))) (let ((__function__ 'dimacs-export)) (declare (ignorable __function__)) (b* ((filename (mbe :logic (if (stringp filename) filename "") :exec filename)) ((mv channel state) (open-output-channel filename :character state)) ((unless channel) (mv nil (max-index-formula formula) state)) ((mv str max-index) (dimacs-write-formula formula)) (state (princ$ str channel state)) (state (close-output-channel channel state))) (mv t max-index state))))
Theorem:
(defthm booleanp-of-dimacs-export.successp (b* (((mv ?successp ?max-index acl2::?state) (dimacs-export-fn formula filename state))) (booleanp successp)) :rule-classes :type-prescription)
Theorem:
(defthm return-type-of-dimacs-export.max-index (b* (((mv ?successp ?max-index acl2::?state) (dimacs-export-fn formula filename state))) (equal max-index (max-index-formula formula))) :rule-classes :rewrite)
Theorem:
(defthm state-p1-of-dimacs-export.state (implies (force (state-p1 state)) (b* (((mv ?successp ?max-index acl2::?state) (dimacs-export-fn formula filename state))) (state-p1 state))) :rule-classes :rewrite)