author | wenzelm |
Wed, 02 Nov 2005 14:47:00 +0100 | |
changeset 18063 | c4bffc47c11b |
parent 16417 | 9bc16273c2d4 |
child 21233 | 5a5c8ea5f66a |
permissions | -rw-r--r-- |
1478 | 1 |
(* Title: ZF/ex/ramsey.thy |
0 | 2 |
ID: $Id$ |
1478 | 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. |
|
12867 | 12 |
(CUP, 1991), pages 89-119 |
0 | 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 |
|
12867 | 19 |
|
20 |
This function compute Ramsey numbers according to the proof given below |
|
21 |
(which, does not constrain the base case values at all. |
|
22 |
||
23 |
fun ram 0 j = 1 |
|
24 |
| ram i 0 = 1 |
|
25 |
| ram i j = ram (i-1) j + ram i (j-1) |
|
26 |
||
0 | 27 |
*) |
28 |
||
16417 | 29 |
theory Ramsey imports Main begin |
12867 | 30 |
constdefs |
31 |
Symmetric :: "i=>o" |
|
32 |
"Symmetric(E) == (\<forall>x y. <x,y>:E --> <y,x>:E)" |
|
33 |
||
34 |
Atleast :: "[i,i]=>o" (*not really necessary: ZF defines cardinality*) |
|
35 |
"Atleast(n,S) == (\<exists>f. f \<in> inj(n,S))" |
|
36 |
||
37 |
Clique :: "[i,i,i]=>o" |
|
38 |
"Clique(C,V,E) == (C \<subseteq> V) & (\<forall>x \<in> C. \<forall>y \<in> C. x\<noteq>y --> <x,y> \<in> E)" |
|
39 |
||
40 |
Indept :: "[i,i,i]=>o" |
|
41 |
"Indept(I,V,E) == (I \<subseteq> V) & (\<forall>x \<in> I. \<forall>y \<in> I. x\<noteq>y --> <x,y> \<notin> E)" |
|
42 |
||
43 |
Ramsey :: "[i,i,i]=>o" |
|
44 |
"Ramsey(n,i,j) == \<forall>V E. Symmetric(E) & Atleast(n,V) --> |
|
45 |
(\<exists>C. Clique(C,V,E) & Atleast(i,C)) | |
|
46 |
(\<exists>I. Indept(I,V,E) & Atleast(j,I))" |
|
47 |
||
48 |
(*** Cliques and Independent sets ***) |
|
49 |
||
50 |
lemma Clique0 [intro]: "Clique(0,V,E)" |
|
51 |
by (unfold Clique_def, blast) |
|
52 |
||
53 |
lemma Clique_superset: "[| Clique(C,V',E); V'<=V |] ==> Clique(C,V,E)" |
|
54 |
by (unfold Clique_def, blast) |
|
55 |
||
56 |
lemma Indept0 [intro]: "Indept(0,V,E)" |
|
57 |
by (unfold Indept_def, blast) |
|
0 | 58 |
|
12867 | 59 |
lemma Indept_superset: "[| Indept(I,V',E); V'<=V |] ==> Indept(I,V,E)" |
60 |
by (unfold Indept_def, blast) |
|
61 |
||
62 |
(*** Atleast ***) |
|
63 |
||
64 |
lemma Atleast0 [intro]: "Atleast(0,A)" |
|
65 |
by (unfold Atleast_def inj_def Pi_def function_def, blast) |
|
66 |
||
67 |
lemma Atleast_succD: |
|
68 |
"Atleast(succ(m),A) ==> \<exists>x \<in> A. Atleast(m, A-{x})" |
|
69 |
apply (unfold Atleast_def) |
|
70 |
apply (blast dest: inj_is_fun [THEN apply_type] inj_succ_restrict) |
|
71 |
done |
|
0 | 72 |
|
12867 | 73 |
lemma Atleast_superset: |
74 |
"[| Atleast(n,A); A \<subseteq> B |] ==> Atleast(n,B)" |
|
75 |
by (unfold Atleast_def, blast intro: inj_weaken_type) |
|
76 |
||
77 |
lemma Atleast_succI: |
|
78 |
"[| Atleast(m,B); b\<notin> B |] ==> Atleast(succ(m), cons(b,B))" |
|
79 |
apply (unfold Atleast_def succ_def) |
|
80 |
apply (blast intro: inj_extend elim: mem_irrefl) |
|
81 |
done |
|
82 |
||
83 |
lemma Atleast_Diff_succI: |
|
84 |
"[| Atleast(m, B-{x}); x \<in> B |] ==> Atleast(succ(m), B)" |
|
85 |
by (blast intro: Atleast_succI [THEN Atleast_superset]) |
|
86 |
||
87 |
(*** Main Cardinality Lemma ***) |
|
0 | 88 |
|
12867 | 89 |
(*The #-succ(0) strengthens the original theorem statement, but precisely |
90 |
the same proof could be used!!*) |
|
91 |
lemma pigeon2 [rule_format]: |
|
92 |
"m \<in> nat ==> |
|
93 |
\<forall>n \<in> nat. \<forall>A B. Atleast((m#+n) #- succ(0), A Un B) --> |
|
94 |
Atleast(m,A) | Atleast(n,B)" |
|
95 |
apply (induct_tac "m") |
|
13339
0f89104dd377
Fixed quantified variable name preservation for ball and bex (bounded quants)
paulson
parents:
12867
diff
changeset
|
96 |
apply (blast intro!: Atleast0, simp) |
12867 | 97 |
apply (rule ballI) |
98 |
apply (rename_tac m' n) (*simplifier does NOT preserve bound names!*) |
|
13339
0f89104dd377
Fixed quantified variable name preservation for ball and bex (bounded quants)
paulson
parents:
12867
diff
changeset
|
99 |
apply (induct_tac "n", auto) |
12867 | 100 |
apply (erule Atleast_succD [THEN bexE]) |
101 |
apply (rename_tac n' A B z) |
|
102 |
apply (erule UnE) |
|
103 |
(**case z \<in> B. Instantiate the '\<forall>A B' induction hypothesis. **) |
|
13339
0f89104dd377
Fixed quantified variable name preservation for ball and bex (bounded quants)
paulson
parents:
12867
diff
changeset
|
104 |
apply (drule_tac [2] x1 = A and x = "B-{z}" in spec [THEN spec]) |
12867 | 105 |
apply (erule_tac [2] mp [THEN disjE]) |
106 |
(*cases Atleast(succ(m1),A) and Atleast(succ(k),B)*) |
|
107 |
apply (erule_tac [3] asm_rl notE Atleast_Diff_succI)+ |
|
108 |
(*proving the condition*) |
|
109 |
prefer 2 apply (blast intro: Atleast_superset) |
|
110 |
(**case z \<in> A. Instantiate the '\<forall>n \<in> nat. \<forall>A B' induction hypothesis. **) |
|
13339
0f89104dd377
Fixed quantified variable name preservation for ball and bex (bounded quants)
paulson
parents:
12867
diff
changeset
|
111 |
apply (drule_tac x2="succ(n')" and x1="A-{z}" and x=B |
12867 | 112 |
in bspec [THEN spec, THEN spec]) |
113 |
apply (erule nat_succI) |
|
114 |
apply (erule mp [THEN disjE]) |
|
115 |
(*cases Atleast(succ(m1),A) and Atleast(succ(k),B)*) |
|
13339
0f89104dd377
Fixed quantified variable name preservation for ball and bex (bounded quants)
paulson
parents:
12867
diff
changeset
|
116 |
apply (erule_tac [2] asm_rl Atleast_Diff_succI notE)+ |
12867 | 117 |
(*proving the condition*) |
118 |
apply simp |
|
119 |
apply (blast intro: Atleast_superset) |
|
120 |
done |
|
0 | 121 |
|
12867 | 122 |
|
123 |
(**** Ramsey's Theorem ****) |
|
124 |
||
125 |
(** Base cases of induction; they now admit ANY Ramsey number **) |
|
126 |
||
127 |
lemma Ramsey0j: "Ramsey(n,0,j)" |
|
128 |
by (unfold Ramsey_def, blast) |
|
129 |
||
130 |
lemma Ramseyi0: "Ramsey(n,i,0)" |
|
131 |
by (unfold Ramsey_def, blast) |
|
132 |
||
133 |
(** Lemmas for induction step **) |
|
0 | 134 |
|
12867 | 135 |
(*The use of succ(m) here, rather than #-succ(0), simplifies the proof of |
136 |
Ramsey_step_lemma.*) |
|
137 |
lemma Atleast_partition: "[| Atleast(m #+ n, A); m \<in> nat; n \<in> nat |] |
|
138 |
==> Atleast(succ(m), {x \<in> A. ~P(x)}) | Atleast(n, {x \<in> A. P(x)})" |
|
13339
0f89104dd377
Fixed quantified variable name preservation for ball and bex (bounded quants)
paulson
parents:
12867
diff
changeset
|
139 |
apply (rule nat_succI [THEN pigeon2], assumption+) |
0f89104dd377
Fixed quantified variable name preservation for ball and bex (bounded quants)
paulson
parents:
12867
diff
changeset
|
140 |
apply (rule Atleast_superset, auto) |
12867 | 141 |
done |
142 |
||
143 |
(*For the Atleast part, proves ~(a \<in> I) from the second premise!*) |
|
144 |
lemma Indept_succ: |
|
145 |
"[| Indept(I, {z \<in> V-{a}. <a,z> \<notin> E}, E); Symmetric(E); a \<in> V; |
|
146 |
Atleast(j,I) |] ==> |
|
147 |
Indept(cons(a,I), V, E) & Atleast(succ(j), cons(a,I))" |
|
148 |
apply (unfold Symmetric_def Indept_def) |
|
149 |
apply (blast intro!: Atleast_succI) |
|
150 |
done |
|
151 |
||
152 |
||
153 |
lemma Clique_succ: |
|
154 |
"[| Clique(C, {z \<in> V-{a}. <a,z>:E}, E); Symmetric(E); a \<in> V; |
|
155 |
Atleast(j,C) |] ==> |
|
156 |
Clique(cons(a,C), V, E) & Atleast(succ(j), cons(a,C))" |
|
157 |
apply (unfold Symmetric_def Clique_def) |
|
158 |
apply (blast intro!: Atleast_succI) |
|
159 |
done |
|
160 |
||
161 |
(** Induction step **) |
|
0 | 162 |
|
12867 | 163 |
(*Published proofs gloss over the need for Ramsey numbers to be POSITIVE.*) |
164 |
lemma Ramsey_step_lemma: |
|
165 |
"[| Ramsey(succ(m), succ(i), j); Ramsey(n, i, succ(j)); |
|
166 |
m \<in> nat; n \<in> nat |] ==> Ramsey(succ(m#+n), succ(i), succ(j))" |
|
13339
0f89104dd377
Fixed quantified variable name preservation for ball and bex (bounded quants)
paulson
parents:
12867
diff
changeset
|
167 |
apply (unfold Ramsey_def, clarify) |
12867 | 168 |
apply (erule Atleast_succD [THEN bexE]) |
169 |
apply (erule_tac P1 = "%z.<x,z>:E" in Atleast_partition [THEN disjE], |
|
170 |
assumption+) |
|
171 |
(*case m*) |
|
172 |
apply (fast dest!: Indept_succ elim: Clique_superset) |
|
173 |
(*case n*) |
|
174 |
apply (fast dest!: Clique_succ elim: Indept_superset) |
|
175 |
done |
|
176 |
||
177 |
||
178 |
(** The actual proof **) |
|
179 |
||
180 |
(*Again, the induction requires Ramsey numbers to be positive.*) |
|
181 |
lemma ramsey_lemma: "i \<in> nat ==> \<forall>j \<in> nat. \<exists>n \<in> nat. Ramsey(succ(n), i, j)" |
|
182 |
apply (induct_tac "i") |
|
183 |
apply (blast intro!: Ramsey0j) |
|
184 |
apply (rule ballI) |
|
185 |
apply (induct_tac "j") |
|
186 |
apply (blast intro!: Ramseyi0) |
|
187 |
apply (blast intro!: add_type Ramsey_step_lemma) |
|
188 |
done |
|
189 |
||
190 |
(*Final statement in a tidy form, without succ(...) *) |
|
191 |
lemma ramsey: "[| i \<in> nat; j \<in> nat |] ==> \<exists>n \<in> nat. Ramsey(n,i,j)" |
|
192 |
by (blast dest: ramsey_lemma) |
|
0 | 193 |
|
194 |
end |