12196
|
1 |
(* Title : Even.ML
|
|
2 |
Author : Jacques D. Fleuriot
|
|
3 |
Copyright : 1999 University of Edinburgh
|
|
4 |
Description : Even numbers defined
|
|
5 |
*)
|
|
6 |
|
|
7 |
Goal "even(Suc(Suc n)) = (even(n))";
|
|
8 |
by (Auto_tac);
|
|
9 |
qed "even_Suc_Suc";
|
|
10 |
Addsimps [even_Suc_Suc];
|
|
11 |
|
|
12 |
Goal "(even(n)) = (~odd(n))";
|
|
13 |
by (induct_tac "n" 1);
|
|
14 |
by (Auto_tac);
|
|
15 |
qed "even_not_odd";
|
|
16 |
|
|
17 |
Goal "(odd(n)) = (~even(n))";
|
|
18 |
by (simp_tac (simpset() addsimps [even_not_odd]) 1);
|
|
19 |
qed "odd_not_even";
|
|
20 |
|
|
21 |
Goal "even(2*n)";
|
|
22 |
by (induct_tac "n" 1);
|
|
23 |
by (Auto_tac);
|
|
24 |
qed "even_mult_two";
|
|
25 |
Addsimps [even_mult_two];
|
|
26 |
|
|
27 |
Goal "even(n*2)";
|
|
28 |
by (induct_tac "n" 1);
|
|
29 |
by (Auto_tac);
|
|
30 |
qed "even_mult_two'";
|
|
31 |
Addsimps [even_mult_two'];
|
|
32 |
|
|
33 |
Goal "even(n + n)";
|
|
34 |
by (induct_tac "n" 1);
|
|
35 |
by (Auto_tac);
|
|
36 |
qed "even_sum_self";
|
|
37 |
Addsimps [even_sum_self];
|
|
38 |
|
|
39 |
Goal "~odd(2*n)";
|
|
40 |
by (induct_tac "n" 1);
|
|
41 |
by Auto_tac;
|
|
42 |
qed "not_odd_self_mult2";
|
|
43 |
Addsimps [not_odd_self_mult2];
|
|
44 |
|
|
45 |
Goal "~odd(n + n)";
|
|
46 |
by (induct_tac "n" 1);
|
|
47 |
by Auto_tac;
|
|
48 |
qed "not_odd_sum_self";
|
|
49 |
Addsimps [not_odd_sum_self];
|
|
50 |
|
|
51 |
Goal "~even(Suc(n + n))";
|
|
52 |
by (induct_tac "n" 1);
|
|
53 |
by Auto_tac;
|
|
54 |
qed "not_even_Suc_sum_self";
|
|
55 |
Addsimps [not_even_Suc_sum_self];
|
|
56 |
|
|
57 |
Goal "odd(Suc(2*n))";
|
|
58 |
by (induct_tac "n" 1);
|
|
59 |
by (Auto_tac);
|
|
60 |
qed "odd_mult_two_add_one";
|
|
61 |
Addsimps [odd_mult_two_add_one];
|
|
62 |
|
|
63 |
Goal "odd(Suc(n + n))";
|
|
64 |
by (induct_tac "n" 1);
|
|
65 |
by (Auto_tac);
|
|
66 |
qed "odd_sum_Suc_self";
|
|
67 |
Addsimps [odd_sum_Suc_self];
|
|
68 |
|
|
69 |
Goal "even(Suc n) = odd(n)";
|
|
70 |
by (induct_tac "n" 1);
|
|
71 |
by (Auto_tac);
|
|
72 |
qed "even_Suc_odd_iff";
|
|
73 |
|
|
74 |
Goal "odd(Suc n) = even(n)";
|
|
75 |
by (induct_tac "n" 1);
|
|
76 |
by (Auto_tac);
|
|
77 |
qed "odd_Suc_even_iff";
|
|
78 |
|
|
79 |
Goal "even n | odd n";
|
|
80 |
by (simp_tac (simpset() addsimps [even_not_odd]) 1);
|
|
81 |
qed "even_odd_disj";
|
|
82 |
|
|
83 |
(* could be proved automatically before: spoiled by numeral arith! *)
|
|
84 |
Goal "EX m. (n = 2*m | n = Suc(2*m))";
|
|
85 |
by (induct_tac "n" 1 THEN Auto_tac);
|
|
86 |
by (res_inst_tac [("x","Suc m")] exI 1 THEN Auto_tac);
|
|
87 |
qed "nat_mult_two_Suc_disj";
|
|
88 |
|
|
89 |
Goal "even(n) = (EX m. n = 2*m)";
|
|
90 |
by (cut_inst_tac [("n","n")] nat_mult_two_Suc_disj 1);
|
|
91 |
by (Auto_tac);
|
|
92 |
qed "even_mult_two_ex";
|
|
93 |
|
|
94 |
Goal "odd(n) = (EX m. n = Suc (2*m))";
|
|
95 |
by (cut_inst_tac [("n","n")] nat_mult_two_Suc_disj 1);
|
|
96 |
by (Auto_tac);
|
|
97 |
qed "odd_Suc_mult_two_ex";
|
|
98 |
|
|
99 |
Goal "even(n) ==> even(m*n)";
|
|
100 |
by (auto_tac (claset(),
|
|
101 |
simpset() addsimps [add_mult_distrib2, even_mult_two_ex]));
|
|
102 |
qed "even_mult_even";
|
|
103 |
Addsimps [even_mult_even];
|
|
104 |
|
|
105 |
Goal "(m + m) div 2 = (m::nat)";
|
13153
|
106 |
by (arith_tac 1);
|
12196
|
107 |
qed "div_add_self_two_is_m";
|
|
108 |
Addsimps [div_add_self_two_is_m];
|
|
109 |
|
|
110 |
Goal "Suc(Suc(m*2)) div 2 = Suc m";
|
13153
|
111 |
by (arith_tac 1);
|
12196
|
112 |
qed "div_mult_self_Suc_Suc";
|
|
113 |
Addsimps [div_mult_self_Suc_Suc];
|
|
114 |
|
|
115 |
Goal "Suc(Suc(2*m)) div 2 = Suc m";
|
13153
|
116 |
by (arith_tac 1);
|
12196
|
117 |
qed "div_mult_self_Suc_Suc2";
|
|
118 |
Addsimps [div_mult_self_Suc_Suc2];
|
|
119 |
|
|
120 |
Goal "Suc(Suc(m + m)) div 2 = Suc m";
|
13153
|
121 |
by (arith_tac 1);
|
12196
|
122 |
qed "div_add_self_Suc_Suc";
|
|
123 |
Addsimps [div_add_self_Suc_Suc];
|
|
124 |
|
|
125 |
Goal "~ even n ==> (Suc n) div 2 = Suc((n - 1) div 2)";
|
|
126 |
by (auto_tac (claset(),simpset() addsimps [odd_not_even RS sym,
|
|
127 |
odd_Suc_mult_two_ex]));
|
|
128 |
qed "not_even_imp_Suc_Suc_diff_one_eq";
|
|
129 |
Addsimps [not_even_imp_Suc_Suc_diff_one_eq];
|
|
130 |
|
|
131 |
Goal "even(m + n) = (even m = even n)";
|
|
132 |
by (induct_tac "m" 1);
|
|
133 |
by Auto_tac;
|
|
134 |
qed "even_add";
|
|
135 |
AddIffs [even_add];
|
|
136 |
|
|
137 |
Goal "even(m * n) = (even m | even n)";
|
|
138 |
by (induct_tac "m" 1);
|
|
139 |
by Auto_tac;
|
|
140 |
qed "even_mult";
|
|
141 |
|
|
142 |
Goal "even (m ^ n) = (even m & n ~= 0)";
|
|
143 |
by (induct_tac "n" 1);
|
|
144 |
by (auto_tac (claset(),simpset() addsimps [even_mult]));
|
|
145 |
qed "even_pow";
|
|
146 |
AddIffs [even_pow];
|
|
147 |
|
|
148 |
Goal "odd(m + n) = (odd m ~= odd n)";
|
|
149 |
by (induct_tac "m" 1);
|
|
150 |
by Auto_tac;
|
|
151 |
qed "odd_add";
|
|
152 |
AddIffs [odd_add];
|
|
153 |
|
|
154 |
Goal "odd(m * n) = (odd m & odd n)";
|
|
155 |
by (induct_tac "m" 1);
|
|
156 |
by Auto_tac;
|
|
157 |
qed "odd_mult";
|
|
158 |
AddIffs [odd_mult];
|
|
159 |
|
|
160 |
Goal "odd (m ^ n) = (odd m | n = 0)";
|
|
161 |
by (induct_tac "n" 1);
|
|
162 |
by Auto_tac;
|
|
163 |
qed "odd_pow";
|
|
164 |
|
|
165 |
Goal "0 < n --> ~even (n + n - 1)";
|
|
166 |
by (induct_tac "n" 1);
|
|
167 |
by Auto_tac;
|
|
168 |
qed_spec_mp "not_even_2n_minus_1";
|
|
169 |
Addsimps [not_even_2n_minus_1];
|
|
170 |
|
|
171 |
Goal "Suc (2 * m) mod 2 = 1";
|
|
172 |
by (induct_tac "m" 1);
|
|
173 |
by (auto_tac (claset(),simpset() addsimps [mod_Suc]));
|
|
174 |
qed "mod_two_Suc_2m";
|
|
175 |
Addsimps [mod_two_Suc_2m];
|
|
176 |
|
|
177 |
Goal "(Suc (Suc (2 * m)) div 2) = Suc m";
|
13153
|
178 |
by (arith_tac 1);
|
12196
|
179 |
qed "div_two_Suc_Suc_2m";
|
|
180 |
Addsimps [div_two_Suc_Suc_2m];
|
|
181 |
|
|
182 |
Goal "even n ==> 2 * ((n + 1) div 2) = n";
|
|
183 |
by (auto_tac (claset(),simpset() addsimps [mult_div_cancel,
|
|
184 |
even_mult_two_ex]));
|
|
185 |
qed "lemma_even_div";
|
|
186 |
Addsimps [lemma_even_div];
|
|
187 |
|
|
188 |
Goal "~even n ==> 2 * ((n + 1) div 2) = Suc n";
|
|
189 |
by (auto_tac (claset(),simpset() addsimps [even_not_odd,
|
|
190 |
odd_Suc_mult_two_ex]));
|
|
191 |
qed "lemma_not_even_div";
|
|
192 |
Addsimps [lemma_not_even_div];
|
|
193 |
|
|
194 |
Goal "Suc n div 2 <= Suc (Suc n) div 2";
|
13153
|
195 |
by (arith_tac 1);
|
12196
|
196 |
qed "Suc_n_le_Suc_Suc_n_div_2";
|
|
197 |
Addsimps [Suc_n_le_Suc_Suc_n_div_2];
|
|
198 |
|
|
199 |
Goal "(0::nat) < n --> 0 < (n + 1) div 2";
|
13153
|
200 |
by (arith_tac 1);
|
12196
|
201 |
qed_spec_mp "Suc_n_div_2_gt_zero";
|
|
202 |
Addsimps [Suc_n_div_2_gt_zero];
|
|
203 |
|
|
204 |
Goal "0 < n & even n --> 1 < n";
|
|
205 |
by (induct_tac "n" 1);
|
|
206 |
by Auto_tac;
|
|
207 |
qed_spec_mp "even_gt_zero_gt_one";
|
|
208 |
bind_thm ("even_gt_zero_gt_one",conjI RS even_gt_zero_gt_one);
|
|
209 |
|
|
210 |
(* more general *)
|
|
211 |
Goal "n div 2 <= (Suc n) div 2";
|
13153
|
212 |
by (arith_tac 1);
|
12196
|
213 |
qed "le_Suc_n_div_2";
|
|
214 |
Addsimps [le_Suc_n_div_2];
|
|
215 |
|
|
216 |
Goal "(1::nat) < n --> 0 < n div 2";
|
13153
|
217 |
by (arith_tac 1);
|
12196
|
218 |
qed_spec_mp "div_2_gt_zero";
|
|
219 |
Addsimps [div_2_gt_zero];
|
|
220 |
|
|
221 |
Goal "even n ==> (n + 1) div 2 = n div 2";
|
|
222 |
by (rtac (CLAIM "2 * x = 2 * y ==> x = (y::nat)") 1);
|
12486
|
223 |
by (stac lemma_even_div 1);
|
12196
|
224 |
by (auto_tac (claset(),simpset() addsimps [even_mult_two_ex]));
|
|
225 |
qed "lemma_even_div2";
|
|
226 |
Addsimps [lemma_even_div2];
|
|
227 |
|
|
228 |
Goal "~even n ==> (n + 1) div 2 = Suc (n div 2)";
|
|
229 |
by (rtac (CLAIM "2 * x = 2 * y ==> x = (y::nat)") 1);
|
12486
|
230 |
by (stac lemma_not_even_div 1);
|
12196
|
231 |
by (auto_tac (claset(),simpset() addsimps [even_not_odd,
|
|
232 |
odd_Suc_mult_two_ex]));
|
|
233 |
by (cut_inst_tac [("m","Suc(2*m)"),("n","2")] mod_div_equality 1);
|
|
234 |
by Auto_tac;
|
|
235 |
qed "lemma_not_even_div2";
|
|
236 |
Addsimps [lemma_not_even_div2];
|
|
237 |
|
|
238 |
Goal "(Suc n) div 2 = 0 ==> even n";
|
|
239 |
by (rtac ccontr 1);
|
|
240 |
by (dtac lemma_not_even_div2 1 THEN Auto_tac);
|
|
241 |
qed "Suc_n_div_two_zero_even";
|
|
242 |
|
|
243 |
Goal "0 < n ==> even n = (~ even(n - 1))";
|
|
244 |
by (case_tac "n" 1);
|
|
245 |
by Auto_tac;
|
|
246 |
qed "even_num_iff";
|
|
247 |
|
|
248 |
Goal "0 < n ==> odd n = (~ odd(n - 1))";
|
|
249 |
by (case_tac "n" 1);
|
|
250 |
by Auto_tac;
|
|
251 |
qed "odd_num_iff";
|
|
252 |
|
|
253 |
(* Some mod and div stuff *)
|
|
254 |
|
|
255 |
Goal "n ~= (0::nat) ==> (m = m div n * n + m mod n) & m mod n < n";
|
13517
|
256 |
by (auto_tac (claset() addIs [mod_less_divisor],simpset()));
|
12196
|
257 |
qed "mod_div_eq_less";
|
|
258 |
|
|
259 |
Goal "(k*n + m) mod n = m mod (n::nat)";
|
|
260 |
by (simp_tac (simpset() addsimps mult_ac @ add_ac) 1);
|
|
261 |
qed "mod_mult_self3";
|
|
262 |
Addsimps [mod_mult_self3];
|
|
263 |
|
|
264 |
Goal "Suc (k*n + m) mod n = Suc m mod n";
|
|
265 |
by (rtac (CLAIM "Suc (m + n) = (m + Suc n)" RS ssubst) 1);
|
|
266 |
by (rtac mod_mult_self3 1);
|
|
267 |
qed "mod_mult_self4";
|
|
268 |
Addsimps [mod_mult_self4];
|
|
269 |
|
|
270 |
Goal "Suc m mod n = Suc (m mod n) mod n";
|
|
271 |
by (cut_inst_tac [("d'","Suc (m mod n) mod n")] (CLAIM "EX d. d' = d") 1);
|
|
272 |
by (etac exE 1);
|
|
273 |
by (Asm_simp_tac 1);
|
|
274 |
by (res_inst_tac [("t","m"),("n1","n")] (mod_div_equality RS subst) 1);
|
13517
|
275 |
by (auto_tac (claset(),simpset() delsimprocs [cancel_div_mod_proc]));
|
12196
|
276 |
qed "mod_Suc_eq_Suc_mod";
|
|
277 |
|
|
278 |
Goal "even n = (even (n mod 4))";
|
|
279 |
by (cut_inst_tac [("d'","(even (n mod 4))")] (CLAIM "EX d. d' = d") 1);
|
|
280 |
by (etac exE 1);
|
|
281 |
by (Asm_simp_tac 1);
|
|
282 |
by (res_inst_tac [("t","n"),("n1","4")] (mod_div_equality RS subst) 1);
|
13517
|
283 |
by (auto_tac (claset(),simpset() addsimps [even_mult,even_num_iff] delsimprocs [cancel_div_mod_proc]));
|
12196
|
284 |
qed "even_even_mod_4_iff";
|
|
285 |
|
|
286 |
Goal "odd n = (odd (n mod 4))";
|
|
287 |
by (auto_tac (claset(),simpset() addsimps [odd_not_even,
|
|
288 |
even_even_mod_4_iff RS sym]));
|
|
289 |
qed "odd_odd_mod_4_iff";
|
|
290 |
|
|
291 |
Goal "odd n ==> ((-1) ^ n) = (-1::real)";
|
|
292 |
by (auto_tac (claset(),simpset() addsimps [odd_Suc_mult_two_ex]));
|
|
293 |
qed "odd_realpow_minus_one";
|
|
294 |
Addsimps [odd_realpow_minus_one];
|
|
295 |
|
|
296 |
Goal "even(4*n)";
|
|
297 |
by (auto_tac (claset(),simpset() addsimps [even_mult_two_ex]));
|
|
298 |
qed "even_4n";
|
|
299 |
Addsimps [even_4n];
|
|
300 |
|
|
301 |
Goal "n mod 4 = 0 ==> even(n div 2)";
|
|
302 |
by Auto_tac;
|
|
303 |
qed "lemma_even_div_2";
|
|
304 |
|
|
305 |
Goal "n mod 4 = 0 ==> even(n)";
|
|
306 |
by Auto_tac;
|
|
307 |
qed "lemma_mod_4_even_n";
|
|
308 |
|
|
309 |
Goal "n mod 4 = 1 ==> odd(n)";
|
|
310 |
by (res_inst_tac [("t","n"),("n1","4")] (mod_div_equality RS subst) 1);
|
13517
|
311 |
by (auto_tac (claset(),simpset() addsimps [odd_num_iff] delsimprocs [cancel_div_mod_proc]));
|
12196
|
312 |
qed "lemma_mod_4_odd_n";
|
|
313 |
|
|
314 |
Goal "n mod 4 = 2 ==> even(n)";
|
|
315 |
by (res_inst_tac [("t","n"),("n1","4")] (mod_div_equality RS subst) 1);
|
13517
|
316 |
by (auto_tac (claset(),simpset() addsimps [even_num_iff] delsimprocs [cancel_div_mod_proc]));
|
12196
|
317 |
qed "lemma_mod_4_even_n2";
|
|
318 |
|
|
319 |
Goal "n mod 4 = 3 ==> odd(n)";
|
|
320 |
by (res_inst_tac [("t","n"),("n1","4")] (mod_div_equality RS subst) 1);
|
13517
|
321 |
by (auto_tac (claset(),simpset() addsimps [odd_num_iff] delsimprocs [cancel_div_mod_proc]));
|
12196
|
322 |
qed "lemma_mod_4_odd_n2";
|
|
323 |
|
|
324 |
Goal "even n ==> ((-1) ^ n) = (1::real)";
|
|
325 |
by (auto_tac (claset(),simpset() addsimps [even_mult_two_ex]));
|
|
326 |
qed "even_realpow_minus_one";
|
|
327 |
Addsimps [even_realpow_minus_one];
|
|
328 |
|
|
329 |
Goal "((4 * n) + 2) div 2 = (2::nat) * n + 1";
|
13153
|
330 |
by (arith_tac 1);
|
12196
|
331 |
qed "lemma_4n_add_2_div_2_eq";
|
|
332 |
Addsimps [lemma_4n_add_2_div_2_eq];
|
|
333 |
|
|
334 |
Goal "(Suc(Suc(4 * n))) div 2 = (2::nat) * n + 1";
|
13153
|
335 |
by (arith_tac 1);
|
12196
|
336 |
qed "lemma_Suc_Suc_4n_div_2_eq";
|
|
337 |
Addsimps [lemma_Suc_Suc_4n_div_2_eq];
|
|
338 |
|
|
339 |
Goal "(Suc(Suc(n * 4))) div 2 = (2::nat) * n + 1";
|
13153
|
340 |
by (arith_tac 1);
|
12196
|
341 |
qed "lemma_Suc_Suc_4n_div_2_eq2";
|
|
342 |
Addsimps [lemma_Suc_Suc_4n_div_2_eq2];
|
|
343 |
|
|
344 |
Goal "n mod 4 = 3 ==> odd((n - 1) div 2)";
|
|
345 |
by (res_inst_tac [("t","n"),("n1","4")] (mod_div_equality RS subst) 1);
|
13517
|
346 |
by (asm_full_simp_tac (simpset() addsimps [odd_num_iff] delsimprocs [cancel_div_mod_proc]) 1);
|
12196
|
347 |
val lemma_odd_mod_4_div_2 = result();
|
|
348 |
|
|
349 |
Goal "(4 * n) div 2 = (2::nat) * n";
|
13153
|
350 |
by (arith_tac 1);
|
12196
|
351 |
qed "lemma_4n_div_2_eq";
|
|
352 |
Addsimps [lemma_4n_div_2_eq];
|
|
353 |
|
|
354 |
Goal "(n * 4) div 2 = (2::nat) * n";
|
13153
|
355 |
by (arith_tac 1);
|
12196
|
356 |
qed "lemma_4n_div_2_eq2";
|
|
357 |
Addsimps [lemma_4n_div_2_eq2];
|
|
358 |
|
|
359 |
Goal "n mod 4 = 1 ==> even ((n - 1) div 2)";
|
|
360 |
by (res_inst_tac [("t","n"),("n1","4")] (mod_div_equality RS subst) 1);
|
|
361 |
by (dtac ssubst 1 THEN assume_tac 2);
|
|
362 |
by (rtac ((CLAIM "(n::nat) + 1 - 1 = n") RS ssubst) 1);
|
|
363 |
by Auto_tac;
|
|
364 |
val lemma_even_mod_4_div_2 = result();
|
|
365 |
|
|
366 |
|