src/HOL/Isar_examples/MutilatedCheckerboard.thy
 author obua Mon Apr 10 16:00:34 2006 +0200 (2006-04-10) changeset 19404 9bf2cdc9e8e8 parent 18241 afdba6b3e383 child 22273 9785397cc344 permissions -rw-r--r--
Moved stuff from Ring_and_Field to Matrix
1 (*  Title:      HOL/Isar_examples/MutilatedCheckerboard.thy
2     ID:         \$Id\$
3     Author:     Markus Wenzel, TU Muenchen (Isar document)
4                 Lawrence C Paulson, Cambridge University Computer Laboratory (original scripts)
5 *)
7 header {* The Mutilated Checker Board Problem *}
9 theory MutilatedCheckerboard imports Main begin
11 text {*
12  The Mutilated Checker Board Problem, formalized inductively.  See
13  \cite{paulson-mutilated-board} and
14  \url{http://isabelle.in.tum.de/library/HOL/Induct/Mutil.html} for the
15  original tactic script version.
16 *}
18 subsection {* Tilings *}
20 consts
21   tiling :: "'a set set => 'a set set"
23 inductive "tiling A"
24   intros
25     empty: "{} : tiling A"
26     Un: "a : A ==> t : tiling A ==> a <= - t ==> a Un t : tiling A"
29 text "The union of two disjoint tilings is a tiling."
31 lemma tiling_Un:
32   assumes "t : tiling A" and "u : tiling A" and "t Int u = {}"
33   shows "t Un u : tiling A"
34 proof -
35   let ?T = "tiling A"
36   from `t : ?T` and `t Int u = {}`
37   show "t Un u : ?T"
38   proof (induct t)
39     case empty
40     with `u : ?T` show "{} Un u : ?T" by simp
41   next
42     case (Un a t)
43     show "(a Un t) Un u : ?T"
44     proof -
45       have "a Un (t Un u) : ?T"
46       proof (rule tiling.Un)
47         show "a : A" .
48         from `(a Un t) Int u = {}` have "t Int u = {}" by blast
49         then show "t Un u: ?T" by (rule Un)
50         have "a <= - t" .
51         with `(a Un t) Int u = {}` show "a <= - (t Un u)" by blast
52       qed
53       also have "a Un (t Un u) = (a Un t) Un u"
54         by (simp only: Un_assoc)
55       finally show ?thesis .
56     qed
57   qed
58 qed
61 subsection {* Basic properties of ``below'' *}
63 constdefs
64   below :: "nat => nat set"
65   "below n == {i. i < n}"
67 lemma below_less_iff [iff]: "(i: below k) = (i < k)"
70 lemma below_0: "below 0 = {}"
73 lemma Sigma_Suc1:
74     "m = n + 1 ==> below m <*> B = ({n} <*> B) Un (below n <*> B)"
75   by (simp add: below_def less_Suc_eq) blast
77 lemma Sigma_Suc2:
78     "m = n + 2 ==> A <*> below m =
79       (A <*> {n}) Un (A <*> {n + 1}) Un (A <*> below n)"
80   by (auto simp add: below_def)
82 lemmas Sigma_Suc = Sigma_Suc1 Sigma_Suc2
85 subsection {* Basic properties of ``evnodd'' *}
87 constdefs
88   evnodd :: "(nat * nat) set => nat => (nat * nat) set"
89   "evnodd A b == A Int {(i, j). (i + j) mod 2 = b}"
91 lemma evnodd_iff:
92     "(i, j): evnodd A b = ((i, j): A  & (i + j) mod 2 = b)"
95 lemma evnodd_subset: "evnodd A b <= A"
96   by (unfold evnodd_def, rule Int_lower1)
98 lemma evnoddD: "x : evnodd A b ==> x : A"
99   by (rule subsetD, rule evnodd_subset)
101 lemma evnodd_finite: "finite A ==> finite (evnodd A b)"
102   by (rule finite_subset, rule evnodd_subset)
104 lemma evnodd_Un: "evnodd (A Un B) b = evnodd A b Un evnodd B b"
105   by (unfold evnodd_def) blast
107 lemma evnodd_Diff: "evnodd (A - B) b = evnodd A b - evnodd B b"
108   by (unfold evnodd_def) blast
110 lemma evnodd_empty: "evnodd {} b = {}"
113 lemma evnodd_insert: "evnodd (insert (i, j) C) b =
114     (if (i + j) mod 2 = b
115       then insert (i, j) (evnodd C b) else evnodd C b)"
116   by (simp add: evnodd_def) blast
119 subsection {* Dominoes *}
121 consts
122   domino :: "(nat * nat) set set"
124 inductive domino
125   intros
126     horiz: "{(i, j), (i, j + 1)} : domino"
127     vertl: "{(i, j), (i + 1, j)} : domino"
129 lemma dominoes_tile_row:
130   "{i} <*> below (2 * n) : tiling domino"
131   (is "?B n : ?T")
132 proof (induct n)
133   case 0
134   show ?case by (simp add: below_0 tiling.empty)
135 next
136   case (Suc n)
137   let ?a = "{i} <*> {2 * n + 1} Un {i} <*> {2 * n}"
138   have "?B (Suc n) = ?a Un ?B n"
139     by (auto simp add: Sigma_Suc Un_assoc)
140   also have "... : ?T"
141   proof (rule tiling.Un)
142     have "{(i, 2 * n), (i, 2 * n + 1)} : domino"
143       by (rule domino.horiz)
144     also have "{(i, 2 * n), (i, 2 * n + 1)} = ?a" by blast
145     finally show "... : domino" .
146     show "?B n : ?T" by (rule Suc)
147     show "?a <= - ?B n" by blast
148   qed
149   finally show ?case .
150 qed
152 lemma dominoes_tile_matrix:
153   "below m <*> below (2 * n) : tiling domino"
154   (is "?B m : ?T")
155 proof (induct m)
156   case 0
157   show ?case by (simp add: below_0 tiling.empty)
158 next
159   case (Suc m)
160   let ?t = "{m} <*> below (2 * n)"
161   have "?B (Suc m) = ?t Un ?B m" by (simp add: Sigma_Suc)
162   also have "... : ?T"
163   proof (rule tiling_Un)
164     show "?t : ?T" by (rule dominoes_tile_row)
165     show "?B m : ?T" by (rule Suc)
166     show "?t Int ?B m = {}" by blast
167   qed
168   finally show ?case .
169 qed
171 lemma domino_singleton:
172   assumes d: "d : domino" and "b < 2"
173   shows "EX i j. evnodd d b = {(i, j)}"  (is "?P d")
174   using d
175 proof induct
176   from `b < 2` have b_cases: "b = 0 | b = 1" by arith
177   fix i j
178   note [simp] = evnodd_empty evnodd_insert mod_Suc
179   from b_cases show "?P {(i, j), (i, j + 1)}" by rule auto
180   from b_cases show "?P {(i, j), (i + 1, j)}" by rule auto
181 qed
183 lemma domino_finite:
184   assumes d: "d: domino"
185   shows "finite d"
186   using d
187 proof induct
188   fix i j :: nat
189   show "finite {(i, j), (i, j + 1)}" by (intro Finites.intros)
190   show "finite {(i, j), (i + 1, j)}" by (intro Finites.intros)
191 qed
194 subsection {* Tilings of dominoes *}
196 lemma tiling_domino_finite:
197   assumes t: "t : tiling domino"  (is "t : ?T")
198   shows "finite t"  (is "?F t")
199   using t
200 proof induct
201   show "?F {}" by (rule Finites.emptyI)
202   fix a t assume "?F t"
203   assume "a : domino" then have "?F a" by (rule domino_finite)
204   then show "?F (a Un t)" by (rule finite_UnI)
205 qed
207 lemma tiling_domino_01:
208   assumes t: "t : tiling domino"  (is "t : ?T")
209   shows "card (evnodd t 0) = card (evnodd t 1)"
210   using t
211 proof induct
212   case empty
213   show ?case by (simp add: evnodd_def)
214 next
215   case (Un a t)
216   let ?e = evnodd
217   note hyp = `card (?e t 0) = card (?e t 1)`
218     and at = `a <= - t`
219   have card_suc:
220     "!!b. b < 2 ==> card (?e (a Un t) b) = Suc (card (?e t b))"
221   proof -
222     fix b :: nat assume "b < 2"
223     have "?e (a Un t) b = ?e a b Un ?e t b" by (rule evnodd_Un)
224     also obtain i j where e: "?e a b = {(i, j)}"
225     proof -
226       have "EX i j. ?e a b = {(i, j)}" by (rule domino_singleton)
227       then show ?thesis by (blast intro: that)
228     qed
229     also have "... Un ?e t b = insert (i, j) (?e t b)" by simp
230     also have "card ... = Suc (card (?e t b))"
231     proof (rule card_insert_disjoint)
232       show "finite (?e t b)"
233         by (rule evnodd_finite, rule tiling_domino_finite)
234       from e have "(i, j) : ?e a b" by simp
235       with at show "(i, j) ~: ?e t b" by (blast dest: evnoddD)
236     qed
237     finally show "?thesis b" .
238   qed
239   then have "card (?e (a Un t) 0) = Suc (card (?e t 0))" by simp
240   also from hyp have "card (?e t 0) = card (?e t 1)" .
241   also from card_suc have "Suc ... = card (?e (a Un t) 1)"
242     by simp
243   finally show ?case .
244 qed
247 subsection {* Main theorem *}
249 constdefs
250   mutilated_board :: "nat => nat => (nat * nat) set"
251   "mutilated_board m n ==
252     below (2 * (m + 1)) <*> below (2 * (n + 1))
253       - {(0, 0)} - {(2 * m + 1, 2 * n + 1)}"
255 theorem mutil_not_tiling: "mutilated_board m n ~: tiling domino"
256 proof (unfold mutilated_board_def)
257   let ?T = "tiling domino"
258   let ?t = "below (2 * (m + 1)) <*> below (2 * (n + 1))"
259   let ?t' = "?t - {(0, 0)}"
260   let ?t'' = "?t' - {(2 * m + 1, 2 * n + 1)}"
262   show "?t'' ~: ?T"
263   proof
264     have t: "?t : ?T" by (rule dominoes_tile_matrix)
265     assume t'': "?t'' : ?T"
267     let ?e = evnodd
268     have fin: "finite (?e ?t 0)"
269       by (rule evnodd_finite, rule tiling_domino_finite, rule t)
271     note [simp] = evnodd_iff evnodd_empty evnodd_insert evnodd_Diff
272     have "card (?e ?t'' 0) < card (?e ?t' 0)"
273     proof -
274       have "card (?e ?t' 0 - {(2 * m + 1, 2 * n + 1)})
275         < card (?e ?t' 0)"
276       proof (rule card_Diff1_less)
277         from _ fin show "finite (?e ?t' 0)"
278           by (rule finite_subset) auto
279         show "(2 * m + 1, 2 * n + 1) : ?e ?t' 0" by simp
280       qed
281       then show ?thesis by simp
282     qed
283     also have "... < card (?e ?t 0)"
284     proof -
285       have "(0, 0) : ?e ?t 0" by simp
286       with fin have "card (?e ?t 0 - {(0, 0)}) < card (?e ?t 0)"
287         by (rule card_Diff1_less)
288       then show ?thesis by simp
289     qed
290     also from t have "... = card (?e ?t 1)"
291       by (rule tiling_domino_01)
292     also have "?e ?t 1 = ?e ?t'' 1" by simp
293     also from t'' have "card ... = card (?e ?t'' 0)"
294       by (rule tiling_domino_01 [symmetric])
295     finally have "... < ..." . then show False ..
296   qed
297 qed
299 end