4
This book contains a hodgepodge of useful arithmetic rules.
5
It's still kind of a mess. But it's better now that we have the rules in common-factor.lisp.
10
(include-book "predicate")
11
(include-book "product")
12
(include-book "../../../meta/meta-times-equal")
13
(include-book "../../../meta/meta-plus-equal")
14
(include-book "../../../meta/meta-plus-lessp")
17
;get more rules from arithmetic-2 ?
22
;;=================================================================================
23
;; Collect leading constants in comparisons.
24
;; This section is complete. [what about products??]
25
;;===================================================================================
27
(defthm collect-constants-in-equal-of-sums
28
(implies (and (syntaxp (and (quotep c1) (quotep c2)))
29
(case-split (acl2-numberp c1))
31
(and (equal (equal (+ c2 x) c1)
32
(equal (fix x) (- c1 c2)))
33
(equal (equal c1 (+ c2 x))
34
(equal (fix x) (- c1 c2))))))
36
(defthm collect-constants-in-equal-of-sums-2
37
(implies (syntaxp (and (quotep c1) (quotep c2)))
38
(and (equal (equal (+ c2 x) (+ c1 y))
39
(equal (fix x) (+ (- c1 c2) y))))))
41
(defthm collect-constants-in-<-of-sums
42
(implies (syntaxp (and (quotep c1) (quotep c2)))
43
(and (equal (< (+ c2 x) c1)
45
(equal (< c1 (+ c2 x))
48
(defthm collect-constants-in-<-of-sums-2
49
(implies (syntaxp (and (quotep c1) (quotep c2)))
50
(equal (< (+ c2 x) (+ c1 y))
51
(< x (+ (- c1 c2) y)))))
54
;this book includes (how many?) main types of lemmas
56
;there's stuff in inverted-factor too
65
;rearranging negative coeffs
66
;getting rid of fractional coeffs
68
;cancelling factors in comparisons of sums (these sums may each have only 1 addend)
70
;misc lemmas (comparing products to 0)
72
;see equal-constant-+ in equalities.lisp
74
;see also see MULT-BOTH-SIDES-OF-EQUAL
75
(defthmd mult-both-sides-of-<-by-positive
76
(implies (and (<= 0 c)
80
(equal (< (* c a) (* c b))
84
(include-book "../../../meta/meta-times-equal")
85
(include-book "../../../meta/meta-plus-equal")
86
(include-book "../../../meta/meta-plus-lessp")
89
(defthm mult-both-sides-of-equal
90
(implies (and (case-split (acl2-numberp a))
91
(case-split (acl2-numberp b))
92
(case-split (acl2-numberp c))
94
(equal (equal (* a c) (* b c))
104
;instead of these, we should just cancel common factors from the constants
106
;open question: how to handle (equal (* 2 x) (* 3 y)) -- should we collect the constants or not?
107
;maybe so, since doing so would let us substitue for one of the vars (x or y).
109
;don't yet handle negative constants
110
;prefers that quotient of the constants be > 1 -perhaps we want the quotient to be < 1???
111
;maybe the constant should be by itself?
112
(defthm collect-constants-in-product-<-1-of-2-with-1-of-2
113
(implies (and (syntaxp (and (quotep c1) (quotep c2)))
120
(equal (< (* c1 a) (* c2 b))
122
(< (* (/ c1 c2) a) b)
123
(< a (* (/ c2 c1) b)))))
124
:hints (("Goal" :use ((:instance mult-both-sides-of-<-by-positive
128
(:instance mult-both-sides-of-<-by-positive
133
(defthm collect-constants-in-product-<-1-of-1-with-1-of-2
134
(implies (and (syntaxp (and (quotep c1) (quotep c2)))
140
(equal (< c1 (* c2 b))
142
:hints (("Goal" :use ((:instance mult-both-sides-of-<-by-positive
147
(defthm collect-constants-in-product-<-1-of-2-with-1-of-1
148
(implies (and (syntaxp (and (quotep c1) (quotep c2)))
154
(equal (< (* c2 b) c1)
156
:hints (("Goal" :use ((:instance mult-both-sides-of-<-by-positive
166
;generalize to acl2-numberp whenever possible
167
;make more like these!
169
;BOZO generalize this hack
171
;is this like rearrange-negative coeffs?
172
(defthm rearr-neg-eric
173
(implies (and (rationalp a)
177
(equal (EQUAL (+ a (* -1 b) c)
179
(equal (+ a c) (+ b d)))))
181
;add "equal" to the name?
184
(defthm collect-constants-with-division
185
(implies (and (syntaxp (and (quotep c1) (quotep c2)))
190
(equal (equal c1 (* c2 x))
191
(equal (/ c1 c2) x))))
194
;; ==================================================================================================
196
;;;comparing a product to 0
198
;; may cause case splits (which, for my purposes, is acceptable)
200
;; ==================================================================================================
205
;BOZO I have more rules about this in product.lisp !!!
207
;case split on the sign of A
208
(defthm prod->-0-cancel-pos
209
(implies (and (< 0 a)
216
(defthm prod-<-0-cancel-pos
217
(implies (and (< 0 a)
225
(defthm prod-<-0-cancel-neg
226
(implies (and (< a 0)
233
(defthm prod->-0-cancel-neg
234
(implies (and (< a 0)
242
;reorder to make the most likely case of the if first?
243
(defthm prod->-0-cancel
244
(implies (and (rationalp x)
254
(defthm prod-<-0-cancel
255
(implies (and (rationalp x)
265
(in-theory (disable prod-<-0-cancel-neg
268
prod->-0-cancel-pos))
274
(defthmd cancel-in-prods-<-case-x->-0
275
(implies (and (rationalp x)
279
(equal (< (* x a) (* x b))
283
(defthmd cancel-in-prods-<-case-x-<-0
284
(implies (and (rationalp x)
288
(equal (< (* x a) (* x b))
292
;changed the var names 'cause "x" was too heavy
293
;disabled, since we have a bind-free rule to cancel
294
(defthmd cancel-in-prods-<
295
(implies (and (rationalp a)
298
(equal (< (* a b) (* a c))
304
:hints (("Goal" :in-theory (enable cancel-in-prods-<-case-x-<-0
305
cancel-in-prods-<-case-x->-0)))
310
;it shouldn't be too hard to write a bind-free function for cancelling common factors; that rule could replace
311
;many of the cancelling rules below
314
;use negative-syntaxp? (or a version of it that operates on single addends only (i.e., has no '+ case)
316
(defthmd move-a-negative-coeff
317
(equal (< (+ a (* -1 b)) c)
320
;can simplify the *-1 term to have only one var
322
(defthm rearr-negative-coeffs-<-sums-blah
323
(equal (< (+ A e (* -1 C)) B)
324
(< (+ A e) (+ (* C) B)))
325
:hints (("Goal" :use (:instance
326
move-a-negative-coeff (a (+ a e)) (b (* c)) (c b)))))
328
(defthm collect-constant-mults-<-1-of-2-with-1-of-2-term-len-2
329
(implies (and (syntaxp (and (quotep c1) (quotep c2)))
336
(equal (< (+ (* c1 c d) a) (+ (* c2 c d) b))
337
(< (+ (* (- c1 c2) c d) a) b))))
340
(include-book "inverted-factor")
343
;events in :rule-classes nil which can be :used in hacks
346
(implies (and (< a b)
354
(defthm <=-transitive
355
(implies (and (<= a b)
363
;a<b and b<=c together imply a<c
364
(defthm <-and-<=-transitivity
365
(implies (and (< a b)
373
;a<=b and b<c together imply a<c
374
(defthm <=-and-<-transitivity
375
(implies (and (< a b)
384
;used only as a hack:
387
(defthm equal-transitive
388
(implies (and (equal a b)
393
;there's a conflict in my arithmetic normal forms:
394
; do we prefer (< (* 2 x) 1) or (< x 1/2) ?
397
(defthm collect-again
398
(implies (and (syntaxp (quotep k))
401
(equal (< (+ x y) (* k x))
402
(< y (* (- k 1) x)))))
406
;natp is defined here to try to make sure its always enabled
409
(declare (xargs :guard t))
413
(in-theory (enable natp))
416
(defthm two-natps-add-to-1
417
(implies (and (natp n)
419
(equal (equal 1 (+ x n))
420
(or (and (equal x 1) (equal n 0))
421
(and (equal x 0) (equal n 1))))))
426
(implies (and (<= 0 x)
428
(not (< (+ x y) 0))))
430
;improve this? make the conclusion more type-like?
431
(defthm nonneg-+-type
432
(implies (and (<= 0 x)
435
:rule-classes (:type-prescription))
437
(defthm move-negative-constant-1
438
(implies (and (syntaxp (and (quotep k) (< (cadr k) 0)))
441
(equal (equal x (+ k y))
442
(equal (+ x (- k)) y))))
444
(defthm rationalp-sum
445
(implies (rationalp k)
446
(and (equal (rationalp (+ k x))
447
(not (complex-rationalp x)))
448
(equal (rationalp (+ x k))
449
(not (complex-rationalp x))))))
452
;make rationalp-sum like this?
453
(defthm rationalp-prod
454
(implies (and (rationalp k)
455
(case-split (not (equal k 0)))
457
(and (equal (rationalp (* k x))
458
(not (complex-rationalp x)))
459
(equal (rationalp (* x k))
460
(not (complex-rationalp x))))))
462
(defthm complex-rationalp-prod
463
(implies (and (rationalp k)
464
(case-split (not (equal k 0)))
466
(and (equal (complex-rationalp (* k x))
467
(complex-rationalp x))
468
(equal (complex-rationalp (* x k))
469
(complex-rationalp x)))))
474
(implies (and (syntaxp (and (quotep k) (quotep j)))
480
(equal (< (+ y (* k x)) (* j x))
481
(< (+ (* (- k j) x) y) 0))))
484
(implies (and (syntaxp (and (quotep k) (quotep j)))
490
(equal (< (+ (* k x) y) (* j x))
491
(< (+ (* (- k j) x) y) 0))))
493
(defthm collect-another
494
(implies (and (syntaxp (and (quotep k) (quotep j)))
500
(equal (< (+ (* k x) y) (+ (* j x) z))
501
(< (+ (* (- k j) x) y) z))))
505
(defthm collect-in-<-of-sums-2
506
(implies (syntaxp (and (quotep k) (quotep j)))
507
(equal (< (+ a (* k x) d) (+ b e (* j x) f))
508
(< (+ a d) (+ b e (* (- j k) x) f)))))
510
(defthm collect-in-<-of-sums-1
511
(implies (syntaxp (and (quotep k) (quotep j)))
512
(equal (< (+ a d (* k x) y) (+ b e f z (* j x) g))
513
(< (+ a d y) (+ b e f z (* (- j k) x) g)))))
516
(defthm cancel-in-sum-equal-zero-1
517
(implies (and (rationalp y)
518
(case-split (not (equal 0 y)))
525
(equal (EQUAL 0 (+ (* Y x1)
529
(equal 0 (+ x1 (* x2 x3) x4 (* x5 x6)))))
530
:hints (("Goal" :in-theory (disable product-equal-zero)
531
:use (:instance product-equal-zero (x y) (y (+ x1 (* x2 x3) x4 (* x5 x6))))))
536
(defthm integerp-implies-not-complex-rationalp
537
(implies (integerp x)
538
(not (complex-rationalp x))))
540
;don't need this if we have frac-coeff rules?
542
(defthm <-of-two-inverses
543
(implies (and (rationalp x)
548
(equal (< (/ x) (/ y))
555
(implies (and (rationalp x)
563
;find a way to make this a rewrite rule wihtout looping?
564
(defthm tighten-integer-bound
565
(implies (and (< x (expt 2 i))
567
(case-split (natp i))
569
(<= x (+ -1 (expt 2 i))))
570
:rule-classes :linear