src/ZF/ex/Mutil.ML
author paulson
Tue, 26 Mar 1996 11:32:14 +0100
changeset 1606 dd66bed09592
child 1624 e2a6102b9369
permissions -rw-r--r--
New example: mutilated checkerboard
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1606
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
     1
(*  Title:      ZF/ex/Mutil
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
     2
    ID:         $Id$
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
     4
    Copyright   1996  University of Cambridge
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
     5
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
     6
The Mutilated Checkerboard Problem, formalized inductively
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
     7
*)
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
     8
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
     9
open Mutil;
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    10
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    11
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    12
(** Basic properties of evnodd **)
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    13
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    14
goalw thy [evnodd_def]
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    15
    "!!i j. [| <i,j>: A;  (i#+j) mod 2 = b |] ==> <i,j>: evnodd(A,b)";
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    16
by (fast_tac ZF_cs 1);
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    17
qed "evnoddI";
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    18
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    19
val major::prems = goalw thy [evnodd_def]
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    20
    "[| z: evnodd(A,b);     \
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    21
\       !!i j. [| z=<i,j>;  <i,j>: A;  (i#+j) mod 2 = b |] ==> P |] ==> P";
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    22
br (major RS CollectE) 1;
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    23
by (REPEAT (eresolve_tac [exE,conjE] 1));
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    24
by (resolve_tac prems 1);
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    25
by (REPEAT (fast_tac ZF_cs 1));
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    26
qed "evnoddE";
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    27
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    28
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    29
goalw thy [evnodd_def] "evnodd(A, b) <= A";
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    30
by (fast_tac ZF_cs 1);
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    31
qed "evnodd_subset";
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    32
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    33
(* Finite(X) ==> Finite(evnodd(X,b)) *)
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    34
bind_thm("Finite_evnodd", evnodd_subset RS subset_imp_lepoll RS lepoll_Finite);
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    35
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    36
goalw thy [evnodd_def] "evnodd(A Un B, b) = evnodd(A,b) Un evnodd(B,b)";
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    37
by (simp_tac (ZF_ss addsimps [Collect_Un]) 1);
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    38
qed "evnodd_Un";
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    39
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    40
goalw thy [evnodd_def] "evnodd(A - B, b) = evnodd(A,b) - evnodd(B,b)";
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    41
by (simp_tac (ZF_ss addsimps [Collect_Diff]) 1);
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    42
qed "evnodd_Diff";
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    43
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    44
goalw thy [evnodd_def]
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    45
    "evnodd(cons(<i,j>,C), b) = \
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    46
\    if((i#+j) mod 2 = b, cons(<i,j>, evnodd(C,b)), evnodd(C,b))";
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    47
by (asm_simp_tac (ZF_ss addsimps [evnodd_def, Collect_cons] 
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    48
                        setloop split_tac [expand_if]) 1);
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    49
by (fast_tac ZF_cs 1);
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    50
qed "evnodd_cons";
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    51
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    52
goalw thy [evnodd_def] "evnodd(0, b) = 0";
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    53
by (simp_tac (ZF_ss addsimps [evnodd_def]) 1);
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    54
qed "evnodd_0";
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    55
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    56
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    57
(*** Dominoes ***)
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    58
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    59
goal thy "!!d. d:domino ==> Finite(d)";
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    60
by (fast_tac (ZF_cs addSIs [Finite_cons, Finite_0] addEs [domino.elim]) 1);
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    61
qed "domino_Finite";
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    62
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    63
goal thy "!!d. [| d:domino; b<2 |] ==> EX i' j'. evnodd(d,b) = {<i',j'>}";
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    64
by (eresolve_tac [domino.elim] 1);
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    65
by (res_inst_tac [("k1", "i#+j")] (mod2_cases RS disjE) 2);
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    66
by (res_inst_tac [("k1", "i#+j")] (mod2_cases RS disjE) 1);
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    67
by (REPEAT_FIRST (ares_tac [add_type]));
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    68
(*Four similar cases: case (i#+j) mod 2 = b, 2#-b, ...*)
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    69
by (REPEAT (asm_simp_tac (arith_ss addsimps [evnodd_cons, evnodd_0, mod_succ,
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    70
					     succ_neq_self] 
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    71
                                   setloop split_tac [expand_if]) 1
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    72
           THEN fast_tac (ZF_cs addDs [ltD]) 1));
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    73
qed "domino_singleton";
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    74
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    75
val prems = goal thy "[| d:domino; b<2 |] ==> |evnodd(d,b)| = 1";
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    76
by (cut_facts_tac [prems MRS domino_singleton] 1);
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    77
by (REPEAT (etac exE 1));
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    78
by (asm_simp_tac (ZF_ss addsimps [cardinal_singleton]) 1);
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    79
qed "cardinal_evnodd_domino";
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    80
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    81
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    82
(*** Tilings ***)
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    83
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    84
(** The union of two disjoint tilings is a tiling **)
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    85
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    86
goal thy "!!t. t: tiling(A) ==> \
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    87
\              ALL u: tiling(A). t Int u = 0 --> t Un u : tiling(A)";
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    88
by (etac tiling.induct 1);
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    89
by (simp_tac (ZF_ss addsimps tiling.intrs) 1);
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    90
by (asm_full_simp_tac (ZF_ss addsimps [Int_Un_distrib, Un_assoc, Un_subset_iff,
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    91
				       subset_empty_iff RS iff_sym]) 1);
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    92
by (safe_tac ZF_cs);
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    93
by (resolve_tac tiling.intrs 1);
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    94
by (assume_tac 1);
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    95
by (fast_tac ZF_cs 1);
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    96
by (fast_tac eq_cs 1);
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    97
val lemma = result();
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    98
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
    99
goal thy "!!t u. [| t: tiling(A);  u: tiling(A);  t Int u = 0 |] ==> \
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
   100
\                t Un u : tiling(A)";
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
   101
by (fast_tac (ZF_cs addIs [lemma RS bspec RS mp]) 1);
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
   102
qed "tiling_UnI";
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
   103
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
   104
goal thy "!!t. t:tiling(domino) ==> Finite(t)";
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
   105
by (eresolve_tac [tiling.induct] 1);
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
   106
by (resolve_tac [Finite_0] 1);
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
   107
by (fast_tac (ZF_cs addIs [domino_Finite, Finite_Un]) 1);
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
   108
qed "tiling_domino_Finite";
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
   109
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
   110
(*Uses AC in the form of cardinal_disjoint_Un; could instead use
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
   111
  tiling_domino_Finite, well_ord_cardinal_eqE and Finite_imp_well_ord*)
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
   112
goal thy "!!t. t: tiling(domino) ==> |evnodd(t,0)| = |evnodd(t,1)|";
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
   113
by (eresolve_tac [tiling.induct] 1);
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
   114
by (simp_tac (ZF_ss addsimps [evnodd_def]) 1);
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
   115
by (asm_simp_tac (ZF_ss addsimps [evnodd_Un]) 1);
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
   116
by (rtac cardinal_disjoint_Un 1);
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
   117
by (asm_simp_tac (arith_ss addsimps [cardinal_evnodd_domino]) 1);
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
   118
by (asm_simp_tac (arith_ss addsimps [cardinal_evnodd_domino]) 1);
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
   119
bw evnodd_def;
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
   120
by (fast_tac (eq_cs addSEs [equalityE]) 1);
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
   121
by (fast_tac (eq_cs addSEs [equalityE]) 1);
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
   122
qed "tiling_domino_0_1";
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
   123
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
   124
goal thy "!!i n. [| i: nat;  n: nat |] ==> {i} * (n #+ n) : tiling(domino)";
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
   125
by (nat_ind_tac "n" [] 1);
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
   126
by (simp_tac (arith_ss addsimps tiling.intrs) 1);
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
   127
by (asm_simp_tac (arith_ss addsimps [Un_assoc RS sym, Sigma_succ2]) 1);
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
   128
by (resolve_tac tiling.intrs 1);
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
   129
by (assume_tac 2);
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
   130
by (subgoal_tac	   (*seems the easiest way of turning one to the other*)
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
   131
    "{i}*{succ(n1#+n1)} Un {i}*{n1#+n1} = {<i,n1#+n1>, <i,succ(n1#+n1)>}" 1);
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
   132
by (fast_tac eq_cs 2);
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
   133
by (asm_simp_tac (arith_ss addsimps [domino.horiz]) 1);
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
   134
by (fast_tac (eq_cs addEs [mem_irrefl, mem_asym]) 1);
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
   135
qed "dominoes_tile_row";
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
   136
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
   137
goal thy "!!m n. [| m: nat;  n: nat |] ==> m * (n #+ n) : tiling(domino)";
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
   138
by (nat_ind_tac "m" [] 1);
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
   139
by (simp_tac (arith_ss addsimps tiling.intrs) 1);
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
   140
by (asm_simp_tac (arith_ss addsimps [Sigma_succ1]) 1);
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
   141
by (fast_tac (eq_cs addIs [tiling_UnI, dominoes_tile_row] 
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
   142
                    addEs [mem_irrefl]) 1);
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
   143
qed "dominoes_tile_matrix";
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
   144
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
   145
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
   146
goal thy "!!m n. [| m: nat;  n: nat;  \
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
   147
\                   t = (succ(m)#+succ(m))*(succ(n)#+succ(n));  \
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
   148
\                   t' = t - {<0,0>} - {<succ(m#+m), succ(n#+n)>} |] ==> \
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
   149
\                t' ~: tiling(domino)";
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
   150
by (resolve_tac [notI] 1);
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
   151
by (dresolve_tac [tiling_domino_0_1] 1);
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
   152
by (subgoal_tac "|evnodd(t',0)| < |evnodd(t',1)|" 1);
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
   153
by (asm_full_simp_tac (ZF_ss addsimps [lt_not_refl]) 1);
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
   154
by (subgoal_tac "t : tiling(domino)" 1);
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
   155
by (asm_simp_tac (ZF_ss addsimps [nat_succI, add_type, 
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
   156
				  dominoes_tile_matrix]) 2);
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
   157
by (subgoal_tac "(m#+m)#+(n#+n) = (m#+n)#+(m#+n)" 1);
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
   158
by (asm_simp_tac (arith_ss addsimps add_ac) 2);
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
   159
by (asm_full_simp_tac 
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
   160
    (arith_ss addsimps [evnodd_Diff, evnodd_cons, evnodd_0, mod2_add_self,
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
   161
			mod2_succ_succ, tiling_domino_0_1 RS sym]) 1);
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
   162
by (resolve_tac [lt_trans] 1);
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
   163
by (REPEAT
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
   164
    (rtac Finite_imp_cardinal_Diff 1 
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
   165
     THEN
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
   166
     asm_simp_tac (arith_ss addsimps [tiling_domino_Finite, Finite_evnodd, 
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
   167
				      Finite_Diff]) 1 
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
   168
     THEN
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
   169
     asm_simp_tac (arith_ss addsimps [evnoddI, nat_0_le RS ltD, mod2_add_self]) 1));
dd66bed09592 New example: mutilated checkerboard
paulson
parents:
diff changeset
   170
qed "mutil_not_tiling";