equal
deleted
inserted
replaced
10 "~ znegative(z) ==> $# zmagnitude(z) = z" |
10 "~ znegative(z) ==> $# zmagnitude(z) = z" |
11 $< is a linear ordering |
11 $< is a linear ordering |
12 $+ and $* are monotonic wrt $< |
12 $+ and $* are monotonic wrt $< |
13 *) |
13 *) |
14 |
14 |
15 val add_cong = |
|
16 read_instantiate_sg (sign_of Arith.thy) [("t","op #+")] subst_context2; |
|
17 |
|
18 |
|
19 open Integ; |
15 open Integ; |
20 |
16 |
21 (*** Proving that intrel is an equivalence relation ***) |
17 (*** Proving that intrel is an equivalence relation ***) |
22 |
|
23 val add_kill = (refl RS add_cong); |
|
24 |
|
25 val add_left_commute_kill = add_kill RSN (3, add_left_commute RS trans); |
|
26 |
18 |
27 (*By luck, requires no typing premises for y1, y2,y3*) |
19 (*By luck, requires no typing premises for y1, y2,y3*) |
28 val eqa::eqb::prems = goal Arith.thy |
20 val eqa::eqb::prems = goal Arith.thy |
29 "[| x1 #+ y2 = x2 #+ y1; x2 #+ y3 = x3 #+ y2; \ |
21 "[| x1 #+ y2 = x2 #+ y1; x2 #+ y3 = x3 #+ y2; \ |
30 \ x1: nat; x2: nat; x3: nat |] ==> x1 #+ y3 = x3 #+ y1"; |
22 \ x1: nat; x2: nat; x3: nat |] ==> x1 #+ y3 = x3 #+ y1"; |
261 by (REPEAT (eresolve_tac [quotientE, SigmaE, ssubst] 1)); |
253 by (REPEAT (eresolve_tac [quotientE, SigmaE, ssubst] 1)); |
262 (*rewriting is much faster without intrel_iff, etc.*) |
254 (*rewriting is much faster without intrel_iff, etc.*) |
263 by (asm_simp_tac (arith_ss addsimps [zadd, add_assoc]) 1); |
255 by (asm_simp_tac (arith_ss addsimps [zadd, add_assoc]) 1); |
264 qed "zadd_assoc"; |
256 qed "zadd_assoc"; |
265 |
257 |
|
258 (*For AC rewriting*) |
|
259 qed_goal "zadd_left_commute" Integ.thy |
|
260 "!!z1 z2 z3. [| z1:integ; z2:integ; z3: integ |] ==> \ |
|
261 \ z1$+(z2$+z3) = z2$+(z1$+z3)" |
|
262 (fn _ => [asm_simp_tac (ZF_ss addsimps [zadd_assoc RS sym, zadd_commute]) 1]); |
|
263 |
|
264 (*Integer addition is an AC operator*) |
|
265 val zadd_ac = [zadd_assoc, zadd_commute, zadd_left_commute]; |
|
266 |
266 goalw Integ.thy [znat_def] |
267 goalw Integ.thy [znat_def] |
267 "!!m n. [| m: nat; n: nat |] ==> $# (m #+ n) = ($#m) $+ ($#n)"; |
268 "!!m n. [| m: nat; n: nat |] ==> $# (m #+ n) = ($#m) $+ ($#n)"; |
268 by (asm_simp_tac (arith_ss addsimps [zadd]) 1); |
269 by (asm_simp_tac (arith_ss addsimps [zadd]) 1); |
269 qed "znat_add"; |
270 qed "znat_add"; |
270 |
271 |
362 by (asm_simp_tac |
363 by (asm_simp_tac |
363 (intrel_ss addsimps ([zmult, add_mult_distrib_left, |
364 (intrel_ss addsimps ([zmult, add_mult_distrib_left, |
364 add_mult_distrib] @ add_ac @ mult_ac)) 1); |
365 add_mult_distrib] @ add_ac @ mult_ac)) 1); |
365 qed "zmult_assoc"; |
366 qed "zmult_assoc"; |
366 |
367 |
|
368 (*For AC rewriting*) |
|
369 qed_goal "zmult_left_commute" Integ.thy |
|
370 "!!z1 z2 z3. [| z1:integ; z2:integ; z3: integ |] ==> \ |
|
371 \ z1$*(z2$*z3) = z2$*(z1$*z3)" |
|
372 (fn _ => [asm_simp_tac (ZF_ss addsimps [zmult_assoc RS sym, |
|
373 zmult_commute]) 1]); |
|
374 |
|
375 (*Integer multiplication is an AC operator*) |
|
376 val zmult_ac = [zmult_assoc, zmult_commute, zmult_left_commute]; |
|
377 |
367 goalw Integ.thy [integ_def] |
378 goalw Integ.thy [integ_def] |
368 "!!z1 z2 z3. [| z1: integ; z2: integ; w: integ |] ==> \ |
379 "!!z1 z2 z3. [| z1: integ; z2: integ; w: integ |] ==> \ |
369 \ (z1 $+ z2) $* w = (z1 $* w) $+ (z2 $* w)"; |
380 \ (z1 $+ z2) $* w = (z1 $* w) $+ (z2 $* w)"; |
370 by (REPEAT (eresolve_tac [quotientE, SigmaE, ssubst] 1)); |
381 by (REPEAT (eresolve_tac [quotientE, SigmaE, ssubst] 1)); |
371 by (asm_simp_tac |
382 by (asm_simp_tac |
374 qed "zadd_zmult_distrib"; |
385 qed "zadd_zmult_distrib"; |
375 |
386 |
376 val integ_typechecks = |
387 val integ_typechecks = |
377 [znat_type, zminus_type, zmagnitude_type, zadd_type, zmult_type]; |
388 [znat_type, zminus_type, zmagnitude_type, zadd_type, zmult_type]; |
378 |
389 |
|
390 val zadd_simps = |
|
391 [zadd_0, zadd_0_right, zadd_zminus_inverse, zadd_zminus_inverse2]; |
|
392 |
|
393 val zminus_simps = [zminus_zminus, zminus_0]; |
|
394 |
|
395 val zmult_simps = [zmult_0, zmult_1, zmult_zminus]; |
|
396 |
379 val integ_ss = |
397 val integ_ss = |
380 arith_ss addsimps ([zminus_zminus, zmagnitude_znat, |
398 arith_ss addsimps (zadd_simps @ zminus_simps @ zmult_simps @ |
381 zmagnitude_zminus_znat, zadd_0] @ integ_typechecks); |
399 [zmagnitude_znat, zmagnitude_zminus_znat] @ |
|
400 integ_typechecks); |