src/HOL/Isar_examples/MutilatedCheckerboard.thy
author wenzelm
Sat Sep 04 21:13:01 1999 +0200 (1999-09-04)
changeset 7480 0a0e0dbe1269
parent 7447 d09f39cd3b6e
child 7565 bfa85f429629
permissions -rw-r--r--
replaced ?? by ?;
     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 The Mutilated Checker Board Problem, formalized inductively.
     7   Originator is Max Black, according to J A Robinson.
     8   Popularized as the Mutilated Checkerboard Problem by J McCarthy.
     9 
    10 See also HOL/Induct/Mutil for the original Isabelle tactic scripts.
    11 *)
    12 
    13 theory MutilatedCheckerboard = Main:;
    14 
    15 
    16 section {* Tilings *};
    17 
    18 consts
    19   tiling :: "'a set set => 'a set set";
    20 
    21 inductive "tiling A"
    22   intrs
    23     empty: "{} : tiling A"
    24     Un:    "[| a : A;  t : tiling A;  a <= - t |] ==> a Un t : tiling A";
    25 
    26 
    27 text "The union of two disjoint tilings is a tiling";
    28 
    29 lemma tiling_Un: "t : tiling A --> u : tiling A --> t Int u = {} --> t Un u : tiling A";
    30 proof;
    31   assume "t : tiling A" (is "_ : ?T");
    32   thus "u : ?T --> t Int u = {} --> t Un u : ?T" (is "?P t");
    33   proof (induct t set: tiling);
    34     show "?P {}"; by simp;
    35 
    36     fix a t;
    37     assume "a : A" "t : ?T" "?P t" "a <= - t";
    38     show "?P (a Un t)";
    39     proof (intro impI);
    40       assume "u : ?T" "(a Un t) Int u = {}";
    41       have hyp: "t Un u: ?T"; by blast;
    42       have "a <= - (t Un u)"; by blast;
    43       with _ hyp; have "a Un (t Un u) : ?T"; by (rule tiling.Un);
    44       also; have "a Un (t Un u) = (a Un t) Un u"; by (simp only: Un_assoc);
    45       finally; show "... : ?T"; .;
    46     qed;
    47   qed;
    48 qed;
    49 
    50 
    51 section {* Basic properties of below *};
    52 
    53 constdefs
    54   below :: "nat => nat set"
    55   "below n == {i. i < n}";
    56 
    57 lemma below_less_iff [iff]: "(i: below k) = (i < k)";
    58   by (simp add: below_def);
    59 
    60 lemma below_0: "below 0 = {}";
    61   by (simp add: below_def);
    62 
    63 lemma Sigma_Suc1: "below (Suc n) Times B = ({n} Times B) Un (below n Times B)";
    64   by (simp add: below_def less_Suc_eq) blast;
    65 
    66 lemma Sigma_Suc2: "A Times below (Suc n) = (A Times {n}) Un (A Times (below n))";
    67   by (simp add: below_def less_Suc_eq) blast;
    68 
    69 lemmas Sigma_Suc = Sigma_Suc1 Sigma_Suc2;
    70 
    71 
    72 section {* Basic properties of evnodd *};
    73 
    74 constdefs
    75   evnodd :: "(nat * nat) set => nat => (nat * nat) set"
    76   "evnodd A b == A Int {(i, j). (i + j) mod 2 = b}";
    77 
    78 lemma evnodd_iff: "(i, j): evnodd A b = ((i, j): A  & (i + j) mod 2 = b)";
    79   by (simp add: evnodd_def);
    80 
    81 lemma evnodd_subset: "evnodd A b <= A";
    82   by (unfold evnodd_def, rule Int_lower1);
    83 
    84 lemma evnoddD: "x : evnodd A b ==> x : A";
    85   by (rule subsetD, rule evnodd_subset);
    86 
    87 lemma evnodd_finite: "finite A ==> finite (evnodd A b)";
    88   by (rule finite_subset, rule evnodd_subset);
    89 
    90 lemma evnodd_Un: "evnodd (A Un B) b = evnodd A b Un evnodd B b";
    91   by (unfold evnodd_def) blast;
    92 
    93 lemma evnodd_Diff: "evnodd (A - B) b = evnodd A b - evnodd B b";
    94   by (unfold evnodd_def) blast;
    95 
    96 lemma evnodd_empty: "evnodd {} b = {}";
    97   by (simp add: evnodd_def);
    98 
    99 lemma evnodd_insert: "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 (simp add: evnodd_def) blast;
   102 
   103 
   104 section {* Dominoes *};
   105 
   106 consts 
   107   domino  :: "(nat * nat) set set";
   108 
   109 inductive domino
   110   intrs
   111     horiz:  "{(i, j), (i, j + 1)} : domino"
   112     vertl:  "{(i, j), (i + 1, j)} : domino";
   113 
   114 
   115 lemma dominoes_tile_row: "{i} Times below (2 * n) : tiling domino"
   116   (is "?P n" is "?B n : ?T");
   117 proof (induct n);
   118   show "?P 0"; by (simp add: below_0 tiling.empty);
   119 
   120   fix n; assume hyp: "?P n";
   121   let ?a = "{i} Times {2 * n + 1} Un {i} Times {2 * n}";
   122 
   123   have "?B (Suc n) = ?a Un ?B n"; by (simp add: Sigma_Suc Un_assoc);
   124   also; have "... : ?T";
   125   proof (rule tiling.Un);
   126     have "{(i, 2 * n), (i, 2 * n + 1)} : domino"; by (rule domino.horiz);
   127     also; have "{(i, 2 * n), (i, 2 * n + 1)} = ?a"; by blast;
   128     finally; show "... : domino"; .;
   129     from hyp; show "?B n : ?T"; .;
   130     show "?a <= - ?B n"; by force;
   131   qed;
   132   finally; show "?P (Suc n)"; .;
   133 qed;
   134 
   135 lemma dominoes_tile_matrix: "below m Times below (2 * n) : tiling domino"
   136   (is "?P m" is "?B m : ?T");
   137 proof (induct m);
   138   show "?P 0"; by (simp add: below_0 tiling.empty);
   139 
   140   fix m; assume hyp: "?P m";
   141   let ?t = "{m} Times below (2 * n)";
   142 
   143   have "?B (Suc m) = ?t Un ?B m"; by (simp add: Sigma_Suc);
   144   also; have "... : ?T";
   145   proof (rule tiling_Un [rulify]);
   146     show "?t : ?T"; by (rule dominoes_tile_row);
   147     from hyp; show "?B m : ?T"; .;
   148     show "?t Int ?B m = {}"; by blast;
   149   qed;
   150   finally; show "?P (Suc m)"; .;
   151 qed;
   152 
   153 
   154 lemma domino_singleton: "[| d : domino; b < 2 |] ==> EX i j. evnodd d b = {(i, j)}";
   155 proof -;
   156   assume "b < 2";
   157   assume "d : domino";
   158   thus ?thesis (is "?P d");
   159   proof (induct d set: domino);
   160     have b_cases: "b = 0 | b = 1"; by arith;
   161     fix i j;
   162     note [simp] = evnodd_empty evnodd_insert mod_Suc;
   163     from b_cases; show "?P {(i, j), (i, j + 1)}"; by rule auto;
   164     from b_cases; show "?P {(i, j), (i + 1, j)}"; by rule auto;
   165   qed;
   166 qed;
   167 
   168 lemma domino_finite: "d: domino ==> finite d";
   169 proof (induct set: domino);
   170   fix i j :: nat;
   171   show "finite {(i, j), (i, j + 1)}"; by (intro Finites.intrs);
   172   show "finite {(i, j), (i + 1, j)}"; by (intro Finites.intrs);
   173 qed;
   174 
   175 
   176 section {* Tilings of dominoes *};
   177 
   178 lemma tiling_domino_finite: "t : tiling domino ==> finite t" (is "t : ?T ==> ?F t");
   179 proof -;
   180   assume "t : ?T";
   181   thus "?F t";
   182   proof (induct t set: tiling);
   183     show "?F {}"; by (rule Finites.emptyI);
   184     fix a t; assume "?F t";
   185     assume "a : domino"; hence "?F a"; by (rule domino_finite);
   186     thus "?F (a Un t)"; by (rule finite_UnI);
   187   qed;
   188 qed;
   189 
   190 lemma tiling_domino_01: "t : tiling domino ==> card (evnodd t 0) = card (evnodd t 1)"
   191   (is "t : ?T ==> ?P t");
   192 proof -;
   193   assume "t : ?T";
   194   thus "?P t";
   195   proof (induct t set: tiling);
   196     show "?P {}"; by (simp add: evnodd_def);
   197 
   198     fix a t;
   199     let ?e = evnodd;
   200     assume "a : domino" "t : ?T"
   201       and hyp: "card (?e t 0) = card (?e t 1)"
   202       and "a <= - t";
   203 
   204     have card_suc: "!!b. b < 2 ==> card (?e (a Un t) b) = Suc (card (?e t b))";
   205     proof -;
   206       fix b; assume "b < 2";
   207       have "EX i j. ?e a b = {(i, j)}"; by (rule domino_singleton);
   208       thus "?thesis b";
   209       proof (elim exE);
   210 	have "?e (a Un t) b = ?e a b Un ?e t b"; by (rule evnodd_Un);
   211 	also; fix i j; assume "?e a b = {(i, j)}";
   212 	also; have "... Un ?e t b = insert (i, j) (?e t b)"; by simp;
   213 	also; have "card ... = Suc (card (?e t b))";
   214 	proof (rule card_insert_disjoint);
   215 	  show "finite (?e t b)"; by (rule evnodd_finite, rule tiling_domino_finite);
   216 	  have "(i, j) : ?e a b"; by asm_simp;
   217 	  thus "(i, j) ~: ?e t b"; by (force dest: evnoddD);
   218 	qed;
   219 	finally; show ?thesis; .;
   220       qed;
   221     qed;
   222     hence "card (?e (a Un t) 0) = Suc (card (?e t 0))"; by simp;
   223     also; from hyp; have "card (?e t 0) = card (?e t 1)"; .;
   224     also; from card_suc; have "Suc ... = card (?e (a Un t) 1)"; by simp;
   225     finally; show "?P (a Un t)"; .;
   226   qed;
   227 qed;
   228 
   229 
   230 section {* Main theorem *};
   231 
   232 constdefs
   233   mutilated_board :: "nat => nat => (nat * nat) set"
   234   "mutilated_board m n == below (2 * (m + 1)) Times below (2 * (n + 1))
   235     - {(0, 0)} - {(2 * m + 1, 2 * n + 1)}";
   236 
   237 theorem mutil_not_tiling: "mutilated_board m n ~: tiling domino";
   238 proof (unfold mutilated_board_def);
   239   let ?T = "tiling domino";
   240   let ?t = "below (2 * (m + 1)) Times below (2 * (n + 1))";
   241   let ?t' = "?t - {(0, 0)}";
   242   let ?t'' = "?t' - {(2 * m + 1, 2 * n + 1)}";
   243   show "?t'' ~: ?T";
   244   proof;
   245     have t: "?t : ?T"; by (rule dominoes_tile_matrix);
   246     assume t'': "?t'' : ?T";
   247 
   248     let ?e = evnodd;
   249     have fin: "finite (?e ?t 0)"; by (rule evnodd_finite, rule tiling_domino_finite, rule t);
   250 
   251     note [simp] = evnodd_iff evnodd_empty evnodd_insert evnodd_Diff;
   252     have "card (?e ?t'' 0) < card (?e ?t' 0)";
   253     proof -;
   254       have "card (?e ?t' 0 - {(2 * m + 1, 2 * n + 1)}) < card (?e ?t' 0)";
   255       proof (rule card_Diff1_less);
   256 	show "finite (?e ?t' 0)"; by (rule finite_subset, rule fin) force;
   257 	show "(2 * m + 1, 2 * n + 1) : ?e ?t' 0"; by simp;
   258       qed;
   259       thus ?thesis; by simp;
   260     qed;
   261     also; have "... < card (?e ?t 0)";
   262     proof -;
   263       have "(0, 0) : ?e ?t 0"; by simp;
   264       with fin; have "card (?e ?t 0 - {(0, 0)}) < card (?e ?t 0)"; by (rule card_Diff1_less);
   265       thus ?thesis; by simp;
   266     qed;
   267     also; from t; have "... = card (?e ?t 1)"; by (rule tiling_domino_01);
   268     also; have "?e ?t 1 = ?e ?t'' 1"; by simp;
   269     also; from t''; have "card ... = card (?e ?t'' 0)"; by (rule tiling_domino_01 [RS sym]);
   270     finally; show False; ..;
   271   qed;
   272 qed;
   273 
   274 
   275 end;