1 (* Title: ZF/Int_ZF.thy |
1 (* Title: ZF/Int_ZF.thy |
2 Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
2 Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
3 Copyright 1993 University of Cambridge |
3 Copyright 1993 University of Cambridge |
4 *) |
4 *) |
5 |
5 |
6 section{*The Integers as Equivalence Classes Over Pairs of Natural Numbers*} |
6 section\<open>The Integers as Equivalence Classes Over Pairs of Natural Numbers\<close> |
7 |
7 |
8 theory Int_ZF imports EquivClass ArithSimp begin |
8 theory Int_ZF imports EquivClass ArithSimp begin |
9 |
9 |
10 definition |
10 definition |
11 intrel :: i where |
11 intrel :: i where |
15 definition |
15 definition |
16 int :: i where |
16 int :: i where |
17 "int == (nat*nat)//intrel" |
17 "int == (nat*nat)//intrel" |
18 |
18 |
19 definition |
19 definition |
20 int_of :: "i=>i" --{*coercion from nat to int*} ("$# _" [80] 80) where |
20 int_of :: "i=>i" --\<open>coercion from nat to int\<close> ("$# _" [80] 80) where |
21 "$# m == intrel `` {<natify(m), 0>}" |
21 "$# m == intrel `` {<natify(m), 0>}" |
22 |
22 |
23 definition |
23 definition |
24 intify :: "i=>i" --{*coercion from ANYTHING to int*} where |
24 intify :: "i=>i" --\<open>coercion from ANYTHING to int\<close> where |
25 "intify(m) == if m \<in> int then m else $#0" |
25 "intify(m) == if m \<in> int then m else $#0" |
26 |
26 |
27 definition |
27 definition |
28 raw_zminus :: "i=>i" where |
28 raw_zminus :: "i=>i" where |
29 "raw_zminus(z) == \<Union><x,y>\<in>z. intrel``{<y,x>}" |
29 "raw_zminus(z) == \<Union><x,y>\<in>z. intrel``{<y,x>}" |
48 nat_of :: "i=>i" where |
48 nat_of :: "i=>i" where |
49 "nat_of(z) == raw_nat_of (intify(z))" |
49 "nat_of(z) == raw_nat_of (intify(z))" |
50 |
50 |
51 definition |
51 definition |
52 zmagnitude :: "i=>i" where |
52 zmagnitude :: "i=>i" where |
53 --{*could be replaced by an absolute value function from int to int?*} |
53 --\<open>could be replaced by an absolute value function from int to int?\<close> |
54 "zmagnitude(z) == |
54 "zmagnitude(z) == |
55 THE m. m\<in>nat & ((~ znegative(z) & z = $# m) | |
55 THE m. m\<in>nat & ((~ znegative(z) & z = $# m) | |
56 (znegative(z) & $- z = $# m))" |
56 (znegative(z) & $- z = $# m))" |
57 |
57 |
58 definition |
58 definition |
91 "z1 $<= z2 == z1 $< z2 | intify(z1)=intify(z2)" |
91 "z1 $<= z2 == z1 $< z2 | intify(z1)=intify(z2)" |
92 |
92 |
93 |
93 |
94 notation (xsymbols) |
94 notation (xsymbols) |
95 zmult (infixl "$\<times>" 70) and |
95 zmult (infixl "$\<times>" 70) and |
96 zle (infixl "$\<le>" 50) --{*less than or equals*} |
96 zle (infixl "$\<le>" 50) --\<open>less than or equals\<close> |
97 |
97 |
98 notation (HTML output) |
98 notation (HTML output) |
99 zmult (infixl "$\<times>" 70) and |
99 zmult (infixl "$\<times>" 70) and |
100 zle (infixl "$\<le>" 50) |
100 zle (infixl "$\<le>" 50) |
101 |
101 |
102 |
102 |
103 declare quotientE [elim!] |
103 declare quotientE [elim!] |
104 |
104 |
105 subsection{*Proving that @{term intrel} is an equivalence relation*} |
105 subsection\<open>Proving that @{term intrel} is an equivalence relation\<close> |
106 |
106 |
107 (** Natural deduction for intrel **) |
107 (** Natural deduction for intrel **) |
108 |
108 |
109 lemma intrel_iff [simp]: |
109 lemma intrel_iff [simp]: |
110 "<<x1,y1>,<x2,y2>>: intrel \<longleftrightarrow> |
110 "<<x1,y1>,<x2,y2>>: intrel \<longleftrightarrow> |
162 |
162 |
163 lemma intify_ident [simp]: "n \<in> int ==> intify(n) = n" |
163 lemma intify_ident [simp]: "n \<in> int ==> intify(n) = n" |
164 by (simp add: intify_def) |
164 by (simp add: intify_def) |
165 |
165 |
166 |
166 |
167 subsection{*Collapsing rules: to remove @{term intify} |
167 subsection\<open>Collapsing rules: to remove @{term intify} |
168 from arithmetic expressions*} |
168 from arithmetic expressions\<close> |
169 |
169 |
170 lemma intify_idem [simp]: "intify(intify(x)) = intify(x)" |
170 lemma intify_idem [simp]: "intify(intify(x)) = intify(x)" |
171 by simp |
171 by simp |
172 |
172 |
173 lemma int_of_natify [simp]: "$# (natify(m)) = $# m" |
173 lemma int_of_natify [simp]: "$# (natify(m)) = $# m" |
213 |
213 |
214 lemma zle_intify2 [simp]:"x $<= intify(y) \<longleftrightarrow> x $<= y" |
214 lemma zle_intify2 [simp]:"x $<= intify(y) \<longleftrightarrow> x $<= y" |
215 by (simp add: zle_def) |
215 by (simp add: zle_def) |
216 |
216 |
217 |
217 |
218 subsection{*@{term zminus}: unary negation on @{term int}*} |
218 subsection\<open>@{term zminus}: unary negation on @{term int}\<close> |
219 |
219 |
220 lemma zminus_congruent: "(%<x,y>. intrel``{<y,x>}) respects intrel" |
220 lemma zminus_congruent: "(%<x,y>. intrel``{<y,x>}) respects intrel" |
221 by (auto simp add: congruent_def add_ac) |
221 by (auto simp add: congruent_def add_ac) |
222 |
222 |
223 lemma raw_zminus_type: "z \<in> int ==> raw_zminus(z) \<in> int" |
223 lemma raw_zminus_type: "z \<in> int ==> raw_zminus(z) \<in> int" |
264 |
264 |
265 lemma zminus_zminus: "z \<in> int ==> $- ($- z) = z" |
265 lemma zminus_zminus: "z \<in> int ==> $- ($- z) = z" |
266 by simp |
266 by simp |
267 |
267 |
268 |
268 |
269 subsection{*@{term znegative}: the test for negative integers*} |
269 subsection\<open>@{term znegative}: the test for negative integers\<close> |
270 |
270 |
271 lemma znegative: "[| x\<in>nat; y\<in>nat |] ==> znegative(intrel``{<x,y>}) \<longleftrightarrow> x<y" |
271 lemma znegative: "[| x\<in>nat; y\<in>nat |] ==> znegative(intrel``{<x,y>}) \<longleftrightarrow> x<y" |
272 apply (cases "x<y") |
272 apply (cases "x<y") |
273 apply (auto simp add: znegative_def not_lt_iff_le) |
273 apply (auto simp add: znegative_def not_lt_iff_le) |
274 apply (subgoal_tac "y #+ x2 < x #+ y2", force) |
274 apply (subgoal_tac "y #+ x2 < x #+ y2", force) |
284 |
284 |
285 lemma not_znegative_imp_zero: "~ znegative($- $# n) ==> natify(n)=0" |
285 lemma not_znegative_imp_zero: "~ znegative($- $# n) ==> natify(n)=0" |
286 by (simp add: znegative int_of_def zminus Ord_0_lt_iff [THEN iff_sym]) |
286 by (simp add: znegative int_of_def zminus Ord_0_lt_iff [THEN iff_sym]) |
287 |
287 |
288 |
288 |
289 subsection{*@{term nat_of}: Coercion of an Integer to a Natural Number*} |
289 subsection\<open>@{term nat_of}: Coercion of an Integer to a Natural Number\<close> |
290 |
290 |
291 lemma nat_of_intify [simp]: "nat_of(intify(z)) = nat_of(z)" |
291 lemma nat_of_intify [simp]: "nat_of(intify(z)) = nat_of(z)" |
292 by (simp add: nat_of_def) |
292 by (simp add: nat_of_def) |
293 |
293 |
294 lemma nat_of_congruent: "(\<lambda>x. (\<lambda>\<langle>x,y\<rangle>. x #- y)(x)) respects intrel" |
294 lemma nat_of_congruent: "(\<lambda>x. (\<lambda>\<langle>x,y\<rangle>. x #- y)(x)) respects intrel" |
308 by (simp add: raw_nat_of_def) |
308 by (simp add: raw_nat_of_def) |
309 |
309 |
310 lemma nat_of_type [iff,TC]: "nat_of(z) \<in> nat" |
310 lemma nat_of_type [iff,TC]: "nat_of(z) \<in> nat" |
311 by (simp add: nat_of_def raw_nat_of_type) |
311 by (simp add: nat_of_def raw_nat_of_type) |
312 |
312 |
313 subsection{*zmagnitude: magnitide of an integer, as a natural number*} |
313 subsection\<open>zmagnitude: magnitide of an integer, as a natural number\<close> |
314 |
314 |
315 lemma zmagnitude_int_of [simp]: "zmagnitude($# n) = natify(n)" |
315 lemma zmagnitude_int_of [simp]: "zmagnitude($# n) = natify(n)" |
316 by (auto simp add: zmagnitude_def int_of_eq) |
316 by (auto simp add: zmagnitude_def int_of_eq) |
317 |
317 |
318 lemma natify_int_of_eq: "natify(x)=n ==> $#x = $# n" |
318 lemma natify_int_of_eq: "natify(x)=n ==> $#x = $# n" |
378 apply (auto simp add: znegative nat_of_def raw_nat_of |
378 apply (auto simp add: znegative nat_of_def raw_nat_of |
379 split add: nat_diff_split) |
379 split add: nat_diff_split) |
380 done |
380 done |
381 |
381 |
382 |
382 |
383 subsection{*@{term zadd}: addition on int*} |
383 subsection\<open>@{term zadd}: addition on int\<close> |
384 |
384 |
385 text{*Congruence Property for Addition*} |
385 text\<open>Congruence Property for Addition\<close> |
386 lemma zadd_congruent2: |
386 lemma zadd_congruent2: |
387 "(%z1 z2. let <x1,y1>=z1; <x2,y2>=z2 |
387 "(%z1 z2. let <x1,y1>=z1; <x2,y2>=z2 |
388 in intrel``{<x1#+x2, y1#+y2>}) |
388 in intrel``{<x1#+x2, y1#+y2>}) |
389 respects2 intrel" |
389 respects2 intrel" |
390 apply (simp add: congruent2_def) |
390 apply (simp add: congruent2_def) |
492 |
492 |
493 lemma zadd_int0_right: "z \<in> int ==> z $+ $#0 = z" |
493 lemma zadd_int0_right: "z \<in> int ==> z $+ $#0 = z" |
494 by simp |
494 by simp |
495 |
495 |
496 |
496 |
497 subsection{*@{term zmult}: Integer Multiplication*} |
497 subsection\<open>@{term zmult}: Integer Multiplication\<close> |
498 |
498 |
499 text{*Congruence property for multiplication*} |
499 text\<open>Congruence property for multiplication\<close> |
500 lemma zmult_congruent2: |
500 lemma zmult_congruent2: |
501 "(%p1 p2. split(%x1 y1. split(%x2 y2. |
501 "(%p1 p2. split(%x1 y1. split(%x2 y2. |
502 intrel``{<x1#*x2 #+ y1#*y2, x1#*y2 #+ y1#*x2>}, p2), p1)) |
502 intrel``{<x1#*x2 #+ y1#*y2, x1#*y2 #+ y1#*x2>}, p2), p1)) |
503 respects2 intrel" |
503 respects2 intrel" |
504 apply (rule equiv_intrel [THEN congruent2_commuteI], auto) |
504 apply (rule equiv_intrel [THEN congruent2_commuteI], auto) |
623 |
623 |
624 lemma zdiff_zadd_eq: "(x $- y) $+ z = (x $+ z) $- y" |
624 lemma zdiff_zadd_eq: "(x $- y) $+ z = (x $+ z) $- y" |
625 by (simp add: zdiff_def zadd_ac) |
625 by (simp add: zdiff_def zadd_ac) |
626 |
626 |
627 |
627 |
628 subsection{*The "Less Than" Relation*} |
628 subsection\<open>The "Less Than" Relation\<close> |
629 |
629 |
630 (*"Less than" is a linear ordering*) |
630 (*"Less than" is a linear ordering*) |
631 lemma zless_linear_lemma: |
631 lemma zless_linear_lemma: |
632 "[| z \<in> int; w \<in> int |] ==> z$<w | z=w | w$<z" |
632 "[| z \<in> int; w \<in> int |] ==> z$<w | z=w | w$<z" |
633 apply (simp add: int_def zless_def znegative_def zdiff_def, auto) |
633 apply (simp add: int_def zless_def znegative_def zdiff_def, auto) |
727 apply (simp add: zle_def) |
727 apply (simp add: zle_def) |
728 apply (cut_tac zless_linear, blast) |
728 apply (cut_tac zless_linear, blast) |
729 done |
729 done |
730 |
730 |
731 |
731 |
732 subsection{*Less Than or Equals*} |
732 subsection\<open>Less Than or Equals\<close> |
733 |
733 |
734 lemma zle_refl: "z $<= z" |
734 lemma zle_refl: "z $<= z" |
735 by (simp add: zle_def) |
735 by (simp add: zle_def) |
736 |
736 |
737 lemma zle_eq_refl: "x=y ==> x $<= y" |
737 lemma zle_eq_refl: "x=y ==> x $<= y" |
777 |
777 |
778 lemma not_zle_iff_zless: "~ (z $<= w) \<longleftrightarrow> (w $< z)" |
778 lemma not_zle_iff_zless: "~ (z $<= w) \<longleftrightarrow> (w $< z)" |
779 by (simp add: not_zless_iff_zle [THEN iff_sym]) |
779 by (simp add: not_zless_iff_zle [THEN iff_sym]) |
780 |
780 |
781 |
781 |
782 subsection{*More subtraction laws (for @{text zcompare_rls})*} |
782 subsection\<open>More subtraction laws (for @{text zcompare_rls})\<close> |
783 |
783 |
784 lemma zdiff_zdiff_eq: "(x $- y) $- z = x $- (y $+ z)" |
784 lemma zdiff_zdiff_eq: "(x $- y) $- z = x $- (y $+ z)" |
785 by (simp add: zdiff_def zadd_ac) |
785 by (simp add: zdiff_def zadd_ac) |
786 |
786 |
787 lemma zdiff_zdiff_eq2: "x $- (y $- z) = (x $+ z) $- y" |
787 lemma zdiff_zdiff_eq2: "x $- (y $- z) = (x $+ z) $- y" |
813 done |
813 done |
814 |
814 |
815 lemma zle_zdiff_iff: "(x $<= z$-y) \<longleftrightarrow> (x $+ y $<= z)" |
815 lemma zle_zdiff_iff: "(x $<= z$-y) \<longleftrightarrow> (x $+ y $<= z)" |
816 by (cut_tac zle_zdiff_iff_lemma [ OF intify_in_int intify_in_int], simp) |
816 by (cut_tac zle_zdiff_iff_lemma [ OF intify_in_int intify_in_int], simp) |
817 |
817 |
818 text{*This list of rewrites simplifies (in)equalities by bringing subtractions |
818 text\<open>This list of rewrites simplifies (in)equalities by bringing subtractions |
819 to the top and then moving negative terms to the other side. |
819 to the top and then moving negative terms to the other side. |
820 Use with @{text zadd_ac}*} |
820 Use with @{text zadd_ac}\<close> |
821 lemmas zcompare_rls = |
821 lemmas zcompare_rls = |
822 zdiff_def [symmetric] |
822 zdiff_def [symmetric] |
823 zadd_zdiff_eq zdiff_zadd_eq zdiff_zdiff_eq zdiff_zdiff_eq2 |
823 zadd_zdiff_eq zdiff_zadd_eq zdiff_zdiff_eq zdiff_zdiff_eq2 |
824 zdiff_zless_iff zless_zdiff_iff zdiff_zle_iff zle_zdiff_iff |
824 zdiff_zless_iff zless_zdiff_iff zdiff_zle_iff zle_zdiff_iff |
825 zdiff_eq_iff eq_zdiff_iff |
825 zdiff_eq_iff eq_zdiff_iff |
826 |
826 |
827 |
827 |
828 subsection{*Monotonicity and Cancellation Results for Instantiation |
828 subsection\<open>Monotonicity and Cancellation Results for Instantiation |
829 of the CancelNumerals Simprocs*} |
829 of the CancelNumerals Simprocs\<close> |
830 |
830 |
831 lemma zadd_left_cancel: |
831 lemma zadd_left_cancel: |
832 "[| w \<in> int; w': int |] ==> (z $+ w' = z $+ w) \<longleftrightarrow> (w' = w)" |
832 "[| w \<in> int; w': int |] ==> (z $+ w' = z $+ w) \<longleftrightarrow> (w' = w)" |
833 apply safe |
833 apply safe |
834 apply (drule_tac t = "%x. x $+ ($-z) " in subst_context) |
834 apply (drule_tac t = "%x. x $+ ($-z) " in subst_context) |
884 |
884 |
885 lemma zadd_zless_mono: "[| w' $< w; z' $<= z |] ==> w' $+ z' $< w $+ z" |
885 lemma zadd_zless_mono: "[| w' $< w; z' $<= z |] ==> w' $+ z' $< w $+ z" |
886 by (erule zadd_zless_mono1 [THEN zless_zle_trans], simp) |
886 by (erule zadd_zless_mono1 [THEN zless_zle_trans], simp) |
887 |
887 |
888 |
888 |
889 subsection{*Comparison laws*} |
889 subsection\<open>Comparison laws\<close> |
890 |
890 |
891 lemma zminus_zless_zminus [simp]: "($- x $< $- y) \<longleftrightarrow> (y $< x)" |
891 lemma zminus_zless_zminus [simp]: "($- x $< $- y) \<longleftrightarrow> (y $< x)" |
892 by (simp add: zless_def zdiff_def zadd_ac) |
892 by (simp add: zless_def zdiff_def zadd_ac) |
893 |
893 |
894 lemma zminus_zle_zminus [simp]: "($- x $<= $- y) \<longleftrightarrow> (y $<= x)" |
894 lemma zminus_zle_zminus [simp]: "($- x $<= $- y) \<longleftrightarrow> (y $<= x)" |
895 by (simp add: not_zless_iff_zle [THEN iff_sym]) |
895 by (simp add: not_zless_iff_zle [THEN iff_sym]) |
896 |
896 |
897 subsubsection{*More inequality lemmas*} |
897 subsubsection\<open>More inequality lemmas\<close> |
898 |
898 |
899 lemma equation_zminus: "[| x \<in> int; y \<in> int |] ==> (x = $- y) \<longleftrightarrow> (y = $- x)" |
899 lemma equation_zminus: "[| x \<in> int; y \<in> int |] ==> (x = $- y) \<longleftrightarrow> (y = $- x)" |
900 by auto |
900 by auto |
901 |
901 |
902 lemma zminus_equation: "[| x \<in> int; y \<in> int |] ==> ($- x = y) \<longleftrightarrow> ($- y = x)" |
902 lemma zminus_equation: "[| x \<in> int; y \<in> int |] ==> ($- x = y) \<longleftrightarrow> ($- y = x)" |
911 apply (cut_tac x = "intify (x) " and y = "intify (y) " in zminus_equation) |
911 apply (cut_tac x = "intify (x) " and y = "intify (y) " in zminus_equation) |
912 apply auto |
912 apply auto |
913 done |
913 done |
914 |
914 |
915 |
915 |
916 subsubsection{*The next several equations are permutative: watch out!*} |
916 subsubsection\<open>The next several equations are permutative: watch out!\<close> |
917 |
917 |
918 lemma zless_zminus: "(x $< $- y) \<longleftrightarrow> (y $< $- x)" |
918 lemma zless_zminus: "(x $< $- y) \<longleftrightarrow> (y $< $- x)" |
919 by (simp add: zless_def zdiff_def zadd_ac) |
919 by (simp add: zless_def zdiff_def zadd_ac) |
920 |
920 |
921 lemma zminus_zless: "($- x $< y) \<longleftrightarrow> ($- y $< x)" |
921 lemma zminus_zless: "($- x $< y) \<longleftrightarrow> ($- y $< x)" |