src/HOL/Isar_examples/MutilatedCheckerboard.thy
 author wenzelm Tue Sep 12 22:13:23 2000 +0200 (2000-09-12) changeset 9941 fe05af7ec816 parent 9906 5c027cca6262 child 10007 64bf7da1994a permissions -rw-r--r--
renamed atts: rulify to rule_format, elimify to elim_format;
```     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 *)
```
```     6
```
```     7 header {* The Mutilated Checker Board Problem *};
```
```     8
```
```     9 theory MutilatedCheckerboard = Main:;
```
```    10
```
```    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 *};
```
```    17
```
```    18 subsection {* Tilings *};
```
```    19
```
```    20 consts
```
```    21   tiling :: "'a set set => 'a set set";
```
```    22
```
```    23 inductive "tiling A"
```
```    24   intros
```
```    25     empty: "{} : tiling A"
```
```    26     Un:    "a : A ==> t : tiling A ==> a <= - t
```
```    27               ==> a Un t : tiling A";
```
```    28
```
```    29
```
```    30 text "The union of two disjoint tilings is a tiling.";
```
```    31
```
```    32 lemma tiling_Un:
```
```    33   "t : tiling A --> u : tiling A --> t Int u = {}
```
```    34     --> t Un u : tiling A";
```
```    35 proof;
```
```    36   assume "t : tiling A" (is "_ : ?T");
```
```    37   thus "u : ?T --> t Int u = {} --> t Un u : ?T" (is "?P t");
```
```    38   proof (induct (stripped) t);
```
```    39     assume "u : ?T" "{} Int u = {}"
```
```    40     thus "{} Un u : ?T" by simp;
```
```    41   next
```
```    42     fix a t;
```
```    43     assume "a : A" "t : ?T" "?P t" "a <= - t";
```
```    44     assume "u : ?T" "(a Un t) Int u = {}";
```
```    45     have hyp: "t Un u: ?T"; by (blast!);
```
```    46     have "a <= - (t Un u)"; by (blast!);
```
```    47     with _ hyp; have "a Un (t Un u) : ?T"; by (rule tiling.Un);
```
```    48     also; have "a Un (t Un u) = (a Un t) Un u";
```
```    49       by (simp only: Un_assoc);
```
```    50     finally; show "... : ?T"; .;
```
```    51   qed;
```
```    52 qed;
```
```    53
```
```    54
```
```    55 subsection {* Basic properties of ``below'' *};
```
```    56
```
```    57 constdefs
```
```    58   below :: "nat => nat set"
```
```    59   "below n == {i. i < n}";
```
```    60
```
```    61 lemma below_less_iff [iff]: "(i: below k) = (i < k)";
```
```    62   by (simp add: below_def);
```
```    63
```
```    64 lemma below_0: "below 0 = {}";
```
```    65   by (simp add: below_def);
```
```    66
```
```    67 lemma Sigma_Suc1:
```
```    68     "m = n + 1 ==> below m <*> B = ({n} <*> B) Un (below n <*> B)";
```
```    69   by (simp add: below_def less_Suc_eq) blast;
```
```    70
```
```    71 lemma Sigma_Suc2:
```
```    72     "m = n + 2 ==> A <*> below m =
```
```    73       (A <*> {n}) Un (A <*> {n + 1}) Un (A <*> below n)";
```
```    74   by (auto simp add: below_def) arith;
```
```    75
```
```    76 lemmas Sigma_Suc = Sigma_Suc1 Sigma_Suc2;
```
```    77
```
```    78
```
```    79 subsection {* Basic properties of ``evnodd'' *};
```
```    80
```
```    81 constdefs
```
```    82   evnodd :: "(nat * nat) set => nat => (nat * nat) set"
```
```    83   "evnodd A b == A Int {(i, j). (i + j) mod #2 = b}";
```
```    84
```
```    85 lemma evnodd_iff:
```
```    86     "(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   by (unfold evnodd_def, 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   by (unfold evnodd_def) blast;
```
```   100
```
```   101 lemma evnodd_Diff: "evnodd (A - B) b = evnodd A b - evnodd B b";
```
```   102   by (unfold evnodd_def) 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) blast;
```
```   111
```
```   112
```
```   113 subsection {* Dominoes *};
```
```   114
```
```   115 consts
```
```   116   domino :: "(nat * nat) set set";
```
```   117
```
```   118 inductive domino
```
```   119   intros
```
```   120     horiz:  "{(i, j), (i, j + 1)} : domino"
```
```   121     vertl:  "{(i, j), (i + 1, j)} : domino";
```
```   122
```
```   123 lemma dominoes_tile_row:
```
```   124   "{i} <*> below (2 * n) : tiling domino"
```
```   125   (is "?P n" is "?B n : ?T");
```
```   126 proof (induct n);
```
```   127   show "?P 0"; by (simp add: below_0 tiling.empty);
```
```   128
```
```   129   fix n; assume hyp: "?P n";
```
```   130   let ?a = "{i} <*> {2 * n + 1} Un {i} <*> {2 * n}";
```
```   131
```
```   132   have "?B (Suc n) = ?a Un ?B n";
```
```   133     by (auto simp add: Sigma_Suc Un_assoc);
```
```   134   also; have "... : ?T";
```
```   135   proof (rule tiling.Un);
```
```   136     have "{(i, 2 * n), (i, 2 * n + 1)} : domino";
```
```   137       by (rule domino.horiz);
```
```   138     also; have "{(i, 2 * n), (i, 2 * n + 1)} = ?a"; by blast;
```
```   139     finally; show "... : domino"; .;
```
```   140     from hyp; show "?B n : ?T"; .;
```
```   141     show "?a <= - ?B n"; by blast;
```
```   142   qed;
```
```   143   finally; show "?P (Suc n)"; .;
```
```   144 qed;
```
```   145
```
```   146 lemma dominoes_tile_matrix:
```
```   147   "below m <*> below (2 * n) : tiling domino"
```
```   148   (is "?P m" is "?B m : ?T");
```
```   149 proof (induct m);
```
```   150   show "?P 0"; by (simp add: below_0 tiling.empty);
```
```   151
```
```   152   fix m; assume hyp: "?P m";
```
```   153   let ?t = "{m} <*> below (2 * n)";
```
```   154
```
```   155   have "?B (Suc m) = ?t Un ?B m"; by (simp add: Sigma_Suc);
```
```   156   also; have "... : ?T";
```
```   157   proof (rule tiling_Un [rule_format]);
```
```   158     show "?t : ?T"; by (rule dominoes_tile_row);
```
```   159     from hyp; show "?B m : ?T"; .;
```
```   160     show "?t Int ?B m = {}"; by blast;
```
```   161   qed;
```
```   162   finally; show "?P (Suc m)"; .;
```
```   163 qed;
```
```   164
```
```   165 lemma domino_singleton:
```
```   166   "d : domino ==> b < 2 ==> EX i j. evnodd d b = {(i, j)}";
```
```   167 proof -;
```
```   168   assume b: "b < 2";
```
```   169   assume "d : domino";
```
```   170   thus ?thesis (is "?P d");
```
```   171   proof induct;
```
```   172     from b; have b_cases: "b = 0 | b = 1"; by arith;
```
```   173     fix i j;
```
```   174     note [simp] = evnodd_empty evnodd_insert mod_Suc;
```
```   175     from b_cases; show "?P {(i, j), (i, j + 1)}"; by rule auto;
```
```   176     from b_cases; show "?P {(i, j), (i + 1, j)}"; by rule auto;
```
```   177   qed;
```
```   178 qed;
```
```   179
```
```   180 lemma domino_finite: "d: domino ==> finite d";
```
```   181 proof (induct set: domino);
```
```   182   fix i j :: nat;
```
```   183   show "finite {(i, j), (i, j + 1)}"; by (intro Finites.intros);
```
```   184   show "finite {(i, j), (i + 1, j)}"; by (intro Finites.intros);
```
```   185 qed;
```
```   186
```
```   187
```
```   188 subsection {* Tilings of dominoes *};
```
```   189
```
```   190 lemma tiling_domino_finite:
```
```   191   "t : tiling domino ==> finite t" (is "t : ?T ==> ?F t");
```
```   192 proof -;
```
```   193   assume "t : ?T";
```
```   194   thus "?F t";
```
```   195   proof induct;
```
```   196     show "?F {}"; by (rule Finites.emptyI);
```
```   197     fix a t; assume "?F t";
```
```   198     assume "a : domino"; hence "?F a"; by (rule domino_finite);
```
```   199     thus "?F (a Un t)"; by (rule finite_UnI);
```
```   200   qed;
```
```   201 qed;
```
```   202
```
```   203 lemma tiling_domino_01:
```
```   204   "t : tiling domino ==> card (evnodd t 0) = card (evnodd t 1)"
```
```   205   (is "t : ?T ==> ?P t");
```
```   206 proof -;
```
```   207   assume "t : ?T";
```
```   208   thus "?P t";
```
```   209   proof induct;
```
```   210     show "?P {}"; by (simp add: evnodd_def);
```
```   211
```
```   212     fix a t;
```
```   213     let ?e = evnodd;
```
```   214     assume "a : domino" "t : ?T"
```
```   215       and hyp: "card (?e t 0) = card (?e t 1)"
```
```   216       and "a <= - t";
```
```   217
```
```   218     have card_suc:
```
```   219       "!!b. b < 2 ==> card (?e (a Un t) b) = Suc (card (?e t b))";
```
```   220     proof -;
```
```   221       fix b; assume "b < 2";
```
```   222       have "?e (a Un t) b = ?e a b Un ?e t b"; by (rule evnodd_Un);
```
```   223       also; obtain i j where "?e a b = {(i, j)}";
```
```   224       proof -;
```
```   225 	have "EX i j. ?e a b = {(i, j)}"; by (rule domino_singleton);
```
```   226 	thus ?thesis; by blast;
```
```   227       qed;
```
```   228       also; have "... Un ?e t b = insert (i, j) (?e t b)"; by simp;
```
```   229       also; have "card ... = Suc (card (?e t b))";
```
```   230       proof (rule card_insert_disjoint);
```
```   231 	show "finite (?e t b)";
```
```   232           by (rule evnodd_finite, rule tiling_domino_finite);
```
```   233 	have "(i, j) : ?e a b"; by (simp!);
```
```   234 	thus "(i, j) ~: ?e t b"; by (blast! dest: evnoddD);
```
```   235       qed;
```
```   236       finally; show "?thesis b"; .;
```
```   237     qed;
```
```   238     hence "card (?e (a Un t) 0) = Suc (card (?e t 0))"; by simp;
```
```   239     also; from hyp; have "card (?e t 0) = card (?e t 1)"; .;
```
```   240     also; from card_suc; have "Suc ... = card (?e (a Un t) 1)";
```
```   241       by simp;
```
```   242     finally; show "?P (a Un t)"; .;
```
```   243   qed;
```
```   244 qed;
```
```   245
```
```   246
```
```   247 subsection {* Main theorem *};
```
```   248
```
```   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)}";
```
```   254
```
```   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)}";
```
```   261
```
```   262   show "?t'' ~: ?T";
```
```   263   proof;
```
```   264     have t: "?t : ?T"; by (rule dominoes_tile_matrix);
```
```   265     assume t'': "?t'' : ?T";
```
```   266
```
```   267     let ?e = evnodd;
```
```   268     have fin: "finite (?e ?t 0)";
```
```   269       by (rule evnodd_finite, rule tiling_domino_finite, rule t);
```
```   270
```
```   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       thus ?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       thus ?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 "... < ..."; .; thus False; ..;
```
```   296   qed;
```
```   297 qed;
```
```   298
```
```   299 end;
```