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