author | wenzelm |
Wed, 29 Aug 2007 11:10:28 +0200 | |
changeset 24470 | 41c81e23c08d |
parent 24355 | 93d78fdeb55a |
child 24506 | 020db6ec334a |
permissions | -rw-r--r-- |
23164 | 1 |
(* Title: IntDef.thy |
2 |
ID: $Id$ |
|
3 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
|
4 |
Copyright 1996 University of Cambridge |
|
5 |
||
6 |
*) |
|
7 |
||
8 |
header{*The Integers as Equivalence Classes over Pairs of Natural Numbers*} |
|
9 |
||
10 |
theory IntDef |
|
11 |
imports Equiv_Relations Nat |
|
12 |
begin |
|
13 |
||
23705 | 14 |
|
23164 | 15 |
text {* the equivalence relation underlying the integers *} |
16 |
||
17 |
definition |
|
18 |
intrel :: "((nat \<times> nat) \<times> (nat \<times> nat)) set" |
|
19 |
where |
|
20 |
"intrel = {((x, y), (u, v)) | x y u v. x + v = u +y }" |
|
21 |
||
22 |
typedef (Integ) |
|
23 |
int = "UNIV//intrel" |
|
24 |
by (auto simp add: quotient_def) |
|
25 |
||
26 |
instance int :: zero |
|
23299
292b1cbd05dc
remove dependencies of proofs on constant int::nat=>int, preparing to remove it
huffman
parents:
23282
diff
changeset
|
27 |
Zero_int_def: "0 \<equiv> Abs_Integ (intrel `` {(0, 0)})" .. |
23164 | 28 |
|
29 |
instance int :: one |
|
23299
292b1cbd05dc
remove dependencies of proofs on constant int::nat=>int, preparing to remove it
huffman
parents:
23282
diff
changeset
|
30 |
One_int_def: "1 \<equiv> Abs_Integ (intrel `` {(1, 0)})" .. |
23164 | 31 |
|
32 |
instance int :: plus |
|
33 |
add_int_def: "z + w \<equiv> Abs_Integ |
|
34 |
(\<Union>(x, y) \<in> Rep_Integ z. \<Union>(u, v) \<in> Rep_Integ w. |
|
35 |
intrel `` {(x + u, y + v)})" .. |
|
36 |
||
37 |
instance int :: minus |
|
38 |
minus_int_def: |
|
39 |
"- z \<equiv> Abs_Integ (\<Union>(x, y) \<in> Rep_Integ z. intrel `` {(y, x)})" |
|
40 |
diff_int_def: "z - w \<equiv> z + (-w)" .. |
|
41 |
||
42 |
instance int :: times |
|
43 |
mult_int_def: "z * w \<equiv> Abs_Integ |
|
44 |
(\<Union>(x, y) \<in> Rep_Integ z. \<Union>(u,v ) \<in> Rep_Integ w. |
|
45 |
intrel `` {(x*u + y*v, x*v + y*u)})" .. |
|
46 |
||
47 |
instance int :: ord |
|
48 |
le_int_def: |
|
49 |
"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" |
|
50 |
less_int_def: "z < w \<equiv> z \<le> w \<and> z \<noteq> w" .. |
|
51 |
||
52 |
lemmas [code func del] = Zero_int_def One_int_def add_int_def |
|
53 |
minus_int_def mult_int_def le_int_def less_int_def |
|
54 |
||
55 |
||
56 |
subsection{*Construction of the Integers*} |
|
57 |
||
58 |
lemma intrel_iff [simp]: "(((x,y),(u,v)) \<in> intrel) = (x+v = u+y)" |
|
59 |
by (simp add: intrel_def) |
|
60 |
||
61 |
lemma equiv_intrel: "equiv UNIV intrel" |
|
62 |
by (simp add: intrel_def equiv_def refl_def sym_def trans_def) |
|
63 |
||
64 |
text{*Reduces equality of equivalence classes to the @{term intrel} relation: |
|
65 |
@{term "(intrel `` {x} = intrel `` {y}) = ((x,y) \<in> intrel)"} *} |
|
66 |
lemmas equiv_intrel_iff [simp] = eq_equiv_class_iff [OF equiv_intrel UNIV_I UNIV_I] |
|
67 |
||
68 |
text{*All equivalence classes belong to set of representatives*} |
|
69 |
lemma [simp]: "intrel``{(x,y)} \<in> Integ" |
|
70 |
by (auto simp add: Integ_def intrel_def quotient_def) |
|
71 |
||
72 |
text{*Reduces equality on abstractions to equality on representatives: |
|
73 |
@{prop "\<lbrakk>x \<in> Integ; y \<in> Integ\<rbrakk> \<Longrightarrow> (Abs_Integ x = Abs_Integ y) = (x=y)"} *} |
|
24286
7619080e49f0
ATP blacklisting is now in theory data, attribute noatp
paulson
parents:
24196
diff
changeset
|
74 |
declare Abs_Integ_inject [simp,noatp] Abs_Integ_inverse [simp,noatp] |
23164 | 75 |
|
76 |
text{*Case analysis on the representation of an integer as an equivalence |
|
77 |
class of pairs of naturals.*} |
|
78 |
lemma eq_Abs_Integ [case_names Abs_Integ, cases type: int]: |
|
79 |
"(!!x y. z = Abs_Integ(intrel``{(x,y)}) ==> P) ==> P" |
|
80 |
apply (rule Abs_Integ_cases [of z]) |
|
81 |
apply (auto simp add: Integ_def quotient_def) |
|
82 |
done |
|
83 |
||
84 |
||
23372
0035be079bee
clean up instance proofs; reorganize section headings
huffman
parents:
23365
diff
changeset
|
85 |
subsection{*Arithmetic Operations*} |
23164 | 86 |
|
87 |
lemma minus: "- Abs_Integ(intrel``{(x,y)}) = Abs_Integ(intrel `` {(y,x)})" |
|
88 |
proof - |
|
89 |
have "(\<lambda>(x,y). intrel``{(y,x)}) respects intrel" |
|
90 |
by (simp add: congruent_def) |
|
91 |
thus ?thesis |
|
92 |
by (simp add: minus_int_def UN_equiv_class [OF equiv_intrel]) |
|
93 |
qed |
|
94 |
||
95 |
lemma add: |
|
96 |
"Abs_Integ (intrel``{(x,y)}) + Abs_Integ (intrel``{(u,v)}) = |
|
97 |
Abs_Integ (intrel``{(x+u, y+v)})" |
|
98 |
proof - |
|
99 |
have "(\<lambda>z w. (\<lambda>(x,y). (\<lambda>(u,v). intrel `` {(x+u, y+v)}) w) z) |
|
100 |
respects2 intrel" |
|
101 |
by (simp add: congruent2_def) |
|
102 |
thus ?thesis |
|
103 |
by (simp add: add_int_def UN_UN_split_split_eq |
|
104 |
UN_equiv_class2 [OF equiv_intrel equiv_intrel]) |
|
105 |
qed |
|
106 |
||
107 |
text{*Congruence property for multiplication*} |
|
108 |
lemma mult_congruent2: |
|
109 |
"(%p1 p2. (%(x,y). (%(u,v). intrel``{(x*u + y*v, x*v + y*u)}) p2) p1) |
|
110 |
respects2 intrel" |
|
111 |
apply (rule equiv_intrel [THEN congruent2_commuteI]) |
|
112 |
apply (force simp add: mult_ac, clarify) |
|
113 |
apply (simp add: congruent_def mult_ac) |
|
114 |
apply (rename_tac u v w x y z) |
|
115 |
apply (subgoal_tac "u*y + x*y = w*y + v*y & u*z + x*z = w*z + v*z") |
|
116 |
apply (simp add: mult_ac) |
|
117 |
apply (simp add: add_mult_distrib [symmetric]) |
|
118 |
done |
|
119 |
||
120 |
lemma mult: |
|
121 |
"Abs_Integ((intrel``{(x,y)})) * Abs_Integ((intrel``{(u,v)})) = |
|
122 |
Abs_Integ(intrel `` {(x*u + y*v, x*v + y*u)})" |
|
123 |
by (simp add: mult_int_def UN_UN_split_split_eq mult_congruent2 |
|
124 |
UN_equiv_class2 [OF equiv_intrel equiv_intrel]) |
|
125 |
||
126 |
text{*The integers form a @{text comm_ring_1}*} |
|
127 |
instance int :: comm_ring_1 |
|
128 |
proof |
|
129 |
fix i j k :: int |
|
23372
0035be079bee
clean up instance proofs; reorganize section headings
huffman
parents:
23365
diff
changeset
|
130 |
show "(i + j) + k = i + (j + k)" |
0035be079bee
clean up instance proofs; reorganize section headings
huffman
parents:
23365
diff
changeset
|
131 |
by (cases i, cases j, cases k) (simp add: add add_assoc) |
0035be079bee
clean up instance proofs; reorganize section headings
huffman
parents:
23365
diff
changeset
|
132 |
show "i + j = j + i" |
0035be079bee
clean up instance proofs; reorganize section headings
huffman
parents:
23365
diff
changeset
|
133 |
by (cases i, cases j) (simp add: add_ac add) |
0035be079bee
clean up instance proofs; reorganize section headings
huffman
parents:
23365
diff
changeset
|
134 |
show "0 + i = i" |
0035be079bee
clean up instance proofs; reorganize section headings
huffman
parents:
23365
diff
changeset
|
135 |
by (cases i) (simp add: Zero_int_def add) |
0035be079bee
clean up instance proofs; reorganize section headings
huffman
parents:
23365
diff
changeset
|
136 |
show "- i + i = 0" |
0035be079bee
clean up instance proofs; reorganize section headings
huffman
parents:
23365
diff
changeset
|
137 |
by (cases i) (simp add: Zero_int_def minus add) |
0035be079bee
clean up instance proofs; reorganize section headings
huffman
parents:
23365
diff
changeset
|
138 |
show "i - j = i + - j" |
0035be079bee
clean up instance proofs; reorganize section headings
huffman
parents:
23365
diff
changeset
|
139 |
by (simp add: diff_int_def) |
0035be079bee
clean up instance proofs; reorganize section headings
huffman
parents:
23365
diff
changeset
|
140 |
show "(i * j) * k = i * (j * k)" |
23477
f4b83f03cac9
tuned and renamed group_eq_simps and ring_eq_simps
nipkow
parents:
23438
diff
changeset
|
141 |
by (cases i, cases j, cases k) (simp add: mult ring_simps) |
23372
0035be079bee
clean up instance proofs; reorganize section headings
huffman
parents:
23365
diff
changeset
|
142 |
show "i * j = j * i" |
23477
f4b83f03cac9
tuned and renamed group_eq_simps and ring_eq_simps
nipkow
parents:
23438
diff
changeset
|
143 |
by (cases i, cases j) (simp add: mult ring_simps) |
23372
0035be079bee
clean up instance proofs; reorganize section headings
huffman
parents:
23365
diff
changeset
|
144 |
show "1 * i = i" |
0035be079bee
clean up instance proofs; reorganize section headings
huffman
parents:
23365
diff
changeset
|
145 |
by (cases i) (simp add: One_int_def mult) |
0035be079bee
clean up instance proofs; reorganize section headings
huffman
parents:
23365
diff
changeset
|
146 |
show "(i + j) * k = i * k + j * k" |
23477
f4b83f03cac9
tuned and renamed group_eq_simps and ring_eq_simps
nipkow
parents:
23438
diff
changeset
|
147 |
by (cases i, cases j, cases k) (simp add: add mult ring_simps) |
23372
0035be079bee
clean up instance proofs; reorganize section headings
huffman
parents:
23365
diff
changeset
|
148 |
show "0 \<noteq> (1::int)" |
0035be079bee
clean up instance proofs; reorganize section headings
huffman
parents:
23365
diff
changeset
|
149 |
by (simp add: Zero_int_def One_int_def) |
23164 | 150 |
qed |
151 |
||
24196 | 152 |
lemma int_def: "of_nat m = Abs_Integ (intrel `` {(m, 0)})" |
23365 | 153 |
by (induct m, simp_all add: Zero_int_def One_int_def add) |
23303
6091e530ff77
add abbreviation int_of_nat for of_nat::nat=>int;
huffman
parents:
23299
diff
changeset
|
154 |
|
23164 | 155 |
|
156 |
subsection{*The @{text "\<le>"} Ordering*} |
|
157 |
||
158 |
lemma le: |
|
159 |
"(Abs_Integ(intrel``{(x,y)}) \<le> Abs_Integ(intrel``{(u,v)})) = (x+v \<le> u+y)" |
|
160 |
by (force simp add: le_int_def) |
|
161 |
||
23299
292b1cbd05dc
remove dependencies of proofs on constant int::nat=>int, preparing to remove it
huffman
parents:
23282
diff
changeset
|
162 |
lemma less: |
292b1cbd05dc
remove dependencies of proofs on constant int::nat=>int, preparing to remove it
huffman
parents:
23282
diff
changeset
|
163 |
"(Abs_Integ(intrel``{(x,y)}) < Abs_Integ(intrel``{(u,v)})) = (x+v < u+y)" |
292b1cbd05dc
remove dependencies of proofs on constant int::nat=>int, preparing to remove it
huffman
parents:
23282
diff
changeset
|
164 |
by (simp add: less_int_def le order_less_le) |
292b1cbd05dc
remove dependencies of proofs on constant int::nat=>int, preparing to remove it
huffman
parents:
23282
diff
changeset
|
165 |
|
23164 | 166 |
instance int :: linorder |
23372
0035be079bee
clean up instance proofs; reorganize section headings
huffman
parents:
23365
diff
changeset
|
167 |
proof |
0035be079bee
clean up instance proofs; reorganize section headings
huffman
parents:
23365
diff
changeset
|
168 |
fix i j k :: int |
0035be079bee
clean up instance proofs; reorganize section headings
huffman
parents:
23365
diff
changeset
|
169 |
show "(i < j) = (i \<le> j \<and> i \<noteq> j)" |
0035be079bee
clean up instance proofs; reorganize section headings
huffman
parents:
23365
diff
changeset
|
170 |
by (simp add: less_int_def) |
0035be079bee
clean up instance proofs; reorganize section headings
huffman
parents:
23365
diff
changeset
|
171 |
show "i \<le> i" |
0035be079bee
clean up instance proofs; reorganize section headings
huffman
parents:
23365
diff
changeset
|
172 |
by (cases i) (simp add: le) |
0035be079bee
clean up instance proofs; reorganize section headings
huffman
parents:
23365
diff
changeset
|
173 |
show "i \<le> j \<Longrightarrow> j \<le> k \<Longrightarrow> i \<le> k" |
0035be079bee
clean up instance proofs; reorganize section headings
huffman
parents:
23365
diff
changeset
|
174 |
by (cases i, cases j, cases k) (simp add: le) |
0035be079bee
clean up instance proofs; reorganize section headings
huffman
parents:
23365
diff
changeset
|
175 |
show "i \<le> j \<Longrightarrow> j \<le> i \<Longrightarrow> i = j" |
0035be079bee
clean up instance proofs; reorganize section headings
huffman
parents:
23365
diff
changeset
|
176 |
by (cases i, cases j) (simp add: le) |
0035be079bee
clean up instance proofs; reorganize section headings
huffman
parents:
23365
diff
changeset
|
177 |
show "i \<le> j \<or> j \<le> i" |
0035be079bee
clean up instance proofs; reorganize section headings
huffman
parents:
23365
diff
changeset
|
178 |
by (cases i, cases j) (simp add: le linorder_linear) |
0035be079bee
clean up instance proofs; reorganize section headings
huffman
parents:
23365
diff
changeset
|
179 |
qed |
23164 | 180 |
|
23299
292b1cbd05dc
remove dependencies of proofs on constant int::nat=>int, preparing to remove it
huffman
parents:
23282
diff
changeset
|
181 |
instance int :: pordered_cancel_ab_semigroup_add |
292b1cbd05dc
remove dependencies of proofs on constant int::nat=>int, preparing to remove it
huffman
parents:
23282
diff
changeset
|
182 |
proof |
23372
0035be079bee
clean up instance proofs; reorganize section headings
huffman
parents:
23365
diff
changeset
|
183 |
fix i j k :: int |
0035be079bee
clean up instance proofs; reorganize section headings
huffman
parents:
23365
diff
changeset
|
184 |
show "i \<le> j \<Longrightarrow> k + i \<le> k + j" |
0035be079bee
clean up instance proofs; reorganize section headings
huffman
parents:
23365
diff
changeset
|
185 |
by (cases i, cases j, cases k) (simp add: le add) |
23299
292b1cbd05dc
remove dependencies of proofs on constant int::nat=>int, preparing to remove it
huffman
parents:
23282
diff
changeset
|
186 |
qed |
292b1cbd05dc
remove dependencies of proofs on constant int::nat=>int, preparing to remove it
huffman
parents:
23282
diff
changeset
|
187 |
|
23372
0035be079bee
clean up instance proofs; reorganize section headings
huffman
parents:
23365
diff
changeset
|
188 |
text{*Strict Monotonicity of Multiplication*} |
23164 | 189 |
|
190 |
text{*strict, in 1st argument; proof is by induction on k>0*} |
|
191 |
lemma zmult_zless_mono2_lemma: |
|
24196 | 192 |
"(i::int)<j ==> 0<k ==> of_nat k * i < of_nat k * j" |
23164 | 193 |
apply (induct "k", simp) |
23299
292b1cbd05dc
remove dependencies of proofs on constant int::nat=>int, preparing to remove it
huffman
parents:
23282
diff
changeset
|
194 |
apply (simp add: left_distrib) |
23164 | 195 |
apply (case_tac "k=0") |
23299
292b1cbd05dc
remove dependencies of proofs on constant int::nat=>int, preparing to remove it
huffman
parents:
23282
diff
changeset
|
196 |
apply (simp_all add: add_strict_mono) |
23164 | 197 |
done |
198 |
||
24196 | 199 |
lemma zero_le_imp_eq_int: "(0::int) \<le> k ==> \<exists>n. k = of_nat n" |
23164 | 200 |
apply (cases k) |
23365 | 201 |
apply (auto simp add: le add int_def Zero_int_def) |
23299
292b1cbd05dc
remove dependencies of proofs on constant int::nat=>int, preparing to remove it
huffman
parents:
23282
diff
changeset
|
202 |
apply (rule_tac x="x-y" in exI, simp) |
292b1cbd05dc
remove dependencies of proofs on constant int::nat=>int, preparing to remove it
huffman
parents:
23282
diff
changeset
|
203 |
done |
292b1cbd05dc
remove dependencies of proofs on constant int::nat=>int, preparing to remove it
huffman
parents:
23282
diff
changeset
|
204 |
|
24196 | 205 |
lemma zero_less_imp_eq_int: "(0::int) < k ==> \<exists>n>0. k = of_nat n" |
23299
292b1cbd05dc
remove dependencies of proofs on constant int::nat=>int, preparing to remove it
huffman
parents:
23282
diff
changeset
|
206 |
apply (cases k) |
23365 | 207 |
apply (simp add: less int_def Zero_int_def) |
23164 | 208 |
apply (rule_tac x="x-y" in exI, simp) |
209 |
done |
|
210 |
||
211 |
lemma zmult_zless_mono2: "[| i<j; (0::int) < k |] ==> k*i < k*j" |
|
23299
292b1cbd05dc
remove dependencies of proofs on constant int::nat=>int, preparing to remove it
huffman
parents:
23282
diff
changeset
|
212 |
apply (drule zero_less_imp_eq_int) |
23164 | 213 |
apply (auto simp add: zmult_zless_mono2_lemma) |
214 |
done |
|
215 |
||
23879 | 216 |
instance int :: abs |
23164 | 217 |
zabs_def: "\<bar>i\<Colon>int\<bar> \<equiv> if i < 0 then - i else i" .. |
218 |
||
219 |
instance int :: distrib_lattice |
|
220 |
"inf \<equiv> min" |
|
221 |
"sup \<equiv> max" |
|
222 |
by intro_classes |
|
223 |
(auto simp add: inf_int_def sup_int_def min_max.sup_inf_distrib1) |
|
224 |
||
23299
292b1cbd05dc
remove dependencies of proofs on constant int::nat=>int, preparing to remove it
huffman
parents:
23282
diff
changeset
|
225 |
text{*The integers form an ordered integral domain*} |
23164 | 226 |
instance int :: ordered_idom |
227 |
proof |
|
228 |
fix i j k :: int |
|
23372
0035be079bee
clean up instance proofs; reorganize section headings
huffman
parents:
23365
diff
changeset
|
229 |
show "i < j \<Longrightarrow> 0 < k \<Longrightarrow> k * i < k * j" |
0035be079bee
clean up instance proofs; reorganize section headings
huffman
parents:
23365
diff
changeset
|
230 |
by (rule zmult_zless_mono2) |
0035be079bee
clean up instance proofs; reorganize section headings
huffman
parents:
23365
diff
changeset
|
231 |
show "\<bar>i\<bar> = (if i < 0 then -i else i)" |
0035be079bee
clean up instance proofs; reorganize section headings
huffman
parents:
23365
diff
changeset
|
232 |
by (simp only: zabs_def) |
23164 | 233 |
qed |
234 |
||
235 |
lemma zless_imp_add1_zle: "w<z ==> w + (1::int) \<le> z" |
|
236 |
apply (cases w, cases z) |
|
23299
292b1cbd05dc
remove dependencies of proofs on constant int::nat=>int, preparing to remove it
huffman
parents:
23282
diff
changeset
|
237 |
apply (simp add: less le add One_int_def) |
23164 | 238 |
done |
239 |
||
23299
292b1cbd05dc
remove dependencies of proofs on constant int::nat=>int, preparing to remove it
huffman
parents:
23282
diff
changeset
|
240 |
|
292b1cbd05dc
remove dependencies of proofs on constant int::nat=>int, preparing to remove it
huffman
parents:
23282
diff
changeset
|
241 |
subsection{*Magnitude of an Integer, as a Natural Number: @{term nat}*} |
23164 | 242 |
|
243 |
definition |
|
244 |
nat :: "int \<Rightarrow> nat" |
|
245 |
where |
|
246 |
[code func del]: "nat z = contents (\<Union>(x, y) \<in> Rep_Integ z. {x-y})" |
|
247 |
||
248 |
lemma nat: "nat (Abs_Integ (intrel``{(x,y)})) = x-y" |
|
249 |
proof - |
|
250 |
have "(\<lambda>(x,y). {x-y}) respects intrel" |
|
251 |
by (simp add: congruent_def) arith |
|
252 |
thus ?thesis |
|
253 |
by (simp add: nat_def UN_equiv_class [OF equiv_intrel]) |
|
254 |
qed |
|
255 |
||
24196 | 256 |
lemma nat_int [simp]: "nat (of_nat n) = n" |
23365 | 257 |
by (simp add: nat int_def) |
23164 | 258 |
|
259 |
lemma nat_zero [simp]: "nat 0 = 0" |
|
23303
6091e530ff77
add abbreviation int_of_nat for of_nat::nat=>int;
huffman
parents:
23299
diff
changeset
|
260 |
by (simp add: Zero_int_def nat) |
23164 | 261 |
|
24196 | 262 |
lemma int_nat_eq [simp]: "of_nat (nat z) = (if 0 \<le> z then z else 0)" |
23365 | 263 |
by (cases z, simp add: nat le int_def Zero_int_def) |
23164 | 264 |
|
24196 | 265 |
corollary nat_0_le: "0 \<le> z ==> of_nat (nat z) = z" |
23164 | 266 |
by simp |
267 |
||
268 |
lemma nat_le_0 [simp]: "z \<le> 0 ==> nat z = 0" |
|
23303
6091e530ff77
add abbreviation int_of_nat for of_nat::nat=>int;
huffman
parents:
23299
diff
changeset
|
269 |
by (cases z, simp add: nat le Zero_int_def) |
23164 | 270 |
|
271 |
lemma nat_le_eq_zle: "0 < w | 0 \<le> z ==> (nat w \<le> nat z) = (w\<le>z)" |
|
272 |
apply (cases w, cases z) |
|
23303
6091e530ff77
add abbreviation int_of_nat for of_nat::nat=>int;
huffman
parents:
23299
diff
changeset
|
273 |
apply (simp add: nat le linorder_not_le [symmetric] Zero_int_def, arith) |
23164 | 274 |
done |
275 |
||
276 |
text{*An alternative condition is @{term "0 \<le> w"} *} |
|
277 |
corollary nat_mono_iff: "0 < z ==> (nat w < nat z) = (w < z)" |
|
278 |
by (simp add: nat_le_eq_zle linorder_not_le [symmetric]) |
|
279 |
||
280 |
corollary nat_less_eq_zless: "0 \<le> w ==> (nat w < nat z) = (w<z)" |
|
281 |
by (simp add: nat_le_eq_zle linorder_not_le [symmetric]) |
|
282 |
||
23365 | 283 |
lemma zless_nat_conj [simp]: "(nat w < nat z) = (0 < z & w < z)" |
23164 | 284 |
apply (cases w, cases z) |
23303
6091e530ff77
add abbreviation int_of_nat for of_nat::nat=>int;
huffman
parents:
23299
diff
changeset
|
285 |
apply (simp add: nat le Zero_int_def linorder_not_le [symmetric], arith) |
23164 | 286 |
done |
287 |
||
24196 | 288 |
lemma nonneg_eq_int: |
289 |
fixes z :: int |
|
290 |
assumes "0 \<le> z" and "\<And>m. z = of_nat m \<Longrightarrow> P" |
|
291 |
shows P |
|
292 |
using assms by (blast dest: nat_0_le sym) |
|
23164 | 293 |
|
24196 | 294 |
lemma nat_eq_iff: "(nat w = m) = (if 0 \<le> w then w = of_nat m else m=0)" |
23365 | 295 |
by (cases w, simp add: nat le int_def Zero_int_def, arith) |
23164 | 296 |
|
24196 | 297 |
corollary nat_eq_iff2: "(m = nat w) = (if 0 \<le> w then w = of_nat m else m=0)" |
23365 | 298 |
by (simp only: eq_commute [of m] nat_eq_iff) |
23164 | 299 |
|
24196 | 300 |
lemma nat_less_iff: "0 \<le> w ==> (nat w < m) = (w < of_nat m)" |
23164 | 301 |
apply (cases w) |
23365 | 302 |
apply (simp add: nat le int_def Zero_int_def linorder_not_le [symmetric], arith) |
23164 | 303 |
done |
304 |
||
24196 | 305 |
lemma int_eq_iff: "(of_nat m = z) = (m = nat z & 0 \<le> z)" |
23365 | 306 |
by (auto simp add: nat_eq_iff2) |
23164 | 307 |
|
308 |
lemma zero_less_nat_eq [simp]: "(0 < nat z) = (0 < z)" |
|
309 |
by (insert zless_nat_conj [of 0], auto) |
|
310 |
||
311 |
lemma nat_add_distrib: |
|
312 |
"[| (0::int) \<le> z; 0 \<le> z' |] ==> nat (z+z') = nat z + nat z'" |
|
23303
6091e530ff77
add abbreviation int_of_nat for of_nat::nat=>int;
huffman
parents:
23299
diff
changeset
|
313 |
by (cases z, cases z', simp add: nat add le Zero_int_def) |
23164 | 314 |
|
315 |
lemma nat_diff_distrib: |
|
316 |
"[| (0::int) \<le> z'; z' \<le> z |] ==> nat (z-z') = nat z - nat z'" |
|
317 |
by (cases z, cases z', |
|
23303
6091e530ff77
add abbreviation int_of_nat for of_nat::nat=>int;
huffman
parents:
23299
diff
changeset
|
318 |
simp add: nat add minus diff_minus le Zero_int_def) |
23164 | 319 |
|
24196 | 320 |
lemma nat_zminus_int [simp]: "nat (- (of_nat n)) = 0" |
23365 | 321 |
by (simp add: int_def minus nat Zero_int_def) |
23164 | 322 |
|
24196 | 323 |
lemma zless_nat_eq_int_zless: "(m < nat z) = (of_nat m < z)" |
23365 | 324 |
by (cases z, simp add: nat less int_def, arith) |
23164 | 325 |
|
326 |
||
24196 | 327 |
subsection{*Lemmas about the Function @{term of_nat} and Orderings*} |
23164 | 328 |
|
24196 | 329 |
lemma negative_zless_0: "- (of_nat (Suc n)) < (0 \<Colon> int)" |
23303
6091e530ff77
add abbreviation int_of_nat for of_nat::nat=>int;
huffman
parents:
23299
diff
changeset
|
330 |
by (simp add: order_less_le del: of_nat_Suc) |
23164 | 331 |
|
24196 | 332 |
lemma negative_zless [iff]: "- (of_nat (Suc n)) < (of_nat m \<Colon> int)" |
23365 | 333 |
by (rule negative_zless_0 [THEN order_less_le_trans], simp) |
23164 | 334 |
|
24196 | 335 |
lemma negative_zle_0: "- of_nat n \<le> (0 \<Colon> int)" |
23164 | 336 |
by (simp add: minus_le_iff) |
337 |
||
24196 | 338 |
lemma negative_zle [iff]: "- of_nat n \<le> (of_nat m \<Colon> int)" |
23365 | 339 |
by (rule order_trans [OF negative_zle_0 of_nat_0_le_iff]) |
23164 | 340 |
|
24196 | 341 |
lemma not_zle_0_negative [simp]: "~ (0 \<le> - (of_nat (Suc n) \<Colon> int))" |
23303
6091e530ff77
add abbreviation int_of_nat for of_nat::nat=>int;
huffman
parents:
23299
diff
changeset
|
342 |
by (subst le_minus_iff, simp del: of_nat_Suc) |
23164 | 343 |
|
24196 | 344 |
lemma int_zle_neg: "((of_nat n \<Colon> int) \<le> - of_nat m) = (n = 0 & m = 0)" |
23365 | 345 |
by (simp add: int_def le minus Zero_int_def) |
23164 | 346 |
|
24196 | 347 |
lemma not_int_zless_negative [simp]: "~ ((of_nat n \<Colon> int) < - of_nat m)" |
23164 | 348 |
by (simp add: linorder_not_less) |
349 |
||
24196 | 350 |
lemma negative_eq_positive [simp]: "((- of_nat n \<Colon> int) = of_nat m) = (n = 0 & m = 0)" |
351 |
by (force simp add: order_eq_iff [of "- of_nat n"] int_zle_neg) |
|
23164 | 352 |
|
24196 | 353 |
lemma zle_iff_zadd: "(w\<Colon>int) \<le> z \<longleftrightarrow> (\<exists>n. z = w + of_nat n)" |
23372
0035be079bee
clean up instance proofs; reorganize section headings
huffman
parents:
23365
diff
changeset
|
354 |
proof - |
0035be079bee
clean up instance proofs; reorganize section headings
huffman
parents:
23365
diff
changeset
|
355 |
have "(w \<le> z) = (0 \<le> z - w)" |
0035be079bee
clean up instance proofs; reorganize section headings
huffman
parents:
23365
diff
changeset
|
356 |
by (simp only: le_diff_eq add_0_left) |
24196 | 357 |
also have "\<dots> = (\<exists>n. z - w = of_nat n)" |
23372
0035be079bee
clean up instance proofs; reorganize section headings
huffman
parents:
23365
diff
changeset
|
358 |
by (auto elim: zero_le_imp_eq_int) |
24196 | 359 |
also have "\<dots> = (\<exists>n. z = w + of_nat n)" |
23477
f4b83f03cac9
tuned and renamed group_eq_simps and ring_eq_simps
nipkow
parents:
23438
diff
changeset
|
360 |
by (simp only: group_simps) |
23372
0035be079bee
clean up instance proofs; reorganize section headings
huffman
parents:
23365
diff
changeset
|
361 |
finally show ?thesis . |
23164 | 362 |
qed |
363 |
||
24196 | 364 |
lemma zadd_int_left: "of_nat m + (of_nat n + z) = of_nat (m + n) + (z\<Colon>int)" |
23372
0035be079bee
clean up instance proofs; reorganize section headings
huffman
parents:
23365
diff
changeset
|
365 |
by simp |
0035be079bee
clean up instance proofs; reorganize section headings
huffman
parents:
23365
diff
changeset
|
366 |
|
24196 | 367 |
lemma int_Suc0_eq_1: "of_nat (Suc 0) = (1\<Colon>int)" |
23372
0035be079bee
clean up instance proofs; reorganize section headings
huffman
parents:
23365
diff
changeset
|
368 |
by simp |
0035be079bee
clean up instance proofs; reorganize section headings
huffman
parents:
23365
diff
changeset
|
369 |
|
23164 | 370 |
text{*This version is proved for all ordered rings, not just integers! |
371 |
It is proved here because attribute @{text arith_split} is not available |
|
372 |
in theory @{text Ring_and_Field}. |
|
373 |
But is it really better than just rewriting with @{text abs_if}?*} |
|
24286
7619080e49f0
ATP blacklisting is now in theory data, attribute noatp
paulson
parents:
24196
diff
changeset
|
374 |
lemma abs_split [arith_split,noatp]: |
23164 | 375 |
"P(abs(a::'a::ordered_idom)) = ((0 \<le> a --> P a) & (a < 0 --> P(-a)))" |
376 |
by (force dest: order_less_le_trans simp add: abs_if linorder_not_less) |
|
377 |
||
378 |
||
379 |
subsection {* Constants @{term neg} and @{term iszero} *} |
|
380 |
||
381 |
definition |
|
382 |
neg :: "'a\<Colon>ordered_idom \<Rightarrow> bool" |
|
383 |
where |
|
384 |
[code inline]: "neg Z \<longleftrightarrow> Z < 0" |
|
385 |
||
386 |
definition (*for simplifying equalities*) |
|
23276
a70934b63910
generalize of_nat and related constants to class semiring_1
huffman
parents:
23164
diff
changeset
|
387 |
iszero :: "'a\<Colon>semiring_1 \<Rightarrow> bool" |
23164 | 388 |
where |
389 |
"iszero z \<longleftrightarrow> z = 0" |
|
390 |
||
24196 | 391 |
lemma not_neg_int [simp]: "~ neg (of_nat n)" |
23164 | 392 |
by (simp add: neg_def) |
393 |
||
24196 | 394 |
lemma neg_zminus_int [simp]: "neg (- (of_nat (Suc n)))" |
23303
6091e530ff77
add abbreviation int_of_nat for of_nat::nat=>int;
huffman
parents:
23299
diff
changeset
|
395 |
by (simp add: neg_def neg_less_0_iff_less del: of_nat_Suc) |
23164 | 396 |
|
397 |
lemmas neg_eq_less_0 = neg_def |
|
398 |
||
399 |
lemma not_neg_eq_ge_0: "(~neg x) = (0 \<le> x)" |
|
400 |
by (simp add: neg_def linorder_not_less) |
|
401 |
||
402 |
||
23372
0035be079bee
clean up instance proofs; reorganize section headings
huffman
parents:
23365
diff
changeset
|
403 |
text{*To simplify inequalities when Numeral1 can get simplified to 1*} |
23164 | 404 |
|
405 |
lemma not_neg_0: "~ neg 0" |
|
406 |
by (simp add: One_int_def neg_def) |
|
407 |
||
408 |
lemma not_neg_1: "~ neg 1" |
|
409 |
by (simp add: neg_def linorder_not_less zero_le_one) |
|
410 |
||
411 |
lemma iszero_0: "iszero 0" |
|
412 |
by (simp add: iszero_def) |
|
413 |
||
414 |
lemma not_iszero_1: "~ iszero 1" |
|
415 |
by (simp add: iszero_def eq_commute) |
|
416 |
||
417 |
lemma neg_nat: "neg z ==> nat z = 0" |
|
418 |
by (simp add: neg_def order_less_imp_le) |
|
419 |
||
24196 | 420 |
lemma not_neg_nat: "~ neg z ==> of_nat (nat z) = z" |
23164 | 421 |
by (simp add: linorder_not_less neg_def) |
422 |
||
423 |
||
23852 | 424 |
subsection{*Embedding of the Integers into any @{text ring_1}: @{term of_int}*} |
23164 | 425 |
|
23950 | 426 |
definition |
427 |
of_int :: "int \<Rightarrow> 'a\<Colon>ring_1" |
|
428 |
where |
|
429 |
"of_int z = contents (\<Union>(i, j) \<in> Rep_Integ z. { of_nat i - of_nat j })" |
|
23852 | 430 |
lemmas [code func del] = of_int_def |
23164 | 431 |
|
432 |
lemma of_int: "of_int (Abs_Integ (intrel `` {(i,j)})) = of_nat i - of_nat j" |
|
433 |
proof - |
|
434 |
have "(\<lambda>(i,j). { of_nat i - (of_nat j :: 'a) }) respects intrel" |
|
435 |
by (simp add: congruent_def compare_rls of_nat_add [symmetric] |
|
436 |
del: of_nat_add) |
|
437 |
thus ?thesis |
|
438 |
by (simp add: of_int_def UN_equiv_class [OF equiv_intrel]) |
|
439 |
qed |
|
440 |
||
441 |
lemma of_int_0 [simp]: "of_int 0 = 0" |
|
23303
6091e530ff77
add abbreviation int_of_nat for of_nat::nat=>int;
huffman
parents:
23299
diff
changeset
|
442 |
by (simp add: of_int Zero_int_def) |
23164 | 443 |
|
444 |
lemma of_int_1 [simp]: "of_int 1 = 1" |
|
23303
6091e530ff77
add abbreviation int_of_nat for of_nat::nat=>int;
huffman
parents:
23299
diff
changeset
|
445 |
by (simp add: of_int One_int_def) |
23164 | 446 |
|
447 |
lemma of_int_add [simp]: "of_int (w+z) = of_int w + of_int z" |
|
448 |
by (cases w, cases z, simp add: compare_rls of_int add) |
|
449 |
||
450 |
lemma of_int_minus [simp]: "of_int (-z) = - (of_int z)" |
|
451 |
by (cases z, simp add: compare_rls of_int minus) |
|
452 |
||
453 |
lemma of_int_diff [simp]: "of_int (w-z) = of_int w - of_int z" |
|
454 |
by (simp add: diff_minus) |
|
455 |
||
456 |
lemma of_int_mult [simp]: "of_int (w*z) = of_int w * of_int z" |
|
457 |
apply (cases w, cases z) |
|
458 |
apply (simp add: compare_rls of_int left_diff_distrib right_diff_distrib |
|
23431
25ca91279a9b
change simp rules for of_nat to work like int did previously (reorient of_nat_Suc, remove of_nat_mult [simp]); preserve original variable names in legacy int theorems
huffman
parents:
23402
diff
changeset
|
459 |
mult add_ac of_nat_mult) |
23164 | 460 |
done |
461 |
||
462 |
lemma of_int_le_iff [simp]: |
|
463 |
"(of_int w \<le> (of_int z::'a::ordered_idom)) = (w \<le> z)" |
|
464 |
apply (cases w) |
|
465 |
apply (cases z) |
|
466 |
apply (simp add: compare_rls of_int le diff_int_def add minus |
|
467 |
of_nat_add [symmetric] del: of_nat_add) |
|
468 |
done |
|
469 |
||
470 |
text{*Special cases where either operand is zero*} |
|
471 |
lemmas of_int_0_le_iff [simp] = of_int_le_iff [of 0, simplified] |
|
472 |
lemmas of_int_le_0_iff [simp] = of_int_le_iff [of _ 0, simplified] |
|
473 |
||
474 |
||
475 |
lemma of_int_less_iff [simp]: |
|
476 |
"(of_int w < (of_int z::'a::ordered_idom)) = (w < z)" |
|
477 |
by (simp add: linorder_not_le [symmetric]) |
|
478 |
||
479 |
text{*Special cases where either operand is zero*} |
|
480 |
lemmas of_int_0_less_iff [simp] = of_int_less_iff [of 0, simplified] |
|
481 |
lemmas of_int_less_0_iff [simp] = of_int_less_iff [of _ 0, simplified] |
|
482 |
||
483 |
text{*Class for unital rings with characteristic zero. |
|
484 |
Includes non-ordered rings like the complex numbers.*} |
|
23950 | 485 |
class ring_char_0 = ring_1 + semiring_char_0 |
23164 | 486 |
|
487 |
lemma of_int_eq_iff [simp]: |
|
24196 | 488 |
"of_int w = (of_int z \<Colon> 'a\<Colon>ring_char_0) \<longleftrightarrow> w = z" |
23282
dfc459989d24
add axclass semiring_char_0 for types where of_nat is injective
huffman
parents:
23276
diff
changeset
|
489 |
apply (cases w, cases z, simp add: of_int) |
dfc459989d24
add axclass semiring_char_0 for types where of_nat is injective
huffman
parents:
23276
diff
changeset
|
490 |
apply (simp only: diff_eq_eq diff_add_eq eq_diff_eq) |
dfc459989d24
add axclass semiring_char_0 for types where of_nat is injective
huffman
parents:
23276
diff
changeset
|
491 |
apply (simp only: of_nat_add [symmetric] of_nat_eq_iff) |
dfc459989d24
add axclass semiring_char_0 for types where of_nat is injective
huffman
parents:
23276
diff
changeset
|
492 |
done |
23164 | 493 |
|
494 |
text{*Every @{text ordered_idom} has characteristic zero.*} |
|
23282
dfc459989d24
add axclass semiring_char_0 for types where of_nat is injective
huffman
parents:
23276
diff
changeset
|
495 |
instance ordered_idom < ring_char_0 .. |
23164 | 496 |
|
497 |
text{*Special cases where either operand is zero*} |
|
498 |
lemmas of_int_0_eq_iff [simp] = of_int_eq_iff [of 0, simplified] |
|
499 |
lemmas of_int_eq_0_iff [simp] = of_int_eq_iff [of _ 0, simplified] |
|
500 |
||
501 |
lemma of_int_eq_id [simp]: "of_int = (id :: int => int)" |
|
502 |
proof |
|
503 |
fix z |
|
23299
292b1cbd05dc
remove dependencies of proofs on constant int::nat=>int, preparing to remove it
huffman
parents:
23282
diff
changeset
|
504 |
show "of_int z = id z" |
23164 | 505 |
by (cases z) |
23365 | 506 |
(simp add: of_int add minus int_def diff_minus) |
23164 | 507 |
qed |
508 |
||
23372
0035be079bee
clean up instance proofs; reorganize section headings
huffman
parents:
23365
diff
changeset
|
509 |
lemma of_nat_nat: "0 \<le> z ==> of_nat (nat z) = of_int z" |
23438
dd824e86fa8a
remove simp attribute from of_nat_diff, for backward compatibility with zdiff_int
huffman
parents:
23431
diff
changeset
|
510 |
by (cases z rule: eq_Abs_Integ) |
dd824e86fa8a
remove simp attribute from of_nat_diff, for backward compatibility with zdiff_int
huffman
parents:
23431
diff
changeset
|
511 |
(simp add: nat le of_int Zero_int_def of_nat_diff) |
23372
0035be079bee
clean up instance proofs; reorganize section headings
huffman
parents:
23365
diff
changeset
|
512 |
|
23164 | 513 |
|
514 |
subsection{*The Set of Integers*} |
|
515 |
||
516 |
constdefs |
|
517 |
Ints :: "'a::ring_1 set" |
|
518 |
"Ints == range of_int" |
|
519 |
||
520 |
notation (xsymbols) |
|
521 |
Ints ("\<int>") |
|
522 |
||
523 |
lemma Ints_0 [simp]: "0 \<in> Ints" |
|
524 |
apply (simp add: Ints_def) |
|
525 |
apply (rule range_eqI) |
|
526 |
apply (rule of_int_0 [symmetric]) |
|
527 |
done |
|
528 |
||
529 |
lemma Ints_1 [simp]: "1 \<in> Ints" |
|
530 |
apply (simp add: Ints_def) |
|
531 |
apply (rule range_eqI) |
|
532 |
apply (rule of_int_1 [symmetric]) |
|
533 |
done |
|
534 |
||
535 |
lemma Ints_add [simp]: "[|a \<in> Ints; b \<in> Ints|] ==> a+b \<in> Ints" |
|
536 |
apply (auto simp add: Ints_def) |
|
537 |
apply (rule range_eqI) |
|
538 |
apply (rule of_int_add [symmetric]) |
|
539 |
done |
|
540 |
||
541 |
lemma Ints_minus [simp]: "a \<in> Ints ==> -a \<in> Ints" |
|
542 |
apply (auto simp add: Ints_def) |
|
543 |
apply (rule range_eqI) |
|
544 |
apply (rule of_int_minus [symmetric]) |
|
545 |
done |
|
546 |
||
547 |
lemma Ints_diff [simp]: "[|a \<in> Ints; b \<in> Ints|] ==> a-b \<in> Ints" |
|
548 |
apply (auto simp add: Ints_def) |
|
549 |
apply (rule range_eqI) |
|
550 |
apply (rule of_int_diff [symmetric]) |
|
551 |
done |
|
552 |
||
553 |
lemma Ints_mult [simp]: "[|a \<in> Ints; b \<in> Ints|] ==> a*b \<in> Ints" |
|
554 |
apply (auto simp add: Ints_def) |
|
555 |
apply (rule range_eqI) |
|
556 |
apply (rule of_int_mult [symmetric]) |
|
557 |
done |
|
558 |
||
559 |
text{*Collapse nested embeddings*} |
|
560 |
lemma of_int_of_nat_eq [simp]: "of_int (of_nat n) = of_nat n" |
|
561 |
by (induct n, auto) |
|
562 |
||
563 |
lemma Ints_cases [cases set: Ints]: |
|
564 |
assumes "q \<in> \<int>" |
|
565 |
obtains (of_int) z where "q = of_int z" |
|
566 |
unfolding Ints_def |
|
567 |
proof - |
|
568 |
from `q \<in> \<int>` have "q \<in> range of_int" unfolding Ints_def . |
|
569 |
then obtain z where "q = of_int z" .. |
|
570 |
then show thesis .. |
|
571 |
qed |
|
572 |
||
573 |
lemma Ints_induct [case_names of_int, induct set: Ints]: |
|
574 |
"q \<in> \<int> ==> (!!z. P (of_int z)) ==> P q" |
|
575 |
by (rule Ints_cases) auto |
|
576 |
||
577 |
||
578 |
subsection {* Further properties *} |
|
579 |
||
580 |
text{*Now we replace the case analysis rule by a more conventional one: |
|
581 |
whether an integer is negative or not.*} |
|
582 |
||
23365 | 583 |
lemma zless_iff_Suc_zadd: |
24196 | 584 |
"(w \<Colon> int) < z \<longleftrightarrow> (\<exists>n. z = w + of_nat (Suc n))" |
23303
6091e530ff77
add abbreviation int_of_nat for of_nat::nat=>int;
huffman
parents:
23299
diff
changeset
|
585 |
apply (cases z, cases w) |
23372
0035be079bee
clean up instance proofs; reorganize section headings
huffman
parents:
23365
diff
changeset
|
586 |
apply (auto simp add: less add int_def) |
23303
6091e530ff77
add abbreviation int_of_nat for of_nat::nat=>int;
huffman
parents:
23299
diff
changeset
|
587 |
apply (rename_tac a b c d) |
6091e530ff77
add abbreviation int_of_nat for of_nat::nat=>int;
huffman
parents:
23299
diff
changeset
|
588 |
apply (rule_tac x="a+d - Suc(c+b)" in exI) |
6091e530ff77
add abbreviation int_of_nat for of_nat::nat=>int;
huffman
parents:
23299
diff
changeset
|
589 |
apply arith |
6091e530ff77
add abbreviation int_of_nat for of_nat::nat=>int;
huffman
parents:
23299
diff
changeset
|
590 |
done |
6091e530ff77
add abbreviation int_of_nat for of_nat::nat=>int;
huffman
parents:
23299
diff
changeset
|
591 |
|
24196 | 592 |
lemma negD: "(x \<Colon> int) < 0 \<Longrightarrow> \<exists>n. x = - (of_nat (Suc n))" |
23303
6091e530ff77
add abbreviation int_of_nat for of_nat::nat=>int;
huffman
parents:
23299
diff
changeset
|
593 |
apply (cases x) |
23365 | 594 |
apply (auto simp add: le minus Zero_int_def int_def order_less_le) |
23303
6091e530ff77
add abbreviation int_of_nat for of_nat::nat=>int;
huffman
parents:
23299
diff
changeset
|
595 |
apply (rule_tac x="y - Suc x" in exI, arith) |
6091e530ff77
add abbreviation int_of_nat for of_nat::nat=>int;
huffman
parents:
23299
diff
changeset
|
596 |
done |
6091e530ff77
add abbreviation int_of_nat for of_nat::nat=>int;
huffman
parents:
23299
diff
changeset
|
597 |
|
23365 | 598 |
theorem int_cases [cases type: int, case_names nonneg neg]: |
24196 | 599 |
"[|!! n. (z \<Colon> int) = of_nat n ==> P; !! n. z = - (of_nat (Suc n)) ==> P |] ==> P" |
23365 | 600 |
apply (cases "z < 0", blast dest!: negD) |
23303
6091e530ff77
add abbreviation int_of_nat for of_nat::nat=>int;
huffman
parents:
23299
diff
changeset
|
601 |
apply (simp add: linorder_not_less del: of_nat_Suc) |
23365 | 602 |
apply (blast dest: nat_0_le [THEN sym]) |
23303
6091e530ff77
add abbreviation int_of_nat for of_nat::nat=>int;
huffman
parents:
23299
diff
changeset
|
603 |
done |
6091e530ff77
add abbreviation int_of_nat for of_nat::nat=>int;
huffman
parents:
23299
diff
changeset
|
604 |
|
23372
0035be079bee
clean up instance proofs; reorganize section headings
huffman
parents:
23365
diff
changeset
|
605 |
theorem int_induct [induct type: int, case_names nonneg neg]: |
24196 | 606 |
"[|!! n. P (of_nat n \<Colon> int); !!n. P (- (of_nat (Suc n))) |] ==> P z" |
23365 | 607 |
by (cases z rule: int_cases) auto |
23303
6091e530ff77
add abbreviation int_of_nat for of_nat::nat=>int;
huffman
parents:
23299
diff
changeset
|
608 |
|
6091e530ff77
add abbreviation int_of_nat for of_nat::nat=>int;
huffman
parents:
23299
diff
changeset
|
609 |
text{*Contributed by Brian Huffman*} |
23365 | 610 |
theorem int_diff_cases [case_names diff]: |
24196 | 611 |
assumes prem: "!!m n. (z\<Colon>int) = of_nat m - of_nat n ==> P" shows "P" |
23303
6091e530ff77
add abbreviation int_of_nat for of_nat::nat=>int;
huffman
parents:
23299
diff
changeset
|
612 |
apply (cases z rule: eq_Abs_Integ) |
6091e530ff77
add abbreviation int_of_nat for of_nat::nat=>int;
huffman
parents:
23299
diff
changeset
|
613 |
apply (rule_tac m=x and n=y in prem) |
23365 | 614 |
apply (simp add: int_def diff_def minus add) |
23303
6091e530ff77
add abbreviation int_of_nat for of_nat::nat=>int;
huffman
parents:
23299
diff
changeset
|
615 |
done |
6091e530ff77
add abbreviation int_of_nat for of_nat::nat=>int;
huffman
parents:
23299
diff
changeset
|
616 |
|
6091e530ff77
add abbreviation int_of_nat for of_nat::nat=>int;
huffman
parents:
23299
diff
changeset
|
617 |
|
23365 | 618 |
subsection {* Legacy theorems *} |
23303
6091e530ff77
add abbreviation int_of_nat for of_nat::nat=>int;
huffman
parents:
23299
diff
changeset
|
619 |
|
23431
25ca91279a9b
change simp rules for of_nat to work like int did previously (reorient of_nat_Suc, remove of_nat_mult [simp]); preserve original variable names in legacy int theorems
huffman
parents:
23402
diff
changeset
|
620 |
lemmas zminus_zminus = minus_minus [of "?z::int"] |
23372
0035be079bee
clean up instance proofs; reorganize section headings
huffman
parents:
23365
diff
changeset
|
621 |
lemmas zminus_0 = minus_zero [where 'a=int] |
23431
25ca91279a9b
change simp rules for of_nat to work like int did previously (reorient of_nat_Suc, remove of_nat_mult [simp]); preserve original variable names in legacy int theorems
huffman
parents:
23402
diff
changeset
|
622 |
lemmas zminus_zadd_distrib = minus_add_distrib [of "?z::int" "?w"] |
25ca91279a9b
change simp rules for of_nat to work like int did previously (reorient of_nat_Suc, remove of_nat_mult [simp]); preserve original variable names in legacy int theorems
huffman
parents:
23402
diff
changeset
|
623 |
lemmas zadd_commute = add_commute [of "?z::int" "?w"] |
25ca91279a9b
change simp rules for of_nat to work like int did previously (reorient of_nat_Suc, remove of_nat_mult [simp]); preserve original variable names in legacy int theorems
huffman
parents:
23402
diff
changeset
|
624 |
lemmas zadd_assoc = add_assoc [of "?z1.0::int" "?z2.0" "?z3.0"] |
25ca91279a9b
change simp rules for of_nat to work like int did previously (reorient of_nat_Suc, remove of_nat_mult [simp]); preserve original variable names in legacy int theorems
huffman
parents:
23402
diff
changeset
|
625 |
lemmas zadd_left_commute = add_left_commute [of "?x::int" "?y" "?z"] |
23372
0035be079bee
clean up instance proofs; reorganize section headings
huffman
parents:
23365
diff
changeset
|
626 |
lemmas zadd_ac = zadd_assoc zadd_commute zadd_left_commute |
0035be079bee
clean up instance proofs; reorganize section headings
huffman
parents:
23365
diff
changeset
|
627 |
lemmas zmult_ac = OrderedGroup.mult_ac |
23431
25ca91279a9b
change simp rules for of_nat to work like int did previously (reorient of_nat_Suc, remove of_nat_mult [simp]); preserve original variable names in legacy int theorems
huffman
parents:
23402
diff
changeset
|
628 |
lemmas zadd_0 = OrderedGroup.add_0_left [of "?z::int"] |
25ca91279a9b
change simp rules for of_nat to work like int did previously (reorient of_nat_Suc, remove of_nat_mult [simp]); preserve original variable names in legacy int theorems
huffman
parents:
23402
diff
changeset
|
629 |
lemmas zadd_0_right = OrderedGroup.add_0_left [of "?z::int"] |
25ca91279a9b
change simp rules for of_nat to work like int did previously (reorient of_nat_Suc, remove of_nat_mult [simp]); preserve original variable names in legacy int theorems
huffman
parents:
23402
diff
changeset
|
630 |
lemmas zadd_zminus_inverse2 = left_minus [of "?z::int"] |
25ca91279a9b
change simp rules for of_nat to work like int did previously (reorient of_nat_Suc, remove of_nat_mult [simp]); preserve original variable names in legacy int theorems
huffman
parents:
23402
diff
changeset
|
631 |
lemmas zmult_zminus = mult_minus_left [of "?z::int" "?w"] |
25ca91279a9b
change simp rules for of_nat to work like int did previously (reorient of_nat_Suc, remove of_nat_mult [simp]); preserve original variable names in legacy int theorems
huffman
parents:
23402
diff
changeset
|
632 |
lemmas zmult_commute = mult_commute [of "?z::int" "?w"] |
25ca91279a9b
change simp rules for of_nat to work like int did previously (reorient of_nat_Suc, remove of_nat_mult [simp]); preserve original variable names in legacy int theorems
huffman
parents:
23402
diff
changeset
|
633 |
lemmas zmult_assoc = mult_assoc [of "?z1.0::int" "?z2.0" "?z3.0"] |
25ca91279a9b
change simp rules for of_nat to work like int did previously (reorient of_nat_Suc, remove of_nat_mult [simp]); preserve original variable names in legacy int theorems
huffman
parents:
23402
diff
changeset
|
634 |
lemmas zadd_zmult_distrib = left_distrib [of "?z1.0::int" "?z2.0" "?w"] |
25ca91279a9b
change simp rules for of_nat to work like int did previously (reorient of_nat_Suc, remove of_nat_mult [simp]); preserve original variable names in legacy int theorems
huffman
parents:
23402
diff
changeset
|
635 |
lemmas zadd_zmult_distrib2 = right_distrib [of "?w::int" "?z1.0" "?z2.0"] |
25ca91279a9b
change simp rules for of_nat to work like int did previously (reorient of_nat_Suc, remove of_nat_mult [simp]); preserve original variable names in legacy int theorems
huffman
parents:
23402
diff
changeset
|
636 |
lemmas zdiff_zmult_distrib = left_diff_distrib [of "?z1.0::int" "?z2.0" "?w"] |
25ca91279a9b
change simp rules for of_nat to work like int did previously (reorient of_nat_Suc, remove of_nat_mult [simp]); preserve original variable names in legacy int theorems
huffman
parents:
23402
diff
changeset
|
637 |
lemmas zdiff_zmult_distrib2 = right_diff_distrib [of "?w::int" "?z1.0" "?z2.0"] |
23303
6091e530ff77
add abbreviation int_of_nat for of_nat::nat=>int;
huffman
parents:
23299
diff
changeset
|
638 |
|
23372
0035be079bee
clean up instance proofs; reorganize section headings
huffman
parents:
23365
diff
changeset
|
639 |
lemmas int_distrib = |
0035be079bee
clean up instance proofs; reorganize section headings
huffman
parents:
23365
diff
changeset
|
640 |
zadd_zmult_distrib zadd_zmult_distrib2 |
0035be079bee
clean up instance proofs; reorganize section headings
huffman
parents:
23365
diff
changeset
|
641 |
zdiff_zmult_distrib zdiff_zmult_distrib2 |
0035be079bee
clean up instance proofs; reorganize section headings
huffman
parents:
23365
diff
changeset
|
642 |
|
23431
25ca91279a9b
change simp rules for of_nat to work like int did previously (reorient of_nat_Suc, remove of_nat_mult [simp]); preserve original variable names in legacy int theorems
huffman
parents:
23402
diff
changeset
|
643 |
lemmas zmult_1 = mult_1_left [of "?z::int"] |
25ca91279a9b
change simp rules for of_nat to work like int did previously (reorient of_nat_Suc, remove of_nat_mult [simp]); preserve original variable names in legacy int theorems
huffman
parents:
23402
diff
changeset
|
644 |
lemmas zmult_1_right = mult_1_right [of "?z::int"] |
23303
6091e530ff77
add abbreviation int_of_nat for of_nat::nat=>int;
huffman
parents:
23299
diff
changeset
|
645 |
|
23431
25ca91279a9b
change simp rules for of_nat to work like int did previously (reorient of_nat_Suc, remove of_nat_mult [simp]); preserve original variable names in legacy int theorems
huffman
parents:
23402
diff
changeset
|
646 |
lemmas zle_refl = order_refl [of "?w::int"] |
23402 | 647 |
lemmas zle_trans = order_trans [where 'a=int and x="?i" and y="?j" and z="?k"] |
23431
25ca91279a9b
change simp rules for of_nat to work like int did previously (reorient of_nat_Suc, remove of_nat_mult [simp]); preserve original variable names in legacy int theorems
huffman
parents:
23402
diff
changeset
|
648 |
lemmas zle_anti_sym = order_antisym [of "?z::int" "?w"] |
25ca91279a9b
change simp rules for of_nat to work like int did previously (reorient of_nat_Suc, remove of_nat_mult [simp]); preserve original variable names in legacy int theorems
huffman
parents:
23402
diff
changeset
|
649 |
lemmas zle_linear = linorder_linear [of "?z::int" "?w"] |
23372
0035be079bee
clean up instance proofs; reorganize section headings
huffman
parents:
23365
diff
changeset
|
650 |
lemmas zless_linear = linorder_less_linear [where 'a = int] |
0035be079bee
clean up instance proofs; reorganize section headings
huffman
parents:
23365
diff
changeset
|
651 |
|
23431
25ca91279a9b
change simp rules for of_nat to work like int did previously (reorient of_nat_Suc, remove of_nat_mult [simp]); preserve original variable names in legacy int theorems
huffman
parents:
23402
diff
changeset
|
652 |
lemmas zadd_left_mono = add_left_mono [of "?i::int" "?j" "?k"] |
25ca91279a9b
change simp rules for of_nat to work like int did previously (reorient of_nat_Suc, remove of_nat_mult [simp]); preserve original variable names in legacy int theorems
huffman
parents:
23402
diff
changeset
|
653 |
lemmas zadd_strict_right_mono = add_strict_right_mono [of "?i::int" "?j" "?k"] |
25ca91279a9b
change simp rules for of_nat to work like int did previously (reorient of_nat_Suc, remove of_nat_mult [simp]); preserve original variable names in legacy int theorems
huffman
parents:
23402
diff
changeset
|
654 |
lemmas zadd_zless_mono = add_less_le_mono [of "?w'::int" "?w" "?z'" "?z"] |
23372
0035be079bee
clean up instance proofs; reorganize section headings
huffman
parents:
23365
diff
changeset
|
655 |
|
0035be079bee
clean up instance proofs; reorganize section headings
huffman
parents:
23365
diff
changeset
|
656 |
lemmas int_0_less_1 = zero_less_one [where 'a=int] |
0035be079bee
clean up instance proofs; reorganize section headings
huffman
parents:
23365
diff
changeset
|
657 |
lemmas int_0_neq_1 = zero_neq_one [where 'a=int] |
23303
6091e530ff77
add abbreviation int_of_nat for of_nat::nat=>int;
huffman
parents:
23299
diff
changeset
|
658 |
|
23365 | 659 |
lemmas inj_int = inj_of_nat [where 'a=int] |
660 |
lemmas int_int_eq = of_nat_eq_iff [where 'a=int] |
|
661 |
lemmas zadd_int = of_nat_add [where 'a=int, symmetric] |
|
662 |
lemmas int_mult = of_nat_mult [where 'a=int] |
|
663 |
lemmas zmult_int = of_nat_mult [where 'a=int, symmetric] |
|
23431
25ca91279a9b
change simp rules for of_nat to work like int did previously (reorient of_nat_Suc, remove of_nat_mult [simp]); preserve original variable names in legacy int theorems
huffman
parents:
23402
diff
changeset
|
664 |
lemmas int_eq_0_conv = of_nat_eq_0_iff [where 'a=int and m="?n"] |
23365 | 665 |
lemmas zless_int = of_nat_less_iff [where 'a=int] |
23431
25ca91279a9b
change simp rules for of_nat to work like int did previously (reorient of_nat_Suc, remove of_nat_mult [simp]); preserve original variable names in legacy int theorems
huffman
parents:
23402
diff
changeset
|
666 |
lemmas int_less_0_conv = of_nat_less_0_iff [where 'a=int and m="?k"] |
23365 | 667 |
lemmas zero_less_int_conv = of_nat_0_less_iff [where 'a=int] |
668 |
lemmas zle_int = of_nat_le_iff [where 'a=int] |
|
669 |
lemmas zero_zle_int = of_nat_0_le_iff [where 'a=int] |
|
23431
25ca91279a9b
change simp rules for of_nat to work like int did previously (reorient of_nat_Suc, remove of_nat_mult [simp]); preserve original variable names in legacy int theorems
huffman
parents:
23402
diff
changeset
|
670 |
lemmas int_le_0_conv = of_nat_le_0_iff [where 'a=int and m="?n"] |
24196 | 671 |
lemmas int_0 = of_nat_0 [where 'a=int] |
23365 | 672 |
lemmas int_1 = of_nat_1 [where 'a=int] |
24196 | 673 |
lemmas int_Suc = of_nat_Suc [where 'a=int] |
23431
25ca91279a9b
change simp rules for of_nat to work like int did previously (reorient of_nat_Suc, remove of_nat_mult [simp]); preserve original variable names in legacy int theorems
huffman
parents:
23402
diff
changeset
|
674 |
lemmas abs_int_eq = abs_of_nat [where 'a=int and n="?m"] |
23365 | 675 |
lemmas of_int_int_eq = of_int_of_nat_eq [where 'a=int] |
676 |
lemmas zdiff_int = of_nat_diff [where 'a=int, symmetric] |
|
677 |
lemmas zless_le = less_int_def [THEN meta_eq_to_obj_eq] |
|
678 |
lemmas int_eq_of_nat = TrueI |
|
23164 | 679 |
|
23365 | 680 |
abbreviation |
24196 | 681 |
int :: "nat \<Rightarrow> int" |
682 |
where |
|
683 |
"int \<equiv> of_nat" |
|
684 |
||
23164 | 685 |
end |