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