author | paulson |
Thu, 26 Sep 1996 12:47:47 +0200 | |
changeset 2031 | 03a843f0f447 |
parent 1911 | c27e624b6d87 |
child 2513 | d708d8cdc8e8 |
permissions | -rw-r--r-- |
1621 | 1 |
(* Title: HOL/ex/Mutil |
2 |
ID: $Id$ |
|
3 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
|
4 |
Copyright 1996 University of Cambridge |
|
5 |
||
1684
3eaf3ab53082
Rearrangement and polishing to look for for publication
paulson
parents:
1673
diff
changeset
|
6 |
The Mutilated Chess Board Problem, formalized inductively |
1621 | 7 |
*) |
8 |
||
9 |
open Mutil; |
|
10 |
||
1684
3eaf3ab53082
Rearrangement and polishing to look for for publication
paulson
parents:
1673
diff
changeset
|
11 |
Addsimps tiling.intrs; |
3eaf3ab53082
Rearrangement and polishing to look for for publication
paulson
parents:
1673
diff
changeset
|
12 |
|
3eaf3ab53082
Rearrangement and polishing to look for for publication
paulson
parents:
1673
diff
changeset
|
13 |
(** The union of two disjoint tilings is a tiling **) |
3eaf3ab53082
Rearrangement and polishing to look for for publication
paulson
parents:
1673
diff
changeset
|
14 |
|
3eaf3ab53082
Rearrangement and polishing to look for for publication
paulson
parents:
1673
diff
changeset
|
15 |
goal thy "!!t. t: tiling A ==> \ |
3eaf3ab53082
Rearrangement and polishing to look for for publication
paulson
parents:
1673
diff
changeset
|
16 |
\ u: tiling A --> t Int u = {} --> t Un u : tiling A"; |
3eaf3ab53082
Rearrangement and polishing to look for for publication
paulson
parents:
1673
diff
changeset
|
17 |
by (etac tiling.induct 1); |
3eaf3ab53082
Rearrangement and polishing to look for for publication
paulson
parents:
1673
diff
changeset
|
18 |
by (Simp_tac 1); |
1820 | 19 |
by (fast_tac (!claset addIs tiling.intrs |
2031 | 20 |
addss (HOL_ss addsimps [Un_assoc, |
21 |
subset_empty_iff RS sym])) 1); |
|
1911 | 22 |
qed_spec_mp "tiling_UnI"; |
1684
3eaf3ab53082
Rearrangement and polishing to look for for publication
paulson
parents:
1673
diff
changeset
|
23 |
|
3eaf3ab53082
Rearrangement and polishing to look for for publication
paulson
parents:
1673
diff
changeset
|
24 |
|
3eaf3ab53082
Rearrangement and polishing to look for for publication
paulson
parents:
1673
diff
changeset
|
25 |
(*** Chess boards ***) |
3eaf3ab53082
Rearrangement and polishing to look for for publication
paulson
parents:
1673
diff
changeset
|
26 |
|
3eaf3ab53082
Rearrangement and polishing to look for for publication
paulson
parents:
1673
diff
changeset
|
27 |
val [below_0, below_Suc] = nat_recs below_def; |
1911 | 28 |
Addsimps [below_0, below_Suc]; |
1684
3eaf3ab53082
Rearrangement and polishing to look for for publication
paulson
parents:
1673
diff
changeset
|
29 |
|
1911 | 30 |
goal thy "ALL i. (i: below k) = (i<k)"; |
1684
3eaf3ab53082
Rearrangement and polishing to look for for publication
paulson
parents:
1673
diff
changeset
|
31 |
by (nat_ind_tac "k" 1); |
1911 | 32 |
by (ALLGOALS (asm_simp_tac (!simpset addsimps [less_Suc_eq]))); |
1820 | 33 |
by (Fast_tac 1); |
1911 | 34 |
qed_spec_mp "below_less_iff"; |
35 |
||
36 |
Addsimps [below_less_iff]; |
|
1621 | 37 |
|
1684
3eaf3ab53082
Rearrangement and polishing to look for for publication
paulson
parents:
1673
diff
changeset
|
38 |
goal thy "below(Suc n) Times B = ({n} Times B) Un ((below n) Times B)"; |
1911 | 39 |
by (Simp_tac 1); |
40 |
by (Fast_tac 1); |
|
1684
3eaf3ab53082
Rearrangement and polishing to look for for publication
paulson
parents:
1673
diff
changeset
|
41 |
qed "Sigma_Suc1"; |
3eaf3ab53082
Rearrangement and polishing to look for for publication
paulson
parents:
1673
diff
changeset
|
42 |
|
3eaf3ab53082
Rearrangement and polishing to look for for publication
paulson
parents:
1673
diff
changeset
|
43 |
goal thy "A Times below(Suc n) = (A Times {n}) Un (A Times (below n))"; |
1911 | 44 |
by (Simp_tac 1); |
45 |
by (Fast_tac 1); |
|
1684
3eaf3ab53082
Rearrangement and polishing to look for for publication
paulson
parents:
1673
diff
changeset
|
46 |
qed "Sigma_Suc2"; |
1621 | 47 |
|
1911 | 48 |
(*Deletion is essential to allow use of Sigma_Suc1,2*) |
49 |
Delsimps [below_Suc]; |
|
50 |
||
1684
3eaf3ab53082
Rearrangement and polishing to look for for publication
paulson
parents:
1673
diff
changeset
|
51 |
goal thy "{i} Times below(n + n) : tiling domino"; |
3eaf3ab53082
Rearrangement and polishing to look for for publication
paulson
parents:
1673
diff
changeset
|
52 |
by (nat_ind_tac "n" 1); |
3eaf3ab53082
Rearrangement and polishing to look for for publication
paulson
parents:
1673
diff
changeset
|
53 |
by (ALLGOALS (asm_simp_tac (!simpset addsimps [Un_assoc RS sym, Sigma_Suc2]))); |
3eaf3ab53082
Rearrangement and polishing to look for for publication
paulson
parents:
1673
diff
changeset
|
54 |
by (resolve_tac tiling.intrs 1); |
3eaf3ab53082
Rearrangement and polishing to look for for publication
paulson
parents:
1673
diff
changeset
|
55 |
by (assume_tac 2); |
3eaf3ab53082
Rearrangement and polishing to look for for publication
paulson
parents:
1673
diff
changeset
|
56 |
by (subgoal_tac (*seems the easiest way of turning one to the other*) |
3eaf3ab53082
Rearrangement and polishing to look for for publication
paulson
parents:
1673
diff
changeset
|
57 |
"({i} Times {Suc(n1+n1)}) Un ({i} Times {n1+n1}) = \ |
3eaf3ab53082
Rearrangement and polishing to look for for publication
paulson
parents:
1673
diff
changeset
|
58 |
\ {(i, n1+n1), (i, Suc(n1+n1))}" 1); |
1911 | 59 |
by (Fast_tac 2); |
1684
3eaf3ab53082
Rearrangement and polishing to look for for publication
paulson
parents:
1673
diff
changeset
|
60 |
by (asm_simp_tac (!simpset addsimps [domino.horiz]) 1); |
1820 | 61 |
by (fast_tac (!claset addIs [equalityI, lessI] addEs [less_irrefl, less_asym] |
1684
3eaf3ab53082
Rearrangement and polishing to look for for publication
paulson
parents:
1673
diff
changeset
|
62 |
addDs [below_less_iff RS iffD1]) 1); |
3eaf3ab53082
Rearrangement and polishing to look for for publication
paulson
parents:
1673
diff
changeset
|
63 |
qed "dominoes_tile_row"; |
3eaf3ab53082
Rearrangement and polishing to look for for publication
paulson
parents:
1673
diff
changeset
|
64 |
|
3eaf3ab53082
Rearrangement and polishing to look for for publication
paulson
parents:
1673
diff
changeset
|
65 |
goal thy "(below m) Times below(n + n) : tiling domino"; |
3eaf3ab53082
Rearrangement and polishing to look for for publication
paulson
parents:
1673
diff
changeset
|
66 |
by (nat_ind_tac "m" 1); |
3eaf3ab53082
Rearrangement and polishing to look for for publication
paulson
parents:
1673
diff
changeset
|
67 |
by (ALLGOALS (asm_simp_tac (!simpset addsimps [Sigma_Suc1]))); |
1820 | 68 |
by (fast_tac (!claset addIs [equalityI, tiling_UnI, dominoes_tile_row] |
1684
3eaf3ab53082
Rearrangement and polishing to look for for publication
paulson
parents:
1673
diff
changeset
|
69 |
addEs [below_less_iff RS iffD1 RS less_irrefl]) 1); |
3eaf3ab53082
Rearrangement and polishing to look for for publication
paulson
parents:
1673
diff
changeset
|
70 |
qed "dominoes_tile_matrix"; |
3eaf3ab53082
Rearrangement and polishing to look for for publication
paulson
parents:
1673
diff
changeset
|
71 |
|
3eaf3ab53082
Rearrangement and polishing to look for for publication
paulson
parents:
1673
diff
changeset
|
72 |
|
3eaf3ab53082
Rearrangement and polishing to look for for publication
paulson
parents:
1673
diff
changeset
|
73 |
(*** Basic properties of evnodd ***) |
3eaf3ab53082
Rearrangement and polishing to look for for publication
paulson
parents:
1673
diff
changeset
|
74 |
|
3eaf3ab53082
Rearrangement and polishing to look for for publication
paulson
parents:
1673
diff
changeset
|
75 |
goalw thy [evnodd_def] "(i,j): evnodd A b = ((i,j): A & (i+j) mod 2 = b)"; |
1621 | 76 |
by (Simp_tac 1); |
77 |
qed "evnodd_iff"; |
|
78 |
||
79 |
goalw thy [evnodd_def] "evnodd A b <= A"; |
|
80 |
by (rtac Int_lower1 1); |
|
81 |
qed "evnodd_subset"; |
|
82 |
||
83 |
(* finite X ==> finite(evnodd X b) *) |
|
84 |
bind_thm("finite_evnodd", evnodd_subset RS finite_subset); |
|
85 |
||
86 |
goalw thy [evnodd_def] "evnodd (A Un B) b = evnodd A b Un evnodd B b"; |
|
1820 | 87 |
by (Fast_tac 1); |
1621 | 88 |
qed "evnodd_Un"; |
89 |
||
90 |
goalw thy [evnodd_def] "evnodd (A - B) b = evnodd A b - evnodd B b"; |
|
1820 | 91 |
by (Fast_tac 1); |
1621 | 92 |
qed "evnodd_Diff"; |
93 |
||
1684
3eaf3ab53082
Rearrangement and polishing to look for for publication
paulson
parents:
1673
diff
changeset
|
94 |
goalw thy [evnodd_def] "evnodd {} b = {}"; |
3eaf3ab53082
Rearrangement and polishing to look for for publication
paulson
parents:
1673
diff
changeset
|
95 |
by (Simp_tac 1); |
3eaf3ab53082
Rearrangement and polishing to look for for publication
paulson
parents:
1673
diff
changeset
|
96 |
qed "evnodd_empty"; |
3eaf3ab53082
Rearrangement and polishing to look for for publication
paulson
parents:
1673
diff
changeset
|
97 |
|
1621 | 98 |
goalw thy [evnodd_def] |
99 |
"evnodd (insert (i,j) C) b = \ |
|
100 |
\ (if (i+j) mod 2 = b then insert (i,j) (evnodd C b) else evnodd C b)"; |
|
101 |
by (asm_full_simp_tac (!simpset addsimps [evnodd_def] |
|
1895 | 102 |
setloop (split_tac [expand_if] THEN' Step_tac)) 1); |
1621 | 103 |
qed "evnodd_insert"; |
104 |
||
105 |
||
106 |
(*** Dominoes ***) |
|
107 |
||
1684
3eaf3ab53082
Rearrangement and polishing to look for for publication
paulson
parents:
1673
diff
changeset
|
108 |
goal thy "!!d. [| d:domino; b<2 |] ==> EX i j. evnodd d b = {(i,j)}"; |
1621 | 109 |
by (eresolve_tac [domino.elim] 1); |
110 |
by (res_inst_tac [("k1", "i+j")] (mod2_cases RS disjE) 2); |
|
111 |
by (res_inst_tac [("k1", "i+j")] (mod2_cases RS disjE) 1); |
|
112 |
by (REPEAT_FIRST assume_tac); |
|
113 |
(*Four similar cases: case (i+j) mod 2 = b, 2#-b, ...*) |
|
1911 | 114 |
by (REPEAT (asm_full_simp_tac (!simpset addsimps |
115 |
[less_Suc_eq, evnodd_insert, evnodd_empty, mod_Suc] |
|
1621 | 116 |
setloop split_tac [expand_if]) 1 |
1820 | 117 |
THEN Fast_tac 1)); |
1621 | 118 |
qed "domino_singleton"; |
119 |
||
1684
3eaf3ab53082
Rearrangement and polishing to look for for publication
paulson
parents:
1673
diff
changeset
|
120 |
goal thy "!!d. d:domino ==> finite d"; |
1820 | 121 |
by (fast_tac (!claset addSIs [finite_insertI, finite_emptyI] |
1911 | 122 |
addEs [domino.elim]) 1); |
1684
3eaf3ab53082
Rearrangement and polishing to look for for publication
paulson
parents:
1673
diff
changeset
|
123 |
qed "domino_finite"; |
1621 | 124 |
|
1684
3eaf3ab53082
Rearrangement and polishing to look for for publication
paulson
parents:
1673
diff
changeset
|
125 |
|
3eaf3ab53082
Rearrangement and polishing to look for for publication
paulson
parents:
1673
diff
changeset
|
126 |
(*** Tilings of dominoes ***) |
1621 | 127 |
|
128 |
goal thy "!!t. t:tiling domino ==> finite t"; |
|
129 |
by (eresolve_tac [tiling.induct] 1); |
|
130 |
by (rtac finite_emptyI 1); |
|
1820 | 131 |
by (fast_tac (!claset addIs [domino_finite, finite_UnI]) 1); |
1621 | 132 |
qed "tiling_domino_finite"; |
133 |
||
134 |
goal thy "!!t. t: tiling domino ==> card(evnodd t 0) = card(evnodd t 1)"; |
|
135 |
by (eresolve_tac [tiling.induct] 1); |
|
136 |
by (simp_tac (!simpset addsimps [evnodd_def]) 1); |
|
137 |
by (res_inst_tac [("b1","0")] (domino_singleton RS exE) 1); |
|
138 |
by (Simp_tac 2 THEN assume_tac 1); |
|
139 |
by (res_inst_tac [("b1","1")] (domino_singleton RS exE) 1); |
|
140 |
by (Simp_tac 2 THEN assume_tac 1); |
|
1895 | 141 |
by (Step_tac 1); |
1621 | 142 |
by (subgoal_tac "ALL p b. p : evnodd a b --> p ~: evnodd ta b" 1); |
143 |
by (asm_simp_tac (!simpset addsimps [evnodd_Un, Un_insert_left, |
|
144 |
tiling_domino_finite, |
|
145 |
evnodd_subset RS finite_subset, |
|
146 |
card_insert_disjoint]) 1); |
|
1820 | 147 |
by (fast_tac (!claset addSDs [evnodd_subset RS subsetD] addEs [equalityE]) 1); |
1621 | 148 |
qed "tiling_domino_0_1"; |
149 |
||
1684
3eaf3ab53082
Rearrangement and polishing to look for for publication
paulson
parents:
1673
diff
changeset
|
150 |
goal thy "!!m n. [| t = below(Suc m + Suc m) Times below(Suc n + Suc n); \ |
3eaf3ab53082
Rearrangement and polishing to look for for publication
paulson
parents:
1673
diff
changeset
|
151 |
\ t' = t - {(0,0)} - {(Suc(m+m), Suc(n+n))} \ |
1621 | 152 |
\ |] ==> t' ~: tiling domino"; |
153 |
by (rtac notI 1); |
|
154 |
by (dtac tiling_domino_0_1 1); |
|
155 |
by (subgoal_tac "card(evnodd t' 0) < card(evnodd t' 1)" 1); |
|
156 |
by (Asm_full_simp_tac 1); |
|
157 |
by (subgoal_tac "t : tiling domino" 1); |
|
158 |
(*Requires a small simpset that won't move the Suc applications*) |
|
159 |
by (asm_simp_tac (HOL_ss addsimps [dominoes_tile_matrix]) 2); |
|
160 |
by (subgoal_tac "(m+m)+(n+n) = (m+n)+(m+n)" 1); |
|
161 |
by (asm_simp_tac (!simpset addsimps add_ac) 2); |
|
162 |
by (asm_full_simp_tac |
|
163 |
(!simpset addsimps [evnodd_Diff, evnodd_insert, evnodd_empty, |
|
164 |
mod_less, tiling_domino_0_1 RS sym]) 1); |
|
165 |
by (rtac less_trans 1); |
|
166 |
by (REPEAT |
|
167 |
(rtac card_Diff 1 |
|
168 |
THEN |
|
169 |
asm_simp_tac (!simpset addsimps [tiling_domino_finite, finite_evnodd]) 1 |
|
170 |
THEN |
|
1911 | 171 |
asm_simp_tac (!simpset addsimps [mod_less, evnodd_iff]) 1)); |
1621 | 172 |
qed "mutil_not_tiling"; |
173 |