10 theory IntDef = Equiv + NatArith: |
10 theory IntDef = Equiv + NatArith: |
11 |
11 |
12 constdefs |
12 constdefs |
13 intrel :: "((nat * nat) * (nat * nat)) set" |
13 intrel :: "((nat * nat) * (nat * nat)) set" |
14 --{*the equivalence relation underlying the integers*} |
14 --{*the equivalence relation underlying the integers*} |
15 "intrel == {p. \<exists>x y u v. p = ((x,y),(u,v)) & x+v = u+y}" |
15 "intrel == {((x,y),(u,v)) | x y u v. x+v = u+y}" |
16 |
16 |
17 typedef (Integ) |
17 typedef (Integ) |
18 int = "UNIV//intrel" |
18 int = "UNIV//intrel" |
19 by (auto simp add: quotient_def) |
19 by (auto simp add: quotient_def) |
20 |
20 |
60 |
60 |
61 subsection{*Construction of the Integers*} |
61 subsection{*Construction of the Integers*} |
62 |
62 |
63 subsubsection{*Preliminary Lemmas about the Equivalence Relation*} |
63 subsubsection{*Preliminary Lemmas about the Equivalence Relation*} |
64 |
64 |
65 lemma intrel_iff [simp]: "(((x,y),(u,v)) \<in> intrel) = (x+v = u+y)" |
65 lemma intrel_iff [simp]: "(((x,y),(u,v)) \<in> intrel) = (x+v = u+y)" |
66 by (simp add: intrel_def) |
66 by (simp add: intrel_def) |
67 |
67 |
68 lemma equiv_intrel: "equiv UNIV intrel" |
68 lemma equiv_intrel: "equiv UNIV intrel" |
69 by (simp add: intrel_def equiv_def refl_def sym_def trans_def) |
69 by (simp add: intrel_def equiv_def refl_def sym_def trans_def) |
70 |
70 |
71 lemmas equiv_intrel_iff = |
71 text{*Reduces equality of equivalence classes to the @{term intrel} relation: |
72 eq_equiv_class_iff [OF equiv_intrel UNIV_I UNIV_I, simp] |
72 @{term "(intrel `` {x} = intrel `` {y}) = ((x,y) \<in> intrel)"} *} |
73 |
73 lemmas equiv_intrel_iff = eq_equiv_class_iff [OF equiv_intrel UNIV_I UNIV_I] |
|
74 |
|
75 declare equiv_intrel_iff [simp] |
|
76 |
|
77 |
|
78 text{*All equivalence classes belong to set of representatives*} |
74 lemma intrel_in_integ [simp]: "intrel``{(x,y)} \<in> Integ" |
79 lemma intrel_in_integ [simp]: "intrel``{(x,y)} \<in> Integ" |
75 by (simp add: Integ_def intrel_def quotient_def, fast) |
80 by (auto simp add: Integ_def intrel_def quotient_def) |
76 |
81 |
77 lemma inj_on_Abs_Integ: "inj_on Abs_Integ Integ" |
82 lemma inj_on_Abs_Integ: "inj_on Abs_Integ Integ" |
78 apply (rule inj_on_inverseI) |
83 apply (rule inj_on_inverseI) |
79 apply (erule Abs_Integ_inverse) |
84 apply (erule Abs_Integ_inverse) |
80 done |
85 done |
81 |
86 |
|
87 text{*This theorem reduces equality on abstractions to equality on |
|
88 representatives: |
|
89 @{term "\<lbrakk>x \<in> Integ; y \<in> Integ\<rbrakk> \<Longrightarrow> (Abs_Integ x = Abs_Integ y) = (x=y)"} *} |
82 declare inj_on_Abs_Integ [THEN inj_on_iff, simp] |
90 declare inj_on_Abs_Integ [THEN inj_on_iff, simp] |
83 Abs_Integ_inverse [simp] |
91 |
|
92 declare Abs_Integ_inverse [simp] |
84 |
93 |
85 text{*Case analysis on the representation of an integer as an equivalence |
94 text{*Case analysis on the representation of an integer as an equivalence |
86 class of pairs of naturals.*} |
95 class of pairs of naturals.*} |
87 lemma eq_Abs_Integ [case_names Abs_Integ, cases type: int]: |
96 lemma eq_Abs_Integ [case_names Abs_Integ, cases type: int]: |
88 "(!!x y. z = Abs_Integ(intrel``{(x,y)}) ==> P) ==> P" |
97 "(!!x y. z = Abs_Integ(intrel``{(x,y)}) ==> P) ==> P" |
209 |
218 |
210 lemma zadd_zmult_distrib2: "(w::int) * (z1 + z2) = (w * z1) + (w * z2)" |
219 lemma zadd_zmult_distrib2: "(w::int) * (z1 + z2) = (w * z1) + (w * z2)" |
211 by (simp add: zmult_commute [of w] zadd_zmult_distrib) |
220 by (simp add: zmult_commute [of w] zadd_zmult_distrib) |
212 |
221 |
213 lemma zdiff_zmult_distrib: "((z1::int) - z2) * w = (z1 * w) - (z2 * w)" |
222 lemma zdiff_zmult_distrib: "((z1::int) - z2) * w = (z1 * w) - (z2 * w)" |
214 apply (simp add: diff_int_def) |
223 by (simp add: diff_int_def zadd_zmult_distrib zmult_zminus) |
215 apply (subst zadd_zmult_distrib) |
|
216 apply (simp add: zmult_zminus) |
|
217 done |
|
218 |
224 |
219 lemma zdiff_zmult_distrib2: "(w::int) * (z1 - z2) = (w * z1) - (w * z2)" |
225 lemma zdiff_zmult_distrib2: "(w::int) * (z1 - z2) = (w * z1) - (w * z2)" |
220 by (simp add: zmult_commute [of w] zdiff_zmult_distrib) |
226 by (simp add: zmult_commute [of w] zdiff_zmult_distrib) |
221 |
227 |
222 lemmas int_distrib = |
228 lemmas int_distrib = |
670 proof |
676 proof |
671 fix n |
677 fix n |
672 show "int n = of_nat n" by (induct n, simp_all add: int_Suc add_ac) |
678 show "int n = of_nat n" by (induct n, simp_all add: int_Suc add_ac) |
673 qed |
679 qed |
674 |
680 |
|
681 lemma of_nat_eq_id [simp]: "of_nat = (id :: nat => nat)" |
|
682 proof |
|
683 fix n |
|
684 show "of_nat n = id n" by (induct n, simp_all) |
|
685 qed |
|
686 |
675 |
687 |
676 subsection{*Embedding of the Integers into any Ring: @{term of_int}*} |
688 subsection{*Embedding of the Integers into any Ring: @{term of_int}*} |
677 |
689 |
678 constdefs |
690 constdefs |
679 of_int :: "int => 'a::ring" |
691 of_int :: "int => 'a::ring" |
680 "of_int z == |
692 "of_int z == contents (\<Union>(i,j) \<in> Rep_Integ(z). { of_nat i - of_nat j })" |
681 (THE a. \<exists>i j. (i,j) \<in> Rep_Integ z & a = (of_nat i) - (of_nat j))" |
|
682 |
693 |
683 |
694 |
684 lemma of_int: "of_int (Abs_Integ (intrel `` {(i,j)})) = of_nat i - of_nat j" |
695 lemma of_int: "of_int (Abs_Integ (intrel `` {(i,j)})) = of_nat i - of_nat j" |
685 apply (simp add: of_int_def) |
696 proof - |
686 apply (rule the_equality, auto) |
697 have "congruent intrel (\<lambda>(i,j). { of_nat i - (of_nat j :: 'a) })" |
687 apply (simp add: compare_rls add_ac of_nat_add [symmetric] |
698 by (simp add: congruent_def compare_rls of_nat_add [symmetric] |
688 del: of_nat_add) |
699 del: of_nat_add) |
689 done |
700 thus ?thesis |
|
701 by (simp add: of_int_def UN_equiv_class [OF equiv_intrel]) |
|
702 qed |
690 |
703 |
691 lemma of_int_0 [simp]: "of_int 0 = 0" |
704 lemma of_int_0 [simp]: "of_int 0 = 0" |
692 by (simp add: of_int Zero_int_def int_def) |
705 by (simp add: of_int Zero_int_def int_def) |
693 |
706 |
694 lemma of_int_1 [simp]: "of_int 1 = 1" |
707 lemma of_int_1 [simp]: "of_int 1 = 1" |
735 by (simp add: order_eq_iff) |
748 by (simp add: order_eq_iff) |
736 |
749 |
737 text{*Special cases where either operand is zero*} |
750 text{*Special cases where either operand is zero*} |
738 declare of_int_eq_iff [of 0, simplified, simp] |
751 declare of_int_eq_iff [of 0, simplified, simp] |
739 declare of_int_eq_iff [of _ 0, simplified, simp] |
752 declare of_int_eq_iff [of _ 0, simplified, simp] |
|
753 |
|
754 lemma of_int_eq_id [simp]: "of_int = (id :: int => int)" |
|
755 proof |
|
756 fix z |
|
757 show "of_int z = id z" |
|
758 by (cases z, |
|
759 simp add: of_int add minus int_eq_of_nat [symmetric] int_def diff_minus) |
|
760 qed |
740 |
761 |
741 |
762 |
742 subsection{*The Set of Integers*} |
763 subsection{*The Set of Integers*} |
743 |
764 |
744 constdefs |
765 constdefs |
884 done |
905 done |
885 |
906 |
886 lemma negD: "x<0 ==> \<exists>n. x = - (int (Suc n))" |
907 lemma negD: "x<0 ==> \<exists>n. x = - (int (Suc n))" |
887 apply (cases x) |
908 apply (cases x) |
888 apply (auto simp add: le minus Zero_int_def int_def order_less_le) |
909 apply (auto simp add: le minus Zero_int_def int_def order_less_le) |
889 apply (rule_tac x="y - Suc x" in exI) |
910 apply (rule_tac x="y - Suc x" in exI, arith) |
890 apply arith |
|
891 done |
911 done |
892 |
912 |
893 theorem int_cases [cases type: int, case_names nonneg neg]: |
913 theorem int_cases [cases type: int, case_names nonneg neg]: |
894 "[|!! n. z = int n ==> P; !! n. z = - (int (Suc n)) ==> P |] ==> P" |
914 "[|!! n. z = int n ==> P; !! n. z = - (int (Suc n)) ==> P |] ==> P" |
895 apply (case_tac "z < 0", blast dest!: negD) |
915 apply (case_tac "z < 0", blast dest!: negD) |
940 val int_def = thm "int_def"; |
960 val int_def = thm "int_def"; |
941 val Zero_int_def = thm "Zero_int_def"; |
961 val Zero_int_def = thm "Zero_int_def"; |
942 val One_int_def = thm "One_int_def"; |
962 val One_int_def = thm "One_int_def"; |
943 val diff_int_def = thm "diff_int_def"; |
963 val diff_int_def = thm "diff_int_def"; |
944 |
964 |
945 val intrel_iff = thm "intrel_iff"; |
|
946 val equiv_intrel = thm "equiv_intrel"; |
|
947 val equiv_intrel_iff = thm "equiv_intrel_iff"; |
|
948 val intrel_in_integ = thm "intrel_in_integ"; |
|
949 val inj_on_Abs_Integ = thm "inj_on_Abs_Integ"; |
|
950 val inj_int = thm "inj_int"; |
965 val inj_int = thm "inj_int"; |
951 val zminus_zminus = thm "zminus_zminus"; |
966 val zminus_zminus = thm "zminus_zminus"; |
952 val zminus_0 = thm "zminus_0"; |
967 val zminus_0 = thm "zminus_0"; |
953 val zminus_zadd_distrib = thm "zminus_zadd_distrib"; |
968 val zminus_zadd_distrib = thm "zminus_zadd_distrib"; |
954 val zadd_commute = thm "zadd_commute"; |
969 val zadd_commute = thm "zadd_commute"; |