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