author | wenzelm |
Fri, 01 Dec 2000 19:43:06 +0100 | |
changeset 10569 | e8346dad78e1 |
parent 10559 | d3fd54fc659b |
child 10600 | 322475c2cb75 |
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 |
||
9108 | 12 |
bind_thm ("wf_less_trans", [eq_reflection, wf_pred_nat RS wf_trancl] MRS |
13 |
def_wfrec RS trans); |
|
3366 | 14 |
|
5069 | 15 |
Goal "(%m. m mod n) = wfrec (trancl pred_nat) \ |
7029
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
7007
diff
changeset
|
16 |
\ (%f j. if j<n | n=0 then j else f (j-n))"; |
4089 | 17 |
by (simp_tac (simpset() addsimps [mod_def]) 1); |
3366 | 18 |
qed "mod_eq"; |
19 |
||
7029
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
7007
diff
changeset
|
20 |
Goal "(%m. m div n) = wfrec (trancl pred_nat) \ |
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
7007
diff
changeset
|
21 |
\ (%f j. if j<n | n=0 then 0 else Suc (f (j-n)))"; |
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
7007
diff
changeset
|
22 |
by (simp_tac (simpset() addsimps [div_def]) 1); |
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
7007
diff
changeset
|
23 |
qed "div_eq"; |
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
7007
diff
changeset
|
24 |
|
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
7007
diff
changeset
|
25 |
|
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
7007
diff
changeset
|
26 |
(** Aribtrary definitions for division by zero. Useful to simplify |
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
7007
diff
changeset
|
27 |
certain equations **) |
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
7007
diff
changeset
|
28 |
|
8935
548901d05a0e
added type constraint ::nat because 0 is now overloaded
paulson
parents:
8860
diff
changeset
|
29 |
Goal "a div 0 = (0::nat)"; |
7029
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
7007
diff
changeset
|
30 |
by (rtac (div_eq RS wf_less_trans) 1); |
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
7007
diff
changeset
|
31 |
by (Asm_simp_tac 1); |
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
7007
diff
changeset
|
32 |
qed "DIVISION_BY_ZERO_DIV"; (*NOT for adding to default simpset*) |
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
7007
diff
changeset
|
33 |
|
8935
548901d05a0e
added type constraint ::nat because 0 is now overloaded
paulson
parents:
8860
diff
changeset
|
34 |
Goal "a mod 0 = (a::nat)"; |
7029
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
7007
diff
changeset
|
35 |
by (rtac (mod_eq RS wf_less_trans) 1); |
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
7007
diff
changeset
|
36 |
by (Asm_simp_tac 1); |
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
7007
diff
changeset
|
37 |
qed "DIVISION_BY_ZERO_MOD"; (*NOT for adding to default simpset*) |
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
7007
diff
changeset
|
38 |
|
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
7007
diff
changeset
|
39 |
fun div_undefined_case_tac s i = |
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
7007
diff
changeset
|
40 |
case_tac s i THEN |
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
7007
diff
changeset
|
41 |
Full_simp_tac (i+1) THEN |
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
7007
diff
changeset
|
42 |
asm_simp_tac (simpset() addsimps [DIVISION_BY_ZERO_DIV, |
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
7007
diff
changeset
|
43 |
DIVISION_BY_ZERO_MOD]) i; |
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
7007
diff
changeset
|
44 |
|
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
7007
diff
changeset
|
45 |
(*** Remainder ***) |
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
7007
diff
changeset
|
46 |
|
6865
5577ffe4c2f1
now div and mod are overloaded; dvd is polymorphic
paulson
parents:
6073
diff
changeset
|
47 |
Goal "m<n ==> m mod n = (m::nat)"; |
3366 | 48 |
by (rtac (mod_eq RS wf_less_trans) 1); |
49 |
by (Asm_simp_tac 1); |
|
50 |
qed "mod_less"; |
|
8393 | 51 |
Addsimps [mod_less]; |
3366 | 52 |
|
7029
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
7007
diff
changeset
|
53 |
Goal "~ m < (n::nat) ==> m mod n = (m-n) mod n"; |
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
7007
diff
changeset
|
54 |
by (div_undefined_case_tac "n=0" 1); |
3366 | 55 |
by (rtac (mod_eq RS wf_less_trans) 1); |
4089 | 56 |
by (asm_simp_tac (simpset() addsimps [diff_less, cut_apply, less_eq]) 1); |
3366 | 57 |
qed "mod_geq"; |
58 |
||
5415 | 59 |
(*Avoids the ugly ~m<n above*) |
7029
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
7007
diff
changeset
|
60 |
Goal "(n::nat) <= m ==> m mod n = (m-n) mod n"; |
5415 | 61 |
by (asm_simp_tac (simpset() addsimps [mod_geq, not_less_iff_le]) 1); |
62 |
qed "le_mod_geq"; |
|
63 |
||
7029
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
7007
diff
changeset
|
64 |
Goal "m mod (n::nat) = (if m<n then m else (m-n) mod n)"; |
8393 | 65 |
by (asm_simp_tac (simpset() addsimps [mod_geq]) 1); |
4774 | 66 |
qed "mod_if"; |
67 |
||
8935
548901d05a0e
added type constraint ::nat because 0 is now overloaded
paulson
parents:
8860
diff
changeset
|
68 |
Goal "m mod 1 = (0::nat)"; |
3366 | 69 |
by (induct_tac "m" 1); |
8393 | 70 |
by (ALLGOALS (asm_simp_tac (simpset() addsimps [mod_geq]))); |
3366 | 71 |
qed "mod_1"; |
72 |
Addsimps [mod_1]; |
|
73 |
||
8935
548901d05a0e
added type constraint ::nat because 0 is now overloaded
paulson
parents:
8860
diff
changeset
|
74 |
Goal "n mod n = (0::nat)"; |
7029
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
7007
diff
changeset
|
75 |
by (div_undefined_case_tac "n=0" 1); |
8393 | 76 |
by (asm_simp_tac (simpset() addsimps [mod_geq]) 1); |
3366 | 77 |
qed "mod_self"; |
10559
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
78 |
Addsimps [mod_self]; |
3366 | 79 |
|
7029
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
7007
diff
changeset
|
80 |
Goal "(m+n) mod n = m mod (n::nat)"; |
3366 | 81 |
by (subgoal_tac "(n + m) mod n = (n+m-n) mod n" 1); |
82 |
by (stac (mod_geq RS sym) 2); |
|
4089 | 83 |
by (ALLGOALS (asm_full_simp_tac (simpset() addsimps [add_commute]))); |
4811 | 84 |
qed "mod_add_self2"; |
4810 | 85 |
|
7029
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
7007
diff
changeset
|
86 |
Goal "(n+m) mod n = m mod (n::nat)"; |
4811 | 87 |
by (asm_simp_tac (simpset() addsimps [add_commute, mod_add_self2]) 1); |
88 |
qed "mod_add_self1"; |
|
4810 | 89 |
|
8783 | 90 |
Addsimps [mod_add_self1, mod_add_self2]; |
91 |
||
7029
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
7007
diff
changeset
|
92 |
Goal "(m + k*n) mod n = m mod (n::nat)"; |
4810 | 93 |
by (induct_tac "k" 1); |
7029
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
7007
diff
changeset
|
94 |
by (ALLGOALS |
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
7007
diff
changeset
|
95 |
(asm_simp_tac |
8783 | 96 |
(simpset() addsimps [read_instantiate [("y","n")] add_left_commute]))); |
4811 | 97 |
qed "mod_mult_self1"; |
4810 | 98 |
|
7029
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
7007
diff
changeset
|
99 |
Goal "(m + n*k) mod n = m mod (n::nat)"; |
4811 | 100 |
by (asm_simp_tac (simpset() addsimps [mult_commute, mod_mult_self1]) 1); |
101 |
qed "mod_mult_self2"; |
|
4810 | 102 |
|
4811 | 103 |
Addsimps [mod_mult_self1, mod_mult_self2]; |
3366 | 104 |
|
7029
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
7007
diff
changeset
|
105 |
Goal "(m mod n) * (k::nat) = (m*k) mod (n*k)"; |
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
7007
diff
changeset
|
106 |
by (div_undefined_case_tac "n=0" 1); |
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
7007
diff
changeset
|
107 |
by (div_undefined_case_tac "k=0" 1); |
9870 | 108 |
by (induct_thm_tac nat_less_induct "m" 1); |
4774 | 109 |
by (stac mod_if 1); |
110 |
by (Asm_simp_tac 1); |
|
8393 | 111 |
by (asm_simp_tac (simpset() addsimps [mod_geq, |
4774 | 112 |
diff_less, diff_mult_distrib]) 1); |
3366 | 113 |
qed "mod_mult_distrib"; |
114 |
||
7029
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
7007
diff
changeset
|
115 |
Goal "(k::nat) * (m mod n) = (k*m) mod (k*n)"; |
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
7007
diff
changeset
|
116 |
by (asm_simp_tac |
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
7007
diff
changeset
|
117 |
(simpset() addsimps [read_instantiate [("m","k")] mult_commute, |
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
7007
diff
changeset
|
118 |
mod_mult_distrib]) 1); |
3366 | 119 |
qed "mod_mult_distrib2"; |
120 |
||
8935
548901d05a0e
added type constraint ::nat because 0 is now overloaded
paulson
parents:
8860
diff
changeset
|
121 |
Goal "(m*n) mod n = (0::nat)"; |
7029
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
7007
diff
changeset
|
122 |
by (div_undefined_case_tac "n=0" 1); |
3366 | 123 |
by (induct_tac "m" 1); |
8393 | 124 |
by (Asm_simp_tac 1); |
7029
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
7007
diff
changeset
|
125 |
by (rename_tac "k" 1); |
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
7007
diff
changeset
|
126 |
by (cut_inst_tac [("m","k*n"),("n","n")] mod_add_self2 1); |
4089 | 127 |
by (asm_full_simp_tac (simpset() addsimps [add_commute]) 1); |
3366 | 128 |
qed "mod_mult_self_is_0"; |
7082 | 129 |
|
8935
548901d05a0e
added type constraint ::nat because 0 is now overloaded
paulson
parents:
8860
diff
changeset
|
130 |
Goal "(n*m) mod n = (0::nat)"; |
7082 | 131 |
by (simp_tac (simpset() addsimps [mult_commute, mod_mult_self_is_0]) 1); |
132 |
qed "mod_mult_self1_is_0"; |
|
133 |
Addsimps [mod_mult_self_is_0, mod_mult_self1_is_0]; |
|
3366 | 134 |
|
7029
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
7007
diff
changeset
|
135 |
|
3366 | 136 |
(*** Quotient ***) |
137 |
||
8935
548901d05a0e
added type constraint ::nat because 0 is now overloaded
paulson
parents:
8860
diff
changeset
|
138 |
Goal "m<n ==> m div n = (0::nat)"; |
3366 | 139 |
by (rtac (div_eq RS wf_less_trans) 1); |
140 |
by (Asm_simp_tac 1); |
|
141 |
qed "div_less"; |
|
8393 | 142 |
Addsimps [div_less]; |
3366 | 143 |
|
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5069
diff
changeset
|
144 |
Goal "[| 0<n; ~m<n |] ==> m div n = Suc((m-n) div n)"; |
3366 | 145 |
by (rtac (div_eq RS wf_less_trans) 1); |
4089 | 146 |
by (asm_simp_tac (simpset() addsimps [diff_less, cut_apply, less_eq]) 1); |
3366 | 147 |
qed "div_geq"; |
148 |
||
5415 | 149 |
(*Avoids the ugly ~m<n above*) |
150 |
Goal "[| 0<n; n<=m |] ==> m div n = Suc((m-n) div n)"; |
|
151 |
by (asm_simp_tac (simpset() addsimps [div_geq, not_less_iff_le]) 1); |
|
152 |
qed "le_div_geq"; |
|
153 |
||
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5069
diff
changeset
|
154 |
Goal "0<n ==> m div n = (if m<n then 0 else Suc((m-n) div n))"; |
8393 | 155 |
by (asm_simp_tac (simpset() addsimps [div_geq]) 1); |
4774 | 156 |
qed "div_if"; |
157 |
||
7029
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
7007
diff
changeset
|
158 |
|
3366 | 159 |
(*Main Result about quotient and remainder.*) |
7029
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
7007
diff
changeset
|
160 |
Goal "(m div n)*n + m mod n = (m::nat)"; |
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
7007
diff
changeset
|
161 |
by (div_undefined_case_tac "n=0" 1); |
9870 | 162 |
by (induct_thm_tac nat_less_induct "m" 1); |
4774 | 163 |
by (stac mod_if 1); |
164 |
by (ALLGOALS (asm_simp_tac |
|
8393 | 165 |
(simpset() addsimps [add_assoc, div_geq, |
5537 | 166 |
add_diff_inverse, diff_less]))); |
3366 | 167 |
qed "mod_div_equality"; |
168 |
||
4358 | 169 |
(* a simple rearrangement of mod_div_equality: *) |
7029
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
7007
diff
changeset
|
170 |
Goal "(n::nat) * (m div n) = m - (m mod n)"; |
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
7007
diff
changeset
|
171 |
by (cut_inst_tac [("m","m"),("n","n")] mod_div_equality 1); |
9912 | 172 |
by (full_simp_tac (simpset() addsimps mult_ac) 1); |
173 |
by (arith_tac 1); |
|
4358 | 174 |
qed "mult_div_cancel"; |
175 |
||
10559
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
176 |
Goal "0<n ==> m mod n < (n::nat)"; |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
177 |
by (induct_thm_tac nat_less_induct "m" 1); |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
178 |
by (case_tac "na<n" 1); |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
179 |
(*case n le na*) |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
180 |
by (asm_full_simp_tac (simpset() addsimps [mod_geq, diff_less]) 2); |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
181 |
(*case na<n*) |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
182 |
by (Asm_simp_tac 1); |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
183 |
qed "mod_less_divisor"; |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
184 |
Addsimps [mod_less_divisor]; |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
185 |
|
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
186 |
(*** More division laws ***) |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
187 |
|
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
188 |
Goal "0<n ==> (m*n) div n = (m::nat)"; |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
189 |
by (cut_inst_tac [("m", "m*n"),("n","n")] mod_div_equality 1); |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
190 |
by Auto_tac; |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
191 |
qed "div_mult_self_is_m"; |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
192 |
|
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
193 |
Goal "0<n ==> (n*m) div n = (m::nat)"; |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
194 |
by (asm_simp_tac (simpset() addsimps [mult_commute, div_mult_self_is_m]) 1); |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
195 |
qed "div_mult_self1_is_m"; |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
196 |
Addsimps [div_mult_self_is_m, div_mult_self1_is_m]; |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
197 |
|
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
198 |
(*mod_mult_distrib2 above is the counterpart for remainder*) |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
199 |
|
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
200 |
|
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
201 |
(*** Proving facts about div and mod using quorem ***) |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
202 |
|
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
203 |
Goal "[| b*q' + r' <= b*q + r; 0 < b; r < b |] \ |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
204 |
\ ==> q' <= (q::nat)"; |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
205 |
by (rtac leI 1); |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
206 |
by (stac less_iff_Suc_add 1); |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
207 |
by (auto_tac (claset(), simpset() addsimps [add_mult_distrib2])); |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
208 |
qed "unique_quotient_lemma"; |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
209 |
|
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
210 |
Goal "[| quorem ((a,b), (q,r)); quorem ((a,b), (q',r')); 0 < b |] \ |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
211 |
\ ==> q = q'"; |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
212 |
by (asm_full_simp_tac |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
213 |
(simpset() addsimps split_ifs @ [quorem_def]) 1); |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
214 |
by Auto_tac; |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
215 |
by (REPEAT |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
216 |
(blast_tac (claset() addIs [order_antisym] |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
217 |
addDs [order_eq_refl RS unique_quotient_lemma, |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
218 |
sym]) 1)); |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
219 |
qed "unique_quotient"; |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
220 |
|
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
221 |
Goal "[| quorem ((a,b), (q,r)); quorem ((a,b), (q',r')); 0 < b |] \ |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
222 |
\ ==> r = r'"; |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
223 |
by (subgoal_tac "q = q'" 1); |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
224 |
by (blast_tac (claset() addIs [unique_quotient]) 2); |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
225 |
by (asm_full_simp_tac (simpset() addsimps [quorem_def]) 1); |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
226 |
qed "unique_remainder"; |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
227 |
|
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
228 |
Goal "0 < b ==> quorem ((a, b), (a div b, a mod b))"; |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
229 |
by (cut_inst_tac [("m","a"),("n","b")] mod_div_equality 1); |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
230 |
by (auto_tac |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
231 |
(claset() addEs [sym], |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
232 |
simpset() addsimps mult_ac@[quorem_def])); |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
233 |
qed "quorem_div_mod"; |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
234 |
|
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
235 |
Goal "[| quorem((a,b),(q,r)); 0 < b |] ==> a div b = q"; |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
236 |
by (asm_simp_tac (simpset() addsimps [quorem_div_mod RS unique_quotient]) 1); |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
237 |
qed "quorem_div"; |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
238 |
|
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
239 |
Goal "[| quorem((a,b),(q,r)); 0 < b |] ==> a mod b = r"; |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
240 |
by (asm_simp_tac (simpset() addsimps [quorem_div_mod RS unique_remainder]) 1); |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
241 |
qed "quorem_mod"; |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
242 |
|
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
243 |
(** proving (a*b) div c = a * (b div c) + a * (b mod c) **) |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
244 |
|
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
245 |
Goal "[| quorem((b,c),(q,r)); 0 < c |] \ |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
246 |
\ ==> quorem ((a*b, c), (a*q + a*r div c, a*r mod c))"; |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
247 |
by (cut_inst_tac [("m", "a*r"), ("n","c")] mod_div_equality 1); |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
248 |
by (auto_tac |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
249 |
(claset(), |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
250 |
simpset() addsimps split_ifs@mult_ac@ |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
251 |
[quorem_def, add_mult_distrib2])); |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
252 |
val lemma = result(); |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
253 |
|
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
254 |
Goal "(a*b) div c = a*(b div c) + a*(b mod c) div (c::nat)"; |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
255 |
by (div_undefined_case_tac "c = 0" 1); |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
256 |
by (blast_tac (claset() addIs [quorem_div_mod RS lemma RS quorem_div]) 1); |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
257 |
qed "div_mult1_eq"; |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
258 |
|
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
259 |
Goal "(a*b) mod c = a*(b mod c) mod (c::nat)"; |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
260 |
by (div_undefined_case_tac "c = 0" 1); |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
261 |
by (blast_tac (claset() addIs [quorem_div_mod RS lemma RS quorem_mod]) 1); |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
262 |
qed "mod_mult1_eq"; |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
263 |
|
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
264 |
Goal "(a*b) mod (c::nat) = ((a mod c) * b) mod c"; |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
265 |
by (rtac trans 1); |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
266 |
by (res_inst_tac [("s","b*a mod c")] trans 1); |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
267 |
by (rtac mod_mult1_eq 2); |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
268 |
by (ALLGOALS (simp_tac (simpset() addsimps [mult_commute]))); |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
269 |
qed "mod_mult1_eq'"; |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
270 |
|
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
271 |
Goal "(a*b) mod (c::nat) = ((a mod c) * (b mod c)) mod c"; |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
272 |
by (rtac (mod_mult1_eq' RS trans) 1); |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
273 |
by (rtac mod_mult1_eq 1); |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
274 |
qed "mod_mult_distrib_mod"; |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
275 |
|
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
276 |
(** proving (a+b) div c = a div c + b div c + ((a mod c + b mod c) div c) **) |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
277 |
|
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
278 |
Goal "[| quorem((a,c),(aq,ar)); quorem((b,c),(bq,br)); 0 < c |] \ |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
279 |
\ ==> quorem ((a+b, c), (aq + bq + (ar+br) div c, (ar+br) mod c))"; |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
280 |
by (cut_inst_tac [("m", "ar+br"), ("n","c")] mod_div_equality 1); |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
281 |
by (auto_tac |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
282 |
(claset(), |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
283 |
simpset() addsimps split_ifs@mult_ac@ |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
284 |
[quorem_def, add_mult_distrib2])); |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
285 |
val lemma = result(); |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
286 |
|
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
287 |
(*NOT suitable for rewriting: the RHS has an instance of the LHS*) |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
288 |
Goal "(a+b) div (c::nat) = a div c + b div c + ((a mod c + b mod c) div c)"; |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
289 |
by (div_undefined_case_tac "c = 0" 1); |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
290 |
by (blast_tac (claset() addIs [[quorem_div_mod,quorem_div_mod] |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
291 |
MRS lemma RS quorem_div]) 1); |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
292 |
qed "div_add1_eq"; |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
293 |
|
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
294 |
Goal "(a+b) mod (c::nat) = (a mod c + b mod c) mod c"; |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
295 |
by (div_undefined_case_tac "c = 0" 1); |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
296 |
by (blast_tac (claset() addIs [[quorem_div_mod,quorem_div_mod] |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
297 |
MRS lemma RS quorem_mod]) 1); |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
298 |
qed "mod_add1_eq"; |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
299 |
|
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
300 |
|
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
301 |
(*** proving a div (b*c) = (a div b) div c ***) |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
302 |
|
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
303 |
(** first, two lemmas to bound the remainder for the cases b<0 and b>0 **) |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
304 |
|
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
305 |
Goal "[| (0::nat) < c; r < b |] ==> 0 <= b * (q mod c) + r"; |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
306 |
by (subgoal_tac "0 <= b * (q mod c)" 1); |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
307 |
by Auto_tac; |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
308 |
val lemma3 = result(); |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
309 |
|
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
310 |
Goal "[| (0::nat) < c; r < b |] ==> b * (q mod c) + r < b * c"; |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
311 |
by (cut_inst_tac [("m","q"),("n","c")] mod_less_divisor 1); |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
312 |
by (dres_inst_tac [("m","q mod c")] less_imp_Suc_add 2); |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
313 |
by Auto_tac; |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
314 |
by (eres_inst_tac [("P","%x. ?lhs < ?rhs x")] ssubst 1); |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
315 |
by (asm_simp_tac (simpset() addsimps [add_mult_distrib2]) 1); |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
316 |
val lemma4 = result(); |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
317 |
|
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
318 |
Goal "[| quorem ((a,b), (q,r)); 0 < b; 0 < c |] \ |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
319 |
\ ==> quorem ((a, b*c), (q div c, b*(q mod c) + r))"; |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
320 |
by (cut_inst_tac [("m", "q"), ("n","c")] mod_div_equality 1); |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
321 |
by (auto_tac |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
322 |
(claset(), |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
323 |
simpset() addsimps mult_ac@ |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
324 |
[quorem_def, add_mult_distrib2 RS sym, |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
325 |
lemma3, lemma4])); |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
326 |
val lemma = result(); |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
327 |
|
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
328 |
Goal "(0::nat) < c ==> a div (b*c) = (a div b) div c"; |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
329 |
by (div_undefined_case_tac "b = 0" 1); |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
330 |
by (force_tac (claset(), |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
331 |
simpset() addsimps [quorem_div_mod RS lemma RS quorem_div]) 1); |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
332 |
qed "div_mult2_eq"; |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
333 |
|
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
334 |
Goal "(0::nat) < c ==> a mod (b*c) = b*(a div b mod c) + a mod b"; |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
335 |
by (div_undefined_case_tac "b = 0" 1); |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
336 |
by (force_tac (claset(), |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
337 |
simpset() addsimps [quorem_div_mod RS lemma RS quorem_mod]) 1); |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
338 |
qed "mod_mult2_eq"; |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
339 |
|
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
340 |
|
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
341 |
(*** Cancellation of common factors in "div" ***) |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
342 |
|
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
343 |
Goal "[| (0::nat) < b; 0 < c |] ==> (c*a) div (c*b) = a div b"; |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
344 |
by (stac div_mult2_eq 1); |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
345 |
by Auto_tac; |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
346 |
val lemma1 = result(); |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
347 |
|
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
348 |
Goal "(0::nat) < c ==> (c*a) div (c*b) = a div b"; |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
349 |
by (div_undefined_case_tac "b = 0" 1); |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
350 |
by (auto_tac |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
351 |
(claset(), |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
352 |
simpset() addsimps [read_instantiate [("x", "b")] linorder_neq_iff, |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
353 |
lemma1, lemma2])); |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
354 |
qed "div_mult_mult1"; |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
355 |
|
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
356 |
Goal "(0::nat) < c ==> (a*c) div (b*c) = a div b"; |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
357 |
by (dtac div_mult_mult1 1); |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
358 |
by (auto_tac (claset(), simpset() addsimps [mult_commute])); |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
359 |
qed "div_mult_mult2"; |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
360 |
|
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
361 |
Addsimps [div_mult_mult1, div_mult_mult2]; |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
362 |
|
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
363 |
|
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
364 |
(*** Distribution of factors over "mod" |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
365 |
|
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
366 |
Could prove these as in Integ/IntDiv.ML, but we already have |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
367 |
mod_mult_distrib and mod_mult_distrib2 above! |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
368 |
|
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
369 |
Goal "(c*a) mod (c*b) = (c::nat) * (a mod b)"; |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
370 |
qed "mod_mult_mult1"; |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
371 |
|
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
372 |
Goal "(a*c) mod (b*c) = (a mod b) * (c::nat)"; |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
373 |
qed "mod_mult_mult2"; |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
374 |
***) |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
375 |
|
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
376 |
(*** Further facts about div and mod ***) |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
377 |
|
5069 | 378 |
Goal "m div 1 = m"; |
3366 | 379 |
by (induct_tac "m" 1); |
8393 | 380 |
by (ALLGOALS (asm_simp_tac (simpset() addsimps [div_geq]))); |
3366 | 381 |
qed "div_1"; |
382 |
Addsimps [div_1]; |
|
383 |
||
8935
548901d05a0e
added type constraint ::nat because 0 is now overloaded
paulson
parents:
8860
diff
changeset
|
384 |
Goal "0<n ==> n div n = (1::nat)"; |
8393 | 385 |
by (asm_simp_tac (simpset() addsimps [div_geq]) 1); |
3366 | 386 |
qed "div_self"; |
10559
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
387 |
Addsimps [div_self]; |
4811 | 388 |
|
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5069
diff
changeset
|
389 |
Goal "0<n ==> (m+n) div n = Suc (m div n)"; |
4811 | 390 |
by (subgoal_tac "(n + m) div n = Suc ((n+m-n) div n)" 1); |
391 |
by (stac (div_geq RS sym) 2); |
|
392 |
by (ALLGOALS (asm_full_simp_tac (simpset() addsimps [add_commute]))); |
|
393 |
qed "div_add_self2"; |
|
394 |
||
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5069
diff
changeset
|
395 |
Goal "0<n ==> (n+m) div n = Suc (m div n)"; |
4811 | 396 |
by (asm_simp_tac (simpset() addsimps [add_commute, div_add_self2]) 1); |
397 |
qed "div_add_self1"; |
|
398 |
||
8935
548901d05a0e
added type constraint ::nat because 0 is now overloaded
paulson
parents:
8860
diff
changeset
|
399 |
Goal "!!n::nat. 0<n ==> (m + k*n) div n = k + m div n"; |
10559
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
400 |
by (stac div_add1_eq 1); |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
401 |
by (stac div_mult1_eq 1); |
d3fd54fc659b
many new div and mod properties (borrowed from Integ/IntDiv)
paulson
parents:
10195
diff
changeset
|
402 |
by (Asm_simp_tac 1); |
4811 | 403 |
qed "div_mult_self1"; |
404 |
||
8935
548901d05a0e
added type constraint ::nat because 0 is now overloaded
paulson
parents:
8860
diff
changeset
|
405 |
Goal "0<n ==> (m + n*k) div n = k + m div (n::nat)"; |
4811 | 406 |
by (asm_simp_tac (simpset() addsimps [mult_commute, div_mult_self1]) 1); |
407 |
qed "div_mult_self2"; |
|
408 |
||
409 |
Addsimps [div_mult_self1, div_mult_self2]; |
|
410 |
||
7029
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
7007
diff
changeset
|
411 |
(** A dividend of zero **) |
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
7007
diff
changeset
|
412 |
|
8935
548901d05a0e
added type constraint ::nat because 0 is now overloaded
paulson
parents:
8860
diff
changeset
|
413 |
Goal "0 div m = (0::nat)"; |
7029
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
7007
diff
changeset
|
414 |
by (div_undefined_case_tac "m=0" 1); |
8393 | 415 |
by (Asm_simp_tac 1); |
7029
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
7007
diff
changeset
|
416 |
qed "div_0"; |
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
7007
diff
changeset
|
417 |
|
8935
548901d05a0e
added type constraint ::nat because 0 is now overloaded
paulson
parents:
8860
diff
changeset
|
418 |
Goal "0 mod m = (0::nat)"; |
7029
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
7007
diff
changeset
|
419 |
by (div_undefined_case_tac "m=0" 1); |
8393 | 420 |
by (Asm_simp_tac 1); |
7029
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
7007
diff
changeset
|
421 |
qed "mod_0"; |
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
7007
diff
changeset
|
422 |
Addsimps [div_0, mod_0]; |
4811 | 423 |
|
3484
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
424 |
(* Monotonicity of div in first argument *) |
7029
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
7007
diff
changeset
|
425 |
Goal "ALL m::nat. m <= n --> (m div k) <= (n div k)"; |
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
7007
diff
changeset
|
426 |
by (div_undefined_case_tac "k=0" 1); |
9870 | 427 |
by (induct_thm_tac nat_less_induct "n" 1); |
3718 | 428 |
by (Clarify_tac 1); |
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5069
diff
changeset
|
429 |
by (case_tac "n<k" 1); |
3484
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
430 |
(* 1 case n<k *) |
8393 | 431 |
by (Asm_simp_tac 1); |
3484
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
432 |
(* 2 case n >= k *) |
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
433 |
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
|
434 |
(* 2.1 case m<k *) |
8393 | 435 |
by (Asm_simp_tac 1); |
3484
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
436 |
(* 2.2 case m>=k *) |
4089 | 437 |
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
|
438 |
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
|
439 |
|
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
440 |
(* Antimonotonicity of div in second argument *) |
8935
548901d05a0e
added type constraint ::nat because 0 is now overloaded
paulson
parents:
8860
diff
changeset
|
441 |
Goal "!!m::nat. [| 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
|
442 |
by (subgoal_tac "0<n" 1); |
6073 | 443 |
by (Asm_simp_tac 2); |
9870 | 444 |
by (induct_thm_tac nat_less_induct "k" 1); |
3496 | 445 |
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
|
446 |
by (case_tac "k<n" 1); |
8393 | 447 |
by (Asm_simp_tac 1); |
3484
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
448 |
by (subgoal_tac "~(k<m)" 1); |
6073 | 449 |
by (Asm_simp_tac 2); |
4089 | 450 |
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
|
451 |
by (subgoal_tac "(k-n) div n <= (k-m) div n" 1); |
7029
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
7007
diff
changeset
|
452 |
by (REPEAT (ares_tac [div_le_mono,diff_le_mono2] 2)); |
5318 | 453 |
by (rtac le_trans 1); |
5316 | 454 |
by (Asm_simp_tac 1); |
455 |
by (asm_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
|
456 |
qed "div_le_mono2"; |
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
457 |
|
7029
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
7007
diff
changeset
|
458 |
Goal "m div n <= (m::nat)"; |
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
7007
diff
changeset
|
459 |
by (div_undefined_case_tac "n=0" 1); |
3484
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
460 |
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
|
461 |
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
|
462 |
by (rtac div_le_mono2 1); |
6073 | 463 |
by (ALLGOALS Asm_simp_tac); |
3484
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
464 |
qed "div_le_dividend"; |
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
465 |
Addsimps [div_le_dividend]; |
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
466 |
|
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
467 |
(* Similar for "less than" *) |
8935
548901d05a0e
added type constraint ::nat because 0 is now overloaded
paulson
parents:
8860
diff
changeset
|
468 |
Goal "!!n::nat. 1<n ==> (0 < m) --> (m div n < m)"; |
9870 | 469 |
by (induct_thm_tac nat_less_induct "m" 1); |
3496 | 470 |
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
|
471 |
by (case_tac "m<n" 1); |
8393 | 472 |
by (Asm_full_simp_tac 1); |
3484
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
473 |
by (subgoal_tac "0<n" 1); |
6073 | 474 |
by (Asm_simp_tac 2); |
4089 | 475 |
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
|
476 |
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
|
477 |
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
|
478 |
by (REPEAT (ares_tac [impI,less_trans_Suc] 1)); |
4089 | 479 |
by (asm_full_simp_tac (simpset() addsimps [diff_less]) 1); |
480 |
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
|
481 |
(* case n=m *) |
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
482 |
by (subgoal_tac "m=n" 1); |
6073 | 483 |
by (Asm_simp_tac 2); |
8393 | 484 |
by (Asm_simp_tac 1); |
3484
1e93eb09ebb9
Added the following lemmas tp Divides and a few others to Arith and NatDef:
nipkow
parents:
3457
diff
changeset
|
485 |
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
|
486 |
Addsimps [div_less_dividend]; |
3366 | 487 |
|
488 |
(*** Further facts about mod (mainly for the mutilated chess board ***) |
|
489 |
||
5278 | 490 |
Goal "0<n ==> Suc(m) mod n = (if Suc(m mod n) = n then 0 else Suc(m mod n))"; |
9870 | 491 |
by (induct_thm_tac nat_less_induct "m" 1); |
8860 | 492 |
by (case_tac "Suc(na)<n" 1); |
3366 | 493 |
(* case Suc(na) < n *) |
8860 | 494 |
by (forward_tac [lessI RS less_trans] 1 |
495 |
THEN asm_simp_tac (simpset() addsimps [less_not_refl3]) 1); |
|
3366 | 496 |
(* case n <= Suc(na) *) |
5415 | 497 |
by (asm_full_simp_tac (simpset() addsimps [not_less_iff_le, le_Suc_eq, |
498 |
mod_geq]) 1); |
|
8860 | 499 |
by (auto_tac (claset(), |
500 |
simpset() addsimps [Suc_diff_le, diff_less, le_mod_geq])); |
|
3366 | 501 |
qed "mod_Suc"; |
502 |
||
503 |
||
504 |
(************************************************) |
|
505 |
(** Divides Relation **) |
|
506 |
(************************************************) |
|
507 |
||
8935
548901d05a0e
added type constraint ::nat because 0 is now overloaded
paulson
parents:
8860
diff
changeset
|
508 |
Goalw [dvd_def] "m dvd (0::nat)"; |
4089 | 509 |
by (blast_tac (claset() addIs [mult_0_right RS sym]) 1); |
3366 | 510 |
qed "dvd_0_right"; |
7029
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
7007
diff
changeset
|
511 |
AddIffs [dvd_0_right]; |
3366 | 512 |
|
8935
548901d05a0e
added type constraint ::nat because 0 is now overloaded
paulson
parents:
8860
diff
changeset
|
513 |
Goalw [dvd_def] "0 dvd m ==> m = (0::nat)"; |
6865
5577ffe4c2f1
now div and mod are overloaded; dvd is polymorphic
paulson
parents:
6073
diff
changeset
|
514 |
by Auto_tac; |
3366 | 515 |
qed "dvd_0_left"; |
516 |
||
8935
548901d05a0e
added type constraint ::nat because 0 is now overloaded
paulson
parents:
8860
diff
changeset
|
517 |
Goalw [dvd_def] "1 dvd (k::nat)"; |
3366 | 518 |
by (Simp_tac 1); |
519 |
qed "dvd_1_left"; |
|
520 |
AddIffs [dvd_1_left]; |
|
521 |
||
6865
5577ffe4c2f1
now div and mod are overloaded; dvd is polymorphic
paulson
parents:
6073
diff
changeset
|
522 |
Goalw [dvd_def] "m dvd (m::nat)"; |
4089 | 523 |
by (blast_tac (claset() addIs [mult_1_right RS sym]) 1); |
3366 | 524 |
qed "dvd_refl"; |
525 |
Addsimps [dvd_refl]; |
|
526 |
||
6865
5577ffe4c2f1
now div and mod are overloaded; dvd is polymorphic
paulson
parents:
6073
diff
changeset
|
527 |
Goalw [dvd_def] "[| m dvd n; n dvd p |] ==> m dvd (p::nat)"; |
4089 | 528 |
by (blast_tac (claset() addIs [mult_assoc] ) 1); |
3366 | 529 |
qed "dvd_trans"; |
530 |
||
6865
5577ffe4c2f1
now div and mod are overloaded; dvd is polymorphic
paulson
parents:
6073
diff
changeset
|
531 |
Goalw [dvd_def] "[| m dvd n; n dvd m |] ==> m = (n::nat)"; |
5577ffe4c2f1
now div and mod are overloaded; dvd is polymorphic
paulson
parents:
6073
diff
changeset
|
532 |
by (force_tac (claset() addDs [mult_eq_self_implies_10], |
5577ffe4c2f1
now div and mod are overloaded; dvd is polymorphic
paulson
parents:
6073
diff
changeset
|
533 |
simpset() addsimps [mult_assoc, mult_eq_1_iff]) 1); |
3366 | 534 |
qed "dvd_anti_sym"; |
535 |
||
6865
5577ffe4c2f1
now div and mod are overloaded; dvd is polymorphic
paulson
parents:
6073
diff
changeset
|
536 |
Goalw [dvd_def] "[| k dvd m; k dvd n |] ==> k dvd (m+n :: nat)"; |
4089 | 537 |
by (blast_tac (claset() addIs [add_mult_distrib2 RS sym]) 1); |
3366 | 538 |
qed "dvd_add"; |
539 |
||
6865
5577ffe4c2f1
now div and mod are overloaded; dvd is polymorphic
paulson
parents:
6073
diff
changeset
|
540 |
Goalw [dvd_def] "[| k dvd m; k dvd n |] ==> k dvd (m-n :: nat)"; |
4089 | 541 |
by (blast_tac (claset() addIs [diff_mult_distrib2 RS sym]) 1); |
3366 | 542 |
qed "dvd_diff"; |
543 |
||
6865
5577ffe4c2f1
now div and mod are overloaded; dvd is polymorphic
paulson
parents:
6073
diff
changeset
|
544 |
Goal "[| k dvd (m-n); k dvd n; n<=m |] ==> k dvd (m::nat)"; |
3457 | 545 |
by (etac (not_less_iff_le RS iffD2 RS add_diff_inverse RS subst) 1); |
4089 | 546 |
by (blast_tac (claset() addIs [dvd_add]) 1); |
3366 | 547 |
qed "dvd_diffD"; |
548 |
||
6865
5577ffe4c2f1
now div and mod are overloaded; dvd is polymorphic
paulson
parents:
6073
diff
changeset
|
549 |
Goalw [dvd_def] "k dvd n ==> k dvd (m*n :: nat)"; |
4089 | 550 |
by (blast_tac (claset() addIs [mult_left_commute]) 1); |
3366 | 551 |
qed "dvd_mult"; |
552 |
||
6865
5577ffe4c2f1
now div and mod are overloaded; dvd is polymorphic
paulson
parents:
6073
diff
changeset
|
553 |
Goal "k dvd m ==> k dvd (m*n :: nat)"; |
3366 | 554 |
by (stac mult_commute 1); |
555 |
by (etac dvd_mult 1); |
|
556 |
qed "dvd_mult2"; |
|
557 |
||
558 |
(* k dvd (m*k) *) |
|
559 |
AddIffs [dvd_refl RS dvd_mult, dvd_refl RS dvd_mult2]; |
|
560 |
||
7493 | 561 |
Goal "k dvd (n + k) = k dvd (n::nat)"; |
7499 | 562 |
by (rtac iffI 1); |
563 |
by (etac dvd_add 2); |
|
564 |
by (rtac dvd_refl 2); |
|
7493 | 565 |
by (subgoal_tac "n = (n+k)-k" 1); |
566 |
by (Simp_tac 2); |
|
7499 | 567 |
by (etac ssubst 1); |
568 |
by (etac dvd_diff 1); |
|
569 |
by (rtac dvd_refl 1); |
|
7493 | 570 |
qed "dvd_reduce"; |
571 |
||
8935
548901d05a0e
added type constraint ::nat because 0 is now overloaded
paulson
parents:
8860
diff
changeset
|
572 |
Goalw [dvd_def] "!!n::nat. [| f dvd m; f dvd n; 0<n |] ==> f dvd (m mod n)"; |
3718 | 573 |
by (Clarify_tac 1); |
7029
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
7007
diff
changeset
|
574 |
by (Full_simp_tac 1); |
3366 | 575 |
by (res_inst_tac |
576 |
[("x", "(((k div ka)*ka + k mod ka) - ((f*k) div (f*ka)) * ka)")] |
|
577 |
exI 1); |
|
7029
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
7007
diff
changeset
|
578 |
by (asm_simp_tac |
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
7007
diff
changeset
|
579 |
(simpset() addsimps [diff_mult_distrib2, mod_mult_distrib2 RS sym, |
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
7007
diff
changeset
|
580 |
add_mult_distrib2]) 1); |
3366 | 581 |
qed "dvd_mod"; |
582 |
||
7029
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
7007
diff
changeset
|
583 |
Goal "[| (k::nat) dvd (m mod n); k dvd n |] ==> k dvd m"; |
3366 | 584 |
by (subgoal_tac "k dvd ((m div n)*n + m mod n)" 1); |
4089 | 585 |
by (asm_simp_tac (simpset() addsimps [dvd_add, dvd_mult]) 2); |
4356 | 586 |
by (asm_full_simp_tac (simpset() addsimps [mod_div_equality]) 1); |
3366 | 587 |
qed "dvd_mod_imp_dvd"; |
588 |
||
9881 | 589 |
Goalw [dvd_def] "!!n::nat. [| f dvd m; f dvd n |] ==> f dvd (m mod n)"; |
590 |
by (div_undefined_case_tac "n=0" 1); |
|
591 |
by (Clarify_tac 1); |
|
592 |
by (Full_simp_tac 1); |
|
593 |
by (rename_tac "j" 1); |
|
594 |
by (res_inst_tac |
|
595 |
[("x", "(((k div j)*j + k mod j) - ((f*k) div (f*j)) * j)")] |
|
596 |
exI 1); |
|
597 |
by (asm_simp_tac |
|
598 |
(simpset() addsimps [diff_mult_distrib2, mod_mult_distrib2 RS sym, |
|
599 |
add_mult_distrib2]) 1); |
|
600 |
qed "dvd_mod"; |
|
601 |
||
602 |
Goal "k dvd n ==> (k::nat) dvd (m mod n) = k dvd m"; |
|
603 |
by (blast_tac (claset() addIs [dvd_mod_imp_dvd, dvd_mod]) 1); |
|
604 |
qed "dvd_mod_iff"; |
|
605 |
||
6865
5577ffe4c2f1
now div and mod are overloaded; dvd is polymorphic
paulson
parents:
6073
diff
changeset
|
606 |
Goalw [dvd_def] "!!k::nat. [| (k*m) dvd (k*n); 0<k |] ==> m dvd n"; |
3366 | 607 |
by (etac exE 1); |
4089 | 608 |
by (asm_full_simp_tac (simpset() addsimps mult_ac) 1); |
3366 | 609 |
qed "dvd_mult_cancel"; |
610 |
||
6865
5577ffe4c2f1
now div and mod are overloaded; dvd is polymorphic
paulson
parents:
6073
diff
changeset
|
611 |
Goalw [dvd_def] "[| i dvd m; j dvd n|] ==> (i*j) dvd (m*n :: nat)"; |
3718 | 612 |
by (Clarify_tac 1); |
3366 | 613 |
by (res_inst_tac [("x","k*ka")] exI 1); |
4089 | 614 |
by (asm_simp_tac (simpset() addsimps mult_ac) 1); |
3366 | 615 |
qed "mult_dvd_mono"; |
616 |
||
6865
5577ffe4c2f1
now div and mod are overloaded; dvd is polymorphic
paulson
parents:
6073
diff
changeset
|
617 |
Goalw [dvd_def] "(i*j :: nat) dvd k ==> i dvd k"; |
4089 | 618 |
by (full_simp_tac (simpset() addsimps [mult_assoc]) 1); |
3366 | 619 |
by (Blast_tac 1); |
620 |
qed "dvd_mult_left"; |
|
621 |
||
8935
548901d05a0e
added type constraint ::nat because 0 is now overloaded
paulson
parents:
8860
diff
changeset
|
622 |
Goalw [dvd_def] "[| k dvd n; 0 < n |] ==> k <= (n::nat)"; |
3718 | 623 |
by (Clarify_tac 1); |
4089 | 624 |
by (ALLGOALS (full_simp_tac (simpset() addsimps [zero_less_mult_iff]))); |
3457 | 625 |
by (etac conjE 1); |
626 |
by (rtac le_trans 1); |
|
627 |
by (rtac (le_refl RS mult_le_mono) 2); |
|
3366 | 628 |
by (etac Suc_leI 2); |
629 |
by (Simp_tac 1); |
|
630 |
qed "dvd_imp_le"; |
|
631 |
||
8935
548901d05a0e
added type constraint ::nat because 0 is now overloaded
paulson
parents:
8860
diff
changeset
|
632 |
Goalw [dvd_def] "!!k::nat. (k dvd n) = (n mod k = 0)"; |
7029
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
7007
diff
changeset
|
633 |
by (div_undefined_case_tac "k=0" 1); |
3724 | 634 |
by Safe_tac; |
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5069
diff
changeset
|
635 |
by (asm_simp_tac (simpset() addsimps [mult_commute]) 1); |
7029
08d4eb8500dd
new division laws taking advantage of (m div 0) = 0 and (m mod 0) = m
paulson
parents:
7007
diff
changeset
|
636 |
by (res_inst_tac [("t","n"),("n1","k")] (mod_div_equality RS subst) 1); |
3366 | 637 |
by (stac mult_commute 1); |
638 |
by (Asm_simp_tac 1); |
|
639 |
qed "dvd_eq_mod_eq_0"; |
|
10195
325b6279ae4f
new theorems mod_eq_0_iff and mod_eqD; also new SD rule
paulson
parents:
9912
diff
changeset
|
640 |
|
325b6279ae4f
new theorems mod_eq_0_iff and mod_eqD; also new SD rule
paulson
parents:
9912
diff
changeset
|
641 |
Goal "(m mod d = 0) = (EX q::nat. m = d*q)"; |
325b6279ae4f
new theorems mod_eq_0_iff and mod_eqD; also new SD rule
paulson
parents:
9912
diff
changeset
|
642 |
by (auto_tac (claset(), |
325b6279ae4f
new theorems mod_eq_0_iff and mod_eqD; also new SD rule
paulson
parents:
9912
diff
changeset
|
643 |
simpset() addsimps [dvd_eq_mod_eq_0 RS sym, dvd_def])); |
325b6279ae4f
new theorems mod_eq_0_iff and mod_eqD; also new SD rule
paulson
parents:
9912
diff
changeset
|
644 |
qed "mod_eq_0_iff"; |
325b6279ae4f
new theorems mod_eq_0_iff and mod_eqD; also new SD rule
paulson
parents:
9912
diff
changeset
|
645 |
AddSDs [mod_eq_0_iff RS iffD1]; |
325b6279ae4f
new theorems mod_eq_0_iff and mod_eqD; also new SD rule
paulson
parents:
9912
diff
changeset
|
646 |
|
325b6279ae4f
new theorems mod_eq_0_iff and mod_eqD; also new SD rule
paulson
parents:
9912
diff
changeset
|
647 |
(*Loses information, namely we also have r<d provided d is nonzero*) |
325b6279ae4f
new theorems mod_eq_0_iff and mod_eqD; also new SD rule
paulson
parents:
9912
diff
changeset
|
648 |
Goal "(m mod d = r) ==> EX q::nat. m = r + q*d"; |
325b6279ae4f
new theorems mod_eq_0_iff and mod_eqD; also new SD rule
paulson
parents:
9912
diff
changeset
|
649 |
by (cut_inst_tac [("m","m")] mod_div_equality 1); |
325b6279ae4f
new theorems mod_eq_0_iff and mod_eqD; also new SD rule
paulson
parents:
9912
diff
changeset
|
650 |
by (full_simp_tac (simpset() addsimps add_ac) 1); |
325b6279ae4f
new theorems mod_eq_0_iff and mod_eqD; also new SD rule
paulson
parents:
9912
diff
changeset
|
651 |
by (blast_tac (claset() addIs [sym]) 1); |
325b6279ae4f
new theorems mod_eq_0_iff and mod_eqD; also new SD rule
paulson
parents:
9912
diff
changeset
|
652 |
qed "mod_eqD"; |
325b6279ae4f
new theorems mod_eq_0_iff and mod_eqD; also new SD rule
paulson
parents:
9912
diff
changeset
|
653 |