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