src/HOL/Isar_examples/MutilatedCheckerboard.thy
author wenzelm
Mon Nov 06 22:56:07 2000 +0100 (2000-11-06)
changeset 10408 d8b3613158b1
parent 10387 9dac2cad5500
child 11701 3d51fbf81c17
permissions -rw-r--r--
improved: 'induct' handle non-atomic goals;
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@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@10408
    40
    from u show "{} Un u : ?T" by simp
wenzelm@9475
    41
  next
wenzelm@10007
    42
    fix a t
wenzelm@10408
    43
    assume "a : A" and hyp: "PROP ?P t"
wenzelm@10408
    44
      and at: "a <= - t" and atu: "(a Un t) Int u = {}"
wenzelm@10408
    45
    show "(a Un t) Un u : ?T"
wenzelm@10408
    46
    proof -
wenzelm@10408
    47
      have "a Un (t Un u) : ?T"
wenzelm@10408
    48
      proof (rule tiling.Un)
wenzelm@10408
    49
        show "a : A" .
wenzelm@10408
    50
        from atu have "t Int u = {}" by blast
wenzelm@10408
    51
        thus "t Un u: ?T" by (rule hyp)
wenzelm@10408
    52
        from at atu show "a <= - (t Un u)" by blast
wenzelm@10408
    53
      qed
wenzelm@10408
    54
      also have "a Un (t Un u) = (a Un t) Un u"
wenzelm@10408
    55
        by (simp only: Un_assoc)
wenzelm@10408
    56
      finally show ?thesis .
wenzelm@10408
    57
    qed
wenzelm@10007
    58
  qed
wenzelm@10007
    59
qed
wenzelm@7382
    60
wenzelm@7382
    61
wenzelm@10007
    62
subsection {* Basic properties of ``below'' *}
wenzelm@7382
    63
wenzelm@7382
    64
constdefs
wenzelm@7382
    65
  below :: "nat => nat set"
wenzelm@10007
    66
  "below n == {i. i < n}"
wenzelm@7382
    67
wenzelm@10007
    68
lemma below_less_iff [iff]: "(i: below k) = (i < k)"
wenzelm@10007
    69
  by (simp add: below_def)
wenzelm@7382
    70
wenzelm@10007
    71
lemma below_0: "below 0 = {}"
wenzelm@10007
    72
  by (simp add: below_def)
wenzelm@7382
    73
wenzelm@7761
    74
lemma Sigma_Suc1:
wenzelm@10007
    75
    "m = n + 1 ==> below m <*> B = ({n} <*> B) Un (below n <*> B)"
wenzelm@10007
    76
  by (simp add: below_def less_Suc_eq) blast
wenzelm@7382
    77
wenzelm@7761
    78
lemma Sigma_Suc2:
wenzelm@9659
    79
    "m = n + 2 ==> A <*> below m =
wenzelm@10007
    80
      (A <*> {n}) Un (A <*> {n + 1}) Un (A <*> below n)"
wenzelm@10007
    81
  by (auto simp add: below_def) arith
wenzelm@7382
    82
wenzelm@10007
    83
lemmas Sigma_Suc = Sigma_Suc1 Sigma_Suc2
wenzelm@7382
    84
wenzelm@7382
    85
wenzelm@10007
    86
subsection {* Basic properties of ``evnodd'' *}
wenzelm@7382
    87
wenzelm@7382
    88
constdefs
wenzelm@7385
    89
  evnodd :: "(nat * nat) set => nat => (nat * nat) set"
wenzelm@10007
    90
  "evnodd A b == A Int {(i, j). (i + j) mod #2 = b}"
wenzelm@7382
    91
wenzelm@7761
    92
lemma evnodd_iff:
wenzelm@10007
    93
    "(i, j): evnodd A b = ((i, j): A  & (i + j) mod #2 = b)"
wenzelm@10007
    94
  by (simp add: evnodd_def)
wenzelm@7382
    95
wenzelm@10007
    96
lemma evnodd_subset: "evnodd A b <= A"
wenzelm@10007
    97
  by (unfold evnodd_def, rule Int_lower1)
wenzelm@7382
    98
wenzelm@10007
    99
lemma evnoddD: "x : evnodd A b ==> x : A"
wenzelm@10007
   100
  by (rule subsetD, rule evnodd_subset)
wenzelm@7382
   101
wenzelm@10007
   102
lemma evnodd_finite: "finite A ==> finite (evnodd A b)"
wenzelm@10007
   103
  by (rule finite_subset, rule evnodd_subset)
wenzelm@7382
   104
wenzelm@10007
   105
lemma evnodd_Un: "evnodd (A Un B) b = evnodd A b Un evnodd B b"
wenzelm@10007
   106
  by (unfold evnodd_def) blast
wenzelm@7382
   107
wenzelm@10007
   108
lemma evnodd_Diff: "evnodd (A - B) b = evnodd A b - evnodd B b"
wenzelm@10007
   109
  by (unfold evnodd_def) blast
wenzelm@7382
   110
wenzelm@10007
   111
lemma evnodd_empty: "evnodd {} b = {}"
wenzelm@10007
   112
  by (simp add: evnodd_def)
wenzelm@7382
   113
wenzelm@7385
   114
lemma evnodd_insert: "evnodd (insert (i, j) C) b =
wenzelm@8814
   115
    (if (i + j) mod #2 = b
wenzelm@10007
   116
      then insert (i, j) (evnodd C b) else evnodd C b)"
wenzelm@10007
   117
  by (simp add: evnodd_def) blast
wenzelm@7382
   118
wenzelm@7382
   119
wenzelm@10007
   120
subsection {* Dominoes *}
wenzelm@7382
   121
wenzelm@10408
   122
consts
wenzelm@10007
   123
  domino :: "(nat * nat) set set"
wenzelm@7382
   124
wenzelm@7382
   125
inductive domino
wenzelm@9596
   126
  intros
wenzelm@10408
   127
    horiz: "{(i, j), (i, j + 1)} : domino"
wenzelm@10408
   128
    vertl: "{(i, j), (i + 1, j)} : domino"
wenzelm@7382
   129
wenzelm@7800
   130
lemma dominoes_tile_row:
nipkow@8703
   131
  "{i} <*> below (2 * n) : tiling domino"
wenzelm@10007
   132
  (is "?P n" is "?B n : ?T")
wenzelm@10007
   133
proof (induct n)
wenzelm@10007
   134
  show "?P 0" by (simp add: below_0 tiling.empty)
wenzelm@7382
   135
wenzelm@10007
   136
  fix n assume hyp: "?P n"
wenzelm@10007
   137
  let ?a = "{i} <*> {2 * n + 1} Un {i} <*> {2 * n}"
wenzelm@7382
   138
wenzelm@10007
   139
  have "?B (Suc n) = ?a Un ?B n"
wenzelm@10007
   140
    by (auto simp add: Sigma_Suc Un_assoc)
wenzelm@10007
   141
  also have "... : ?T"
wenzelm@10007
   142
  proof (rule tiling.Un)
wenzelm@10007
   143
    have "{(i, 2 * n), (i, 2 * n + 1)} : domino"
wenzelm@10007
   144
      by (rule domino.horiz)
wenzelm@10007
   145
    also have "{(i, 2 * n), (i, 2 * n + 1)} = ?a" by blast
wenzelm@10007
   146
    finally show "... : domino" .
wenzelm@10007
   147
    from hyp show "?B n : ?T" .
wenzelm@10007
   148
    show "?a <= - ?B n" by blast
wenzelm@10007
   149
  qed
wenzelm@10007
   150
  finally show "?P (Suc n)" .
wenzelm@10007
   151
qed
wenzelm@7382
   152
wenzelm@7761
   153
lemma dominoes_tile_matrix:
nipkow@8703
   154
  "below m <*> below (2 * n) : tiling domino"
wenzelm@10007
   155
  (is "?P m" is "?B m : ?T")
wenzelm@10007
   156
proof (induct m)
wenzelm@10007
   157
  show "?P 0" by (simp add: below_0 tiling.empty)
wenzelm@7382
   158
wenzelm@10007
   159
  fix m assume hyp: "?P m"
wenzelm@10007
   160
  let ?t = "{m} <*> below (2 * n)"
wenzelm@7382
   161
wenzelm@10007
   162
  have "?B (Suc m) = ?t Un ?B m" by (simp add: Sigma_Suc)
wenzelm@10007
   163
  also have "... : ?T"
wenzelm@10408
   164
  proof (rule tiling_Un)
wenzelm@10007
   165
    show "?t : ?T" by (rule dominoes_tile_row)
wenzelm@10007
   166
    from hyp show "?B m : ?T" .
wenzelm@10007
   167
    show "?t Int ?B m = {}" by blast
wenzelm@10007
   168
  qed
wenzelm@10007
   169
  finally show "?P (Suc m)" .
wenzelm@10007
   170
qed
wenzelm@7382
   171
wenzelm@7761
   172
lemma domino_singleton:
wenzelm@10007
   173
  "d : domino ==> b < 2 ==> EX i j. evnodd d b = {(i, j)}"
wenzelm@10007
   174
proof -
wenzelm@10007
   175
  assume b: "b < 2"
wenzelm@10007
   176
  assume "d : domino"
wenzelm@10007
   177
  thus ?thesis (is "?P d")
wenzelm@10007
   178
  proof induct
wenzelm@10007
   179
    from b have b_cases: "b = 0 | b = 1" by arith
wenzelm@10007
   180
    fix i j
wenzelm@10007
   181
    note [simp] = evnodd_empty evnodd_insert mod_Suc
wenzelm@10007
   182
    from b_cases show "?P {(i, j), (i, j + 1)}" by rule auto
wenzelm@10007
   183
    from b_cases show "?P {(i, j), (i + 1, j)}" by rule auto
wenzelm@10007
   184
  qed
wenzelm@10007
   185
qed
wenzelm@7382
   186
wenzelm@10007
   187
lemma domino_finite: "d: domino ==> finite d"
wenzelm@10408
   188
proof -
wenzelm@10408
   189
  assume "d: domino"
wenzelm@10408
   190
  thus ?thesis
wenzelm@10408
   191
  proof induct
wenzelm@10408
   192
    fix i j :: nat
wenzelm@10408
   193
    show "finite {(i, j), (i, j + 1)}" by (intro Finites.intros)
wenzelm@10408
   194
    show "finite {(i, j), (i + 1, j)}" by (intro Finites.intros)
wenzelm@10408
   195
  qed
wenzelm@10007
   196
qed
wenzelm@7382
   197
wenzelm@7382
   198
wenzelm@10007
   199
subsection {* Tilings of dominoes *}
wenzelm@7382
   200
wenzelm@7761
   201
lemma tiling_domino_finite:
wenzelm@10007
   202
  "t : tiling domino ==> finite t" (is "t : ?T ==> ?F t")
wenzelm@10007
   203
proof -
wenzelm@10007
   204
  assume "t : ?T"
wenzelm@10007
   205
  thus "?F t"
wenzelm@10007
   206
  proof induct
wenzelm@10007
   207
    show "?F {}" by (rule Finites.emptyI)
wenzelm@10007
   208
    fix a t assume "?F t"
wenzelm@10007
   209
    assume "a : domino" hence "?F a" by (rule domino_finite)
wenzelm@10007
   210
    thus "?F (a Un t)" by (rule finite_UnI)
wenzelm@10007
   211
  qed
wenzelm@10007
   212
qed
wenzelm@7382
   213
wenzelm@7761
   214
lemma tiling_domino_01:
wenzelm@7761
   215
  "t : tiling domino ==> card (evnodd t 0) = card (evnodd t 1)"
wenzelm@10007
   216
  (is "t : ?T ==> ?P t")
wenzelm@10007
   217
proof -
wenzelm@10007
   218
  assume "t : ?T"
wenzelm@10007
   219
  thus "?P t"
wenzelm@10007
   220
  proof induct
wenzelm@10007
   221
    show "?P {}" by (simp add: evnodd_def)
wenzelm@7382
   222
wenzelm@10007
   223
    fix a t
wenzelm@10007
   224
    let ?e = evnodd
wenzelm@10408
   225
    assume "a : domino" and "t : ?T"
wenzelm@7480
   226
      and hyp: "card (?e t 0) = card (?e t 1)"
wenzelm@10408
   227
      and at: "a <= - t"
wenzelm@7382
   228
wenzelm@7761
   229
    have card_suc:
wenzelm@10007
   230
      "!!b. b < 2 ==> card (?e (a Un t) b) = Suc (card (?e t b))"
wenzelm@10007
   231
    proof -
wenzelm@10007
   232
      fix b 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@10007
   253
    finally show "?P (a Un t)" .
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 ==
nipkow@8703
   263
    below (2 * (m + 1)) <*> below (2 * (n + 1))
wenzelm@10007
   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@10007
   269
  let ?t = "below (2 * (m + 1)) <*> below (2 * (n + 1))"
wenzelm@10007
   270
  let ?t' = "?t - {(0, 0)}"
wenzelm@10007
   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@7800
   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@10408
   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