author | wenzelm |
Sat, 04 Apr 1998 12:28:39 +0200 | |
changeset 4793 | 03fd006fb97b |
parent 4774 | b4760a833480 |
child 4810 | d55e2fee2084 |
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 |
||
25 |
goal thy "(%m. m mod n) = wfrec (trancl pred_nat) \ |
|
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 |
||
30 |
goal thy "!!m. m<n ==> m mod n = m"; |
|
31 |
by (rtac (mod_eq RS wf_less_trans) 1); |
|
32 |
by (Asm_simp_tac 1); |
|
33 |
qed "mod_less"; |
|
34 |
||
35 |
goal thy "!!m. [| 0<n; ~m<n |] ==> m mod n = (m-n) mod n"; |
|
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*) |
41 |
goal thy "!!m. 0<n ==> m mod n = (if m<n then m else (m-n) mod n)"; |
|
42 |
by (asm_simp_tac (simpset() addsimps [mod_less, mod_geq]) 1); |
|
43 |
qed "mod_if"; |
|
44 |
||
3366 | 45 |
goal thy "m mod 1 = 0"; |
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 |
||
51 |
goal thy "!!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 |
||
55 |
goal thy "!!n. 0<n ==> (m+n) mod n = m mod n"; |
|
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]))); |
3366 | 59 |
qed "mod_eq_add"; |
60 |
||
61 |
goal thy "!!k. [| 0<k; 0<n |] ==> (m mod n)*k = (m*k) mod (n*k)"; |
|
62 |
by (res_inst_tac [("n","m")] less_induct 1); |
|
4774 | 63 |
by (stac mod_if 1); |
64 |
by (Asm_simp_tac 1); |
|
65 |
by (asm_simp_tac (simpset() addsimps [mod_less, mod_geq, |
|
66 |
diff_less, diff_mult_distrib]) 1); |
|
3366 | 67 |
qed "mod_mult_distrib"; |
68 |
||
69 |
goal thy "!!k. [| 0<k; 0<n |] ==> k*(m mod n) = (k*m) mod (k*n)"; |
|
70 |
by (res_inst_tac [("n","m")] less_induct 1); |
|
4774 | 71 |
by (stac mod_if 1); |
72 |
by (Asm_simp_tac 1); |
|
73 |
by (asm_simp_tac (simpset() addsimps [mod_less, mod_geq, |
|
74 |
diff_less, diff_mult_distrib2]) 1); |
|
3366 | 75 |
qed "mod_mult_distrib2"; |
76 |
||
77 |
goal thy "!!n. 0<n ==> m*n mod n = 0"; |
|
78 |
by (induct_tac "m" 1); |
|
4089 | 79 |
by (asm_simp_tac (simpset() addsimps [mod_less]) 1); |
3366 | 80 |
by (dres_inst_tac [("m","m*n")] mod_eq_add 1); |
4089 | 81 |
by (asm_full_simp_tac (simpset() addsimps [add_commute]) 1); |
3366 | 82 |
qed "mod_mult_self_is_0"; |
83 |
Addsimps [mod_mult_self_is_0]; |
|
84 |
||
85 |
(*** Quotient ***) |
|
86 |
||
87 |
goal thy "(%m. m div n) = wfrec (trancl pred_nat) \ |
|
88 |
\ (%f j. if j<n then 0 else Suc (f (j-n)))"; |
|
4089 | 89 |
by (simp_tac (simpset() addsimps [div_def]) 1); |
3366 | 90 |
qed "div_eq"; |
91 |
||
92 |
goal thy "!!m. m<n ==> m div n = 0"; |
|
93 |
by (rtac (div_eq RS wf_less_trans) 1); |
|
94 |
by (Asm_simp_tac 1); |
|
95 |
qed "div_less"; |
|
96 |
||
97 |
goal thy "!!M. [| 0<n; ~m<n |] ==> m div n = Suc((m-n) div n)"; |
|
98 |
by (rtac (div_eq RS wf_less_trans) 1); |
|
4089 | 99 |
by (asm_simp_tac (simpset() addsimps [diff_less, cut_apply, less_eq]) 1); |
3366 | 100 |
qed "div_geq"; |
101 |
||
4774 | 102 |
(*NOT suitable for rewriting: loops*) |
103 |
goal thy "!!m. 0<n ==> m div n = (if m<n then 0 else Suc((m-n) div n))"; |
|
104 |
by (asm_simp_tac (simpset() addsimps [div_less, div_geq]) 1); |
|
105 |
qed "div_if"; |
|
106 |
||
3366 | 107 |
(*Main Result about quotient and remainder.*) |
108 |
goal thy "!!m. 0<n ==> (m div n)*n + m mod n = m"; |
|
109 |
by (res_inst_tac [("n","m")] less_induct 1); |
|
4774 | 110 |
by (stac mod_if 1); |
111 |
by (ALLGOALS (asm_simp_tac |
|
112 |
(simpset() addsimps ([add_assoc] @ |
|
113 |
[div_less, div_geq, |
|
114 |
add_diff_inverse, diff_less])))); |
|
3366 | 115 |
qed "mod_div_equality"; |
116 |
||
4358 | 117 |
(* a simple rearrangement of mod_div_equality: *) |
118 |
goal thy "!!k. 0<k ==> k*(m div k) = m - (m mod k)"; |
|
4423 | 119 |
by (dres_inst_tac [("m","m")] mod_div_equality 1); |
4358 | 120 |
by (EVERY1[etac subst, simp_tac (simpset() addsimps mult_ac), |
121 |
K(IF_UNSOLVED no_tac)]); |
|
122 |
qed "mult_div_cancel"; |
|
123 |
||
3366 | 124 |
goal thy "m div 1 = m"; |
125 |
by (induct_tac "m" 1); |
|
4089 | 126 |
by (ALLGOALS (asm_simp_tac (simpset() addsimps [div_less, div_geq]))); |
3366 | 127 |
qed "div_1"; |
128 |
Addsimps [div_1]; |
|
129 |
||
130 |
goal thy "!!n. 0<n ==> n div n = 1"; |
|
4089 | 131 |
by (asm_simp_tac (simpset() addsimps [div_less, div_geq]) 1); |
3366 | 132 |
qed "div_self"; |
133 |
||
3484
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
134 |
(* Monotonicity of div in first argument *) |
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
135 |
goal thy "!!n. 0<k ==> ALL m. m <= n --> (m div k) <= (n div k)"; |
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
136 |
by (res_inst_tac [("n","n")] less_induct 1); |
3718 | 137 |
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
|
138 |
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
|
139 |
(* 1 case n<k *) |
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
140 |
by (subgoal_tac "m<k" 1); |
4089 | 141 |
by (asm_simp_tac (simpset() addsimps [div_less]) 1); |
3496 | 142 |
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
|
143 |
(* 2 case n >= k *) |
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
144 |
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
|
145 |
(* 2.1 case m<k *) |
4089 | 146 |
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
|
147 |
(* 2.2 case m>=k *) |
4089 | 148 |
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
|
149 |
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
|
150 |
|
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
151 |
|
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
152 |
(* Antimonotonicity of div in second argument *) |
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
153 |
goal thy "!!k m n. [| 0<m; m<=n |] ==> (k div n) <= (k div m)"; |
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
154 |
by (subgoal_tac "0<n" 1); |
3496 | 155 |
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
|
156 |
by (res_inst_tac [("n","k")] less_induct 1); |
3496 | 157 |
by (Simp_tac 1); |
158 |
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
|
159 |
by (case_tac "k<n" 1); |
4089 | 160 |
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
|
161 |
by (subgoal_tac "~(k<m)" 1); |
3496 | 162 |
by (trans_tac 2); |
4089 | 163 |
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
|
164 |
by (subgoal_tac "(k-n) div n <= (k-m) div n" 1); |
4089 | 165 |
by (best_tac (claset() addIs [le_trans] |
166 |
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
|
167 |
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
|
168 |
qed "div_le_mono2"; |
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
169 |
|
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
170 |
goal thy "!!m n. 0<n ==> m div n <= m"; |
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
171 |
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
|
172 |
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
|
173 |
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
|
174 |
by (ALLGOALS trans_tac); |
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
175 |
qed "div_le_dividend"; |
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
176 |
Addsimps [div_le_dividend]; |
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
177 |
|
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
178 |
(* Similar for "less than" *) |
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
179 |
goal thy "!!m n. 1<n ==> (0 < m) --> (m div n < m)"; |
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
180 |
by (res_inst_tac [("n","m")] less_induct 1); |
3496 | 181 |
by (Simp_tac 1); |
182 |
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
|
183 |
by (case_tac "m<n" 1); |
4089 | 184 |
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
|
185 |
by (subgoal_tac "0<n" 1); |
3496 | 186 |
by (trans_tac 2); |
4089 | 187 |
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
|
188 |
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
|
189 |
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
|
190 |
by (REPEAT (ares_tac [impI,less_trans_Suc] 1)); |
4089 | 191 |
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
|
192 |
by (dres_inst_tac [("m","n")] less_imp_diff_positive 1); |
4089 | 193 |
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
|
194 |
(* case n=m *) |
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
195 |
by (subgoal_tac "m=n" 1); |
3496 | 196 |
by (trans_tac 2); |
4089 | 197 |
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
|
198 |
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
|
199 |
Addsimps [div_less_dividend]; |
3366 | 200 |
|
201 |
(*** Further facts about mod (mainly for the mutilated chess board ***) |
|
202 |
||
203 |
goal thy |
|
204 |
"!!m n. 0<n ==> \ |
|
205 |
\ Suc(m) mod n = (if Suc(m mod n) = n then 0 else Suc(m mod n))"; |
|
206 |
by (res_inst_tac [("n","m")] less_induct 1); |
|
207 |
by (excluded_middle_tac "Suc(na)<n" 1); |
|
208 |
(* case Suc(na) < n *) |
|
209 |
by (forward_tac [lessI RS less_trans] 2); |
|
4089 | 210 |
by (asm_simp_tac (simpset() addsimps [mod_less, less_not_refl2 RS not_sym]) 2); |
3366 | 211 |
(* case n <= Suc(na) *) |
4089 | 212 |
by (asm_full_simp_tac (simpset() addsimps [not_less_iff_le, mod_geq]) 1); |
3366 | 213 |
by (etac (le_imp_less_or_eq RS disjE) 1); |
4089 | 214 |
by (asm_simp_tac (simpset() addsimps [Suc_diff_n]) 1); |
215 |
by (asm_full_simp_tac (simpset() addsimps [not_less_eq RS sym, |
|
3366 | 216 |
diff_less, mod_geq]) 1); |
4089 | 217 |
by (asm_simp_tac (simpset() addsimps [mod_less]) 1); |
3366 | 218 |
qed "mod_Suc"; |
219 |
||
220 |
goal thy "!!m n. 0<n ==> m mod n < n"; |
|
221 |
by (res_inst_tac [("n","m")] less_induct 1); |
|
222 |
by (excluded_middle_tac "na<n" 1); |
|
223 |
(*case na<n*) |
|
4089 | 224 |
by (asm_simp_tac (simpset() addsimps [mod_less]) 2); |
3366 | 225 |
(*case n le na*) |
4089 | 226 |
by (asm_full_simp_tac (simpset() addsimps [mod_geq, diff_less]) 1); |
3366 | 227 |
qed "mod_less_divisor"; |
228 |
||
229 |
||
230 |
(** Evens and Odds **) |
|
231 |
||
232 |
(*With less_zeroE, causes case analysis on b<2*) |
|
233 |
AddSEs [less_SucE]; |
|
234 |
||
235 |
goal thy "!!k b. b<2 ==> k mod 2 = b | k mod 2 = (if b=1 then 0 else 1)"; |
|
236 |
by (subgoal_tac "k mod 2 < 2" 1); |
|
4089 | 237 |
by (asm_simp_tac (simpset() addsimps [mod_less_divisor]) 2); |
4686 | 238 |
by (Asm_simp_tac 1); |
4356 | 239 |
by Safe_tac; |
3366 | 240 |
qed "mod2_cases"; |
241 |
||
242 |
goal thy "Suc(Suc(m)) mod 2 = m mod 2"; |
|
243 |
by (subgoal_tac "m mod 2 < 2" 1); |
|
4089 | 244 |
by (asm_simp_tac (simpset() addsimps [mod_less_divisor]) 2); |
3724 | 245 |
by Safe_tac; |
4089 | 246 |
by (ALLGOALS (asm_simp_tac (simpset() addsimps [mod_Suc]))); |
3366 | 247 |
qed "mod2_Suc_Suc"; |
248 |
Addsimps [mod2_Suc_Suc]; |
|
249 |
||
4385 | 250 |
goal Divides.thy "(0 < m mod 2) = (m mod 2 = 1)"; |
3366 | 251 |
by (subgoal_tac "m mod 2 < 2" 1); |
4089 | 252 |
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
|
253 |
by Auto_tac; |
4356 | 254 |
qed "mod2_gr_0"; |
255 |
Addsimps [mod2_gr_0]; |
|
256 |
||
3366 | 257 |
goal thy "(m+m) mod 2 = 0"; |
258 |
by (induct_tac "m" 1); |
|
4089 | 259 |
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
|
260 |
by (Asm_simp_tac 1); |
4385 | 261 |
qed "mod2_add_self_eq_0"; |
262 |
Addsimps [mod2_add_self_eq_0]; |
|
263 |
||
264 |
goal thy "((m+m)+n) mod 2 = n mod 2"; |
|
265 |
by (induct_tac "m" 1); |
|
266 |
by (simp_tac (simpset() addsimps [mod_less]) 1); |
|
267 |
by (Asm_simp_tac 1); |
|
3366 | 268 |
qed "mod2_add_self"; |
269 |
Addsimps [mod2_add_self]; |
|
270 |
||
271 |
Delrules [less_SucE]; |
|
272 |
||
273 |
||
274 |
(*** More division laws ***) |
|
275 |
||
276 |
goal thy "!!n. 0<n ==> m*n div n = m"; |
|
277 |
by (cut_inst_tac [("m", "m*n")] mod_div_equality 1); |
|
3457 | 278 |
by (assume_tac 1); |
4089 | 279 |
by (asm_full_simp_tac (simpset() addsimps [mod_mult_self_is_0]) 1); |
3366 | 280 |
qed "div_mult_self_is_m"; |
281 |
Addsimps [div_mult_self_is_m]; |
|
282 |
||
283 |
(*Cancellation law for division*) |
|
284 |
goal thy "!!k. [| 0<n; 0<k |] ==> (k*m) div (k*n) = m div n"; |
|
285 |
by (res_inst_tac [("n","m")] less_induct 1); |
|
286 |
by (case_tac "na<n" 1); |
|
4089 | 287 |
by (asm_simp_tac (simpset() addsimps [div_less, zero_less_mult_iff, |
3366 | 288 |
mult_less_mono2]) 1); |
289 |
by (subgoal_tac "~ k*na < k*n" 1); |
|
290 |
by (asm_simp_tac |
|
4089 | 291 |
(simpset() addsimps [zero_less_mult_iff, div_geq, |
3366 | 292 |
diff_mult_distrib2 RS sym, diff_less]) 1); |
4089 | 293 |
by (asm_full_simp_tac (simpset() addsimps [not_less_iff_le, |
3366 | 294 |
le_refl RS mult_le_mono]) 1); |
295 |
qed "div_cancel"; |
|
296 |
Addsimps [div_cancel]; |
|
297 |
||
298 |
goal thy "!!k. [| 0<n; 0<k |] ==> (k*m) mod (k*n) = k * (m mod n)"; |
|
299 |
by (res_inst_tac [("n","m")] less_induct 1); |
|
300 |
by (case_tac "na<n" 1); |
|
4089 | 301 |
by (asm_simp_tac (simpset() addsimps [mod_less, zero_less_mult_iff, |
3366 | 302 |
mult_less_mono2]) 1); |
303 |
by (subgoal_tac "~ k*na < k*n" 1); |
|
304 |
by (asm_simp_tac |
|
4089 | 305 |
(simpset() addsimps [zero_less_mult_iff, mod_geq, |
3366 | 306 |
diff_mult_distrib2 RS sym, diff_less]) 1); |
4089 | 307 |
by (asm_full_simp_tac (simpset() addsimps [not_less_iff_le, |
3366 | 308 |
le_refl RS mult_le_mono]) 1); |
309 |
qed "mult_mod_distrib"; |
|
310 |
||
311 |
||
312 |
(************************************************) |
|
313 |
(** Divides Relation **) |
|
314 |
(************************************************) |
|
315 |
||
316 |
goalw thy [dvd_def] "m dvd 0"; |
|
4089 | 317 |
by (blast_tac (claset() addIs [mult_0_right RS sym]) 1); |
3366 | 318 |
qed "dvd_0_right"; |
319 |
Addsimps [dvd_0_right]; |
|
320 |
||
321 |
goalw thy [dvd_def] "!!m. 0 dvd m ==> m = 0"; |
|
4089 | 322 |
by (fast_tac (claset() addss simpset()) 1); |
3366 | 323 |
qed "dvd_0_left"; |
324 |
||
325 |
goalw thy [dvd_def] "1 dvd k"; |
|
326 |
by (Simp_tac 1); |
|
327 |
qed "dvd_1_left"; |
|
328 |
AddIffs [dvd_1_left]; |
|
329 |
||
330 |
goalw thy [dvd_def] "m dvd m"; |
|
4089 | 331 |
by (blast_tac (claset() addIs [mult_1_right RS sym]) 1); |
3366 | 332 |
qed "dvd_refl"; |
333 |
Addsimps [dvd_refl]; |
|
334 |
||
335 |
goalw thy [dvd_def] "!!m n p. [| m dvd n; n dvd p |] ==> m dvd p"; |
|
4089 | 336 |
by (blast_tac (claset() addIs [mult_assoc] ) 1); |
3366 | 337 |
qed "dvd_trans"; |
338 |
||
339 |
goalw thy [dvd_def] "!!m n. [| m dvd n; n dvd m |] ==> m=n"; |
|
4089 | 340 |
by (fast_tac (claset() addDs [mult_eq_self_implies_10] |
341 |
addss (simpset() addsimps [mult_assoc, mult_eq_1_iff])) 1); |
|
3366 | 342 |
qed "dvd_anti_sym"; |
343 |
||
344 |
goalw thy [dvd_def] "!!k. [| k dvd m; k dvd n |] ==> k dvd (m + n)"; |
|
4089 | 345 |
by (blast_tac (claset() addIs [add_mult_distrib2 RS sym]) 1); |
3366 | 346 |
qed "dvd_add"; |
347 |
||
348 |
goalw thy [dvd_def] "!!k. [| k dvd m; k dvd n |] ==> k dvd (m-n)"; |
|
4089 | 349 |
by (blast_tac (claset() addIs [diff_mult_distrib2 RS sym]) 1); |
3366 | 350 |
qed "dvd_diff"; |
351 |
||
352 |
goal thy "!!k. [| k dvd (m-n); k dvd n; n<=m |] ==> k dvd m"; |
|
3457 | 353 |
by (etac (not_less_iff_le RS iffD2 RS add_diff_inverse RS subst) 1); |
4089 | 354 |
by (blast_tac (claset() addIs [dvd_add]) 1); |
3366 | 355 |
qed "dvd_diffD"; |
356 |
||
357 |
goalw thy [dvd_def] "!!k. k dvd n ==> k dvd (m*n)"; |
|
4089 | 358 |
by (blast_tac (claset() addIs [mult_left_commute]) 1); |
3366 | 359 |
qed "dvd_mult"; |
360 |
||
361 |
goal thy "!!k. k dvd m ==> k dvd (m*n)"; |
|
362 |
by (stac mult_commute 1); |
|
363 |
by (etac dvd_mult 1); |
|
364 |
qed "dvd_mult2"; |
|
365 |
||
366 |
(* k dvd (m*k) *) |
|
367 |
AddIffs [dvd_refl RS dvd_mult, dvd_refl RS dvd_mult2]; |
|
368 |
||
369 |
goalw thy [dvd_def] "!!m. [| f dvd m; f dvd n; 0<n |] ==> f dvd (m mod n)"; |
|
3718 | 370 |
by (Clarify_tac 1); |
4089 | 371 |
by (full_simp_tac (simpset() addsimps [zero_less_mult_iff]) 1); |
3366 | 372 |
by (res_inst_tac |
373 |
[("x", "(((k div ka)*ka + k mod ka) - ((f*k) div (f*ka)) * ka)")] |
|
374 |
exI 1); |
|
4089 | 375 |
by (asm_simp_tac (simpset() addsimps [diff_mult_distrib2, |
3366 | 376 |
mult_mod_distrib, add_mult_distrib2]) 1); |
377 |
qed "dvd_mod"; |
|
378 |
||
4356 | 379 |
goal thy "!!k. [| k dvd (m mod n); k dvd n; 0<n |] ==> k dvd m"; |
3366 | 380 |
by (subgoal_tac "k dvd ((m div n)*n + m mod n)" 1); |
4089 | 381 |
by (asm_simp_tac (simpset() addsimps [dvd_add, dvd_mult]) 2); |
4356 | 382 |
by (asm_full_simp_tac (simpset() addsimps [mod_div_equality]) 1); |
3366 | 383 |
qed "dvd_mod_imp_dvd"; |
384 |
||
385 |
goalw thy [dvd_def] "!!k m n. [| (k*m) dvd (k*n); 0<k |] ==> m dvd n"; |
|
386 |
by (etac exE 1); |
|
4089 | 387 |
by (asm_full_simp_tac (simpset() addsimps mult_ac) 1); |
3366 | 388 |
by (Blast_tac 1); |
389 |
qed "dvd_mult_cancel"; |
|
390 |
||
391 |
goalw thy [dvd_def] "!!i j. [| i dvd m; j dvd n|] ==> (i*j) dvd (m*n)"; |
|
3718 | 392 |
by (Clarify_tac 1); |
3366 | 393 |
by (res_inst_tac [("x","k*ka")] exI 1); |
4089 | 394 |
by (asm_simp_tac (simpset() addsimps mult_ac) 1); |
3366 | 395 |
qed "mult_dvd_mono"; |
396 |
||
397 |
goalw thy [dvd_def] "!!c. (i*j) dvd k ==> i dvd k"; |
|
4089 | 398 |
by (full_simp_tac (simpset() addsimps [mult_assoc]) 1); |
3366 | 399 |
by (Blast_tac 1); |
400 |
qed "dvd_mult_left"; |
|
401 |
||
402 |
goalw thy [dvd_def] "!!n. [| k dvd n; 0 < n |] ==> k <= n"; |
|
3718 | 403 |
by (Clarify_tac 1); |
4089 | 404 |
by (ALLGOALS (full_simp_tac (simpset() addsimps [zero_less_mult_iff]))); |
3457 | 405 |
by (etac conjE 1); |
406 |
by (rtac le_trans 1); |
|
407 |
by (rtac (le_refl RS mult_le_mono) 2); |
|
3366 | 408 |
by (etac Suc_leI 2); |
409 |
by (Simp_tac 1); |
|
410 |
qed "dvd_imp_le"; |
|
411 |
||
412 |
goalw thy [dvd_def] "!!k. 0<k ==> (k dvd n) = (n mod k = 0)"; |
|
3724 | 413 |
by Safe_tac; |
3366 | 414 |
by (stac mult_commute 1); |
415 |
by (Asm_simp_tac 1); |
|
416 |
by (eres_inst_tac [("t","n")] (mod_div_equality RS subst) 1); |
|
4089 | 417 |
by (asm_simp_tac (simpset() addsimps [mult_commute]) 1); |
3366 | 418 |
by (Blast_tac 1); |
419 |
qed "dvd_eq_mod_eq_0"; |