1
; Computational Object Inference
2
; Copyright (C) 2005-2014 Kookamara LLC
7
; 11410 Windermere Meadows
8
; Austin, TX 78759, USA
9
; http://www.kookamara.com/
11
; License: (An MIT/X11-style license)
13
; Permission is hereby granted, free of charge, to any person obtaining a
14
; copy of this software and associated documentation files (the "Software"),
15
; to deal in the Software without restriction, including without limitation
16
; the rights to use, copy, modify, merge, publish, distribute, sublicense,
17
; and/or sell copies of the Software, and to permit persons to whom the
18
; Software is furnished to do so, subject to the following conditions:
20
; The above copyright notice and this permission notice shall be included in
21
; all copies or substantial portions of the Software.
23
; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24
; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25
; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26
; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27
; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28
; FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29
; DEALINGS IN THE SOFTWARE.
1
31
; Jared: what's this file for? It's not certifiable, so I'm
2
32
; renaming it to a .lsp extension for Make compatibility
9
39
;(in-package "SUPER-IHS")
12
;; This file isolates super-ihs definitions and types. The file currently
42
;; This file isolates super-ihs definitions and types. The file currently
13
43
;; contains the following ACL2 constructs as they occur in the super-ihs book:
28
58
:hints (("Goal" :in-theory (enable logext logapp))))
30
60
(defthm logext-when-i-is-zero
31
(equal (logext size 0)
61
(equal (logext size 0)
33
:hints (("goal" :in-theory (e/d (logext
63
:hints (("goal" :in-theory (e/d (logext
38
68
(defthm logext-when-size-is-not-an-integerp
156
186
:hints (("Goal" :in-theory (enable logcdr))))
158
188
(defthmd logcdr-of-zero
161
191
:hints (("goal" :in-theory (enable logcdr ifix))))
163
193
(defthm logcdr-when-i-is-not-an-integerp
164
194
(implies (not (integerp i))
167
197
:hints (("goal" :in-theory (enable logcdr ifix))))
170
200
(defthm logcdr-greater-than-0-rewrite
171
(equal (< 0 (logcdr x))
201
(equal (< 0 (logcdr x))
172
202
(and (integerp x)
250
280
(equal (logcdr (expt 2 n))
251
281
(expt 2 (1- n))))
252
282
:hints (("goal" :in-theory (enable logcdr))))
254
284
(defthm logcdr---expt
255
285
(implies (and (integerp n)
257
287
(equal (logcdr (- (expt 2 n)))
260
290
(- (expt 2 (1- n))))))
261
291
:hints (("goal" :in-theory (enable logcdr))))
263
293
(defthm logcdr-+2
264
294
(implies (integerp x)
265
(equal (logcdr (+ 2 x))
295
(equal (logcdr (+ 2 x))
266
296
(1+ (logcdr x))))
267
297
:hints (("goal" :in-theory (enable logcdr))))
570
600
(defthm logapp-when-size-is-not-an-integerp
571
601
(implies (not (integerp size))
572
(equal (logapp size i j)
602
(equal (logapp size i j)
574
604
:hints (("Goal" :in-theory (enable logext
577
607
(defthm logapp-when-size-is-negative
578
608
(implies (< size 0)
579
(equal (logapp size i j)
609
(equal (logapp size i j)
581
611
:hints (("Goal" :in-theory (enable logext
674
704
in Acl2. In particular, we prove the following theorem:
676
706
(defthm convergence-of-iter-sqrt
677
(implies (and (rationalp x)
707
(implies (and (rationalp x)
678
708
(rationalp epsilon)
723
753
(local (in-theory (enable (force)))) ;unfortunate that i had to do this
725
(local (in-theory (disable distributivity-alt)))
755
(local (in-theory (disable distributivity-alt)))
727
757
;(include-book (:relative :back "arithmetic" "top")
728
758
; :load-compiled-file nil)
1284
1314
(cond ((or (zip m) (zp n)) x)
1285
1315
((< m 0) (loglist-ashr (1+ m) n (logcdr x)))
1286
1316
(t (loglist-ashr (1- m) (1- n) x))))
1288
1318
(defthm loglist-ash-induction t
1289
1319
:rule-classes ((:induction :pattern (loglistr n (ash x m))
1438
1468
(unsigned-byte-p n (+ p (* 4 x))))
1439
1469
:hints (("Goal" :in-theory (e/d (logapp) ( UNSIGNED-BYTE-P-LOGAPP))
1440
:use (:instance UNSIGNED-BYTE-P-LOGAPP (size n) (size1 2) (i p) (j x)))))
1470
:use (:instance UNSIGNED-BYTE-P-LOGAPP (size n) (size1 2) (i p) (j x)))))
1442
1472
;; ;drop??? see next lemma
1443
1473
;; (defthmd logcdr-all-ones-lemma
1489
1519
(< x (expt 2 (+ -1 n)))))
1490
1520
:hints (("Goal" :in-theory (disable LOGBITP-TO-BOUND-WHEN-USB)
1491
1521
:use (:instance logbitp-to-bound-when-usb))))
1493
1523
(defthm logand-non-negative
1494
1524
(implies (or (<= 0 x) (<= 0 y))
1495
1525
(<= 0 (logand x y)))
1668
1698
(equal (loghead-30-exec i)
1669
1699
(loghead 30 i))
1670
1700
:hints (("Goal" :in-theory (enable loghead-30-exec))))
1672
1702
(defund logbitp-30-exec (j)
1673
1703
(declare (type (unsigned-byte 31) j))
1674
1704
(not (equal 0 (logand 1073741824 j))))
1794
1824
(equal (oddp (expt 2 j))
1795
1825
(or (not (integerp j))
1797
:hints (("Goal" :in-theory (enable oddp
1827
:hints (("Goal" :in-theory (enable oddp
1798
1828
expt ;improve evenp rule and drop
1799
1829
EXPONENTS-ADD-UNRESTRICTED))))
1801
1831
;consider adding (disabled!) versions of these without the backchain-limits?
1802
(defthmd even-odd-different-1
1832
(defthmd even-odd-different-1
1803
1833
(implies (and (evenp a)
1804
1834
(not (evenp b)))
1805
1835
(not (equal a b)))
1808
1838
;bzo do we need both of these rules?
1809
1839
;consider adding (disabled!) versions of these without the backchain-limits?
1810
(defthmd even-odd-different-2
1840
(defthmd even-odd-different-2
1811
1841
(implies (and (not (evenp a))
1813
1843
(not (equal a b)))
1891
1921
(defthm equal-i+-*2
1892
(implies (and (integerp a)
1922
(implies (and (integerp a)
1896
1926
(not (evenp i)))
1897
1927
(equal (equal (expt 2 a) (+ i (* 2 b)))
1898
1928
(and (zp a) (equal b (- (* 1/2 (+ -1 i)))))))
1899
1929
:hints (("Goal" :in-theory (enable even-odd-different-2 even-odd-different-1))))
1901
1931
(defthm equal-i+-+-*2-*2
1902
(implies (and (integerp a)
1932
(implies (and (integerp a)
2167
2197
(declare (type (signed-byte 32) a)
2168
2198
(type (signed-byte 32) b)
2169
2199
(type (signed-byte 32) c))
2174
2204
;; We want to open c_conditional when the test value is a constant, since in
2329
2359
(local (in-theory (enable FALSIFY-UNSIGNED-BYTE-P)))
2331
;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;
2361
;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;
2332
2362
;; signed-byte-p, unsigned-byte-p
2333
2363
;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;
2384
2414
(equal (signed-byte-p n x)
2387
2417
:in-theory (enable signed-byte-p unsigned-byte-p)
2388
2418
:use ((:instance EXPT-IS-INCREASING-FOR-BASE>1
2391
2421
(j (1- n)))))))
2393
2423
(defthm unsigned-byte-p-subtype
2394
2424
(implies (and (unsigned-byte-p free x) ;free is a free variable
2397
2427
(equal (unsigned-byte-p n x)
2401
2431
:in-theory (enable signed-byte-p unsigned-byte-p)
2402
2432
:use ((:instance EXPT-IS-INCREASING-FOR-BASE>1
2528
2558
;; :hints (("Goal" :in-theory (disable signed-byte-p-of-shift)
2529
2559
;; :use ((:instance signed-byte-p-of-shift)
2530
2560
;; (:instance signed-byte-p-of-shift (x (- x)))))))
2534
2564
;; :hints (("Goal" ; :induct (logcdr-induction x)
2535
2565
;; ;:nonlinearp t
2536
2566
;; :cases ((< x 0))
2537
;; :in-theory (enable ;lrdt
2567
;; :in-theory (enable ;lrdt
2538
2568
;; SIGNED-BYTE-P
2539
2569
;; EXPONENTS-ADD-UNRESTRICTED
2544
2574
(defthm unsigned-byte-p-1+
2560
2590
(unsigned-byte-p 1 c))
2561
2591
(unsigned-byte-p n (+ c x y)))
2562
2592
:rule-classes nil
2563
:hints (("goal" :in-theory (e/d (unsigned-byte-p EXPONENTS-ADD-UNRESTRICTED)
2593
:hints (("goal" :in-theory (e/d (unsigned-byte-p EXPONENTS-ADD-UNRESTRICTED)
2564
2594
(unsigned-byte-p-+)))))
2566
2596
(defthm unsigned-byte-p-+-bridge
2698
2728
;; (unsigned-byte-p (- n) (nth n1 (nth n2 x))))
2699
2729
;; (equal (ash (nth n1 (nth n2 x)) n) 0)))
2700
;; :hints (("goal" :use (:instance ASH-GOES-TO-0
2730
;; :hints (("goal" :use (:instance ASH-GOES-TO-0
2708
2738
:hints (("goal" :in-theory (enable ash
2881
2911
(not (logbitp n (+ y x)))))
2882
2912
:hints (("goal" :use (:instance logbitp-+-usb-v4-helper (c 0)))))
2884
;; (deftheory overflow-bits
2885
;; '(logbitp-+-usb-v4
2889
;; logbitp-+-simple2
2914
;; (deftheory overflow-bits
2915
;; '(logbitp-+-usb-v4
2919
;; logbitp-+-simple2
2890
2920
;; logbitp-+-simple
2891
2921
;; unsigned-byte-p-+))
2893
2923
(in-theory (disable ;overflow-bits
2899
2929
logbitp-+-simple
2900
2930
unsigned-byte-p-+))
3005
3035
(logbitp n1 (+ x z y)))
3006
3036
(equal (logbitp n1 (+ x (loghead n2 y) z))
3007
3037
(logbitp n1 (+ x y z)))))))
3008
:hints (("goal" :use
3038
:hints (("goal" :use
3009
3039
((:instance logbitp-+-loghead-helper (c 0))
3010
3040
(:instance logbitp-+-loghead-helper (c 0) (x (+ x z)))))))
3012
3042
(defthm logbitp-+-logext-bridge
3013
3043
(implies (and (integerp n1)
3125
3155
(defthm negate-as-bits-reverse
3126
3156
(implies (integerp x)
3127
(equal (1+ (lognot x))
3157
(equal (1+ (lognot x))
3129
3159
:hints (("goal" :in-theory (enable LRDT logendp))))
3131
3161
(defthm negate-as-bits-reverse-bridge
3132
3162
(implies (and (integerp x)
3134
(equal (+ 1 x (lognot y))
3164
(equal (+ 1 x (lognot y))
3137
3167
:use (:instance negate-as-bits-reverse (x y))
3138
3168
:in-theory (disable negate-as-bits-reverse))))
3372
3402
(implies (and (< m n)
3377
3407
(equal (logext n (ash x m))
3378
3408
(ash (logext (- n m) x) m)))
3379
3409
:hints (("goal"; :induct t
3380
:in-theory (e/d (LRDT) (ASH-RECOLLAPSE
3410
:in-theory (e/d (LRDT) (ASH-RECOLLAPSE
3383
3413
(defthm logext-logior
3390
3420
(logext n (logior x y))))
3392
3422
(theory-invariant (incompatible (:rewrite logext-logior) (:rewrite logior-of-logext-and-logext)))
3394
3424
;; This should be in the loghead section, but it uses so many logext
3395
3425
;; rules we place it here.
3461
3491
;; (defthm logtail-logext-hack
3462
3492
;; (equal (logtail 16 (logext 32 x))
3463
3493
;; (logext 16 (logtail 16 x)))
3464
;; :hints (("Goal" :in-theory (enable ;logtail
3494
;; :hints (("Goal" :in-theory (enable ;logtail
3465
3495
;; logext ifix))))
3467
3497
;We make this a separate rule so it will be enabled even when logext-logapp is disabled.
3549
3579
(equal n (1+ m)))
3550
3580
(equal (ash (logext n x) (- m))
3551
3581
(if (logbitp m x) -1 0)))
3552
:hints (("goal" :use (:instance ash-sbp-downto-1-or-0-helper
3582
:hints (("goal" :use (:instance ash-sbp-downto-1-or-0-helper
3554
3584
(x (logext n x))))))
3556
3586
(defthm ash-sbp-downto-1-or-0-bridge
3560
3590
(unsigned-byte-p n y))
3561
3591
(equal (ash (+ x (- y)) (- n))
3562
3592
(if (logbitp n (+ x (- y))) -1 0)))
3563
:hints (("goal" :use (:instance ash-sbp-downto-1-or-0-helper
3593
:hints (("goal" :use (:instance ash-sbp-downto-1-or-0-helper
3564
3594
(x (+ x (- y))))
3565
3595
:in-theory (enable unsigned-byte-p signed-byte-p))))
3569
3599
;; Needed just for the FCP models?
3570
3600
(defthm equal-ash-expt-0-fact
3571
(implies (and (integerp n)
3601
(implies (and (integerp n)
3574
3604
(equal (equal (ash (+ x (expt 2 n)) (- n)) 0)
3606
3636
(unsigned-byte-p n y))
3607
3637
(equal (ash (+ k x (- y)) (- n))
3608
3638
(if (logbitp n (+ x (- y))) 0 1)))
3609
:hints (("goal" :use (:instance ash-sbp-expt-downto-1-or-0-helper
3639
:hints (("goal" :use (:instance ash-sbp-expt-downto-1-or-0-helper
3610
3640
(x (+ x (- y)))))))
3612
3642
(defthm equal-ash-+---expt--1
3613
3643
(implies (and (integerp n)
3615
3645
(signed-byte-p (1+ n) x))
3616
3646
(equal (equal (ash (+ x (- (expt 2 n))) (- n)) -1)
3617
3647
(not (logbitp n x))))
3618
3648
:hints (("goal" :in-theory (enable LRDT expt))))
3620
3650
(defthm equal-ash-+---expt--1-rewrite
3621
(implies (and (syntaxp (quotep k)) (integerp k)
3651
(implies (and (syntaxp (quotep k)) (integerp k)
3622
3652
(equal (- (expt 2 (1- (integer-length (- k))))) k)
3623
3653
(equal n (1- (integer-length (- k))))
3624
3654
(signed-byte-p (1+ n) x))
3625
3655
(equal (equal (ash (+ k x) (- n)) -1)
3626
3656
(not (logbitp n x))))
3627
:hints (("goal" :use (:instance equal-ash-+---expt--1
3657
:hints (("goal" :use (:instance equal-ash-+---expt--1
3628
3658
(n (1- (integer-length (- k))))))))
3630
3660
(defthm ash-logext-neg
3678
(equal (ash x (- n))
3708
(equal (ash x (- n))
3680
3710
; :rule-classes nil
3682
3712
:induct (logbitp n x)
3683
3713
:in-theory (enable LRDT logbit))))
3684
3714
;; :induct (sub1-logcdr-induction n x)
3685
3715
;; :in-theory (enable LOGOPS-RECURSIVE-DEFINITIONS-THEORY logbit))))
3687
3717
;; (defthm ash--15-special
3689
3719
;; (unsigned-byte-p 16 x)
3724
3754
(equal (< (+ (logext n x) (logext n y)) 0)
3725
3755
(logbitp n (+ (logext n x) (logext n y)))))
3726
:hints (("goal" :use (:instance sign-as-logbitp
3756
:hints (("goal" :use (:instance sign-as-logbitp
3727
3757
(x (+ (logext n x) (logext n y)))))))
3729
3759
(defthm sign-logext-as-logbitp
3951
3981
(in-theory (enable natp))
3953
3983
;since UNSIGNED-BYTE-P-FORWARD-TO-NONNEGATIVE-INTEGERP is built into acl2 and we have acl2::unsigned-byte-p-forward-to-expt-bound:
3954
(in-theory (disable ACL2::UNSIGNED-BYTE-P-FORWARD))
3956
(local (in-theory (enable FALSIFY-UNSIGNED-BYTE-P)))
3984
(in-theory (disable ACL2::UNSIGNED-BYTE-P-FORWARD))
3986
(local (in-theory (enable FALSIFY-UNSIGNED-BYTE-P)))
3959
3989
; (:REWRITE ZP-OPEN)
3960
3990
; (:REWRITE ZIP-OPEN)
4006
4036
; (:REWRITE <-0-+-NEGATIVE-2)
4007
4037
; (:REWRITE <-+-NEGATIVE-0-1)
4008
4038
; (:REWRITE <-+-NEGATIVE-0-2)
4009
;dsh Removed for ACL2 2.9.2, where NATP-CR and POSP-CR no longer exist.
4039
;dsh Removed for ACL2 2.9.2, where NATP-CR and POSP-CR no longer exist.
4010
4040
; This change doesn't appear to affect proofs under ACL2 2.9.
4011
4041
; (:COMPOUND-RECOGNIZER NATP-CR)
4012
4042
; (:COMPOUND-RECOGNIZER POSP-CR)
4867
4897
(implies (syntaxp (not (quotep x))) ;without the not-quotep test, the rule matches things like: (< -1 x)
4868
4898
(equal (< (- x) y)
4869
4899
(< 0 (+ x y)))))
4871
4901
(defthm move-negated-term-to-other-side-of-<-term-1-on-rhs
4872
4902
(implies (syntaxp (not (quotep y))) ;without the not-quotep test, the rule matches things like: (< x -1) ?
4873
4903
(equal (< x (- y))
5052
5082
:in-theory (disable acl2::integerp-expt))))
5054
5084
(defthm integerp-prod-of-3-first-two
5055
(implies (and (integerp (* a b))
5085
(implies (and (integerp (* a b))
5057
5087
(integerp (* a b c)))
5058
5088
:hints (("Goal" :in-theory (disable acl2::integerp-+-minus-*-4)
5192
5222
(if (< (nfix size1) (nfix size))
5193
5223
(loghead (nfix size1) i)
5194
5224
(loghead (nfix size) i)))
5195
:hints (("Goal" :in-theory (e/d ()
5225
:hints (("Goal" :in-theory (e/d ()
5196
5226
(loghead-loghead
5198
5228
:use loghead-loghead)))
5200
(in-theory (disable loghead-loghead))
5230
(in-theory (disable loghead-loghead))
5202
5232
(defthm loghead-does-nothing-rewrite
5203
5233
(equal (equal (loghead n x) x)
5228
5258
(equal (logcar (loghead size i))
5229
5259
(if (or (not (integerp size))
5234
5264
(("Goal" :use logcar-loghead
5235
5265
:in-theory (e/d (
5237
5267
(logcar-loghead)))))
5239
(in-theory (disable logcar-loghead))
5269
(in-theory (disable logcar-loghead))
5270
5300
:hints (("Goal" :use (:instance loghead-+-cancel)
5271
5301
:in-theory (disable loghead-+-cancel))))
5273
(in-theory (disable loghead-+-cancel))
5303
(in-theory (disable loghead-+-cancel))
5275
5305
;make more versions of this
5276
5306
;bzo normalize the leading constant of things like (LOGHEAD 16 (+ 65535 x)).
5311
5341
(loghead size (+ i1 i2 j))
5312
5342
(loghead size (+ i1 i2))))
5313
5343
:hints (("Goal" :use (:instance loghead-+-loghead-better (i (+ i1 i2)) (j j)))))
5315
5345
; improve loghead-cancel-better-alt, etc.
5316
5346
(defthm loghead-sum-subst-helper
5317
5347
(implies (and (equal (loghead n x) y)
5385
5415
(EQUAL (LOGHEAD size (+ j A)) (LOGHEAD size K))))
5386
5416
:hints (("Goal" :use (:instance LOGHEAD-+-CANCEL-BETTER (size size) (i j) (j a) (k (- k j)))))
5389
5419
(defthm loghead-plus-constant-equal-constant
5390
5420
(implies (and (syntaxp (and (quotep j)
5634
5664
(+ (loghead n i) (loghead n j))
5635
5665
(+ (loghead n i) (loghead n j) (- (expt 2 n))))))
5636
5666
:hints (("Goal" :in-theory (disable loghead-split-into-2-cases)
5637
:use (:instance loghead-split-into-2-cases
5667
:use (:instance loghead-split-into-2-cases
5639
5669
(x (+ (loghead n i) (loghead n j)))
5695
5725
;; :do-not-induct t
5696
5726
;; :in-theory (e/d (loghead-sum-split-into-2-cases
5697
5727
;; ;UNSIGNED-BYTE-P-FORWARD-TO-NONNEGATIVE-INTEGERP
5699
5729
;; (LOGHEAD-TYPE ;bzo these disables are gross!
5700
5730
;; loghead-identity
5701
5731
;; LOGHEAD-DOES-NOTHING-REWRITE
5702
5732
;; UNSIGNED-BYTE-P-LOGHEAD-FORWARD-CHAINING)))))
5704
5734
(defthm loghead-cancel-lemma
5705
5735
(implies (and (integerp a)
5706
5736
(integerp size)
5767
5797
(defthmd loghead-hack2
5768
5798
(implies (and (equal (expt 2 n) (+ (loghead n a) (loghead n b)))
5772
5802
(equal (loghead n (+ a b))
5774
5804
:hints (("Goal" :in-theory (enable loghead-sum-split-into-2-cases))))
5776
5806
;; Allows ACL2 to quicly see that facts like this contradict:
5777
5807
;; (EQUAL x (LOGHEAD 16 (+ 4 y)))
5778
5808
;; (EQUAL (LOGHEAD 16 (+ 3 x)) y))
5855
5885
:hints (("Goal" :use (:instance acl2::loghead-+-cancel-0 (acl2::i i) (acl2::j j) (acl2::size size))
5856
5886
:in-theory (disable acl2::loghead-+-cancel-0))))
5858
(in-theory (disable acl2::loghead-+-cancel-0))
5888
(in-theory (disable acl2::loghead-+-cancel-0))
5860
5890
(defthm loghead-+-cancel-0-alt
5861
5891
(implies (and (integerp m)
5895
5925
(equal (equal x (loghead n (+ b y)))
5897
5927
:hints (("Goal" :use (:instance acl2::loghead-cancel-lemma-3 (acl2::n n) (acl2::b b) (acl2::x x) (acl2::a a))
5898
:in-theory (disable acl2::loghead-cancel-lemma-3))))
5928
:in-theory (disable acl2::loghead-cancel-lemma-3))))
6137
6167
(("Goal" :in-theory (e/d (
6138
6168
; LOGHEAD-WITH-SIZE-NON-POSITIVE
6140
6170
(logextu-as-loghead))
6141
6171
:use logextu-as-loghead)))
6143
6173
(defthm logand-bit-0
6144
6174
(implies (unsigned-byte-p 1 x)
6146
6176
(b-and x (logcar y))))
6147
6177
:hints (("goal" :in-theory (e/d (LRDT logand-zip) (LOGHEAD* logand*))))
6148
6178
:rule-classes ((:rewrite :backchain-limit-lst 1)))
6201
6231
:hints (("Goal" :in-theory (enable integer-length))))
6203
6233
(defthm logand-expt-constant-version
6204
(implies (and (syntaxp (quotep n))
6234
(implies (and (syntaxp (quotep n))
6205
6235
(equal (expt 2 (1- (integer-length n))) n)
6207
6237
(equal (logand n x)
6221
6251
;just use logand-expt-constant-version?
6222
6252
(defthm equal-logand-expt-rewrite
6223
(implies (and (syntaxp (quotep n))
6253
(implies (and (syntaxp (quotep n))
6224
6254
(equal (expt 2 (1- (integer-length n))) n)
6227
6257
(equal (equal (logand n x) k)
6228
(if (logbitp (1- (integer-length n)) x)
6258
(if (logbitp (1- (integer-length n)) x)
6232
6262
:in-theory (e/d (LRDT) (logand*))
6233
:use (:instance equal-logand-expt
6263
:use (:instance equal-logand-expt
6234
6264
(n (1- (integer-length n)))))))
6236
6266
(defthm logand---expt
6239
6269
(signed-byte-p (1+ n) x))
6240
6270
(equal (logand (- (expt 2 n)) x)
6241
6271
(if (logbitp n x) (- (expt 2 n)) 0)))
6243
6273
:in-theory (enable LRDT expt2* ash open-logcons))))
6245
6275
(defthm logand---expt-rewrite
6246
(implies (and (syntaxp (quotep k))
6276
(implies (and (syntaxp (quotep k))
6248
6278
(equal (- (expt 2 (1- (integer-length (- k))))) k)
6249
6279
(signed-byte-p (integer-length (- k)) x))
6250
6280
(equal (logand k x)
6290
6320
:hints (("goal" :in-theory (enable LRDT))))
6292
6322
(defthm logand-bfix
6293
(and (equal (logand (bfix x) y)
6323
(and (equal (logand (bfix x) y)
6294
6324
(b-and (bfix x) (logcar y)))
6295
(equal (logand y (bfix x))
6325
(equal (logand y (bfix x))
6296
6326
(b-and (bfix x) (logcar y)))))
6298
6328
(defthm *ash*-equal-logand-ash-pos-0
6325
6355
(equal (- (expt 2 (1- (integer-length (- k))))) k))
6326
6356
(equal (equal k (logand k x))
6327
6357
(equal (ash x (- (1- (integer-length (- k))))) -1)))
6329
:use (:instance *ash*-equal-logand---expt---expt-helper
6359
:use (:instance *ash*-equal-logand---expt---expt-helper
6330
6360
(n (1- (integer-length (- k))))))))
6332
6362
(defthm logand---expt-v2
6338
6368
:hints (("goal" :in-theory (enable LRDT expt2*))))
6340
6370
(defthm logand---expt-rewrite-v2
6341
(implies (and (syntaxp (quotep k))
6371
(implies (and (syntaxp (quotep k))
6343
6373
(equal (- (expt 2 (1- (integer-length (- k))))) k)
6344
6374
(unsigned-byte-p (integer-length (- k)) x))
6345
6375
(equal (logand k x)
6346
(if (logbitp (1- (integer-length (- k))) x)
6347
(expt 2 (1- (integer-length (- k))))
6376
(if (logbitp (1- (integer-length (- k))) x)
6377
(expt 2 (1- (integer-length (- k))))
6349
:hints (("goal" :use (:instance logand---expt-v2
6379
:hints (("goal" :use (:instance logand---expt-v2
6350
6380
(n (1- (integer-length (- k))))))))
6352
6382
(defthm equal-logand---expt-0
6357
6387
(unsigned-byte-p n x)))
6358
6388
:hints (("goal"
6359
6389
:in-theory (e/d (LRDT)
6361
logand---expt-rewrite-v2
6391
logand---expt-rewrite-v2
6362
6392
logand---expt)))))
6364
6394
(defthm equal-logand---expt-0-rewrite
6365
6395
(implies (and (integerp x)
6366
(syntaxp (quotep k)) (integerp k)
6396
(syntaxp (quotep k)) (integerp k)
6367
6397
(equal (- (expt 2 (1- (integer-length (- k))))) k))
6368
6398
(equal (equal (logand k x) 0)
6369
6399
(unsigned-byte-p (1- (integer-length (- k))) x)))
6370
:hints (("goal" :use (:instance equal-logand---expt-0
6400
:hints (("goal" :use (:instance equal-logand---expt-0
6371
6401
(n (1- (integer-length (- k))))))))
6373
6403
;see from-rtl.lisp for more stuff about logand (and perhaps other functions...)
6432
6462
(equal (logbitp n (logcdr y))
6433
6463
(logbitp (+ 1 n) y)))
6434
6464
:hints (("Goal" :do-not '(generalize eliminate-destructors)
6435
:in-theory (e/d (logbitp
6465
:in-theory (e/d (logbitp
6437
exponents-add-unrestricted)
6467
exponents-add-unrestricted)
6438
6468
(FLOOR-OF-SHIFT-RIGHT-2)))))
6440
6470
;similarly for logtail?
6470
6500
(equal (equal (logior y z) x)
6471
6501
(and (logbitp (1- (integer-length x)) (logior y z))
6472
6502
(equal 0 (logand (lognot x) (logior y z))))))
6474
:do-not '(;generalize eliminate-destructors
6504
:do-not '(;generalize eliminate-destructors
6475
6505
; fertilize ;bzo. why didn't it fertilize completely?
6477
:in-theory (e/d (LRDT
6478
even-odd-different-2
6507
:in-theory (e/d (LRDT
6508
even-odd-different-2
6479
6509
even-odd-different-1
6481
6511
EQUAL-B-NOT-LOGCAR
6484
6514
(integer-length*
6550
6580
(if (equal (logcar x) 0)
6551
6581
(ash (loghead (1+ m) (1+ x)) (1- n))
6552
6582
(ash (loghead (1+ m) x) (1- n)))))
6553
:hints (("goal" :use (:instance logior-expt-ash-loghead-bridge-helper
6583
:hints (("goal" :use (:instance logior-expt-ash-loghead-bridge-helper
6554
6584
(n (integer-length v))))))
6556
6586
(defthm logior-expt-ash-loghead-bridge-bridge
6604
6634
(unsigned-byte-p n v)
6605
6635
(not (unsigned-byte-p n (+ v a))))
6606
6636
(equal (+ v (logior a (ash x n)))
6607
(logior (loghead n (+ v a))
6637
(logior (loghead n (+ v a))
6608
6638
(ash (1+ x) n))))
6609
6639
:hints (("goal" :in-theory (e/d (logior-as-+
6638
6668
(defthm logior-duplicate
6642
6672
:induct (logcdr-induction x)
6643
:in-theory (enable LRDT zip
6673
:in-theory (enable LRDT zip
6646
6676
;add to rtl library?
6647
6677
(defthm logior-duplicate-1
6648
(equal (logior x x y)
6678
(equal (logior x x y)
6651
6681
:in-theory (e/d () ( logior-associative))
6652
6682
:use ((:instance logior-associative
6670
6700
;; ;; moved to logcar
6671
6701
;; ;; (defthm logcar-logxor
6672
;; ;; (implies (and (integerp a)
6702
;; ;; (implies (and (integerp a)
6673
6703
;; ;; (integerp b))
6674
;; ;; (equal (logcar (logxor a b))
6704
;; ;; (equal (logcar (logxor a b))
6675
6705
;; ;; (b-xor (logcar a) (logcar b))))
6676
6706
;; ;; :hints (("goal" :in-theory (enable
6677
6707
;; ;; LOGOPS-RECURSIVE-DEFINITIONS-THEORY
6678
6708
;; ;; simplify-bit-functions))))
6680
6710
;; (defthm logxor-lognot
6681
;; (implies (and (integerp a)
6711
;; (implies (and (integerp a)
6682
6712
;; (integerp b))
6683
6713
;; (and (equal (logxor (lognot a) b) (lognot (logxor a b)))
6684
6714
;; (equal (logxor a (lognot b)) (lognot (logxor a b)))))
6686
6716
;; :in-theory (enable LRDT simplify-bit-functions))))
6690
6720
;; (defthm logxor-cancel2
6691
;; (implies (and (integerp a)
6721
;; (implies (and (integerp a)
6692
6722
;; (integerp b))
6693
6723
;; (equal (logxor b (logxor b a)) a))
6694
6724
;; :hints (("goal" :use (:instance commutativity-of-logxor
6829
6859
(equal (logapp n (logior w y) (logior x z))
6830
6860
(logior (logapp n w x) (logapp n y z))))
6831
:hints (("goal" :in-theory (enable LRDT))))
6861
:hints (("goal" :in-theory (enable LRDT))))
6833
6863
(defthm logapp-logand
6834
6864
(implies (and (integerp w)
7006
7036
(local (in-theory (disable UNSIGNED-BYTE-P-OF-LOGCDR))) ;this doesn't play well with LRDT
7008
7038
(defthm equal-loghead-lognot-all-ones
7009
(implies (and (integerp n)
7039
(implies (and (integerp n)
7012
7042
(equal (equal (loghead n (lognot x)) (1- (expt 2 n)))
7063
7093
(equal (loghead n (logxor x y))
7064
7094
(logxor (loghead n x) (loghead n y))))
7065
:hints (("goal" :in-theory (enable LRDT))))
7095
:hints (("goal" :in-theory (enable LRDT))))
7067
7097
(defthm loghead-lognot-loghead
7068
7098
(implies (and (integerp n1)
7073
7103
(equal (loghead n1 (lognot (loghead n2 x)))
7074
7104
(loghead n1 (lognot x))))
7076
:in-theory (e/d (LRDT logendp) (LOGHEAD-OF-MINUS
7106
:in-theory (e/d (LRDT logendp) (LOGHEAD-OF-MINUS
7078
7108
;:induct (sub1-sub1-logcdr-induction n2 n1 x))))
7125
7155
:hints (("Goal" :use (:instance loghead-logapp (size (ifix size)))
7126
7156
:in-theory (disable loghead-logapp))))
7128
(in-theory (disable loghead-logapp))
7158
(in-theory (disable loghead-logapp))
7130
7160
(defthmd logtail-loghead-better
7131
7161
(equal (logtail size1 (loghead size i))
7134
7164
:hints (("Goal" :use (:instance logtail-loghead)
7135
7165
:in-theory (disable logtail-loghead))))
7137
(in-theory (disable logtail-loghead))
7167
(in-theory (disable logtail-loghead))
7139
7169
(defthm loghead-logtail
7140
7170
(equal (loghead i (logtail j x))
7160
7190
:hints (("Goal" :use (:instance logtail-logapp)
7161
7191
:in-theory (disable logtail-logapp))))
7163
(in-theory (disable logtail-logapp))
7193
(in-theory (disable logtail-logapp))
7165
7195
;move to logapp.lisp?
7166
7196
(defthm associativity-of-logapp-better
7174
7204
:hints (("Goal" :use (:instance associativity-of-logapp)
7175
7205
:in-theory (disable associativity-of-logapp))))
7177
(in-theory (disable associativity-of-logapp))
7207
(in-theory (disable associativity-of-logapp))
7179
7209
;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;
7181
7211
;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;
7217
7247
(equal (logtail n (lognot x))
7218
7248
(lognot (logtail n x))))
7220
7250
:in-theory (disable logapp-lognot)
7221
7251
:use ((:instance logapp-lognot
7222
7252
(x (loghead n x))
7223
7253
(y (logtail n x)))))))
7225
7255
(defthm logcar-lognot
7226
(equal (logcar (lognot a))
7256
(equal (logcar (lognot a))
7227
7257
(b-not (logcar a)))
7228
7258
:hints (("Goal" :in-theory (enable logops-recursive-definitions-theory))))
7258
(equal (logcar (ash x n))
7288
(equal (logcar (ash x n))
7259
7289
(logbit (- n) x)))
7260
7290
:hints (("goal" :in-theory (e/d (LRDT logbit) (logtail* ;was forcing
7263
7293
(defthm logcar-ash-both
7264
7294
(implies (integerp n)
7265
(equal (logcar (ash x n))
7295
(equal (logcar (ash x n))
7268
7298
(logbit (- n) x))))
7348
7378
(defthm logcdr-+1
7349
7379
(implies (integerp x)
7350
7380
(and (implies (equal (logcar x) 0)
7351
(equal (logcdr (+ 1 x))
7381
(equal (logcdr (+ 1 x))
7353
7383
(implies (equal (logcar x) 1)
7354
(equal (logcdr (+ 1 x))
7384
(equal (logcdr (+ 1 x))
7355
7385
(+ 1 (logcdr x))))
7356
7386
(implies (and (integerp y)
7357
7387
(equal (logcar x) 1))
7358
(equal (logcdr (+ 1 x y))
7388
(equal (logcdr (+ 1 x y))
7359
7389
(+ 1 (logcdr x) (logcdr y))))
7360
7390
(implies (and (integerp y)
7361
7391
(equal (logcar x) 1))
7362
(equal (logcdr (+ 1 y x))
7392
(equal (logcdr (+ 1 y x))
7363
7393
(+ 1 (logcdr x) (logcdr y))))))
7364
7394
:hints (("Goal" :in-theory (enable logcons))))
7366
7396
(defthm logcdr-+3
7367
7397
(and (implies (and (integerp x)
7368
7398
(equal (logcar x) 0))
7369
(equal (logcdr (+ 3 x))
7399
(equal (logcdr (+ 3 x))
7370
7400
(+ 1 (logcdr x))))
7371
7401
(implies (and (integerp x)
7372
7402
(equal (logcar x) 1))
7373
(equal (logcdr (+ 3 x))
7403
(equal (logcdr (+ 3 x))
7374
7404
(+ 2 (logcdr x)))))
7375
7405
:hints (("goal" :in-theory (enable logcar logcdr))))
7384
7414
(implies (and (integerp n)
7387
(equal (logcdr (logext n x))
7417
(equal (logcdr (logext n x))
7388
7418
(logext (1- n) (logcdr x))))
7389
7419
:hints (("goal" :in-theory (enable LRDT))))
7391
7421
(defthm logcdr-bitop
7392
7422
(and (equal (logcdr (b-and x y)) 0)
7393
7423
(equal (logcdr (b-ior x y)) 0)
7427
7457
(in-theory (disable logtail))
7429
7459
(defthm logtail-when-i-is-zero
7430
(equal (logtail pos 0)
7460
(equal (logtail pos 0)
7432
7462
:hints (("Goal" :in-theory (enable logtail))))
7434
(in-theory (disable logtail-size-0))
7464
(in-theory (disable logtail-size-0))
7436
7466
(defthm logtail-when-i-is-not-an-integerp
7437
7467
(implies (not (integerp i))
7438
(equal (logtail pos i)
7468
(equal (logtail pos i)
7441
7471
(("Goal" :in-theory (enable logtail))))
7443
7473
(defthm logtail-when-pos-is-not-positive
7444
7474
(implies (<= pos 0)
7445
(equal (logtail pos i)
7475
(equal (logtail pos i)
7448
7478
:hints (("Goal" :in-theory (enable logtail))))
7632
7662
(<= (lshu n2 v s) (1- (expt 2 n1))))
7633
7663
:rule-classes nil
7634
:hints (("goal" :use (lshu-bound-2)
7664
:hints (("goal" :use (lshu-bound-2)
7635
7665
:in-theory (e/d (UNSIGNED-BYTE-P)
7636
7666
( lshu-bound-2 EXPT-MINUS)))))
7681
7711
;Returns a term representing the conjunctionof TERM1 and TERM2.
7682
7712
(defund make-conjunction (term1 term2)
7683
7713
(declare (type t term1 term2))
7684
(if (equal term1 ''t)
7714
(if (equal term1 ''t)
7685
7715
term2 ;conjoining something with "true" has no effect
7686
7716
(if (equal term2 ''t)
7687
7717
term1 ;conjoining something with "true" has no effect
7751
7781
(if (not (consp term))
7752
7782
`(integerp ,term)
7753
7783
(case (car term)
7754
(binary-+ (make-conjunction
7784
(binary-+ (make-conjunction
7755
7785
(hyp-for-addends n (cadr term))
7756
7786
(hyp-for-addends n (caddr term))))
7757
7787
(unary-- (hyp-for-addend n (cadr term)))
7799
7829
(loghead-sum-eval (strip-logheads-from-sum n term) alist))))
7800
7830
:hints (("Goal" :in-theory (e/d (make-conjunction
7801
7831
strip-loghead-from-term
7802
CALL-TO-LOGHEAD-WITH-N-OR-GREATER-SIZE)
7832
CALL-TO-LOGHEAD-WITH-N-OR-GREATER-SIZE)
7803
7833
(UNSIGNED-BYTE-P-LOGHEAD-FORWARD-CHAINING ;i think this prevents specious simplification
7805
7835
:do-not '(generalize eliminate-destructors))))
8049
8079
simplify-bit-functions))))
8051
8081
(defthm logxor-lognot-one
8052
(implies (and (integerp a)
8082
(implies (and (integerp a)
8054
8084
(equal (logxor (lognot a) b)
8055
8085
(lognot (logxor a b)))))
8215
8245
(equal (logext n (+ x (expt 2 n)))
8217
8247
:hints (("goal" :in-theory (e/d (LRDT
8222
(local (in-theory (enable open-logcons)))
8252
(local (in-theory (enable open-logcons)))
8224
8254
(local (in-theory (disable logcons-of-0)))
8434
8464
:in-theory (e/d (FALSIFY-UNSIGNED-BYTE-P)
8435
8465
( unsigned-byte-p-logapp)))))
8437
(in-theory (disable unsigned-byte-p-logapp))
8467
(in-theory (disable unsigned-byte-p-logapp))
8439
8469
(defthm ash-<=-to-sbp
8440
8470
(implies (and (signed-byte-p (- 32 N) V)
8663
8693
;think more about how we want to handle claims about bit vectors of length 1. do we prefer to normalize all the claims to claims about 0, or do we
8664
8694
;want to leave (equal (logcar x) 1) to get ACL2 to substitute 1 for (logcar x)? -ews
8665
8695
;eric saw something similar to this at AMD.
8666
(defthm equal-logcar-1
8667
(equal (equal (logcar x) 1)
8668
(not (equal (logcar x) 0)))
8696
(defthm equal-logcar-1
8697
(equal (equal (logcar x) 1)
8698
(not (equal (logcar x) 0)))
8669
8699
:hints (("goal" :in-theory (enable))))
8758
8788
:hints (("Goal" :do-not '(generalize eliminate-destructors)
8759
8789
:in-theory (enable logapp))))
8761
(in-theory (disable logcar-logapp))
8791
(in-theory (disable logcar-logapp))
8763
8793
(defthm logbitp-logapp-better
8764
8794
(equal (logbitp pos (logapp size i j))
8773
8803
(defthm logext-of-logext-same
8774
8804
(equal (logext size (logext size i))
8775
8805
(logext size i))
8776
:hints (("Goal" :in-theory (e/d (logext)
8806
:hints (("Goal" :in-theory (e/d (logext)
8777
8807
(EQUAL-LOGAPP-X-Y-Z
8778
EQUAL-LOGAPP-X-Y-Z-CONSTANTS
8808
EQUAL-LOGAPP-X-Y-Z-CONSTANTS
8779
8809
;;LOGHEAD-LOGAPP
8782
8812
(defthm logext-+-logext-better-alt
8783
8813
(equal (logext size (+ (logext size j) i))
8784
8814
(logext size (+ (ifix j) i)))
8785
:hints (("Goal" :use (:instance logext-+-logext-better)
8815
:hints (("Goal" :use (:instance logext-+-logext-better)
8786
8816
:in-theory (disable logext-+-logext-better))))
8788
8818
(defthm logbitp-of-product-with-2
8804
8834
:hints (("Goal" :do-not '(generalize eliminate-destructors)
8805
8835
:in-theory (e/d (FLOOR-NORMALIZES-TO-HAVE-J-BE-1 EXPONENTS-ADD-UNRESTRICTED logbitp) ()))))
8807
8837
(defthm logbitp-of-*-expt-2-special
8808
8838
(implies (and (integerp x)
8922
8952
(:REWRITE UNSIGNED-BYTE-P-+-EASY)
8923
8953
(:FORWARD-CHAINING UNSIGNED-BYTE-P-+-EASY-FC)
8924
8954
(:REWRITE UNSIGNED-BYTE-P-+-BRIDGE2)
8925
; (:REWRITE SIGNED-BYTE-P-+)
8955
; (:REWRITE SIGNED-BYTE-P-+)
8926
8956
; (:REWRITE SIGNED-BYTE-P-UNSIGNED-BYTE-P)
8927
8957
; (:REWRITE UNSIGNED-BYTE-P-SUBTYPE)
8928
8958
; (:REWRITE SIGNED-BYTE-P-SUBTYPE)
9098
;;; The true-listp guard to nth and update-nth is used elswhere,
9099
;;; There are two versions, which are identical except that our
9128
;;; The true-listp guard to nth and update-nth is used elswhere,
9129
;;; There are two versions, which are identical except that our
9100
9130
;;; guard is that the index is in the list, not that the list is true.
9215
9245
(<= (LOGAND X Y) 2147483647)))
9218
;The out rules in the next series may not handle all these cases,
9248
;The out rules in the next series may not handle all these cases,
9219
9249
;so it has been left it in this file, but commented out
9294
9324
;; BY: This book is rather fragile. For example, it seems previously to have
9295
9325
;; been certified with EXPT enabled, but it is currently disabled, so I
9296
;; had to deal with that throughout.
9326
;; had to deal with that throughout.
9327
9357
;:do-not '(generalize eliminate-destructors)
9328
9358
:in-theory (enable LOGOPS-RECURSIVE-DEFINITIONS-THEORY b-and b-xor open-logcons))))
9330
;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;
9360
;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;
9331
9361
;; signed-byte-p, unsigned-byte-p
9332
9362
;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;
9710
9740
:hints (("Goal" :in-theory (enable signed-byte-p))))
9712
;bzo we could need a rule like this for subtracting 2, subtracting 3, etc.
9742
;bzo we could need a rule like this for subtracting 2, subtracting 3, etc.
9713
9743
;(and the rules for those cases would get grosser) I bet that subtracting 1
9714
;covers most of the cases we'll see in practice.this rule gives us a little
9715
;flexibility around the ends of the unsigned-byte-p range without just
9744
;covers most of the cases we'll see in practice.this rule gives us a little
9745
;flexibility around the ends of the unsigned-byte-p range without just
9716
9746
;opening up to arithmetic
9717
9747
(defthm unsigned-byte-p-of-one-less-than-x
9718
9748
(implies (syntaxp (not (quotep x))) ;prevents loops (i think because acl2 unifies say, the constant 42 with the pattern (+ -1 x)
9757
9787
;; (defthm plus-of-logapp-suck-in
9758
9788
;; (implies (unsigned-byte-p 16 (+ x y))
9759
9789
;; (equal (+ x (logapp 16 y j))
9760
;; (if (unsigned-byte-p 16 y)
9790
;; (if (unsigned-byte-p 16 y)
9761
9791
;; (logapp 16 (+ x y) j)
9762
9792
;; (+ (loghead 16 y) (- y) (logapp 16 (+ x y) j)) ;this seems strange
9769
9799
(defthm plus-of-logapp-suck-in
9770
9800
(implies (unsigned-byte-p n (+ x y))
9771
9801
(equal (+ x (logapp n y j))
9772
(if (unsigned-byte-p n y)
9802
(if (unsigned-byte-p n y)
9773
9803
(logapp n (+ x y) j)
9774
9804
(+ (loghead n y) (- y) (logapp n (+ x y) j)) ;this seems strange
9778
9808
(defthm plus-of-logapp-suck-in-alt
9779
9809
(implies (unsigned-byte-p n (+ x z y))
9780
9810
(equal (+ x z (logapp n y j))
9781
(if (unsigned-byte-p n y)
9811
(if (unsigned-byte-p n y)
9782
9812
(logapp n (+ x z y) j)
9783
9813
(+ (loghead n y) (- y) (logapp n (+ x z y) j)) ;this seems strange
9897
9927
(equal (ash z n) z) ; bzo ;figure out what this should simplify to and prove a rule, then rephrase this rule
9899
9929
:hints (("Goal" :do-not '(generalize eliminate-destructors)
9900
:in-theory (e/d (floor-normalizes-to-have-j-be-1
9930
:in-theory (e/d (floor-normalizes-to-have-j-be-1
9904
9934
( ;(:type-prescription floor)
9905
9935
(:type-prescription floor)
10169
10199
;; :rule-classes ((:rewrite :backchain-limit-lst (0)))
10170
10200
;; :hints (("Goal" :in-theory (e/d (unsigned-byte-p
10171
10201
;; INTEGER-RANGE-P
10173
10203
;; (FLOOR-BY-TWICE-HACK)))))
10175
10205
;think more about this
10177
10207
(defthmd loghead-when-know-top-bit
10178
10208
(implies (and (equal (logbit m x) b) ;using m so that this will be sure to match
10179
10209
(equal m (+ -1 n))
10263
10293
:hints (("Goal" :cases ((integerp y))
10264
10294
:in-theory (e/d (mod)))))
10266
10296
;generalize to handle addends other than 1 with corresponding predicates (like "multiple of 4" than even)?
10267
10297
;prove without using elimination?
10338
10368
(or (equal x (expt 2 (+ -1 n)))
10339
10369
(and (signed-byte-p n x)
10340
10370
(not (equal x (- (expt 2 (+ -1 n))))))))))
10341
:hints (("Goal" :in-theory (enable signed-byte-p
10371
:hints (("Goal" :in-theory (enable signed-byte-p
10342
10372
integer-range-p ;prove a rule for integer-range-p of (+ 1 x)
10497
10527
(loghead n (+ a (- (* k (ifix b))))))))
10499
10529
;;Note the overflow case:
10500
;;(truncate (- (expt 2 31)) -1) is equal to (expt2 31), which is not a signed-byte-p 32.
10530
;;(truncate (- (expt 2 31)) -1) is equal to (expt2 31), which is not a signed-byte-p 32.
10502
10532
(defthm signed-byte-p-of-truncate
10503
10533
(implies (and (signed-byte-p 32 i)
10715
10745
(defthmd one-way
10716
10746
(IMPLIES (AND (INTEGERP (* 1/2 (FLOOR X 16384)))
10717
10747
(INTEGERP X))
10718
(EQUAL (MOD X 16384)
10748
(EQUAL (MOD X 16384)
10719
10749
(MOD X 32768)))
10720
10750
:hints (("Goal" :in-theory (disable evenp-collapse))))
10723
10753
;keep this disabled most of the time
10724
10754
(defthmd loghead-split-x-rewrite
10725
(implies (and (syntaxp (equal x 'x))
10755
(implies (and (syntaxp (equal x 'x))
10728
10758
(equal (loghead n x)
10808
10838
(logtail (- n m) x)))
10809
10839
:hints (("Goal" :use (:instance INTEGERP-EXPT (n (- n m)))
10810
10840
:in-theory (e/d (logtail ifloor ifix FLOOR-NORMALIZES-TO-HAVE-J-BE-1
10811
EXPONENTS-ADD-UNRESTRICTED)
10841
EXPONENTS-ADD-UNRESTRICTED)
10812
10842
(INTEGERP-EXPT)))))
10814
10844
(defthm logtail-shift-constant-version
10957
10987
(equal (equal 0 (loghead n (+ y (- x))))
10958
10988
(equal (loghead n x) (loghead n y))))
10960
(("Goal" :in-theory (e/d (;loghead
10990
(("Goal" :in-theory (e/d (;loghead
10961
10991
LOGHEAD-SUM-SPLIT-INTO-2-CASES
10962
10992
imod ifix) (mod-=-0)))))
10965
10995
(defthm loghead-of-difference-equal-0-rewrite
10966
(implies (and (integerp x)
10996
(implies (and (integerp x)
10971
11001
(equal (equal 0 (loghead n (+ (- x) y)))
10972
11002
(equal (loghead n x) (loghead n y))))
10974
(("Goal" :in-theory (e/d (;loghead
11004
(("Goal" :in-theory (e/d (;loghead
10975
11005
LOGHEAD-SUM-SPLIT-INTO-2-CASES
10976
imod ifix) (mod-=-0)))))
11006
imod ifix) (mod-=-0)))))
10978
11008
;bzo harvest the stuff below
11029
11059
;; (defthm sbp-of-logapp-hack
11030
11060
;; (implies (signed-byte-p 16 b)
11031
11061
;; (signed-byte-p 32 (logapp 16 a b)))
11032
;; :hints (("Goal" :in-theory (enable logapp
11062
;; :hints (("Goal" :in-theory (enable logapp
11033
11063
;; signed-byte-p
11034
11064
;; integer-range-p))))
11051
11081
;We want to extend an inequality like (< x 65535) to (< x 65536) when we also know (not (equal x 65535)) and (integerp x).
11052
11082
;Writing the rule with the free variable means we really must find the disquality right there in the context.
11053
11083
;Perhaps this should pay attention to whether we're trying to satisfy or falsity the <.
11055
11085
(defthmd extend-<
11056
11086
(implies (and (not (equal x free))
11057
11087
(equal free k)
11079
11109
:hints (("Goal" :in-theory (enable logbitp signed-byte-p))))
11080
11110
(in-theory (disable LOGBITP-TEST-OF-TOP-BIT))
11083
11113
;; (defthm loghead-subst-32
11084
11114
;; (implies (and (equal (loghead 32 x) k)
11085
11115
;; (syntaxp (quotep k))
11087
;; (equal (loghead 31 x)
11117
;; (equal (loghead 31 x)
11088
11118
;; (loghead 31 k))))
11092
11122
(defthm loghead-subst-2
11093
11123
(implies (and (equal (loghead 31 x) k)
11094
11124
(syntaxp (quotep k))
11096
(equal (loghead 32 x)
11126
(equal (loghead 32 x)
11097
11127
(logapp 31 k (logbit 31 x))
11297
11327
(defthm loghead-equal-logapp-same-rewrite
11298
(implies (and (integerp n)
11328
(implies (and (integerp n)
11300
11330
(equal (equal (loghead n x) (logapp (+ -1 n) x 1))
11301
11331
(equal 1 (logbit (+ -1 n) x)))))
11303
11333
(defthm loghead-equal-loghead-one-shorter-rewrite
11304
11334
(implies (and (integerp x)
11452
11482
:hints (("Goal" :in-theory (enable logext ash))))
11454
11484
(defthm logext-equal-min-value-hack-gen-constant-version
11455
(implies (and (syntaxp (and (quotep k)
11485
(implies (and (syntaxp (and (quotep k)
11458
11488
(equal k (- (expt 2 (+ -1 n))))
11502
11532
;Can cause a case split.
11503
11533
(defthmd loghead-suck-in-one-plus
11504
(implies (and (syntaxp (and (consp x)
11505
(equal (car x) 'binary-+)
11534
(implies (and (syntaxp (and (consp x)
11535
(equal (car x) 'binary-+)
11506
11536
(quotep (cadr x))))
11692
11722
(defthm loghead-of-logext-hack-1
11693
(implies (and (integerp x)
11723
(implies (and (integerp x)
11694
11724
(integerp y))
11695
11725
(equal (loghead size (+ (- (logext size x)) y))
11696
11726
(loghead size (+ (- x) y))))
11703
11733
LOGHEAD-+-CANCEL-BETTER))))
11705
11735
(defthm loghead-of-logext-hack-1-alt
11706
(implies (and (integerp x)
11736
(implies (and (integerp x)
11707
11737
(integerp y))
11708
11738
(equal (loghead size (+ y (- (logext size x))))
11709
11739
(loghead size (+ y (- x)))))
12015
12045
(equal (LOGAPP m (+ w v x y (* N (LOGEXT size z))) xx)
12016
12046
(LOGAPP m (+ w v x y (* N z)) xx))))
12018
12048
(defthm loghead-hack-blah
12019
(implies (and (integerp y)
12049
(implies (and (integerp y)
12022
12052
(integerp size))
12350
12380
(implies (and (integerp size) (< 0 size))
12351
12381
(equal (logext size (expt 2 (+ -1 size)))
12352
12382
(- (expt 2 (+ -1 size)))))
12353
:hints (("Goal" :in-theory (e/d (logext EQUAL-LOGAPP-X-Y-Z)
12383
:hints (("Goal" :in-theory (e/d (logext EQUAL-LOGAPP-X-Y-Z)
12354
12384
(logapp-subst-in-first-arg ;LOGAPP-HACK2 ;bzo
12358
12388
(defthmd minus-of-logext
12359
12389
(implies (and (integerp size)
12478
12508
(y (logtail size2 (loghead size1 x)))
12479
12509
(z (loghead size1 x))))
12481
:in-theory (e/d (loghead-equal-rewrite)
12511
:in-theory (e/d (loghead-equal-rewrite)
12482
12512
(equal-logapp-x-y-z
12483
12513
equal-logapp-x-y-z-constants
12484
12514
LOGAPP-RECOMBINE-LOGHEAD-CASE
12527
12557
(y (logtail size2 (logext size1 x)))
12528
12558
(z (logext size1 x))))
12530
:in-theory (e/d (loghead-equal-rewrite)
12560
:in-theory (e/d (loghead-equal-rewrite)
12531
12561
(LOGAPP-RECOMBINE-LOGEXT-CASE
12532
12562
equal-logapp-x-y-z
12533
12563
equal-logapp-x-y-z-constants
12613
12643
:hints (("Goal" :cases ((and (integerp n)
12615
:in-theory (e/d (ash-as-logapp)
12645
:in-theory (e/d (ash-as-logapp)
12616
12646
(logapp-0-part-2-better)))))
12618
12648
(defthm logtail-of-sum-of-ash-alt
12659
12689
(implies (and (unsigned-byte-p 16 x)
12661
12691
(integerp k))
12662
(equal (unsigned-byte-p 16 (+ (- k) x))
12692
(equal (unsigned-byte-p 16 (+ (- k) x))
12665
12695
(defthm unsigned-byte-p-becomes-inequality-alt
12666
12696
(implies (and (unsigned-byte-p 16 x)
12668
12698
(integerp k))
12669
(equal (unsigned-byte-p 16 (+ x (- k)))
12699
(equal (unsigned-byte-p 16 (+ x (- k)))
12672
12702
(defthmd usb-of-sum-with-two-other-addends-hack
12831
12861
(defthm loghead-equality-impossible
12832
(implies (and (syntaxp (and (quotep k1)
12862
(implies (and (syntaxp (and (quotep k1)
12833
12863
(quotep k2)))
12834
12864
(not (equal 0 (loghead 16 (+ k1 k2))))
12835
12865
(unsigned-byte-p 16 x) ;not needed?
12839
12869
(equal (equal x (+ k1 (loghead 16 (+ k2 x)))) ;note that x appears twice in LHS
12841
12871
:hints (("Goal" :in-theory (e/d (loghead-sum-split-into-2-cases
12843
12873
(unsigned-byte-p-loghead-forward-chaining
12845
12875
;(:type-prescription loghead)
12966
12996
(equal (EQUAL x (+ (expt 2 n) (LOGEXT n x)))
12967
12997
(<= (expt 2 (+ -1 n)) x)))
12968
:hints (("Goal" :in-theory (enable logext
12998
:hints (("Goal" :in-theory (enable logext
12970
13000
EXPONENTS-ADD-UNRESTRICTED))))
13044
13074
(and (integerp x)
13045
13075
(equal 0 (loghead n x))
13046
13076
(equal (ifix y) (logtail n x))))))
13048
13078
;trying a switch of the direction to associate logapp! doing it this way
13049
13079
;means the sizes in the logapp nest are the sizes of their corresponding
13050
13080
;values, rather than sums of the sizes of several values
13061
13091
;This one's :executable-counterpart stays enabled.
13062
13092
(defund expt-execute (r i) (expt r i))
13064
;Allows expt calls with small exponents to be computed
13094
;Allows expt calls with small exponents to be computed
13065
13095
;You can change 1000 to your own desired bound.
13066
13096
(defthmd expt-execute-rewrite
13067
13097
(implies (and (syntaxp (and (quotep r) (quotep i) (< (abs (cadr i)) 1000))))
13407
13437
:hints (("Goal" :in-theory (enable unsigned-byte-p signed-byte-p))))
13409
13439
;this might be expensive?
13410
(defthm equal-bit-1
13411
(implies (unsigned-byte-p 1 x)
13440
(defthm equal-bit-1
13441
(implies (unsigned-byte-p 1 x)
13413
13443
(not (equal x 0)))))
13415
13445
(defthm unsigned-byte-p-+-easy