author | paulson |
Fri, 28 Nov 2003 12:09:37 +0100 | |
changeset 14269 | 502a7c95de73 |
parent 14259 | 79f7d3451b1e |
child 14271 | 8ed6989228bb |
permissions | -rw-r--r-- |
5508 | 1 |
(* Title: IntDef.thy |
2 |
ID: $Id$ |
|
3 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
|
4 |
Copyright 1996 University of Cambridge |
|
5 |
||
6 |
The integers as equivalence classes over nat*nat. |
|
7 |
*) |
|
8 |
||
14259 | 9 |
theory IntDef = Equiv + NatArith: |
5508 | 10 |
constdefs |
11 |
intrel :: "((nat * nat) * (nat * nat)) set" |
|
9392 | 12 |
"intrel == {p. EX x1 y1 x2 y2. p=((x1::nat,y1),(x2,y2)) & x1+y2 = x2+y1}" |
5508 | 13 |
|
14 |
typedef (Integ) |
|
14259 | 15 |
int = "UNIV//intrel" |
16 |
by (auto simp add: quotient_def) |
|
5508 | 17 |
|
14259 | 18 |
instance int :: ord .. |
19 |
instance int :: zero .. |
|
20 |
instance int :: one .. |
|
21 |
instance int :: plus .. |
|
22 |
instance int :: times .. |
|
23 |
instance int :: minus .. |
|
5508 | 24 |
|
25 |
defs |
|
14259 | 26 |
zminus_def: |
10834 | 27 |
"- Z == Abs_Integ(UN (x,y):Rep_Integ(Z). intrel``{(y,x)})" |
5508 | 28 |
|
29 |
constdefs |
|
30 |
||
14259 | 31 |
int :: "nat => int" |
10834 | 32 |
"int m == Abs_Integ(intrel `` {(m,0)})" |
5508 | 33 |
|
14259 | 34 |
neg :: "int => bool" |
5540 | 35 |
"neg(Z) == EX x y. x<y & (x,y::nat):Rep_Integ(Z)" |
5508 | 36 |
|
37 |
(*For simplifying equalities*) |
|
14259 | 38 |
iszero :: "int => bool" |
11868
56db9f3a6b3e
Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents:
11713
diff
changeset
|
39 |
"iszero z == z = (0::int)" |
5508 | 40 |
|
14269 | 41 |
defs (overloaded) |
9392 | 42 |
|
14259 | 43 |
Zero_int_def: "0 == int 0" |
44 |
One_int_def: "1 == int 1" |
|
8937 | 45 |
|
14259 | 46 |
zadd_def: |
5594 | 47 |
"z + w == |
7375
2cb340e66d15
tidied, allowing pattern-matching in defs of zadd and zmult
paulson
parents:
7127
diff
changeset
|
48 |
Abs_Integ(UN (x1,y1):Rep_Integ(z). UN (x2,y2):Rep_Integ(w). |
10834 | 49 |
intrel``{(x1+x2, y1+y2)})" |
5508 | 50 |
|
14259 | 51 |
zdiff_def: "z - (w::int) == z + (-w)" |
5508 | 52 |
|
14259 | 53 |
zless_def: "z<w == neg(z - w)" |
5508 | 54 |
|
14259 | 55 |
zle_def: "z <= (w::int) == ~(w < z)" |
5508 | 56 |
|
14259 | 57 |
zmult_def: |
5594 | 58 |
"z * w == |
7375
2cb340e66d15
tidied, allowing pattern-matching in defs of zadd and zmult
paulson
parents:
7127
diff
changeset
|
59 |
Abs_Integ(UN (x1,y1):Rep_Integ(z). UN (x2,y2):Rep_Integ(w). |
10834 | 60 |
intrel``{(x1*x2 + y1*y2, x1*y2 + y1*x2)})" |
5508 | 61 |
|
14259 | 62 |
lemma intrel_iff [simp]: "(((x1,y1),(x2,y2)): intrel) = (x1+y2 = x2+y1)" |
63 |
by (unfold intrel_def, blast) |
|
64 |
||
65 |
lemma equiv_intrel: "equiv UNIV intrel" |
|
66 |
by (unfold intrel_def equiv_def refl_def sym_def trans_def, auto) |
|
67 |
||
68 |
lemmas equiv_intrel_iff = |
|
69 |
eq_equiv_class_iff [OF equiv_intrel UNIV_I UNIV_I, simp] |
|
70 |
||
71 |
lemma intrel_in_integ [simp]: "intrel``{(x,y)}:Integ" |
|
72 |
by (unfold Integ_def intrel_def quotient_def, fast) |
|
73 |
||
74 |
lemma inj_on_Abs_Integ: "inj_on Abs_Integ Integ" |
|
75 |
apply (rule inj_on_inverseI) |
|
76 |
apply (erule Abs_Integ_inverse) |
|
77 |
done |
|
78 |
||
79 |
declare inj_on_Abs_Integ [THEN inj_on_iff, simp] |
|
80 |
Abs_Integ_inverse [simp] |
|
81 |
||
82 |
lemma inj_Rep_Integ: "inj(Rep_Integ)" |
|
83 |
apply (rule inj_on_inverseI) |
|
84 |
apply (rule Rep_Integ_inverse) |
|
85 |
done |
|
86 |
||
87 |
||
88 |
(** int: the injection from "nat" to "int" **) |
|
89 |
||
90 |
lemma inj_int: "inj int" |
|
91 |
apply (rule inj_onI) |
|
92 |
apply (unfold int_def) |
|
93 |
apply (drule inj_on_Abs_Integ [THEN inj_onD]) |
|
94 |
apply (rule intrel_in_integ)+ |
|
95 |
apply (drule eq_equiv_class) |
|
96 |
apply (rule equiv_intrel, fast) |
|
97 |
apply (simp add: intrel_def) |
|
98 |
done |
|
99 |
||
100 |
||
101 |
subsection{*zminus: unary negation on Integ*} |
|
102 |
||
103 |
lemma zminus_congruent: "congruent intrel (%(x,y). intrel``{(y,x)})" |
|
104 |
apply (unfold congruent_def intrel_def) |
|
105 |
apply (auto simp add: add_ac) |
|
106 |
done |
|
107 |
||
108 |
lemma zminus: "- Abs_Integ(intrel``{(x,y)}) = Abs_Integ(intrel `` {(y,x)})" |
|
109 |
by (simp add: zminus_def equiv_intrel [THEN UN_equiv_class] zminus_congruent) |
|
110 |
||
111 |
(*Every integer can be written in the form Abs_Integ(...) *) |
|
112 |
lemma eq_Abs_Integ: |
|
113 |
"(!!x y. z = Abs_Integ(intrel``{(x,y)}) ==> P) ==> P" |
|
114 |
apply (rule_tac x1=z in Rep_Integ [unfolded Integ_def, THEN quotientE]) |
|
115 |
apply (drule_tac f = Abs_Integ in arg_cong) |
|
116 |
apply (rule_tac p = x in PairE) |
|
117 |
apply (simp add: Rep_Integ_inverse) |
|
118 |
done |
|
119 |
||
120 |
lemma zminus_zminus [simp]: "- (- z) = (z::int)" |
|
121 |
apply (rule_tac z = z in eq_Abs_Integ) |
|
122 |
apply (simp (no_asm_simp) add: zminus) |
|
123 |
done |
|
124 |
||
125 |
lemma inj_zminus: "inj(%z::int. -z)" |
|
126 |
apply (rule inj_onI) |
|
127 |
apply (drule_tac f = uminus in arg_cong, simp) |
|
128 |
done |
|
129 |
||
130 |
lemma zminus_0 [simp]: "- 0 = (0::int)" |
|
131 |
by (simp add: int_def Zero_int_def zminus) |
|
132 |
||
133 |
||
134 |
subsection{*neg: the test for negative integers*} |
|
135 |
||
136 |
||
137 |
lemma not_neg_int [simp]: "~ neg(int n)" |
|
138 |
by (simp add: neg_def int_def) |
|
139 |
||
140 |
lemma neg_zminus_int [simp]: "neg(- (int (Suc n)))" |
|
141 |
by (simp add: neg_def int_def zminus) |
|
142 |
||
143 |
||
144 |
subsection{*zadd: addition on Integ*} |
|
145 |
||
146 |
lemma zadd: |
|
147 |
"Abs_Integ(intrel``{(x1,y1)}) + Abs_Integ(intrel``{(x2,y2)}) = |
|
148 |
Abs_Integ(intrel``{(x1+x2, y1+y2)})" |
|
149 |
apply (simp add: zadd_def UN_UN_split_split_eq) |
|
150 |
apply (subst equiv_intrel [THEN UN_equiv_class2]) |
|
151 |
apply (auto simp add: congruent2_def) |
|
152 |
done |
|
153 |
||
154 |
lemma zminus_zadd_distrib [simp]: "- (z + w) = (- z) + (- w::int)" |
|
155 |
apply (rule_tac z = z in eq_Abs_Integ) |
|
156 |
apply (rule_tac z = w in eq_Abs_Integ) |
|
157 |
apply (simp (no_asm_simp) add: zminus zadd) |
|
158 |
done |
|
159 |
||
160 |
lemma zadd_commute: "(z::int) + w = w + z" |
|
161 |
apply (rule_tac z = z in eq_Abs_Integ) |
|
162 |
apply (rule_tac z = w in eq_Abs_Integ) |
|
163 |
apply (simp (no_asm_simp) add: add_ac zadd) |
|
164 |
done |
|
165 |
||
166 |
lemma zadd_assoc: "((z1::int) + z2) + z3 = z1 + (z2 + z3)" |
|
167 |
apply (rule_tac z = z1 in eq_Abs_Integ) |
|
168 |
apply (rule_tac z = z2 in eq_Abs_Integ) |
|
169 |
apply (rule_tac z = z3 in eq_Abs_Integ) |
|
170 |
apply (simp (no_asm_simp) add: zadd add_assoc) |
|
171 |
done |
|
172 |
||
173 |
(*For AC rewriting*) |
|
174 |
lemma zadd_left_commute: "x + (y + z) = y + ((x + z)::int)" |
|
175 |
apply (rule mk_left_commute [of "op +"]) |
|
176 |
apply (rule zadd_assoc) |
|
177 |
apply (rule zadd_commute) |
|
178 |
done |
|
179 |
||
180 |
(*Integer addition is an AC operator*) |
|
181 |
lemmas zadd_ac = zadd_assoc zadd_commute zadd_left_commute |
|
182 |
||
183 |
lemma zadd_int: "(int m) + (int n) = int (m + n)" |
|
184 |
by (simp add: int_def zadd) |
|
185 |
||
186 |
lemma zadd_int_left: "(int m) + (int n + z) = int (m + n) + z" |
|
187 |
by (simp add: zadd_int zadd_assoc [symmetric]) |
|
188 |
||
189 |
lemma int_Suc: "int (Suc m) = 1 + (int m)" |
|
190 |
by (simp add: One_int_def zadd_int) |
|
191 |
||
192 |
(*also for the instance declaration int :: plus_ac0*) |
|
193 |
lemma zadd_0 [simp]: "(0::int) + z = z" |
|
194 |
apply (unfold Zero_int_def int_def) |
|
195 |
apply (rule_tac z = z in eq_Abs_Integ) |
|
196 |
apply (simp (no_asm_simp) add: zadd) |
|
197 |
done |
|
198 |
||
199 |
lemma zadd_0_right [simp]: "z + (0::int) = z" |
|
200 |
by (rule trans [OF zadd_commute zadd_0]) |
|
201 |
||
202 |
lemma zadd_zminus_inverse [simp]: "z + (- z) = (0::int)" |
|
203 |
apply (unfold int_def Zero_int_def) |
|
204 |
apply (rule_tac z = z in eq_Abs_Integ) |
|
205 |
apply (simp (no_asm_simp) add: zminus zadd add_commute) |
|
206 |
done |
|
207 |
||
208 |
lemma zadd_zminus_inverse2 [simp]: "(- z) + z = (0::int)" |
|
209 |
apply (rule zadd_commute [THEN trans]) |
|
210 |
apply (rule zadd_zminus_inverse) |
|
211 |
done |
|
212 |
||
213 |
lemma zadd_zminus_cancel [simp]: "z + (- z + w) = (w::int)" |
|
214 |
by (simp add: zadd_assoc [symmetric] zadd_0) |
|
215 |
||
216 |
lemma zminus_zadd_cancel [simp]: "(-z) + (z + w) = (w::int)" |
|
217 |
by (simp add: zadd_assoc [symmetric] zadd_0) |
|
218 |
||
219 |
lemma zdiff0 [simp]: "(0::int) - x = -x" |
|
220 |
by (simp add: zdiff_def) |
|
221 |
||
222 |
lemma zdiff0_right [simp]: "x - (0::int) = x" |
|
223 |
by (simp add: zdiff_def) |
|
224 |
||
225 |
lemma zdiff_self [simp]: "x - x = (0::int)" |
|
226 |
by (simp add: zdiff_def Zero_int_def) |
|
227 |
||
228 |
||
229 |
(** Lemmas **) |
|
230 |
||
231 |
lemma zadd_assoc_cong: "(z::int) + v = z' + v' ==> z + (v + w) = z' + (v' + w)" |
|
232 |
by (simp add: zadd_assoc [symmetric]) |
|
233 |
||
234 |
lemma zadd_assoc_swap: "(z::int) + (v + w) = v + (z + w)" |
|
235 |
by (rule zadd_commute [THEN zadd_assoc_cong]) |
|
236 |
||
237 |
||
238 |
subsection{*zmult: multiplication on Integ*} |
|
239 |
||
240 |
(*Congruence property for multiplication*) |
|
241 |
lemma zmult_congruent2: "congruent2 intrel |
|
242 |
(%p1 p2. (%(x1,y1). (%(x2,y2). |
|
243 |
intrel``{(x1*x2 + y1*y2, x1*y2 + y1*x2)}) p2) p1)" |
|
244 |
apply (rule equiv_intrel [THEN congruent2_commuteI]) |
|
245 |
apply (rule_tac [2] p=w in PairE) |
|
246 |
apply (force simp add: add_ac mult_ac, clarify) |
|
247 |
apply (simp (no_asm_simp) del: equiv_intrel_iff add: add_ac mult_ac) |
|
248 |
apply (rename_tac x1 x2 y1 y2 z1 z2) |
|
249 |
apply (rule equiv_class_eq [OF equiv_intrel intrel_iff [THEN iffD2]]) |
|
250 |
apply (simp add: intrel_def) |
|
251 |
apply (subgoal_tac "x1*z1 + y2*z1 = y1*z1 + x2*z1 & x1*z2 + y2*z2 = y1*z2 + x2*z2", arith) |
|
252 |
apply (simp add: add_mult_distrib [symmetric]) |
|
253 |
done |
|
254 |
||
255 |
lemma zmult: |
|
256 |
"Abs_Integ((intrel``{(x1,y1)})) * Abs_Integ((intrel``{(x2,y2)})) = |
|
257 |
Abs_Integ(intrel `` {(x1*x2 + y1*y2, x1*y2 + y1*x2)})" |
|
258 |
apply (unfold zmult_def) |
|
259 |
apply (simp (no_asm_simp) add: UN_UN_split_split_eq zmult_congruent2 equiv_intrel [THEN UN_equiv_class2]) |
|
260 |
done |
|
261 |
||
262 |
lemma zmult_zminus: "(- z) * w = - (z * (w::int))" |
|
263 |
apply (rule_tac z = z in eq_Abs_Integ) |
|
264 |
apply (rule_tac z = w in eq_Abs_Integ) |
|
265 |
apply (simp (no_asm_simp) add: zminus zmult add_ac) |
|
266 |
done |
|
267 |
||
268 |
lemma zmult_commute: "(z::int) * w = w * z" |
|
269 |
apply (rule_tac z = z in eq_Abs_Integ) |
|
270 |
apply (rule_tac z = w in eq_Abs_Integ) |
|
271 |
apply (simp (no_asm_simp) add: zmult add_ac mult_ac) |
|
272 |
done |
|
273 |
||
274 |
lemma zmult_assoc: "((z1::int) * z2) * z3 = z1 * (z2 * z3)" |
|
275 |
apply (rule_tac z = z1 in eq_Abs_Integ) |
|
276 |
apply (rule_tac z = z2 in eq_Abs_Integ) |
|
277 |
apply (rule_tac z = z3 in eq_Abs_Integ) |
|
278 |
apply (simp (no_asm_simp) add: add_mult_distrib2 zmult add_ac mult_ac) |
|
279 |
done |
|
280 |
||
281 |
(*For AC rewriting*) |
|
282 |
lemma zmult_left_commute: "x * (y * z) = y * ((x * z)::int)" |
|
283 |
apply (rule mk_left_commute [of "op *"]) |
|
284 |
apply (rule zmult_assoc) |
|
285 |
apply (rule zmult_commute) |
|
286 |
done |
|
287 |
||
288 |
(*Integer multiplication is an AC operator*) |
|
289 |
lemmas zmult_ac = zmult_assoc zmult_commute zmult_left_commute |
|
290 |
||
291 |
lemma zadd_zmult_distrib: "((z1::int) + z2) * w = (z1 * w) + (z2 * w)" |
|
292 |
apply (rule_tac z = z1 in eq_Abs_Integ) |
|
293 |
apply (rule_tac z = z2 in eq_Abs_Integ) |
|
294 |
apply (rule_tac z = w in eq_Abs_Integ) |
|
295 |
apply (simp add: add_mult_distrib2 zadd zmult add_ac mult_ac) |
|
296 |
done |
|
297 |
||
298 |
lemma zmult_zminus_right: "w * (- z) = - (w * (z::int))" |
|
299 |
by (simp add: zmult_commute [of w] zmult_zminus) |
|
300 |
||
301 |
lemma zadd_zmult_distrib2: "(w::int) * (z1 + z2) = (w * z1) + (w * z2)" |
|
302 |
by (simp add: zmult_commute [of w] zadd_zmult_distrib) |
|
303 |
||
304 |
lemma zdiff_zmult_distrib: "((z1::int) - z2) * w = (z1 * w) - (z2 * w)" |
|
305 |
apply (unfold zdiff_def) |
|
306 |
apply (subst zadd_zmult_distrib) |
|
307 |
apply (simp add: zmult_zminus) |
|
308 |
done |
|
309 |
||
310 |
lemma zdiff_zmult_distrib2: "(w::int) * (z1 - z2) = (w * z1) - (w * z2)" |
|
311 |
by (simp add: zmult_commute [of w] zdiff_zmult_distrib) |
|
312 |
||
313 |
lemmas int_distrib = |
|
314 |
zadd_zmult_distrib zadd_zmult_distrib2 |
|
315 |
zdiff_zmult_distrib zdiff_zmult_distrib2 |
|
316 |
||
317 |
lemma zmult_int: "(int m) * (int n) = int (m * n)" |
|
318 |
by (simp add: int_def zmult) |
|
319 |
||
320 |
lemma zmult_0 [simp]: "0 * z = (0::int)" |
|
321 |
apply (unfold Zero_int_def int_def) |
|
322 |
apply (rule_tac z = z in eq_Abs_Integ) |
|
323 |
apply (simp (no_asm_simp) add: zmult) |
|
324 |
done |
|
325 |
||
326 |
lemma zmult_1 [simp]: "(1::int) * z = z" |
|
327 |
apply (unfold One_int_def int_def) |
|
328 |
apply (rule_tac z = z in eq_Abs_Integ) |
|
329 |
apply (simp (no_asm_simp) add: zmult) |
|
330 |
done |
|
331 |
||
332 |
lemma zmult_0_right [simp]: "z * 0 = (0::int)" |
|
333 |
by (rule trans [OF zmult_commute zmult_0]) |
|
334 |
||
335 |
lemma zmult_1_right [simp]: "z * (1::int) = z" |
|
336 |
by (rule trans [OF zmult_commute zmult_1]) |
|
337 |
||
338 |
||
339 |
(* Theorems about less and less_equal *) |
|
340 |
||
341 |
(*This lemma allows direct proofs of other <-properties*) |
|
342 |
lemma zless_iff_Suc_zadd: |
|
343 |
"(w < z) = (EX n. z = w + int(Suc n))" |
|
344 |
apply (unfold zless_def neg_def zdiff_def int_def) |
|
345 |
apply (rule_tac z = z in eq_Abs_Integ) |
|
346 |
apply (rule_tac z = w in eq_Abs_Integ, clarify) |
|
347 |
apply (simp add: zadd zminus) |
|
348 |
apply (safe dest!: less_imp_Suc_add) |
|
349 |
apply (rule_tac x = k in exI) |
|
350 |
apply (simp_all add: add_ac) |
|
351 |
done |
|
352 |
||
353 |
lemma zless_zadd_Suc: "z < z + int (Suc n)" |
|
354 |
by (auto simp add: zless_iff_Suc_zadd zadd_assoc zadd_int) |
|
355 |
||
356 |
lemma zless_trans: "[| z1<z2; z2<z3 |] ==> z1 < (z3::int)" |
|
357 |
by (auto simp add: zless_iff_Suc_zadd zadd_assoc zadd_int) |
|
358 |
||
359 |
lemma zless_not_sym: "!!w::int. z<w ==> ~w<z" |
|
360 |
apply (safe dest!: zless_iff_Suc_zadd [THEN iffD1]) |
|
361 |
apply (rule_tac z = z in eq_Abs_Integ, safe) |
|
362 |
apply (simp add: int_def zadd) |
|
363 |
done |
|
364 |
||
365 |
(* [| n<m; ~P ==> m<n |] ==> P *) |
|
366 |
lemmas zless_asym = zless_not_sym [THEN swap, standard] |
|
367 |
||
368 |
lemma zless_not_refl: "!!z::int. ~ z<z" |
|
369 |
apply (rule zless_asym [THEN notI]) |
|
370 |
apply (assumption+) |
|
371 |
done |
|
372 |
||
373 |
(* z<z ==> R *) |
|
374 |
lemmas zless_irrefl = zless_not_refl [THEN notE, standard, elim!] |
|
375 |
||
376 |
||
377 |
(*"Less than" is a linear ordering*) |
|
378 |
lemma zless_linear: |
|
379 |
"z<w | z=w | w<(z::int)" |
|
380 |
apply (unfold zless_def neg_def zdiff_def) |
|
381 |
apply (rule_tac z = z in eq_Abs_Integ) |
|
382 |
apply (rule_tac z = w in eq_Abs_Integ, safe) |
|
383 |
apply (simp add: zadd zminus Image_iff Bex_def) |
|
384 |
apply (rule_tac m1 = "x+ya" and n1 = "xa+y" in less_linear [THEN disjE]) |
|
385 |
apply (force simp add: add_ac)+ |
|
386 |
done |
|
387 |
||
388 |
lemma int_neq_iff: "!!w::int. (w ~= z) = (w<z | z<w)" |
|
389 |
by (cut_tac zless_linear, blast) |
|
390 |
||
391 |
(*** eliminates ~= in premises ***) |
|
392 |
lemmas int_neqE = int_neq_iff [THEN iffD1, THEN disjE, standard] |
|
393 |
||
394 |
lemma int_int_eq [iff]: "(int m = int n) = (m = n)" |
|
395 |
by (fast elim!: inj_int [THEN injD]) |
|
396 |
||
397 |
lemma int_eq_0_conv [simp]: "(int n = 0) = (n = 0)" |
|
398 |
by (simp add: Zero_int_def) |
|
399 |
||
400 |
lemma zless_int [simp]: "(int m < int n) = (m<n)" |
|
401 |
by (simp add: less_iff_Suc_add zless_iff_Suc_zadd zadd_int) |
|
402 |
||
403 |
lemma int_less_0_conv [simp]: "~ (int k < 0)" |
|
404 |
by (simp add: Zero_int_def) |
|
405 |
||
406 |
lemma zero_less_int_conv [simp]: "(0 < int n) = (0 < n)" |
|
407 |
by (simp add: Zero_int_def) |
|
408 |
||
409 |
||
410 |
(*** Properties of <= ***) |
|
411 |
||
412 |
lemma zle_int [simp]: "(int m <= int n) = (m<=n)" |
|
413 |
by (simp add: zle_def le_def) |
|
414 |
||
415 |
lemma zero_zle_int [simp]: "(0 <= int n)" |
|
416 |
by (simp add: Zero_int_def) |
|
417 |
||
418 |
lemma int_le_0_conv [simp]: "(int n <= 0) = (n = 0)" |
|
419 |
by (simp add: Zero_int_def) |
|
420 |
||
421 |
lemma zle_imp_zless_or_eq: "z <= w ==> z < w | z=(w::int)" |
|
422 |
apply (unfold zle_def) |
|
423 |
apply (cut_tac zless_linear) |
|
424 |
apply (blast elim: zless_asym) |
|
425 |
done |
|
426 |
||
427 |
lemma zless_or_eq_imp_zle: "z<w | z=w ==> z <= (w::int)" |
|
428 |
apply (unfold zle_def) |
|
429 |
apply (cut_tac zless_linear) |
|
430 |
apply (blast elim: zless_asym) |
|
431 |
done |
|
432 |
||
433 |
lemma int_le_less: "(x <= (y::int)) = (x < y | x=y)" |
|
434 |
apply (rule iffI) |
|
435 |
apply (erule zle_imp_zless_or_eq) |
|
436 |
apply (erule zless_or_eq_imp_zle) |
|
437 |
done |
|
438 |
||
439 |
lemma zle_refl: "w <= (w::int)" |
|
440 |
by (simp add: int_le_less) |
|
441 |
||
442 |
(* Axiom 'linorder_linear' of class 'linorder': *) |
|
443 |
lemma zle_linear: "(z::int) <= w | w <= z" |
|
444 |
apply (simp add: int_le_less) |
|
445 |
apply (cut_tac zless_linear, blast) |
|
446 |
done |
|
447 |
||
448 |
(* Axiom 'order_trans of class 'order': *) |
|
449 |
lemma zle_trans: "[| i <= j; j <= k |] ==> i <= (k::int)" |
|
450 |
apply (drule zle_imp_zless_or_eq) |
|
451 |
apply (drule zle_imp_zless_or_eq) |
|
452 |
apply (rule zless_or_eq_imp_zle) |
|
453 |
apply (blast intro: zless_trans) |
|
454 |
done |
|
455 |
||
456 |
lemma zle_anti_sym: "[| z <= w; w <= z |] ==> z = (w::int)" |
|
457 |
apply (drule zle_imp_zless_or_eq) |
|
458 |
apply (drule zle_imp_zless_or_eq) |
|
459 |
apply (blast elim: zless_asym) |
|
460 |
done |
|
461 |
||
462 |
(* Axiom 'order_less_le' of class 'order': *) |
|
463 |
lemma int_less_le: "((w::int) < z) = (w <= z & w ~= z)" |
|
464 |
apply (simp add: zle_def int_neq_iff) |
|
465 |
apply (blast elim!: zless_asym) |
|
466 |
done |
|
467 |
||
468 |
||
469 |
(*** Subtraction laws ***) |
|
470 |
||
471 |
lemma zadd_zdiff_eq: "x + (y - z) = (x + y) - (z::int)" |
|
472 |
by (simp add: zdiff_def zadd_ac) |
|
473 |
||
474 |
lemma zdiff_zadd_eq: "(x - y) + z = (x + z) - (y::int)" |
|
475 |
by (simp add: zdiff_def zadd_ac) |
|
476 |
||
477 |
lemma zdiff_zdiff_eq: "(x - y) - z = x - (y + (z::int))" |
|
478 |
by (simp add: zdiff_def zadd_ac) |
|
479 |
||
480 |
lemma zdiff_zdiff_eq2: "x - (y - z) = (x + z) - (y::int)" |
|
481 |
by (simp add: zdiff_def zadd_ac) |
|
482 |
||
483 |
lemma zdiff_zless_eq: "(x-y < z) = (x < z + (y::int))" |
|
484 |
apply (unfold zless_def zdiff_def) |
|
485 |
apply (simp add: zadd_ac) |
|
486 |
done |
|
487 |
||
488 |
lemma zless_zdiff_eq: "(x < z-y) = (x + (y::int) < z)" |
|
489 |
apply (unfold zless_def zdiff_def) |
|
490 |
apply (simp add: zadd_ac) |
|
491 |
done |
|
492 |
||
493 |
lemma zdiff_zle_eq: "(x-y <= z) = (x <= z + (y::int))" |
|
494 |
apply (unfold zle_def) |
|
495 |
apply (simp add: zless_zdiff_eq) |
|
496 |
done |
|
497 |
||
498 |
lemma zle_zdiff_eq: "(x <= z-y) = (x + (y::int) <= z)" |
|
499 |
apply (unfold zle_def) |
|
500 |
apply (simp add: zdiff_zless_eq) |
|
501 |
done |
|
502 |
||
503 |
lemma zdiff_eq_eq: "(x-y = z) = (x = z + (y::int))" |
|
504 |
by (auto simp add: zdiff_def zadd_assoc Zero_int_def [symmetric]) |
|
505 |
||
506 |
lemma eq_zdiff_eq: "(x = z-y) = (x + (y::int) = z)" |
|
507 |
by (auto simp add: zdiff_def zadd_assoc Zero_int_def [symmetric]) |
|
508 |
||
509 |
(*This list of rewrites simplifies (in)equalities by bringing subtractions |
|
510 |
to the top and then moving negative terms to the other side. |
|
511 |
Use with zadd_ac*) |
|
512 |
lemmas zcompare_rls = |
|
513 |
zdiff_def [symmetric] |
|
514 |
zadd_zdiff_eq zdiff_zadd_eq zdiff_zdiff_eq zdiff_zdiff_eq2 |
|
515 |
zdiff_zless_eq zless_zdiff_eq zdiff_zle_eq zle_zdiff_eq |
|
516 |
zdiff_eq_eq eq_zdiff_eq |
|
517 |
||
518 |
||
519 |
(** Cancellation laws **) |
|
520 |
||
521 |
lemma zadd_left_cancel [simp]: "!!w::int. (z + w' = z + w) = (w' = w)" |
|
522 |
apply safe |
|
523 |
apply (drule_tac f = "%x. x + (-z) " in arg_cong) |
|
524 |
apply (simp add: Zero_int_def [symmetric] zadd_ac) |
|
525 |
done |
|
526 |
||
527 |
lemma zadd_right_cancel [simp]: "!!z::int. (w' + z = w + z) = (w' = w)" |
|
528 |
by (simp add: zadd_ac) |
|
529 |
||
530 |
||
531 |
(** For the cancellation simproc. |
|
532 |
The idea is to cancel like terms on opposite sides by subtraction **) |
|
533 |
||
534 |
lemma zless_eqI: "(x::int) - y = x' - y' ==> (x<y) = (x'<y')" |
|
535 |
by (simp add: zless_def) |
|
536 |
||
537 |
lemma zle_eqI: "(x::int) - y = x' - y' ==> (y<=x) = (y'<=x')" |
|
538 |
apply (drule zless_eqI) |
|
539 |
apply (simp (no_asm_simp) add: zle_def) |
|
540 |
done |
|
541 |
||
542 |
lemma zeq_eqI: "(x::int) - y = x' - y' ==> (x=y) = (x'=y')" |
|
543 |
apply safe |
|
544 |
apply (simp_all add: eq_zdiff_eq zdiff_eq_eq) |
|
545 |
done |
|
546 |
||
547 |
ML |
|
548 |
{* |
|
549 |
val int_def = thm "int_def"; |
|
550 |
val neg_def = thm "neg_def"; |
|
551 |
val iszero_def = thm "iszero_def"; |
|
552 |
val Zero_int_def = thm "Zero_int_def"; |
|
553 |
val One_int_def = thm "One_int_def"; |
|
554 |
val zadd_def = thm "zadd_def"; |
|
555 |
val zdiff_def = thm "zdiff_def"; |
|
556 |
val zless_def = thm "zless_def"; |
|
557 |
val zle_def = thm "zle_def"; |
|
558 |
val zmult_def = thm "zmult_def"; |
|
559 |
||
560 |
val intrel_iff = thm "intrel_iff"; |
|
561 |
val equiv_intrel = thm "equiv_intrel"; |
|
562 |
val equiv_intrel_iff = thm "equiv_intrel_iff"; |
|
563 |
val intrel_in_integ = thm "intrel_in_integ"; |
|
564 |
val inj_on_Abs_Integ = thm "inj_on_Abs_Integ"; |
|
565 |
val inj_Rep_Integ = thm "inj_Rep_Integ"; |
|
566 |
val inj_int = thm "inj_int"; |
|
567 |
val zminus_congruent = thm "zminus_congruent"; |
|
568 |
val zminus = thm "zminus"; |
|
569 |
val eq_Abs_Integ = thm "eq_Abs_Integ"; |
|
570 |
val zminus_zminus = thm "zminus_zminus"; |
|
571 |
val inj_zminus = thm "inj_zminus"; |
|
572 |
val zminus_0 = thm "zminus_0"; |
|
573 |
val not_neg_int = thm "not_neg_int"; |
|
574 |
val neg_zminus_int = thm "neg_zminus_int"; |
|
575 |
val zadd = thm "zadd"; |
|
576 |
val zminus_zadd_distrib = thm "zminus_zadd_distrib"; |
|
577 |
val zadd_commute = thm "zadd_commute"; |
|
578 |
val zadd_assoc = thm "zadd_assoc"; |
|
579 |
val zadd_left_commute = thm "zadd_left_commute"; |
|
580 |
val zadd_ac = thms "zadd_ac"; |
|
581 |
val zadd_int = thm "zadd_int"; |
|
582 |
val zadd_int_left = thm "zadd_int_left"; |
|
583 |
val int_Suc = thm "int_Suc"; |
|
584 |
val zadd_0 = thm "zadd_0"; |
|
585 |
val zadd_0_right = thm "zadd_0_right"; |
|
586 |
val zadd_zminus_inverse = thm "zadd_zminus_inverse"; |
|
587 |
val zadd_zminus_inverse2 = thm "zadd_zminus_inverse2"; |
|
588 |
val zadd_zminus_cancel = thm "zadd_zminus_cancel"; |
|
589 |
val zminus_zadd_cancel = thm "zminus_zadd_cancel"; |
|
590 |
val zdiff0 = thm "zdiff0"; |
|
591 |
val zdiff0_right = thm "zdiff0_right"; |
|
592 |
val zdiff_self = thm "zdiff_self"; |
|
593 |
val zadd_assoc_cong = thm "zadd_assoc_cong"; |
|
594 |
val zadd_assoc_swap = thm "zadd_assoc_swap"; |
|
595 |
val zmult_congruent2 = thm "zmult_congruent2"; |
|
596 |
val zmult = thm "zmult"; |
|
597 |
val zmult_zminus = thm "zmult_zminus"; |
|
598 |
val zmult_commute = thm "zmult_commute"; |
|
599 |
val zmult_assoc = thm "zmult_assoc"; |
|
600 |
val zmult_left_commute = thm "zmult_left_commute"; |
|
601 |
val zmult_ac = thms "zmult_ac"; |
|
602 |
val zadd_zmult_distrib = thm "zadd_zmult_distrib"; |
|
603 |
val zmult_zminus_right = thm "zmult_zminus_right"; |
|
604 |
val zadd_zmult_distrib2 = thm "zadd_zmult_distrib2"; |
|
605 |
val zdiff_zmult_distrib = thm "zdiff_zmult_distrib"; |
|
606 |
val zdiff_zmult_distrib2 = thm "zdiff_zmult_distrib2"; |
|
607 |
val int_distrib = thms "int_distrib"; |
|
608 |
val zmult_int = thm "zmult_int"; |
|
609 |
val zmult_0 = thm "zmult_0"; |
|
610 |
val zmult_1 = thm "zmult_1"; |
|
611 |
val zmult_0_right = thm "zmult_0_right"; |
|
612 |
val zmult_1_right = thm "zmult_1_right"; |
|
613 |
val zless_iff_Suc_zadd = thm "zless_iff_Suc_zadd"; |
|
614 |
val zless_zadd_Suc = thm "zless_zadd_Suc"; |
|
615 |
val zless_trans = thm "zless_trans"; |
|
616 |
val zless_not_sym = thm "zless_not_sym"; |
|
617 |
val zless_asym = thm "zless_asym"; |
|
618 |
val zless_not_refl = thm "zless_not_refl"; |
|
619 |
val zless_irrefl = thm "zless_irrefl"; |
|
620 |
val zless_linear = thm "zless_linear"; |
|
621 |
val int_neq_iff = thm "int_neq_iff"; |
|
622 |
val int_neqE = thm "int_neqE"; |
|
623 |
val int_int_eq = thm "int_int_eq"; |
|
624 |
val int_eq_0_conv = thm "int_eq_0_conv"; |
|
625 |
val zless_int = thm "zless_int"; |
|
626 |
val int_less_0_conv = thm "int_less_0_conv"; |
|
627 |
val zero_less_int_conv = thm "zero_less_int_conv"; |
|
628 |
val zle_int = thm "zle_int"; |
|
629 |
val zero_zle_int = thm "zero_zle_int"; |
|
630 |
val int_le_0_conv = thm "int_le_0_conv"; |
|
631 |
val zle_imp_zless_or_eq = thm "zle_imp_zless_or_eq"; |
|
632 |
val zless_or_eq_imp_zle = thm "zless_or_eq_imp_zle"; |
|
633 |
val int_le_less = thm "int_le_less"; |
|
634 |
val zle_refl = thm "zle_refl"; |
|
635 |
val zle_linear = thm "zle_linear"; |
|
636 |
val zle_trans = thm "zle_trans"; |
|
637 |
val zle_anti_sym = thm "zle_anti_sym"; |
|
638 |
val int_less_le = thm "int_less_le"; |
|
639 |
val zadd_zdiff_eq = thm "zadd_zdiff_eq"; |
|
640 |
val zdiff_zadd_eq = thm "zdiff_zadd_eq"; |
|
641 |
val zdiff_zdiff_eq = thm "zdiff_zdiff_eq"; |
|
642 |
val zdiff_zdiff_eq2 = thm "zdiff_zdiff_eq2"; |
|
643 |
val zdiff_zless_eq = thm "zdiff_zless_eq"; |
|
644 |
val zless_zdiff_eq = thm "zless_zdiff_eq"; |
|
645 |
val zdiff_zle_eq = thm "zdiff_zle_eq"; |
|
646 |
val zle_zdiff_eq = thm "zle_zdiff_eq"; |
|
647 |
val zdiff_eq_eq = thm "zdiff_eq_eq"; |
|
648 |
val eq_zdiff_eq = thm "eq_zdiff_eq"; |
|
649 |
val zcompare_rls = thms "zcompare_rls"; |
|
650 |
val zadd_left_cancel = thm "zadd_left_cancel"; |
|
651 |
val zadd_right_cancel = thm "zadd_right_cancel"; |
|
652 |
val zless_eqI = thm "zless_eqI"; |
|
653 |
val zle_eqI = thm "zle_eqI"; |
|
654 |
val zeq_eqI = thm "zeq_eqI"; |
|
655 |
*} |
|
656 |
||
5508 | 657 |
end |