author | wenzelm |
Wed, 02 Aug 2000 19:40:14 +0200 | |
changeset 9502 | 50ec59aff389 |
parent 9392 | c8e6529cc082 |
child 9544 | f9202e219a29 |
permissions | -rw-r--r-- |
5508 | 1 |
(* Title: IntDef.ML |
2 |
ID: $Id$ |
|
3 |
Authors: Lawrence C Paulson, Cambridge University Computer Laboratory |
|
4 |
Copyright 1993 University of Cambridge |
|
5 |
||
6 |
The integers as equivalence classes over nat*nat. |
|
7 |
*) |
|
8 |
||
9 |
||
8937 | 10 |
(*Rewrite the overloaded 0::int to (int 0)*) |
11 |
Addsimps [Zero_def]; |
|
12 |
||
9392 | 13 |
Goalw [intrel_def] "((x1,y1),(x2,y2)): intrel = (x1+y2 = x2+y1)"; |
14 |
by (Blast_tac 1); |
|
5508 | 15 |
qed "intrel_iff"; |
16 |
||
9392 | 17 |
Goalw [intrel_def] "(x,x): intrel"; |
9366 | 18 |
by (pair_tac "x" 1); |
9392 | 19 |
by (Blast_tac 1); |
5508 | 20 |
qed "intrel_refl"; |
21 |
||
9392 | 22 |
Goalw [intrel_def, equiv_def, refl_def, sym_def, trans_def] |
7375
2cb340e66d15
tidied, allowing pattern-matching in defs of zadd and zmult
paulson
parents:
7127
diff
changeset
|
23 |
"equiv UNIV intrel"; |
9392 | 24 |
by Auto_tac; |
5508 | 25 |
qed "equiv_intrel"; |
26 |
||
9392 | 27 |
bind_thm ("equiv_intrel_iff", |
28 |
[equiv_intrel, UNIV_I, UNIV_I] MRS eq_equiv_class_iff); |
|
5508 | 29 |
|
9392 | 30 |
Goalw [Integ_def,intrel_def,quotient_def] |
31 |
"intrel^^{(x,y)}:Integ"; |
|
5508 | 32 |
by (Fast_tac 1); |
33 |
qed "intrel_in_integ"; |
|
34 |
||
35 |
Goal "inj_on Abs_Integ Integ"; |
|
36 |
by (rtac inj_on_inverseI 1); |
|
37 |
by (etac Abs_Integ_inverse 1); |
|
38 |
qed "inj_on_Abs_Integ"; |
|
39 |
||
40 |
Addsimps [equiv_intrel_iff, inj_on_Abs_Integ RS inj_on_iff, |
|
41 |
intrel_iff, intrel_in_integ, Abs_Integ_inverse]; |
|
42 |
||
43 |
Goal "inj(Rep_Integ)"; |
|
44 |
by (rtac inj_inverseI 1); |
|
45 |
by (rtac Rep_Integ_inverse 1); |
|
46 |
qed "inj_Rep_Integ"; |
|
47 |
||
48 |
||
5562
02261e6880d1
Renaming of Integ/Integ.* to Integ/Int.*, and renaming of related constants
paulson
parents:
5540
diff
changeset
|
49 |
(** int: the injection from "nat" to "int" **) |
5508 | 50 |
|
5562
02261e6880d1
Renaming of Integ/Integ.* to Integ/Int.*, and renaming of related constants
paulson
parents:
5540
diff
changeset
|
51 |
Goal "inj int"; |
5508 | 52 |
by (rtac injI 1); |
5562
02261e6880d1
Renaming of Integ/Integ.* to Integ/Int.*, and renaming of related constants
paulson
parents:
5540
diff
changeset
|
53 |
by (rewtac int_def); |
5508 | 54 |
by (dtac (inj_on_Abs_Integ RS inj_onD) 1); |
55 |
by (REPEAT (rtac intrel_in_integ 1)); |
|
56 |
by (dtac eq_equiv_class 1); |
|
57 |
by (rtac equiv_intrel 1); |
|
58 |
by (Fast_tac 1); |
|
9392 | 59 |
by (asm_full_simp_tac (simpset() addsimps [intrel_def]) 1); |
6991 | 60 |
qed "inj_int"; |
5508 | 61 |
|
62 |
||
63 |
(**** zminus: unary negation on Integ ****) |
|
64 |
||
9392 | 65 |
Goalw [congruent_def, intrel_def] |
66 |
"congruent intrel (%(x,y). intrel^^{(y,x)})"; |
|
67 |
by (auto_tac (claset(), simpset() addsimps add_ac)); |
|
5508 | 68 |
qed "zminus_congruent"; |
69 |
||
70 |
Goalw [zminus_def] |
|
71 |
"- Abs_Integ(intrel^^{(x,y)}) = Abs_Integ(intrel ^^ {(y,x)})"; |
|
72 |
by (simp_tac (simpset() addsimps |
|
7375
2cb340e66d15
tidied, allowing pattern-matching in defs of zadd and zmult
paulson
parents:
7127
diff
changeset
|
73 |
[equiv_intrel RS UN_equiv_class, zminus_congruent]) 1); |
5508 | 74 |
qed "zminus"; |
75 |
||
7375
2cb340e66d15
tidied, allowing pattern-matching in defs of zadd and zmult
paulson
parents:
7127
diff
changeset
|
76 |
(*Every integer can be written in the form Abs_Integ(...) *) |
5508 | 77 |
val [prem] = Goal "(!!x y. z = Abs_Integ(intrel^^{(x,y)}) ==> P) ==> P"; |
78 |
by (res_inst_tac [("x1","z")] |
|
79 |
(rewrite_rule [Integ_def] Rep_Integ RS quotientE) 1); |
|
80 |
by (dres_inst_tac [("f","Abs_Integ")] arg_cong 1); |
|
81 |
by (res_inst_tac [("p","x")] PairE 1); |
|
82 |
by (rtac prem 1); |
|
83 |
by (asm_full_simp_tac (simpset() addsimps [Rep_Integ_inverse]) 1); |
|
84 |
qed "eq_Abs_Integ"; |
|
85 |
||
86 |
Goal "- (- z) = (z::int)"; |
|
87 |
by (res_inst_tac [("z","z")] eq_Abs_Integ 1); |
|
88 |
by (asm_simp_tac (simpset() addsimps [zminus]) 1); |
|
89 |
qed "zminus_zminus"; |
|
90 |
Addsimps [zminus_zminus]; |
|
91 |
||
5594 | 92 |
Goal "inj(%z::int. -z)"; |
5508 | 93 |
by (rtac injI 1); |
94 |
by (dres_inst_tac [("f","uminus")] arg_cong 1); |
|
95 |
by (Asm_full_simp_tac 1); |
|
96 |
qed "inj_zminus"; |
|
97 |
||
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
98 |
Goalw [int_def] "- (int 0) = int 0"; |
5508 | 99 |
by (simp_tac (simpset() addsimps [zminus]) 1); |
6917 | 100 |
qed "zminus_int0"; |
5508 | 101 |
|
6917 | 102 |
Addsimps [zminus_int0]; |
5508 | 103 |
|
104 |
||
5540 | 105 |
(**** neg: the test for negative integers ****) |
5508 | 106 |
|
107 |
||
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
108 |
Goalw [neg_def, int_def] "~ neg(int n)"; |
5508 | 109 |
by (Simp_tac 1); |
7010
63120b6dca50
more renaming of theorems from _nat to _int (corresponding to a function that
paulson
parents:
6991
diff
changeset
|
110 |
qed "not_neg_int"; |
5508 | 111 |
|
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
112 |
Goalw [neg_def, int_def] "neg(- (int (Suc n)))"; |
5508 | 113 |
by (simp_tac (simpset() addsimps [zminus]) 1); |
7010
63120b6dca50
more renaming of theorems from _nat to _int (corresponding to a function that
paulson
parents:
6991
diff
changeset
|
114 |
qed "neg_zminus_int"; |
5508 | 115 |
|
7010
63120b6dca50
more renaming of theorems from _nat to _int (corresponding to a function that
paulson
parents:
6991
diff
changeset
|
116 |
Addsimps [neg_zminus_int, not_neg_int]; |
5508 | 117 |
|
118 |
||
119 |
(**** zadd: addition on Integ ****) |
|
120 |
||
121 |
Goalw [zadd_def] |
|
122 |
"Abs_Integ(intrel^^{(x1,y1)}) + Abs_Integ(intrel^^{(x2,y2)}) = \ |
|
123 |
\ Abs_Integ(intrel^^{(x1+x2, y1+y2)})"; |
|
7375
2cb340e66d15
tidied, allowing pattern-matching in defs of zadd and zmult
paulson
parents:
7127
diff
changeset
|
124 |
by (asm_simp_tac (simpset() addsimps [UN_UN_split_split_eq]) 1); |
2cb340e66d15
tidied, allowing pattern-matching in defs of zadd and zmult
paulson
parents:
7127
diff
changeset
|
125 |
by (stac (equiv_intrel RS UN_equiv_class2) 1); |
2cb340e66d15
tidied, allowing pattern-matching in defs of zadd and zmult
paulson
parents:
7127
diff
changeset
|
126 |
by (auto_tac (claset(), simpset() addsimps [congruent2_def])); |
5508 | 127 |
qed "zadd"; |
128 |
||
7127
48e235179ffb
added parentheses to cope with a possible reduction of the precedence of unary
paulson
parents:
7010
diff
changeset
|
129 |
Goal "- (z + w) = (- z) + (- w::int)"; |
5508 | 130 |
by (res_inst_tac [("z","z")] eq_Abs_Integ 1); |
131 |
by (res_inst_tac [("z","w")] eq_Abs_Integ 1); |
|
132 |
by (asm_simp_tac (simpset() addsimps [zminus,zadd]) 1); |
|
133 |
qed "zminus_zadd_distrib"; |
|
134 |
Addsimps [zminus_zadd_distrib]; |
|
135 |
||
136 |
Goal "(z::int) + w = w + z"; |
|
137 |
by (res_inst_tac [("z","z")] eq_Abs_Integ 1); |
|
138 |
by (res_inst_tac [("z","w")] eq_Abs_Integ 1); |
|
5540 | 139 |
by (asm_simp_tac (simpset() addsimps add_ac @ [zadd]) 1); |
5508 | 140 |
qed "zadd_commute"; |
141 |
||
142 |
Goal "((z1::int) + z2) + z3 = z1 + (z2 + z3)"; |
|
143 |
by (res_inst_tac [("z","z1")] eq_Abs_Integ 1); |
|
144 |
by (res_inst_tac [("z","z2")] eq_Abs_Integ 1); |
|
145 |
by (res_inst_tac [("z","z3")] eq_Abs_Integ 1); |
|
146 |
by (asm_simp_tac (simpset() addsimps [zadd, add_assoc]) 1); |
|
147 |
qed "zadd_assoc"; |
|
148 |
||
149 |
(*For AC rewriting*) |
|
150 |
Goal "(x::int)+(y+z)=y+(x+z)"; |
|
151 |
by (rtac (zadd_commute RS trans) 1); |
|
152 |
by (rtac (zadd_assoc RS trans) 1); |
|
153 |
by (rtac (zadd_commute RS arg_cong) 1); |
|
154 |
qed "zadd_left_commute"; |
|
155 |
||
156 |
(*Integer addition is an AC operator*) |
|
7428 | 157 |
bind_thms ("zadd_ac", [zadd_assoc,zadd_commute,zadd_left_commute]); |
5508 | 158 |
|
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
159 |
Goalw [int_def] "(int m) + (int n) = int (m + n)"; |
5508 | 160 |
by (simp_tac (simpset() addsimps [zadd]) 1); |
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
161 |
qed "zadd_int"; |
5508 | 162 |
|
5594 | 163 |
Goal "(int m) + (int n + z) = int (m + n) + z"; |
164 |
by (simp_tac (simpset() addsimps [zadd_int, zadd_assoc RS sym]) 1); |
|
165 |
qed "zadd_int_left"; |
|
166 |
||
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
167 |
Goal "int (Suc m) = int 1 + (int m)"; |
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
168 |
by (simp_tac (simpset() addsimps [zadd_int]) 1); |
6717
70b251dc7055
int_Suc->int_Suc_int_1 avoiding confusion with the more useful Bin.int_Suc
paulson
parents:
6674
diff
changeset
|
169 |
qed "int_Suc_int_1"; |
5508 | 170 |
|
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
171 |
Goalw [int_def] "int 0 + z = z"; |
5508 | 172 |
by (res_inst_tac [("z","z")] eq_Abs_Integ 1); |
173 |
by (asm_simp_tac (simpset() addsimps [zadd]) 1); |
|
6917 | 174 |
qed "zadd_int0"; |
5508 | 175 |
|
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
176 |
Goal "z + int 0 = z"; |
5508 | 177 |
by (rtac (zadd_commute RS trans) 1); |
6917 | 178 |
by (rtac zadd_int0 1); |
179 |
qed "zadd_int0_right"; |
|
5508 | 180 |
|
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
181 |
Goalw [int_def] "z + (- z) = int 0"; |
5508 | 182 |
by (res_inst_tac [("z","z")] eq_Abs_Integ 1); |
183 |
by (asm_simp_tac (simpset() addsimps [zminus, zadd, add_commute]) 1); |
|
5594 | 184 |
qed "zadd_zminus_inverse"; |
5508 | 185 |
|
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
186 |
Goal "(- z) + z = int 0"; |
5508 | 187 |
by (rtac (zadd_commute RS trans) 1); |
5594 | 188 |
by (rtac zadd_zminus_inverse 1); |
189 |
qed "zadd_zminus_inverse2"; |
|
5508 | 190 |
|
6917 | 191 |
Addsimps [zadd_int0, zadd_int0_right, |
5594 | 192 |
zadd_zminus_inverse, zadd_zminus_inverse2]; |
5508 | 193 |
|
8949 | 194 |
(*for the instance declaration int :: plus_ac0*) |
195 |
Goal "0 + z = (z::int)"; |
|
196 |
by (Simp_tac 1); |
|
197 |
qed "zadd_zero"; |
|
198 |
||
5508 | 199 |
Goal "z + (- z + w) = (w::int)"; |
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
200 |
by (simp_tac (simpset() addsimps [zadd_assoc RS sym]) 1); |
5508 | 201 |
qed "zadd_zminus_cancel"; |
202 |
||
203 |
Goal "(-z) + (z + w) = (w::int)"; |
|
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
204 |
by (simp_tac (simpset() addsimps [zadd_assoc RS sym]) 1); |
5508 | 205 |
qed "zminus_zadd_cancel"; |
206 |
||
207 |
Addsimps [zadd_zminus_cancel, zminus_zadd_cancel]; |
|
208 |
||
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
209 |
Goal "int 0 - x = -x"; |
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
210 |
by (simp_tac (simpset() addsimps [zdiff_def]) 1); |
6917 | 211 |
qed "zdiff_int0"; |
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
212 |
|
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
213 |
Goal "x - int 0 = x"; |
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
214 |
by (simp_tac (simpset() addsimps [zdiff_def]) 1); |
6917 | 215 |
qed "zdiff_int0_right"; |
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
216 |
|
5594 | 217 |
Goal "x - x = int 0"; |
218 |
by (simp_tac (simpset() addsimps [zdiff_def]) 1); |
|
219 |
qed "zdiff_self"; |
|
220 |
||
6917 | 221 |
Addsimps [zdiff_int0, zdiff_int0_right, zdiff_self]; |
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
222 |
|
5508 | 223 |
|
224 |
(** Lemmas **) |
|
225 |
||
226 |
Goal "(z::int) + v = z' + v' ==> z + (v + w) = z' + (v' + w)"; |
|
227 |
by (asm_simp_tac (simpset() addsimps [zadd_assoc RS sym]) 1); |
|
228 |
qed "zadd_assoc_cong"; |
|
229 |
||
230 |
Goal "(z::int) + (v + w) = v + (z + w)"; |
|
231 |
by (REPEAT (ares_tac [zadd_commute RS zadd_assoc_cong] 1)); |
|
232 |
qed "zadd_assoc_swap"; |
|
233 |
||
234 |
||
235 |
(*Need properties of subtraction? Or use $- just as an abbreviation!*) |
|
236 |
||
237 |
(**** zmult: multiplication on Integ ****) |
|
238 |
||
7375
2cb340e66d15
tidied, allowing pattern-matching in defs of zadd and zmult
paulson
parents:
7127
diff
changeset
|
239 |
(*Congruence property for multiplication*) |
2cb340e66d15
tidied, allowing pattern-matching in defs of zadd and zmult
paulson
parents:
7127
diff
changeset
|
240 |
Goal "congruent2 intrel \ |
2cb340e66d15
tidied, allowing pattern-matching in defs of zadd and zmult
paulson
parents:
7127
diff
changeset
|
241 |
\ (%p1 p2. (%(x1,y1). (%(x2,y2). \ |
5508 | 242 |
\ intrel^^{(x1*x2 + y1*y2, x1*y2 + y1*x2)}) p2) p1)"; |
243 |
by (rtac (equiv_intrel RS congruent2_commuteI) 1); |
|
244 |
by (pair_tac "w" 2); |
|
7375
2cb340e66d15
tidied, allowing pattern-matching in defs of zadd and zmult
paulson
parents:
7127
diff
changeset
|
245 |
by (ALLGOALS Clarify_tac); |
5508 | 246 |
by (simp_tac (simpset() addsimps add_ac@mult_ac) 1); |
247 |
by (asm_simp_tac (simpset() delsimps [equiv_intrel_iff] |
|
7375
2cb340e66d15
tidied, allowing pattern-matching in defs of zadd and zmult
paulson
parents:
7127
diff
changeset
|
248 |
addsimps add_ac@mult_ac) 1); |
9392 | 249 |
by (rename_tac "x1 x2 y1 y2 z1 z2" 1); |
250 |
by (rtac ([equiv_intrel, intrel_iff RS iffD2] MRS equiv_class_eq) 1); |
|
251 |
by (asm_full_simp_tac (simpset() addsimps [intrel_def]) 1); |
|
252 |
by (subgoal_tac |
|
253 |
"x1*z1 + y2*z1 = y1*z1 + x2*z1 & x1*z2 + y2*z2 = y1*z2 + x2*z2" 1); |
|
254 |
by (asm_simp_tac (simpset() addsimps [add_mult_distrib RS sym]) 2); |
|
255 |
by (arith_tac 1); |
|
5508 | 256 |
qed "zmult_congruent2"; |
257 |
||
258 |
Goalw [zmult_def] |
|
259 |
"Abs_Integ((intrel^^{(x1,y1)})) * Abs_Integ((intrel^^{(x2,y2)})) = \ |
|
260 |
\ Abs_Integ(intrel ^^ {(x1*x2 + y1*y2, x1*y2 + y1*x2)})"; |
|
7375
2cb340e66d15
tidied, allowing pattern-matching in defs of zadd and zmult
paulson
parents:
7127
diff
changeset
|
261 |
by (asm_simp_tac |
2cb340e66d15
tidied, allowing pattern-matching in defs of zadd and zmult
paulson
parents:
7127
diff
changeset
|
262 |
(simpset() addsimps [UN_UN_split_split_eq, zmult_congruent2, |
2cb340e66d15
tidied, allowing pattern-matching in defs of zadd and zmult
paulson
parents:
7127
diff
changeset
|
263 |
equiv_intrel RS UN_equiv_class2]) 1); |
5508 | 264 |
qed "zmult"; |
265 |
||
266 |
Goal "(- z) * w = - (z * (w::int))"; |
|
267 |
by (res_inst_tac [("z","z")] eq_Abs_Integ 1); |
|
268 |
by (res_inst_tac [("z","w")] eq_Abs_Integ 1); |
|
5540 | 269 |
by (asm_simp_tac (simpset() addsimps [zminus, zmult] @ add_ac) 1); |
5508 | 270 |
qed "zmult_zminus"; |
271 |
||
272 |
Goal "(z::int) * w = w * z"; |
|
273 |
by (res_inst_tac [("z","z")] eq_Abs_Integ 1); |
|
274 |
by (res_inst_tac [("z","w")] eq_Abs_Integ 1); |
|
5540 | 275 |
by (asm_simp_tac (simpset() addsimps [zmult] @ add_ac @ mult_ac) 1); |
5508 | 276 |
qed "zmult_commute"; |
277 |
||
278 |
Goal "((z1::int) * z2) * z3 = z1 * (z2 * z3)"; |
|
279 |
by (res_inst_tac [("z","z1")] eq_Abs_Integ 1); |
|
280 |
by (res_inst_tac [("z","z2")] eq_Abs_Integ 1); |
|
281 |
by (res_inst_tac [("z","z3")] eq_Abs_Integ 1); |
|
5540 | 282 |
by (asm_simp_tac (simpset() addsimps [add_mult_distrib2,zmult] @ |
283 |
add_ac @ mult_ac) 1); |
|
5508 | 284 |
qed "zmult_assoc"; |
285 |
||
286 |
(*For AC rewriting*) |
|
287 |
Goal "(z1::int)*(z2*z3) = z2*(z1*z3)"; |
|
288 |
by (rtac (zmult_commute RS trans) 1); |
|
289 |
by (rtac (zmult_assoc RS trans) 1); |
|
290 |
by (rtac (zmult_commute RS arg_cong) 1); |
|
291 |
qed "zmult_left_commute"; |
|
292 |
||
293 |
(*Integer multiplication is an AC operator*) |
|
7428 | 294 |
bind_thms ("zmult_ac", [zmult_assoc, zmult_commute, zmult_left_commute]); |
5508 | 295 |
|
296 |
Goal "((z1::int) + z2) * w = (z1 * w) + (z2 * w)"; |
|
297 |
by (res_inst_tac [("z","z1")] eq_Abs_Integ 1); |
|
298 |
by (res_inst_tac [("z","z2")] eq_Abs_Integ 1); |
|
299 |
by (res_inst_tac [("z","w")] eq_Abs_Integ 1); |
|
300 |
by (asm_simp_tac |
|
5540 | 301 |
(simpset() addsimps [add_mult_distrib2, zadd, zmult] @ |
302 |
add_ac @ mult_ac) 1); |
|
5508 | 303 |
qed "zadd_zmult_distrib"; |
304 |
||
305 |
val zmult_commute'= read_instantiate [("z","w")] zmult_commute; |
|
306 |
||
307 |
Goal "w * (- z) = - (w * (z::int))"; |
|
308 |
by (simp_tac (simpset() addsimps [zmult_commute', zmult_zminus]) 1); |
|
309 |
qed "zmult_zminus_right"; |
|
310 |
||
311 |
Goal "(w::int) * (z1 + z2) = (w * z1) + (w * z2)"; |
|
312 |
by (simp_tac (simpset() addsimps [zmult_commute',zadd_zmult_distrib]) 1); |
|
313 |
qed "zadd_zmult_distrib2"; |
|
314 |
||
6839 | 315 |
Goalw [zdiff_def] "((z1::int) - z2) * w = (z1 * w) - (z2 * w)"; |
316 |
by (stac zadd_zmult_distrib 1); |
|
317 |
by (simp_tac (simpset() addsimps [zmult_zminus]) 1); |
|
318 |
qed "zdiff_zmult_distrib"; |
|
319 |
||
320 |
Goal "(w::int) * (z1 - z2) = (w * z1) - (w * z2)"; |
|
321 |
by (simp_tac (simpset() addsimps [zmult_commute',zdiff_zmult_distrib]) 1); |
|
322 |
qed "zdiff_zmult_distrib2"; |
|
323 |
||
7010
63120b6dca50
more renaming of theorems from _nat to _int (corresponding to a function that
paulson
parents:
6991
diff
changeset
|
324 |
Goalw [int_def] "(int m) * (int n) = int (m * n)"; |
63120b6dca50
more renaming of theorems from _nat to _int (corresponding to a function that
paulson
parents:
6991
diff
changeset
|
325 |
by (simp_tac (simpset() addsimps [zmult]) 1); |
63120b6dca50
more renaming of theorems from _nat to _int (corresponding to a function that
paulson
parents:
6991
diff
changeset
|
326 |
qed "zmult_int"; |
63120b6dca50
more renaming of theorems from _nat to _int (corresponding to a function that
paulson
parents:
6991
diff
changeset
|
327 |
|
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
328 |
Goalw [int_def] "int 0 * z = int 0"; |
5508 | 329 |
by (res_inst_tac [("z","z")] eq_Abs_Integ 1); |
330 |
by (asm_simp_tac (simpset() addsimps [zmult]) 1); |
|
6917 | 331 |
qed "zmult_int0"; |
5508 | 332 |
|
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
333 |
Goalw [int_def] "int 1 * z = z"; |
5508 | 334 |
by (res_inst_tac [("z","z")] eq_Abs_Integ 1); |
335 |
by (asm_simp_tac (simpset() addsimps [zmult]) 1); |
|
6917 | 336 |
qed "zmult_int1"; |
5508 | 337 |
|
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
338 |
Goal "z * int 0 = int 0"; |
6917 | 339 |
by (rtac ([zmult_commute, zmult_int0] MRS trans) 1); |
340 |
qed "zmult_int0_right"; |
|
5508 | 341 |
|
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
342 |
Goal "z * int 1 = z"; |
6917 | 343 |
by (rtac ([zmult_commute, zmult_int1] MRS trans) 1); |
344 |
qed "zmult_int1_right"; |
|
5508 | 345 |
|
6917 | 346 |
Addsimps [zmult_int0, zmult_int0_right, zmult_int1, zmult_int1_right]; |
5508 | 347 |
|
348 |
||
349 |
(* Theorems about less and less_equal *) |
|
350 |
||
351 |
(*This lemma allows direct proofs of other <-properties*) |
|
5562
02261e6880d1
Renaming of Integ/Integ.* to Integ/Int.*, and renaming of related constants
paulson
parents:
5540
diff
changeset
|
352 |
Goalw [zless_def, neg_def, zdiff_def, int_def] |
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
353 |
"(w < z) = (EX n. z = w + int(Suc n))"; |
5508 | 354 |
by (res_inst_tac [("z","z")] eq_Abs_Integ 1); |
355 |
by (res_inst_tac [("z","w")] eq_Abs_Integ 1); |
|
356 |
by (Clarify_tac 1); |
|
357 |
by (asm_full_simp_tac (simpset() addsimps [zadd, zminus]) 1); |
|
358 |
by (safe_tac (claset() addSDs [less_eq_Suc_add])); |
|
359 |
by (res_inst_tac [("x","k")] exI 1); |
|
360 |
by (ALLGOALS (asm_full_simp_tac (simpset() addsimps add_ac))); |
|
361 |
qed "zless_iff_Suc_zadd"; |
|
362 |
||
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
363 |
Goal "z < z + int (Suc n)"; |
5508 | 364 |
by (auto_tac (claset(), |
365 |
simpset() addsimps [zless_iff_Suc_zadd, zadd_assoc, |
|
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
366 |
zadd_int])); |
5508 | 367 |
qed "zless_zadd_Suc"; |
368 |
||
369 |
Goal "[| z1<z2; z2<z3 |] ==> z1 < (z3::int)"; |
|
370 |
by (auto_tac (claset(), |
|
371 |
simpset() addsimps [zless_iff_Suc_zadd, zadd_assoc, |
|
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
372 |
zadd_int])); |
5508 | 373 |
qed "zless_trans"; |
374 |
||
375 |
Goal "!!w::int. z<w ==> ~w<z"; |
|
376 |
by (safe_tac (claset() addSDs [zless_iff_Suc_zadd RS iffD1])); |
|
377 |
by (res_inst_tac [("z","z")] eq_Abs_Integ 1); |
|
378 |
by Safe_tac; |
|
5562
02261e6880d1
Renaming of Integ/Integ.* to Integ/Int.*, and renaming of related constants
paulson
parents:
5540
diff
changeset
|
379 |
by (asm_full_simp_tac (simpset() addsimps [int_def, zadd]) 1); |
5508 | 380 |
qed "zless_not_sym"; |
381 |
||
382 |
(* [| n<m; ~P ==> m<n |] ==> P *) |
|
5540 | 383 |
bind_thm ("zless_asym", zless_not_sym RS swap); |
5508 | 384 |
|
385 |
Goal "!!z::int. ~ z<z"; |
|
386 |
by (resolve_tac [zless_asym RS notI] 1); |
|
387 |
by (REPEAT (assume_tac 1)); |
|
388 |
qed "zless_not_refl"; |
|
389 |
||
390 |
(* z<z ==> R *) |
|
5594 | 391 |
bind_thm ("zless_irrefl", zless_not_refl RS notE); |
5508 | 392 |
AddSEs [zless_irrefl]; |
393 |
||
394 |
Goal "z<w ==> w ~= (z::int)"; |
|
395 |
by (Blast_tac 1); |
|
396 |
qed "zless_not_refl2"; |
|
397 |
||
398 |
(* s < t ==> s ~= t *) |
|
399 |
bind_thm ("zless_not_refl3", zless_not_refl2 RS not_sym); |
|
400 |
||
401 |
||
402 |
(*"Less than" is a linear ordering*) |
|
5540 | 403 |
Goalw [zless_def, neg_def, zdiff_def] |
5508 | 404 |
"z<w | z=w | w<(z::int)"; |
405 |
by (res_inst_tac [("z","z")] eq_Abs_Integ 1); |
|
406 |
by (res_inst_tac [("z","w")] eq_Abs_Integ 1); |
|
407 |
by Safe_tac; |
|
408 |
by (asm_full_simp_tac |
|
409 |
(simpset() addsimps [zadd, zminus, Image_iff, Bex_def]) 1); |
|
410 |
by (res_inst_tac [("m1", "x+ya"), ("n1", "xa+y")] (less_linear RS disjE) 1); |
|
5758
27a2b36efd95
corrected auto_tac (applications of unsafe wrappers)
oheimb
parents:
5594
diff
changeset
|
411 |
by (ALLGOALS (force_tac (claset(), simpset() addsimps add_ac))); |
5508 | 412 |
qed "zless_linear"; |
413 |
||
414 |
Goal "!!w::int. (w ~= z) = (w<z | z<w)"; |
|
415 |
by (cut_facts_tac [zless_linear] 1); |
|
416 |
by (Blast_tac 1); |
|
417 |
qed "int_neq_iff"; |
|
418 |
||
419 |
(*** eliminates ~= in premises ***) |
|
420 |
bind_thm("int_neqE", int_neq_iff RS iffD1 RS disjE); |
|
421 |
||
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
422 |
Goal "(int m = int n) = (m = n)"; |
6991 | 423 |
by (fast_tac (claset() addSEs [inj_int RS injD]) 1); |
5562
02261e6880d1
Renaming of Integ/Integ.* to Integ/Int.*, and renaming of related constants
paulson
parents:
5540
diff
changeset
|
424 |
qed "int_int_eq"; |
02261e6880d1
Renaming of Integ/Integ.* to Integ/Int.*, and renaming of related constants
paulson
parents:
5540
diff
changeset
|
425 |
AddIffs [int_int_eq]; |
5508 | 426 |
|
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
427 |
Goal "(int m < int n) = (m<n)"; |
5508 | 428 |
by (simp_tac (simpset() addsimps [less_iff_Suc_add, zless_iff_Suc_zadd, |
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
429 |
zadd_int]) 1); |
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
430 |
qed "zless_int"; |
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
431 |
Addsimps [zless_int]; |
5508 | 432 |
|
433 |
||
434 |
(*** Properties of <= ***) |
|
435 |
||
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
436 |
Goalw [zle_def, le_def] "(int m <= int n) = (m<=n)"; |
5508 | 437 |
by (Simp_tac 1); |
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
438 |
qed "zle_int"; |
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
439 |
Addsimps [zle_int]; |
5508 | 440 |
|
441 |
Goalw [zle_def] "z <= w ==> z < w | z=(w::int)"; |
|
442 |
by (cut_facts_tac [zless_linear] 1); |
|
443 |
by (blast_tac (claset() addEs [zless_asym]) 1); |
|
444 |
qed "zle_imp_zless_or_eq"; |
|
445 |
||
446 |
Goalw [zle_def] "z<w | z=w ==> z <= (w::int)"; |
|
447 |
by (cut_facts_tac [zless_linear] 1); |
|
448 |
by (blast_tac (claset() addEs [zless_asym]) 1); |
|
449 |
qed "zless_or_eq_imp_zle"; |
|
450 |
||
451 |
Goal "(x <= (y::int)) = (x < y | x=y)"; |
|
452 |
by (REPEAT(ares_tac [iffI, zless_or_eq_imp_zle, zle_imp_zless_or_eq] 1)); |
|
5540 | 453 |
qed "integ_le_less"; |
5508 | 454 |
|
455 |
Goal "w <= (w::int)"; |
|
5540 | 456 |
by (simp_tac (simpset() addsimps [integ_le_less]) 1); |
5508 | 457 |
qed "zle_refl"; |
458 |
||
459 |
Goalw [zle_def] "z < w ==> z <= (w::int)"; |
|
460 |
by (blast_tac (claset() addEs [zless_asym]) 1); |
|
461 |
qed "zless_imp_zle"; |
|
462 |
||
463 |
(* Axiom 'linorder_linear' of class 'linorder': *) |
|
464 |
Goal "(z::int) <= w | w <= z"; |
|
5540 | 465 |
by (simp_tac (simpset() addsimps [integ_le_less]) 1); |
5508 | 466 |
by (cut_facts_tac [zless_linear] 1); |
467 |
by (Blast_tac 1); |
|
468 |
qed "zle_linear"; |
|
469 |
||
470 |
Goal "[| i <= j; j < k |] ==> i < (k::int)"; |
|
471 |
by (dtac zle_imp_zless_or_eq 1); |
|
472 |
by (blast_tac (claset() addIs [zless_trans]) 1); |
|
473 |
qed "zle_zless_trans"; |
|
474 |
||
475 |
Goal "[| i < j; j <= k |] ==> i < (k::int)"; |
|
476 |
by (dtac zle_imp_zless_or_eq 1); |
|
477 |
by (blast_tac (claset() addIs [zless_trans]) 1); |
|
478 |
qed "zless_zle_trans"; |
|
479 |
||
480 |
Goal "[| i <= j; j <= k |] ==> i <= (k::int)"; |
|
481 |
by (EVERY1 [dtac zle_imp_zless_or_eq, dtac zle_imp_zless_or_eq, |
|
482 |
rtac zless_or_eq_imp_zle, |
|
483 |
blast_tac (claset() addIs [zless_trans])]); |
|
484 |
qed "zle_trans"; |
|
485 |
||
486 |
Goal "[| z <= w; w <= z |] ==> z = (w::int)"; |
|
487 |
by (EVERY1 [dtac zle_imp_zless_or_eq, dtac zle_imp_zless_or_eq, |
|
488 |
blast_tac (claset() addEs [zless_asym])]); |
|
489 |
qed "zle_anti_sym"; |
|
490 |
||
491 |
(* Axiom 'order_less_le' of class 'order': *) |
|
492 |
Goal "(w::int) < z = (w <= z & w ~= z)"; |
|
493 |
by (simp_tac (simpset() addsimps [zle_def, int_neq_iff]) 1); |
|
494 |
by (blast_tac (claset() addSEs [zless_asym]) 1); |
|
495 |
qed "int_less_le"; |
|
496 |
||
497 |
(* [| w <= z; w ~= z |] ==> w < z *) |
|
498 |
bind_thm ("zle_neq_implies_zless", [int_less_le, conjI] MRS iffD2); |
|
499 |
||
500 |
||
501 |
||
502 |
(*** Subtraction laws ***) |
|
503 |
||
504 |
Goal "x + (y - z) = (x + y) - (z::int)"; |
|
5540 | 505 |
by (simp_tac (simpset() addsimps zdiff_def::zadd_ac) 1); |
5508 | 506 |
qed "zadd_zdiff_eq"; |
507 |
||
508 |
Goal "(x - y) + z = (x + z) - (y::int)"; |
|
5540 | 509 |
by (simp_tac (simpset() addsimps zdiff_def::zadd_ac) 1); |
5508 | 510 |
qed "zdiff_zadd_eq"; |
511 |
||
512 |
Goal "(x - y) - z = x - (y + (z::int))"; |
|
5540 | 513 |
by (simp_tac (simpset() addsimps zdiff_def::zadd_ac) 1); |
5508 | 514 |
qed "zdiff_zdiff_eq"; |
515 |
||
516 |
Goal "x - (y - z) = (x + z) - (y::int)"; |
|
5540 | 517 |
by (simp_tac (simpset() addsimps zdiff_def::zadd_ac) 1); |
5508 | 518 |
qed "zdiff_zdiff_eq2"; |
519 |
||
520 |
Goalw [zless_def, zdiff_def] "(x-y < z) = (x < z + (y::int))"; |
|
521 |
by (simp_tac (simpset() addsimps zadd_ac) 1); |
|
522 |
qed "zdiff_zless_eq"; |
|
523 |
||
524 |
Goalw [zless_def, zdiff_def] "(x < z-y) = (x + (y::int) < z)"; |
|
525 |
by (simp_tac (simpset() addsimps zadd_ac) 1); |
|
526 |
qed "zless_zdiff_eq"; |
|
527 |
||
528 |
Goalw [zle_def] "(x-y <= z) = (x <= z + (y::int))"; |
|
529 |
by (simp_tac (simpset() addsimps [zless_zdiff_eq]) 1); |
|
530 |
qed "zdiff_zle_eq"; |
|
531 |
||
532 |
Goalw [zle_def] "(x <= z-y) = (x + (y::int) <= z)"; |
|
533 |
by (simp_tac (simpset() addsimps [zdiff_zless_eq]) 1); |
|
534 |
qed "zle_zdiff_eq"; |
|
535 |
||
536 |
Goalw [zdiff_def] "(x-y = z) = (x = z + (y::int))"; |
|
537 |
by (auto_tac (claset(), simpset() addsimps [zadd_assoc])); |
|
538 |
qed "zdiff_eq_eq"; |
|
539 |
||
540 |
Goalw [zdiff_def] "(x = z-y) = (x + (y::int) = z)"; |
|
541 |
by (auto_tac (claset(), simpset() addsimps [zadd_assoc])); |
|
542 |
qed "eq_zdiff_eq"; |
|
543 |
||
544 |
(*This list of rewrites simplifies (in)equalities by bringing subtractions |
|
545 |
to the top and then moving negative terms to the other side. |
|
546 |
Use with zadd_ac*) |
|
9108 | 547 |
bind_thms ("zcompare_rls", |
5508 | 548 |
[symmetric zdiff_def, |
549 |
zadd_zdiff_eq, zdiff_zadd_eq, zdiff_zdiff_eq, zdiff_zdiff_eq2, |
|
550 |
zdiff_zless_eq, zless_zdiff_eq, zdiff_zle_eq, zle_zdiff_eq, |
|
9108 | 551 |
zdiff_eq_eq, eq_zdiff_eq]); |
5508 | 552 |
|
553 |
||
554 |
(** Cancellation laws **) |
|
555 |
||
556 |
Goal "!!w::int. (z + w' = z + w) = (w' = w)"; |
|
557 |
by Safe_tac; |
|
7127
48e235179ffb
added parentheses to cope with a possible reduction of the precedence of unary
paulson
parents:
7010
diff
changeset
|
558 |
by (dres_inst_tac [("f", "%x. x + (-z)")] arg_cong 1); |
5508 | 559 |
by (asm_full_simp_tac (simpset() addsimps zadd_ac) 1); |
560 |
qed "zadd_left_cancel"; |
|
561 |
||
562 |
Addsimps [zadd_left_cancel]; |
|
563 |
||
564 |
Goal "!!z::int. (w' + z = w + z) = (w' = w)"; |
|
565 |
by (asm_full_simp_tac (simpset() addsimps zadd_ac) 1); |
|
566 |
qed "zadd_right_cancel"; |
|
567 |
||
568 |
Addsimps [zadd_right_cancel]; |
|
569 |
||
570 |
||
5594 | 571 |
(** For the cancellation simproc. |
572 |
The idea is to cancel like terms on opposite sides by subtraction **) |
|
573 |
||
574 |
Goal "(x::int) - y = x' - y' ==> (x<y) = (x'<y')"; |
|
575 |
by (asm_simp_tac (simpset() addsimps [zless_def]) 1); |
|
576 |
qed "zless_eqI"; |
|
5508 | 577 |
|
5594 | 578 |
Goal "(x::int) - y = x' - y' ==> (y<=x) = (y'<=x')"; |
579 |
by (dtac zless_eqI 1); |
|
580 |
by (asm_simp_tac (simpset() addsimps [zle_def]) 1); |
|
581 |
qed "zle_eqI"; |
|
5508 | 582 |
|
5594 | 583 |
Goal "(x::int) - y = x' - y' ==> (x=y) = (x'=y')"; |
584 |
by Safe_tac; |
|
585 |
by (ALLGOALS |
|
586 |
(asm_full_simp_tac (simpset() addsimps [eq_zdiff_eq, zdiff_eq_eq]))); |
|
587 |
qed "zeq_eqI"; |
|
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
588 |