Convert an ACL2-like S-expression into an AIG.
(expr-to-aig expr) accepts S-expressions
a (not a) (and a b c)
It currently accepts S-expressions composed of the following operators, all of which are assumed to be Boolean-valued (i.e., there's nothing four-valued going on here):
It constructs an AIG from the S-expression using the ordinary aig-constructors.
This can be useful for one-off debugging. We probably wouldn't recommend using it for anything serious, or trying to prove anything about it.
Function:
(defun expr-to-aig (expr) (declare (xargs :guard t)) (if (atom expr) expr (let ((fn (car expr)) (args (cdr expr))) (cond ((and (eq fn 'not) (= (len args) 1)) (aig-not (expr-to-aig (car args)))) ((eq fn 'and) (expr-to-aig-args 'and t args)) ((eq fn 'or) (expr-to-aig-args 'or nil args)) ((eq fn 'nand) (aig-not (expr-to-aig-args 'and t args))) ((eq fn 'nor) (aig-not (expr-to-aig-args 'or nil args))) ((and (eq fn 'iff) (= (len args) 2)) (aig-iff (expr-to-aig (car args)) (expr-to-aig (cadr args)))) ((and (eq fn 'xor) (= (len args) 2)) (aig-xor (expr-to-aig (car args)) (expr-to-aig (cadr args)))) ((and (eq fn 'implies) (= (len args) 2)) (aig-or (aig-not (expr-to-aig (car args))) (expr-to-aig (cadr args)))) ((and (eq fn 'if) (= (len args) 3)) (aig-ite (expr-to-aig (car args)) (expr-to-aig (cadr args)) (expr-to-aig (caddr args)))) (t (prog2$ (er hard? 'expr-to-aig "Malformed: ~x0~%" expr) nil))))))
Function:
(defun expr-to-aig-args (op final exprs) (declare (xargs :guard t)) (if (atom exprs) final (let ((first (expr-to-aig (car exprs))) (rest (expr-to-aig-args op final (cdr exprs)))) (case op (and (aig-and first rest)) (or (aig-or first rest))))))