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