author | paulson |
Sat, 18 May 2002 20:08:17 +0200 | |
changeset 13163 | e320a52ff711 |
parent 12089 | 34e7693271a9 |
child 13175 | 81082cfa5618 |
permissions | -rw-r--r-- |
9578
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
1 |
(* Title: HOL/IntDiv.ML |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
2 |
ID: $Id$ |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
3 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
4 |
Copyright 1999 University of Cambridge |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
5 |
|
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
6 |
The division operators div, mod and the divides relation "dvd" |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
7 |
|
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
8 |
Here is the division algorithm in ML: |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
9 |
|
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
10 |
fun posDivAlg (a,b) = |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
11 |
if a<b then (0,a) |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
12 |
else let val (q,r) = posDivAlg(a, 2*b) |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
13 |
in if 0<=r-b then (2*q+1, r-b) else (2*q, r) |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
14 |
end; |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
15 |
|
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
16 |
fun negDivAlg (a,b) = |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
17 |
if 0<=a+b then (~1,a+b) |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
18 |
else let val (q,r) = negDivAlg(a, 2*b) |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
19 |
in if 0<=r-b then (2*q+1, r-b) else (2*q, r) |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
20 |
end; |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
21 |
|
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
22 |
fun negateSnd (q,r:int) = (q,~r); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
23 |
|
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
24 |
fun divAlg (a,b) = if 0<=a then |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
25 |
if b>0 then posDivAlg (a,b) |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
26 |
else if a=0 then (0,0) |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
27 |
else negateSnd (negDivAlg (~a,~b)) |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
28 |
else |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
29 |
if 0<b then negDivAlg (a,b) |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
30 |
else negateSnd (posDivAlg (~a,~b)); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
31 |
*) |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
32 |
|
12089
34e7693271a9
Sidi Ehmety's port of the fold_set operator and multisets to ZF.
paulson
parents:
11871
diff
changeset
|
33 |
(** Some basic laws by Sidi Ehmety (need linear arithmetic!) **) |
34e7693271a9
Sidi Ehmety's port of the fold_set operator and multisets to ZF.
paulson
parents:
11871
diff
changeset
|
34 |
|
34e7693271a9
Sidi Ehmety's port of the fold_set operator and multisets to ZF.
paulson
parents:
11871
diff
changeset
|
35 |
Goal "[| #0 $< x; #0 $< y |] ==> #0 $< x $+ y"; |
34e7693271a9
Sidi Ehmety's port of the fold_set operator and multisets to ZF.
paulson
parents:
11871
diff
changeset
|
36 |
by (res_inst_tac [("y", "y")] zless_trans 1); |
34e7693271a9
Sidi Ehmety's port of the fold_set operator and multisets to ZF.
paulson
parents:
11871
diff
changeset
|
37 |
by (rtac (zdiff_zless_iff RS iffD1) 2); |
34e7693271a9
Sidi Ehmety's port of the fold_set operator and multisets to ZF.
paulson
parents:
11871
diff
changeset
|
38 |
by Auto_tac; |
34e7693271a9
Sidi Ehmety's port of the fold_set operator and multisets to ZF.
paulson
parents:
11871
diff
changeset
|
39 |
qed "zspos_add_zspos_imp_zspos"; |
34e7693271a9
Sidi Ehmety's port of the fold_set operator and multisets to ZF.
paulson
parents:
11871
diff
changeset
|
40 |
|
34e7693271a9
Sidi Ehmety's port of the fold_set operator and multisets to ZF.
paulson
parents:
11871
diff
changeset
|
41 |
Goal "[| #0 $<= x; #0 $<= y |] ==> #0 $<= x $+ y"; |
34e7693271a9
Sidi Ehmety's port of the fold_set operator and multisets to ZF.
paulson
parents:
11871
diff
changeset
|
42 |
by (res_inst_tac [("y", "y")] zle_trans 1); |
34e7693271a9
Sidi Ehmety's port of the fold_set operator and multisets to ZF.
paulson
parents:
11871
diff
changeset
|
43 |
by (rtac (zdiff_zle_iff RS iffD1) 2); |
34e7693271a9
Sidi Ehmety's port of the fold_set operator and multisets to ZF.
paulson
parents:
11871
diff
changeset
|
44 |
by Auto_tac; |
34e7693271a9
Sidi Ehmety's port of the fold_set operator and multisets to ZF.
paulson
parents:
11871
diff
changeset
|
45 |
qed "zpos_add_zpos_imp_zpos"; |
34e7693271a9
Sidi Ehmety's port of the fold_set operator and multisets to ZF.
paulson
parents:
11871
diff
changeset
|
46 |
|
34e7693271a9
Sidi Ehmety's port of the fold_set operator and multisets to ZF.
paulson
parents:
11871
diff
changeset
|
47 |
Goal "[| x $< #0; y $< #0 |] ==> x $+ y $< #0"; |
34e7693271a9
Sidi Ehmety's port of the fold_set operator and multisets to ZF.
paulson
parents:
11871
diff
changeset
|
48 |
by (res_inst_tac [("y", "y")] zless_trans 1); |
34e7693271a9
Sidi Ehmety's port of the fold_set operator and multisets to ZF.
paulson
parents:
11871
diff
changeset
|
49 |
by (rtac (zless_zdiff_iff RS iffD1) 1); |
34e7693271a9
Sidi Ehmety's port of the fold_set operator and multisets to ZF.
paulson
parents:
11871
diff
changeset
|
50 |
by Auto_tac; |
34e7693271a9
Sidi Ehmety's port of the fold_set operator and multisets to ZF.
paulson
parents:
11871
diff
changeset
|
51 |
qed "zneg_add_zneg_imp_zneg"; |
34e7693271a9
Sidi Ehmety's port of the fold_set operator and multisets to ZF.
paulson
parents:
11871
diff
changeset
|
52 |
|
34e7693271a9
Sidi Ehmety's port of the fold_set operator and multisets to ZF.
paulson
parents:
11871
diff
changeset
|
53 |
(* this theorem is used below *) |
34e7693271a9
Sidi Ehmety's port of the fold_set operator and multisets to ZF.
paulson
parents:
11871
diff
changeset
|
54 |
Goal "[| x $<= #0; y $<= #0 |] ==> x $+ y $<= #0"; |
34e7693271a9
Sidi Ehmety's port of the fold_set operator and multisets to ZF.
paulson
parents:
11871
diff
changeset
|
55 |
by (res_inst_tac [("y", "y")] zle_trans 1); |
34e7693271a9
Sidi Ehmety's port of the fold_set operator and multisets to ZF.
paulson
parents:
11871
diff
changeset
|
56 |
by (rtac (zle_zdiff_iff RS iffD1) 1); |
34e7693271a9
Sidi Ehmety's port of the fold_set operator and multisets to ZF.
paulson
parents:
11871
diff
changeset
|
57 |
by Auto_tac; |
34e7693271a9
Sidi Ehmety's port of the fold_set operator and multisets to ZF.
paulson
parents:
11871
diff
changeset
|
58 |
qed "zneg_or_0_add_zneg_or_0_imp_zneg_or_0"; |
34e7693271a9
Sidi Ehmety's port of the fold_set operator and multisets to ZF.
paulson
parents:
11871
diff
changeset
|
59 |
|
11321 | 60 |
Goal "[| #0 $< k; k \\<in> int |] ==> 0 < zmagnitude(k)"; |
9578
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
61 |
by (dtac zero_zless_imp_znegative_zminus 1); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
62 |
by (dtac zneg_int_of 2); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
63 |
by (auto_tac (claset(), simpset() addsimps [inst "x" "k" zminus_equation])); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
64 |
by (subgoal_tac "0 < zmagnitude($# succ(x))" 1); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
65 |
by (Asm_full_simp_tac 1); |
13163 | 66 |
by (asm_full_simp_tac (FOL_ss addsimps [zmagnitude_int_of]) 1); |
67 |
by (Asm_full_simp_tac 1); |
|
9578
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
68 |
qed "zero_lt_zmagnitude"; |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
69 |
|
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
70 |
|
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
71 |
(*** Inequality lemmas involving $#succ(m) ***) |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
72 |
|
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
73 |
Goal "(w $< z $+ $# succ(m)) <-> (w $< z $+ $#m | intify(w) = z $+ $#m)"; |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
74 |
by (auto_tac (claset(), |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
75 |
simpset() addsimps [zless_iff_succ_zadd, zadd_assoc, |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
76 |
int_of_add RS sym])); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
77 |
by (res_inst_tac [("x","0")] bexI 3); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
78 |
by (TRYALL (dtac sym)); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
79 |
by (cut_inst_tac [("m","m")] int_succ_int_1 1); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
80 |
by (cut_inst_tac [("m","n")] int_succ_int_1 1); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
81 |
by (Asm_full_simp_tac 1); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
82 |
by (eres_inst_tac [("n","x")] natE 1); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
83 |
by Auto_tac; |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
84 |
by (res_inst_tac [("x","succ(x)")] bexI 1); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
85 |
by Auto_tac; |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
86 |
qed "zless_add_succ_iff"; |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
87 |
|
11321 | 88 |
Goal "z \\<in> int ==> (w $+ $# succ(m) $<= z) <-> (w $+ $#m $< z)"; |
9578
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
89 |
by (asm_simp_tac (simpset_of Int.thy addsimps |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
90 |
[not_zless_iff_zle RS iff_sym, zless_add_succ_iff]) 1); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
91 |
by (auto_tac (claset() addIs [zle_anti_sym] addEs [zless_asym], |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
92 |
simpset() addsimps [zless_imp_zle, not_zless_iff_zle])); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
93 |
qed "lemma"; |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
94 |
|
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
95 |
Goal "(w $+ $# succ(m) $<= z) <-> (w $+ $#m $< z)"; |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
96 |
by (cut_inst_tac [("z","intify(z)")] lemma 1); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
97 |
by Auto_tac; |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
98 |
qed "zadd_succ_zle_iff"; |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
99 |
|
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
100 |
(** Inequality reasoning **) |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
101 |
|
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
102 |
Goal "(w $< z $+ #1) <-> (w$<=z)"; |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
103 |
by (subgoal_tac "#1 = $# 1" 1); |
9648
35d761c7d934
better rules for cancellation of common factors across comparisons
paulson
parents:
9578
diff
changeset
|
104 |
by (asm_simp_tac (simpset_of Int.thy |
35d761c7d934
better rules for cancellation of common factors across comparisons
paulson
parents:
9578
diff
changeset
|
105 |
addsimps [zless_add_succ_iff, zle_def]) 1); |
9578
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
106 |
by Auto_tac; |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
107 |
qed "zless_add1_iff_zle"; |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
108 |
|
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
109 |
Goal "(w $+ #1 $<= z) <-> (w $< z)"; |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
110 |
by (subgoal_tac "#1 = $# 1" 1); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
111 |
by (asm_simp_tac (simpset_of Int.thy addsimps [zadd_succ_zle_iff]) 1); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
112 |
by Auto_tac; |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
113 |
qed "add1_zle_iff"; |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
114 |
|
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
115 |
Goal "(#1 $+ w $<= z) <-> (w $< z)"; |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
116 |
by (stac zadd_commute 1); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
117 |
by (rtac add1_zle_iff 1); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
118 |
qed "add1_left_zle_iff"; |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
119 |
|
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
120 |
|
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
121 |
(*** Monotonicity of Multiplication ***) |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
122 |
|
11321 | 123 |
Goal "k \\<in> nat ==> i $<= j ==> i $* $#k $<= j $* $#k"; |
9578
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
124 |
by (induct_tac "k" 1); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
125 |
by (stac int_succ_int_1 2); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
126 |
by (ALLGOALS |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
127 |
(asm_simp_tac (simpset() addsimps [zadd_zmult_distrib2, zadd_zle_mono]))); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
128 |
val lemma = result(); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
129 |
|
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
130 |
Goal "[| i $<= j; #0 $<= k |] ==> i$*k $<= j$*k"; |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
131 |
by (subgoal_tac "i $* intify(k) $<= j $* intify(k)" 1); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
132 |
by (Full_simp_tac 1); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
133 |
by (res_inst_tac [("b", "intify(k)")] (not_zneg_mag RS subst) 1); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
134 |
by (rtac lemma 3); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
135 |
by Auto_tac; |
9883 | 136 |
by (asm_full_simp_tac (simpset() addsimps [znegative_iff_zless_0, |
137 |
not_zless_iff_zle RS iff_sym]) 1); |
|
9578
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
138 |
qed "zmult_zle_mono1"; |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
139 |
|
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
140 |
Goal "[| i $<= j; k $<= #0 |] ==> j$*k $<= i$*k"; |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
141 |
by (rtac (zminus_zle_zminus RS iffD1) 1); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
142 |
by (asm_simp_tac (simpset() delsimps [zmult_zminus_right] |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
143 |
addsimps [zmult_zminus_right RS sym, |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
144 |
zmult_zle_mono1, zle_zminus]) 1); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
145 |
qed "zmult_zle_mono1_neg"; |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
146 |
|
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
147 |
Goal "[| i $<= j; #0 $<= k |] ==> k$*i $<= k$*j"; |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
148 |
by (dtac zmult_zle_mono1 1); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
149 |
by (ALLGOALS (asm_full_simp_tac (simpset() addsimps [zmult_commute]))); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
150 |
qed "zmult_zle_mono2"; |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
151 |
|
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
152 |
Goal "[| i $<= j; k $<= #0 |] ==> k$*j $<= k$*i"; |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
153 |
by (dtac zmult_zle_mono1_neg 1); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
154 |
by (ALLGOALS (asm_full_simp_tac (simpset() addsimps [zmult_commute]))); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
155 |
qed "zmult_zle_mono2_neg"; |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
156 |
|
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
157 |
(* $<= monotonicity, BOTH arguments*) |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
158 |
Goal "[| i $<= j; k $<= l; #0 $<= j; #0 $<= k |] ==> i$*k $<= j$*l"; |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
159 |
by (etac (zmult_zle_mono1 RS zle_trans) 1); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
160 |
by (assume_tac 1); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
161 |
by (etac zmult_zle_mono2 1); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
162 |
by (assume_tac 1); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
163 |
qed "zmult_zle_mono"; |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
164 |
|
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
165 |
|
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
166 |
(** strict, in 1st argument; proof is by induction on k>0 **) |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
167 |
|
11321 | 168 |
Goal "[| i$<j; k \\<in> nat |] ==> 0<k --> $#k $* i $< $#k $* j"; |
9578
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
169 |
by (induct_tac "k" 1); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
170 |
by (stac int_succ_int_1 2); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
171 |
by (etac natE 2); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
172 |
by (ALLGOALS (asm_full_simp_tac |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
173 |
(simpset() addsimps [zadd_zmult_distrib, zadd_zless_mono, |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
174 |
zle_def]))); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
175 |
by (ftac nat_0_le 1); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
176 |
by (mp_tac 1); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
177 |
by (subgoal_tac "i $+ (i $+ $# xa $* i) $< j $+ (j $+ $# xa $* j)" 1); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
178 |
by (Full_simp_tac 1); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
179 |
by (rtac zadd_zless_mono 1); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
180 |
by (ALLGOALS (asm_simp_tac (simpset() addsimps [zle_def]))); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
181 |
val lemma = result() RS mp; |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
182 |
|
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
183 |
Goal "[| i$<j; #0 $< k |] ==> k$*i $< k$*j"; |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
184 |
by (subgoal_tac "intify(k) $* i $< intify(k) $* j" 1); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
185 |
by (Full_simp_tac 1); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
186 |
by (res_inst_tac [("b", "intify(k)")] (not_zneg_mag RS subst) 1); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
187 |
by (rtac lemma 3); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
188 |
by Auto_tac; |
9883 | 189 |
by (asm_full_simp_tac (simpset() addsimps [znegative_iff_zless_0]) 1); |
190 |
by (dtac zless_trans 1 THEN assume_tac 1); |
|
9578
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
191 |
by (auto_tac (claset(), simpset() addsimps [zero_lt_zmagnitude])); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
192 |
qed "zmult_zless_mono2"; |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
193 |
|
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
194 |
Goal "[| i$<j; #0 $< k |] ==> i$*k $< j$*k"; |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
195 |
by (dtac zmult_zless_mono2 1); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
196 |
by (ALLGOALS (asm_full_simp_tac (simpset() addsimps [zmult_commute]))); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
197 |
qed "zmult_zless_mono1"; |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
198 |
|
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
199 |
(* < monotonicity, BOTH arguments*) |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
200 |
Goal "[| i $< j; k $< l; #0 $< j; #0 $< k |] ==> i$*k $< j$*l"; |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
201 |
by (etac (zmult_zless_mono1 RS zless_trans) 1); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
202 |
by (assume_tac 1); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
203 |
by (etac zmult_zless_mono2 1); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
204 |
by (assume_tac 1); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
205 |
qed "zmult_zless_mono"; |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
206 |
|
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
207 |
Goal "[| i $< j; k $< #0 |] ==> j$*k $< i$*k"; |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
208 |
by (rtac (zminus_zless_zminus RS iffD1) 1); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
209 |
by (asm_simp_tac (simpset() delsimps [zmult_zminus_right] |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
210 |
addsimps [zmult_zminus_right RS sym, |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
211 |
zmult_zless_mono1, zless_zminus]) 1); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
212 |
qed "zmult_zless_mono1_neg"; |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
213 |
|
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
214 |
Goal "[| i $< j; k $< #0 |] ==> k$*j $< k$*i"; |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
215 |
by (rtac (zminus_zless_zminus RS iffD1) 1); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
216 |
by (asm_simp_tac (simpset() delsimps [zmult_zminus] |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
217 |
addsimps [zmult_zminus RS sym, |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
218 |
zmult_zless_mono2, zless_zminus]) 1); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
219 |
qed "zmult_zless_mono2_neg"; |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
220 |
|
11381 | 221 |
|
222 |
(** Products of zeroes **) |
|
223 |
||
11321 | 224 |
Goal "[| m \\<in> int; n \\<in> int |] ==> (m$*n = #0) <-> (m = #0 | n = #0)"; |
9578
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
225 |
by (case_tac "m $< #0" 1); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
226 |
by (auto_tac (claset(), |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
227 |
simpset() addsimps [not_zless_iff_zle, zle_def, neq_iff_zless])); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
228 |
by (REPEAT |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
229 |
(force_tac (claset() addDs [zmult_zless_mono1_neg, zmult_zless_mono1], |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
230 |
simpset()) 1)); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
231 |
val lemma = result(); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
232 |
|
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
233 |
Goal "(m$*n = #0) <-> (intify(m) = #0 | intify(n) = #0)"; |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
234 |
by (asm_full_simp_tac (simpset() addsimps [lemma RS iff_sym]) 1); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
235 |
qed "zmult_eq_0_iff"; |
11381 | 236 |
AddIffs [zmult_eq_0_iff]; |
9578
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
237 |
|
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
238 |
|
9648
35d761c7d934
better rules for cancellation of common factors across comparisons
paulson
parents:
9578
diff
changeset
|
239 |
(** Cancellation laws for k*m < k*n and m*k < n*k, also for <= and =, |
35d761c7d934
better rules for cancellation of common factors across comparisons
paulson
parents:
9578
diff
changeset
|
240 |
but not (yet?) for k*m < n*k. **) |
35d761c7d934
better rules for cancellation of common factors across comparisons
paulson
parents:
9578
diff
changeset
|
241 |
|
11321 | 242 |
Goal "[| k \\<in> int; m \\<in> int; n \\<in> int |] \ |
9648
35d761c7d934
better rules for cancellation of common factors across comparisons
paulson
parents:
9578
diff
changeset
|
243 |
\ ==> (m$*k $< n$*k) <-> ((#0 $< k & m$<n) | (k $< #0 & n$<m))"; |
35d761c7d934
better rules for cancellation of common factors across comparisons
paulson
parents:
9578
diff
changeset
|
244 |
by (case_tac "k = #0" 1); |
35d761c7d934
better rules for cancellation of common factors across comparisons
paulson
parents:
9578
diff
changeset
|
245 |
by (auto_tac (claset(), simpset() addsimps [neq_iff_zless, |
35d761c7d934
better rules for cancellation of common factors across comparisons
paulson
parents:
9578
diff
changeset
|
246 |
zmult_zless_mono1, zmult_zless_mono1_neg])); |
35d761c7d934
better rules for cancellation of common factors across comparisons
paulson
parents:
9578
diff
changeset
|
247 |
by (auto_tac (claset(), |
35d761c7d934
better rules for cancellation of common factors across comparisons
paulson
parents:
9578
diff
changeset
|
248 |
simpset() addsimps [not_zless_iff_zle, |
35d761c7d934
better rules for cancellation of common factors across comparisons
paulson
parents:
9578
diff
changeset
|
249 |
inst "w1" "m$*k" (not_zle_iff_zless RS iff_sym), |
35d761c7d934
better rules for cancellation of common factors across comparisons
paulson
parents:
9578
diff
changeset
|
250 |
inst "w1" "m" (not_zle_iff_zless RS iff_sym)])); |
35d761c7d934
better rules for cancellation of common factors across comparisons
paulson
parents:
9578
diff
changeset
|
251 |
by (ALLGOALS (etac notE)); |
35d761c7d934
better rules for cancellation of common factors across comparisons
paulson
parents:
9578
diff
changeset
|
252 |
by (auto_tac (claset(), simpset() addsimps [zless_imp_zle, zmult_zle_mono1, |
35d761c7d934
better rules for cancellation of common factors across comparisons
paulson
parents:
9578
diff
changeset
|
253 |
zmult_zle_mono1_neg])); |
9578
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
254 |
val lemma = result(); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
255 |
|
9648
35d761c7d934
better rules for cancellation of common factors across comparisons
paulson
parents:
9578
diff
changeset
|
256 |
Goal "(m$*k $< n$*k) <-> ((#0 $< k & m$<n) | (k $< #0 & n$<m))"; |
35d761c7d934
better rules for cancellation of common factors across comparisons
paulson
parents:
9578
diff
changeset
|
257 |
by (cut_inst_tac [("k","intify(k)"),("m","intify(m)"),("n","intify(n)")] |
35d761c7d934
better rules for cancellation of common factors across comparisons
paulson
parents:
9578
diff
changeset
|
258 |
lemma 1); |
9578
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
259 |
by Auto_tac; |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
260 |
qed "zmult_zless_cancel2"; |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
261 |
|
9648
35d761c7d934
better rules for cancellation of common factors across comparisons
paulson
parents:
9578
diff
changeset
|
262 |
Goal "(k$*m $< k$*n) <-> ((#0 $< k & m$<n) | (k $< #0 & n$<m))"; |
35d761c7d934
better rules for cancellation of common factors across comparisons
paulson
parents:
9578
diff
changeset
|
263 |
by (simp_tac (simpset() addsimps [inst "z" "k" zmult_commute, |
35d761c7d934
better rules for cancellation of common factors across comparisons
paulson
parents:
9578
diff
changeset
|
264 |
zmult_zless_cancel2]) 1); |
9578
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
265 |
qed "zmult_zless_cancel1"; |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
266 |
|
9648
35d761c7d934
better rules for cancellation of common factors across comparisons
paulson
parents:
9578
diff
changeset
|
267 |
Goal "(m$*k $<= n$*k) <-> ((#0 $< k --> m$<=n) & (k $< #0 --> n$<=m))"; |
35d761c7d934
better rules for cancellation of common factors across comparisons
paulson
parents:
9578
diff
changeset
|
268 |
by (simp_tac (simpset() addsimps [not_zless_iff_zle RS iff_sym, |
35d761c7d934
better rules for cancellation of common factors across comparisons
paulson
parents:
9578
diff
changeset
|
269 |
zmult_zless_cancel2]) 1); |
9578
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
270 |
by Auto_tac; |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
271 |
qed "zmult_zle_cancel2"; |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
272 |
|
9648
35d761c7d934
better rules for cancellation of common factors across comparisons
paulson
parents:
9578
diff
changeset
|
273 |
Goal "(k$*m $<= k$*n) <-> ((#0 $< k --> m$<=n) & (k $< #0 --> n$<=m))"; |
35d761c7d934
better rules for cancellation of common factors across comparisons
paulson
parents:
9578
diff
changeset
|
274 |
by (simp_tac (simpset() addsimps [not_zless_iff_zle RS iff_sym, |
35d761c7d934
better rules for cancellation of common factors across comparisons
paulson
parents:
9578
diff
changeset
|
275 |
zmult_zless_cancel1]) 1); |
35d761c7d934
better rules for cancellation of common factors across comparisons
paulson
parents:
9578
diff
changeset
|
276 |
by Auto_tac; |
9578
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
277 |
qed "zmult_zle_cancel1"; |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
278 |
|
11321 | 279 |
Goal "[| m \\<in> int; n \\<in> int |] ==> m=n <-> (m $<= n & n $<= m)"; |
9648
35d761c7d934
better rules for cancellation of common factors across comparisons
paulson
parents:
9578
diff
changeset
|
280 |
by (blast_tac (claset() addIs [zle_refl,zle_anti_sym]) 1); |
35d761c7d934
better rules for cancellation of common factors across comparisons
paulson
parents:
9578
diff
changeset
|
281 |
qed "int_eq_iff_zle"; |
9578
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
282 |
|
11321 | 283 |
Goal "[| k \\<in> int; m \\<in> int; n \\<in> int |] ==> (m$*k = n$*k) <-> (k=#0 | m=n)"; |
9648
35d761c7d934
better rules for cancellation of common factors across comparisons
paulson
parents:
9578
diff
changeset
|
284 |
by (asm_simp_tac (simpset() addsimps [inst "m" "m$*k" int_eq_iff_zle, |
35d761c7d934
better rules for cancellation of common factors across comparisons
paulson
parents:
9578
diff
changeset
|
285 |
inst "m" "m" int_eq_iff_zle]) 1); |
35d761c7d934
better rules for cancellation of common factors across comparisons
paulson
parents:
9578
diff
changeset
|
286 |
by (auto_tac (claset(), |
35d761c7d934
better rules for cancellation of common factors across comparisons
paulson
parents:
9578
diff
changeset
|
287 |
simpset() addsimps [zmult_zle_cancel2, neq_iff_zless])); |
35d761c7d934
better rules for cancellation of common factors across comparisons
paulson
parents:
9578
diff
changeset
|
288 |
val lemma = result(); |
9578
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
289 |
|
9648
35d761c7d934
better rules for cancellation of common factors across comparisons
paulson
parents:
9578
diff
changeset
|
290 |
Goal "(m$*k = n$*k) <-> (intify(k) = #0 | intify(m) = intify(n))"; |
35d761c7d934
better rules for cancellation of common factors across comparisons
paulson
parents:
9578
diff
changeset
|
291 |
by (rtac iff_trans 1); |
35d761c7d934
better rules for cancellation of common factors across comparisons
paulson
parents:
9578
diff
changeset
|
292 |
by (rtac lemma 2); |
35d761c7d934
better rules for cancellation of common factors across comparisons
paulson
parents:
9578
diff
changeset
|
293 |
by Auto_tac; |
9578
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
294 |
qed "zmult_cancel2"; |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
295 |
|
9648
35d761c7d934
better rules for cancellation of common factors across comparisons
paulson
parents:
9578
diff
changeset
|
296 |
Goal "(k$*m = k$*n) <-> (intify(k) = #0 | intify(m) = intify(n))"; |
35d761c7d934
better rules for cancellation of common factors across comparisons
paulson
parents:
9578
diff
changeset
|
297 |
by (simp_tac (simpset() addsimps [inst "z" "k" zmult_commute, |
35d761c7d934
better rules for cancellation of common factors across comparisons
paulson
parents:
9578
diff
changeset
|
298 |
zmult_cancel2]) 1); |
9578
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
299 |
qed "zmult_cancel1"; |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
300 |
Addsimps [zmult_cancel1, zmult_cancel2]; |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
301 |
|
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
302 |
|
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
303 |
(*** Uniqueness and monotonicity of quotients and remainders ***) |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
304 |
|
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
305 |
|
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
306 |
Goal "[| b$*q' $+ r' $<= b$*q $+ r; #0 $<= r'; #0 $< b; r $< b |] \ |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
307 |
\ ==> q' $<= q"; |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
308 |
by (subgoal_tac "r' $+ b $* (q'$-q) $<= r" 1); |
9648
35d761c7d934
better rules for cancellation of common factors across comparisons
paulson
parents:
9578
diff
changeset
|
309 |
by (full_simp_tac |
35d761c7d934
better rules for cancellation of common factors across comparisons
paulson
parents:
9578
diff
changeset
|
310 |
(simpset() addsimps [zdiff_zmult_distrib2]@zadd_ac@zcompare_rls) 2); |
9578
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
311 |
by (subgoal_tac "#0 $< b $* (#1 $+ q $- q')" 1); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
312 |
by (etac zle_zless_trans 2); |
9648
35d761c7d934
better rules for cancellation of common factors across comparisons
paulson
parents:
9578
diff
changeset
|
313 |
by (full_simp_tac |
35d761c7d934
better rules for cancellation of common factors across comparisons
paulson
parents:
9578
diff
changeset
|
314 |
(simpset() addsimps [zdiff_zmult_distrib2, |
35d761c7d934
better rules for cancellation of common factors across comparisons
paulson
parents:
9578
diff
changeset
|
315 |
zadd_zmult_distrib2]@zadd_ac@zcompare_rls) 2); |
9578
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
316 |
by (etac zle_zless_trans 2); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
317 |
by (Asm_simp_tac 2); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
318 |
by (subgoal_tac "b $* q' $< b $* (#1 $+ q)" 1); |
9648
35d761c7d934
better rules for cancellation of common factors across comparisons
paulson
parents:
9578
diff
changeset
|
319 |
by (full_simp_tac |
35d761c7d934
better rules for cancellation of common factors across comparisons
paulson
parents:
9578
diff
changeset
|
320 |
(simpset() addsimps [zdiff_zmult_distrib2, |
35d761c7d934
better rules for cancellation of common factors across comparisons
paulson
parents:
9578
diff
changeset
|
321 |
zadd_zmult_distrib2]@zadd_ac@zcompare_rls) 2); |
35d761c7d934
better rules for cancellation of common factors across comparisons
paulson
parents:
9578
diff
changeset
|
322 |
by (auto_tac (claset() addEs [zless_asym], |
35d761c7d934
better rules for cancellation of common factors across comparisons
paulson
parents:
9578
diff
changeset
|
323 |
simpset() addsimps [zmult_zless_cancel1, zless_add1_iff_zle]@ |
35d761c7d934
better rules for cancellation of common factors across comparisons
paulson
parents:
9578
diff
changeset
|
324 |
zadd_ac@zcompare_rls)); |
9578
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
325 |
qed "unique_quotient_lemma"; |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
326 |
|
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
327 |
Goal "[| b$*q' $+ r' $<= b$*q $+ r; r $<= #0; b $< #0; b $< r' |] \ |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
328 |
\ ==> q $<= q'"; |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
329 |
by (res_inst_tac [("b", "$-b"), ("r", "$-r'"), ("r'", "$-r")] |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
330 |
unique_quotient_lemma 1); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
331 |
by (auto_tac (claset(), |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
332 |
simpset() delsimps [zminus_zadd_distrib] |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
333 |
addsimps [zminus_zadd_distrib RS sym, |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
334 |
zle_zminus, zless_zminus])); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
335 |
qed "unique_quotient_lemma_neg"; |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
336 |
|
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
337 |
|
11321 | 338 |
Goal "[| quorem (<a,b>, <q,r>); quorem (<a,b>, <q',r'>); b \\<in> int; b ~= #0; \ |
339 |
\ q \\<in> int; q' \\<in> int |] ==> q = q'"; |
|
9578
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
340 |
by (asm_full_simp_tac |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
341 |
(simpset() addsimps split_ifs@ |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
342 |
[quorem_def, neq_iff_zless]) 1); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
343 |
by Safe_tac; |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
344 |
by (ALLGOALS Asm_full_simp_tac); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
345 |
by (REPEAT |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
346 |
(blast_tac (claset() addIs [zle_anti_sym] |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
347 |
addDs [zle_eq_refl RS unique_quotient_lemma, |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
348 |
zle_eq_refl RS unique_quotient_lemma_neg, |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
349 |
sym]) 1)); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
350 |
qed "unique_quotient"; |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
351 |
|
11321 | 352 |
Goal "[| quorem (<a,b>, <q,r>); quorem (<a,b>, <q',r'>); b \\<in> int; b ~= #0; \ |
353 |
\ q \\<in> int; q' \\<in> int; \ |
|
354 |
\ r \\<in> int; r' \\<in> int |] ==> r = r'"; |
|
9578
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
355 |
by (subgoal_tac "q = q'" 1); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
356 |
by (blast_tac (claset() addIs [unique_quotient]) 2); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
357 |
by (asm_full_simp_tac (simpset() addsimps [quorem_def]) 1); |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
358 |
by Auto_tac; |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
359 |
qed "unique_remainder"; |
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
360 |
|
ab26d6c8ebfe
new theory Integ/IntDiv and many more monotonicity laws, etc., for the integers
paulson
parents:
diff
changeset
|
361 |
|
9955 | 362 |
(*** Correctness of posDivAlg, the division algorithm for a>=0 and b>0 ***) |
363 |
||
11871
0493188cff42
deleted the redundant first argument of adjust(a,b)
paulson
parents:
11381
diff
changeset
|
364 |
Goal "adjust(b, <q,r>) = (let diff = r$-b in \ |
9955 | 365 |
\ if #0 $<= diff then <#2$*q $+ #1,diff> \ |
11871
0493188cff42
deleted the redundant first argument of adjust(a,b)
paulson
parents:
11381
diff
changeset
|
366 |
\ else <#2$*q,r>)"; |
9955 | 367 |
by (simp_tac (simpset() addsimps [Let_def,adjust_def]) 1); |
368 |
qed "adjust_eq"; |
|
369 |
Addsimps [adjust_eq]; |
|
370 |
||
371 |
||
10635 | 372 |
Goal "[| #0 $< b; \\<not> a $< b |] \ |
373 |
\ ==> nat_of(a $- #2 $\\<times> b $+ #1) < nat_of(a $- b $+ #1)"; |
|
9955 | 374 |
by (simp_tac (simpset() addsimps [zless_nat_conj]) 1); |
375 |
by (asm_full_simp_tac (simpset() addsimps [not_zless_iff_zle, |
|
376 |
zless_add1_iff_zle]@zcompare_rls) 1); |
|
377 |
qed "posDivAlg_termination"; |
|
378 |
||
11321 | 379 |
val posDivAlg_unfold = wf_measure RS (posDivAlg_def RS def_wfrec); |
9955 | 380 |
|
11321 | 381 |
Goal "[| #0 $< b; a \\<in> int; b \\<in> int |] ==> \ |
9955 | 382 |
\ posDivAlg(<a,b>) = \ |
11871
0493188cff42
deleted the redundant first argument of adjust(a,b)
paulson
parents:
11381
diff
changeset
|
383 |
\ (if a$<b then <#0,a> else adjust(b, posDivAlg (<a, #2$*b>)))"; |
11321 | 384 |
by (rtac (posDivAlg_unfold RS trans) 1); |
9955 | 385 |
by (asm_simp_tac (simpset() addsimps [not_zless_iff_zle RS iff_sym]) 1); |
386 |
by (asm_simp_tac (simpset() addsimps [vimage_iff, posDivAlg_termination]) 1); |
|
387 |
qed "posDivAlg_eqn"; |
|
388 |
||
389 |
val [prem] = |
|
11321 | 390 |
Goal "[| !!a b. [| a \\<in> int; b \\<in> int; \ |
9955 | 391 |
\ ~ (a $< b | b $<= #0) --> P(<a, #2 $* b>) |] \ |
392 |
\ ==> P(<a,b>) |] \ |
|
11321 | 393 |
\ ==> <u,v> \\<in> int*int --> P(<u,v>)"; |
9955 | 394 |
by (res_inst_tac [("a","<u,v>")] wf_induct 1); |
395 |
by (res_inst_tac [("A","int*int"), ("f","%<a,b>.nat_of (a $- b $+ #1)")] |
|
396 |
wf_measure 1); |
|
397 |
by (Clarify_tac 1); |
|
398 |
by (rtac prem 1); |
|
399 |
by (dres_inst_tac [("x","<xa, #2 $\\<times> y>")] spec 3); |
|
400 |
by Auto_tac; |
|
401 |
by (asm_full_simp_tac (simpset() addsimps [not_zle_iff_zless, |
|
402 |
posDivAlg_termination]) 1); |
|
403 |
val lemma = result() RS mp; |
|
404 |
||
405 |
||
406 |
val prems = |
|
11321 | 407 |
Goal "[| u \\<in> int; v \\<in> int; \ |
408 |
\ !!a b. [| a \\<in> int; b \\<in> int; ~ (a $< b | b $<= #0) --> P(a, #2 $* b) |] \ |
|
9955 | 409 |
\ ==> P(a,b) |] \ |
410 |
\ ==> P(u,v)"; |
|
411 |
by (subgoal_tac "(%<x,y>. P(x,y))(<u,v>)" 1); |
|
412 |
by (Asm_full_simp_tac 1); |
|
413 |
by (rtac lemma 1); |
|
414 |
by (simp_tac (simpset() addsimps prems) 2); |
|
415 |
by (Full_simp_tac 1); |
|
416 |
by (resolve_tac prems 1); |
|
417 |
by Auto_tac; |
|
418 |
qed "posDivAlg_induct"; |
|
419 |
||
11321 | 420 |
(*FIXME: use intify in integ_of so that we always have integ_of w \\<in> int. |
421 |
then this rewrite can work for ALL constants!!*) |
|
422 |
Goal "intify(m) = #0 <-> (m $<= #0 & #0 $<= m)"; |
|
423 |
by (simp_tac (simpset() addsimps [int_eq_iff_zle]) 1); |
|
424 |
qed "intify_eq_0_iff_zle"; |
|
425 |
||
426 |
||
427 |
(*** Some convenient biconditionals for products of signs ***) |
|
428 |
||
429 |
Goal "[| #0 $< i; #0 $< j |] ==> #0 $< i $* j"; |
|
430 |
by (dtac zmult_zless_mono1 1); |
|
431 |
by Auto_tac; |
|
432 |
qed "zmult_pos"; |
|
433 |
||
434 |
Goal "[| i $< #0; j $< #0 |] ==> #0 $< i $* j"; |
|
435 |
by (dtac zmult_zless_mono1_neg 1); |
|
436 |
by Auto_tac; |
|
437 |
qed "zmult_neg"; |
|
438 |
||
439 |
Goal "[| #0 $< i; j $< #0 |] ==> i $* j $< #0"; |
|
440 |
by (dtac zmult_zless_mono1_neg 1); |
|
441 |
by Auto_tac; |
|
442 |
qed "zmult_pos_neg"; |
|
443 |
||
444 |
(** Inequality reasoning **) |
|
445 |
||
446 |
Goal "[| x \\<in> int; y \\<in> int |] \ |
|
447 |
\ ==> (#0 $< x $* y) <-> (#0 $< x & #0 $< y | x $< #0 & y $< #0)"; |
|
448 |
by (auto_tac (claset(), |
|
449 |
simpset() addsimps [zle_def, not_zless_iff_zle, |
|
450 |
zmult_pos, zmult_neg])); |
|
451 |
by (ALLGOALS (rtac ccontr)); |
|
452 |
by (auto_tac (claset(), |
|
453 |
simpset() addsimps [zle_def, not_zless_iff_zle])); |
|
454 |
by (ALLGOALS (eres_inst_tac [("P","#0$< x$* y")] rev_mp)); |
|
455 |
by (ALLGOALS (dtac zmult_pos_neg THEN' assume_tac)); |
|
456 |
by (auto_tac (claset() addDs [zless_not_sym], |
|
457 |
simpset() addsimps [zmult_commute])); |
|
458 |
val lemma = result(); |
|
459 |
||
460 |
Goal "(#0 $< x $* y) <-> (#0 $< x & #0 $< y | x $< #0 & y $< #0)"; |
|
461 |
by (cut_inst_tac [("x","intify(x)"),("y","intify(y)")] lemma 1); |
|
462 |
by Auto_tac; |
|
463 |
qed "int_0_less_mult_iff"; |
|
464 |
||
465 |
Goal "[| x \\<in> int; y \\<in> int |] \ |
|
466 |
\ ==> (#0 $<= x $* y) <-> (#0 $<= x & #0 $<= y | x $<= #0 & y $<= #0)"; |
|
467 |
by (auto_tac (claset(), |
|
468 |
simpset() addsimps [zle_def, not_zless_iff_zle, |
|
469 |
int_0_less_mult_iff])); |
|
470 |
val lemma = result(); |
|
471 |
||
472 |
Goal "(#0 $<= x $* y) <-> ((#0 $<= x & #0 $<= y) | (x $<= #0 & y $<= #0))"; |
|
473 |
by (cut_inst_tac [("x","intify(x)"),("y","intify(y)")] lemma 1); |
|
474 |
by Auto_tac; |
|
475 |
qed "int_0_le_mult_iff"; |
|
476 |
||
477 |
Goal "(x $* y $< #0) <-> (#0 $< x & y $< #0 | x $< #0 & #0 $< y)"; |
|
478 |
by (auto_tac (claset(), |
|
479 |
simpset() addsimps [int_0_le_mult_iff, |
|
480 |
not_zle_iff_zless RS iff_sym])); |
|
481 |
by (auto_tac (claset() addDs [zless_not_sym], |
|
482 |
simpset() addsimps [not_zle_iff_zless])); |
|
483 |
qed "zmult_less_0_iff"; |
|
484 |
||
485 |
Goal "(x $* y $<= #0) <-> (#0 $<= x & y $<= #0 | x $<= #0 & #0 $<= y)"; |
|
486 |
by (auto_tac (claset() addDs [zless_not_sym], |
|
487 |
simpset() addsimps [int_0_less_mult_iff, |
|
488 |
not_zless_iff_zle RS iff_sym])); |
|
489 |
qed "zmult_le_0_iff"; |
|
490 |
||
491 |
||
492 |
(*Typechecking for posDivAlg*) |
|
493 |
Goal "[| a \\<in> int; b \\<in> int |] ==> posDivAlg(<a,b>) \\<in> int * int"; |
|
494 |
by (res_inst_tac [("u", "a"), ("v", "b")] posDivAlg_induct 1); |
|
495 |
by (TRYALL assume_tac); |
|
496 |
by (case_tac "#0 $< ba" 1); |
|
497 |
by (asm_simp_tac (simpset() addsimps [posDivAlg_eqn,adjust_def,integ_of_type] |
|
498 |
addsplits [split_if_asm]) 1); |
|
499 |
by (Clarify_tac 1); |
|
500 |
by (asm_full_simp_tac |
|
501 |
(simpset() addsimps [int_0_less_mult_iff, not_zle_iff_zless]) 1); |
|
502 |
by (asm_full_simp_tac (simpset() addsimps [not_zless_iff_zle]) 1); |
|
503 |
by (stac posDivAlg_unfold 1); |
|
504 |
by (Asm_full_simp_tac 1); |
|
505 |
qed_spec_mp "posDivAlg_type"; |
|
506 |
||
507 |
(*Correctness of posDivAlg: it computes quotients correctly*) |
|
508 |
Goal "[| a \\<in> int; b \\<in> int |] \ |
|
509 |
\ ==> #0 $<= a --> #0 $< b --> quorem (<a,b>, posDivAlg(<a,b>))"; |
|
510 |
by (res_inst_tac [("u", "a"), ("v", "b")] posDivAlg_induct 1); |
|
511 |
by Auto_tac; |
|
512 |
by (ALLGOALS (asm_full_simp_tac (simpset() addsimps [quorem_def]))); |
|
513 |
(*base case: a<b*) |
|
514 |
by (asm_full_simp_tac (simpset() addsimps [int_0_less_mult_iff]) 3); |
|
515 |
by (asm_full_simp_tac (simpset() addsimps [not_zless_iff_zle RS iff_sym]) 2); |
|
516 |
by (asm_full_simp_tac (simpset() addsimps [posDivAlg_eqn]) 1); |
|
517 |
(*main argument*) |
|
518 |
by (stac posDivAlg_eqn 1); |
|
519 |
by (ALLGOALS Asm_simp_tac); |
|
520 |
by (etac splitE 1); |
|
521 |
by (rtac posDivAlg_type 1); |
|
522 |
by (ALLGOALS (asm_full_simp_tac (simpset() addsimps [int_0_less_mult_iff]))); |
|
523 |
by (auto_tac (claset(), simpset() addsimps [zadd_zmult_distrib2, Let_def])); |
|
524 |
(*now just linear arithmetic*) |
|
525 |
by (asm_full_simp_tac |
|
526 |
(simpset() addsimps [not_zle_iff_zless, zdiff_zless_iff]) 1); |
|
527 |
qed_spec_mp "posDivAlg_correct"; |
|
528 |
||
529 |
||
530 |
(*** Correctness of negDivAlg, the division algorithm for a<0 and b>0 ***) |
|
531 |
||
532 |
Goal "[| #0 $< b; \\<not> #0 $<= a $+ b |] \ |
|
533 |
\ ==> nat_of($- a $- #2 $\\<times> b) < nat_of($- a $- b)"; |
|
534 |
by (simp_tac (simpset() addsimps [zless_nat_conj]) 1); |
|
535 |
by (asm_full_simp_tac (simpset() addsimps zcompare_rls @ |
|
536 |
[not_zle_iff_zless, zless_zdiff_iff RS iff_sym, zless_zminus]) 1); |
|
537 |
qed "negDivAlg_termination"; |
|
538 |
||
539 |
val negDivAlg_unfold = wf_measure RS (negDivAlg_def RS def_wfrec); |
|
540 |
||
541 |
Goal "[| #0 $< b; a \\<in> int; b \\<in> int |] ==> \ |
|
542 |
\ negDivAlg(<a,b>) = \ |
|
543 |
\ (if #0 $<= a$+b then <#-1,a$+b> \ |
|
11871
0493188cff42
deleted the redundant first argument of adjust(a,b)
paulson
parents:
11381
diff
changeset
|
544 |
\ else adjust(b, negDivAlg (<a, #2$*b>)))"; |
11321 | 545 |
by (rtac (negDivAlg_unfold RS trans) 1); |
546 |
by (asm_simp_tac (simpset() addsimps [not_zless_iff_zle RS iff_sym]) 1); |
|
547 |
by (asm_simp_tac (simpset() addsimps [not_zle_iff_zless, vimage_iff, |
|
548 |
negDivAlg_termination]) 1); |
|
549 |
qed "negDivAlg_eqn"; |
|
550 |
||
551 |
val [prem] = |
|
552 |
Goal "[| !!a b. [| a \\<in> int; b \\<in> int; \ |
|
553 |
\ ~ (#0 $<= a $+ b | b $<= #0) --> P(<a, #2 $* b>) |] \ |
|
554 |
\ ==> P(<a,b>) |] \ |
|
555 |
\ ==> <u,v> \\<in> int*int --> P(<u,v>)"; |
|
556 |
by (res_inst_tac [("a","<u,v>")] wf_induct 1); |
|
557 |
by (res_inst_tac [("A","int*int"), ("f","%<a,b>.nat_of ($- a $- b)")] |
|
558 |
wf_measure 1); |
|
559 |
by (Clarify_tac 1); |
|
560 |
by (rtac prem 1); |
|
561 |
by (dres_inst_tac [("x","<xa, #2 $\\<times> y>")] spec 3); |
|
562 |
by Auto_tac; |
|
563 |
by (asm_full_simp_tac (simpset() addsimps [not_zle_iff_zless, |
|
564 |
negDivAlg_termination]) 1); |
|
565 |
val lemma = result() RS mp; |
|
566 |
||
567 |
val prems = |
|
568 |
Goal "[| u \\<in> int; v \\<in> int; \ |
|
569 |
\ !!a b. [| a \\<in> int; b \\<in> int; \ |
|
570 |
\ ~ (#0 $<= a $+ b | b $<= #0) --> P(a, #2 $* b) |] \ |
|
571 |
\ ==> P(a,b) |] \ |
|
572 |
\ ==> P(u,v)"; |
|
573 |
by (subgoal_tac "(%<x,y>. P(x,y))(<u,v>)" 1); |
|
574 |
by (Asm_full_simp_tac 1); |
|
575 |
by (rtac lemma 1); |
|
576 |
by (simp_tac (simpset() addsimps prems) 2); |
|
577 |
by (Full_simp_tac 1); |
|
578 |
by (resolve_tac prems 1); |
|
579 |
by Auto_tac; |
|
580 |
qed "negDivAlg_induct"; |
|
581 |
||
582 |
||
583 |
(*Typechecking for negDivAlg*) |
|
584 |
Goal "[| a \\<in> int; b \\<in> int |] ==> negDivAlg(<a,b>) \\<in> int * int"; |
|
585 |
by (res_inst_tac [("u", "a"), ("v", "b")] negDivAlg_induct 1); |
|
586 |
by (TRYALL assume_tac); |
|
587 |
by (case_tac "#0 $< ba" 1); |
|
588 |
by (asm_simp_tac (simpset() addsimps [negDivAlg_eqn,adjust_def,integ_of_type] |
|
589 |
addsplits [split_if_asm]) 1); |
|
590 |
by (Clarify_tac 1); |
|
591 |
by (asm_full_simp_tac |
|
592 |
(simpset() addsimps [int_0_less_mult_iff, not_zle_iff_zless]) 1); |
|
593 |
by (asm_full_simp_tac (simpset() addsimps [not_zless_iff_zle]) 1); |
|
594 |
by (stac negDivAlg_unfold 1); |
|
595 |
by (Asm_full_simp_tac 1); |
|
596 |
qed "negDivAlg_type"; |
|
597 |
||
598 |
||
599 |
(*Correctness of negDivAlg: it computes quotients correctly |
|
600 |
It doesn't work if a=0 because the 0/b=0 rather than -1*) |
|
601 |
Goal "[| a \\<in> int; b \\<in> int |] \ |
|
602 |
\ ==> a $< #0 --> #0 $< b --> quorem (<a,b>, negDivAlg(<a,b>))"; |
|
603 |
by (res_inst_tac [("u", "a"), ("v", "b")] negDivAlg_induct 1); |
|
604 |
by Auto_tac; |
|
605 |
by (ALLGOALS (asm_full_simp_tac (simpset() addsimps [quorem_def]))); |
|
606 |
(*base case: 0$<=a$+b*) |
|
607 |
by (asm_full_simp_tac (simpset() addsimps [int_0_less_mult_iff]) 3); |
|
608 |
by (asm_full_simp_tac (simpset() addsimps [not_zless_iff_zle RS iff_sym]) 2); |
|
609 |
by (asm_full_simp_tac (simpset() addsimps [negDivAlg_eqn]) 1); |
|
610 |
(*main argument*) |
|
611 |
by (stac negDivAlg_eqn 1); |
|
612 |
by (ALLGOALS Asm_simp_tac); |
|
613 |
by (etac splitE 1); |
|
614 |
by (rtac negDivAlg_type 1); |
|
615 |
by (ALLGOALS (asm_full_simp_tac (simpset() addsimps [int_0_less_mult_iff]))); |
|
616 |
by (auto_tac (claset(), simpset() addsimps [zadd_zmult_distrib2, Let_def])); |
|
617 |
(*now just linear arithmetic*) |
|
618 |
by (asm_full_simp_tac |
|
619 |
(simpset() addsimps [not_zle_iff_zless, zdiff_zless_iff]) 1); |
|
620 |
qed_spec_mp "negDivAlg_correct"; |
|
621 |
||
622 |
||
623 |
(*** Existence shown by proving the division algorithm to be correct ***) |
|
624 |
||
625 |
(*the case a=0*) |
|
626 |
Goal "[|b \\<noteq> #0; b \\<in> int|] ==> quorem (<#0,b>, <#0,#0>)"; |
|
627 |
by (rotate_tac ~1 1); |
|
628 |
by (auto_tac (claset(), |
|
629 |
simpset() addsimps [quorem_def, neq_iff_zless])); |
|
630 |
qed "quorem_0"; |
|
631 |
||
632 |
Goal "posDivAlg(<a,#0>) = <#0,a>"; |
|
633 |
by (stac posDivAlg_unfold 1); |
|
634 |
by (Simp_tac 1); |
|
635 |
qed "posDivAlg_zero_divisor"; |
|
636 |
||
637 |
Goal "posDivAlg (<#0,b>) = <#0,#0>"; |
|
638 |
by (stac posDivAlg_unfold 1); |
|
639 |
by (simp_tac (simpset() addsimps [not_zle_iff_zless]) 1); |
|
640 |
qed "posDivAlg_0"; |
|
641 |
Addsimps [posDivAlg_0]; |
|
642 |
||
643 |
Goal "negDivAlg (<#-1,b>) = <#-1, b$-#1>"; |
|
644 |
by (stac negDivAlg_unfold 1); |
|
645 |
by Auto_tac; |
|
646 |
(*ALL the rest is linear arithmetic: to notice the contradiction*) |
|
647 |
by (asm_full_simp_tac (simpset() addsimps [not_zle_iff_zless]) 1); |
|
648 |
by (dtac (zminus_zless_zminus RS iffD2) 1); |
|
649 |
by (asm_full_simp_tac (simpset() addsimps [zadd_commute, zless_add1_iff_zle, |
|
650 |
zle_zminus]) 1); |
|
651 |
by (asm_full_simp_tac (simpset() addsimps [not_zle_iff_zless RS iff_sym]) 1); |
|
652 |
qed "negDivAlg_minus1"; |
|
653 |
Addsimps [negDivAlg_minus1]; |
|
654 |
||
655 |
Goalw [negateSnd_def] "negateSnd (<q,r>) = <q, $-r>"; |
|
656 |
by Auto_tac; |
|
657 |
qed "negateSnd_eq"; |
|
658 |
Addsimps [negateSnd_eq]; |
|
659 |
||
660 |
Goalw [negateSnd_def] "qr \\<in> int * int ==> negateSnd (qr) \\<in> int * int"; |
|
661 |
by Auto_tac; |
|
662 |
qed "negateSnd_type"; |
|
663 |
||
664 |
Goal "[|quorem (<$-a,$-b>, qr); a \\<in> int; b \\<in> int; qr \\<in> int * int|] \ |
|
665 |
\ ==> quorem (<a,b>, negateSnd(qr))"; |
|
666 |
by (Clarify_tac 1); |
|
667 |
by (auto_tac (claset() addEs [zless_asym], |
|
668 |
simpset() addsimps [quorem_def, zless_zminus])); |
|
669 |
(*linear arithmetic from here on*) |
|
670 |
by (ALLGOALS |
|
671 |
(asm_full_simp_tac |
|
672 |
(simpset() addsimps [inst "x" "a" zminus_equation, zminus_zless]))); |
|
673 |
by (ALLGOALS (cut_inst_tac [("z","b"),("w","#0")] zless_linear)); |
|
674 |
by Auto_tac; |
|
675 |
by (ALLGOALS (blast_tac (claset() addDs [zle_zless_trans]))); |
|
676 |
qed "quorem_neg"; |
|
677 |
||
678 |
Goal "[|b \\<noteq> #0; a \\<in> int; b \\<in> int|] ==> quorem (<a,b>, divAlg(<a,b>))"; |
|
679 |
by (rotate_tac 1 1); |
|
680 |
by (auto_tac (claset(), |
|
681 |
simpset() addsimps [quorem_0, divAlg_def])); |
|
682 |
by (REPEAT_FIRST (ares_tac [quorem_neg, posDivAlg_correct, negDivAlg_correct, |
|
683 |
posDivAlg_type, negDivAlg_type])); |
|
684 |
by (auto_tac (claset(), |
|
685 |
simpset() addsimps [quorem_def, neq_iff_zless])); |
|
686 |
(*linear arithmetic from here on*) |
|
687 |
by (auto_tac (claset(), simpset() addsimps [zle_def])); |
|
688 |
qed "divAlg_correct"; |
|
689 |
||
690 |
Goal "[|a \\<in> int; b \\<in> int|] ==> divAlg(<a,b>) \\<in> int * int"; |
|
691 |
by (auto_tac (claset(), simpset() addsimps [divAlg_def])); |
|
692 |
by (auto_tac (claset(), |
|
693 |
simpset() addsimps [posDivAlg_type, negDivAlg_type, negateSnd_type])); |
|
694 |
qed "divAlg_type"; |
|
695 |
||
696 |
||
697 |
(** intify cancellation **) |
|
698 |
||
699 |
Goal "intify(x) zdiv y = x zdiv y"; |
|
700 |
by (simp_tac (simpset() addsimps [zdiv_def]) 1); |
|
701 |
qed "zdiv_intify1"; |
|
702 |
||
703 |
Goal "x zdiv intify(y) = x zdiv y"; |
|
704 |
by (simp_tac (simpset() addsimps [zdiv_def]) 1); |
|
705 |
qed "zdiv_intify2"; |
|
706 |
Addsimps [zdiv_intify1, zdiv_intify2]; |
|
707 |
||
708 |
Goalw [zdiv_def] "z zdiv w \\<in> int"; |
|
709 |
by (blast_tac (claset() addIs [fst_type, divAlg_type]) 1); |
|
710 |
qed "zdiv_type"; |
|
711 |
AddIffs [zdiv_type]; AddTCs [zdiv_type]; |
|
712 |
||
713 |
Goal "intify(x) zmod y = x zmod y"; |
|
714 |
by (simp_tac (simpset() addsimps [zmod_def]) 1); |
|
715 |
qed "zmod_intify1"; |
|
716 |
||
717 |
Goal "x zmod intify(y) = x zmod y"; |
|
718 |
by (simp_tac (simpset() addsimps [zmod_def]) 1); |
|
719 |
qed "zmod_intify2"; |
|
720 |
Addsimps [zmod_intify1, zmod_intify2]; |
|
721 |
||
722 |
Goalw [zmod_def] "z zmod w \\<in> int"; |
|
723 |
by (rtac snd_type 1); |
|
724 |
by (blast_tac (claset() addIs [divAlg_type]) 1); |
|
725 |
qed "zmod_type"; |
|
726 |
AddIffs [zmod_type]; AddTCs [zmod_type]; |
|
727 |
||
728 |
||
729 |
(** Arbitrary definitions for division by zero. Useful to simplify |
|
730 |
certain equations **) |
|
731 |
||
732 |
Goal "a zdiv #0 = #0"; |
|
733 |
by (simp_tac |
|
734 |
(simpset() addsimps [zdiv_def, divAlg_def, posDivAlg_zero_divisor]) 1); |
|
735 |
qed "DIVISION_BY_ZERO_ZDIV"; (*NOT for adding to default simpset*) |
|
736 |
||
737 |
Goal "a zmod #0 = intify(a)"; |
|
738 |
by (simp_tac |
|
739 |
(simpset() addsimps [zmod_def, divAlg_def, posDivAlg_zero_divisor]) 1); |
|
740 |
qed "DIVISION_BY_ZERO_ZMOD"; (*NOT for adding to default simpset*) |
|
741 |
||
742 |
fun zdiv_undefined_case_tac s i = |
|
743 |
case_tac s i THEN |
|
744 |
asm_simp_tac (simpset() addsimps [DIVISION_BY_ZERO_ZDIV, |
|
745 |
DIVISION_BY_ZERO_ZMOD]) i; |
|
746 |
||
747 |
||
748 |
(** Basic laws about division and remainder **) |
|
749 |
||
750 |
Goal "[| a \\<in> int; b \\<in> int |] ==> a = b $* (a zdiv b) $+ (a zmod b)"; |
|
751 |
by (zdiv_undefined_case_tac "b = #0" 1); |
|
752 |
by (cut_inst_tac [("a","a"),("b","b")] divAlg_correct 1); |
|
753 |
by (auto_tac (claset(), |
|
754 |
simpset() addsimps [quorem_def, zdiv_def, zmod_def, split_def])); |
|
755 |
qed "raw_zmod_zdiv_equality"; |
|
756 |
||
757 |
Goal "intify(a) = b $* (a zdiv b) $+ (a zmod b)"; |
|
758 |
by (rtac trans 1); |
|
759 |
by (res_inst_tac [("b","intify(b)")] raw_zmod_zdiv_equality 1); |
|
760 |
by Auto_tac; |
|
761 |
qed "zmod_zdiv_equality"; |
|
762 |
||
763 |
Goal "#0 $< b ==> #0 $<= a zmod b & a zmod b $< b"; |
|
764 |
by (cut_inst_tac [("a","intify(a)"),("b","intify(b)")] divAlg_correct 1); |
|
765 |
by (auto_tac (claset(), |
|
766 |
simpset() addsimps [intify_eq_0_iff_zle, quorem_def, zmod_def, |
|
767 |
split_def])); |
|
768 |
by (ALLGOALS (blast_tac (claset() addDs [zle_zless_trans]))); |
|
769 |
bind_thm ("pos_mod_sign", result() RS conjunct1); |
|
770 |
bind_thm ("pos_mod_bound", result() RS conjunct2); |
|
771 |
||
772 |
Goal "b $< #0 ==> a zmod b $<= #0 & b $< a zmod b"; |
|
773 |
by (cut_inst_tac [("a","intify(a)"),("b","intify(b)")] divAlg_correct 1); |
|
774 |
by (auto_tac (claset(), |
|
775 |
simpset() addsimps [intify_eq_0_iff_zle, quorem_def, zmod_def, |
|
776 |
split_def])); |
|
777 |
by (blast_tac (claset() addDs [zle_zless_trans]) 1); |
|
778 |
by (ALLGOALS (blast_tac (claset() addDs [zless_trans]))); |
|
779 |
bind_thm ("neg_mod_sign", result() RS conjunct1); |
|
780 |
bind_thm ("neg_mod_bound", result() RS conjunct2); |
|
781 |
||
782 |
||
783 |
(** proving general properties of zdiv and zmod **) |
|
784 |
||
785 |
Goal "[|b \\<noteq> #0; a \\<in> int; b \\<in> int |] \ |
|
786 |
\ ==> quorem (<a,b>, <a zdiv b, a zmod b>)"; |
|
787 |
by (cut_inst_tac [("a","a"),("b","b")] zmod_zdiv_equality 1); |
|
788 |
by (rotate_tac 1 1); |
|
789 |
by (auto_tac |
|
790 |
(claset(), |
|
791 |
simpset() addsimps [quorem_def, neq_iff_zless, |
|
792 |
pos_mod_sign,pos_mod_bound, |
|
793 |
neg_mod_sign, neg_mod_bound])); |
|
794 |
qed "quorem_div_mod"; |
|
795 |
||
796 |
(*Surely quorem(<a,b>,<q,r>) implies a \\<in> int, but it doesn't matter*) |
|
797 |
Goal "[| quorem(<a,b>,<q,r>); b \\<noteq> #0; a \\<in> int; b \\<in> int; q \\<in> int |] \ |
|
798 |
\ ==> a zdiv b = q"; |
|
799 |
by (blast_tac (claset() addIs [quorem_div_mod RS unique_quotient]) 1); |
|
800 |
qed "quorem_div"; |
|
801 |
||
802 |
Goal "[| quorem(<a,b>,<q,r>); b \\<noteq> #0; a \\<in> int; b \\<in> int; q \\<in> int; r \\<in> int |] ==> a zmod b = r"; |
|
803 |
by (blast_tac (claset() addIs [quorem_div_mod RS unique_remainder]) 1); |
|
804 |
qed "quorem_mod"; |
|
805 |
||
806 |
Goal "[| a \\<in> int; b \\<in> int; #0 $<= a; a $< b |] ==> a zdiv b = #0"; |
|
807 |
by (rtac quorem_div 1); |
|
808 |
by (auto_tac (claset(), simpset() addsimps [quorem_def])); |
|
809 |
(*linear arithmetic*) |
|
810 |
by (ALLGOALS (blast_tac (claset() addDs [zle_zless_trans]))); |
|
811 |
qed "zdiv_pos_pos_trivial_raw"; |
|
812 |
||
813 |
Goal "[| #0 $<= a; a $< b |] ==> a zdiv b = #0"; |
|
814 |
by (cut_inst_tac [("a", "intify(a)"), ("b", "intify(b)")] |
|
815 |
zdiv_pos_pos_trivial_raw 1); |
|
816 |
by Auto_tac; |
|
817 |
qed "zdiv_pos_pos_trivial"; |
|
818 |
||
819 |
Goal "[| a \\<in> int; b \\<in> int; a $<= #0; b $< a |] ==> a zdiv b = #0"; |
|
820 |
by (res_inst_tac [("r","a")] quorem_div 1); |
|
821 |
by (auto_tac (claset(), simpset() addsimps [quorem_def])); |
|
822 |
(*linear arithmetic*) |
|
823 |
by (ALLGOALS (blast_tac (claset() addDs [zle_zless_trans, zless_trans]))); |
|
824 |
qed "zdiv_neg_neg_trivial_raw"; |
|
825 |
||
826 |
Goal "[| a $<= #0; b $< a |] ==> a zdiv b = #0"; |
|
827 |
by (cut_inst_tac [("a", "intify(a)"), ("b", "intify(b)")] |
|
828 |
zdiv_neg_neg_trivial_raw 1); |
|
829 |
by Auto_tac; |
|
830 |
qed "zdiv_neg_neg_trivial"; |
|
831 |
||
832 |
Goal "[| a$+b $<= #0; #0 $< a; #0 $< b |] ==> False"; |
|
833 |
by (dres_inst_tac [("z'","#0"), ("z","b")] zadd_zless_mono 1); |
|
834 |
by (auto_tac (claset(), simpset() addsimps [zle_def])); |
|
835 |
by (blast_tac (claset() addDs [zless_trans]) 1); |
|
836 |
qed "zadd_le_0_lemma"; |
|
837 |
||
838 |
Goal "[| a \\<in> int; b \\<in> int; #0 $< a; a$+b $<= #0 |] ==> a zdiv b = #-1"; |
|
839 |
by (res_inst_tac [("r","a $+ b ")] quorem_div 1); |
|
840 |
by (auto_tac (claset(), simpset() addsimps [quorem_def])); |
|
841 |
(*linear arithmetic*) |
|
842 |
by (ALLGOALS (blast_tac (claset() addDs [zadd_le_0_lemma, zle_zless_trans]))); |
|
843 |
qed "zdiv_pos_neg_trivial_raw"; |
|
844 |
||
845 |
Goal "[| #0 $< a; a$+b $<= #0 |] ==> a zdiv b = #-1"; |
|
846 |
by (cut_inst_tac [("a", "intify(a)"), ("b", "intify(b)")] |
|
847 |
zdiv_pos_neg_trivial_raw 1); |
|
848 |
by Auto_tac; |
|
849 |
qed "zdiv_pos_neg_trivial"; |
|
850 |
||
851 |
(*There is no zdiv_neg_pos_trivial because #0 zdiv b = #0 would supersede it*) |
|
852 |
||
853 |
||
854 |
Goal "[| a \\<in> int; b \\<in> int; #0 $<= a; a $< b |] ==> a zmod b = a"; |
|
855 |
by (res_inst_tac [("q","#0")] quorem_mod 1); |
|
856 |
by (auto_tac (claset(), simpset() addsimps [quorem_def])); |
|
857 |
(*linear arithmetic*) |
|
858 |
by (ALLGOALS (blast_tac (claset() addDs [zle_zless_trans]))); |
|
859 |
qed "zmod_pos_pos_trivial_raw"; |
|
860 |
||
861 |
Goal "[| #0 $<= a; a $< b |] ==> a zmod b = intify(a)"; |
|
862 |
by (cut_inst_tac [("a", "intify(a)"), ("b", "intify(b)")] |
|
863 |
zmod_pos_pos_trivial_raw 1); |
|
864 |
by Auto_tac; |
|
865 |
qed "zmod_pos_pos_trivial"; |
|
866 |
||
867 |
Goal "[| a \\<in> int; b \\<in> int; a $<= #0; b $< a |] ==> a zmod b = a"; |
|
868 |
by (res_inst_tac [("q","#0")] quorem_mod 1); |
|
869 |
by (auto_tac (claset(), simpset() addsimps [quorem_def])); |
|
870 |
(*linear arithmetic*) |
|
871 |
by (ALLGOALS (blast_tac (claset() addDs [zle_zless_trans, zless_trans]))); |
|
872 |
qed "zmod_neg_neg_trivial_raw"; |
|
873 |
||
874 |
Goal "[| a $<= #0; b $< a |] ==> a zmod b = intify(a)"; |
|
875 |
by (cut_inst_tac [("a", "intify(a)"), ("b", "intify(b)")] |
|
876 |
zmod_neg_neg_trivial_raw 1); |
|
877 |
by Auto_tac; |
|
878 |
qed "zmod_neg_neg_trivial"; |
|
879 |
||
880 |
Goal "[| a \\<in> int; b \\<in> int; #0 $< a; a$+b $<= #0 |] ==> a zmod b = a$+b"; |
|
881 |
by (res_inst_tac [("q","#-1")] quorem_mod 1); |
|
882 |
by (auto_tac (claset(), simpset() addsimps [quorem_def])); |
|
883 |
(*linear arithmetic*) |
|
884 |
by (ALLGOALS (blast_tac (claset() addDs [zadd_le_0_lemma, zle_zless_trans]))); |
|
885 |
qed "zmod_pos_neg_trivial_raw"; |
|
886 |
||
887 |
Goal "[| #0 $< a; a$+b $<= #0 |] ==> a zmod b = a$+b"; |
|
888 |
by (cut_inst_tac [("a", "intify(a)"), ("b", "intify(b)")] |
|
889 |
zmod_pos_neg_trivial_raw 1); |
|
890 |
by Auto_tac; |
|
891 |
qed "zmod_pos_neg_trivial"; |
|
892 |
||
893 |
(*There is no zmod_neg_pos_trivial...*) |
|
894 |
||
895 |
||
896 |
(*Simpler laws such as -a zdiv b = -(a zdiv b) FAIL*) |
|
897 |
||
898 |
Goal "[|a \\<in> int; b \\<in> int|] ==> ($-a) zdiv ($-b) = a zdiv b"; |
|
899 |
by (zdiv_undefined_case_tac "b = #0" 1); |
|
900 |
by (stac ((simplify(simpset()) (quorem_div_mod RS quorem_neg)) |
|
901 |
RS quorem_div) 1); |
|
902 |
by Auto_tac; |
|
903 |
qed "zdiv_zminus_zminus_raw"; |
|
904 |
||
905 |
Goal "($-a) zdiv ($-b) = a zdiv b"; |
|
906 |
by (cut_inst_tac [("a","intify(a)"), ("b","intify(b)")] |
|
907 |
zdiv_zminus_zminus_raw 1); |
|
908 |
by Auto_tac; |
|
909 |
qed "zdiv_zminus_zminus"; |
|
910 |
Addsimps [zdiv_zminus_zminus]; |
|
911 |
||
912 |
(*Simpler laws such as -a zmod b = -(a zmod b) FAIL*) |
|
913 |
Goal "[|a \\<in> int; b \\<in> int|] ==> ($-a) zmod ($-b) = $- (a zmod b)"; |
|
914 |
by (zdiv_undefined_case_tac "b = #0" 1); |
|
915 |
by (stac ((simplify(simpset()) (quorem_div_mod RS quorem_neg)) |
|
916 |
RS quorem_mod) 1); |
|
917 |
by Auto_tac; |
|
918 |
qed "zmod_zminus_zminus_raw"; |
|
919 |
||
920 |
Goal "($-a) zmod ($-b) = $- (a zmod b)"; |
|
921 |
by (cut_inst_tac [("a","intify(a)"), ("b","intify(b)")] |
|
922 |
zmod_zminus_zminus_raw 1); |
|
923 |
by Auto_tac; |
|
924 |
qed "zmod_zminus_zminus"; |
|
925 |
Addsimps [zmod_zminus_zminus]; |
|
926 |
||
927 |
||
928 |
(*** division of a number by itself ***) |
|
929 |
||
930 |
Goal "[| #0 $< a; a = r $+ a$*q; r $< a |] ==> #1 $<= q"; |
|
931 |
by (subgoal_tac "#0 $< a$*q" 1); |
|
932 |
by (cut_inst_tac [("w","#0"),("z","q")] add1_zle_iff 1); |
|
933 |
by (asm_full_simp_tac (simpset() addsimps [int_0_less_mult_iff]) 1); |
|
934 |
by (blast_tac (claset() addDs [zless_trans]) 1); |
|
935 |
(*linear arithmetic...*) |
|
936 |
by (dres_inst_tac [("t","%x. x $- r")] subst_context 1); |
|
937 |
by (dtac sym 1); |
|
938 |
by (asm_full_simp_tac (simpset() addsimps zcompare_rls) 1); |
|
939 |
val lemma1 = result(); |
|
940 |
||
941 |
Goal "[| #0 $< a; a = r $+ a$*q; #0 $<= r |] ==> q $<= #1"; |
|
942 |
by (subgoal_tac "#0 $<= a$*(#1$-q)" 1); |
|
943 |
by (asm_simp_tac (simpset() addsimps [zdiff_zmult_distrib2]) 2); |
|
944 |
by (dres_inst_tac [("t","%x. x $- a $* q")] subst_context 2); |
|
945 |
by (asm_full_simp_tac (simpset() addsimps zcompare_rls) 2); |
|
946 |
by (asm_full_simp_tac (simpset() addsimps int_0_le_mult_iff::zcompare_rls) 1); |
|
947 |
by (blast_tac (claset() addDs [zle_zless_trans]) 1); |
|
948 |
val lemma2 = result(); |
|
949 |
||
950 |
Goal "[| quorem(<a,a>,<q,r>); a \\<in> int; q \\<in> int; a \\<noteq> #0|] ==> q = #1"; |
|
951 |
by (asm_full_simp_tac |
|
952 |
(simpset() addsimps split_ifs@[quorem_def, neq_iff_zless]) 1); |
|
953 |
by (rtac zle_anti_sym 1); |
|
954 |
by Safe_tac; |
|
955 |
by Auto_tac; |
|
956 |
by (blast_tac (claset() addDs [zless_trans]) 4); |
|
957 |
by (blast_tac (claset() addDs [zless_trans]) 1); |
|
958 |
by (res_inst_tac [("a", "$-a"),("r", "$-r")] lemma1 3); |
|
959 |
by (res_inst_tac [("a", "$-a"),("r", "$-r")] lemma2 1); |
|
960 |
by (rtac (zminus_equation RS iffD1) 6); |
|
961 |
by (rtac (zminus_equation RS iffD1) 2); |
|
962 |
by (REPEAT (force_tac (claset() addIs [lemma1,lemma2], |
|
963 |
simpset() addsimps [zadd_commute, zmult_zminus]) 1)); |
|
964 |
qed "self_quotient"; |
|
965 |
||
966 |
Goal "[|quorem(<a,a>,<q,r>); a \\<in> int; q \\<in> int; r \\<in> int; a \\<noteq> #0|] ==> r = #0"; |
|
967 |
by (ftac self_quotient 1); |
|
968 |
by (auto_tac (claset(), simpset() addsimps [quorem_def])); |
|
969 |
qed "self_remainder"; |
|
970 |
||
971 |
Goal "[|a \\<noteq> #0; a \\<in> int|] ==> a zdiv a = #1"; |
|
972 |
by (blast_tac (claset() addIs [quorem_div_mod RS self_quotient]) 1); |
|
973 |
qed "zdiv_self_raw"; |
|
974 |
||
975 |
Goal "intify(a) \\<noteq> #0 ==> a zdiv a = #1"; |
|
976 |
by (dtac zdiv_self_raw 1); |
|
977 |
by Auto_tac; |
|
978 |
qed "zdiv_self"; |
|
979 |
Addsimps [zdiv_self]; |
|
980 |
||
981 |
(*Here we have 0 zmod 0 = 0, also assumed by Knuth (who puts m zmod 0 = 0) *) |
|
982 |
Goal "a \\<in> int ==> a zmod a = #0"; |
|
983 |
by (zdiv_undefined_case_tac "a = #0" 1); |
|
984 |
by (blast_tac (claset() addIs [quorem_div_mod RS self_remainder]) 1); |
|
985 |
qed "zmod_self_raw"; |
|
986 |
||
987 |
Goal "a zmod a = #0"; |
|
988 |
by (cut_inst_tac [("a","intify(a)")] zmod_self_raw 1); |
|
989 |
by Auto_tac; |
|
990 |
qed "zmod_self"; |
|
991 |
Addsimps [zmod_self]; |
|
992 |
||
993 |
||
994 |
(*** Computation of division and remainder ***) |
|
995 |
||
996 |
Goal "#0 zdiv b = #0"; |
|
997 |
by (simp_tac (simpset() addsimps [zdiv_def, divAlg_def]) 1); |
|
998 |
qed "zdiv_zero"; |
|
999 |
||
1000 |
Goal "#0 $< b ==> #-1 zdiv b = #-1"; |
|
1001 |
by (asm_simp_tac (simpset() addsimps [zdiv_def, divAlg_def]) 1); |
|
1002 |
qed "zdiv_eq_minus1"; |
|
1003 |
||
1004 |
Goal "#0 zmod b = #0"; |
|
1005 |
by (simp_tac (simpset() addsimps [zmod_def, divAlg_def]) 1); |
|
1006 |
qed "zmod_zero"; |
|
1007 |
||
1008 |
Addsimps [zdiv_zero, zmod_zero]; |
|
1009 |
||
1010 |
Goal "#0 $< b ==> #-1 zdiv b = #-1"; |
|
1011 |
by (asm_simp_tac (simpset() addsimps [zdiv_def, divAlg_def]) 1); |
|
1012 |
qed "zdiv_minus1"; |
|
1013 |
||
1014 |
Goal "#0 $< b ==> #-1 zmod b = b $- #1"; |
|
1015 |
by (asm_simp_tac (simpset() addsimps [zmod_def, divAlg_def]) 1); |
|
1016 |
qed "zmod_minus1"; |
|
1017 |
||
1018 |
(** a positive, b positive **) |
|
1019 |
||
1020 |
Goal "[| #0 $< a; #0 $<= b |] \ |
|
1021 |
\ ==> a zdiv b = fst (posDivAlg(<intify(a), intify(b)>))"; |
|
1022 |
by (asm_simp_tac (simpset() addsimps [zdiv_def, divAlg_def]) 1); |
|
1023 |
by (auto_tac (claset(), simpset() addsimps [zle_def])); |
|
1024 |
qed "zdiv_pos_pos"; |
|
1025 |
||
1026 |
Goal "[| #0 $< a; #0 $<= b |] \ |
|
1027 |
\ ==> a zmod b = snd (posDivAlg(<intify(a), intify(b)>))"; |
|
1028 |
by (asm_simp_tac (simpset() addsimps [zmod_def, divAlg_def]) 1); |
|
1029 |
by (auto_tac (claset(), simpset() addsimps [zle_def])); |
|
1030 |
qed "zmod_pos_pos"; |
|
1031 |
||
1032 |
(** a negative, b positive **) |
|
1033 |
||
1034 |
Goal "[| a $< #0; #0 $< b |] \ |
|
1035 |
\ ==> a zdiv b = fst (negDivAlg(<intify(a), intify(b)>))"; |
|
1036 |
by (asm_simp_tac (simpset() addsimps [zdiv_def, divAlg_def]) 1); |
|
1037 |
by (blast_tac (claset() addDs [zle_zless_trans]) 1); |
|
1038 |
qed "zdiv_neg_pos"; |
|
1039 |
||
1040 |
Goal "[| a $< #0; #0 $< b |] \ |
|
1041 |
\ ==> a zmod b = snd (negDivAlg(<intify(a), intify(b)>))"; |
|
1042 |
by (asm_simp_tac (simpset() addsimps [zmod_def, divAlg_def]) 1); |
|
1043 |
by (blast_tac (claset() addDs [zle_zless_trans]) 1); |
|
1044 |
qed "zmod_neg_pos"; |
|
1045 |
||
1046 |
(** a positive, b negative **) |
|
1047 |
||
1048 |
Goal "[| #0 $< a; b $< #0 |] \ |
|
1049 |
\ ==> a zdiv b = fst (negateSnd(negDivAlg (<$-a, $-b>)))"; |
|
1050 |
by (asm_simp_tac |
|
1051 |
(simpset() addsimps [zdiv_def, divAlg_def, intify_eq_0_iff_zle]) 1); |
|
1052 |
by Auto_tac; |
|
1053 |
by (REPEAT (blast_tac (claset() addDs [zle_zless_trans]) 1)); |
|
1054 |
by (blast_tac (claset() addDs [zless_trans]) 1); |
|
1055 |
by (blast_tac (claset() addIs [zless_imp_zle]) 1); |
|
1056 |
qed "zdiv_pos_neg"; |
|
1057 |
||
1058 |
Goal "[| #0 $< a; b $< #0 |] \ |
|
1059 |
\ ==> a zmod b = snd (negateSnd(negDivAlg (<$-a, $-b>)))"; |
|
1060 |
by (asm_simp_tac |
|
1061 |
(simpset() addsimps [zmod_def, divAlg_def, intify_eq_0_iff_zle]) 1); |
|
1062 |
by Auto_tac; |
|
1063 |
by (REPEAT (blast_tac (claset() addDs [zle_zless_trans]) 1)); |
|
1064 |
by (blast_tac (claset() addDs [zless_trans]) 1); |
|
1065 |
by (blast_tac (claset() addIs [zless_imp_zle]) 1); |
|
1066 |
qed "zmod_pos_neg"; |
|
1067 |
||
1068 |
(** a negative, b negative **) |
|
1069 |
||
1070 |
Goal "[| a $< #0; b $<= #0 |] \ |
|
1071 |
\ ==> a zdiv b = fst (negateSnd(posDivAlg(<$-a, $-b>)))"; |
|
1072 |
by (asm_simp_tac (simpset() addsimps [zdiv_def, divAlg_def]) 1); |
|
1073 |
by Auto_tac; |
|
1074 |
by (REPEAT (blast_tac (claset() addSDs [zle_zless_trans]) 1)); |
|
1075 |
qed "zdiv_neg_neg"; |
|
1076 |
||
1077 |
Goal "[| a $< #0; b $<= #0 |] \ |
|
1078 |
\ ==> a zmod b = snd (negateSnd(posDivAlg(<$-a, $-b>)))"; |
|
1079 |
by (asm_simp_tac (simpset() addsimps [zmod_def, divAlg_def]) 1); |
|
1080 |
by Auto_tac; |
|
1081 |
by (REPEAT (blast_tac (claset() addSDs [zle_zless_trans]) 1)); |
|
1082 |
qed "zmod_neg_neg"; |
|
9955 | 1083 |
|
11321 | 1084 |
Addsimps (map (read_instantiate_sg (sign_of (the_context ())) |
1085 |
[("a", "integ_of (?v)"), ("b", "integ_of (?w)")]) |
|
1086 |
[zdiv_pos_pos, zdiv_neg_pos, zdiv_pos_neg, zdiv_neg_neg, |
|
1087 |
zmod_pos_pos, zmod_neg_pos, zmod_pos_neg, zmod_neg_neg, |
|
1088 |
posDivAlg_eqn, negDivAlg_eqn]); |
|
1089 |
||
1090 |
||
1091 |
(** Special-case simplification **) |
|
1092 |
||
1093 |
Goal "a zmod #1 = #0"; |
|
1094 |
by (cut_inst_tac [("a","a"),("b","#1")] pos_mod_sign 1); |
|
1095 |
by (cut_inst_tac [("a","a"),("b","#1")] pos_mod_bound 2); |
|
1096 |
by Auto_tac; |
|
1097 |
(*arithmetic*) |
|
1098 |
by (dtac (add1_zle_iff RS iffD2) 1); |
|
1099 |
by (rtac zle_anti_sym 1); |
|
1100 |
by Auto_tac; |
|
1101 |
qed "zmod_1"; |
|
1102 |
Addsimps [zmod_1]; |
|
1103 |
||
1104 |
Goal "a zdiv #1 = intify(a)"; |
|
1105 |
by (cut_inst_tac [("a","a"),("b","#1")] zmod_zdiv_equality 1); |
|
1106 |
by Auto_tac; |
|
1107 |
qed "zdiv_1"; |
|
1108 |
Addsimps [zdiv_1]; |
|
1109 |
||
1110 |
Goal "a zmod #-1 = #0"; |
|
1111 |
by (cut_inst_tac [("a","a"),("b","#-1")] neg_mod_sign 1); |
|
1112 |
by (cut_inst_tac [("a","a"),("b","#-1")] neg_mod_bound 2); |
|
1113 |
by Auto_tac; |
|
1114 |
(*arithmetic*) |
|
1115 |
by (dtac (add1_zle_iff RS iffD2) 1); |
|
1116 |
by (rtac zle_anti_sym 1); |
|
1117 |
by Auto_tac; |
|
1118 |
qed "zmod_minus1_right"; |
|
1119 |
Addsimps [zmod_minus1_right]; |
|
1120 |
||
1121 |
Goal "a \\<in> int ==> a zdiv #-1 = $-a"; |
|
1122 |
by (cut_inst_tac [("a","a"),("b","#-1")] zmod_zdiv_equality 1); |
|
1123 |
by Auto_tac; |
|
1124 |
by (rtac (equation_zminus RS iffD2) 1); |
|
1125 |
by Auto_tac; |
|
1126 |
qed "zdiv_minus1_right_raw"; |
|
1127 |
||
1128 |
Goal "a zdiv #-1 = $-a"; |
|
1129 |
by (cut_inst_tac [("a","intify(a)")] zdiv_minus1_right_raw 1); |
|
1130 |
by Auto_tac; |
|
1131 |
qed "zdiv_minus1_right"; |
|
1132 |
Addsimps [zdiv_minus1_right]; |
|
1133 |
||
1134 |
||
1135 |
(*** Monotonicity in the first argument (divisor) ***) |
|
1136 |
||
1137 |
Goal "[| a $<= a'; #0 $< b |] ==> a zdiv b $<= a' zdiv b"; |
|
1138 |
by (cut_inst_tac [("a","a"),("b","b")] zmod_zdiv_equality 1); |
|
1139 |
by (cut_inst_tac [("a","a'"),("b","b")] zmod_zdiv_equality 1); |
|
1140 |
by (rtac unique_quotient_lemma 1); |
|
1141 |
by (etac subst 1); |
|
1142 |
by (etac subst 1); |
|
1143 |
by (ALLGOALS (asm_simp_tac (simpset() addsimps [pos_mod_sign,pos_mod_bound]))); |
|
1144 |
qed "zdiv_mono1"; |
|
1145 |
||
1146 |
Goal "[| a $<= a'; b $< #0 |] ==> a' zdiv b $<= a zdiv b"; |
|
1147 |
by (cut_inst_tac [("a","a"),("b","b")] zmod_zdiv_equality 1); |
|
1148 |
by (cut_inst_tac [("a","a'"),("b","b")] zmod_zdiv_equality 1); |
|
1149 |
by (rtac unique_quotient_lemma_neg 1); |
|
1150 |
by (etac subst 1); |
|
1151 |
by (etac subst 1); |
|
1152 |
by (ALLGOALS (asm_simp_tac (simpset() addsimps [neg_mod_sign,neg_mod_bound]))); |
|
1153 |
qed "zdiv_mono1_neg"; |
|
1154 |
||
1155 |
||
1156 |
(*** Monotonicity in the second argument (dividend) ***) |
|
1157 |
||
1158 |
Goal "[| b$*q $+ r = b'$*q' $+ r'; #0 $<= b'$*q' $+ r'; \ |
|
1159 |
\ r' $< b'; #0 $<= r; #0 $< b'; b' $<= b |] \ |
|
1160 |
\ ==> q $<= q'"; |
|
1161 |
by (subgoal_tac "#0 $<= q'" 1); |
|
1162 |
by (subgoal_tac "#0 $< b'$*(q' $+ #1)" 2); |
|
1163 |
by (asm_simp_tac (simpset() addsimps [zadd_zmult_distrib2]) 3); |
|
1164 |
by (etac zle_zless_trans 3); |
|
1165 |
by (etac zadd_zless_mono2 3); |
|
1166 |
by (asm_full_simp_tac (simpset() addsimps [int_0_less_mult_iff]) 2); |
|
1167 |
by (blast_tac (claset() addDs [zless_trans] |
|
1168 |
addIs [zless_add1_iff_zle RS iffD1]) 2); |
|
1169 |
by (subgoal_tac "b$*q $< b$*(q' $+ #1)" 1); |
|
1170 |
by (asm_full_simp_tac (simpset() addsimps [zmult_zless_cancel1]) 1); |
|
1171 |
by (force_tac (claset() addDs [zless_add1_iff_zle RS iffD1, |
|
1172 |
zless_trans, zless_zle_trans], |
|
1173 |
simpset()) 1); |
|
1174 |
by (subgoal_tac "b$*q = r' $- r $+ b'$*q'" 1); |
|
1175 |
by (asm_simp_tac (simpset() addsimps zcompare_rls) 2); |
|
1176 |
by (asm_simp_tac (simpset() addsimps [zadd_zmult_distrib2]) 1); |
|
1177 |
by (stac zadd_commute 1 THEN rtac zadd_zless_mono 1); |
|
1178 |
by (blast_tac (claset() addIs [zmult_zle_mono1]) 2); |
|
1179 |
by (subgoal_tac "r' $+ #0 $< b $+ r" 1); |
|
1180 |
by (asm_full_simp_tac (simpset() addsimps zcompare_rls) 1); |
|
1181 |
by (rtac zadd_zless_mono 1); |
|
1182 |
by Auto_tac; |
|
1183 |
by (blast_tac (claset() addDs [zless_zle_trans]) 1); |
|
1184 |
qed "zdiv_mono2_lemma"; |
|
1185 |
||
1186 |
Goal "[| #0 $<= a; #0 $< b'; b' $<= b; a \\<in> int |] \ |
|
1187 |
\ ==> a zdiv b $<= a zdiv b'"; |
|
1188 |
by (subgoal_tac "#0 $< b" 1); |
|
1189 |
by (blast_tac (claset() addDs [zless_zle_trans]) 2); |
|
1190 |
by (cut_inst_tac [("a","a"),("b","b")] zmod_zdiv_equality 1); |
|
1191 |
by (cut_inst_tac [("a","a"),("b","b'")] zmod_zdiv_equality 1); |
|
1192 |
by (rtac zdiv_mono2_lemma 1); |
|
1193 |
by (etac subst 1); |
|
1194 |
by (etac subst 1); |
|
1195 |
by (ALLGOALS |
|
1196 |
(asm_full_simp_tac (simpset() addsimps [pos_mod_sign,pos_mod_bound]))); |
|
1197 |
qed "zdiv_mono2_raw"; |
|
1198 |
||
1199 |
Goal "[| #0 $<= a; #0 $< b'; b' $<= b |] \ |
|
1200 |
\ ==> a zdiv b $<= a zdiv b'"; |
|
1201 |
by (cut_inst_tac [("a","intify(a)")] zdiv_mono2_raw 1); |
|
1202 |
by Auto_tac; |
|
1203 |
qed "zdiv_mono2"; |
|
1204 |
||
1205 |
Goal "[| b$*q $+ r = b'$*q' $+ r'; b'$*q' $+ r' $< #0; \ |
|
1206 |
\ r $< b; #0 $<= r'; #0 $< b'; b' $<= b |] \ |
|
1207 |
\ ==> q' $<= q"; |
|
1208 |
by (subgoal_tac "#0 $< b" 1); |
|
1209 |
by (blast_tac (claset() addDs [zless_zle_trans]) 2); |
|
1210 |
by (subgoal_tac "q' $< #0" 1); |
|
1211 |
by (subgoal_tac "b'$*q' $< #0" 2); |
|
1212 |
by (force_tac (claset() addIs [zle_zless_trans], simpset()) 3); |
|
1213 |
by (asm_full_simp_tac (simpset() addsimps [zmult_less_0_iff]) 2); |
|
1214 |
by (blast_tac (claset() addDs [zless_trans]) 2); |
|
1215 |
by (subgoal_tac "b$*q' $< b$*(q $+ #1)" 1); |
|
1216 |
by (asm_full_simp_tac (simpset() addsimps [zmult_zless_cancel1]) 1); |
|
1217 |
by (blast_tac (claset() addDs [zless_trans, zless_add1_iff_zle RS iffD1]) 1); |
|
1218 |
by (asm_simp_tac (simpset() addsimps [zadd_zmult_distrib2]) 1); |
|
1219 |
by (subgoal_tac "b$*q' $<= b'$*q'" 1); |
|
1220 |
by (asm_simp_tac (simpset() addsimps [zmult_zle_cancel2]) 2); |
|
1221 |
by (blast_tac (claset() addDs [zless_trans]) 2); |
|
1222 |
by (subgoal_tac "b'$*q' $+ r $< b $+ (b$*q $+ r)" 1); |
|
1223 |
by (etac ssubst 2); |
|
1224 |
by (Asm_simp_tac 2); |
|
1225 |
by (dres_inst_tac [("w'","r"),("z'","#0")] zadd_zless_mono 2); |
|
1226 |
by (assume_tac 2); |
|
1227 |
by (Asm_full_simp_tac 2); |
|
1228 |
by (full_simp_tac (simpset() addsimps [zadd_commute]) 1); |
|
1229 |
by (rtac zle_zless_trans 1); |
|
1230 |
by (assume_tac 2); |
|
1231 |
by (asm_simp_tac (simpset() addsimps [zmult_zle_cancel2]) 1); |
|
1232 |
by (blast_tac (claset() addDs [zless_trans]) 1); |
|
1233 |
qed "zdiv_mono2_neg_lemma"; |
|
1234 |
||
1235 |
Goal "[| a $< #0; #0 $< b'; b' $<= b; a \\<in> int |] \ |
|
1236 |
\ ==> a zdiv b' $<= a zdiv b"; |
|
1237 |
by (subgoal_tac "#0 $< b" 1); |
|
1238 |
by (blast_tac (claset() addDs [zless_zle_trans]) 2); |
|
1239 |
by (cut_inst_tac [("a","a"),("b","b")] zmod_zdiv_equality 1); |
|
1240 |
by (cut_inst_tac [("a","a"),("b","b'")] zmod_zdiv_equality 1); |
|
1241 |
by (rtac zdiv_mono2_neg_lemma 1); |
|
1242 |
by (etac subst 1); |
|
1243 |
by (etac subst 1); |
|
1244 |
by (ALLGOALS |
|
1245 |
(asm_full_simp_tac (simpset() addsimps [pos_mod_sign,pos_mod_bound]))); |
|
1246 |
qed "zdiv_mono2_neg_raw"; |
|
1247 |
||
1248 |
Goal "[| a $< #0; #0 $< b'; b' $<= b |] \ |
|
1249 |
\ ==> a zdiv b' $<= a zdiv b"; |
|
1250 |
by (cut_inst_tac [("a","intify(a)")] zdiv_mono2_neg_raw 1); |
|
1251 |
by Auto_tac; |
|
1252 |
qed "zdiv_mono2_neg"; |
|
1253 |
||
1254 |
||
1255 |
||
1256 |
(*** More algebraic laws for zdiv and zmod ***) |
|
1257 |
||
1258 |
(** proving (a*b) zdiv c = a $* (b zdiv c) $+ a * (b zmod c) **) |
|
1259 |
||
1260 |
Goal "[| quorem(<b,c>, <q,r>); c \\<in> int; c \\<noteq> #0 |] \ |
|
1261 |
\ ==> quorem (<a$*b, c>, <a$*q $+ (a$*r) zdiv c, (a$*r) zmod c>)"; |
|
1262 |
by (auto_tac |
|
1263 |
(claset(), |
|
1264 |
simpset() addsimps split_ifs@ |
|
1265 |
[quorem_def, neq_iff_zless, |
|
1266 |
zadd_zmult_distrib2, |
|
1267 |
pos_mod_sign,pos_mod_bound, |
|
1268 |
neg_mod_sign, neg_mod_bound])); |
|
1269 |
by (ALLGOALS (rtac raw_zmod_zdiv_equality)); |
|
1270 |
by Auto_tac; |
|
1271 |
qed "zmult1_lemma"; |
|
1272 |
||
1273 |
Goal "[|b \\<in> int; c \\<in> int|] \ |
|
1274 |
\ ==> (a$*b) zdiv c = a$*(b zdiv c) $+ a$*(b zmod c) zdiv c"; |
|
1275 |
by (zdiv_undefined_case_tac "c = #0" 1); |
|
1276 |
by (rtac (quorem_div_mod RS zmult1_lemma RS quorem_div) 1); |
|
1277 |
by Auto_tac; |
|
1278 |
qed "zdiv_zmult1_eq_raw"; |
|
1279 |
||
1280 |
Goal "(a$*b) zdiv c = a$*(b zdiv c) $+ a$*(b zmod c) zdiv c"; |
|
1281 |
by (cut_inst_tac [("b","intify(b)"), ("c","intify(c)")] zdiv_zmult1_eq_raw 1); |
|
1282 |
by Auto_tac; |
|
1283 |
qed "zdiv_zmult1_eq"; |
|
1284 |
||
1285 |
Goal "[|b \\<in> int; c \\<in> int|] ==> (a$*b) zmod c = a$*(b zmod c) zmod c"; |
|
1286 |
by (zdiv_undefined_case_tac "c = #0" 1); |
|
1287 |
by (rtac (quorem_div_mod RS zmult1_lemma RS quorem_mod) 1); |
|
1288 |
by Auto_tac; |
|
1289 |
qed "zmod_zmult1_eq_raw"; |
|
1290 |
||
1291 |
Goal "(a$*b) zmod c = a$*(b zmod c) zmod c"; |
|
1292 |
by (cut_inst_tac [("b","intify(b)"), ("c","intify(c)")] zmod_zmult1_eq_raw 1); |
|
1293 |
by Auto_tac; |
|
1294 |
qed "zmod_zmult1_eq"; |
|
1295 |
||
1296 |
Goal "(a$*b) zmod c = ((a zmod c) $* b) zmod c"; |
|
1297 |
by (rtac trans 1); |
|
1298 |
by (res_inst_tac [("b", "(b $* a) zmod c")] trans 1); |
|
1299 |
by (rtac zmod_zmult1_eq 2); |
|
1300 |
by (ALLGOALS (simp_tac (simpset() addsimps [zmult_commute]))); |
|
1301 |
qed "zmod_zmult1_eq'"; |
|
1302 |
||
1303 |
Goal "(a$*b) zmod c = ((a zmod c) $* (b zmod c)) zmod c"; |
|
1304 |
by (rtac (zmod_zmult1_eq' RS trans) 1); |
|
1305 |
by (rtac zmod_zmult1_eq 1); |
|
1306 |
qed "zmod_zmult_distrib"; |
|
1307 |
||
1308 |
Goal "intify(b) \\<noteq> #0 ==> (a$*b) zdiv b = intify(a)"; |
|
1309 |
by (asm_simp_tac (simpset() addsimps [zdiv_zmult1_eq]) 1); |
|
1310 |
qed "zdiv_zmult_self1"; |
|
1311 |
Addsimps [zdiv_zmult_self1]; |
|
1312 |
||
1313 |
Goal "intify(b) \\<noteq> #0 ==> (b$*a) zdiv b = intify(a)"; |
|
1314 |
by (stac zmult_commute 1 THEN etac zdiv_zmult_self1 1); |
|
1315 |
qed "zdiv_zmult_self2"; |
|
1316 |
Addsimps [zdiv_zmult_self2]; |
|
1317 |
||
1318 |
Goal "(a$*b) zmod b = #0"; |
|
1319 |
by (simp_tac (simpset() addsimps [zmod_zmult1_eq]) 1); |
|
1320 |
qed "zmod_zmult_self1"; |
|
1321 |
Addsimps [zmod_zmult_self1]; |
|
1322 |
||
1323 |
Goal "(b$*a) zmod b = #0"; |
|
1324 |
by (simp_tac (simpset() addsimps [zmult_commute, zmod_zmult1_eq]) 1); |
|
1325 |
qed "zmod_zmult_self2"; |
|
1326 |
Addsimps [zmod_zmult_self2]; |
|
1327 |
||
1328 |
||
1329 |
(** proving (a$+b) zdiv c = |
|
1330 |
a zdiv c $+ b zdiv c $+ ((a zmod c $+ b zmod c) zdiv c) **) |
|
1331 |
||
1332 |
Goal "[| quorem(<a,c>, <aq,ar>); quorem(<b,c>, <bq,br>); \ |
|
1333 |
\ c \\<in> int; c \\<noteq> #0 |] \ |
|
1334 |
\ ==> quorem (<a$+b, c>, <aq $+ bq $+ (ar$+br) zdiv c, (ar$+br) zmod c>)"; |
|
1335 |
by (auto_tac |
|
1336 |
(claset(), |
|
1337 |
simpset() addsimps split_ifs@ |
|
1338 |
[quorem_def, neq_iff_zless, |
|
1339 |
zadd_zmult_distrib2, |
|
1340 |
pos_mod_sign,pos_mod_bound, |
|
1341 |
neg_mod_sign, neg_mod_bound])); |
|
1342 |
by (ALLGOALS (rtac raw_zmod_zdiv_equality)); |
|
1343 |
by Auto_tac; |
|
1344 |
val zadd1_lemma = result(); |
|
1345 |
||
1346 |
(*NOT suitable for rewriting: the RHS has an instance of the LHS*) |
|
1347 |
Goal "[|a \\<in> int; b \\<in> int; c \\<in> int|] ==> \ |
|
1348 |
\ (a$+b) zdiv c = a zdiv c $+ b zdiv c $+ ((a zmod c $+ b zmod c) zdiv c)"; |
|
1349 |
by (zdiv_undefined_case_tac "c = #0" 1); |
|
1350 |
by (blast_tac (claset() addIs [[quorem_div_mod,quorem_div_mod] |
|
1351 |
MRS zadd1_lemma RS quorem_div]) 1); |
|
1352 |
qed "zdiv_zadd1_eq_raw"; |
|
1353 |
||
1354 |
Goal "(a$+b) zdiv c = a zdiv c $+ b zdiv c $+ ((a zmod c $+ b zmod c) zdiv c)"; |
|
1355 |
by (cut_inst_tac [("a","intify(a)"), ("b","intify(b)"), ("c","intify(c)")] |
|
1356 |
zdiv_zadd1_eq_raw 1); |
|
1357 |
by Auto_tac; |
|
1358 |
qed "zdiv_zadd1_eq"; |
|
1359 |
||
1360 |
Goal "[|a \\<in> int; b \\<in> int; c \\<in> int|] \ |
|
1361 |
\ ==> (a$+b) zmod c = (a zmod c $+ b zmod c) zmod c"; |
|
1362 |
by (zdiv_undefined_case_tac "c = #0" 1); |
|
1363 |
by (blast_tac (claset() addIs [[quorem_div_mod,quorem_div_mod] |
|
1364 |
MRS zadd1_lemma RS quorem_mod]) 1); |
|
1365 |
qed "zmod_zadd1_eq_raw"; |
|
1366 |
||
1367 |
Goal "(a$+b) zmod c = (a zmod c $+ b zmod c) zmod c"; |
|
1368 |
by (cut_inst_tac [("a","intify(a)"), ("b","intify(b)"), ("c","intify(c)")] |
|
1369 |
zmod_zadd1_eq_raw 1); |
|
1370 |
by Auto_tac; |
|
1371 |
qed "zmod_zadd1_eq"; |
|
1372 |
||
1373 |
Goal "[|a \\<in> int; b \\<in> int|] ==> (a zmod b) zdiv b = #0"; |
|
1374 |
by (zdiv_undefined_case_tac "b = #0" 1); |
|
1375 |
by (auto_tac (claset(), |
|
1376 |
simpset() addsimps [neq_iff_zless, |
|
1377 |
pos_mod_sign, pos_mod_bound, zdiv_pos_pos_trivial, |
|
1378 |
neg_mod_sign, neg_mod_bound, zdiv_neg_neg_trivial])); |
|
1379 |
qed "zmod_div_trivial_raw"; |
|
1380 |
||
1381 |
Goal "(a zmod b) zdiv b = #0"; |
|
1382 |
by (cut_inst_tac [("a","intify(a)"), ("b","intify(b)")] |
|
1383 |
zmod_div_trivial_raw 1); |
|
1384 |
by Auto_tac; |
|
1385 |
qed "zmod_div_trivial"; |
|
1386 |
Addsimps [zmod_div_trivial]; |
|
1387 |
||
1388 |
Goal "[|a \\<in> int; b \\<in> int|] ==> (a zmod b) zmod b = a zmod b"; |
|
1389 |
by (zdiv_undefined_case_tac "b = #0" 1); |
|
1390 |
by (auto_tac (claset(), |
|
1391 |
simpset() addsimps [neq_iff_zless, |
|
1392 |
pos_mod_sign, pos_mod_bound, zmod_pos_pos_trivial, |
|
1393 |
neg_mod_sign, neg_mod_bound, zmod_neg_neg_trivial])); |
|
1394 |
qed "zmod_mod_trivial_raw"; |
|
1395 |
||
1396 |
Goal "(a zmod b) zmod b = a zmod b"; |
|
1397 |
by (cut_inst_tac [("a","intify(a)"), ("b","intify(b)")] |
|
1398 |
zmod_mod_trivial_raw 1); |
|
1399 |
by Auto_tac; |
|
1400 |
qed "zmod_mod_trivial"; |
|
1401 |
Addsimps [zmod_mod_trivial]; |
|
1402 |
||
1403 |
Goal "(a$+b) zmod c = ((a zmod c) $+ b) zmod c"; |
|
1404 |
by (rtac (trans RS sym) 1); |
|
1405 |
by (rtac zmod_zadd1_eq 1); |
|
1406 |
by (Simp_tac 1); |
|
1407 |
by (rtac (zmod_zadd1_eq RS sym) 1); |
|
1408 |
qed "zmod_zadd_left_eq"; |
|
1409 |
||
1410 |
Goal "(a$+b) zmod c = (a $+ (b zmod c)) zmod c"; |
|
1411 |
by (rtac (trans RS sym) 1); |
|
1412 |
by (rtac zmod_zadd1_eq 1); |
|
1413 |
by (Simp_tac 1); |
|
1414 |
by (rtac (zmod_zadd1_eq RS sym) 1); |
|
1415 |
qed "zmod_zadd_right_eq"; |
|
1416 |
||
1417 |
||
1418 |
Goal "intify(a) \\<noteq> #0 ==> (a$+b) zdiv a = b zdiv a $+ #1"; |
|
1419 |
by (asm_simp_tac (simpset() addsimps [zdiv_zadd1_eq]) 1); |
|
1420 |
qed "zdiv_zadd_self1"; |
|
1421 |
Addsimps [zdiv_zadd_self1]; |
|
1422 |
||
1423 |
Goal "intify(a) \\<noteq> #0 ==> (b$+a) zdiv a = b zdiv a $+ #1"; |
|
1424 |
by (asm_simp_tac (simpset() addsimps [zdiv_zadd1_eq]) 1); |
|
1425 |
qed "zdiv_zadd_self2"; |
|
1426 |
Addsimps [zdiv_zadd_self2]; |
|
1427 |
||
1428 |
Goal "(a$+b) zmod a = b zmod a"; |
|
1429 |
by (zdiv_undefined_case_tac "a = #0" 1); |
|
1430 |
by (asm_simp_tac (simpset() addsimps [zmod_zadd1_eq]) 1); |
|
1431 |
qed "zmod_zadd_self1"; |
|
1432 |
||
1433 |
Goal "(b$+a) zmod a = b zmod a"; |
|
1434 |
by (zdiv_undefined_case_tac "a = #0" 1); |
|
1435 |
by (asm_simp_tac (simpset() addsimps [zmod_zadd1_eq]) 1); |
|
1436 |
qed "zmod_zadd_self2"; |
|
1437 |
Addsimps [zmod_zadd_self1, zmod_zadd_self2]; |
|
1438 |
||
1439 |
||
1440 |
(*** proving a zdiv (b*c) = (a zdiv b) zdiv c ***) |
|
1441 |
||
1442 |
(*The condition c>0 seems necessary. Consider that 7 zdiv ~6 = ~2 but |
|
1443 |
7 zdiv 2 zdiv ~3 = 3 zdiv ~3 = ~1. The subcase (a zdiv b) zmod c = 0 seems |
|
1444 |
to cause particular problems.*) |
|
1445 |
||
1446 |
(** first, four lemmas to bound the remainder for the cases b<0 and b>0 **) |
|
1447 |
||
1448 |
Goal "[| #0 $< c; b $< r; r $<= #0 |] ==> b$*c $< b$*(q zmod c) $+ r"; |
|
1449 |
by (subgoal_tac "b $* (c $- q zmod c) $< r $* #1" 1); |
|
1450 |
by (asm_full_simp_tac |
|
1451 |
(simpset() addsimps [zdiff_zmult_distrib2, zadd_commute]@zcompare_rls) 1); |
|
1452 |
by (rtac zle_zless_trans 1); |
|
1453 |
by (etac zmult_zless_mono1 2); |
|
1454 |
by (rtac zmult_zle_mono2_neg 1); |
|
1455 |
by (auto_tac |
|
1456 |
(claset(), |
|
1457 |
simpset() addsimps zcompare_rls@ |
|
1458 |
[zadd_commute, add1_zle_iff, pos_mod_bound])); |
|
1459 |
by (blast_tac (claset() addIs [zless_imp_zle] |
|
1460 |
addDs [zless_zle_trans]) 1); |
|
1461 |
val lemma1 = result(); |
|
1462 |
||
1463 |
Goal "[| #0 $< c; b $< r; r $<= #0 |] ==> b $* (q zmod c) $+ r $<= #0"; |
|
1464 |
by (subgoal_tac "b $* (q zmod c) $<= #0" 1); |
|
1465 |
by (asm_simp_tac (simpset() addsimps [zmult_le_0_iff, pos_mod_sign]) 2); |
|
1466 |
by (blast_tac (claset() addIs [zless_imp_zle] |
|
1467 |
addDs [zless_zle_trans]) 2); |
|
1468 |
(*arithmetic*) |
|
1469 |
by (dtac zadd_zle_mono 1); |
|
1470 |
by (assume_tac 1); |
|
1471 |
by (asm_full_simp_tac (simpset() addsimps [zadd_commute]) 1); |
|
1472 |
val lemma2 = result(); |
|
1473 |
||
1474 |
Goal "[| #0 $< c; #0 $<= r; r $< b |] ==> #0 $<= b $* (q zmod c) $+ r"; |
|
1475 |
by (subgoal_tac "#0 $<= b $* (q zmod c)" 1); |
|
1476 |
by (asm_simp_tac (simpset() addsimps [int_0_le_mult_iff, pos_mod_sign]) 2); |
|
1477 |
by (blast_tac (claset() addIs [zless_imp_zle] |
|
1478 |
addDs [zle_zless_trans]) 2); |
|
1479 |
(*arithmetic*) |
|
1480 |
by (dtac zadd_zle_mono 1); |
|
1481 |
by (assume_tac 1); |
|
1482 |
by (asm_full_simp_tac (simpset() addsimps [zadd_commute]) 1); |
|
1483 |
val lemma3 = result(); |
|
1484 |
||
1485 |
Goal "[| #0 $< c; #0 $<= r; r $< b |] ==> b $* (q zmod c) $+ r $< b $* c"; |
|
1486 |
by (subgoal_tac "r $* #1 $< b $* (c $- q zmod c)" 1); |
|
1487 |
by (asm_full_simp_tac |
|
1488 |
(simpset() addsimps [zdiff_zmult_distrib2, zadd_commute]@zcompare_rls) 1); |
|
1489 |
by (rtac zless_zle_trans 1); |
|
1490 |
by (etac zmult_zless_mono1 1); |
|
1491 |
by (rtac zmult_zle_mono2 2); |
|
1492 |
by (auto_tac |
|
1493 |
(claset(), |
|
1494 |
simpset() addsimps zcompare_rls@ |
|
1495 |
[zadd_commute, add1_zle_iff, pos_mod_bound])); |
|
1496 |
by (blast_tac (claset() addIs [zless_imp_zle] |
|
1497 |
addDs [zle_zless_trans]) 1); |
|
1498 |
val lemma4 = result(); |
|
1499 |
||
1500 |
Goal "[| quorem (<a,b>, <q,r>); a \\<in> int; b \\<in> int; b \\<noteq> #0; #0 $< c |] \ |
|
1501 |
\ ==> quorem (<a,b$*c>, <q zdiv c, b$*(q zmod c) $+ r>)"; |
|
1502 |
by (auto_tac |
|
1503 |
(claset(), |
|
1504 |
simpset() addsimps zmult_ac@ |
|
1505 |
[zmod_zdiv_equality RS sym, quorem_def, neq_iff_zless, |
|
1506 |
int_0_less_mult_iff, |
|
1507 |
zadd_zmult_distrib2 RS sym, |
|
1508 |
lemma1, lemma2, lemma3, lemma4])); |
|
1509 |
by (ALLGOALS (blast_tac (claset() addDs [zless_trans]))); |
|
1510 |
val lemma = result(); |
|
1511 |
||
1512 |
Goal "[|#0 $< c; a \\<in> int; b \\<in> int|] ==> a zdiv (b$*c) = (a zdiv b) zdiv c"; |
|
1513 |
by (zdiv_undefined_case_tac "b = #0" 1); |
|
1514 |
by (rtac (quorem_div_mod RS lemma RS quorem_div) 1); |
|
1515 |
by (auto_tac (claset(), simpset() addsimps [intify_eq_0_iff_zle])); |
|
1516 |
by (blast_tac (claset() addDs [zle_zless_trans]) 1); |
|
1517 |
qed "zdiv_zmult2_eq_raw"; |
|
1518 |
||
1519 |
Goal "#0 $< c ==> a zdiv (b$*c) = (a zdiv b) zdiv c"; |
|
1520 |
by (cut_inst_tac [("a","intify(a)"), ("b","intify(b)")] |
|
1521 |
zdiv_zmult2_eq_raw 1); |
|
1522 |
by Auto_tac; |
|
1523 |
qed "zdiv_zmult2_eq"; |
|
1524 |
||
1525 |
Goal "[|#0 $< c; a \\<in> int; b \\<in> int|] \ |
|
1526 |
\ ==> a zmod (b$*c) = b$*(a zdiv b zmod c) $+ a zmod b"; |
|
1527 |
by (zdiv_undefined_case_tac "b = #0" 1); |
|
1528 |
by (rtac (quorem_div_mod RS lemma RS quorem_mod) 1); |
|
1529 |
by (auto_tac (claset(), simpset() addsimps [intify_eq_0_iff_zle])); |
|
1530 |
by (blast_tac (claset() addDs [zle_zless_trans]) 1); |
|
1531 |
qed "zmod_zmult2_eq_raw"; |
|
1532 |
||
1533 |
Goal "#0 $< c ==> a zmod (b$*c) = b$*(a zdiv b zmod c) $+ a zmod b"; |
|
1534 |
by (cut_inst_tac [("a","intify(a)"), ("b","intify(b)")] |
|
1535 |
zmod_zmult2_eq_raw 1); |
|
1536 |
by Auto_tac; |
|
1537 |
qed "zmod_zmult2_eq"; |
|
1538 |
||
1539 |
(*** Cancellation of common factors in "zdiv" ***) |
|
1540 |
||
1541 |
Goal "[| #0 $< b; intify(c) \\<noteq> #0 |] ==> (c$*a) zdiv (c$*b) = a zdiv b"; |
|
1542 |
by (stac zdiv_zmult2_eq 1); |
|
1543 |
by Auto_tac; |
|
1544 |
val lemma1 = result(); |
|
1545 |
||
1546 |
Goal "[| b $< #0; intify(c) \\<noteq> #0 |] ==> (c$*a) zdiv (c$*b) = a zdiv b"; |
|
1547 |
by (subgoal_tac "(c $* ($-a)) zdiv (c $* ($-b)) = ($-a) zdiv ($-b)" 1); |
|
1548 |
by (rtac lemma1 2); |
|
1549 |
by Auto_tac; |
|
1550 |
val lemma2 = result(); |
|
1551 |
||
1552 |
Goal "[|intify(c) \\<noteq> #0; b \\<in> int|] ==> (c$*a) zdiv (c$*b) = a zdiv b"; |
|
1553 |
by (zdiv_undefined_case_tac "b = #0" 1); |
|
1554 |
by (auto_tac |
|
1555 |
(claset(), |
|
1556 |
simpset() addsimps [read_instantiate [("x", "b")] neq_iff_zless, |
|
1557 |
lemma1, lemma2])); |
|
1558 |
qed "zdiv_zmult_zmult1_raw"; |
|
1559 |
||
1560 |
Goal "intify(c) \\<noteq> #0 ==> (c$*a) zdiv (c$*b) = a zdiv b"; |
|
1561 |
by (cut_inst_tac [("b","intify(b)")] zdiv_zmult_zmult1_raw 1); |
|
1562 |
by Auto_tac; |
|
1563 |
qed "zdiv_zmult_zmult1"; |
|
1564 |
||
1565 |
Goal "intify(c) \\<noteq> #0 ==> (a$*c) zdiv (b$*c) = a zdiv b"; |
|
1566 |
by (dtac zdiv_zmult_zmult1 1); |
|
1567 |
by (auto_tac (claset(), simpset() addsimps [zmult_commute])); |
|
1568 |
qed "zdiv_zmult_zmult2"; |
|
1569 |
||
1570 |
||
1571 |
(*** Distribution of factors over "zmod" ***) |
|
1572 |
||
1573 |
Goal "[| #0 $< b; intify(c) \\<noteq> #0 |] \ |
|
1574 |
\ ==> (c$*a) zmod (c$*b) = c $* (a zmod b)"; |
|
1575 |
by (stac zmod_zmult2_eq 1); |
|
1576 |
by Auto_tac; |
|
1577 |
val lemma1 = result(); |
|
1578 |
||
1579 |
Goal "[| b $< #0; intify(c) \\<noteq> #0 |] \ |
|
1580 |
\ ==> (c$*a) zmod (c$*b) = c $* (a zmod b)"; |
|
1581 |
by (subgoal_tac "(c $* ($-a)) zmod (c $* ($-b)) = c $* (($-a) zmod ($-b))" 1); |
|
1582 |
by (rtac lemma1 2); |
|
1583 |
by Auto_tac; |
|
1584 |
val lemma2 = result(); |
|
1585 |
||
1586 |
Goal "[|b \\<in> int; c \\<in> int|] ==> (c$*a) zmod (c$*b) = c $* (a zmod b)"; |
|
1587 |
by (zdiv_undefined_case_tac "b = #0" 1); |
|
1588 |
by (zdiv_undefined_case_tac "c = #0" 1); |
|
1589 |
by (auto_tac |
|
1590 |
(claset(), |
|
1591 |
simpset() addsimps [read_instantiate [("x", "b")] neq_iff_zless, |
|
1592 |
lemma1, lemma2])); |
|
1593 |
qed "zmod_zmult_zmult1_raw"; |
|
1594 |
||
1595 |
Goal "(c$*a) zmod (c$*b) = c $* (a zmod b)"; |
|
1596 |
by (cut_inst_tac [("b","intify(b)"),("c","intify(c)")] |
|
1597 |
zmod_zmult_zmult1_raw 1); |
|
1598 |
by Auto_tac; |
|
1599 |
qed "zmod_zmult_zmult1"; |
|
1600 |
||
1601 |
Goal "(a$*c) zmod (b$*c) = (a zmod b) $* c"; |
|
1602 |
by (cut_inst_tac [("c","c")] zmod_zmult_zmult1 1); |
|
1603 |
by (auto_tac (claset(), simpset() addsimps [zmult_commute])); |
|
1604 |
qed "zmod_zmult_zmult2"; |
|
1605 |
||
1606 |
||
1607 |
(** Quotients of signs **) |
|
1608 |
||
1609 |
Goal "[| a $< #0; #0 $< b |] ==> a zdiv b $< #0"; |
|
1610 |
by (subgoal_tac "a zdiv b $<= #-1" 1); |
|
1611 |
by (etac zle_zless_trans 1); |
|
1612 |
by (Simp_tac 1); |
|
1613 |
by (rtac zle_trans 1); |
|
1614 |
by (res_inst_tac [("a'","#-1")] zdiv_mono1 1); |
|
1615 |
by (rtac (zless_add1_iff_zle RS iffD1) 1); |
|
1616 |
by (Simp_tac 1); |
|
1617 |
by (auto_tac (claset(), simpset() addsimps [zdiv_minus1])); |
|
1618 |
qed "zdiv_neg_pos_less0"; |
|
1619 |
||
1620 |
Goal "[| #0 $<= a; b $< #0 |] ==> a zdiv b $<= #0"; |
|
1621 |
by (dtac zdiv_mono1_neg 1); |
|
1622 |
by Auto_tac; |
|
1623 |
qed "zdiv_nonneg_neg_le0"; |
|
1624 |
||
1625 |
Goal "#0 $< b ==> (#0 $<= a zdiv b) <-> (#0 $<= a)"; |
|
1626 |
by Auto_tac; |
|
1627 |
by (dtac zdiv_mono1 2); |
|
1628 |
by (auto_tac (claset(), simpset() addsimps [neq_iff_zless])); |
|
1629 |
by (full_simp_tac (simpset() addsimps [not_zless_iff_zle RS iff_sym]) 1); |
|
1630 |
by (blast_tac (claset() addIs [zdiv_neg_pos_less0]) 1); |
|
1631 |
qed "pos_imp_zdiv_nonneg_iff"; |
|
1632 |
||
1633 |
Goal "b $< #0 ==> (#0 $<= a zdiv b) <-> (a $<= #0)"; |
|
1634 |
by (stac (zdiv_zminus_zminus RS sym) 1); |
|
1635 |
by (rtac iff_trans 1); |
|
1636 |
by (rtac pos_imp_zdiv_nonneg_iff 1); |
|
1637 |
by Auto_tac; |
|
1638 |
qed "neg_imp_zdiv_nonneg_iff"; |
|
1639 |
||
1640 |
(*But not (a zdiv b $<= 0 iff a$<=0); consider a=1, b=2 when a zdiv b = 0.*) |
|
1641 |
Goal "#0 $< b ==> (a zdiv b $< #0) <-> (a $< #0)"; |
|
1642 |
by (asm_simp_tac (simpset() addsimps [not_zle_iff_zless RS iff_sym]) 1); |
|
1643 |
by (etac pos_imp_zdiv_nonneg_iff 1); |
|
1644 |
qed "pos_imp_zdiv_neg_iff"; |
|
1645 |
||
1646 |
(*Again the law fails for $<=: consider a = -1, b = -2 when a zdiv b = 0*) |
|
1647 |
Goal "b $< #0 ==> (a zdiv b $< #0) <-> (#0 $< a)"; |
|
1648 |
by (asm_simp_tac (simpset() addsimps [not_zle_iff_zless RS iff_sym]) 1); |
|
1649 |
by (etac neg_imp_zdiv_nonneg_iff 1); |
|
1650 |
qed "neg_imp_zdiv_neg_iff"; |
|
1651 |
||
1652 |
(* |
|
1653 |
THESE REMAIN TO BE CONVERTED -- but aren't that useful! |
|
1654 |
||
1655 |
(*** Speeding up the division algorithm with shifting ***) |
|
1656 |
||
1657 |
(** computing "zdiv" by shifting **) |
|
1658 |
||
1659 |
Goal "#0 $<= a ==> (#1 $+ #2$*b) zdiv (#2$*a) = b zdiv a"; |
|
1660 |
by (zdiv_undefined_case_tac "a = #0" 1); |
|
1661 |
by (subgoal_tac "#1 $<= a" 1); |
|
1662 |
by (arith_tac 2); |
|
1663 |
by (subgoal_tac "#1 $< a $* #2" 1); |
|
1664 |
by (arith_tac 2); |
|
1665 |
by (subgoal_tac "#2$*(#1 $+ b zmod a) $<= #2$*a" 1); |
|
1666 |
by (rtac zmult_zle_mono2 2); |
|
1667 |
by (auto_tac (claset(), |
|
1668 |
simpset() addsimps [zadd_commute, zmult_commute, |
|
1669 |
add1_zle_iff, pos_mod_bound])); |
|
1670 |
by (stac zdiv_zadd1_eq 1); |
|
1671 |
by (asm_simp_tac (simpset() addsimps [zdiv_zmult_zmult2, zmod_zmult_zmult2, |
|
1672 |
zdiv_pos_pos_trivial]) 1); |
|
1673 |
by (stac zdiv_pos_pos_trivial 1); |
|
1674 |
by (asm_simp_tac (simpset() |
|
1675 |
addsimps [zmod_pos_pos_trivial, |
|
1676 |
pos_mod_sign RS zadd_zle_mono1 RSN (2,zle_trans)]) 1); |
|
1677 |
by (auto_tac (claset(), |
|
1678 |
simpset() addsimps [zmod_pos_pos_trivial])); |
|
1679 |
by (subgoal_tac "#0 $<= b zmod a" 1); |
|
1680 |
by (asm_simp_tac (simpset() addsimps [pos_mod_sign]) 2); |
|
1681 |
by (arith_tac 1); |
|
1682 |
qed "pos_zdiv_mult_2"; |
|
1683 |
||
1684 |
||
1685 |
Goal "a $<= #0 ==> (#1 $+ #2$*b) zdiv (#2$*a) <-> (b$+#1) zdiv a"; |
|
1686 |
by (subgoal_tac "(#1 $+ #2$*($-b-#1)) zdiv (#2 $* ($-a)) <-> ($-b-#1) zdiv ($-a)" 1); |
|
1687 |
by (rtac pos_zdiv_mult_2 2); |
|
1688 |
by (auto_tac (claset(), |
|
1689 |
simpset() addsimps [zmult_zminus_right])); |
|
1690 |
by (subgoal_tac "(#-1 - (#2 $* b)) = - (#1 $+ (#2 $* b))" 1); |
|
1691 |
by (Simp_tac 2); |
|
1692 |
by (asm_full_simp_tac (HOL_ss |
|
1693 |
addsimps [zdiv_zminus_zminus, zdiff_def, |
|
1694 |
zminus_zadd_distrib RS sym]) 1); |
|
1695 |
qed "neg_zdiv_mult_2"; |
|
1696 |
||
1697 |
||
1698 |
(*Not clear why this must be proved separately; probably integ_of causes |
|
1699 |
simplification problems*) |
|
1700 |
Goal "~ #0 $<= x ==> x $<= #0"; |
|
1701 |
by Auto_tac; |
|
1702 |
val lemma = result(); |
|
1703 |
||
1704 |
Goal "integ_of (v BIT b) zdiv integ_of (w BIT False) = \ |
|
1705 |
\ (if ~b | #0 $<= integ_of w \ |
|
1706 |
\ then integ_of v zdiv (integ_of w) \ |
|
1707 |
\ else (integ_of v $+ #1) zdiv (integ_of w))"; |
|
1708 |
by (simp_tac (simpset_of Int.thy addsimps [zadd_assoc, integ_of_BIT]) 1); |
|
1709 |
by (asm_simp_tac (simpset() |
|
1710 |
delsimps bin_arith_extra_simps@bin_rel_simps |
|
1711 |
addsimps [zdiv_zmult_zmult1, |
|
1712 |
pos_zdiv_mult_2, lemma, neg_zdiv_mult_2]) 1); |
|
1713 |
qed "zdiv_integ_of_BIT"; |
|
1714 |
||
1715 |
Addsimps [zdiv_integ_of_BIT]; |
|
1716 |
||
1717 |
||
1718 |
(** computing "zmod" by shifting (proofs resemble those for "zdiv") **) |
|
1719 |
||
1720 |
Goal "#0 $<= a ==> (#1 $+ #2$*b) zmod (#2$*a) = #1 $+ #2 $* (b zmod a)"; |
|
1721 |
by (zdiv_undefined_case_tac "a = #0" 1); |
|
1722 |
by (subgoal_tac "#1 $<= a" 1); |
|
1723 |
by (arith_tac 2); |
|
1724 |
by (subgoal_tac "#1 $< a $* #2" 1); |
|
1725 |
by (arith_tac 2); |
|
1726 |
by (subgoal_tac "#2$*(#1 $+ b zmod a) $<= #2$*a" 1); |
|
1727 |
by (rtac zmult_zle_mono2 2); |
|
1728 |
by (auto_tac (claset(), |
|
1729 |
simpset() addsimps [zadd_commute, zmult_commute, |
|
1730 |
add1_zle_iff, pos_mod_bound])); |
|
1731 |
by (stac zmod_zadd1_eq 1); |
|
1732 |
by (asm_simp_tac (simpset() addsimps [zmod_zmult_zmult2, |
|
1733 |
zmod_pos_pos_trivial]) 1); |
|
1734 |
by (rtac zmod_pos_pos_trivial 1); |
|
1735 |
by (asm_simp_tac (simpset() |
|
1736 |
# addsimps [zmod_pos_pos_trivial, |
|
1737 |
pos_mod_sign RS zadd_zle_mono1 RSN (2,zle_trans)]) 1); |
|
1738 |
by (auto_tac (claset(), |
|
1739 |
simpset() addsimps [zmod_pos_pos_trivial])); |
|
1740 |
by (subgoal_tac "#0 $<= b zmod a" 1); |
|
1741 |
by (asm_simp_tac (simpset() addsimps [pos_mod_sign]) 2); |
|
1742 |
by (arith_tac 1); |
|
1743 |
qed "pos_zmod_mult_2"; |
|
1744 |
||
1745 |
||
1746 |
Goal "a $<= #0 ==> (#1 $+ #2$*b) zmod (#2$*a) = #2 $* ((b$+#1) zmod a) - #1"; |
|
1747 |
by (subgoal_tac |
|
1748 |
"(#1 $+ #2$*($-b-#1)) zmod (#2$*($-a)) = #1 $+ #2$*(($-b-#1) zmod ($-a))" 1); |
|
1749 |
by (rtac pos_zmod_mult_2 2); |
|
1750 |
by (auto_tac (claset(), |
|
1751 |
simpset() addsimps [zmult_zminus_right])); |
|
1752 |
by (subgoal_tac "(#-1 - (#2 $* b)) = - (#1 $+ (#2 $* b))" 1); |
|
1753 |
by (Simp_tac 2); |
|
1754 |
by (asm_full_simp_tac (HOL_ss |
|
1755 |
addsimps [zmod_zminus_zminus, zdiff_def, |
|
1756 |
zminus_zadd_distrib RS sym]) 1); |
|
1757 |
by (dtac (zminus_equation RS iffD1 RS sym) 1); |
|
1758 |
by Auto_tac; |
|
1759 |
qed "neg_zmod_mult_2"; |
|
1760 |
||
1761 |
Goal "integ_of (v BIT b) zmod integ_of (w BIT False) = \ |
|
1762 |
\ (if b then \ |
|
1763 |
\ if #0 $<= integ_of w \ |
|
1764 |
\ then #2 $* (integ_of v zmod integ_of w) $+ #1 \ |
|
1765 |
\ else #2 $* ((integ_of v $+ #1) zmod integ_of w) - #1 \ |
|
1766 |
\ else #2 $* (integ_of v zmod integ_of w))"; |
|
1767 |
by (simp_tac (simpset_of Int.thy addsimps [zadd_assoc, integ_of_BIT]) 1); |
|
1768 |
by (asm_simp_tac (simpset() |
|
1769 |
delsimps bin_arith_extra_simps@bin_rel_simps |
|
1770 |
addsimps [zmod_zmult_zmult1, |
|
1771 |
pos_zmod_mult_2, lemma, neg_zmod_mult_2]) 1); |
|
1772 |
qed "zmod_integ_of_BIT"; |
|
1773 |
||
1774 |
Addsimps [zmod_integ_of_BIT]; |
|
1775 |
*) |