author | wenzelm |
Fri, 06 Oct 2000 17:35:58 +0200 | |
changeset 10168 | 50be659d4222 |
parent 6112 | 5e4871c5136b |
child 11316 | b4e71bd751e4 |
permissions | -rw-r--r-- |
1461 | 1 |
(* Title: ZF/ex/ramsey.ML |
0 | 2 |
ID: $Id$ |
1461 | 3 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
0 | 4 |
Copyright 1992 University of Cambridge |
5 |
||
6 |
Ramsey's Theorem (finite exponent 2 version) |
|
7 |
||
8 |
Based upon the article |
|
9 |
D Basin and M Kaufmann, |
|
10 |
The Boyer-Moore Prover and Nuprl: An Experimental Comparison. |
|
11 |
In G Huet and G Plotkin, editors, Logical Frameworks. |
|
12 |
(CUP, 1991), pages 89--119 |
|
13 |
||
14 |
See also |
|
15 |
M Kaufmann, |
|
16 |
An example in NQTHM: Ramsey's Theorem |
|
17 |
Internal Note, Computational Logic, Inc., Austin, Texas 78703 |
|
18 |
Available from the author: kaufmann@cli.com |
|
19 |
*) |
|
20 |
||
21 |
(*** Cliques and Independent sets ***) |
|
22 |
||
5068 | 23 |
Goalw [Clique_def] "Clique(0,V,E)"; |
2469 | 24 |
by (Fast_tac 1); |
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
25 |
qed "Clique0"; |
0 | 26 |
|
6070 | 27 |
Goalw [Clique_def] "[| Clique(C,V',E); V'<=V |] ==> Clique(C,V,E)"; |
2469 | 28 |
by (Fast_tac 1); |
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
29 |
qed "Clique_superset"; |
0 | 30 |
|
5068 | 31 |
Goalw [Indept_def] "Indept(0,V,E)"; |
2469 | 32 |
by (Fast_tac 1); |
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
33 |
qed "Indept0"; |
0 | 34 |
|
5147
825877190618
More tidying and removal of "\!\!... from Goal commands
paulson
parents:
5137
diff
changeset
|
35 |
Goalw [Indept_def] "[| Indept(I,V',E); V'<=V |] ==> Indept(I,V,E)"; |
2469 | 36 |
by (Fast_tac 1); |
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
37 |
qed "Indept_superset"; |
0 | 38 |
|
39 |
(*** Atleast ***) |
|
40 |
||
5068 | 41 |
Goalw [Atleast_def, inj_def, Pi_def, function_def] "Atleast(0,A)"; |
2469 | 42 |
by (Fast_tac 1); |
760 | 43 |
qed "Atleast0"; |
0 | 44 |
|
5068 | 45 |
Goalw [Atleast_def] |
5147
825877190618
More tidying and removal of "\!\!... from Goal commands
paulson
parents:
5137
diff
changeset
|
46 |
"Atleast(succ(m),A) ==> EX x:A. Atleast(m, A-{x})"; |
4091 | 47 |
by (fast_tac (claset() addEs [inj_is_fun RS apply_type, inj_succ_restrict]) 1); |
760 | 48 |
qed "Atleast_succD"; |
0 | 49 |
|
5068 | 50 |
Goalw [Atleast_def] |
5147
825877190618
More tidying and removal of "\!\!... from Goal commands
paulson
parents:
5137
diff
changeset
|
51 |
"[| Atleast(n,A); A<=B |] ==> Atleast(n,B)"; |
4091 | 52 |
by (fast_tac (claset() addEs [inj_weaken_type]) 1); |
760 | 53 |
qed "Atleast_superset"; |
0 | 54 |
|
5068 | 55 |
Goalw [Atleast_def,succ_def] |
5147
825877190618
More tidying and removal of "\!\!... from Goal commands
paulson
parents:
5137
diff
changeset
|
56 |
"[| Atleast(m,B); b~: B |] ==> Atleast(succ(m), cons(b,B))"; |
0 | 57 |
by (etac exE 1); |
58 |
by (rtac exI 1); |
|
59 |
by (etac inj_extend 1); |
|
60 |
by (rtac mem_not_refl 1); |
|
61 |
by (assume_tac 1); |
|
760 | 62 |
qed "Atleast_succI"; |
0 | 63 |
|
5147
825877190618
More tidying and removal of "\!\!... from Goal commands
paulson
parents:
5137
diff
changeset
|
64 |
Goal "[| Atleast(m, B-{x}); x: B |] ==> Atleast(succ(m), B)"; |
0 | 65 |
by (etac (Atleast_succI RS Atleast_superset) 1); |
2469 | 66 |
by (Fast_tac 1); |
67 |
by (Fast_tac 1); |
|
760 | 68 |
qed "Atleast_Diff_succI"; |
0 | 69 |
|
70 |
(*** Main Cardinality Lemma ***) |
|
71 |
||
72 |
(*The #-succ(0) strengthens the original theorem statement, but precisely |
|
73 |
the same proof could be used!!*) |
|
6070 | 74 |
Goal "m: nat ==> \ |
75 |
\ ALL n: nat. ALL A B. Atleast((m#+n) #- succ(0), A Un B) --> \ |
|
76 |
\ Atleast(m,A) | Atleast(n,B)"; |
|
77 |
by (induct_tac "m" 1); |
|
4091 | 78 |
by (fast_tac (claset() addSIs [Atleast0]) 1); |
2469 | 79 |
by (Asm_simp_tac 1); |
0 | 80 |
by (rtac ballI 1); |
6070 | 81 |
by (rename_tac "m' n" 1); (*simplifier does NOT preserve bound names!*) |
82 |
by (induct_tac "n" 1); |
|
4091 | 83 |
by (fast_tac (claset() addSIs [Atleast0]) 1); |
6070 | 84 |
by (Asm_simp_tac 1); |
4152 | 85 |
by Safe_tac; |
0 | 86 |
by (etac (Atleast_succD RS bexE) 1); |
6070 | 87 |
by (rename_tac "n' A B z" 1); |
0 | 88 |
by (etac UnE 1); |
6070 | 89 |
(**case z:B. Instantiate the 'ALL A B' induction hypothesis. **) |
90 |
by (dres_inst_tac [("x1","A"), ("x","B-{z}")] (spec RS spec) 2); |
|
0 | 91 |
by (etac (mp RS disjE) 2); |
6070 | 92 |
(*cases Atleast(succ(m1),A) and Atleast(succ(k),B)*) |
0 | 93 |
by (REPEAT (eresolve_tac [asm_rl, notE, Atleast_Diff_succI] 3)); |
94 |
(*proving the condition*) |
|
2469 | 95 |
by (etac Atleast_superset 2 THEN Fast_tac 2); |
6070 | 96 |
(**case z:A. Instantiate the 'ALL n:nat. ALL A B' induction hypothesis. **) |
97 |
by (dres_inst_tac [("x2","succ(n')"), ("x1","A-{z}"), ("x","B")] |
|
0 | 98 |
(bspec RS spec RS spec) 1); |
99 |
by (etac nat_succI 1); |
|
100 |
by (etac (mp RS disjE) 1); |
|
6070 | 101 |
(*cases Atleast(succ(m1),A) and Atleast(succ(k),B)*) |
0 | 102 |
by (REPEAT (eresolve_tac [asm_rl, Atleast_Diff_succI, notE] 2)); |
103 |
(*proving the condition*) |
|
6070 | 104 |
by (Asm_simp_tac 1); |
2469 | 105 |
by (etac Atleast_superset 1 THEN Fast_tac 1); |
6112 | 106 |
qed_spec_mp "pigeon2"; |
0 | 107 |
|
108 |
||
109 |
(**** Ramsey's Theorem ****) |
|
110 |
||
111 |
(** Base cases of induction; they now admit ANY Ramsey number **) |
|
112 |
||
5068 | 113 |
Goalw [Ramsey_def] "Ramsey(n,0,j)"; |
4091 | 114 |
by (fast_tac (claset() addIs [Clique0,Atleast0]) 1); |
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
115 |
qed "Ramsey0j"; |
0 | 116 |
|
5068 | 117 |
Goalw [Ramsey_def] "Ramsey(n,i,0)"; |
4091 | 118 |
by (fast_tac (claset() addIs [Indept0,Atleast0]) 1); |
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
119 |
qed "Ramseyi0"; |
0 | 120 |
|
121 |
(** Lemmas for induction step **) |
|
122 |
||
123 |
(*The use of succ(m) here, rather than #-succ(0), simplifies the proof of |
|
124 |
Ramsey_step_lemma.*) |
|
6070 | 125 |
Goal "[| Atleast(m #+ n, A); m: nat; n: nat |] \ |
126 |
\ ==> Atleast(succ(m), {x:A. ~P(x)}) | Atleast(n, {x:A. P(x)})"; |
|
0 | 127 |
by (rtac (nat_succI RS pigeon2) 1); |
6070 | 128 |
by (Asm_simp_tac 3); |
0 | 129 |
by (rtac Atleast_superset 3); |
6070 | 130 |
by Auto_tac; |
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
131 |
qed "Atleast_partition"; |
0 | 132 |
|
133 |
(*For the Atleast part, proves ~(a:I) from the second premise!*) |
|
6070 | 134 |
Goalw [Symmetric_def,Indept_def] |
38 | 135 |
"[| Symmetric(E); Indept(I, {z: V-{a}. <a,z> ~: E}, E); a: V; \ |
0 | 136 |
\ Atleast(j,I) |] ==> \ |
137 |
\ Indept(cons(a,I), V, E) & Atleast(succ(j), cons(a,I))"; |
|
6070 | 138 |
by (blast_tac (claset() addSIs [Atleast_succI]) 1); |
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
139 |
qed "Indept_succ"; |
0 | 140 |
|
6070 | 141 |
Goalw [Symmetric_def,Clique_def] |
0 | 142 |
"[| Symmetric(E); Clique(C, {z: V-{a}. <a,z>:E}, E); a: V; \ |
143 |
\ Atleast(j,C) |] ==> \ |
|
144 |
\ Clique(cons(a,C), V, E) & Atleast(succ(j), cons(a,C))"; |
|
6070 | 145 |
by (blast_tac (claset() addSIs [Atleast_succI]) 1); |
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
146 |
qed "Clique_succ"; |
0 | 147 |
|
148 |
(** Induction step **) |
|
149 |
||
150 |
(*Published proofs gloss over the need for Ramsey numbers to be POSITIVE.*) |
|
151 |
val ram1::ram2::prems = goalw Ramsey.thy [Ramsey_def] |
|
152 |
"[| Ramsey(succ(m), succ(i), j); Ramsey(n, i, succ(j)); \ |
|
153 |
\ m: nat; n: nat |] ==> \ |
|
154 |
\ Ramsey(succ(m#+n), succ(i), succ(j))"; |
|
4152 | 155 |
by Safe_tac; |
0 | 156 |
by (etac (Atleast_succD RS bexE) 1); |
157 |
by (eres_inst_tac [("P1","%z.<x,z>:E")] (Atleast_partition RS disjE) 1); |
|
158 |
by (REPEAT (resolve_tac prems 1)); |
|
159 |
(*case m*) |
|
160 |
by (rtac (ram1 RS spec RS spec RS mp RS disjE) 1); |
|
2469 | 161 |
by (Fast_tac 1); |
4091 | 162 |
by (fast_tac (claset() addEs [Clique_superset]) 1); (*easy -- given a Clique*) |
4152 | 163 |
by Safe_tac; |
1461 | 164 |
by (eresolve_tac (swapify [exI]) 1); (*ignore main EX quantifier*) |
165 |
by (REPEAT (ares_tac [Indept_succ] 1)); (*make a bigger Indept*) |
|
0 | 166 |
(*case n*) |
167 |
by (rtac (ram2 RS spec RS spec RS mp RS disjE) 1); |
|
2469 | 168 |
by (Fast_tac 1); |
4152 | 169 |
by Safe_tac; |
0 | 170 |
by (rtac exI 1); |
1461 | 171 |
by (REPEAT (ares_tac [Clique_succ] 1)); (*make a bigger Clique*) |
4091 | 172 |
by (fast_tac (claset() addEs [Indept_superset]) 1); (*easy -- given an Indept*) |
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
173 |
qed "Ramsey_step_lemma"; |
0 | 174 |
|
175 |
||
176 |
(** The actual proof **) |
|
177 |
||
178 |
(*Again, the induction requires Ramsey numbers to be positive.*) |
|
6070 | 179 |
Goal "i: nat ==> ALL j: nat. EX n:nat. Ramsey(succ(n), i, j)"; |
180 |
by (induct_tac "i" 1); |
|
4091 | 181 |
by (fast_tac (claset() addSIs [Ramsey0j]) 1); |
0 | 182 |
by (rtac ballI 1); |
6070 | 183 |
by (induct_tac "j" 1); |
4091 | 184 |
by (fast_tac (claset() addSIs [Ramseyi0]) 1); |
185 |
by (fast_tac (claset() addSDs [bspec] |
|
5137 | 186 |
addSIs [add_type,Ramsey_step_lemma]) 1); |
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
187 |
qed "ramsey_lemma"; |
0 | 188 |
|
189 |
(*Final statement in a tidy form, without succ(...) *) |
|
5137 | 190 |
Goal "[| i: nat; j: nat |] ==> EX n:nat. Ramsey(n,i,j)"; |
191 |
by (best_tac (claset() addDs [ramsey_lemma]) 1); |
|
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
192 |
qed "ramsey"; |
0 | 193 |
|
438 | 194 |
(*Compute Ramsey numbers according to proof above -- which, actually, |
0 | 195 |
does not constrain the base case values at all!*) |
196 |
fun ram 0 j = 1 |
|
197 |
| ram i 0 = 1 |
|
198 |
| ram i j = ram (i-1) j + ram i (j-1); |
|
199 |
||
200 |
(*Previous proof gave the following Ramsey numbers, which are smaller than |
|
201 |
those above by one!*) |
|
202 |
fun ram' 0 j = 0 |
|
203 |
| ram' i 0 = 0 |
|
204 |
| ram' i j = ram' (i-1) j + ram' i (j-1) + 1; |