1 (* Title: Integ.ML |
1 (* Title: Integ.ML |
2 ID: $Id$ |
2 ID: $Id$ |
3 Authors: Riccardo Mattolini, Dip. Sistemi e Informatica |
3 Authors: Riccardo Mattolini, Dip. Sistemi e Informatica |
4 Lawrence C Paulson, Cambridge University Computer Laboratory |
4 Lawrence C Paulson, Cambridge University Computer Laboratory |
5 Copyright 1994 Universita' di Firenze |
5 Copyright 1994 Universita' di Firenze |
6 Copyright 1993 University of Cambridge |
6 Copyright 1993 University of Cambridge |
7 |
7 |
8 The integers as equivalence classes over nat*nat. |
8 The integers as equivalence classes over nat*nat. |
9 |
9 |
82 by (rtac inj_onto_inverseI 1); |
82 by (rtac inj_onto_inverseI 1); |
83 by (etac Abs_Integ_inverse 1); |
83 by (etac Abs_Integ_inverse 1); |
84 qed "inj_onto_Abs_Integ"; |
84 qed "inj_onto_Abs_Integ"; |
85 |
85 |
86 Addsimps [equiv_intrel_iff, inj_onto_Abs_Integ RS inj_onto_iff, |
86 Addsimps [equiv_intrel_iff, inj_onto_Abs_Integ RS inj_onto_iff, |
87 intrel_iff, intrel_in_integ, Abs_Integ_inverse]; |
87 intrel_iff, intrel_in_integ, Abs_Integ_inverse]; |
88 |
88 |
89 goal Integ.thy "inj(Rep_Integ)"; |
89 goal Integ.thy "inj(Rep_Integ)"; |
90 by (rtac inj_inverseI 1); |
90 by (rtac inj_inverseI 1); |
91 by (rtac Rep_Integ_inverse 1); |
91 by (rtac Rep_Integ_inverse 1); |
92 qed "inj_Rep_Integ"; |
92 qed "inj_Rep_Integ"; |
211 by (etac subst 1); |
211 by (etac subst 1); |
212 by (res_inst_tac [("m1","x")] (add_commute RS ssubst) 1); |
212 by (res_inst_tac [("m1","x")] (add_commute RS ssubst) 1); |
213 by (asm_simp_tac (!simpset addsimps [diff_add_inverse,diff_add_0]) 1); |
213 by (asm_simp_tac (!simpset addsimps [diff_add_inverse,diff_add_0]) 1); |
214 by (rtac impI 1); |
214 by (rtac impI 1); |
215 by (asm_simp_tac (!simpset addsimps |
215 by (asm_simp_tac (!simpset addsimps |
216 [diff_add_inverse, diff_add_0, diff_Suc_add_0, |
216 [diff_add_inverse, diff_add_0, diff_Suc_add_0, |
217 diff_Suc_add_inverse]) 1); |
217 diff_Suc_add_inverse]) 1); |
218 qed "zmagnitude_congruent"; |
218 qed "zmagnitude_congruent"; |
219 |
219 |
220 (*Resolve th against the corresponding facts for zmagnitude*) |
220 (*Resolve th against the corresponding facts for zmagnitude*) |
221 val zmagnitude_ize = RSLIST [equiv_intrel, zmagnitude_congruent]; |
221 val zmagnitude_ize = RSLIST [equiv_intrel, zmagnitude_congruent]; |
222 |
222 |
326 goal Integ.thy "((k::nat) + l) + (m + n) = (k + m) + (n + l)"; |
326 goal Integ.thy "((k::nat) + l) + (m + n) = (k + m) + (n + l)"; |
327 by (simp_tac (!simpset addsimps add_ac) 1); |
327 by (simp_tac (!simpset addsimps add_ac) 1); |
328 qed "zmult_congruent_lemma"; |
328 qed "zmult_congruent_lemma"; |
329 |
329 |
330 goal Integ.thy |
330 goal Integ.thy |
331 "congruent2 intrel (%p1 p2. \ |
331 "congruent2 intrel (%p1 p2. \ |
332 \ split (%x1 y1. split (%x2 y2. \ |
332 \ split (%x1 y1. split (%x2 y2. \ |
333 \ intrel^^{(x1*x2 + y1*y2, x1*y2 + y1*x2)}) p2) p1)"; |
333 \ intrel^^{(x1*x2 + y1*y2, x1*y2 + y1*x2)}) p2) p1)"; |
334 by (rtac (equiv_intrel RS congruent2_commuteI) 1); |
334 by (rtac (equiv_intrel RS congruent2_commuteI) 1); |
335 by (safe_tac intrel_cs); |
335 by (safe_tac intrel_cs); |
336 by (rewtac split_def); |
336 by (rewtac split_def); |
337 by (simp_tac (!simpset addsimps add_ac@mult_ac) 1); |
337 by (simp_tac (!simpset addsimps add_ac@mult_ac) 1); |
349 |
349 |
350 (*Resolve th against the corresponding facts for zmult*) |
350 (*Resolve th against the corresponding facts for zmult*) |
351 val zmult_ize = RSLIST [equiv_intrel, zmult_congruent2]; |
351 val zmult_ize = RSLIST [equiv_intrel, zmult_congruent2]; |
352 |
352 |
353 goalw Integ.thy [zmult_def] |
353 goalw Integ.thy [zmult_def] |
354 "Abs_Integ((intrel^^{(x1,y1)})) * Abs_Integ((intrel^^{(x2,y2)})) = \ |
354 "Abs_Integ((intrel^^{(x1,y1)})) * Abs_Integ((intrel^^{(x2,y2)})) = \ |
355 \ Abs_Integ(intrel ^^ {(x1*x2 + y1*y2, x1*y2 + y1*x2)})"; |
355 \ Abs_Integ(intrel ^^ {(x1*x2 + y1*y2, x1*y2 + y1*x2)})"; |
356 by (simp_tac (!simpset addsimps [zmult_ize UN_equiv_class2]) 1); |
356 by (simp_tac (!simpset addsimps [zmult_ize UN_equiv_class2]) 1); |
357 qed "zmult"; |
357 qed "zmult"; |
358 |
358 |
359 goalw Integ.thy [znat_def] "$#0 * z = $#0"; |
359 goalw Integ.thy [znat_def] "$#0 * z = $#0"; |
431 [zadd_0, zadd_0_right, zadd_zminus_inverse, zadd_zminus_inverse2]; |
431 [zadd_0, zadd_0_right, zadd_zminus_inverse, zadd_zminus_inverse2]; |
432 |
432 |
433 val zminus_simps = [zminus_zminus, zminus_0, zminus_zadd_distrib]; |
433 val zminus_simps = [zminus_zminus, zminus_0, zminus_zadd_distrib]; |
434 |
434 |
435 val zmult_simps = [zmult_0, zmult_1, zmult_0_right, zmult_1_right, |
435 val zmult_simps = [zmult_0, zmult_1, zmult_0_right, zmult_1_right, |
436 zmult_zminus, zmult_zminus_right]; |
436 zmult_zminus, zmult_zminus_right]; |
437 |
437 |
438 Addsimps (zadd_simps @ zminus_simps @ zmult_simps @ |
438 Addsimps (zadd_simps @ zminus_simps @ zmult_simps @ |
439 [zmagnitude_znat, zmagnitude_zminus_znat]); |
439 [zmagnitude_znat, zmagnitude_zminus_znat]); |
440 |
440 |
441 |
441 |
698 by (fast_tac (HOL_cs addIs [zless_trans]) 1); |
698 by (fast_tac (HOL_cs addIs [zless_trans]) 1); |
699 qed "zle_zless_trans"; |
699 qed "zle_zless_trans"; |
700 |
700 |
701 goal Integ.thy "!!i. [| i <= j; j <= k |] ==> i <= (k::int)"; |
701 goal Integ.thy "!!i. [| i <= j; j <= k |] ==> i <= (k::int)"; |
702 by (EVERY1 [dtac zle_imp_zless_or_eq, dtac zle_imp_zless_or_eq, |
702 by (EVERY1 [dtac zle_imp_zless_or_eq, dtac zle_imp_zless_or_eq, |
703 rtac zless_or_eq_imp_zle, fast_tac (HOL_cs addIs [zless_trans])]); |
703 rtac zless_or_eq_imp_zle, fast_tac (HOL_cs addIs [zless_trans])]); |
704 qed "zle_trans"; |
704 qed "zle_trans"; |
705 |
705 |
706 goal Integ.thy "!!z. [| z <= w; w <= z |] ==> z = (w::int)"; |
706 goal Integ.thy "!!z. [| z <= w; w <= z |] ==> z = (w::int)"; |
707 by (EVERY1 [dtac zle_imp_zless_or_eq, dtac zle_imp_zless_or_eq, |
707 by (EVERY1 [dtac zle_imp_zless_or_eq, dtac zle_imp_zless_or_eq, |
708 fast_tac (HOL_cs addEs [zless_anti_refl,zless_asym])]); |
708 fast_tac (HOL_cs addEs [zless_anti_refl,zless_asym])]); |
709 qed "zle_anti_sym"; |
709 qed "zle_anti_sym"; |
710 |
710 |
711 |
711 |
712 goal Integ.thy "!!w w' z::int. z + w' = z + w ==> w' = w"; |
712 goal Integ.thy "!!w w' z::int. z + w' = z + w ==> w' = w"; |
713 by (dres_inst_tac [("f", "%x. x + $~z")] arg_cong 1); |
713 by (dres_inst_tac [("f", "%x. x + $~z")] arg_cong 1); |