src/HOL/Isar_Examples/Mutilated_Checkerboard.thy
 author hoelzl Tue Mar 26 12:20:58 2013 +0100 (2013-03-26) changeset 51526 155263089e7b parent 46582 dcc312f22ee8 child 55656 eb07b0acbebc permissions -rw-r--r--
move SEQ.thy and Lim.thy to Limits.thy
```     1 (*  Title:      HOL/Isar_Examples/Mutilated_Checkerboard.thy
```
```     2     Author:     Markus Wenzel, TU Muenchen (Isar document)
```
```     3     Author:     Lawrence C Paulson, Cambridge University Computer Laboratory (original scripts)
```
```     4 *)
```
```     5
```
```     6 header {* The Mutilated Checker Board Problem *}
```
```     7
```
```     8 theory Mutilated_Checkerboard
```
```     9 imports Main
```
```    10 begin
```
```    11
```
```    12 text {* The Mutilated Checker Board Problem, formalized inductively.
```
```    13   See \cite{paulson-mutilated-board} for the original tactic script version. *}
```
```    14
```
```    15 subsection {* Tilings *}
```
```    16
```
```    17 inductive_set tiling :: "'a set set => 'a set set"
```
```    18   for A :: "'a set set"
```
```    19 where
```
```    20   empty: "{} : tiling A"
```
```    21 | Un: "a : A ==> t : tiling A ==> a <= - t ==> a Un t : tiling A"
```
```    22
```
```    23
```
```    24 text "The union of two disjoint tilings is a tiling."
```
```    25
```
```    26 lemma tiling_Un:
```
```    27   assumes "t : tiling A"
```
```    28     and "u : tiling A"
```
```    29     and "t Int u = {}"
```
```    30   shows "t Un u : tiling A"
```
```    31 proof -
```
```    32   let ?T = "tiling A"
```
```    33   from `t : ?T` and `t Int u = {}`
```
```    34   show "t Un u : ?T"
```
```    35   proof (induct t)
```
```    36     case empty
```
```    37     with `u : ?T` show "{} Un u : ?T" by simp
```
```    38   next
```
```    39     case (Un a t)
```
```    40     show "(a Un t) Un u : ?T"
```
```    41     proof -
```
```    42       have "a Un (t Un u) : ?T"
```
```    43         using `a : A`
```
```    44       proof (rule tiling.Un)
```
```    45         from `(a Un t) Int u = {}` have "t Int u = {}" by blast
```
```    46         then show "t Un u: ?T" by (rule Un)
```
```    47         from `a <= - t` and `(a Un t) Int u = {}`
```
```    48         show "a <= - (t Un u)" by blast
```
```    49       qed
```
```    50       also have "a Un (t Un u) = (a Un t) Un u"
```
```    51         by (simp only: Un_assoc)
```
```    52       finally show ?thesis .
```
```    53     qed
```
```    54   qed
```
```    55 qed
```
```    56
```
```    57
```
```    58 subsection {* Basic properties of ``below'' *}
```
```    59
```
```    60 definition below :: "nat => nat set"
```
```    61   where "below n = {i. i < n}"
```
```    62
```
```    63 lemma below_less_iff [iff]: "(i: below k) = (i < k)"
```
```    64   by (simp add: below_def)
```
```    65
```
```    66 lemma below_0: "below 0 = {}"
```
```    67   by (simp add: below_def)
```
```    68
```
```    69 lemma Sigma_Suc1:
```
```    70     "m = n + 1 ==> below m <*> B = ({n} <*> B) Un (below n <*> B)"
```
```    71   by (simp add: below_def less_Suc_eq) blast
```
```    72
```
```    73 lemma Sigma_Suc2:
```
```    74   "m = n + 2 ==> A <*> below m =
```
```    75     (A <*> {n}) Un (A <*> {n + 1}) Un (A <*> below n)"
```
```    76   by (auto simp add: below_def)
```
```    77
```
```    78 lemmas Sigma_Suc = Sigma_Suc1 Sigma_Suc2
```
```    79
```
```    80
```
```    81 subsection {* Basic properties of ``evnodd'' *}
```
```    82
```
```    83 definition evnodd :: "(nat * nat) set => nat => (nat * nat) set"
```
```    84   where "evnodd A b = A Int {(i, j). (i + j) mod 2 = b}"
```
```    85
```
```    86 lemma evnodd_iff: "(i, j): evnodd A b = ((i, j): A  & (i + j) mod 2 = b)"
```
```    87   by (simp add: evnodd_def)
```
```    88
```
```    89 lemma evnodd_subset: "evnodd A b <= A"
```
```    90   unfolding evnodd_def by (rule Int_lower1)
```
```    91
```
```    92 lemma evnoddD: "x : evnodd A b ==> x : A"
```
```    93   by (rule subsetD) (rule evnodd_subset)
```
```    94
```
```    95 lemma evnodd_finite: "finite A ==> finite (evnodd A b)"
```
```    96   by (rule finite_subset) (rule evnodd_subset)
```
```    97
```
```    98 lemma evnodd_Un: "evnodd (A Un B) b = evnodd A b Un evnodd B b"
```
```    99   unfolding evnodd_def by blast
```
```   100
```
```   101 lemma evnodd_Diff: "evnodd (A - B) b = evnodd A b - evnodd B b"
```
```   102   unfolding evnodd_def by blast
```
```   103
```
```   104 lemma evnodd_empty: "evnodd {} b = {}"
```
```   105   by (simp add: evnodd_def)
```
```   106
```
```   107 lemma evnodd_insert: "evnodd (insert (i, j) C) b =
```
```   108     (if (i + j) mod 2 = b
```
```   109       then insert (i, j) (evnodd C b) else evnodd C b)"
```
```   110   by (simp add: evnodd_def)
```
```   111
```
```   112
```
```   113 subsection {* Dominoes *}
```
```   114
```
```   115 inductive_set domino :: "(nat * nat) set set"
```
```   116 where
```
```   117   horiz: "{(i, j), (i, j + 1)} : domino"
```
```   118 | vertl: "{(i, j), (i + 1, j)} : domino"
```
```   119
```
```   120 lemma dominoes_tile_row:
```
```   121   "{i} <*> below (2 * n) : tiling domino"
```
```   122   (is "?B n : ?T")
```
```   123 proof (induct n)
```
```   124   case 0
```
```   125   show ?case by (simp add: below_0 tiling.empty)
```
```   126 next
```
```   127   case (Suc n)
```
```   128   let ?a = "{i} <*> {2 * n + 1} Un {i} <*> {2 * n}"
```
```   129   have "?B (Suc n) = ?a Un ?B n"
```
```   130     by (auto simp add: Sigma_Suc Un_assoc)
```
```   131   also have "... : ?T"
```
```   132   proof (rule tiling.Un)
```
```   133     have "{(i, 2 * n), (i, 2 * n + 1)} : domino"
```
```   134       by (rule domino.horiz)
```
```   135     also have "{(i, 2 * n), (i, 2 * n + 1)} = ?a" by blast
```
```   136     finally show "... : domino" .
```
```   137     show "?B n : ?T" by (rule Suc)
```
```   138     show "?a <= - ?B n" by blast
```
```   139   qed
```
```   140   finally show ?case .
```
```   141 qed
```
```   142
```
```   143 lemma dominoes_tile_matrix:
```
```   144   "below m <*> below (2 * n) : tiling domino"
```
```   145   (is "?B m : ?T")
```
```   146 proof (induct m)
```
```   147   case 0
```
```   148   show ?case by (simp add: below_0 tiling.empty)
```
```   149 next
```
```   150   case (Suc m)
```
```   151   let ?t = "{m} <*> below (2 * n)"
```
```   152   have "?B (Suc m) = ?t Un ?B m" by (simp add: Sigma_Suc)
```
```   153   also have "... : ?T"
```
```   154   proof (rule tiling_Un)
```
```   155     show "?t : ?T" by (rule dominoes_tile_row)
```
```   156     show "?B m : ?T" by (rule Suc)
```
```   157     show "?t Int ?B m = {}" by blast
```
```   158   qed
```
```   159   finally show ?case .
```
```   160 qed
```
```   161
```
```   162 lemma domino_singleton:
```
```   163   assumes "d : domino"
```
```   164     and "b < 2"
```
```   165   shows "EX i j. evnodd d b = {(i, j)}"  (is "?P d")
```
```   166   using assms
```
```   167 proof induct
```
```   168   from `b < 2` have b_cases: "b = 0 | b = 1" by arith
```
```   169   fix i j
```
```   170   note [simp] = evnodd_empty evnodd_insert mod_Suc
```
```   171   from b_cases show "?P {(i, j), (i, j + 1)}" by rule auto
```
```   172   from b_cases show "?P {(i, j), (i + 1, j)}" by rule auto
```
```   173 qed
```
```   174
```
```   175 lemma domino_finite:
```
```   176   assumes "d: domino"
```
```   177   shows "finite d"
```
```   178   using assms
```
```   179 proof induct
```
```   180   fix i j :: nat
```
```   181   show "finite {(i, j), (i, j + 1)}" by (intro finite.intros)
```
```   182   show "finite {(i, j), (i + 1, j)}" by (intro finite.intros)
```
```   183 qed
```
```   184
```
```   185
```
```   186 subsection {* Tilings of dominoes *}
```
```   187
```
```   188 lemma tiling_domino_finite:
```
```   189   assumes t: "t : tiling domino"  (is "t : ?T")
```
```   190   shows "finite t"  (is "?F t")
```
```   191   using t
```
```   192 proof induct
```
```   193   show "?F {}" by (rule finite.emptyI)
```
```   194   fix a t assume "?F t"
```
```   195   assume "a : domino" then have "?F a" by (rule domino_finite)
```
```   196   from this and `?F t` show "?F (a Un t)" by (rule finite_UnI)
```
```   197 qed
```
```   198
```
```   199 lemma tiling_domino_01:
```
```   200   assumes t: "t : tiling domino"  (is "t : ?T")
```
```   201   shows "card (evnodd t 0) = card (evnodd t 1)"
```
```   202   using t
```
```   203 proof induct
```
```   204   case empty
```
```   205   show ?case by (simp add: evnodd_def)
```
```   206 next
```
```   207   case (Un a t)
```
```   208   let ?e = evnodd
```
```   209   note hyp = `card (?e t 0) = card (?e t 1)`
```
```   210     and at = `a <= - t`
```
```   211   have card_suc:
```
```   212     "!!b. b < 2 ==> card (?e (a Un t) b) = Suc (card (?e t b))"
```
```   213   proof -
```
```   214     fix b :: nat assume "b < 2"
```
```   215     have "?e (a Un t) b = ?e a b Un ?e t b" by (rule evnodd_Un)
```
```   216     also obtain i j where e: "?e a b = {(i, j)}"
```
```   217     proof -
```
```   218       from `a \<in> domino` and `b < 2`
```
```   219       have "EX i j. ?e a b = {(i, j)}" by (rule domino_singleton)
```
```   220       then show ?thesis by (blast intro: that)
```
```   221     qed
```
```   222     also have "... Un ?e t b = insert (i, j) (?e t b)" by simp
```
```   223     also have "card ... = Suc (card (?e t b))"
```
```   224     proof (rule card_insert_disjoint)
```
```   225       from `t \<in> tiling domino` have "finite t"
```
```   226         by (rule tiling_domino_finite)
```
```   227       then show "finite (?e t b)"
```
```   228         by (rule evnodd_finite)
```
```   229       from e have "(i, j) : ?e a b" by simp
```
```   230       with at show "(i, j) ~: ?e t b" by (blast dest: evnoddD)
```
```   231     qed
```
```   232     finally show "?thesis b" .
```
```   233   qed
```
```   234   then have "card (?e (a Un t) 0) = Suc (card (?e t 0))" by simp
```
```   235   also from hyp have "card (?e t 0) = card (?e t 1)" .
```
```   236   also from card_suc have "Suc ... = card (?e (a Un t) 1)"
```
```   237     by simp
```
```   238   finally show ?case .
```
```   239 qed
```
```   240
```
```   241
```
```   242 subsection {* Main theorem *}
```
```   243
```
```   244 definition mutilated_board :: "nat => nat => (nat * nat) set"
```
```   245   where
```
```   246     "mutilated_board m n =
```
```   247       below (2 * (m + 1)) <*> below (2 * (n + 1))
```
```   248         - {(0, 0)} - {(2 * m + 1, 2 * n + 1)}"
```
```   249
```
```   250 theorem mutil_not_tiling: "mutilated_board m n ~: tiling domino"
```
```   251 proof (unfold mutilated_board_def)
```
```   252   let ?T = "tiling domino"
```
```   253   let ?t = "below (2 * (m + 1)) <*> below (2 * (n + 1))"
```
```   254   let ?t' = "?t - {(0, 0)}"
```
```   255   let ?t'' = "?t' - {(2 * m + 1, 2 * n + 1)}"
```
```   256
```
```   257   show "?t'' ~: ?T"
```
```   258   proof
```
```   259     have t: "?t : ?T" by (rule dominoes_tile_matrix)
```
```   260     assume t'': "?t'' : ?T"
```
```   261
```
```   262     let ?e = evnodd
```
```   263     have fin: "finite (?e ?t 0)"
```
```   264       by (rule evnodd_finite, rule tiling_domino_finite, rule t)
```
```   265
```
```   266     note [simp] = evnodd_iff evnodd_empty evnodd_insert evnodd_Diff
```
```   267     have "card (?e ?t'' 0) < card (?e ?t' 0)"
```
```   268     proof -
```
```   269       have "card (?e ?t' 0 - {(2 * m + 1, 2 * n + 1)})
```
```   270         < card (?e ?t' 0)"
```
```   271       proof (rule card_Diff1_less)
```
```   272         from _ fin show "finite (?e ?t' 0)"
```
```   273           by (rule finite_subset) auto
```
```   274         show "(2 * m + 1, 2 * n + 1) : ?e ?t' 0" by simp
```
```   275       qed
```
```   276       then show ?thesis by simp
```
```   277     qed
```
```   278     also have "... < card (?e ?t 0)"
```
```   279     proof -
```
```   280       have "(0, 0) : ?e ?t 0" by simp
```
```   281       with fin have "card (?e ?t 0 - {(0, 0)}) < card (?e ?t 0)"
```
```   282         by (rule card_Diff1_less)
```
```   283       then show ?thesis by simp
```
```   284     qed
```
```   285     also from t have "... = card (?e ?t 1)"
```
```   286       by (rule tiling_domino_01)
```
```   287     also have "?e ?t 1 = ?e ?t'' 1" by simp
```
```   288     also from t'' have "card ... = card (?e ?t'' 0)"
```
```   289       by (rule tiling_domino_01 [symmetric])
```
```   290     finally have "... < ..." . then show False ..
```
```   291   qed
```
```   292 qed
```
```   293
```
```   294 end
```