author | mueller |
Thu, 17 Jul 1997 12:44:58 +0200 | |
changeset 3523 | 23eae933c2d9 |
parent 2469 | b50b8c0eec01 |
child 4091 | 771b1f6422a8 |
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 |
open Ramsey; |
|
22 |
||
23 |
(*** Cliques and Independent sets ***) |
|
24 |
||
25 |
goalw Ramsey.thy [Clique_def] "Clique(0,V,E)"; |
|
2469 | 26 |
by (Fast_tac 1); |
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
27 |
qed "Clique0"; |
0 | 28 |
|
29 |
goalw Ramsey.thy [Clique_def] |
|
30 |
"!!C V E. [| Clique(C,V',E); V'<=V |] ==> Clique(C,V,E)"; |
|
2469 | 31 |
by (Fast_tac 1); |
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
32 |
qed "Clique_superset"; |
0 | 33 |
|
34 |
goalw Ramsey.thy [Indept_def] "Indept(0,V,E)"; |
|
2469 | 35 |
by (Fast_tac 1); |
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
36 |
qed "Indept0"; |
0 | 37 |
|
38 |
val prems = goalw Ramsey.thy [Indept_def] |
|
39 |
"!!I V E. [| Indept(I,V',E); V'<=V |] ==> Indept(I,V,E)"; |
|
2469 | 40 |
by (Fast_tac 1); |
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
41 |
qed "Indept_superset"; |
0 | 42 |
|
43 |
(*** Atleast ***) |
|
44 |
||
694
c7d592f6312a
ZF/ex/Ramsey,Rmap,misc.ML: modified for new definition of Pi(A,B)
lcp
parents:
438
diff
changeset
|
45 |
goalw Ramsey.thy [Atleast_def, inj_def, Pi_def, function_def] "Atleast(0,A)"; |
2469 | 46 |
by (Fast_tac 1); |
760 | 47 |
qed "Atleast0"; |
0 | 48 |
|
1785 | 49 |
goalw Ramsey.thy [Atleast_def] |
50 |
"!!m A. Atleast(succ(m),A) ==> EX x:A. Atleast(m, A-{x})"; |
|
2469 | 51 |
by (fast_tac (!claset addEs [inj_is_fun RS apply_type, inj_succ_restrict]) 1); |
760 | 52 |
qed "Atleast_succD"; |
0 | 53 |
|
1785 | 54 |
goalw Ramsey.thy [Atleast_def] |
55 |
"!!n A. [| Atleast(n,A); A<=B |] ==> Atleast(n,B)"; |
|
2469 | 56 |
by (fast_tac (!claset addEs [inj_weaken_type]) 1); |
760 | 57 |
qed "Atleast_superset"; |
0 | 58 |
|
2469 | 59 |
goalw Ramsey.thy [Atleast_def,succ_def] |
60 |
"!!m. [| Atleast(m,B); b~: B |] ==> Atleast(succ(m), cons(b,B))"; |
|
0 | 61 |
by (etac exE 1); |
62 |
by (rtac exI 1); |
|
63 |
by (etac inj_extend 1); |
|
64 |
by (rtac mem_not_refl 1); |
|
65 |
by (assume_tac 1); |
|
760 | 66 |
qed "Atleast_succI"; |
0 | 67 |
|
2469 | 68 |
goal Ramsey.thy |
69 |
"!!m. [| Atleast(m, B-{x}); x: B |] ==> Atleast(succ(m), B)"; |
|
0 | 70 |
by (etac (Atleast_succI RS Atleast_superset) 1); |
2469 | 71 |
by (Fast_tac 1); |
72 |
by (Fast_tac 1); |
|
760 | 73 |
qed "Atleast_Diff_succI"; |
0 | 74 |
|
75 |
(*** Main Cardinality Lemma ***) |
|
76 |
||
77 |
(*The #-succ(0) strengthens the original theorem statement, but precisely |
|
78 |
the same proof could be used!!*) |
|
79 |
val prems = goal Ramsey.thy |
|
80 |
"m: nat ==> \ |
|
81 |
\ ALL n: nat. ALL A B. Atleast((m#+n) #- succ(0), A Un B) --> \ |
|
82 |
\ Atleast(m,A) | Atleast(n,B)"; |
|
83 |
by (nat_ind_tac "m" prems 1); |
|
2469 | 84 |
by (fast_tac (!claset addSIs [Atleast0]) 1); |
85 |
by (Asm_simp_tac 1); |
|
0 | 86 |
by (rtac ballI 1); |
1461 | 87 |
by (rename_tac "n" 1); (*simplifier does NOT preserve bound names!*) |
0 | 88 |
by (nat_ind_tac "n" [] 1); |
2469 | 89 |
by (fast_tac (!claset addSIs [Atleast0]) 1); |
90 |
by (asm_simp_tac (!simpset addsimps [add_succ_right]) 1); |
|
91 |
by (safe_tac (!claset)); |
|
0 | 92 |
by (etac (Atleast_succD RS bexE) 1); |
93 |
by (etac UnE 1); |
|
94 |
(**case x:B. Instantiate the 'ALL A B' induction hypothesis. **) |
|
95 |
by (dres_inst_tac [("x1","A"), ("x","B-{x}")] (spec RS spec) 2); |
|
96 |
by (etac (mp RS disjE) 2); |
|
97 |
(*cases Atleast(succ(m1),A) and Atleast(succ(n1),B)*) |
|
98 |
by (REPEAT (eresolve_tac [asm_rl, notE, Atleast_Diff_succI] 3)); |
|
99 |
(*proving the condition*) |
|
2469 | 100 |
by (etac Atleast_superset 2 THEN Fast_tac 2); |
0 | 101 |
(**case x:A. Instantiate the 'ALL n:nat. ALL A B' induction hypothesis. **) |
102 |
by (dres_inst_tac [("x2","succ(n1)"), ("x1","A-{x}"), ("x","B")] |
|
103 |
(bspec RS spec RS spec) 1); |
|
104 |
by (etac nat_succI 1); |
|
105 |
by (etac (mp RS disjE) 1); |
|
106 |
(*cases Atleast(succ(m1),A) and Atleast(succ(n1),B)*) |
|
107 |
by (REPEAT (eresolve_tac [asm_rl, Atleast_Diff_succI, notE] 2)); |
|
108 |
(*proving the condition*) |
|
2469 | 109 |
by (asm_simp_tac (!simpset addsimps [add_succ_right]) 1); |
110 |
by (etac Atleast_superset 1 THEN Fast_tac 1); |
|
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
111 |
qed "pigeon2_lemma"; |
0 | 112 |
|
113 |
(* [| m:nat; n:nat; Atleast(m #+ n #- succ(0), A Un B) |] ==> |
|
114 |
Atleast(m,A) | Atleast(n,B) *) |
|
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
115 |
bind_thm ("pigeon2", (pigeon2_lemma RS bspec RS spec RS spec RS mp)); |
0 | 116 |
|
117 |
||
118 |
(**** Ramsey's Theorem ****) |
|
119 |
||
120 |
(** Base cases of induction; they now admit ANY Ramsey number **) |
|
121 |
||
122 |
goalw Ramsey.thy [Ramsey_def] "Ramsey(n,0,j)"; |
|
2469 | 123 |
by (fast_tac (!claset addIs [Clique0,Atleast0]) 1); |
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
124 |
qed "Ramsey0j"; |
0 | 125 |
|
126 |
goalw Ramsey.thy [Ramsey_def] "Ramsey(n,i,0)"; |
|
2469 | 127 |
by (fast_tac (!claset addIs [Indept0,Atleast0]) 1); |
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
128 |
qed "Ramseyi0"; |
0 | 129 |
|
130 |
(** Lemmas for induction step **) |
|
131 |
||
132 |
(*The use of succ(m) here, rather than #-succ(0), simplifies the proof of |
|
133 |
Ramsey_step_lemma.*) |
|
134 |
val prems = goal Ramsey.thy |
|
135 |
"[| Atleast(m #+ n, A); m: nat; n: nat |] ==> \ |
|
136 |
\ Atleast(succ(m), {x:A. ~P(x)}) | Atleast(n, {x:A. P(x)})"; |
|
137 |
by (rtac (nat_succI RS pigeon2) 1); |
|
2469 | 138 |
by (simp_tac (!simpset addsimps prems) 3); |
0 | 139 |
by (rtac Atleast_superset 3); |
140 |
by (REPEAT (resolve_tac prems 1)); |
|
2469 | 141 |
by (Fast_tac 1); |
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
142 |
qed "Atleast_partition"; |
0 | 143 |
|
144 |
(*For the Atleast part, proves ~(a:I) from the second premise!*) |
|
145 |
val prems = goalw Ramsey.thy [Symmetric_def,Indept_def] |
|
38 | 146 |
"[| Symmetric(E); Indept(I, {z: V-{a}. <a,z> ~: E}, E); a: V; \ |
0 | 147 |
\ Atleast(j,I) |] ==> \ |
148 |
\ Indept(cons(a,I), V, E) & Atleast(succ(j), cons(a,I))"; |
|
149 |
by (cut_facts_tac prems 1); |
|
2469 | 150 |
by (fast_tac (!claset addSEs [Atleast_succI]) 1); (*34 secs*) |
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
151 |
qed "Indept_succ"; |
0 | 152 |
|
153 |
val prems = goalw Ramsey.thy [Symmetric_def,Clique_def] |
|
154 |
"[| Symmetric(E); Clique(C, {z: V-{a}. <a,z>:E}, E); a: V; \ |
|
155 |
\ Atleast(j,C) |] ==> \ |
|
156 |
\ Clique(cons(a,C), V, E) & Atleast(succ(j), cons(a,C))"; |
|
157 |
by (cut_facts_tac prems 1); |
|
2469 | 158 |
by (fast_tac (!claset addSEs [Atleast_succI]) 1); (*41 secs*) |
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
159 |
qed "Clique_succ"; |
0 | 160 |
|
161 |
(** Induction step **) |
|
162 |
||
163 |
(*Published proofs gloss over the need for Ramsey numbers to be POSITIVE.*) |
|
164 |
val ram1::ram2::prems = goalw Ramsey.thy [Ramsey_def] |
|
165 |
"[| Ramsey(succ(m), succ(i), j); Ramsey(n, i, succ(j)); \ |
|
166 |
\ m: nat; n: nat |] ==> \ |
|
167 |
\ Ramsey(succ(m#+n), succ(i), succ(j))"; |
|
2469 | 168 |
by (safe_tac (!claset)); |
0 | 169 |
by (etac (Atleast_succD RS bexE) 1); |
170 |
by (eres_inst_tac [("P1","%z.<x,z>:E")] (Atleast_partition RS disjE) 1); |
|
171 |
by (REPEAT (resolve_tac prems 1)); |
|
172 |
(*case m*) |
|
173 |
by (rtac (ram1 RS spec RS spec RS mp RS disjE) 1); |
|
2469 | 174 |
by (Fast_tac 1); |
175 |
by (fast_tac (!claset addEs [Clique_superset]) 1); (*easy -- given a Clique*) |
|
176 |
by (safe_tac (!claset)); |
|
1461 | 177 |
by (eresolve_tac (swapify [exI]) 1); (*ignore main EX quantifier*) |
178 |
by (REPEAT (ares_tac [Indept_succ] 1)); (*make a bigger Indept*) |
|
0 | 179 |
(*case n*) |
180 |
by (rtac (ram2 RS spec RS spec RS mp RS disjE) 1); |
|
2469 | 181 |
by (Fast_tac 1); |
182 |
by (safe_tac (!claset)); |
|
0 | 183 |
by (rtac exI 1); |
1461 | 184 |
by (REPEAT (ares_tac [Clique_succ] 1)); (*make a bigger Clique*) |
2469 | 185 |
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
|
186 |
qed "Ramsey_step_lemma"; |
0 | 187 |
|
188 |
||
189 |
(** The actual proof **) |
|
190 |
||
191 |
(*Again, the induction requires Ramsey numbers to be positive.*) |
|
192 |
val prems = goal Ramsey.thy |
|
193 |
"i: nat ==> ALL j: nat. EX n:nat. Ramsey(succ(n), i, j)"; |
|
194 |
by (nat_ind_tac "i" prems 1); |
|
2469 | 195 |
by (fast_tac (!claset addSIs [Ramsey0j]) 1); |
0 | 196 |
by (rtac ballI 1); |
197 |
by (nat_ind_tac "j" [] 1); |
|
2469 | 198 |
by (fast_tac (!claset addSIs [Ramseyi0]) 1); |
199 |
by (fast_tac (!claset addSDs [bspec] |
|
200 |
addSIs [nat_succI,add_type,Ramsey_step_lemma]) 1); |
|
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
201 |
qed "ramsey_lemma"; |
0 | 202 |
|
203 |
(*Final statement in a tidy form, without succ(...) *) |
|
1785 | 204 |
goal Ramsey.thy "!!i j. [| i: nat; j: nat |] ==> EX n:nat. Ramsey(n,i,j)"; |
2469 | 205 |
by (best_tac (!claset addDs [ramsey_lemma] addSIs [nat_succI]) 1); |
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
206 |
qed "ramsey"; |
0 | 207 |
|
438 | 208 |
(*Compute Ramsey numbers according to proof above -- which, actually, |
0 | 209 |
does not constrain the base case values at all!*) |
210 |
fun ram 0 j = 1 |
|
211 |
| ram i 0 = 1 |
|
212 |
| ram i j = ram (i-1) j + ram i (j-1); |
|
213 |
||
214 |
(*Previous proof gave the following Ramsey numbers, which are smaller than |
|
215 |
those above by one!*) |
|
216 |
fun ram' 0 j = 0 |
|
217 |
| ram' i 0 = 0 |
|
218 |
| ram' i j = ram' (i-1) j + ram' i (j-1) + 1; |