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