author | paulson |
Thu, 01 Oct 1998 18:27:17 +0200 | |
changeset 5594 | e4439230af67 |
parent 5582 | a356fb49e69e |
child 5758 | 27a2b36efd95 |
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 |
||
10 |
(*** Proving that intrel is an equivalence relation ***) |
|
11 |
||
12 |
val eqa::eqb::prems = goal Arith.thy |
|
13 |
"[| (x1::nat) + y2 = x2 + y1; x2 + y3 = x3 + y2 |] ==> \ |
|
14 |
\ x1 + y3 = x3 + y1"; |
|
15 |
by (res_inst_tac [("k1","x2")] (add_left_cancel RS iffD1) 1); |
|
16 |
by (rtac (add_left_commute RS trans) 1); |
|
17 |
by (stac eqb 1); |
|
18 |
by (rtac (add_left_commute RS trans) 1); |
|
19 |
by (stac eqa 1); |
|
20 |
by (rtac (add_left_commute) 1); |
|
21 |
qed "integ_trans_lemma"; |
|
22 |
||
23 |
(** Natural deduction for intrel **) |
|
24 |
||
25 |
Goalw [intrel_def] "[| x1+y2 = x2+y1|] ==> ((x1,y1),(x2,y2)): intrel"; |
|
26 |
by (Fast_tac 1); |
|
27 |
qed "intrelI"; |
|
28 |
||
29 |
(*intrelE is hard to derive because fast_tac tries hyp_subst_tac so soon*) |
|
30 |
Goalw [intrel_def] |
|
31 |
"p: intrel --> (EX x1 y1 x2 y2. \ |
|
32 |
\ p = ((x1,y1),(x2,y2)) & x1+y2 = x2+y1)"; |
|
33 |
by (Fast_tac 1); |
|
34 |
qed "intrelE_lemma"; |
|
35 |
||
36 |
val [major,minor] = Goal |
|
37 |
"[| p: intrel; \ |
|
38 |
\ !!x1 y1 x2 y2. [| p = ((x1,y1),(x2,y2)); x1+y2 = x2+y1|] ==> Q |] \ |
|
39 |
\ ==> Q"; |
|
40 |
by (cut_facts_tac [major RS (intrelE_lemma RS mp)] 1); |
|
41 |
by (REPEAT (eresolve_tac [asm_rl,exE,conjE,minor] 1)); |
|
42 |
qed "intrelE"; |
|
43 |
||
44 |
AddSIs [intrelI]; |
|
45 |
AddSEs [intrelE]; |
|
46 |
||
47 |
Goal "((x1,y1),(x2,y2)): intrel = (x1+y2 = x2+y1)"; |
|
48 |
by (Fast_tac 1); |
|
49 |
qed "intrel_iff"; |
|
50 |
||
51 |
Goal "(x,x): intrel"; |
|
52 |
by (stac surjective_pairing 1 THEN rtac (refl RS intrelI) 1); |
|
53 |
qed "intrel_refl"; |
|
54 |
||
55 |
Goalw [equiv_def, refl_def, sym_def, trans_def] |
|
56 |
"equiv {x::(nat*nat).True} intrel"; |
|
57 |
by (fast_tac (claset() addSIs [intrel_refl] |
|
58 |
addSEs [sym, integ_trans_lemma]) 1); |
|
59 |
qed "equiv_intrel"; |
|
60 |
||
61 |
val equiv_intrel_iff = |
|
62 |
[TrueI, TrueI] MRS |
|
63 |
([CollectI, CollectI] MRS |
|
64 |
(equiv_intrel RS eq_equiv_class_iff)); |
|
65 |
||
66 |
Goalw [Integ_def,intrel_def,quotient_def] "intrel^^{(x,y)}:Integ"; |
|
67 |
by (Fast_tac 1); |
|
68 |
qed "intrel_in_integ"; |
|
69 |
||
70 |
Goal "inj_on Abs_Integ Integ"; |
|
71 |
by (rtac inj_on_inverseI 1); |
|
72 |
by (etac Abs_Integ_inverse 1); |
|
73 |
qed "inj_on_Abs_Integ"; |
|
74 |
||
75 |
Addsimps [equiv_intrel_iff, inj_on_Abs_Integ RS inj_on_iff, |
|
76 |
intrel_iff, intrel_in_integ, Abs_Integ_inverse]; |
|
77 |
||
78 |
Goal "inj(Rep_Integ)"; |
|
79 |
by (rtac inj_inverseI 1); |
|
80 |
by (rtac Rep_Integ_inverse 1); |
|
81 |
qed "inj_Rep_Integ"; |
|
82 |
||
83 |
||
5562
02261e6880d1
Renaming of Integ/Integ.* to Integ/Int.*, and renaming of related constants
paulson
parents:
5540
diff
changeset
|
84 |
(** int: the injection from "nat" to "int" **) |
5508 | 85 |
|
5562
02261e6880d1
Renaming of Integ/Integ.* to Integ/Int.*, and renaming of related constants
paulson
parents:
5540
diff
changeset
|
86 |
Goal "inj int"; |
5508 | 87 |
by (rtac injI 1); |
5562
02261e6880d1
Renaming of Integ/Integ.* to Integ/Int.*, and renaming of related constants
paulson
parents:
5540
diff
changeset
|
88 |
by (rewtac int_def); |
5508 | 89 |
by (dtac (inj_on_Abs_Integ RS inj_onD) 1); |
90 |
by (REPEAT (rtac intrel_in_integ 1)); |
|
91 |
by (dtac eq_equiv_class 1); |
|
92 |
by (rtac equiv_intrel 1); |
|
93 |
by (Fast_tac 1); |
|
94 |
by Safe_tac; |
|
95 |
by (Asm_full_simp_tac 1); |
|
5540 | 96 |
qed "inj_nat"; |
5508 | 97 |
|
98 |
||
99 |
(**** zminus: unary negation on Integ ****) |
|
100 |
||
101 |
Goalw [congruent_def] |
|
102 |
"congruent intrel (%p. split (%x y. intrel^^{(y,x)}) p)"; |
|
103 |
by Safe_tac; |
|
104 |
by (asm_simp_tac (simpset() addsimps add_ac) 1); |
|
105 |
qed "zminus_congruent"; |
|
106 |
||
107 |
||
108 |
(*Resolve th against the corresponding facts for zminus*) |
|
109 |
val zminus_ize = RSLIST [equiv_intrel, zminus_congruent]; |
|
110 |
||
111 |
Goalw [zminus_def] |
|
112 |
"- Abs_Integ(intrel^^{(x,y)}) = Abs_Integ(intrel ^^ {(y,x)})"; |
|
113 |
by (res_inst_tac [("f","Abs_Integ")] arg_cong 1); |
|
114 |
by (simp_tac (simpset() addsimps |
|
115 |
[intrel_in_integ RS Abs_Integ_inverse,zminus_ize UN_equiv_class]) 1); |
|
116 |
qed "zminus"; |
|
117 |
||
118 |
(*by lcp*) |
|
119 |
val [prem] = Goal "(!!x y. z = Abs_Integ(intrel^^{(x,y)}) ==> P) ==> P"; |
|
120 |
by (res_inst_tac [("x1","z")] |
|
121 |
(rewrite_rule [Integ_def] Rep_Integ RS quotientE) 1); |
|
122 |
by (dres_inst_tac [("f","Abs_Integ")] arg_cong 1); |
|
123 |
by (res_inst_tac [("p","x")] PairE 1); |
|
124 |
by (rtac prem 1); |
|
125 |
by (asm_full_simp_tac (simpset() addsimps [Rep_Integ_inverse]) 1); |
|
126 |
qed "eq_Abs_Integ"; |
|
127 |
||
128 |
Goal "- (- z) = (z::int)"; |
|
129 |
by (res_inst_tac [("z","z")] eq_Abs_Integ 1); |
|
130 |
by (asm_simp_tac (simpset() addsimps [zminus]) 1); |
|
131 |
qed "zminus_zminus"; |
|
132 |
Addsimps [zminus_zminus]; |
|
133 |
||
5594 | 134 |
Goal "inj(%z::int. -z)"; |
5508 | 135 |
by (rtac injI 1); |
136 |
by (dres_inst_tac [("f","uminus")] arg_cong 1); |
|
137 |
by (Asm_full_simp_tac 1); |
|
138 |
qed "inj_zminus"; |
|
139 |
||
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
140 |
Goalw [int_def] "- (int 0) = int 0"; |
5508 | 141 |
by (simp_tac (simpset() addsimps [zminus]) 1); |
142 |
qed "zminus_nat0"; |
|
143 |
||
144 |
Addsimps [zminus_nat0]; |
|
145 |
||
146 |
||
5540 | 147 |
(**** neg: the test for negative integers ****) |
5508 | 148 |
|
149 |
||
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
150 |
Goalw [neg_def, int_def] "~ neg(int n)"; |
5508 | 151 |
by (Simp_tac 1); |
152 |
by Safe_tac; |
|
5540 | 153 |
qed "not_neg_nat"; |
5508 | 154 |
|
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
155 |
Goalw [neg_def, int_def] "neg(- (int (Suc n)))"; |
5508 | 156 |
by (simp_tac (simpset() addsimps [zminus]) 1); |
5540 | 157 |
qed "neg_zminus_nat"; |
5508 | 158 |
|
5540 | 159 |
Addsimps [neg_zminus_nat, not_neg_nat]; |
5508 | 160 |
|
161 |
||
162 |
(**** zadd: addition on Integ ****) |
|
163 |
||
164 |
(** Congruence property for addition **) |
|
165 |
||
166 |
Goalw [congruent2_def] |
|
167 |
"congruent2 intrel (%p1 p2. \ |
|
168 |
\ split (%x1 y1. split (%x2 y2. intrel^^{(x1+x2, y1+y2)}) p2) p1)"; |
|
169 |
(*Proof via congruent2_commuteI seems longer*) |
|
170 |
by Safe_tac; |
|
171 |
by (asm_simp_tac (simpset() addsimps [add_assoc]) 1); |
|
172 |
(*The rest should be trivial, but rearranging terms is hard*) |
|
173 |
by (res_inst_tac [("x1","x1a")] (add_left_commute RS ssubst) 1); |
|
174 |
by (asm_simp_tac (simpset() addsimps [add_assoc RS sym]) 1); |
|
175 |
qed "zadd_congruent2"; |
|
176 |
||
177 |
(*Resolve th against the corresponding facts for zadd*) |
|
178 |
val zadd_ize = RSLIST [equiv_intrel, zadd_congruent2]; |
|
179 |
||
180 |
Goalw [zadd_def] |
|
181 |
"Abs_Integ(intrel^^{(x1,y1)}) + Abs_Integ(intrel^^{(x2,y2)}) = \ |
|
182 |
\ Abs_Integ(intrel^^{(x1+x2, y1+y2)})"; |
|
183 |
by (asm_simp_tac |
|
184 |
(simpset() addsimps [zadd_ize UN_equiv_class2]) 1); |
|
185 |
qed "zadd"; |
|
186 |
||
187 |
Goal "- (z + w) = - z + - (w::int)"; |
|
188 |
by (res_inst_tac [("z","z")] eq_Abs_Integ 1); |
|
189 |
by (res_inst_tac [("z","w")] eq_Abs_Integ 1); |
|
190 |
by (asm_simp_tac (simpset() addsimps [zminus,zadd]) 1); |
|
191 |
qed "zminus_zadd_distrib"; |
|
192 |
Addsimps [zminus_zadd_distrib]; |
|
193 |
||
194 |
Goal "(z::int) + w = w + z"; |
|
195 |
by (res_inst_tac [("z","z")] eq_Abs_Integ 1); |
|
196 |
by (res_inst_tac [("z","w")] eq_Abs_Integ 1); |
|
5540 | 197 |
by (asm_simp_tac (simpset() addsimps add_ac @ [zadd]) 1); |
5508 | 198 |
qed "zadd_commute"; |
199 |
||
200 |
Goal "((z1::int) + z2) + z3 = z1 + (z2 + z3)"; |
|
201 |
by (res_inst_tac [("z","z1")] eq_Abs_Integ 1); |
|
202 |
by (res_inst_tac [("z","z2")] eq_Abs_Integ 1); |
|
203 |
by (res_inst_tac [("z","z3")] eq_Abs_Integ 1); |
|
204 |
by (asm_simp_tac (simpset() addsimps [zadd, add_assoc]) 1); |
|
205 |
qed "zadd_assoc"; |
|
206 |
||
207 |
(*For AC rewriting*) |
|
208 |
Goal "(x::int)+(y+z)=y+(x+z)"; |
|
209 |
by (rtac (zadd_commute RS trans) 1); |
|
210 |
by (rtac (zadd_assoc RS trans) 1); |
|
211 |
by (rtac (zadd_commute RS arg_cong) 1); |
|
212 |
qed "zadd_left_commute"; |
|
213 |
||
214 |
(*Integer addition is an AC operator*) |
|
215 |
val zadd_ac = [zadd_assoc,zadd_commute,zadd_left_commute]; |
|
216 |
||
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
217 |
Goalw [int_def] "(int m) + (int n) = int (m + n)"; |
5508 | 218 |
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
|
219 |
qed "zadd_int"; |
5508 | 220 |
|
5594 | 221 |
Goal "(int m) + (int n + z) = int (m + n) + z"; |
222 |
by (simp_tac (simpset() addsimps [zadd_int, zadd_assoc RS sym]) 1); |
|
223 |
qed "zadd_int_left"; |
|
224 |
||
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
225 |
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
|
226 |
by (simp_tac (simpset() addsimps [zadd_int]) 1); |
5562
02261e6880d1
Renaming of Integ/Integ.* to Integ/Int.*, and renaming of related constants
paulson
parents:
5540
diff
changeset
|
227 |
qed "int_Suc"; |
5508 | 228 |
|
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
229 |
Goalw [int_def] "int 0 + z = z"; |
5508 | 230 |
by (res_inst_tac [("z","z")] eq_Abs_Integ 1); |
231 |
by (asm_simp_tac (simpset() addsimps [zadd]) 1); |
|
232 |
qed "zadd_nat0"; |
|
233 |
||
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
234 |
Goal "z + int 0 = z"; |
5508 | 235 |
by (rtac (zadd_commute RS trans) 1); |
236 |
by (rtac zadd_nat0 1); |
|
237 |
qed "zadd_nat0_right"; |
|
238 |
||
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
239 |
Goalw [int_def] "z + (- z) = int 0"; |
5508 | 240 |
by (res_inst_tac [("z","z")] eq_Abs_Integ 1); |
241 |
by (asm_simp_tac (simpset() addsimps [zminus, zadd, add_commute]) 1); |
|
5594 | 242 |
qed "zadd_zminus_inverse"; |
5508 | 243 |
|
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
244 |
Goal "(- z) + z = int 0"; |
5508 | 245 |
by (rtac (zadd_commute RS trans) 1); |
5594 | 246 |
by (rtac zadd_zminus_inverse 1); |
247 |
qed "zadd_zminus_inverse2"; |
|
5508 | 248 |
|
249 |
Addsimps [zadd_nat0, zadd_nat0_right, |
|
5594 | 250 |
zadd_zminus_inverse, zadd_zminus_inverse2]; |
5508 | 251 |
|
252 |
Goal "z + (- z + w) = (w::int)"; |
|
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
253 |
by (simp_tac (simpset() addsimps [zadd_assoc RS sym]) 1); |
5508 | 254 |
qed "zadd_zminus_cancel"; |
255 |
||
256 |
Goal "(-z) + (z + w) = (w::int)"; |
|
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
257 |
by (simp_tac (simpset() addsimps [zadd_assoc RS sym]) 1); |
5508 | 258 |
qed "zminus_zadd_cancel"; |
259 |
||
260 |
Addsimps [zadd_zminus_cancel, zminus_zadd_cancel]; |
|
261 |
||
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
262 |
Goal "int 0 - x = -x"; |
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
263 |
by (simp_tac (simpset() addsimps [zdiff_def]) 1); |
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
264 |
qed "zdiff_nat0"; |
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
265 |
|
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
266 |
Goal "x - int 0 = x"; |
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
267 |
by (simp_tac (simpset() addsimps [zdiff_def]) 1); |
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
268 |
qed "zdiff_nat0_right"; |
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
269 |
|
5594 | 270 |
Goal "x - x = int 0"; |
271 |
by (simp_tac (simpset() addsimps [zdiff_def]) 1); |
|
272 |
qed "zdiff_self"; |
|
273 |
||
274 |
Addsimps [zdiff_nat0, zdiff_nat0_right, zdiff_self]; |
|
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
275 |
|
5508 | 276 |
|
277 |
(** Lemmas **) |
|
278 |
||
279 |
Goal "(z::int) + v = z' + v' ==> z + (v + w) = z' + (v' + w)"; |
|
280 |
by (asm_simp_tac (simpset() addsimps [zadd_assoc RS sym]) 1); |
|
281 |
qed "zadd_assoc_cong"; |
|
282 |
||
283 |
Goal "(z::int) + (v + w) = v + (z + w)"; |
|
284 |
by (REPEAT (ares_tac [zadd_commute RS zadd_assoc_cong] 1)); |
|
285 |
qed "zadd_assoc_swap"; |
|
286 |
||
287 |
||
288 |
(*Need properties of subtraction? Or use $- just as an abbreviation!*) |
|
289 |
||
290 |
(**** zmult: multiplication on Integ ****) |
|
291 |
||
292 |
(** Congruence property for multiplication **) |
|
293 |
||
294 |
Goal "((k::nat) + l) + (m + n) = (k + m) + (n + l)"; |
|
295 |
by (simp_tac (simpset() addsimps add_ac) 1); |
|
296 |
qed "zmult_congruent_lemma"; |
|
297 |
||
298 |
Goal "congruent2 intrel (%p1 p2. \ |
|
299 |
\ split (%x1 y1. split (%x2 y2. \ |
|
300 |
\ intrel^^{(x1*x2 + y1*y2, x1*y2 + y1*x2)}) p2) p1)"; |
|
301 |
by (rtac (equiv_intrel RS congruent2_commuteI) 1); |
|
302 |
by (pair_tac "w" 2); |
|
303 |
by (rename_tac "z1 z2" 2); |
|
304 |
by Safe_tac; |
|
305 |
by (rewtac split_def); |
|
306 |
by (simp_tac (simpset() addsimps add_ac@mult_ac) 1); |
|
307 |
by (asm_simp_tac (simpset() delsimps [equiv_intrel_iff] |
|
308 |
addsimps add_ac@mult_ac) 1); |
|
309 |
by (rtac (intrelI RS(equiv_intrel RS equiv_class_eq)) 1); |
|
310 |
by (rtac (zmult_congruent_lemma RS trans) 1); |
|
311 |
by (rtac (zmult_congruent_lemma RS trans RS sym) 1); |
|
312 |
by (rtac (zmult_congruent_lemma RS trans RS sym) 1); |
|
313 |
by (rtac (zmult_congruent_lemma RS trans RS sym) 1); |
|
314 |
by (asm_simp_tac (simpset() addsimps [add_mult_distrib RS sym]) 1); |
|
315 |
by (asm_simp_tac (simpset() addsimps add_ac@mult_ac) 1); |
|
316 |
qed "zmult_congruent2"; |
|
317 |
||
318 |
(*Resolve th against the corresponding facts for zmult*) |
|
319 |
val zmult_ize = RSLIST [equiv_intrel, zmult_congruent2]; |
|
320 |
||
321 |
Goalw [zmult_def] |
|
322 |
"Abs_Integ((intrel^^{(x1,y1)})) * Abs_Integ((intrel^^{(x2,y2)})) = \ |
|
323 |
\ Abs_Integ(intrel ^^ {(x1*x2 + y1*y2, x1*y2 + y1*x2)})"; |
|
324 |
by (simp_tac (simpset() addsimps [zmult_ize UN_equiv_class2]) 1); |
|
325 |
qed "zmult"; |
|
326 |
||
327 |
Goal "(- z) * w = - (z * (w::int))"; |
|
328 |
by (res_inst_tac [("z","z")] eq_Abs_Integ 1); |
|
329 |
by (res_inst_tac [("z","w")] eq_Abs_Integ 1); |
|
5540 | 330 |
by (asm_simp_tac (simpset() addsimps [zminus, zmult] @ add_ac) 1); |
5508 | 331 |
qed "zmult_zminus"; |
332 |
||
333 |
||
334 |
Goal "(- z) * (- w) = (z * (w::int))"; |
|
335 |
by (res_inst_tac [("z","z")] eq_Abs_Integ 1); |
|
336 |
by (res_inst_tac [("z","w")] eq_Abs_Integ 1); |
|
5540 | 337 |
by (asm_simp_tac (simpset() addsimps [zminus, zmult] @ add_ac) 1); |
5508 | 338 |
qed "zmult_zminus_zminus"; |
339 |
||
340 |
Goal "(z::int) * w = w * z"; |
|
341 |
by (res_inst_tac [("z","z")] eq_Abs_Integ 1); |
|
342 |
by (res_inst_tac [("z","w")] eq_Abs_Integ 1); |
|
5540 | 343 |
by (asm_simp_tac (simpset() addsimps [zmult] @ add_ac @ mult_ac) 1); |
5508 | 344 |
qed "zmult_commute"; |
345 |
||
346 |
Goal "((z1::int) * z2) * z3 = z1 * (z2 * z3)"; |
|
347 |
by (res_inst_tac [("z","z1")] eq_Abs_Integ 1); |
|
348 |
by (res_inst_tac [("z","z2")] eq_Abs_Integ 1); |
|
349 |
by (res_inst_tac [("z","z3")] eq_Abs_Integ 1); |
|
5540 | 350 |
by (asm_simp_tac (simpset() addsimps [add_mult_distrib2,zmult] @ |
351 |
add_ac @ mult_ac) 1); |
|
5508 | 352 |
qed "zmult_assoc"; |
353 |
||
354 |
(*For AC rewriting*) |
|
355 |
Goal "(z1::int)*(z2*z3) = z2*(z1*z3)"; |
|
356 |
by (rtac (zmult_commute RS trans) 1); |
|
357 |
by (rtac (zmult_assoc RS trans) 1); |
|
358 |
by (rtac (zmult_commute RS arg_cong) 1); |
|
359 |
qed "zmult_left_commute"; |
|
360 |
||
361 |
(*Integer multiplication is an AC operator*) |
|
362 |
val zmult_ac = [zmult_assoc, zmult_commute, zmult_left_commute]; |
|
363 |
||
364 |
Goal "((z1::int) + z2) * w = (z1 * w) + (z2 * w)"; |
|
365 |
by (res_inst_tac [("z","z1")] eq_Abs_Integ 1); |
|
366 |
by (res_inst_tac [("z","z2")] eq_Abs_Integ 1); |
|
367 |
by (res_inst_tac [("z","w")] eq_Abs_Integ 1); |
|
368 |
by (asm_simp_tac |
|
5540 | 369 |
(simpset() addsimps [add_mult_distrib2, zadd, zmult] @ |
370 |
add_ac @ mult_ac) 1); |
|
5508 | 371 |
qed "zadd_zmult_distrib"; |
372 |
||
373 |
val zmult_commute'= read_instantiate [("z","w")] zmult_commute; |
|
374 |
||
375 |
Goal "w * (- z) = - (w * (z::int))"; |
|
376 |
by (simp_tac (simpset() addsimps [zmult_commute', zmult_zminus]) 1); |
|
377 |
qed "zmult_zminus_right"; |
|
378 |
||
379 |
Goal "(w::int) * (z1 + z2) = (w * z1) + (w * z2)"; |
|
380 |
by (simp_tac (simpset() addsimps [zmult_commute',zadd_zmult_distrib]) 1); |
|
381 |
qed "zadd_zmult_distrib2"; |
|
382 |
||
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
383 |
Goalw [int_def] "int 0 * z = int 0"; |
5508 | 384 |
by (res_inst_tac [("z","z")] eq_Abs_Integ 1); |
385 |
by (asm_simp_tac (simpset() addsimps [zmult]) 1); |
|
386 |
qed "zmult_nat0"; |
|
387 |
||
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
388 |
Goalw [int_def] "int 1 * z = z"; |
5508 | 389 |
by (res_inst_tac [("z","z")] eq_Abs_Integ 1); |
390 |
by (asm_simp_tac (simpset() addsimps [zmult]) 1); |
|
391 |
qed "zmult_nat1"; |
|
392 |
||
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
393 |
Goal "z * int 0 = int 0"; |
5508 | 394 |
by (rtac ([zmult_commute, zmult_nat0] MRS trans) 1); |
395 |
qed "zmult_nat0_right"; |
|
396 |
||
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
397 |
Goal "z * int 1 = z"; |
5508 | 398 |
by (rtac ([zmult_commute, zmult_nat1] MRS trans) 1); |
399 |
qed "zmult_nat1_right"; |
|
400 |
||
401 |
Addsimps [zmult_nat0, zmult_nat0_right, zmult_nat1, zmult_nat1_right]; |
|
402 |
||
403 |
||
404 |
Goal "(- z = w) = (z = - (w::int))"; |
|
405 |
by Safe_tac; |
|
406 |
by (rtac (zminus_zminus RS sym) 1); |
|
407 |
by (rtac zminus_zminus 1); |
|
408 |
qed "zminus_exchange"; |
|
409 |
||
410 |
||
411 |
(* Theorems about less and less_equal *) |
|
412 |
||
413 |
(*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
|
414 |
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
|
415 |
"(w < z) = (EX n. z = w + int(Suc n))"; |
5508 | 416 |
by (res_inst_tac [("z","z")] eq_Abs_Integ 1); |
417 |
by (res_inst_tac [("z","w")] eq_Abs_Integ 1); |
|
418 |
by (Clarify_tac 1); |
|
419 |
by (asm_full_simp_tac (simpset() addsimps [zadd, zminus]) 1); |
|
420 |
by (safe_tac (claset() addSDs [less_eq_Suc_add])); |
|
421 |
by (res_inst_tac [("x","k")] exI 1); |
|
422 |
by (ALLGOALS (asm_full_simp_tac (simpset() addsimps add_ac))); |
|
423 |
qed "zless_iff_Suc_zadd"; |
|
424 |
||
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
425 |
Goal "z < z + int (Suc n)"; |
5508 | 426 |
by (auto_tac (claset(), |
427 |
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
|
428 |
zadd_int])); |
5508 | 429 |
qed "zless_zadd_Suc"; |
430 |
||
431 |
Goal "[| z1<z2; z2<z3 |] ==> z1 < (z3::int)"; |
|
432 |
by (auto_tac (claset(), |
|
433 |
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
|
434 |
zadd_int])); |
5508 | 435 |
qed "zless_trans"; |
436 |
||
437 |
Goal "!!w::int. z<w ==> ~w<z"; |
|
438 |
by (safe_tac (claset() addSDs [zless_iff_Suc_zadd RS iffD1])); |
|
439 |
by (res_inst_tac [("z","z")] eq_Abs_Integ 1); |
|
440 |
by Safe_tac; |
|
5562
02261e6880d1
Renaming of Integ/Integ.* to Integ/Int.*, and renaming of related constants
paulson
parents:
5540
diff
changeset
|
441 |
by (asm_full_simp_tac (simpset() addsimps [int_def, zadd]) 1); |
5508 | 442 |
qed "zless_not_sym"; |
443 |
||
444 |
(* [| n<m; ~P ==> m<n |] ==> P *) |
|
5540 | 445 |
bind_thm ("zless_asym", zless_not_sym RS swap); |
5508 | 446 |
|
447 |
Goal "!!z::int. ~ z<z"; |
|
448 |
by (resolve_tac [zless_asym RS notI] 1); |
|
449 |
by (REPEAT (assume_tac 1)); |
|
450 |
qed "zless_not_refl"; |
|
451 |
||
452 |
(* z<z ==> R *) |
|
5594 | 453 |
bind_thm ("zless_irrefl", zless_not_refl RS notE); |
5508 | 454 |
AddSEs [zless_irrefl]; |
455 |
||
456 |
Goal "z<w ==> w ~= (z::int)"; |
|
457 |
by (Blast_tac 1); |
|
458 |
qed "zless_not_refl2"; |
|
459 |
||
460 |
(* s < t ==> s ~= t *) |
|
461 |
bind_thm ("zless_not_refl3", zless_not_refl2 RS not_sym); |
|
462 |
||
463 |
||
464 |
(*"Less than" is a linear ordering*) |
|
5540 | 465 |
Goalw [zless_def, neg_def, zdiff_def] |
5508 | 466 |
"z<w | z=w | w<(z::int)"; |
467 |
by (res_inst_tac [("z","z")] eq_Abs_Integ 1); |
|
468 |
by (res_inst_tac [("z","w")] eq_Abs_Integ 1); |
|
469 |
by Safe_tac; |
|
470 |
by (asm_full_simp_tac |
|
471 |
(simpset() addsimps [zadd, zminus, Image_iff, Bex_def]) 1); |
|
472 |
by (res_inst_tac [("m1", "x+ya"), ("n1", "xa+y")] (less_linear RS disjE) 1); |
|
473 |
by (auto_tac (claset(), simpset() addsimps add_ac)); |
|
474 |
qed "zless_linear"; |
|
475 |
||
476 |
Goal "!!w::int. (w ~= z) = (w<z | z<w)"; |
|
477 |
by (cut_facts_tac [zless_linear] 1); |
|
478 |
by (Blast_tac 1); |
|
479 |
qed "int_neq_iff"; |
|
480 |
||
481 |
(*** eliminates ~= in premises ***) |
|
482 |
bind_thm("int_neqE", int_neq_iff RS iffD1 RS disjE); |
|
483 |
||
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
484 |
Goal "(int m = int n) = (m = n)"; |
5540 | 485 |
by (fast_tac (claset() addSEs [inj_nat RS injD]) 1); |
5562
02261e6880d1
Renaming of Integ/Integ.* to Integ/Int.*, and renaming of related constants
paulson
parents:
5540
diff
changeset
|
486 |
qed "int_int_eq"; |
02261e6880d1
Renaming of Integ/Integ.* to Integ/Int.*, and renaming of related constants
paulson
parents:
5540
diff
changeset
|
487 |
AddIffs [int_int_eq]; |
5508 | 488 |
|
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
489 |
Goal "(int m < int n) = (m<n)"; |
5508 | 490 |
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
|
491 |
zadd_int]) 1); |
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
492 |
qed "zless_int"; |
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
493 |
Addsimps [zless_int]; |
5508 | 494 |
|
495 |
||
496 |
(*** Properties of <= ***) |
|
497 |
||
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
498 |
Goalw [zle_def, le_def] "(int m <= int n) = (m<=n)"; |
5508 | 499 |
by (Simp_tac 1); |
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
500 |
qed "zle_int"; |
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
501 |
Addsimps [zle_int]; |
5508 | 502 |
|
503 |
Goalw [zle_def] "~(w<z) ==> z<=(w::int)"; |
|
504 |
by (assume_tac 1); |
|
505 |
qed "zleI"; |
|
506 |
||
507 |
Goalw [zle_def] "z<=w ==> ~(w<(z::int))"; |
|
508 |
by (assume_tac 1); |
|
509 |
qed "zleD"; |
|
510 |
||
511 |
(* [| z <= w; ~ P ==> w < z |] ==> P *) |
|
512 |
bind_thm ("zleE", zleD RS swap); |
|
513 |
||
514 |
Goalw [zle_def] "(~w<=z) = (z<(w::int))"; |
|
515 |
by (Simp_tac 1); |
|
516 |
qed "not_zle_iff_zless"; |
|
517 |
||
518 |
Goalw [zle_def] "~ z <= w ==> w<(z::int)"; |
|
519 |
by (Fast_tac 1); |
|
520 |
qed "not_zleE"; |
|
521 |
||
522 |
Goalw [zle_def] "z <= w ==> z < w | z=(w::int)"; |
|
523 |
by (cut_facts_tac [zless_linear] 1); |
|
524 |
by (blast_tac (claset() addEs [zless_asym]) 1); |
|
525 |
qed "zle_imp_zless_or_eq"; |
|
526 |
||
527 |
Goalw [zle_def] "z<w | z=w ==> z <= (w::int)"; |
|
528 |
by (cut_facts_tac [zless_linear] 1); |
|
529 |
by (blast_tac (claset() addEs [zless_asym]) 1); |
|
530 |
qed "zless_or_eq_imp_zle"; |
|
531 |
||
532 |
Goal "(x <= (y::int)) = (x < y | x=y)"; |
|
533 |
by (REPEAT(ares_tac [iffI, zless_or_eq_imp_zle, zle_imp_zless_or_eq] 1)); |
|
5540 | 534 |
qed "integ_le_less"; |
5508 | 535 |
|
536 |
Goal "w <= (w::int)"; |
|
5540 | 537 |
by (simp_tac (simpset() addsimps [integ_le_less]) 1); |
5508 | 538 |
qed "zle_refl"; |
539 |
||
5594 | 540 |
AddIffs [le_refl]; |
541 |
||
5508 | 542 |
Goalw [zle_def] "z < w ==> z <= (w::int)"; |
543 |
by (blast_tac (claset() addEs [zless_asym]) 1); |
|
544 |
qed "zless_imp_zle"; |
|
545 |
||
546 |
(* Axiom 'linorder_linear' of class 'linorder': *) |
|
547 |
Goal "(z::int) <= w | w <= z"; |
|
5540 | 548 |
by (simp_tac (simpset() addsimps [integ_le_less]) 1); |
5508 | 549 |
by (cut_facts_tac [zless_linear] 1); |
550 |
by (Blast_tac 1); |
|
551 |
qed "zle_linear"; |
|
552 |
||
553 |
Goal "[| i <= j; j < k |] ==> i < (k::int)"; |
|
554 |
by (dtac zle_imp_zless_or_eq 1); |
|
555 |
by (blast_tac (claset() addIs [zless_trans]) 1); |
|
556 |
qed "zle_zless_trans"; |
|
557 |
||
558 |
Goal "[| i < j; j <= k |] ==> i < (k::int)"; |
|
559 |
by (dtac zle_imp_zless_or_eq 1); |
|
560 |
by (blast_tac (claset() addIs [zless_trans]) 1); |
|
561 |
qed "zless_zle_trans"; |
|
562 |
||
563 |
Goal "[| i <= j; j <= k |] ==> i <= (k::int)"; |
|
564 |
by (EVERY1 [dtac zle_imp_zless_or_eq, dtac zle_imp_zless_or_eq, |
|
565 |
rtac zless_or_eq_imp_zle, |
|
566 |
blast_tac (claset() addIs [zless_trans])]); |
|
567 |
qed "zle_trans"; |
|
568 |
||
569 |
Goal "[| z <= w; w <= z |] ==> z = (w::int)"; |
|
570 |
by (EVERY1 [dtac zle_imp_zless_or_eq, dtac zle_imp_zless_or_eq, |
|
571 |
blast_tac (claset() addEs [zless_asym])]); |
|
572 |
qed "zle_anti_sym"; |
|
573 |
||
574 |
(* Axiom 'order_less_le' of class 'order': *) |
|
575 |
Goal "(w::int) < z = (w <= z & w ~= z)"; |
|
576 |
by (simp_tac (simpset() addsimps [zle_def, int_neq_iff]) 1); |
|
577 |
by (blast_tac (claset() addSEs [zless_asym]) 1); |
|
578 |
qed "int_less_le"; |
|
579 |
||
580 |
(* [| w <= z; w ~= z |] ==> w < z *) |
|
581 |
bind_thm ("zle_neq_implies_zless", [int_less_le, conjI] MRS iffD2); |
|
582 |
||
583 |
||
584 |
||
585 |
(*** Subtraction laws ***) |
|
586 |
||
587 |
Goal "x + (y - z) = (x + y) - (z::int)"; |
|
5540 | 588 |
by (simp_tac (simpset() addsimps zdiff_def::zadd_ac) 1); |
5508 | 589 |
qed "zadd_zdiff_eq"; |
590 |
||
591 |
Goal "(x - y) + z = (x + z) - (y::int)"; |
|
5540 | 592 |
by (simp_tac (simpset() addsimps zdiff_def::zadd_ac) 1); |
5508 | 593 |
qed "zdiff_zadd_eq"; |
594 |
||
595 |
Goal "(x - y) - z = x - (y + (z::int))"; |
|
5540 | 596 |
by (simp_tac (simpset() addsimps zdiff_def::zadd_ac) 1); |
5508 | 597 |
qed "zdiff_zdiff_eq"; |
598 |
||
599 |
Goal "x - (y - z) = (x + z) - (y::int)"; |
|
5540 | 600 |
by (simp_tac (simpset() addsimps zdiff_def::zadd_ac) 1); |
5508 | 601 |
qed "zdiff_zdiff_eq2"; |
602 |
||
603 |
Goalw [zless_def, zdiff_def] "(x-y < z) = (x < z + (y::int))"; |
|
604 |
by (simp_tac (simpset() addsimps zadd_ac) 1); |
|
605 |
qed "zdiff_zless_eq"; |
|
606 |
||
607 |
Goalw [zless_def, zdiff_def] "(x < z-y) = (x + (y::int) < z)"; |
|
608 |
by (simp_tac (simpset() addsimps zadd_ac) 1); |
|
609 |
qed "zless_zdiff_eq"; |
|
610 |
||
611 |
Goalw [zle_def] "(x-y <= z) = (x <= z + (y::int))"; |
|
612 |
by (simp_tac (simpset() addsimps [zless_zdiff_eq]) 1); |
|
613 |
qed "zdiff_zle_eq"; |
|
614 |
||
615 |
Goalw [zle_def] "(x <= z-y) = (x + (y::int) <= z)"; |
|
616 |
by (simp_tac (simpset() addsimps [zdiff_zless_eq]) 1); |
|
617 |
qed "zle_zdiff_eq"; |
|
618 |
||
619 |
Goalw [zdiff_def] "(x-y = z) = (x = z + (y::int))"; |
|
620 |
by (auto_tac (claset(), simpset() addsimps [zadd_assoc])); |
|
621 |
qed "zdiff_eq_eq"; |
|
622 |
||
623 |
Goalw [zdiff_def] "(x = z-y) = (x + (y::int) = z)"; |
|
624 |
by (auto_tac (claset(), simpset() addsimps [zadd_assoc])); |
|
625 |
qed "eq_zdiff_eq"; |
|
626 |
||
627 |
(*This list of rewrites simplifies (in)equalities by bringing subtractions |
|
628 |
to the top and then moving negative terms to the other side. |
|
629 |
Use with zadd_ac*) |
|
630 |
val zcompare_rls = |
|
631 |
[symmetric zdiff_def, |
|
632 |
zadd_zdiff_eq, zdiff_zadd_eq, zdiff_zdiff_eq, zdiff_zdiff_eq2, |
|
633 |
zdiff_zless_eq, zless_zdiff_eq, zdiff_zle_eq, zle_zdiff_eq, |
|
634 |
zdiff_eq_eq, eq_zdiff_eq]; |
|
635 |
||
636 |
||
637 |
(** Cancellation laws **) |
|
638 |
||
639 |
Goal "!!w::int. (z + w' = z + w) = (w' = w)"; |
|
640 |
by Safe_tac; |
|
641 |
by (dres_inst_tac [("f", "%x. x + -z")] arg_cong 1); |
|
642 |
by (asm_full_simp_tac (simpset() addsimps zadd_ac) 1); |
|
643 |
qed "zadd_left_cancel"; |
|
644 |
||
645 |
Addsimps [zadd_left_cancel]; |
|
646 |
||
647 |
Goal "!!z::int. (w' + z = w + z) = (w' = w)"; |
|
648 |
by (asm_full_simp_tac (simpset() addsimps zadd_ac) 1); |
|
649 |
qed "zadd_right_cancel"; |
|
650 |
||
651 |
Addsimps [zadd_right_cancel]; |
|
652 |
||
653 |
||
5594 | 654 |
(** For the cancellation simproc. |
655 |
The idea is to cancel like terms on opposite sides by subtraction **) |
|
656 |
||
657 |
Goal "(x::int) - y = x' - y' ==> (x<y) = (x'<y')"; |
|
658 |
by (asm_simp_tac (simpset() addsimps [zless_def]) 1); |
|
659 |
qed "zless_eqI"; |
|
5508 | 660 |
|
5594 | 661 |
Goal "(x::int) - y = x' - y' ==> (y<=x) = (y'<=x')"; |
662 |
by (dtac zless_eqI 1); |
|
663 |
by (asm_simp_tac (simpset() addsimps [zle_def]) 1); |
|
664 |
qed "zle_eqI"; |
|
5508 | 665 |
|
5594 | 666 |
Goal "(x::int) - y = x' - y' ==> (x=y) = (x'=y')"; |
667 |
by Safe_tac; |
|
668 |
by (ALLGOALS |
|
669 |
(asm_full_simp_tac (simpset() addsimps [eq_zdiff_eq, zdiff_eq_eq]))); |
|
670 |
qed "zeq_eqI"; |
|
5582
a356fb49e69e
many renamings and changes. Simproc for cancelling common terms in relations
paulson
parents:
5562
diff
changeset
|
671 |