1
; This file is based on the old "fp book", which was initially created by J
2
; Moore and Matt Kaufmann in 1995 in support of their proof of the AMD-K5
3
; division code. Here, we have moved
4
; non-local in-theory events to the end. All events should be redundant, so we
5
; have deleted all local in-theory events and added (local (in-theory nil)) to
10
(set-enforce-redundancy t)
12
(local (include-book "../arithmetic/fp"))
13
(local (include-book "../arithmetic/fp2"))
14
(local (include-book "../arithmetic/fl"))
15
(local (include-book "../arithmetic/expt"))
16
(local (include-book "../arithmetic/expo"))
17
(local (include-book "../arithmetic/extra-rules"))
18
(local (include-book "../support/support/ash"))
20
;; (local (include-book "../support/top/top"))
22
;; these already have lib1.delta1's
23
;; arith.lisp!! deftheory???
24
;; Why I can't do that??
27
(set-inhibit-warnings "theory") ; avoid warning in the next event
28
(local (in-theory nil))
29
;(set-inhibit-warnings) ; restore theory warnings (optional)
31
(defthm a1 (equal (+ x (+ y z)) (+ y (+ x z))))
32
(defthm a2 (equal (- x) (* -1 x)))
37
(syntaxp (and (quotep c1) (quotep c2)))
38
(and (equal (+ (* c1 x) (* c2 x)) (* (+ c1 c2) x))
39
(equal (+ (* c1 x) (+ (* c2 x) y)) (+ (* (+ c1 c2) x) y))))
42
(and (equal (+ x (* c2 x)) (* (+ 1 c2) x))
43
(equal (+ x (+ (* c2 x) y1)) (+ (* (+ 1 c2) x) y1))
44
(equal (+ x (+ y1 (* c2 x))) (+ (* (+ 1 c2) x) y1))
45
(equal (+ x (+ y1 (+ (* c2 x) y2))) (+ (* (+ 1 c2) x) y1 y2))
46
(equal (+ x (+ y1 (+ y2 (* c2 x)))) (+ (* (+ 1 c2) x) y1 y2))
47
(equal (+ x (+ y1 (+ y2 (+ y3 (* c2 x)))))
48
(+ (* (+ 1 c2) x) y1 y2 y3))
49
(equal (+ x (+ y1 (+ y2 (+ (* c2 x) y3))))
50
(+ (* (+ 1 c2) x) y1 y2 y3))))
51
(and (equal (+ x x) (* 2 x))
52
(equal (+ x (+ x y1)) (+ (* 2 x) y1)))))
54
(implies (syntaxp (and (quotep c1) (quotep c2)))
55
(equal (+ c1 (+ c2 y1)) (+ (+ c1 c2) y1))))
57
(implies (syntaxp (and (quotep c1) (quotep c2)))
58
(equal (* c1 (* c2 y1)) (* (* c1 c2) y1))))
65
(equal (/ (/ x)) (fix x)))
67
(equal (/ (* x y)) (* (/ x) (/ y))))
69
;replaced force with case-split
71
(implies (and (case-split (acl2-numberp x))
72
(case-split (not (equal x 0))))
73
(and (equal (* x (* (/ x) y)) (fix y))
74
(equal (* x (/ x)) 1))))
77
(and (equal (* 0 x) 0)
78
(equal (* x (* y z)) (* y (* x z)))
79
(equal (* x (+ y z)) (+ (* x y) (* x z)))
80
(equal (* (+ y z) x) (+ (* y x) (* z x)))))
83
(declare (xargs :guard (real/rationalp x)))
89
(and (implies (integerp i) (equal (fl i) i))
90
(implies (and (integerp i)
91
(case-split (rationalp x1)) ;can actually drop this
93
(and (equal (fl (+ i x1)) (+ i (fl x1)))
94
(equal (fl (+ x1 i)) (+ i (fl x1)))))
95
(implies (and (integerp i)
96
(case-split (rationalp x1))
97
(case-split (rationalp x2)))
98
(and (equal (fl (+ x1 (+ i x2))) (+ i (fl (+ x1 x2))))
99
(equal (fl (+ x1 (+ x2 i))) (+ i (fl (+ x1 x2))))))
100
(implies (and (integerp i)
101
(case-split (rationalp x1))
102
(case-split (rationalp x2))
103
(case-split (rationalp x3)))
104
(and (equal (fl (+ x1 (+ x2 (+ i x3))))
105
(+ i (fl (+ x1 x2 x3))))
106
(equal (fl (+ x1 (+ x2 (+ x3 i))))
107
(+ i (fl (+ x1 x2 x3))))))
108
(implies (and (integerp i)
109
(case-split (rationalp x1))
110
(case-split (rationalp x2))
111
(case-split (rationalp x3))
112
(case-split (rationalp x4)))
113
(and (equal (fl (+ x1 (+ x2 (+ x3 (+ i x4)))))
114
(+ i (fl (+ x1 x2 x3 x4))))
115
(equal (fl (+ x1 (+ x2 (+ x3 (+ x4 i)))))
116
(+ i (fl (+ x1 x2 x3 x4))))))))
119
(implies (and (integerp i)
123
(and (< (acl2-count (fl (/ i j))) (acl2-count i))
124
(< (acl2-count (fl (* (/ j) i))) (acl2-count i))))
125
:rule-classes :linear)
128
;replaced force with case-split
129
;later, drop the hyp completely
131
(implies (case-split (rationalp x)) ;drop!
132
(and (< (1- x) (fl x))
134
:rule-classes :linear)
138
(implies (and (integerp i)
141
(and (integerp (expt i j))
143
(implies (and (rationalp i)
145
(not (equal (expt i j) 0))))
149
(implies (and (integerp i)
152
(and (integerp (expt i j))
156
(implies (and (rationalp i)
158
(not (equal (expt i j) 0))))))
161
(implies (and (rationalp i)
165
(and (equal (* (expt i j1) (expt i j2))
167
(equal (* (expt i j1) (* (expt i j2) x))
168
(* (expt i (+ j1 j2)) x)))))
170
(equal (expt (* a b) i)
171
(* (expt a i) (expt b i))))
173
(defthm /-weakly-monotonic
174
(implies (and (<= y y+)
176
(case-split (rationalp y))
177
(case-split (rationalp y+))
181
((:forward-chaining :trigger-terms ((/ y+) (/ y))) :linear))
183
(defthm /-strongly-monotonic
184
(implies (and (< y y+)
186
(case-split (rationalp y))
187
(case-split (rationalp y+))
191
((:forward-chaining :trigger-terms ((/ y+) (/ y))) :linear))
193
(defthm *-weakly-monotonic
194
(implies (and (<= y y+)
196
(case-split (rationalp x)) ; This does not hold if x, y, and z are complex!
198
(<= (* x y) (* x y+)))
200
((:forward-chaining :trigger-terms ((* x y) (* x y+)))
203
:trigger-terms ((* y x) (* y+ x))
205
(implies (and (<= y y+)
207
(case-split (rationalp x))
209
(<= (* y x) (* y+ x))))
212
(implies (and (<= y y+)
214
(case-split (rationalp x))
216
(<= (* y x) (* y+ x))))))
218
#| Here is the complex counterexample to which we alluded above.
223
(implies (and (<= y y+)
225
(<= (* x y) (* x y+))))
228
(defthm *-strongly-monotonic
229
(implies (and (< y y+)
231
(case-split (rationalp x))
233
(< (* x y) (* x y+)))
235
((:forward-chaining :trigger-terms ((* x y) (* x y+)))
238
:trigger-terms ((* y x) (* y+ x))
240
(implies (and (< y y+)
242
(case-split (rationalp x))
244
(< (* y x) (* y+ x))))
247
(implies (and (< y y+)
249
(case-split (rationalp x))
251
(< (* y x) (* y+ x))))))
253
(defthm *-weakly-monotonic-negative-multiplier
254
(implies (and (<= y y+)
256
(case-split (rationalp x))
258
(<= (* x y+) (* x y)))
260
((:forward-chaining :trigger-terms ((* x y) (* x y+)))
263
:trigger-terms ((* y x) (* y+ x))
265
(implies (and (<= y y+)
267
(case-split (rationalp x))
269
(<= (* y+ x) (* y x))))
272
(implies (and (<= y y+)
274
(case-split (rationalp x))
276
(<= (* y+ x) (* y x))))))
278
(defthm *-strongly-monotonic-negative-multiplier
279
(implies (and (< y y+)
281
(case-split (rationalp x))
283
(< (* x y+) (* x y)))
285
((:forward-chaining :trigger-terms ((* x y) (* x y+)))
288
:trigger-terms ((* y x) (* y+ x))
290
(implies (and (< y y+)
292
(case-split (rationalp x))
294
(< (* y+ x) (* y x))))
297
(implies (and (< y y+)
299
(case-split (rationalp x))
301
(< (* y+ x) (* y x))))))
303
(defthm fl-weakly-monotonic
304
(implies (and (<= y y+)
305
(case-split (rationalp y)) ;drop?
306
(case-split (rationalp y+)) ;drop?
309
:rule-classes ((:forward-chaining :trigger-terms ((fl y) (fl y+)))
312
:trigger-terms ((fl y) (fl y+))
313
:corollary (implies (and (< y y+)
314
(case-split (rationalp y))
315
(case-split (rationalp y+)))
316
(<= (fl y) (fl y+))))
318
:corollary (implies (and (< y y+)
319
(case-split (rationalp y))
320
(case-split (rationalp y+)))
321
(<= (fl y) (fl y+))))))
323
(deftheory arith-fc-monotonicity
324
'((:forward-chaining /-weakly-monotonic)
325
(:forward-chaining /-strongly-monotonic)
326
(:forward-chaining *-weakly-monotonic . 1)
327
(:forward-chaining *-weakly-monotonic . 2)
328
(:forward-chaining *-strongly-monotonic . 1)
329
(:forward-chaining *-strongly-monotonic . 2)
330
(:forward-chaining *-weakly-monotonic-negative-multiplier . 1)
331
(:forward-chaining *-weakly-monotonic-negative-multiplier . 2)
332
(:forward-chaining *-strongly-monotonic-negative-multiplier . 1)
333
(:forward-chaining *-strongly-monotonic-negative-multiplier . 2)
334
(:forward-chaining fl-weakly-monotonic . 1)
335
(:forward-chaining fl-weakly-monotonic . 2)
338
; We now prove a bunch of bounds theorems for *. We are concerned with bounding the
339
; product of a and b given intervals for a and b. We consider three kinds of intervals.
340
; We discuss only the a case.
342
; abs intervals mean (abs a) < amax or -amax < a < amax, where amax is positive.
344
; nonneg-open intervals mean 0<=a<amax.
346
; nonneg-closed intervals mean 0<=a<=amax, where amax is positive.
348
; We now prove theorems with names like abs*nonneg-open, etc. characterizing
349
; the product of two elements from two such intervals. All of these theorems
350
; are made with :rule-classes nil because I don't know how to control their
353
; This lemma is for lookup * d and lookup * away. We don't need to consider 0
354
; < b for the d case because we have 0 < 1 <= d and the conclusion of the new
355
; lemma would be no different.
357
(defthm abs*nonneg-open
358
(implies (and (rationalp a)
363
(<= a amax) ; (< a amax) is all we'll ever use, I bet.
367
(and (< (- (* amax bmax)) (* a b))
368
(< (* a b) (* amax bmax))))
373
(defthm abs*nonneg-closed
374
(implies (and (rationalp a)
384
(and (< (- (* amax bmax)) (* a b))
385
(< (* a b) (* amax bmax))))
388
(defthm nonneg-closed*abs
389
(implies (and (rationalp a)
399
(and (< (- (* amax bmax)) (* b a))
400
(< (* b a) (* amax bmax))))
403
(defthm nonneg-open*abs
404
(implies (and (rationalp a)
409
(<= a amax) ; (< a amax) is all we'll ever use, I bet.
413
(and (< (- (* bmax amax)) (* a b))
414
(< (* a b) (* bmax amax))))
417
; The next three, which handle nonnegative open intervals in the first argument,
418
; can actually be seen as uses of the abs intervals above. Simply observe that
419
; if 0<=a<amax then -amax<a<amax.
421
(defthm nonneg-open*nonneg-closed
422
(implies (and (rationalp a)
432
(< (* a b) (* amax bmax))))
435
(defthm nonneg-open*nonneg-open
436
(implies (and (rationalp a)
445
(< (* a b) (* amax bmax))))
448
; and the commuted version
449
(defthm nonneg-closed*nonneg-open
450
(implies (and (rationalp a)
460
(< (* b a) (* amax bmax))))
463
(defthm nonneg-closed*nonneg-closed
464
(implies (and (rationalp a)
475
(<= (* a b) (* amax bmax))))
479
(implies (and (rationalp a)
489
(and (< (- (* amax bmax)) (* a b))
490
(< (* a b) (* amax bmax))))
493
(defthm rearrange-negative-coefs-<
494
(and (equal (< (* (- c) x) z)
496
(equal (< (+ (* (- c) x) y) z)
498
(equal (< (+ y (* (- c) x)) z)
500
(equal (< (+ y1 y2 (* (- c) x)) z)
501
(< (+ y1 y2) (+ (* c x) z)))
502
(equal (< (+ y1 y2 y3 (* (- c) x)) z)
503
(< (+ y1 y2 y3) (+ (* c x) z)))
504
(equal (< z (+ (* (- c) x) y))
506
(equal (< z (+ y (* (- c) x)))
508
(equal (< z (+ y1 y2 (* (- c) x)))
509
(< (+ (* c x) z) (+ y1 y2)))
510
(equal (< z (+ y1 y2 y3 (* (- c) x)))
511
(< (+ (* c x) z) (+ y1 y2 y3)))))
513
(defthm rearrange-negative-coefs-equal
514
(and (implies (and (case-split (rationalp c))
515
(case-split (rationalp x))
516
(case-split (rationalp z)))
517
(equal (equal (* (- c) x) z)
518
(equal 0 (+ (* c x) z))))
519
(implies (and (case-split (rationalp c))
520
(case-split (rationalp x))
521
(case-split (rationalp y))
522
(case-split (rationalp z)))
523
(equal (equal (+ (* (- c) x) y) z)
524
(equal y (+ (* c x) z))))
525
(implies (and (case-split (rationalp c))
526
(case-split (rationalp x))
527
(case-split (rationalp y))
528
(case-split (rationalp z)))
529
(equal (equal (+ y (* (- c) x)) z)
530
(equal y (+ (* c x) z))))
531
(implies (and (case-split (rationalp c))
532
(case-split (rationalp x))
533
(case-split (rationalp y1))
534
(case-split (rationalp y2))
535
(case-split (rationalp z)))
536
(equal (equal (+ y1 y2 (* (- c) x)) z)
537
(equal (+ y1 y2) (+ (* c x) z))))
538
(implies (and (case-split (rationalp c))
539
(case-split (rationalp x))
540
(case-split (rationalp y1))
541
(case-split (rationalp y2))
542
(case-split (rationalp y3))
543
(case-split (rationalp z)))
544
(equal (equal (+ y1 y2 y3 (* (- c) x)) z)
545
(equal (+ y1 y2 y3) (+ (* c x) z))))
546
(implies (and (case-split (rationalp c))
547
(case-split (rationalp x))
548
(case-split (rationalp y))
549
(case-split (rationalp z)))
550
(equal (equal z (+ (* (- c) x) y))
551
(equal (+ (* c x) z) y)))
552
(implies (and (case-split (rationalp c))
553
(case-split (rationalp x))
554
(case-split (rationalp y))
555
(case-split (rationalp z)))
556
(equal (equal z (+ y (* (- c) x)))
557
(equal (+ (* c x) z) y)))
558
(implies (and (case-split (rationalp c))
559
(case-split (rationalp x))
560
(case-split (rationalp y1))
561
(case-split (rationalp y2))
562
(case-split (rationalp z)))
563
(equal (equal z (+ y1 y2 (* (- c) x)))
564
(equal (+ (* c x) z) (+ y1 y2))))
565
(implies (and (case-split (rationalp c))
566
(case-split (rationalp x))
567
(case-split (rationalp y1))
568
(case-split (rationalp y2))
569
(case-split (rationalp y3))
570
(case-split (rationalp z)))
571
(equal (equal z (+ y1 y2 y3 (* (- c) x)))
572
(equal (+ (* c x) z) (+ y1 y2 y3))))))
574
(defthm rearrange-fractional-coefs-<
576
(implies (and (case-split (rationalp c))
577
(case-split (rationalp z))
578
(case-split (rationalp x))
580
(equal (< (* (/ c) x) z)
582
(implies (and (case-split (rationalp c))
583
(case-split (rationalp z))
584
(case-split (rationalp x))
585
(case-split (rationalp y))
587
(equal (< (+ (* (/ c) x) y) z)
588
(< (+ x (* c y)) (* c z))))
589
(implies (and (case-split (rationalp c))
590
(case-split (rationalp z))
591
(case-split (rationalp x))
592
(case-split (rationalp y))
594
(equal (< (+ y (* (/ c) x)) z)
595
(< (+ (* c y) x) (* c z))))
596
(implies (and (case-split (rationalp c))
597
(case-split (rationalp z))
598
(case-split (rationalp x))
599
(case-split (rationalp y1))
600
(case-split (rationalp y2))
602
(equal (< (+ y1 y2 (* (/ c) x)) z)
603
(< (+ (* c y1) (* c y2) x) (* c z))))
604
(implies (and (case-split (rationalp c))
605
(case-split (rationalp z))
606
(case-split (rationalp x))
607
(case-split (rationalp y1))
608
(case-split (rationalp y2))
609
(case-split (rationalp y3))
611
(equal (< (+ y1 y2 y3 (* (/ c) x)) z)
612
(< (+ (* c y1) (* c y2) (* c y3) x) (* c z))))
613
(implies (and (case-split (rationalp c))
614
(case-split (rationalp z))
615
(case-split (rationalp x))
617
(equal (< z (* (/ c) x))
619
(implies (and (case-split (rationalp c))
620
(case-split (rationalp z))
621
(case-split (rationalp x))
622
(case-split (rationalp y))
624
(equal (< z (+ (* (/ c) x) y))
625
(< (* c z) (+ x (* c y)))))
626
(implies (and (case-split (rationalp c))
627
(case-split (rationalp z))
628
(case-split (rationalp x))
629
(case-split (rationalp y))
631
(equal (< z (+ y (* (/ c) x)))
632
(< (* c z) (+ (* c y) x))))
633
(implies (and (case-split (rationalp c))
634
(case-split (rationalp z))
635
(case-split (rationalp x))
636
(case-split (rationalp y1))
637
(case-split (rationalp y2))
639
(equal (< z (+ y1 y2 (* (/ c) x)))
640
(< (* c z) (+ (* c y1) (* c y2) x))))
641
(implies (and (case-split (rationalp c))
642
(case-split (rationalp z))
643
(case-split (rationalp x))
644
(case-split (rationalp y1))
645
(case-split (rationalp y2))
646
(case-split (rationalp y3))
648
(equal (< z (+ y1 y2 y3 (* (/ c) x)))
649
(< (* c z) (+ (* c y1) (* c y2) (* c y3) x))))))
651
(defthm rearrange-fractional-coefs-equal
653
(implies (and (case-split (rationalp c))
654
(case-split (rationalp z))
655
(case-split (rationalp x))
657
(equal (equal (* (/ c) x) z)
659
(implies (and (case-split (rationalp c))
660
(case-split (rationalp z))
661
(case-split (rationalp x))
662
(case-split (rationalp y))
664
(equal (equal (+ (* (/ c) x) y) z)
665
(equal (+ x (* c y)) (* c z))))
666
(implies (and (case-split (rationalp c))
667
(case-split (rationalp z))
668
(case-split (rationalp x))
669
(case-split (rationalp y))
671
(equal (equal (+ y (* (/ c) x)) z)
672
(equal (+ (* c y) x) (* c z))))
673
(implies (and (case-split (rationalp c))
674
(case-split (rationalp z))
675
(case-split (rationalp x))
676
(case-split (rationalp y1))
677
(case-split (rationalp y2))
679
(equal (equal (+ y1 y2 (* (/ c) x)) z)
680
(equal (+ (* c y1) (* c y2) x) (* c z))))
681
(implies (and (case-split (rationalp c))
682
(case-split (rationalp z))
683
(case-split (rationalp x))
684
(case-split (rationalp y1))
685
(case-split (rationalp y2))
686
(case-split (rationalp y3))
688
(equal (equal (+ y1 y2 y3 (* (/ c) x)) z)
689
(equal (+ (* c y1) (* c y2) (* c y3) x) (* c z))))))
692
(implies (and (rationalp x)
696
(equal (equal (* x (/ y)) 1)
700
(defun point-right-measure (x)
701
(floor (if (and (rationalp x) (< 0 x)) (/ x) 0) 1))
703
(defun point-left-measure (x)
704
(floor (if (and (rationalp x) (> x 0)) x 0) 1))
706
(include-book "ordinals/e0-ordinal" :dir :system)
707
(set-well-founded-relation e0-ord-<)
709
(defthm recursion-by-point-right
710
(and (e0-ordinalp (point-right-measure x))
711
(implies (and (rationalp x)
714
(e0-ord-< (point-right-measure (* 2 x))
715
(point-right-measure x)))))
717
(defthm recursion-by-point-left
718
(and (e0-ordinalp (point-left-measure x))
719
(implies (and (rationalp x)
721
(e0-ord-< (point-left-measure (* 1/2 x))
722
(point-left-measure x)))))
725
(implies (and (rationalp x)
728
(equal (< x (* x y)) (< 1 y)))
731
(defthm cancel-equal-*
732
(implies (and (rationalp r)
736
(equal (equal (* a r) (* a s))
741
(implies (and (integerp i)
743
(case-split (acl2-numberp r)) ;(integerp r)
744
(case-split (not (equal r 0)))
746
(equal (expt r (+ i j))
747
(* (expt r i) (expt r j)))))
750
(implies (and (rationalp r)
754
(equal (< (* a r) (* a s))
758
(in-theory (disable fl
760
point-right-measure point-left-measure))
763
;;;**********************************************************************
765
;;;**********************************************************************
767
(defthm expt-2-positive-rational-type
768
(and (rationalp (expt 2 i))
770
:rule-classes (:rewrite (:type-prescription :typed-term (expt 2 i))))
772
(defthm expt-2-positive-integer-type
774
(and (integerp (expt 2 i))
776
:rule-classes (:type-prescription))
778
(defthm expt-2-type-linear
781
:rule-classes ((:linear :trigger-terms ((expt 2 i)))))
783
(defthmd expt-weak-monotone
784
(implies (and (integerp n)
786
(equal (<= (expt 2 n) (expt 2 m))
789
(defthmd expt-strong-monotone
790
(implies (and (integerp n)
792
(equal (< (expt 2 n) (expt 2 m))
795
(defthmd expt-inverse
796
(equal (/ (expt 2 i))
800
(implies (integerp n)
802
(fl (* n (expt 2 i))))))
805
(implies (and (integerp m)
808
(> (* (- 1 (expt 2 m)) (- 1 (expt 2 n)))
809
(- 1 (expt 2 (1+ m)))))
813
(implies (and (integerp n)
817
(< (* (1+ (expt 2 m)) (1+ (expt 2 n)))
818
(1+ (expt 2 (+ m 2)))))
822
(implies (and (integerp n)
824
(<= (/ (- 1 (expt 2 n)))
825
(1+ (expt 2 (1+ n)))))