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