20 |
20 |
21 typedef (Integ) |
21 typedef (Integ) |
22 int = "UNIV//intrel" |
22 int = "UNIV//intrel" |
23 by (auto simp add: quotient_def) |
23 by (auto simp add: quotient_def) |
24 |
24 |
25 instance int :: zero |
25 instantiation int :: "{zero, one, plus, minus, times, ord, abs, sgn}" |
26 Zero_int_def: "0 \<equiv> Abs_Integ (intrel `` {(0, 0)})" .. |
26 begin |
27 |
27 |
28 instance int :: one |
28 definition |
29 One_int_def: "1 \<equiv> Abs_Integ (intrel `` {(1, 0)})" .. |
29 Zero_int_def [code func del]: "0 = Abs_Integ (intrel `` {(0, 0)})" |
30 |
30 |
31 instance int :: plus |
31 definition |
32 add_int_def: "z + w \<equiv> Abs_Integ |
32 One_int_def [code func del]: "1 = Abs_Integ (intrel `` {(1, 0)})" |
|
33 |
|
34 definition |
|
35 add_int_def [code func del]: "z + w = Abs_Integ |
33 (\<Union>(x, y) \<in> Rep_Integ z. \<Union>(u, v) \<in> Rep_Integ w. |
36 (\<Union>(x, y) \<in> Rep_Integ z. \<Union>(u, v) \<in> Rep_Integ w. |
34 intrel `` {(x + u, y + v)})" .. |
37 intrel `` {(x + u, y + v)})" |
35 |
38 |
36 instance int :: minus |
39 definition |
37 minus_int_def: |
40 minus_int_def [code func del]: |
38 "- z \<equiv> Abs_Integ (\<Union>(x, y) \<in> Rep_Integ z. intrel `` {(y, x)})" |
41 "- z = Abs_Integ (\<Union>(x, y) \<in> Rep_Integ z. intrel `` {(y, x)})" |
39 diff_int_def: "z - w \<equiv> z + (-w \<Colon> int)" .. |
42 |
40 |
43 definition |
41 instance int :: times |
44 diff_int_def [code func del]: "z - w = z + (-w \<Colon> int)" |
42 mult_int_def: "z * w \<equiv> Abs_Integ |
45 |
|
46 definition |
|
47 mult_int_def [code func del]: "z * w = Abs_Integ |
43 (\<Union>(x, y) \<in> Rep_Integ z. \<Union>(u,v ) \<in> Rep_Integ w. |
48 (\<Union>(x, y) \<in> Rep_Integ z. \<Union>(u,v ) \<in> Rep_Integ w. |
44 intrel `` {(x*u + y*v, x*v + y*u)})" .. |
49 intrel `` {(x*u + y*v, x*v + y*u)})" |
45 |
50 |
46 instance int :: ord |
51 definition |
47 le_int_def: |
52 le_int_def [code func del]: |
48 "z \<le> w \<equiv> \<exists>x y u v. x+v \<le> u+y \<and> (x, y) \<in> Rep_Integ z \<and> (u, v) \<in> Rep_Integ w" |
53 "z \<le> w \<longleftrightarrow> (\<exists>x y u v. x+v \<le> u+y \<and> (x, y) \<in> Rep_Integ z \<and> (u, v) \<in> Rep_Integ w)" |
49 less_int_def: "(z\<Colon>int) < w \<equiv> z \<le> w \<and> z \<noteq> w" .. |
54 |
50 |
55 definition |
51 lemmas [code func del] = Zero_int_def One_int_def add_int_def |
56 less_int_def [code func del]: "(z\<Colon>int) < w \<longleftrightarrow> z \<le> w \<and> z \<noteq> w" |
52 minus_int_def mult_int_def le_int_def less_int_def |
57 |
|
58 definition |
|
59 zabs_def: "\<bar>i\<Colon>int\<bar> = (if i < 0 then - i else i)" |
|
60 |
|
61 definition |
|
62 zsgn_def: "sgn (i\<Colon>int) = (if i=0 then 0 else if 0<i then 1 else - 1)" |
|
63 |
|
64 instance .. |
|
65 |
|
66 end |
53 |
67 |
54 |
68 |
55 subsection{*Construction of the Integers*} |
69 subsection{*Construction of the Integers*} |
56 |
70 |
57 lemma intrel_iff [simp]: "(((x,y),(u,v)) \<in> intrel) = (x+v = u+y)" |
71 lemma intrel_iff [simp]: "(((x,y),(u,v)) \<in> intrel) = (x+v = u+y)" |
210 lemma zmult_zless_mono2: "[| i<j; (0::int) < k |] ==> k*i < k*j" |
224 lemma zmult_zless_mono2: "[| i<j; (0::int) < k |] ==> k*i < k*j" |
211 apply (drule zero_less_imp_eq_int) |
225 apply (drule zero_less_imp_eq_int) |
212 apply (auto simp add: zmult_zless_mono2_lemma) |
226 apply (auto simp add: zmult_zless_mono2_lemma) |
213 done |
227 done |
214 |
228 |
215 instance int :: abs |
229 instantiation int :: distrib_lattice |
216 zabs_def: "\<bar>i\<Colon>int\<bar> \<equiv> if i < 0 then - i else i" .. |
230 begin |
217 instance int :: sgn |
231 |
218 zsgn_def: "sgn(i\<Colon>int) \<equiv> (if i=0 then 0 else if 0<i then 1 else - 1)" .. |
232 definition |
219 |
233 "(inf \<Colon> int \<Rightarrow> int \<Rightarrow> int) = min" |
220 instance int :: distrib_lattice |
234 |
221 "inf \<Colon> int \<Rightarrow> int \<Rightarrow> int \<equiv> min" |
235 definition |
222 "sup \<Colon> int \<Rightarrow> int \<Rightarrow> int \<equiv> max" |
236 "(sup \<Colon> int \<Rightarrow> int \<Rightarrow> int) = max" |
|
237 |
|
238 instance |
223 by intro_classes |
239 by intro_classes |
224 (auto simp add: inf_int_def sup_int_def min_max.sup_inf_distrib1) |
240 (auto simp add: inf_int_def sup_int_def min_max.sup_inf_distrib1) |
|
241 |
|
242 end |
225 |
243 |
226 text{*The integers form an ordered integral domain*} |
244 text{*The integers form an ordered integral domain*} |
227 instance int :: ordered_idom |
245 instance int :: ordered_idom |
228 proof |
246 proof |
229 fix i j k :: int |
247 fix i j k :: int |
742 lemmas int_1 = of_nat_1 [where 'a=int] |
760 lemmas int_1 = of_nat_1 [where 'a=int] |
743 lemmas int_Suc = of_nat_Suc [where 'a=int] |
761 lemmas int_Suc = of_nat_Suc [where 'a=int] |
744 lemmas abs_int_eq = abs_of_nat [where 'a=int and n="m", standard] |
762 lemmas abs_int_eq = abs_of_nat [where 'a=int and n="m", standard] |
745 lemmas of_int_int_eq = of_int_of_nat_eq [where 'a=int] |
763 lemmas of_int_int_eq = of_int_of_nat_eq [where 'a=int] |
746 lemmas zdiff_int = of_nat_diff [where 'a=int, symmetric] |
764 lemmas zdiff_int = of_nat_diff [where 'a=int, symmetric] |
747 lemmas zless_le = less_int_def [THEN meta_eq_to_obj_eq] |
765 lemmas zless_le = less_int_def |
748 lemmas int_eq_of_nat = TrueI |
766 lemmas int_eq_of_nat = TrueI |
749 |
767 |
750 abbreviation |
768 abbreviation |
751 int :: "nat \<Rightarrow> int" |
769 int :: "nat \<Rightarrow> int" |
752 where |
770 where |