1
; ACL2 Euclidean Domain books -- Book 4aa -- Example: Integers.
2
; The Integers are shown to be an Euclidean Domain with
3
; unique factorization. Here Size is abs; Quotient is floor
4
; and Remainder is mod.
6
; This version uses quantifiers (defun-sk) and is
9
; Copyright (C) 2005 John R. Cowles, University of Wyoming
11
; This book is free software; you can redistribute it and/or modify
12
; it under the terms of the GNU General Public License as published by
13
; the Free Software Foundation; either version 2 of the License, or
14
; (at your option) any later version.
16
; This book is distributed in the hope that it will be useful,
17
; but WITHOUT ANY WARRANTY; without even the implied warranty of
18
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
; GNU General Public License for more details.
21
; You should have received a copy of the GNU General Public License
22
; along with this book; if not, write to the Free Software
23
; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27
; Department of Computer Science
28
; University of Wyoming
29
; Laramie, WY 82071-3682 U.S.A.
31
; Last modified Feb. 06.
34
To certify this book, first, create a world with the following package:
38
(union-eq *acl2-exports*
39
*common-lisp-symbols-from-main-lisp-package*)
40
; Subtracted 12/4/2012 by Matt K. for addition to *acl2-exports*
41
'(nat-listp acl2-number-listp)))
48
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
49
;; The Integers are an Euclidean Doamin:
51
;; integerp ; Predicate for set of Euclidean Domain elements.
52
;; equal ; Equality predicate for Euclidean Domain elements.
53
;; identity ; Choose unique equivalence class representative for equal.
54
;; + ; Addition in Euclidean Domain.
55
;; * ; Multiplication in Euclidean Domain.
56
;; - ; Unary minus in Euclidean Domain.
57
;; 0 ; 0 element in Euclidean Domain.
58
;; 1 ; 1 element in Euclidean Domain.
59
;; abs ; Natp size of each nonzero Euclidean Domain element.
60
;; floor ; Quotient in Euclidean Domain.
61
;; mod ; Remainder in Euclidean Domain.
63
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
64
;; An Euclidean Domain is an integral domain, together with a Size function
65
;; from nonzero domain elements into the nonnegative integers, that
66
;; satisfies the Division Propery:
68
;; Division Propery. For all domain elements x and all nonzero domain
69
;; elements y there are domain elements q and r such that
71
;; x = yq + r and either r is the domain's zero or Size(r) < Size(y)
73
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
74
;; An Integral Domain is a commutative ring with no zero-divisors.
76
;; A Zero-Divisor in a commutative ring is a nonzero ring element, x, such
77
;; that there is a nonzero ring element y such that the product xy equals
78
;; the zero element of the ring.
80
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
81
;; A Commutative Ring is a nonempty set with two binary operations, addition
82
;; and multiplication, an unary operation, minus, and a ring element, zero,
85
;; (1) the binary operations are commutative and associative,
86
;; (2) multiplication distributes over addition,
87
;; (3) zero is an identity for addition, and
88
;; (4) minus produces an additive inverse
90
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
91
;; Every Euclidean Domain has a multiplicative identity.
92
;; See Book 1 of ACL2 Euclidean Domain books, ed1.lisp, for a proof.
94
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
95
;; There is no loss of generality in assuming the
96
;; Multiplicative Size Property:
98
;; For all nonzero domain elements x and y, Size(x) <= Size(xy).
100
;; If the original Size function does not satisfy this property,
101
;; then it can replaced by another that does satisfy this and the
102
;; division property.
103
;; See Book 2 of the ACL2 Euclidean Domain books, ed2.lisp,
106
;; In fact, for integers x and y, (abs (* x y)) = (* (abs x)(abs y)).
107
;; So, if integer y differs from 0, then (<= 1 (abs y)); then for
108
;; any integer x, (abs x) = (* (abs x) 1) <= (* (abs x)(abs y))
110
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
111
(in-package "INT-MOD")
112
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
113
; Make temporary use of an ACL2 Arithmetic Book and a book containing facts
114
; about FLOOR and MOD to help certify this book
117
(include-book "arithmetic/top" :dir :system
118
; Matt K.: Commenting out use of :uncertified-okp after v4-3 in order to
119
; support provisional certification:
120
; :uncertified-okp nil
122
:skip-proofs-okp nil))
125
(include-book "ihs/quotient-remainder-lemmas" :dir :system
126
; Matt K.: Commenting out use of :uncertified-okp after v4-3 in order to
127
; support provisional certification:
128
; :uncertified-okp nil
130
:skip-proofs-okp nil))
133
(in-theory (disable acl2::quotient-remainder-functions)))
135
;; Make temporary use of an ACL2 Euclidean Domain Book:
138
; Matt K.: Commenting out use of :uncertified-okp after v4-3 in order to
139
; support provisional certification:
140
; :uncertified-okp nil
142
:skip-proofs-okp nil))
145
;;; Integral Domain Axioms:
148
(and (implies (integerp x)
149
(and (implies (integerp y)
150
(and (integerp (+ x y))
159
(implies (integerp x)
161
(implies (integerp y)
162
(and (booleanp (equal x y))
165
(implies (integerp z)
166
(implies (and (equal x y)
173
(implies (equal y1 y2)
174
(and (iff (integerp y1)
176
(implies (and (integerp y1)
178
(and (implies (integerp x)
183
(implies (integerp z)
194
(implies (integerp x)
195
(integerp (identity x)))
199
Equivalence-class-Laws
200
(and (implies (integerp x)
201
(equal (identity x) x))
202
(implies (and (integerp y1)
211
(implies (and (integerp x)
221
(implies (and (integerp x)
224
(and (equal (+ (+ x y) z)
231
Left-Distributivity-Law
232
(implies (and (integerp x)
242
(implies (integerp x)
251
(implies (integerp x)
258
(implies (and (integerp x)
260
(equal (equal (* x y) 0)
265
;; Euclidean Domain Axioms:
268
(implies (and (integerp x)
270
(and (integerp (abs x))
272
:rule-classes ((:type-prescription
274
(implies (integerp x)
275
(and (integerp (abs x))
279
(implies (and (integerp x)
285
(implies (and (integerp y1)
293
Closure-of-floor-&-mod
294
(implies (and (integerp x)
297
(and (integerp (floor x y))
298
(integerp (mod x y))))
302
Congruence-for-floor-&-mod
303
(implies (and (integerp y1)
306
(and (implies (and (integerp x)
308
(and (equal (floor x y1)
312
(implies (and (integerp z)
314
(and (equal (floor y1 z)
322
(implies (and (integerp x)
325
(and (equal x (+ (* y (floor x y))
327
(or (equal (mod x y) 0)
330
:rule-classes ((:rewrite
332
(implies (and (integerp x)
335
(not (equal (mod x y) 0)))
340
(implies (and (integerp x)
343
(not (equal (mod x y)0)))
349
(implies (and (integerp x)
355
:rule-classes (:linear
358
(and (implies (and (integerp x)
362
(implies (and (integerp x)
369
:in-theory (disable (:definition abs))
372
(implies (and (integerp x)
380
(implies (and (integerp x)
383
(* (abs x)(abs y)))))))
385
:in-theory (enable (:definition abs)))))
387
(in-theory (disable (:definition abs)))
392
;; Divides-p is defined using quantifiers (defun-sk) and
397
(exists z (and (integerp x)
417
(:functional-instance
418
acl2::Size-unit-p=Size-1_e
421
(acl2::C_=_e identity)
422
(acl2::binary-+_e binary-+)
423
(acl2::binary-*_e binary-*)
425
(acl2::0_e (lambda () 0))
426
(acl2::1_e (lambda () 1))
430
(acl2::divides-p divides-p)
431
(acl2::divides-p-witness divides-p-witness)
432
(acl2::unit-p unit-p))
437
(implies (and (integerp x)
445
(:functional-instance
446
acl2::Size=Size-1_e-implies-unit-p
449
(acl2::C_=_e identity)
450
(acl2::binary-+_e binary-+)
451
(acl2::binary-*_e binary-*)
453
(acl2::0_e (lambda () 0))
454
(acl2::1_e (lambda () 1))
458
(acl2::divides-p divides-p)
459
(acl2::divides-p-witness divides-p-witness)
460
(acl2::unit-p unit-p))
469
:in-theory (enable abs)
471
Abs=1-implies-unit-p))))
475
(implies (and (not (unit-p y))
482
:rule-classes (:linear
485
:in-theory (e/d ((:definition abs))
486
((:definition unit-p))))))
488
;;;;;;;;;;;;;;;;;;;;;;;;
490
;; Irreducible-p theory:
492
;; Reducible-p is defined using quantifiers (defun-sk) and
497
(exists (y z)(and (integerp y)
507
(not (reducible-p x))))
510
Irreducible-p-implies-prime-property
511
(implies (and (irreducible-p x)
514
(divides-p x (* y z)))
520
(:functional-instance
521
acl2::Irreducible-p-implies-prime-property
524
(acl2::C_=_e identity)
525
(acl2::binary-+_e binary-+)
526
(acl2::binary-*_e binary-*)
528
(acl2::0_e (lambda () 0))
529
(acl2::1_e (lambda () 1))
533
(acl2::divides-p divides-p)
534
(acl2::divides-p-witness divides-p-witness)
535
(acl2::unit-p unit-p)
536
(acl2::reducible-p reducible-p)
537
(acl2::reducible-p-witness reducible-p-witness)
538
(acl2::irreducible-p irreducible-p))
543
:in-theory (disable unit-p=_+1_or_-1
544
(:definition reducible-p)
545
(:definition divides-p)))
553
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
554
;; Factorization existence theory:
557
irreducible-factors (x)
558
"Return a list, lst, of irreducible
559
elements of integerp, so that if x is
560
in integerp, x is not 0, and x is not
561
an unit, then x = product of the
563
(declare (xargs :measure (if (integerp x)
567
:in-theory (disable (:definition mv-nth)
568
(:definition unit-p))
571
(x (mv-nth 1 (reducible-p-witness x)))
572
(y (mv-nth 0 (reducible-p-witness x)))))
574
:in-theory (disable (:definition mv-nth)
575
(:definition unit-p))
578
(x (mv-nth 0 (reducible-p-witness x)))
579
(y (mv-nth 1 (reducible-p-witness x))))))))
580
(cond ((or (not (integerp x))
586
(reducible-p-witness x)
587
(append (irreducible-factors y)
588
(irreducible-factors z))))
594
(and (integerp (car lst))
595
(integerp-listp (cdr lst)))
599
irreducible-listp (lst)
601
(and (irreducible-p (car lst))
602
(irreducible-listp (cdr lst)))
608
(if (integerp (car lst))
609
(* (car lst)(*-lst (cdr lst)))
614
IRREDUCIBLE-FACTORIZATION-EXISTENCE
615
(and (true-listp (irreducible-factors x))
616
(integerp-listp (irreducible-factors x))
617
(irreducible-listp (irreducible-factors x))
618
(implies (and (integerp x)
621
(equal (*-lst (irreducible-factors x)) x)))
625
(:functional-instance
626
acl2::IRREDUCIBLE-FACTORIZATION-EXISTENCE
629
(acl2::C_=_e identity)
630
(acl2::binary-+_e binary-+)
631
(acl2::binary-*_e binary-*)
633
(acl2::0_e (lambda () 0))
634
(acl2::1_e (lambda () 1))
638
(acl2::divides-p divides-p)
639
(acl2::divides-p-witness divides-p-witness)
640
(acl2::unit-p unit-p)
641
(acl2::reducible-p reducible-p)
642
(acl2::reducible-p-witness reducible-p-witness)
643
(acl2::irreducible-p irreducible-p)
644
(acl2::irreducible-factors irreducible-factors)
645
(acl2::irreducible-listp irreducible-listp)
646
(acl2::edp-listp integerp-listp)
647
(acl2::*_e-lst *-lst))
650
:in-theory (disable (:definition irreducible-p)))
652
:in-theory (disable (:definition mv-nth)
653
(:definition reducible-p)))))
655
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
656
;; Unit-associates-p theory:
658
;; Unit-associates-p is defined using quantifiers (defun-sk) and
662
unit-associates-p (x y)
663
(exists u (if (and (integerp x)
671
Irreducible-p-unit-associates
672
(implies (and (divides-p x y)
675
(unit-associates-p x y))
679
(:functional-instance
680
acl2::Irreducible-p-unit-associates
683
(acl2::C_=_e identity)
684
(acl2::binary-+_e binary-+)
685
(acl2::binary-*_e binary-*)
687
(acl2::0_e (lambda () 0))
688
(acl2::1_e (lambda () 1))
692
(acl2::divides-p divides-p)
693
(acl2::divides-p-witness divides-p-witness)
694
(acl2::unit-p unit-p)
695
(acl2::reducible-p reducible-p)
696
(acl2::reducible-p-witness reducible-p-witness)
697
(acl2::irreducible-p irreducible-p)
698
(acl2::unit-associates-p unit-associates-p)
699
(acl2::unit-associates-p-witness unit-associates-p-witness))
704
unit-associates-p-suff
708
:in-theory (disable unit-p=_+1_or_-1))))
710
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
711
;; Unique factorization theory:
714
Member-unit-associate (x lst)
715
"Determine if an unit-associate
716
of x is a member of lst."
719
((unit-associates-p x (car lst))
721
(t (member-unit-associate x (cdr lst)))))
724
Delete-one-unit-associate (x lst)
725
"Return the result of deleting one occurrence
726
of an unit-associate of x from the list lst."
728
(if (unit-associates-p x (car lst))
730
(cons (car lst)(delete-one-unit-associate x (cdr lst))))
734
Bag-equal-unit-associates (lst1 lst2)
735
"Return T iff lst1 and lst2 have the same
736
members, up to unit-associates, with the
737
same multiplicity, up to unit-associates."
739
(and (member-unit-associate (car lst1) lst2)
740
(bag-equal-unit-associates (cdr lst1)
741
(delete-one-unit-associate (car lst1)
745
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
746
;; Show that bag-equal-unit-associates has the expected properties:
748
;; Lisp objects that are bag-equal-unit-associates have the same length.
750
;; Lisp objects that are bag-equal-unit-associates have the same members
751
;; up to unit-associates.
753
;; Elements in Lisp objects that are bag-equal-unit-associates occur
754
;; in each object with the same multiplicity up to unit-associates.
757
Bag-equal-unit-associates->equal-len
758
(implies (bag-equal-unit-associates lst1 lst2)
764
(:functional-instance
765
acl2::Bag-equal-unit-associates->equal-len
768
(acl2::C_=_e identity)
769
(acl2::binary-+_e binary-+)
770
(acl2::binary-*_e binary-*)
772
(acl2::0_e (lambda () 0))
773
(acl2::1_e (lambda () 1))
777
(acl2::divides-p divides-p)
778
(acl2::divides-p-witness divides-p-witness)
779
(acl2::unit-p unit-p)
780
(acl2::unit-associates-p unit-associates-p)
781
(acl2::unit-associates-p-witness unit-associates-p-witness)
782
(acl2::Member-unit-associate Member-unit-associate)
783
(acl2::Delete-one-unit-associate Delete-one-unit-associate)
784
(acl2::Bag-equal-unit-associates Bag-equal-unit-associates))
786
(acl2::lst2 lst2)))))
789
Bag-equal-unit-associates->iff-member-unit-associate
790
(implies (bag-equal-unit-associates lst1 lst2)
791
(iff (member-unit-associate x lst1)
792
(member-unit-associate x lst2)))
796
(:functional-instance
797
acl2::Bag-equal-unit-associates->iff-member-unit-associate
800
(acl2::C_=_e identity)
801
(acl2::binary-+_e binary-+)
802
(acl2::binary-*_e binary-*)
804
(acl2::0_e (lambda () 0))
805
(acl2::1_e (lambda () 1))
809
(acl2::divides-p divides-p)
810
(acl2::divides-p-witness divides-p-witness)
811
(acl2::unit-p unit-p)
812
(acl2::unit-associates-p unit-associates-p)
813
(acl2::unit-associates-p-witness unit-associates-p-witness)
814
(acl2::Member-unit-associate Member-unit-associate)
815
(acl2::Delete-one-unit-associate Delete-one-unit-associate)
816
(acl2::Bag-equal-unit-associates Bag-equal-unit-associates))
818
(acl2::lst2 lst2)))))
821
Multiplicity-unit-associate (x lst)
823
(if (unit-associates-p x (car lst))
824
(+ 1 (multiplicity-unit-associate x (cdr lst)))
825
(multiplicity-unit-associate x (cdr lst)))
829
Bag-equal-unit-associates->equal-multiplicity-unit-associate
830
(implies (bag-equal-unit-associates lst1 lst2)
831
(equal (multiplicity-unit-associate x lst1)
832
(multiplicity-unit-associate x lst2)))
836
(:functional-instance
837
acl2::Bag-equal-unit-associates->equal-multiplicity-unit-associate
840
(acl2::C_=_e identity)
841
(acl2::binary-+_e binary-+)
842
(acl2::binary-*_e binary-*)
844
(acl2::0_e (lambda () 0))
845
(acl2::1_e (lambda () 1))
849
(acl2::divides-p divides-p)
850
(acl2::divides-p-witness divides-p-witness)
851
(acl2::unit-p unit-p)
852
(acl2::unit-associates-p unit-associates-p)
853
(acl2::unit-associates-p-witness unit-associates-p-witness)
854
(acl2::Member-unit-associate Member-unit-associate)
855
(acl2::Delete-one-unit-associate Delete-one-unit-associate)
856
(acl2::Bag-equal-unit-associates Bag-equal-unit-associates)
857
(acl2::Multiplicity-unit-associate Multiplicity-unit-associate))
860
(acl2::lst2 lst2)))))
863
IRREDUCIBLE-FACTORIZATION-UNIQUENESS-general
864
(implies (and (irreducible-listp lst1)
865
(irreducible-listp lst2)
866
(unit-associates-p (*-lst lst1)
868
(bag-equal-unit-associates lst1 lst2))
872
(:functional-instance
873
acl2::IRREDUCIBLE-FACTORIZATION-UNIQUENESS-general
876
(acl2::C_=_e identity)
877
(acl2::binary-+_e binary-+)
878
(acl2::binary-*_e binary-*)
880
(acl2::0_e (lambda () 0))
881
(acl2::1_e (lambda () 1))
885
(acl2::divides-p divides-p)
886
(acl2::divides-p-witness divides-p-witness)
887
(acl2::unit-p unit-p)
888
(acl2::reducible-p reducible-p)
889
(acl2::reducible-p-witness reducible-p-witness)
890
(acl2::irreducible-p irreducible-p)
891
(acl2::irreducible-listp irreducible-listp)
892
(acl2::*_e-lst *-lst)
893
(acl2::unit-associates-p unit-associates-p)
894
(acl2::unit-associates-p-witness unit-associates-p-witness)
895
(acl2::Member-unit-associate Member-unit-associate)
896
(acl2::Delete-one-unit-associate Delete-one-unit-associate)
897
(acl2::Bag-equal-unit-associates Bag-equal-unit-associates))
899
(acl2::lst2 lst2)))))
902
IRREDUCIBLE-FACTORIZATION-UNIQUENESS
903
(implies (and (irreducible-listp lst1)
904
(irreducible-listp lst2)
907
(bag-equal-unit-associates lst1 lst2))
911
(:functional-instance
912
acl2::IRREDUCIBLE-FACTORIZATION-UNIQUENESS
915
(acl2::C_=_e identity)
916
(acl2::binary-+_e binary-+)
917
(acl2::binary-*_e binary-*)
919
(acl2::0_e (lambda () 0))
920
(acl2::1_e (lambda () 1))
924
(acl2::divides-p divides-p)
925
(acl2::divides-p-witness divides-p-witness)
926
(acl2::unit-p unit-p)
927
(acl2::reducible-p reducible-p)
928
(acl2::reducible-p-witness reducible-p-witness)
929
(acl2::irreducible-p irreducible-p)
930
(acl2::irreducible-listp irreducible-listp)
931
(acl2::*_e-lst *-lst)
932
(acl2::unit-associates-p unit-associates-p)
933
(acl2::unit-associates-p-witness unit-associates-p-witness)
934
(acl2::Member-unit-associate Member-unit-associate)
935
(acl2::Delete-one-unit-associate Delete-one-unit-associate)
936
(acl2::Bag-equal-unit-associates Bag-equal-unit-associates))
938
(acl2::lst2 lst2)))))