3
;The rule power2p-rewrite has proven quite helpful.
6
(declare (xargs :guard (real/rationalp x)))
9
(local (include-book "fl")) ;or could use floor?
10
(local (include-book "fp2"))
11
(local (include-book "predicate"))
12
(local (include-book "unary-divide"))
16
; (equal x (expt 2 (expo x))))
18
(include-book "../../../ordinals/e0-ordinal")
19
(set-well-founded-relation e0-ord-<)
21
(defund power2p-measure (x)
22
(declare (xargs :guard (and (rationalp x) (not (equal x 0)))))
23
(cond ((or (not (rationalp x))
25
((< x 1) (cons 1 (fl (/ x))))
29
(declare (xargs :guard t
30
:measure (power2p-measure x)
31
:hints (("goal" :in-theory (enable power2p-measure)))))
32
(cond ((or (not (rationalp x))
35
((< x 1) (power2p (* 2 x)))
36
((<= 2 x) (power2p (* 1/2 x)))
38
(t nil) ;got a number in the doubly-open interval (1,2)
41
#| A term fits the "power of 2" pattern iff it is a tree built using * and / (actually, binary-* and unary-/)
42
in which each leaf is either a rational constant which is a power of 2 or a term of the form (EXPT 2 I).
45
(defund power2-syntaxp (term)
46
(if (not (consp term))
49
(quote (and (rationalp (cadr term))
50
(power2p (cadr term))))
51
(expt (equal (cadr term) '(quote 2))) ;allow the base to be any power of 2? (constants only? or (expt 2 n)??
52
(binary-* (and (power2-syntaxp (cadr term))
53
(power2-syntaxp (caddr term))))
54
(unary-/ (power2-syntaxp (cadr term)))
62
(power2-syntaxp '(expt 2 i))
63
(power2-syntaxp '(unary-/ (expt 2 i)))
64
(power2-syntaxp '(binary-/ (expt 2 i) (expt 2 j)))
65
(power2-syntaxp '(binary-* (expt 2 i) (expt 2 j)))
66
(power2-syntaxp '(binary-* '2 (binary-* (expt '2 j) (expt '2 k))))
67
(power2-syntaxp '(binary-* '2 (binary-* (expt '2 j) (expt '2 (binary-+ k (binary-* '-1 j))))))
73
(defthmd power2p-with-arg-between-one-and-two
74
(implies (and (< 1/2 x)
78
:hints (("goal" :in-theory (enable power2p)))
81
(defthm power2p-of-non-rational
82
(implies (not (rationalp x))
85
:hints (("goal" :in-theory (enable power2p))))
87
(defthm power2p-of-non-positive
88
(implies (not (< 0 x))
91
:hints (("goal" :in-theory (enable power2p))))
94
(defthm power2p-inverse
95
(and (equal (power2p (/ x))
97
(equal (power2p (/ 1 x)) ;do we need this?
100
:hints (("goal" :in-theory (enable power2p
101
power2p-with-arg-between-one-and-two))))
103
;what about (/ -1 x) ? (/ 1 (- x)) ?
104
;in general, what if x is negative, and we have something like (power2p (- x)) ?
106
;power2p-double and power2p-half helped clean up the proof of power2p-prod
107
(defthmd power2p-double
108
(equal (power2p (* 2 x))
110
:hints (("goal" :in-theory (enable power2p
111
power2p-with-arg-between-one-and-two))))
113
(defthmd power2p-half
114
(equal (power2p (* 1/2 x))
116
:hints (("goal" :in-theory (enable power2p
117
power2p-with-arg-between-one-and-two))))
119
(defthmd power2p-prod
120
(implies (and (power2p x)
123
:hints (("goal" :in-theory (enable power2p power2p-double power2p-half
124
power2p-with-arg-between-one-and-two))))
126
;robustify with power2p-quotient?
128
;reorder hyps? make conclusion into an equality?
129
(defthmd power2p-prod-not
130
(implies (and (not (power2p x))
133
(not (power2p (* x y))))
134
:hints (("goal" :in-theory (disable power2p-prod)
135
:use (:instance power2p-prod (x (* x y)) (y (/ y))))))
137
(defthm power2p-shift
138
(implies (and (syntaxp (power2-syntaxp x))
139
(force (power2p x)) ;this should be true if the syntaxp hyp is satisfied
141
(equal (power2p (* x y))
144
:use ((:instance power2p-prod-not (y x) (x y))
145
(:instance power2p-prod (y x) (x y))))))
147
(defthm power2p-shift-2
148
(implies (and (syntaxp (power2-syntaxp y))
149
(force (power2p y)) ;this should be true if the syntaxp hyp is satisfied
151
(equal (power2p (* x y))
153
:hints (("goal" :in-theory (disable power2p)
154
:use ( power2p-prod-not power2p-prod))))
157
;make rules for quotient of powers of 2
160
(defthm power2p-means-positive-rationalp
164
:rule-classes ((:forward-chaining :trigger-terms ((POWER2P X)))))