Included Books
other
(in-package "ACL2")
local
(local (include-book "../pass1/top"))
package-witnessfunction
(defun package-witness nil t)
intern-namefunction
(defun intern-name (lst) (declare (xargs :mode :program)) (intern-in-package-of-symbol (coerce (packn1 lst) 'string) 'package-witness))
other
(defevaluator eva eva-list ((un-hide-+ x y) (un-hide-* x y) (collect-* x y) (collect-+ x y) (binary-* x y) (binary-+ x y) (unary-/ x) (unary-- x) (expt x y) (equal x y) (< x y) (if x y z) (rationalp x) (acl2-numberp x) (fix x) (rfix x) (not x) (hide x)))
un-hide-plustheorem
(defthm un-hide-plus (equal (un-hide-+ x (hide y)) (+ x y)))
collect-plus-0theorem
(defthm collect-plus-0 (implies (equal x x) (equal (collect-+ (hide x) (hide y)) (+ x y))))
collect-plus-0atheorem
(defthm collect-plus-0a (implies (and (syntaxp (consp x)) (syntaxp (equal (car x) 'quote)) (syntaxp (consp y)) (syntaxp (equal (car y) 'quote))) (equal (collect-+ (hide x) (hide y)) (+ x y))))
collect-plus-1dtheorem
(defthm collect-plus-1d (equal (collect-+ (hide (- x)) (hide (- x))) (* -2 x)))
collect-plus-2atheorem
(defthm collect-plus-2a (equal (collect-+ (hide x) (hide (* a x))) (* (+ a 1) x)))
collect-plus-2btheorem
(defthm collect-plus-2b (equal (collect-+ (hide (* a x)) (hide x)) (* (+ a 1) x)))
collect-plus-2ctheorem
(defthm collect-plus-2c (equal (collect-+ (hide (- x)) (hide (* a x))) (* (- a 1) x)))
collect-plus-2dtheorem
(defthm collect-plus-2d (equal (collect-+ (hide (* a x)) (hide (- x))) (* (- a 1) x)))
collect-plus-3theorem
(defthm collect-plus-3 (equal (collect-+ (hide (* a x)) (hide (* b x))) (* (+ a b) x)))
un-hide-timestheorem
(defthm un-hide-times (equal (un-hide-* x (hide y)) (* x y)))
collect-times-0theorem
(defthm collect-times-0 (implies (equal x x) (equal (collect-* (hide x) (hide y)) (* x y))))
collect-times-0atheorem
(defthm collect-times-0a (equal (collect-* (hide x) (hide 0)) 0))
collect-times-0btheorem
(defthm collect-times-0b (equal (collect-* (hide 0) (hide x)) 0))
collect-times-0ctheorem
(defthm collect-times-0c (implies (and (syntaxp (consp x)) (syntaxp (equal (car x) 'quote)) (syntaxp (consp y)) (syntaxp (equal (car y) 'quote))) (equal (collect-* (hide x) (hide y)) (* x y))))
collect-times-1atheorem
(defthm collect-times-1a (equal (collect-* (hide x) (hide x)) (expt x 2)))
collect-times-1btheorem
(defthm collect-times-1b (equal (collect-* (hide x) (hide (/ x))) (if (equal (fix x) 0) 0 1)))
collect-times-1ctheorem
(defthm collect-times-1c (equal (collect-* (hide (/ x)) (hide x)) (if (equal (fix x) 0) 0 1)))
collect-times-1dtheorem
(defthm collect-times-1d (equal (collect-* (hide (/ x)) (hide (/ x))) (expt x -2)) :hints (("Subgoal 1" :expand ((expt x -2)))))
collect-times-2atheorem
(defthm collect-times-2a (implies (integerp i) (equal (collect-* (hide x) (hide (expt x i))) (if (equal (fix x) 0) 0 (expt x (+ i 1))))))
collect-times-2btheorem
(defthm collect-times-2b (implies (integerp i) (equal (collect-* (hide (expt x i)) (hide x)) (if (equal (fix x) 0) 0 (expt x (+ i 1))))))
collect-times-2ctheorem
(defthm collect-times-2c (implies (integerp i) (equal (collect-* (hide x) (hide (expt (/ x) i))) (if (equal (fix x) 0) 0 (expt (/ x) (- i 1))))))
collect-times-2dtheorem
(defthm collect-times-2d (implies (integerp i) (equal (collect-* (hide (expt (/ x) i)) (hide x)) (if (equal (fix x) 0) 0 (expt (/ x) (- i 1))))))
collect-times-2etheorem
(defthm collect-times-2e (implies (integerp i) (equal (collect-* (hide (/ x)) (hide (expt x i))) (if (equal (fix x) 0) 0 (expt x (- i 1))))))
collect-times-2ftheorem
(defthm collect-times-2f (implies (integerp i) (equal (collect-* (hide (expt x i)) (hide (/ x))) (if (equal (fix x) 0) 0 (expt x (- i 1))))))
collect-times-2gtheorem
(defthm collect-times-2g (implies (integerp i) (equal (collect-* (hide (/ x)) (hide (expt (/ x) i))) (if (equal (fix x) 0) 0 (expt (/ x) (+ i 1))))))
collect-times-2htheorem
(defthm collect-times-2h (implies (integerp i) (equal (collect-* (hide (expt (/ x) i)) (hide (/ x))) (if (equal (fix x) 0) 0 (expt (/ x) (+ i 1))))))
collect-times-3atheorem
(defthm collect-times-3a (implies (and (integerp i) (integerp j)) (equal (collect-* (hide (expt x i)) (hide (expt x j))) (if (and (equal (fix x) 0) (not (equal i 0)) (not (equal j 0))) 0 (expt x (+ i j))))))
collect-times-3btheorem
(defthm collect-times-3b (implies (and (integerp i) (integerp j)) (equal (collect-* (hide (expt (/ x) i)) (hide (expt x j))) (if (and (equal (fix x) 0) (not (equal i 0)) (not (equal j 0))) 0 (expt x (- j i))))))
collect-times-3ctheorem
(defthm collect-times-3c (implies (and (integerp i) (integerp j)) (equal (collect-* (hide (expt x i)) (hide (expt (/ x) j))) (if (and (equal (fix x) 0) (not (equal i 0)) (not (equal j 0))) 0 (expt x (- i j))))))
collect-times-3dtheorem
(defthm collect-times-3d (implies (and (integerp i) (integerp j)) (equal (collect-* (hide (expt (/ x) i)) (hide (expt (/ x) j))) (if (and (equal (fix x) 0) (not (equal i 0)) (not (equal j 0))) 0 (expt (/ x) (+ i j))))))
collect-times-4theorem
(defthm collect-times-4 (implies (integerp n) (equal (collect-* (hide (expt x n)) (hide (expt y n))) (expt (* x y) n))))
addend-patternfunction
(defun addend-pattern (addend) (cond ((variablep addend) addend) ((fquotep addend) (if (equal addend ''0) nil (unquote addend))) ((eq (ffn-symb addend) 'unary--) (addend-pattern (arg1 addend))) ((and (eq (ffn-symb addend) 'binary-*) (acl2-nump (arg1 addend))) (addend-pattern (arg2 addend))) (t addend)))
factor-pattern-gather-exponentsfunction
(defun factor-pattern-gather-exponents (factor) (cond ((variablep factor) factor) ((fquotep factor) (let ((c (unquote factor))) (cond ((eql c 0) 0) ((rationalp c) (if (< (abs c) 1) (/ c) c)) (t c)))) ((eq (ffn-symb factor) 'unary-/) (factor-pattern-gather-exponents (arg1 factor))) ((eq (ffn-symb factor) 'expt) (let ((base (arg1 factor)) (exponent (arg2 factor))) (cond ((quotep base) (let ((c (unquote base))) (cond ((eql c 0) nil) ((rationalp c) (if (< (abs c) 1) (list :mark1 (/ c) exponent) (list :mark1 c exponent))) (t (list :mark1 c exponent))))) ((member-eq (fn-symb base) '(unary-- unary-/)) (factor-pattern-gather-exponents (arg1 base))) (t base)))) (t factor)))
factor-pattern-exponent2function
(defun factor-pattern-exponent2 (addend weight) (let ((weight (zfix weight))) (if (and (eq (fn-symb addend) 'binary-*) (quotep (arg1 addend))) (if (eql (unquote (arg1 addend)) weight) (arg2 addend) `(binary-* ,(KWOTE (/ (ZFIX (UNQUOTE (ARG1 ADDEND))) WEIGHT)) ,(ARG2 ADDEND))) `(binary-* ,(KWOTE (/ WEIGHT)) ,ADDEND))))
factor-pattern-exponent1function
(defun factor-pattern-exponent1 (exponent weight) (if (eq (fn-symb exponent) 'binary-+) `(binary-+ ,(FACTOR-PATTERN-EXPONENT2 (ARG1 EXPONENT) WEIGHT) ,(FACTOR-PATTERN-EXPONENT1 (ARG2 EXPONENT) WEIGHT)) (factor-pattern-exponent2 exponent weight)))
factor-pattern-exponentfunction
(defun factor-pattern-exponent (exponent) (cond ((or (variablep exponent) (fquotep exponent)) (mv 1 exponent)) ((eq (ffn-symb exponent) 'binary-*) (if (quotep (arg1 exponent)) (mv (arg1 exponent) (arg2 exponent)) (mv 1 exponent))) ((eq (ffn-symb exponent) 'binary-+) (if (and (eq (fn-symb (arg1 exponent)) 'binary-*) (acl2-nump (arg1 (arg1 exponent)))) (let ((weight (unquote (arg1 (arg1 exponent))))) (mv weight (factor-pattern-exponent1 exponent weight))) (mv 1 exponent))) (t (mv 1 exponent))))
factor-pattern-scatter-exponentsfunction
(defun factor-pattern-scatter-exponents (factor) (cond ((variablep factor) factor) ((fquotep factor) (let ((c (unquote factor))) (cond ((eql c 0) 0) ((rationalp c) (if (< (abs c) 1) (/ c) c)) (t c)))) ((eq (ffn-symb factor) 'unary-/) (factor-pattern-scatter-exponents (arg1 factor))) ((eq (ffn-symb factor) 'expt) (let ((base (cond ((quotep (arg1 factor)) (unquote factor)) ((member-eq (fn-symb (arg1 factor)) '(unary-- unary-/)) (arg1 (arg1 factor))) (t (arg1 factor)))) (exponent (arg2 factor))) (if (acl2-numberp base) (cond ((variablep exponent) `(:mark2 ,BASE 1 ,EXPONENT)) ((fquotep exponent) `(:mark2 ,BASE 1 ,EXPONENT)) ((eq (ffn-symb exponent) 'binary-*) (if (quotep (arg1 exponent)) `(:mark2 ,BASE ,(UNQUOTE (ARG1 EXPONENT)) ,(ARG2 EXPONENT)) `(:mark2 ,BASE 1 ,(ARG2 EXPONENT)))) ((eq (ffn-symb exponent) 'binary-+) (mv-let (weight new-exponent) (factor-pattern-exponent exponent) `(:mark2 ,BASE ,WEIGHT ,NEW-EXPONENT))) (t `(:mark2 ,BASE 1 ,EXPONENT))) (cond ((variablep exponent) `(expt ,BASE ,EXPONENT)) ((fquotep exponent) base) ((eq (ffn-symb exponent) 'binary-*) (if (quotep (arg1 exponent)) `(expt ,BASE ,(ARG2 EXPONENT)) factor)) ((eq (ffn-symb exponent) 'binary-+) (mv-let (weight new-exponent) (factor-pattern-exponent exponent) (declare (ignore weight)) `(expt ,BASE ,NEW-EXPONENT))) (t `(expt ,BASE ,EXPONENT)))))) (t factor)))
pattern-matchpfunction
(defun pattern-matchp (x y) (cond ((or (eq x nil) (eq y nil)) nil) ((or (eq x t) (eq y t)) t) ((or (eql x 0) (eql y 0)) (not (and (eql x 0) (eql y 0)))) ((acl2-numberp x) (or (acl2-numberp y) (and (consp y) (eq (car y) :mark1) (equal (cadr y) x)))) ((and (consp x) (eq (car x) :mark1)) (or (equal y (cadr x)) (and (consp y) (eq (car y) :mark) (or (equal (cadr y) (cadr x)) (equal (caddr y) (caddr x)))))) ((and (consp x) (eq (car x) :mark2)) (and (consp y) (eq (car y) :mark2) (equal (cadr x) (cadr y)) (equal (cadddr x) (cadddr y)))) (t (equal x y))))
local
(local (in-theory (disable pattern-matchp)))
assoc-pattern-matchpfunction
(defun assoc-pattern-matchp (key alist) (cond ((endp alist) nil) ((pattern-matchp key (caar alist)) (car alist)) (t (assoc-pattern-matchp key (cdr alist)))))
addend-valfunction
(defun addend-val (addend) (cond ((variablep addend) 1) ((fquotep addend) (fix-val addend)) ((eq (ffn-symb addend) 'unary--) -1) ((and (eq (ffn-symb addend) 'binary-*) (quotep (arg1 addend))) (fix-val (arg1 addend))) (t 1)))
factor-val1function
(defun factor-val1 (exponent) (cond ((variablep exponent) 1) ((fquotep exponent) (fix-val exponent)) ((eq (ffn-symb exponent) 'binary-*) (if (quotep (arg1 exponent)) (fix-val (arg1 exponent)) 1)) ((eq (ffn-symb exponent) 'binary-+) (+ (factor-val1 (arg1 exponent)) (factor-val1 (arg2 exponent)))) (t 1)))
factor-valfunction
(defun factor-val (factor) (cond ((variablep factor) 1) ((fquotep factor) (if (or (equal factor ''0) (equal factor ''1)) 0 1)) ((eq (ffn-symb factor) 'unary-/) -1) ((eq (ffn-symb factor) 'expt) (factor-val1 (arg2 factor))) (t 1)))
use-firstpfunction
(defun use-firstp (val1 val2 bin-op) (declare (ignore bin-op)) (cond ((eql (abs val1) (abs val2)) (< val1 0)) (t (< (abs val2) (abs val1)))))
my-apply-1function
(defun my-apply-1 (fun arg) (case fun (addend-pattern (addend-pattern arg)) (factor-pattern-gather-exponents (factor-pattern-gather-exponents arg)) (factor-pattern-scatter-exponents (factor-pattern-scatter-exponents arg)) (addend-val (addend-val arg)) (factor-val (factor-val arg))))
local
(local (in-theory (disable my-apply-1)))
pull-piece-outfunction
(defun pull-piece-out (term pattern pattern-fun bin-op) (cond ((or (variablep term) (fquotep term)) (mv nil nil term)) ((pattern-matchp (my-apply-1 pattern-fun (arg1 term)) pattern) (mv t (arg1 term) (arg2 term))) ((eq (fn-symb (arg2 term)) bin-op) (mv-let (flag piece rest) (pull-piece-out (arg2 term) pattern pattern-fun bin-op) (if flag (mv t piece `(,BIN-OP ,(ARG1 TERM) ,REST)) (mv nil nil term)))) ((pattern-matchp (my-apply-1 pattern-fun (arg2 term)) pattern) (mv t (arg2 term) (arg1 term))) (t (mv nil nil term))))
new-term1function
(defun new-term1 (term new-piece pattern pattern-fun bin-op) (if (member-eq bin-op '(binary-+ binary-*)) (cond ((eq (fn-symb term) bin-op) (mv-let (flag piece rest) (pull-piece-out term pattern pattern-fun bin-op) (if flag (case bin-op ((binary-+) (mv t `(un-hide-+ (collect-+ (hide ,NEW-PIECE) (hide ,PIECE)) (hide ,REST)))) ((binary-*) (mv t `(un-hide-* (collect-* (hide ,NEW-PIECE) (hide ,PIECE)) (hide ,REST)))) (otherwise (mv t `(,BIN-OP ,NEW-PIECE ,TERM)))) (mv nil `(,BIN-OP ,NEW-PIECE ,TERM))))) ((pattern-matchp (my-apply-1 pattern-fun term) pattern) (if (eq bin-op 'binary-+) (mv t `(collect-+ (hide ,NEW-PIECE) (hide ,TERM))) (mv t `(collect-* (hide ,NEW-PIECE) (hide ,TERM))))) (t (mv nil `(,BIN-OP ,NEW-PIECE ,TERM)))) (mv nil `(,BIN-OP ,NEW-PIECE ,TERM))))
new-termfunction
(defun new-term (term new-piece pattern pattern-fun bin-op) (if (and (eq bin-op 'binary-*) (eq (fn-symb term) 'binary-+)) (mv-let (flag1 new-term1) (new-term1 (arg1 term) new-piece pattern pattern-fun bin-op) (mv-let (flag2 new-term2) (new-term (arg2 term) new-piece pattern pattern-fun bin-op) (mv (or flag1 flag2) `(binary-+ ,NEW-TERM1 ,NEW-TERM2)))) (new-term1 term new-piece pattern pattern-fun bin-op)))
new-term-correctencapsulate
(encapsulate nil (local (defun pull-piece-up (term pattern pattern-fun bin-op) (if (and (member-eq bin-op '(binary-+ binary-*)) (eq (fn-symb term) bin-op)) (mv-let (flag piece new-term) (pull-piece-out term pattern pattern-fun bin-op) (if flag `(,BIN-OP ,PIECE ,NEW-TERM) term)) term))) (local (defthm pull-piece-up-correct (equal (eva (pull-piece-up term pattern pattern-fun bin-op) a) (eva term a)) :hints (("Subgoal 2'" :induct t) ("Subgoal 1'" :induct t)) :rule-classes nil)) (local (defthm new-term1-correct (mv-let (flag new-term) (new-term1 term new-piece pattern pattern-fun bin-op) (declare (ignore flag)) (equal (eva new-term a) (eva `(,BIN-OP ,NEW-PIECE ,TERM) a))) :hints (("Goal" :in-theory (disable pull-piece-out)) ("Subgoal 7''" :use ((:instance pull-piece-up-correct (bin-op 'binary-+)))) ("Subgoal 3''" :use ((:instance pull-piece-up-correct (bin-op 'binary-*))))))) (defthm new-term-correct (mv-let (flag new-term) (new-term term new-piece pattern pattern-fun bin-op) (declare (ignore flag)) (equal (eva new-term a) (eva `(,BIN-OP ,NEW-PIECE ,TERM) a))) :hints (("Goal" :do-not '(generalize eliminate-destructors) :in-theory (disable new-term1)))))
in-theory
(in-theory (disable factor-pattern-exponent2 factor-pattern-exponent1 factor-pattern-exponent factor-val1))
in-theory
(in-theory (disable addend-pattern factor-pattern-gather-exponents factor-pattern-scatter-exponents fix-val addend-val factor-val))
in-theory
(in-theory (disable pattern-matchp))
in-theory
(in-theory (disable assoc-pattern-matchp))
in-theory
(in-theory (disable my-apply-1))
in-theory
(in-theory (disable pull-piece-out new-term1 new-term))
in-theory
(in-theory (disable un-hide-times collect-times-0 collect-times-0a collect-times-0b collect-times-1a collect-times-1b collect-times-1c collect-times-1d collect-times-2a collect-times-2b collect-times-2c collect-times-2d collect-times-2e collect-times-2f collect-times-2g collect-times-2h collect-times-3a collect-times-3b collect-times-3c collect-times-3d collect-times-4))