author | wenzelm |
Mon, 22 Jun 1998 17:26:46 +0200 | |
changeset 5069 | 3ea049f7979d |
parent 4811 | 7a98aa1f9a9d |
child 5143 | b94cd208f073 |
permissions | -rw-r--r-- |
3366 | 1 |
(* Title: HOL/Divides.ML |
2 |
ID: $Id$ |
|
3 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
|
4 |
Copyright 1993 University of Cambridge |
|
5 |
||
6 |
The division operators div, mod and the divides relation "dvd" |
|
7 |
*) |
|
8 |
||
9 |
||
10 |
(** Less-then properties **) |
|
11 |
||
12 |
(*In ordinary notation: if 0<n and n<=m then m-n < m *) |
|
13 |
goal Arith.thy "!!m. [| 0<n; ~ m<n |] ==> m - n < m"; |
|
14 |
by (subgoal_tac "0<n --> ~ m<n --> m - n < m" 1); |
|
15 |
by (Blast_tac 1); |
|
16 |
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1); |
|
4089 | 17 |
by (ALLGOALS(asm_simp_tac(simpset() addsimps [diff_less_Suc]))); |
3366 | 18 |
qed "diff_less"; |
19 |
||
20 |
val wf_less_trans = [eq_reflection, wf_pred_nat RS wf_trancl] MRS |
|
21 |
def_wfrec RS trans; |
|
22 |
||
23 |
(*** Remainder ***) |
|
24 |
||
5069 | 25 |
Goal "(%m. m mod n) = wfrec (trancl pred_nat) \ |
3366 | 26 |
\ (%f j. if j<n then j else f (j-n))"; |
4089 | 27 |
by (simp_tac (simpset() addsimps [mod_def]) 1); |
3366 | 28 |
qed "mod_eq"; |
29 |
||
5069 | 30 |
Goal "!!m. m<n ==> m mod n = m"; |
3366 | 31 |
by (rtac (mod_eq RS wf_less_trans) 1); |
32 |
by (Asm_simp_tac 1); |
|
33 |
qed "mod_less"; |
|
34 |
||
5069 | 35 |
Goal "!!m. [| 0<n; ~m<n |] ==> m mod n = (m-n) mod n"; |
3366 | 36 |
by (rtac (mod_eq RS wf_less_trans) 1); |
4089 | 37 |
by (asm_simp_tac (simpset() addsimps [diff_less, cut_apply, less_eq]) 1); |
3366 | 38 |
qed "mod_geq"; |
39 |
||
4774 | 40 |
(*NOT suitable for rewriting: loops*) |
5069 | 41 |
Goal "!!m. 0<n ==> m mod n = (if m<n then m else (m-n) mod n)"; |
4774 | 42 |
by (asm_simp_tac (simpset() addsimps [mod_less, mod_geq]) 1); |
43 |
qed "mod_if"; |
|
44 |
||
5069 | 45 |
Goal "m mod 1 = 0"; |
3366 | 46 |
by (induct_tac "m" 1); |
4089 | 47 |
by (ALLGOALS (asm_simp_tac (simpset() addsimps [mod_less, mod_geq]))); |
3366 | 48 |
qed "mod_1"; |
49 |
Addsimps [mod_1]; |
|
50 |
||
5069 | 51 |
Goal "!!n. 0<n ==> n mod n = 0"; |
4089 | 52 |
by (asm_simp_tac (simpset() addsimps [mod_less, mod_geq]) 1); |
3366 | 53 |
qed "mod_self"; |
54 |
||
5069 | 55 |
Goal "!!n. 0<n ==> (m+n) mod n = m mod n"; |
3366 | 56 |
by (subgoal_tac "(n + m) mod n = (n+m-n) mod n" 1); |
57 |
by (stac (mod_geq RS sym) 2); |
|
4089 | 58 |
by (ALLGOALS (asm_full_simp_tac (simpset() addsimps [add_commute]))); |
4811 | 59 |
qed "mod_add_self2"; |
4810 | 60 |
|
5069 | 61 |
Goal "!!k. 0<n ==> (n+m) mod n = m mod n"; |
4811 | 62 |
by (asm_simp_tac (simpset() addsimps [add_commute, mod_add_self2]) 1); |
63 |
qed "mod_add_self1"; |
|
4810 | 64 |
|
5069 | 65 |
Goal "!!n. 0<n ==> (m + k*n) mod n = m mod n"; |
4810 | 66 |
by (induct_tac "k" 1); |
4811 | 67 |
by (ALLGOALS (asm_simp_tac (simpset() addsimps (add_ac @ [mod_add_self1])))); |
68 |
qed "mod_mult_self1"; |
|
4810 | 69 |
|
5069 | 70 |
Goal "!!m. 0<n ==> (m + n*k) mod n = m mod n"; |
4811 | 71 |
by (asm_simp_tac (simpset() addsimps [mult_commute, mod_mult_self1]) 1); |
72 |
qed "mod_mult_self2"; |
|
4810 | 73 |
|
4811 | 74 |
Addsimps [mod_mult_self1, mod_mult_self2]; |
3366 | 75 |
|
5069 | 76 |
Goal "!!k. [| 0<k; 0<n |] ==> (m mod n)*k = (m*k) mod (n*k)"; |
3366 | 77 |
by (res_inst_tac [("n","m")] less_induct 1); |
4774 | 78 |
by (stac mod_if 1); |
79 |
by (Asm_simp_tac 1); |
|
80 |
by (asm_simp_tac (simpset() addsimps [mod_less, mod_geq, |
|
81 |
diff_less, diff_mult_distrib]) 1); |
|
3366 | 82 |
qed "mod_mult_distrib"; |
83 |
||
5069 | 84 |
Goal "!!k. [| 0<k; 0<n |] ==> k*(m mod n) = (k*m) mod (k*n)"; |
3366 | 85 |
by (res_inst_tac [("n","m")] less_induct 1); |
4774 | 86 |
by (stac mod_if 1); |
87 |
by (Asm_simp_tac 1); |
|
88 |
by (asm_simp_tac (simpset() addsimps [mod_less, mod_geq, |
|
89 |
diff_less, diff_mult_distrib2]) 1); |
|
3366 | 90 |
qed "mod_mult_distrib2"; |
91 |
||
5069 | 92 |
Goal "!!n. 0<n ==> m*n mod n = 0"; |
3366 | 93 |
by (induct_tac "m" 1); |
4089 | 94 |
by (asm_simp_tac (simpset() addsimps [mod_less]) 1); |
4811 | 95 |
by (dres_inst_tac [("m","m*n")] mod_add_self2 1); |
4089 | 96 |
by (asm_full_simp_tac (simpset() addsimps [add_commute]) 1); |
3366 | 97 |
qed "mod_mult_self_is_0"; |
98 |
Addsimps [mod_mult_self_is_0]; |
|
99 |
||
100 |
(*** Quotient ***) |
|
101 |
||
5069 | 102 |
Goal "(%m. m div n) = wfrec (trancl pred_nat) \ |
3366 | 103 |
\ (%f j. if j<n then 0 else Suc (f (j-n)))"; |
4089 | 104 |
by (simp_tac (simpset() addsimps [div_def]) 1); |
3366 | 105 |
qed "div_eq"; |
106 |
||
5069 | 107 |
Goal "!!m. m<n ==> m div n = 0"; |
3366 | 108 |
by (rtac (div_eq RS wf_less_trans) 1); |
109 |
by (Asm_simp_tac 1); |
|
110 |
qed "div_less"; |
|
111 |
||
5069 | 112 |
Goal "!!M. [| 0<n; ~m<n |] ==> m div n = Suc((m-n) div n)"; |
3366 | 113 |
by (rtac (div_eq RS wf_less_trans) 1); |
4089 | 114 |
by (asm_simp_tac (simpset() addsimps [diff_less, cut_apply, less_eq]) 1); |
3366 | 115 |
qed "div_geq"; |
116 |
||
4774 | 117 |
(*NOT suitable for rewriting: loops*) |
5069 | 118 |
Goal "!!m. 0<n ==> m div n = (if m<n then 0 else Suc((m-n) div n))"; |
4774 | 119 |
by (asm_simp_tac (simpset() addsimps [div_less, div_geq]) 1); |
120 |
qed "div_if"; |
|
121 |
||
3366 | 122 |
(*Main Result about quotient and remainder.*) |
5069 | 123 |
Goal "!!m. 0<n ==> (m div n)*n + m mod n = m"; |
3366 | 124 |
by (res_inst_tac [("n","m")] less_induct 1); |
4774 | 125 |
by (stac mod_if 1); |
126 |
by (ALLGOALS (asm_simp_tac |
|
127 |
(simpset() addsimps ([add_assoc] @ |
|
128 |
[div_less, div_geq, |
|
129 |
add_diff_inverse, diff_less])))); |
|
3366 | 130 |
qed "mod_div_equality"; |
131 |
||
4358 | 132 |
(* a simple rearrangement of mod_div_equality: *) |
5069 | 133 |
Goal "!!k. 0<k ==> k*(m div k) = m - (m mod k)"; |
4423 | 134 |
by (dres_inst_tac [("m","m")] mod_div_equality 1); |
4358 | 135 |
by (EVERY1[etac subst, simp_tac (simpset() addsimps mult_ac), |
136 |
K(IF_UNSOLVED no_tac)]); |
|
137 |
qed "mult_div_cancel"; |
|
138 |
||
5069 | 139 |
Goal "m div 1 = m"; |
3366 | 140 |
by (induct_tac "m" 1); |
4089 | 141 |
by (ALLGOALS (asm_simp_tac (simpset() addsimps [div_less, div_geq]))); |
3366 | 142 |
qed "div_1"; |
143 |
Addsimps [div_1]; |
|
144 |
||
5069 | 145 |
Goal "!!n. 0<n ==> n div n = 1"; |
4089 | 146 |
by (asm_simp_tac (simpset() addsimps [div_less, div_geq]) 1); |
3366 | 147 |
qed "div_self"; |
148 |
||
4811 | 149 |
|
5069 | 150 |
Goal "!!n. 0<n ==> (m+n) div n = Suc (m div n)"; |
4811 | 151 |
by (subgoal_tac "(n + m) div n = Suc ((n+m-n) div n)" 1); |
152 |
by (stac (div_geq RS sym) 2); |
|
153 |
by (ALLGOALS (asm_full_simp_tac (simpset() addsimps [add_commute]))); |
|
154 |
qed "div_add_self2"; |
|
155 |
||
5069 | 156 |
Goal "!!k. 0<n ==> (n+m) div n = Suc (m div n)"; |
4811 | 157 |
by (asm_simp_tac (simpset() addsimps [add_commute, div_add_self2]) 1); |
158 |
qed "div_add_self1"; |
|
159 |
||
5069 | 160 |
Goal "!!n. 0<n ==> (m + k*n) div n = k + m div n"; |
4811 | 161 |
by (induct_tac "k" 1); |
162 |
by (ALLGOALS (asm_simp_tac (simpset() addsimps (add_ac @ [div_add_self1])))); |
|
163 |
qed "div_mult_self1"; |
|
164 |
||
5069 | 165 |
Goal "!!m. 0<n ==> (m + n*k) div n = k + m div n"; |
4811 | 166 |
by (asm_simp_tac (simpset() addsimps [mult_commute, div_mult_self1]) 1); |
167 |
qed "div_mult_self2"; |
|
168 |
||
169 |
Addsimps [div_mult_self1, div_mult_self2]; |
|
170 |
||
171 |
||
3484
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
172 |
(* Monotonicity of div in first argument *) |
5069 | 173 |
Goal "!!n. 0<k ==> ALL m. m <= n --> (m div k) <= (n div k)"; |
3484
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
174 |
by (res_inst_tac [("n","n")] less_induct 1); |
3718 | 175 |
by (Clarify_tac 1); |
3484
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
176 |
by (case_tac "na<k" 1); |
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
177 |
(* 1 case n<k *) |
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
178 |
by (subgoal_tac "m<k" 1); |
4089 | 179 |
by (asm_simp_tac (simpset() addsimps [div_less]) 1); |
3496 | 180 |
by (trans_tac 1); |
3484
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
181 |
(* 2 case n >= k *) |
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
182 |
by (case_tac "m<k" 1); |
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
183 |
(* 2.1 case m<k *) |
4089 | 184 |
by (asm_simp_tac (simpset() addsimps [div_less]) 1); |
3484
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
185 |
(* 2.2 case m>=k *) |
4089 | 186 |
by (asm_simp_tac (simpset() addsimps [div_geq, diff_less, diff_le_mono]) 1); |
3484
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
187 |
qed_spec_mp "div_le_mono"; |
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
188 |
|
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
189 |
|
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
190 |
(* Antimonotonicity of div in second argument *) |
5069 | 191 |
Goal "!!k m n. [| 0<m; m<=n |] ==> (k div n) <= (k div m)"; |
3484
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
192 |
by (subgoal_tac "0<n" 1); |
3496 | 193 |
by (trans_tac 2); |
3484
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
194 |
by (res_inst_tac [("n","k")] less_induct 1); |
3496 | 195 |
by (Simp_tac 1); |
196 |
by (rename_tac "k" 1); |
|
3484
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
197 |
by (case_tac "k<n" 1); |
4089 | 198 |
by (asm_simp_tac (simpset() addsimps [div_less]) 1); |
3484
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
199 |
by (subgoal_tac "~(k<m)" 1); |
3496 | 200 |
by (trans_tac 2); |
4089 | 201 |
by (asm_simp_tac (simpset() addsimps [div_geq]) 1); |
3484
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
202 |
by (subgoal_tac "(k-n) div n <= (k-m) div n" 1); |
4089 | 203 |
by (best_tac (claset() addIs [le_trans] |
204 |
addss (simpset() addsimps [diff_less])) 1); |
|
3484
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
205 |
by (REPEAT (eresolve_tac [div_le_mono,diff_le_mono2] 1)); |
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
206 |
qed "div_le_mono2"; |
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
207 |
|
5069 | 208 |
Goal "!!m n. 0<n ==> m div n <= m"; |
3484
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
209 |
by (subgoal_tac "m div n <= m div 1" 1); |
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
210 |
by (Asm_full_simp_tac 1); |
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
211 |
by (rtac div_le_mono2 1); |
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
212 |
by (ALLGOALS trans_tac); |
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
213 |
qed "div_le_dividend"; |
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
214 |
Addsimps [div_le_dividend]; |
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
215 |
|
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
216 |
(* Similar for "less than" *) |
5069 | 217 |
Goal "!!m n. 1<n ==> (0 < m) --> (m div n < m)"; |
3484
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
218 |
by (res_inst_tac [("n","m")] less_induct 1); |
3496 | 219 |
by (Simp_tac 1); |
220 |
by (rename_tac "m" 1); |
|
3484
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
221 |
by (case_tac "m<n" 1); |
4089 | 222 |
by (asm_full_simp_tac (simpset() addsimps [div_less]) 1); |
3484
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
223 |
by (subgoal_tac "0<n" 1); |
3496 | 224 |
by (trans_tac 2); |
4089 | 225 |
by (asm_full_simp_tac (simpset() addsimps [div_geq]) 1); |
3484
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
226 |
by (case_tac "n<m" 1); |
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
227 |
by (subgoal_tac "(m-n) div n < (m-n)" 1); |
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
228 |
by (REPEAT (ares_tac [impI,less_trans_Suc] 1)); |
4089 | 229 |
by (asm_full_simp_tac (simpset() addsimps [diff_less]) 1); |
3484
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
230 |
by (dres_inst_tac [("m","n")] less_imp_diff_positive 1); |
4089 | 231 |
by (asm_full_simp_tac (simpset() addsimps [diff_less]) 1); |
3484
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
232 |
(* case n=m *) |
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
233 |
by (subgoal_tac "m=n" 1); |
3496 | 234 |
by (trans_tac 2); |
4089 | 235 |
by (asm_simp_tac (simpset() addsimps [div_less]) 1); |
3484
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
236 |
qed_spec_mp "div_less_dividend"; |
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
237 |
Addsimps [div_less_dividend]; |
3366 | 238 |
|
239 |
(*** Further facts about mod (mainly for the mutilated chess board ***) |
|
240 |
||
5069 | 241 |
Goal |
3366 | 242 |
"!!m n. 0<n ==> \ |
243 |
\ Suc(m) mod n = (if Suc(m mod n) = n then 0 else Suc(m mod n))"; |
|
244 |
by (res_inst_tac [("n","m")] less_induct 1); |
|
245 |
by (excluded_middle_tac "Suc(na)<n" 1); |
|
246 |
(* case Suc(na) < n *) |
|
247 |
by (forward_tac [lessI RS less_trans] 2); |
|
4089 | 248 |
by (asm_simp_tac (simpset() addsimps [mod_less, less_not_refl2 RS not_sym]) 2); |
3366 | 249 |
(* case n <= Suc(na) *) |
4089 | 250 |
by (asm_full_simp_tac (simpset() addsimps [not_less_iff_le, mod_geq]) 1); |
3366 | 251 |
by (etac (le_imp_less_or_eq RS disjE) 1); |
4089 | 252 |
by (asm_simp_tac (simpset() addsimps [Suc_diff_n]) 1); |
253 |
by (asm_full_simp_tac (simpset() addsimps [not_less_eq RS sym, |
|
3366 | 254 |
diff_less, mod_geq]) 1); |
4089 | 255 |
by (asm_simp_tac (simpset() addsimps [mod_less]) 1); |
3366 | 256 |
qed "mod_Suc"; |
257 |
||
5069 | 258 |
Goal "!!m n. 0<n ==> m mod n < n"; |
3366 | 259 |
by (res_inst_tac [("n","m")] less_induct 1); |
260 |
by (excluded_middle_tac "na<n" 1); |
|
261 |
(*case na<n*) |
|
4089 | 262 |
by (asm_simp_tac (simpset() addsimps [mod_less]) 2); |
3366 | 263 |
(*case n le na*) |
4089 | 264 |
by (asm_full_simp_tac (simpset() addsimps [mod_geq, diff_less]) 1); |
3366 | 265 |
qed "mod_less_divisor"; |
266 |
||
267 |
||
268 |
(** Evens and Odds **) |
|
269 |
||
270 |
(*With less_zeroE, causes case analysis on b<2*) |
|
271 |
AddSEs [less_SucE]; |
|
272 |
||
5069 | 273 |
Goal "!!k b. b<2 ==> k mod 2 = b | k mod 2 = (if b=1 then 0 else 1)"; |
3366 | 274 |
by (subgoal_tac "k mod 2 < 2" 1); |
4089 | 275 |
by (asm_simp_tac (simpset() addsimps [mod_less_divisor]) 2); |
4686 | 276 |
by (Asm_simp_tac 1); |
4356 | 277 |
by Safe_tac; |
3366 | 278 |
qed "mod2_cases"; |
279 |
||
5069 | 280 |
Goal "Suc(Suc(m)) mod 2 = m mod 2"; |
3366 | 281 |
by (subgoal_tac "m mod 2 < 2" 1); |
4089 | 282 |
by (asm_simp_tac (simpset() addsimps [mod_less_divisor]) 2); |
3724 | 283 |
by Safe_tac; |
4089 | 284 |
by (ALLGOALS (asm_simp_tac (simpset() addsimps [mod_Suc]))); |
3366 | 285 |
qed "mod2_Suc_Suc"; |
286 |
Addsimps [mod2_Suc_Suc]; |
|
287 |
||
5069 | 288 |
Goal "(0 < m mod 2) = (m mod 2 = 1)"; |
3366 | 289 |
by (subgoal_tac "m mod 2 < 2" 1); |
4089 | 290 |
by (asm_simp_tac (simpset() addsimps [mod_less_divisor]) 2); |
4477
b3e5857d8d99
New Auto_tac (by Oheimb), and new syntax (without parens), and expandshort
paulson
parents:
4423
diff
changeset
|
291 |
by Auto_tac; |
4356 | 292 |
qed "mod2_gr_0"; |
293 |
Addsimps [mod2_gr_0]; |
|
294 |
||
5069 | 295 |
Goal "(m+m) mod 2 = 0"; |
3366 | 296 |
by (induct_tac "m" 1); |
4089 | 297 |
by (simp_tac (simpset() addsimps [mod_less]) 1); |
3427
e7cef2081106
Removed a few redundant additions of simprules or classical rules
paulson
parents:
3366
diff
changeset
|
298 |
by (Asm_simp_tac 1); |
4385 | 299 |
qed "mod2_add_self_eq_0"; |
300 |
Addsimps [mod2_add_self_eq_0]; |
|
301 |
||
5069 | 302 |
Goal "((m+m)+n) mod 2 = n mod 2"; |
4385 | 303 |
by (induct_tac "m" 1); |
304 |
by (simp_tac (simpset() addsimps [mod_less]) 1); |
|
305 |
by (Asm_simp_tac 1); |
|
3366 | 306 |
qed "mod2_add_self"; |
307 |
Addsimps [mod2_add_self]; |
|
308 |
||
309 |
Delrules [less_SucE]; |
|
310 |
||
311 |
||
312 |
(*** More division laws ***) |
|
313 |
||
5069 | 314 |
Goal "!!n. 0<n ==> m*n div n = m"; |
3366 | 315 |
by (cut_inst_tac [("m", "m*n")] mod_div_equality 1); |
3457 | 316 |
by (assume_tac 1); |
4089 | 317 |
by (asm_full_simp_tac (simpset() addsimps [mod_mult_self_is_0]) 1); |
3366 | 318 |
qed "div_mult_self_is_m"; |
319 |
Addsimps [div_mult_self_is_m]; |
|
320 |
||
321 |
(*Cancellation law for division*) |
|
5069 | 322 |
Goal "!!k. [| 0<n; 0<k |] ==> (k*m) div (k*n) = m div n"; |
3366 | 323 |
by (res_inst_tac [("n","m")] less_induct 1); |
324 |
by (case_tac "na<n" 1); |
|
4089 | 325 |
by (asm_simp_tac (simpset() addsimps [div_less, zero_less_mult_iff, |
3366 | 326 |
mult_less_mono2]) 1); |
327 |
by (subgoal_tac "~ k*na < k*n" 1); |
|
328 |
by (asm_simp_tac |
|
4089 | 329 |
(simpset() addsimps [zero_less_mult_iff, div_geq, |
3366 | 330 |
diff_mult_distrib2 RS sym, diff_less]) 1); |
4089 | 331 |
by (asm_full_simp_tac (simpset() addsimps [not_less_iff_le, |
3366 | 332 |
le_refl RS mult_le_mono]) 1); |
333 |
qed "div_cancel"; |
|
334 |
Addsimps [div_cancel]; |
|
335 |
||
5069 | 336 |
Goal "!!k. [| 0<n; 0<k |] ==> (k*m) mod (k*n) = k * (m mod n)"; |
3366 | 337 |
by (res_inst_tac [("n","m")] less_induct 1); |
338 |
by (case_tac "na<n" 1); |
|
4089 | 339 |
by (asm_simp_tac (simpset() addsimps [mod_less, zero_less_mult_iff, |
3366 | 340 |
mult_less_mono2]) 1); |
341 |
by (subgoal_tac "~ k*na < k*n" 1); |
|
342 |
by (asm_simp_tac |
|
4089 | 343 |
(simpset() addsimps [zero_less_mult_iff, mod_geq, |
3366 | 344 |
diff_mult_distrib2 RS sym, diff_less]) 1); |
4089 | 345 |
by (asm_full_simp_tac (simpset() addsimps [not_less_iff_le, |
3366 | 346 |
le_refl RS mult_le_mono]) 1); |
347 |
qed "mult_mod_distrib"; |
|
348 |
||
349 |
||
350 |
(************************************************) |
|
351 |
(** Divides Relation **) |
|
352 |
(************************************************) |
|
353 |
||
5069 | 354 |
Goalw [dvd_def] "m dvd 0"; |
4089 | 355 |
by (blast_tac (claset() addIs [mult_0_right RS sym]) 1); |
3366 | 356 |
qed "dvd_0_right"; |
357 |
Addsimps [dvd_0_right]; |
|
358 |
||
5069 | 359 |
Goalw [dvd_def] "!!m. 0 dvd m ==> m = 0"; |
4089 | 360 |
by (fast_tac (claset() addss simpset()) 1); |
3366 | 361 |
qed "dvd_0_left"; |
362 |
||
5069 | 363 |
Goalw [dvd_def] "1 dvd k"; |
3366 | 364 |
by (Simp_tac 1); |
365 |
qed "dvd_1_left"; |
|
366 |
AddIffs [dvd_1_left]; |
|
367 |
||
5069 | 368 |
Goalw [dvd_def] "m dvd m"; |
4089 | 369 |
by (blast_tac (claset() addIs [mult_1_right RS sym]) 1); |
3366 | 370 |
qed "dvd_refl"; |
371 |
Addsimps [dvd_refl]; |
|
372 |
||
5069 | 373 |
Goalw [dvd_def] "!!m n p. [| m dvd n; n dvd p |] ==> m dvd p"; |
4089 | 374 |
by (blast_tac (claset() addIs [mult_assoc] ) 1); |
3366 | 375 |
qed "dvd_trans"; |
376 |
||
5069 | 377 |
Goalw [dvd_def] "!!m n. [| m dvd n; n dvd m |] ==> m=n"; |
4089 | 378 |
by (fast_tac (claset() addDs [mult_eq_self_implies_10] |
379 |
addss (simpset() addsimps [mult_assoc, mult_eq_1_iff])) 1); |
|
3366 | 380 |
qed "dvd_anti_sym"; |
381 |
||
5069 | 382 |
Goalw [dvd_def] "!!k. [| k dvd m; k dvd n |] ==> k dvd (m + n)"; |
4089 | 383 |
by (blast_tac (claset() addIs [add_mult_distrib2 RS sym]) 1); |
3366 | 384 |
qed "dvd_add"; |
385 |
||
5069 | 386 |
Goalw [dvd_def] "!!k. [| k dvd m; k dvd n |] ==> k dvd (m-n)"; |
4089 | 387 |
by (blast_tac (claset() addIs [diff_mult_distrib2 RS sym]) 1); |
3366 | 388 |
qed "dvd_diff"; |
389 |
||
5069 | 390 |
Goal "!!k. [| k dvd (m-n); k dvd n; n<=m |] ==> k dvd m"; |
3457 | 391 |
by (etac (not_less_iff_le RS iffD2 RS add_diff_inverse RS subst) 1); |
4089 | 392 |
by (blast_tac (claset() addIs [dvd_add]) 1); |
3366 | 393 |
qed "dvd_diffD"; |
394 |
||
5069 | 395 |
Goalw [dvd_def] "!!k. k dvd n ==> k dvd (m*n)"; |
4089 | 396 |
by (blast_tac (claset() addIs [mult_left_commute]) 1); |
3366 | 397 |
qed "dvd_mult"; |
398 |
||
5069 | 399 |
Goal "!!k. k dvd m ==> k dvd (m*n)"; |
3366 | 400 |
by (stac mult_commute 1); |
401 |
by (etac dvd_mult 1); |
|
402 |
qed "dvd_mult2"; |
|
403 |
||
404 |
(* k dvd (m*k) *) |
|
405 |
AddIffs [dvd_refl RS dvd_mult, dvd_refl RS dvd_mult2]; |
|
406 |
||
5069 | 407 |
Goalw [dvd_def] "!!m. [| f dvd m; f dvd n; 0<n |] ==> f dvd (m mod n)"; |
3718 | 408 |
by (Clarify_tac 1); |
4089 | 409 |
by (full_simp_tac (simpset() addsimps [zero_less_mult_iff]) 1); |
3366 | 410 |
by (res_inst_tac |
411 |
[("x", "(((k div ka)*ka + k mod ka) - ((f*k) div (f*ka)) * ka)")] |
|
412 |
exI 1); |
|
4089 | 413 |
by (asm_simp_tac (simpset() addsimps [diff_mult_distrib2, |
3366 | 414 |
mult_mod_distrib, add_mult_distrib2]) 1); |
415 |
qed "dvd_mod"; |
|
416 |
||
5069 | 417 |
Goal "!!k. [| k dvd (m mod n); k dvd n; 0<n |] ==> k dvd m"; |
3366 | 418 |
by (subgoal_tac "k dvd ((m div n)*n + m mod n)" 1); |
4089 | 419 |
by (asm_simp_tac (simpset() addsimps [dvd_add, dvd_mult]) 2); |
4356 | 420 |
by (asm_full_simp_tac (simpset() addsimps [mod_div_equality]) 1); |
3366 | 421 |
qed "dvd_mod_imp_dvd"; |
422 |
||
5069 | 423 |
Goalw [dvd_def] "!!k m n. [| (k*m) dvd (k*n); 0<k |] ==> m dvd n"; |
3366 | 424 |
by (etac exE 1); |
4089 | 425 |
by (asm_full_simp_tac (simpset() addsimps mult_ac) 1); |
3366 | 426 |
by (Blast_tac 1); |
427 |
qed "dvd_mult_cancel"; |
|
428 |
||
5069 | 429 |
Goalw [dvd_def] "!!i j. [| i dvd m; j dvd n|] ==> (i*j) dvd (m*n)"; |
3718 | 430 |
by (Clarify_tac 1); |
3366 | 431 |
by (res_inst_tac [("x","k*ka")] exI 1); |
4089 | 432 |
by (asm_simp_tac (simpset() addsimps mult_ac) 1); |
3366 | 433 |
qed "mult_dvd_mono"; |
434 |
||
5069 | 435 |
Goalw [dvd_def] "!!c. (i*j) dvd k ==> i dvd k"; |
4089 | 436 |
by (full_simp_tac (simpset() addsimps [mult_assoc]) 1); |
3366 | 437 |
by (Blast_tac 1); |
438 |
qed "dvd_mult_left"; |
|
439 |
||
5069 | 440 |
Goalw [dvd_def] "!!n. [| k dvd n; 0 < n |] ==> k <= n"; |
3718 | 441 |
by (Clarify_tac 1); |
4089 | 442 |
by (ALLGOALS (full_simp_tac (simpset() addsimps [zero_less_mult_iff]))); |
3457 | 443 |
by (etac conjE 1); |
444 |
by (rtac le_trans 1); |
|
445 |
by (rtac (le_refl RS mult_le_mono) 2); |
|
3366 | 446 |
by (etac Suc_leI 2); |
447 |
by (Simp_tac 1); |
|
448 |
qed "dvd_imp_le"; |
|
449 |
||
5069 | 450 |
Goalw [dvd_def] "!!k. 0<k ==> (k dvd n) = (n mod k = 0)"; |
3724 | 451 |
by Safe_tac; |
3366 | 452 |
by (stac mult_commute 1); |
453 |
by (Asm_simp_tac 1); |
|
454 |
by (eres_inst_tac [("t","n")] (mod_div_equality RS subst) 1); |
|
4089 | 455 |
by (asm_simp_tac (simpset() addsimps [mult_commute]) 1); |
3366 | 456 |
by (Blast_tac 1); |
457 |
qed "dvd_eq_mod_eq_0"; |