src/HOL/Isar_Examples/Mutilated_Checkerboard.thy
author wenzelm
Wed Dec 28 20:03:13 2011 +0100 (2011-12-28)
changeset 46008 c296c75f4cf4
parent 40880 be44a567ed28
child 46582 dcc312f22ee8
permissions -rw-r--r--
reverted some changes for set->predicate transition, according to "hg log -u berghofe -r Isabelle2007:Isabelle2008";
tuned proofs;
wenzelm@33026
     1
(*  Title:      HOL/Isar_Examples/Mutilated_Checkerboard.thy
wenzelm@7385
     2
    Author:     Markus Wenzel, TU Muenchen (Isar document)
wenzelm@31758
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory (original scripts)
wenzelm@7382
     4
*)
wenzelm@7382
     5
wenzelm@10007
     6
header {* The Mutilated Checker Board Problem *}
wenzelm@7761
     7
wenzelm@31758
     8
theory Mutilated_Checkerboard
wenzelm@31758
     9
imports Main
wenzelm@31758
    10
begin
wenzelm@7382
    11
wenzelm@37671
    12
text {* The Mutilated Checker Board Problem, formalized inductively.
wenzelm@40880
    13
  See \cite{paulson-mutilated-board} for the original tactic script version. *}
wenzelm@7382
    14
wenzelm@10007
    15
subsection {* Tilings *}
wenzelm@7382
    16
wenzelm@37671
    17
inductive_set tiling :: "'a set set => 'a set set"
berghofe@23746
    18
  for A :: "'a set set"
wenzelm@37671
    19
where
wenzelm@37671
    20
  empty: "{} : tiling A"
wenzelm@37671
    21
| Un: "a : A ==> t : tiling A ==> a <= - t ==> a Un t : tiling A"
wenzelm@7382
    22
wenzelm@7382
    23
wenzelm@10007
    24
text "The union of two disjoint tilings is a tiling."
wenzelm@7382
    25
wenzelm@7761
    26
lemma tiling_Un:
wenzelm@37671
    27
  assumes "t : tiling A"
wenzelm@37671
    28
    and "u : tiling A"
wenzelm@37671
    29
    and "t Int u = {}"
wenzelm@18153
    30
  shows "t Un u : tiling A"
wenzelm@10408
    31
proof -
wenzelm@10408
    32
  let ?T = "tiling A"
wenzelm@18153
    33
  from `t : ?T` and `t Int u = {}`
wenzelm@18153
    34
  show "t Un u : ?T"
wenzelm@10408
    35
  proof (induct t)
wenzelm@11987
    36
    case empty
wenzelm@18153
    37
    with `u : ?T` show "{} Un u : ?T" by simp
wenzelm@9475
    38
  next
wenzelm@11987
    39
    case (Un a t)
wenzelm@10408
    40
    show "(a Un t) Un u : ?T"
wenzelm@10408
    41
    proof -
wenzelm@10408
    42
      have "a Un (t Un u) : ?T"
wenzelm@32960
    43
        using `a : A`
wenzelm@10408
    44
      proof (rule tiling.Un)
wenzelm@18153
    45
        from `(a Un t) Int u = {}` have "t Int u = {}" by blast
wenzelm@18153
    46
        then show "t Un u: ?T" by (rule Un)
wenzelm@23373
    47
        from `a <= - t` and `(a Un t) Int u = {}`
wenzelm@32960
    48
        show "a <= - (t Un u)" by blast
wenzelm@10408
    49
      qed
wenzelm@10408
    50
      also have "a Un (t Un u) = (a Un t) Un u"
wenzelm@10408
    51
        by (simp only: Un_assoc)
wenzelm@10408
    52
      finally show ?thesis .
wenzelm@10408
    53
    qed
wenzelm@10007
    54
  qed
wenzelm@10007
    55
qed
wenzelm@7382
    56
wenzelm@7382
    57
wenzelm@10007
    58
subsection {* Basic properties of ``below'' *}
wenzelm@7382
    59
wenzelm@37671
    60
definition below :: "nat => nat set"
wenzelm@37671
    61
  where "below n = {i. i < n}"
wenzelm@7382
    62
wenzelm@10007
    63
lemma below_less_iff [iff]: "(i: below k) = (i < k)"
wenzelm@10007
    64
  by (simp add: below_def)
wenzelm@7382
    65
wenzelm@10007
    66
lemma below_0: "below 0 = {}"
wenzelm@10007
    67
  by (simp add: below_def)
wenzelm@7382
    68
wenzelm@7761
    69
lemma Sigma_Suc1:
wenzelm@10007
    70
    "m = n + 1 ==> below m <*> B = ({n} <*> B) Un (below n <*> B)"
wenzelm@10007
    71
  by (simp add: below_def less_Suc_eq) blast
wenzelm@7382
    72
wenzelm@7761
    73
lemma Sigma_Suc2:
wenzelm@37671
    74
  "m = n + 2 ==> A <*> below m =
wenzelm@37671
    75
    (A <*> {n}) Un (A <*> {n + 1}) Un (A <*> below n)"
nipkow@13187
    76
  by (auto simp add: below_def)
wenzelm@7382
    77
wenzelm@10007
    78
lemmas Sigma_Suc = Sigma_Suc1 Sigma_Suc2
wenzelm@7382
    79
wenzelm@7382
    80
wenzelm@10007
    81
subsection {* Basic properties of ``evnodd'' *}
wenzelm@7382
    82
wenzelm@37671
    83
definition evnodd :: "(nat * nat) set => nat => (nat * nat) set"
wenzelm@37671
    84
  where "evnodd A b = A Int {(i, j). (i + j) mod 2 = b}"
wenzelm@7382
    85
wenzelm@37671
    86
lemma evnodd_iff: "(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@37671
    90
  unfolding evnodd_def by (rule Int_lower1)
wenzelm@7382
    91
wenzelm@10007
    92
lemma evnoddD: "x : evnodd A b ==> x : A"
wenzelm@37671
    93
  by (rule subsetD) (rule evnodd_subset)
wenzelm@7382
    94
wenzelm@10007
    95
lemma evnodd_finite: "finite A ==> finite (evnodd A b)"
wenzelm@37671
    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@37671
    99
  unfolding evnodd_def by blast
wenzelm@7382
   100
wenzelm@10007
   101
lemma evnodd_Diff: "evnodd (A - B) b = evnodd A b - evnodd B b"
wenzelm@37671
   102
  unfolding evnodd_def by 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@11704
   108
    (if (i + j) mod 2 = b
wenzelm@10007
   109
      then insert (i, j) (evnodd C b) else evnodd C b)"
nipkow@32456
   110
  by (simp add: evnodd_def)
wenzelm@7382
   111
wenzelm@7382
   112
wenzelm@10007
   113
subsection {* Dominoes *}
wenzelm@7382
   114
wenzelm@37671
   115
inductive_set domino :: "(nat * nat) set set"
wenzelm@37671
   116
where
wenzelm@37671
   117
  horiz: "{(i, j), (i, j + 1)} : domino"
wenzelm@37671
   118
| vertl: "{(i, j), (i + 1, j)} : domino"
wenzelm@7382
   119
wenzelm@7800
   120
lemma dominoes_tile_row:
wenzelm@11704
   121
  "{i} <*> below (2 * n) : tiling domino"
wenzelm@11987
   122
  (is "?B n : ?T")
wenzelm@10007
   123
proof (induct n)
wenzelm@11987
   124
  case 0
wenzelm@11987
   125
  show ?case by (simp add: below_0 tiling.empty)
wenzelm@11987
   126
next
wenzelm@11987
   127
  case (Suc n)
wenzelm@11704
   128
  let ?a = "{i} <*> {2 * n + 1} Un {i} <*> {2 * n}"
wenzelm@10007
   129
  have "?B (Suc n) = ?a Un ?B n"
wenzelm@10007
   130
    by (auto simp add: Sigma_Suc Un_assoc)
wenzelm@46008
   131
  also have "... : ?T"
wenzelm@10007
   132
  proof (rule tiling.Un)
wenzelm@11704
   133
    have "{(i, 2 * n), (i, 2 * n + 1)} : domino"
wenzelm@10007
   134
      by (rule domino.horiz)
wenzelm@11704
   135
    also have "{(i, 2 * n), (i, 2 * n + 1)} = ?a" by blast
wenzelm@10007
   136
    finally show "... : domino" .
wenzelm@11987
   137
    show "?B n : ?T" by (rule Suc)
wenzelm@10007
   138
    show "?a <= - ?B n" by blast
wenzelm@10007
   139
  qed
wenzelm@46008
   140
  finally show ?case .
wenzelm@10007
   141
qed
wenzelm@7382
   142
wenzelm@7761
   143
lemma dominoes_tile_matrix:
wenzelm@11704
   144
  "below m <*> below (2 * n) : tiling domino"
wenzelm@11987
   145
  (is "?B m : ?T")
wenzelm@10007
   146
proof (induct m)
wenzelm@11987
   147
  case 0
wenzelm@11987
   148
  show ?case by (simp add: below_0 tiling.empty)
wenzelm@11987
   149
next
wenzelm@11987
   150
  case (Suc m)
wenzelm@11704
   151
  let ?t = "{m} <*> below (2 * n)"
wenzelm@10007
   152
  have "?B (Suc m) = ?t Un ?B m" by (simp add: Sigma_Suc)
wenzelm@46008
   153
  also have "... : ?T"
wenzelm@10408
   154
  proof (rule tiling_Un)
wenzelm@10007
   155
    show "?t : ?T" by (rule dominoes_tile_row)
wenzelm@11987
   156
    show "?B m : ?T" by (rule Suc)
wenzelm@10007
   157
    show "?t Int ?B m = {}" by blast
wenzelm@10007
   158
  qed
wenzelm@46008
   159
  finally show ?case .
wenzelm@10007
   160
qed
wenzelm@7382
   161
wenzelm@7761
   162
lemma domino_singleton:
wenzelm@37671
   163
  assumes "d : domino"
wenzelm@37671
   164
    and "b < 2"
wenzelm@18241
   165
  shows "EX i j. evnodd d b = {(i, j)}"  (is "?P d")
wenzelm@37671
   166
  using assms
wenzelm@18241
   167
proof induct
wenzelm@18241
   168
  from `b < 2` have b_cases: "b = 0 | b = 1" by arith
wenzelm@18241
   169
  fix i j
wenzelm@18241
   170
  note [simp] = evnodd_empty evnodd_insert mod_Suc
wenzelm@18241
   171
  from b_cases show "?P {(i, j), (i, j + 1)}" by rule auto
wenzelm@18241
   172
  from b_cases show "?P {(i, j), (i + 1, j)}" by rule auto
wenzelm@10007
   173
qed
wenzelm@7382
   174
wenzelm@18153
   175
lemma domino_finite:
wenzelm@37671
   176
  assumes "d: domino"
wenzelm@18153
   177
  shows "finite d"
wenzelm@37671
   178
  using assms
wenzelm@18192
   179
proof induct
wenzelm@18192
   180
  fix i j :: nat
berghofe@22273
   181
  show "finite {(i, j), (i, j + 1)}" by (intro finite.intros)
berghofe@22273
   182
  show "finite {(i, j), (i + 1, j)}" by (intro finite.intros)
wenzelm@10007
   183
qed
wenzelm@7382
   184
wenzelm@7382
   185
wenzelm@10007
   186
subsection {* Tilings of dominoes *}
wenzelm@7382
   187
wenzelm@7761
   188
lemma tiling_domino_finite:
wenzelm@18241
   189
  assumes t: "t : tiling domino"  (is "t : ?T")
wenzelm@18153
   190
  shows "finite t"  (is "?F t")
wenzelm@18241
   191
  using t
wenzelm@18153
   192
proof induct
berghofe@22273
   193
  show "?F {}" by (rule finite.emptyI)
wenzelm@18153
   194
  fix a t assume "?F t"
wenzelm@18153
   195
  assume "a : domino" then have "?F a" by (rule domino_finite)
wenzelm@23373
   196
  from this and `?F t` show "?F (a Un t)" by (rule finite_UnI)
wenzelm@10007
   197
qed
wenzelm@7382
   198
wenzelm@7761
   199
lemma tiling_domino_01:
wenzelm@18241
   200
  assumes t: "t : tiling domino"  (is "t : ?T")
wenzelm@18153
   201
  shows "card (evnodd t 0) = card (evnodd t 1)"
wenzelm@18241
   202
  using t
wenzelm@18153
   203
proof induct
wenzelm@18153
   204
  case empty
wenzelm@18153
   205
  show ?case by (simp add: evnodd_def)
wenzelm@18153
   206
next
wenzelm@18153
   207
  case (Un a t)
wenzelm@18153
   208
  let ?e = evnodd
wenzelm@18153
   209
  note hyp = `card (?e t 0) = card (?e t 1)`
wenzelm@18153
   210
    and at = `a <= - t`
wenzelm@18153
   211
  have card_suc:
wenzelm@18153
   212
    "!!b. b < 2 ==> card (?e (a Un t) b) = Suc (card (?e t b))"
wenzelm@18153
   213
  proof -
wenzelm@18153
   214
    fix b :: nat assume "b < 2"
wenzelm@18153
   215
    have "?e (a Un t) b = ?e a b Un ?e t b" by (rule evnodd_Un)
wenzelm@18153
   216
    also obtain i j where e: "?e a b = {(i, j)}"
wenzelm@10007
   217
    proof -
wenzelm@23373
   218
      from `a \<in> domino` and `b < 2`
wenzelm@18153
   219
      have "EX i j. ?e a b = {(i, j)}" by (rule domino_singleton)
wenzelm@18153
   220
      then show ?thesis by (blast intro: that)
wenzelm@10007
   221
    qed
wenzelm@46008
   222
    also have "... Un ?e t b = insert (i, j) (?e t b)" by simp
wenzelm@46008
   223
    also have "card ... = Suc (card (?e t b))"
wenzelm@18153
   224
    proof (rule card_insert_disjoint)
wenzelm@23373
   225
      from `t \<in> tiling domino` have "finite t"
wenzelm@32960
   226
        by (rule tiling_domino_finite)
wenzelm@23373
   227
      then show "finite (?e t b)"
wenzelm@23373
   228
        by (rule evnodd_finite)
wenzelm@18153
   229
      from e have "(i, j) : ?e a b" by simp
wenzelm@18153
   230
      with at show "(i, j) ~: ?e t b" by (blast dest: evnoddD)
wenzelm@18153
   231
    qed
wenzelm@46008
   232
    finally show "?thesis b" .
wenzelm@10007
   233
  qed
wenzelm@18153
   234
  then have "card (?e (a Un t) 0) = Suc (card (?e t 0))" by simp
wenzelm@18153
   235
  also from hyp have "card (?e t 0) = card (?e t 1)" .
wenzelm@18153
   236
  also from card_suc have "Suc ... = card (?e (a Un t) 1)"
wenzelm@18153
   237
    by simp
wenzelm@18153
   238
  finally show ?case .
wenzelm@10007
   239
qed
wenzelm@7382
   240
wenzelm@7382
   241
wenzelm@10007
   242
subsection {* Main theorem *}
wenzelm@7382
   243
wenzelm@37671
   244
definition mutilated_board :: "nat => nat => (nat * nat) set"
wenzelm@37671
   245
where
wenzelm@37671
   246
  "mutilated_board m n =
wenzelm@11704
   247
    below (2 * (m + 1)) <*> below (2 * (n + 1))
wenzelm@11704
   248
      - {(0, 0)} - {(2 * m + 1, 2 * n + 1)}"
wenzelm@7382
   249
wenzelm@10007
   250
theorem mutil_not_tiling: "mutilated_board m n ~: tiling domino"
wenzelm@10007
   251
proof (unfold mutilated_board_def)
wenzelm@10007
   252
  let ?T = "tiling domino"
wenzelm@11704
   253
  let ?t = "below (2 * (m + 1)) <*> below (2 * (n + 1))"
wenzelm@10007
   254
  let ?t' = "?t - {(0, 0)}"
wenzelm@11704
   255
  let ?t'' = "?t' - {(2 * m + 1, 2 * n + 1)}"
wenzelm@37671
   256
  
wenzelm@10007
   257
  show "?t'' ~: ?T"
wenzelm@10007
   258
  proof
wenzelm@10007
   259
    have t: "?t : ?T" by (rule dominoes_tile_matrix)
wenzelm@10007
   260
    assume t'': "?t'' : ?T"
wenzelm@7382
   261
wenzelm@10007
   262
    let ?e = evnodd
wenzelm@10007
   263
    have fin: "finite (?e ?t 0)"
wenzelm@10007
   264
      by (rule evnodd_finite, rule tiling_domino_finite, rule t)
wenzelm@7382
   265
wenzelm@10007
   266
    note [simp] = evnodd_iff evnodd_empty evnodd_insert evnodd_Diff
wenzelm@10007
   267
    have "card (?e ?t'' 0) < card (?e ?t' 0)"
wenzelm@10007
   268
    proof -
wenzelm@11704
   269
      have "card (?e ?t' 0 - {(2 * m + 1, 2 * n + 1)})
wenzelm@10007
   270
        < card (?e ?t' 0)"
wenzelm@10007
   271
      proof (rule card_Diff1_less)
wenzelm@10408
   272
        from _ fin show "finite (?e ?t' 0)"
wenzelm@10007
   273
          by (rule finite_subset) auto
wenzelm@11704
   274
        show "(2 * m + 1, 2 * n + 1) : ?e ?t' 0" by simp
wenzelm@10007
   275
      qed
wenzelm@18153
   276
      then show ?thesis by simp
wenzelm@10007
   277
    qed
wenzelm@10007
   278
    also have "... < card (?e ?t 0)"
wenzelm@10007
   279
    proof -
wenzelm@10007
   280
      have "(0, 0) : ?e ?t 0" by simp
wenzelm@10007
   281
      with fin have "card (?e ?t 0 - {(0, 0)}) < card (?e ?t 0)"
wenzelm@10007
   282
        by (rule card_Diff1_less)
wenzelm@18153
   283
      then show ?thesis by simp
wenzelm@10007
   284
    qed
wenzelm@10007
   285
    also from t have "... = card (?e ?t 1)"
wenzelm@10007
   286
      by (rule tiling_domino_01)
wenzelm@10007
   287
    also have "?e ?t 1 = ?e ?t'' 1" by simp
wenzelm@10007
   288
    also from t'' have "card ... = card (?e ?t'' 0)"
wenzelm@10007
   289
      by (rule tiling_domino_01 [symmetric])
wenzelm@18153
   290
    finally have "... < ..." . then show False ..
wenzelm@10007
   291
  qed
wenzelm@10007
   292
qed
wenzelm@7382
   293
wenzelm@10007
   294
end