src/HOL/Isar_examples/MutilatedCheckerboard.thy
author wenzelm
Sun Jul 30 13:03:49 2000 +0200 (2000-07-30)
changeset 9475 b24516d96847
parent 8814 0a5edcbe0695
child 9596 6d6bf351b2cc
permissions -rw-r--r--
adapted obtain;
tuned;
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@7382
     6
wenzelm@7761
     7
header {* The Mutilated Checker Board Problem *};
wenzelm@7761
     8
wenzelm@7382
     9
theory MutilatedCheckerboard = Main:;
wenzelm@7382
    10
wenzelm@7968
    11
text {*
wenzelm@7968
    12
 The Mutilated Checker Board Problem, formalized inductively.  See
wenzelm@7968
    13
 \cite{paulson-mutilated-board} and
wenzelm@7968
    14
 \url{http://isabelle.in.tum.de/library/HOL/Induct/Mutil.html} for the
wenzelm@7968
    15
 original tactic script version.
wenzelm@7968
    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@8814
    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@9475
    38
  proof (induct (stripped) t);
wenzelm@9475
    39
    assume "u : ?T" "{} Int u = {}"
wenzelm@9475
    40
    thus "{} Un u : ?T" by simp;
wenzelm@9475
    41
  next
wenzelm@7382
    42
    fix a t;
wenzelm@7480
    43
    assume "a : A" "t : ?T" "?P t" "a <= - t";
wenzelm@9475
    44
    assume "u : ?T" "(a Un t) Int u = {}";
wenzelm@9475
    45
    have hyp: "t Un u: ?T"; by (blast!);
wenzelm@9475
    46
    have "a <= - (t Un u)"; by (blast!);
wenzelm@9475
    47
    with _ hyp; have "a Un (t Un u) : ?T"; by (rule tiling.Un);
wenzelm@9475
    48
    also; have "a Un (t Un u) = (a Un t) Un u";
wenzelm@9475
    49
      by (simp only: Un_assoc);
wenzelm@9475
    50
    finally; show "... : ?T"; .;
wenzelm@7382
    51
  qed;
wenzelm@7382
    52
qed;
wenzelm@7382
    53
wenzelm@7382
    54
wenzelm@7874
    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@8814
    68
    "m = n + 1 ==> below m <*> B = ({n} <*> B) Un (below n <*> B)";
wenzelm@7382
    69
  by (simp add: below_def less_Suc_eq) blast;
wenzelm@7382
    70
wenzelm@7761
    71
lemma Sigma_Suc2:
wenzelm@8814
    72
    "m = n + 2 ==> A <*> below m = (A <*> {n}) Un (A <*> {n + 1}) Un (A <*> below n)";
wenzelm@8814
    73
  by (auto simp add: below_def) arith;
wenzelm@7382
    74
wenzelm@7382
    75
lemmas Sigma_Suc = Sigma_Suc1 Sigma_Suc2;
wenzelm@7382
    76
wenzelm@7382
    77
wenzelm@7874
    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@8814
    82
  "evnodd A b == A Int {(i, j). (i + j) mod #2 = b}";
wenzelm@7382
    83
wenzelm@7761
    84
lemma evnodd_iff:
wenzelm@8814
    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@8814
   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@7800
   122
lemma dominoes_tile_row:
nipkow@8703
   123
  "{i} <*> below (2 * n) : tiling domino"
wenzelm@7480
   124
  (is "?P n" is "?B n : ?T");
wenzelm@7382
   125
proof (induct n);
wenzelm@7480
   126
  show "?P 0"; by (simp add: below_0 tiling.empty);
wenzelm@7382
   127
wenzelm@7480
   128
  fix n; assume hyp: "?P n";
nipkow@8703
   129
  let ?a = "{i} <*> {2 * n + 1} Un {i} <*> {2 * n}";
wenzelm@7382
   130
wenzelm@8814
   131
  have "?B (Suc n) = ?a Un ?B n";
wenzelm@8814
   132
    by (auto simp add: Sigma_Suc Un_assoc);
wenzelm@7480
   133
  also; have "... : ?T";
wenzelm@7382
   134
  proof (rule tiling.Un);
wenzelm@7761
   135
    have "{(i, 2 * n), (i, 2 * n + 1)} : domino";
wenzelm@7761
   136
      by (rule domino.horiz);
wenzelm@7480
   137
    also; have "{(i, 2 * n), (i, 2 * n + 1)} = ?a"; by blast;
wenzelm@7385
   138
    finally; show "... : domino"; .;
wenzelm@7480
   139
    from hyp; show "?B n : ?T"; .;
wenzelm@9475
   140
    show "?a <= - ?B n"; by blast;
wenzelm@7382
   141
  qed;
wenzelm@7480
   142
  finally; show "?P (Suc n)"; .;
wenzelm@7382
   143
qed;
wenzelm@7382
   144
wenzelm@7761
   145
lemma dominoes_tile_matrix:
nipkow@8703
   146
  "below m <*> below (2 * n) : tiling domino"
wenzelm@7480
   147
  (is "?P m" is "?B m : ?T");
wenzelm@7382
   148
proof (induct m);
wenzelm@7480
   149
  show "?P 0"; by (simp add: below_0 tiling.empty);
wenzelm@7382
   150
wenzelm@7480
   151
  fix m; assume hyp: "?P m";
nipkow@8703
   152
  let ?t = "{m} <*> below (2 * n)";
wenzelm@7382
   153
wenzelm@7480
   154
  have "?B (Suc m) = ?t Un ?B m"; by (simp add: Sigma_Suc);
wenzelm@7480
   155
  also; have "... : ?T";
wenzelm@7385
   156
  proof (rule tiling_Un [rulify]);
wenzelm@7480
   157
    show "?t : ?T"; by (rule dominoes_tile_row);
wenzelm@7480
   158
    from hyp; show "?B m : ?T"; .;
wenzelm@7480
   159
    show "?t Int ?B m = {}"; by blast;
wenzelm@7382
   160
  qed;
wenzelm@7480
   161
  finally; show "?P (Suc m)"; .;
wenzelm@7382
   162
qed;
wenzelm@7382
   163
wenzelm@7761
   164
lemma domino_singleton:
wenzelm@8814
   165
  "d : domino ==> b < 2 ==> EX i j. evnodd d b = {(i, j)}";
wenzelm@7382
   166
proof -;
wenzelm@7565
   167
  assume b: "b < 2";
wenzelm@7382
   168
  assume "d : domino";
wenzelm@7480
   169
  thus ?thesis (is "?P d");
wenzelm@8297
   170
  proof induct;
wenzelm@7565
   171
    from b; have b_cases: "b = 0 | b = 1"; by arith;
wenzelm@7382
   172
    fix i j;
wenzelm@7385
   173
    note [simp] = evnodd_empty evnodd_insert mod_Suc;
wenzelm@7480
   174
    from b_cases; show "?P {(i, j), (i, j + 1)}"; by rule auto;
wenzelm@7480
   175
    from b_cases; show "?P {(i, j), (i + 1, j)}"; by rule auto;
wenzelm@7382
   176
  qed;
wenzelm@7382
   177
qed;
wenzelm@7382
   178
wenzelm@7382
   179
lemma domino_finite: "d: domino ==> finite d";
wenzelm@7382
   180
proof (induct set: domino);
wenzelm@7434
   181
  fix i j :: nat;
wenzelm@7385
   182
  show "finite {(i, j), (i, j + 1)}"; by (intro Finites.intrs);
wenzelm@7385
   183
  show "finite {(i, j), (i + 1, j)}"; by (intro Finites.intrs);
wenzelm@7382
   184
qed;
wenzelm@7382
   185
wenzelm@7382
   186
wenzelm@7761
   187
subsection {* Tilings of dominoes *};
wenzelm@7382
   188
wenzelm@7761
   189
lemma tiling_domino_finite:
wenzelm@7761
   190
  "t : tiling domino ==> finite t" (is "t : ?T ==> ?F t");
wenzelm@7382
   191
proof -;
wenzelm@7480
   192
  assume "t : ?T";
wenzelm@7480
   193
  thus "?F t";
wenzelm@8297
   194
  proof induct;
wenzelm@7480
   195
    show "?F {}"; by (rule Finites.emptyI);
wenzelm@7480
   196
    fix a t; assume "?F t";
wenzelm@7480
   197
    assume "a : domino"; hence "?F a"; by (rule domino_finite);
wenzelm@7480
   198
    thus "?F (a Un t)"; by (rule finite_UnI);
wenzelm@7382
   199
  qed;
wenzelm@7382
   200
qed;
wenzelm@7382
   201
wenzelm@7761
   202
lemma tiling_domino_01:
wenzelm@7761
   203
  "t : tiling domino ==> card (evnodd t 0) = card (evnodd t 1)"
wenzelm@7480
   204
  (is "t : ?T ==> ?P t");
wenzelm@7382
   205
proof -;
wenzelm@7480
   206
  assume "t : ?T";
wenzelm@7480
   207
  thus "?P t";
wenzelm@8297
   208
  proof induct;
wenzelm@7480
   209
    show "?P {}"; by (simp add: evnodd_def);
wenzelm@7382
   210
wenzelm@7382
   211
    fix a t;
wenzelm@7480
   212
    let ?e = evnodd;
wenzelm@7480
   213
    assume "a : domino" "t : ?T"
wenzelm@7480
   214
      and hyp: "card (?e t 0) = card (?e t 1)"
wenzelm@7382
   215
      and "a <= - t";
wenzelm@7382
   216
wenzelm@7761
   217
    have card_suc:
wenzelm@7761
   218
      "!!b. b < 2 ==> card (?e (a Un t) b) = Suc (card (?e t b))";
wenzelm@7382
   219
    proof -;
wenzelm@7382
   220
      fix b; assume "b < 2";
wenzelm@9475
   221
      have "?e (a Un t) b = ?e a b Un ?e t b"; by (rule evnodd_Un);
wenzelm@9475
   222
      also; obtain i j where "?e a b = {(i, j)}";
wenzelm@9475
   223
      proof -;
wenzelm@9475
   224
	have "EX i j. ?e a b = {(i, j)}"; by (rule domino_singleton);
wenzelm@9475
   225
	thus ?thesis; by blast;
wenzelm@7382
   226
      qed;
wenzelm@9475
   227
      also; have "... Un ?e t b = insert (i, j) (?e t b)"; by simp;
wenzelm@9475
   228
      also; have "card ... = Suc (card (?e t b))";
wenzelm@9475
   229
      proof (rule card_insert_disjoint);
wenzelm@9475
   230
	show "finite (?e t b)";
wenzelm@9475
   231
          by (rule evnodd_finite, rule tiling_domino_finite);
wenzelm@9475
   232
	have "(i, j) : ?e a b"; by (simp!);
wenzelm@9475
   233
	thus "(i, j) ~: ?e t b"; by (blast! dest: evnoddD);
wenzelm@9475
   234
      qed;
wenzelm@9475
   235
      finally; show "?thesis b"; .;
wenzelm@7382
   236
    qed;
wenzelm@7480
   237
    hence "card (?e (a Un t) 0) = Suc (card (?e t 0))"; by simp;
wenzelm@7480
   238
    also; from hyp; have "card (?e t 0) = card (?e t 1)"; .;
wenzelm@7761
   239
    also; from card_suc; have "Suc ... = card (?e (a Un t) 1)";
wenzelm@7761
   240
      by simp;
wenzelm@7480
   241
    finally; show "?P (a Un t)"; .;
wenzelm@7382
   242
  qed;
wenzelm@7382
   243
qed;
wenzelm@7382
   244
wenzelm@7382
   245
wenzelm@7761
   246
subsection {* Main theorem *};
wenzelm@7382
   247
wenzelm@7382
   248
constdefs
wenzelm@7382
   249
  mutilated_board :: "nat => nat => (nat * nat) set"
wenzelm@7761
   250
  "mutilated_board m n ==
nipkow@8703
   251
    below (2 * (m + 1)) <*> below (2 * (n + 1))
wenzelm@7761
   252
      - {(0, 0)} - {(2 * m + 1, 2 * n + 1)}";
wenzelm@7382
   253
wenzelm@7385
   254
theorem mutil_not_tiling: "mutilated_board m n ~: tiling domino";
wenzelm@7382
   255
proof (unfold mutilated_board_def);
wenzelm@7480
   256
  let ?T = "tiling domino";
nipkow@8703
   257
  let ?t = "below (2 * (m + 1)) <*> below (2 * (n + 1))";
wenzelm@7480
   258
  let ?t' = "?t - {(0, 0)}";
wenzelm@7480
   259
  let ?t'' = "?t' - {(2 * m + 1, 2 * n + 1)}";
wenzelm@7761
   260
wenzelm@7480
   261
  show "?t'' ~: ?T";
wenzelm@7382
   262
  proof;
wenzelm@7480
   263
    have t: "?t : ?T"; by (rule dominoes_tile_matrix);
wenzelm@7480
   264
    assume t'': "?t'' : ?T";
wenzelm@7382
   265
wenzelm@7480
   266
    let ?e = evnodd;
wenzelm@7761
   267
    have fin: "finite (?e ?t 0)";
wenzelm@7761
   268
      by (rule evnodd_finite, rule tiling_domino_finite, rule t);
wenzelm@7382
   269
wenzelm@7385
   270
    note [simp] = evnodd_iff evnodd_empty evnodd_insert evnodd_Diff;
wenzelm@7480
   271
    have "card (?e ?t'' 0) < card (?e ?t' 0)";
wenzelm@7382
   272
    proof -;
wenzelm@7800
   273
      have "card (?e ?t' 0 - {(2 * m + 1, 2 * n + 1)})
wenzelm@7800
   274
        < card (?e ?t' 0)";
wenzelm@7382
   275
      proof (rule card_Diff1_less);
wenzelm@8674
   276
	from _ fin; show "finite (?e ?t' 0)";
wenzelm@9475
   277
          by (rule finite_subset) auto;
wenzelm@7480
   278
	show "(2 * m + 1, 2 * n + 1) : ?e ?t' 0"; by simp;
wenzelm@7382
   279
      qed;
wenzelm@7480
   280
      thus ?thesis; by simp;
wenzelm@7382
   281
    qed;
wenzelm@7480
   282
    also; have "... < card (?e ?t 0)";
wenzelm@7382
   283
    proof -;
wenzelm@7480
   284
      have "(0, 0) : ?e ?t 0"; by simp;
wenzelm@7761
   285
      with fin; have "card (?e ?t 0 - {(0, 0)}) < card (?e ?t 0)";
wenzelm@7761
   286
        by (rule card_Diff1_less);
wenzelm@7480
   287
      thus ?thesis; by simp;
wenzelm@7382
   288
    qed;
wenzelm@7800
   289
    also; from t; have "... = card (?e ?t 1)";
wenzelm@7800
   290
      by (rule tiling_domino_01);
wenzelm@7480
   291
    also; have "?e ?t 1 = ?e ?t'' 1"; by simp;
wenzelm@7761
   292
    also; from t''; have "card ... = card (?e ?t'' 0)";
wenzelm@7761
   293
      by (rule tiling_domino_01 [RS sym]);
wenzelm@7874
   294
    finally; have "... < ..."; .; thus False; ..;
wenzelm@7382
   295
  qed;
wenzelm@7382
   296
qed;
wenzelm@7382
   297
wenzelm@7383
   298
end;