author | urbanc |
Fri, 02 Sep 2011 09:53:56 +0000 | |
changeset 223 | 5f7b7ad498dd |
parent 222 | 191769fc68c3 |
child 231 | 999fce5f9d34 |
permissions | -rw-r--r-- |
220 | 1 |
theory Closure2 |
221 | 2 |
imports |
3 |
Closures |
|
222
191769fc68c3
included Higman's lemma from the Isabelle repository
urbanc
parents:
221
diff
changeset
|
4 |
Higman |
221 | 5 |
(* "~~/src/HOL/Proofs/Extraction/Higman" *) |
220 | 6 |
begin |
7 |
||
223 | 8 |
section {* Closure under @{text SUBSEQ} and @{text SUPSEQ} *} |
9 |
||
10 |
(* compatibility with Higman theory by Stefan *) |
|
222
191769fc68c3
included Higman's lemma from the Isabelle repository
urbanc
parents:
221
diff
changeset
|
11 |
notation |
191769fc68c3
included Higman's lemma from the Isabelle repository
urbanc
parents:
221
diff
changeset
|
12 |
emb ("_ \<preceq> _") |
191769fc68c3
included Higman's lemma from the Isabelle repository
urbanc
parents:
221
diff
changeset
|
13 |
|
191769fc68c3
included Higman's lemma from the Isabelle repository
urbanc
parents:
221
diff
changeset
|
14 |
declare emb0 [intro] |
191769fc68c3
included Higman's lemma from the Isabelle repository
urbanc
parents:
221
diff
changeset
|
15 |
declare emb1 [intro] |
191769fc68c3
included Higman's lemma from the Isabelle repository
urbanc
parents:
221
diff
changeset
|
16 |
declare emb2 [intro] |
191769fc68c3
included Higman's lemma from the Isabelle repository
urbanc
parents:
221
diff
changeset
|
17 |
|
191769fc68c3
included Higman's lemma from the Isabelle repository
urbanc
parents:
221
diff
changeset
|
18 |
lemma letter_UNIV: |
191769fc68c3
included Higman's lemma from the Isabelle repository
urbanc
parents:
221
diff
changeset
|
19 |
shows "UNIV = {A, B::letter}" |
191769fc68c3
included Higman's lemma from the Isabelle repository
urbanc
parents:
221
diff
changeset
|
20 |
apply(auto) |
191769fc68c3
included Higman's lemma from the Isabelle repository
urbanc
parents:
221
diff
changeset
|
21 |
apply(case_tac x) |
191769fc68c3
included Higman's lemma from the Isabelle repository
urbanc
parents:
221
diff
changeset
|
22 |
apply(auto) |
191769fc68c3
included Higman's lemma from the Isabelle repository
urbanc
parents:
221
diff
changeset
|
23 |
done |
191769fc68c3
included Higman's lemma from the Isabelle repository
urbanc
parents:
221
diff
changeset
|
24 |
|
191769fc68c3
included Higman's lemma from the Isabelle repository
urbanc
parents:
221
diff
changeset
|
25 |
instance letter :: finite |
191769fc68c3
included Higman's lemma from the Isabelle repository
urbanc
parents:
221
diff
changeset
|
26 |
apply(default) |
191769fc68c3
included Higman's lemma from the Isabelle repository
urbanc
parents:
221
diff
changeset
|
27 |
apply(simp add: letter_UNIV) |
191769fc68c3
included Higman's lemma from the Isabelle repository
urbanc
parents:
221
diff
changeset
|
28 |
done |
191769fc68c3
included Higman's lemma from the Isabelle repository
urbanc
parents:
221
diff
changeset
|
29 |
|
191769fc68c3
included Higman's lemma from the Isabelle repository
urbanc
parents:
221
diff
changeset
|
30 |
hide_const A |
191769fc68c3
included Higman's lemma from the Isabelle repository
urbanc
parents:
221
diff
changeset
|
31 |
hide_const B |
191769fc68c3
included Higman's lemma from the Isabelle repository
urbanc
parents:
221
diff
changeset
|
32 |
|
191769fc68c3
included Higman's lemma from the Isabelle repository
urbanc
parents:
221
diff
changeset
|
33 |
(* |
221 | 34 |
inductive |
35 |
emb :: "'a list \<Rightarrow> 'a list \<Rightarrow> bool" ("_ \<preceq> _") |
|
220 | 36 |
where |
221 | 37 |
emb0 [intro]: "emb [] y" |
38 |
| emb1 [intro]: "emb x y \<Longrightarrow> emb x (c # y)" |
|
39 |
| emb2 [intro]: "emb x y \<Longrightarrow> emb (c # x) (c # y)" |
|
222
191769fc68c3
included Higman's lemma from the Isabelle repository
urbanc
parents:
221
diff
changeset
|
40 |
*) |
220 | 41 |
|
221 | 42 |
lemma emb_refl [intro]: |
220 | 43 |
shows "x \<preceq> x" |
222
191769fc68c3
included Higman's lemma from the Isabelle repository
urbanc
parents:
221
diff
changeset
|
44 |
by (induct x) (auto) |
220 | 45 |
|
221 | 46 |
lemma emb_right [intro]: |
220 | 47 |
assumes a: "x \<preceq> y" |
48 |
shows "x \<preceq> y @ y'" |
|
222
191769fc68c3
included Higman's lemma from the Isabelle repository
urbanc
parents:
221
diff
changeset
|
49 |
using a |
191769fc68c3
included Higman's lemma from the Isabelle repository
urbanc
parents:
221
diff
changeset
|
50 |
by (induct arbitrary: y') (auto) |
220 | 51 |
|
221 | 52 |
lemma emb_left [intro]: |
220 | 53 |
assumes a: "x \<preceq> y" |
54 |
shows "x \<preceq> y' @ y" |
|
221 | 55 |
using a by (induct y') (auto) |
220 | 56 |
|
221 | 57 |
lemma emb_appendI [intro]: |
220 | 58 |
assumes a: "x \<preceq> x'" |
59 |
and b: "y \<preceq> y'" |
|
60 |
shows "x @ y \<preceq> x' @ y'" |
|
221 | 61 |
using a b by (induct) (auto) |
62 |
||
63 |
lemma emb_cons_leftD: |
|
64 |
assumes "a # x \<preceq> y" |
|
65 |
shows "\<exists>y1 y2. y = y1 @ [a] @ y2 \<and> x \<preceq> y2" |
|
66 |
using assms |
|
67 |
apply(induct x\<equiv>"a # x" y\<equiv>"y" arbitrary: a x y) |
|
68 |
apply(auto) |
|
69 |
apply(metis append_Cons) |
|
70 |
done |
|
71 |
||
72 |
lemma emb_append_leftD: |
|
73 |
assumes "x1 @ x2 \<preceq> y" |
|
74 |
shows "\<exists>y1 y2. y = y1 @ y2 \<and> x1 \<preceq> y1 \<and> x2 \<preceq> y2" |
|
75 |
using assms |
|
76 |
apply(induct x1 arbitrary: x2 y) |
|
77 |
apply(auto) |
|
78 |
apply(drule emb_cons_leftD) |
|
79 |
apply(auto) |
|
80 |
apply(drule_tac x="x2" in meta_spec) |
|
81 |
apply(drule_tac x="y2" in meta_spec) |
|
82 |
apply(auto) |
|
83 |
apply(rule_tac x="y1 @ (a # y1a)" in exI) |
|
84 |
apply(rule_tac x="y2a" in exI) |
|
85 |
apply(auto) |
|
220 | 86 |
done |
87 |
||
221 | 88 |
lemma emb_trans: |
89 |
assumes a: "x1 \<preceq> x2" |
|
90 |
and b: "x2 \<preceq> x3" |
|
91 |
shows "x1 \<preceq> x3" |
|
92 |
using a b |
|
93 |
apply(induct arbitrary: x3) |
|
94 |
apply(metis emb0) |
|
95 |
apply(metis emb_cons_leftD emb_left) |
|
96 |
apply(drule_tac emb_cons_leftD) |
|
97 |
apply(auto) |
|
220 | 98 |
done |
99 |
||
221 | 100 |
lemma emb_strict_length: |
101 |
assumes a: "x \<preceq> y" "x \<noteq> y" |
|
102 |
shows "length x < length y" |
|
103 |
using a |
|
104 |
by (induct) (auto simp add: less_Suc_eq) |
|
105 |
||
106 |
lemma emb_antisym: |
|
107 |
assumes a: "x \<preceq> y" "y \<preceq> x" |
|
108 |
shows "x = y" |
|
109 |
using a emb_strict_length |
|
110 |
by (metis not_less_iff_gr_or_eq) |
|
111 |
||
112 |
lemma emb_wf: |
|
113 |
shows "wf {(x, y). x \<preceq> y \<and> x \<noteq> y}" |
|
114 |
proof - |
|
115 |
have "wf (measure length)" by simp |
|
116 |
moreover |
|
117 |
have "{(x, y). x \<preceq> y \<and> x \<noteq> y} \<subseteq> measure length" |
|
118 |
unfolding measure_def by (auto simp add: emb_strict_length) |
|
119 |
ultimately |
|
120 |
show "wf {(x, y). x \<preceq> y \<and> x \<noteq> y}" by (rule wf_subset) |
|
121 |
qed |
|
122 |
||
123 |
subsection {* Sub- and Supsequences *} |
|
220 | 124 |
|
125 |
definition |
|
126 |
"SUBSEQ A \<equiv> {x. \<exists>y \<in> A. x \<preceq> y}" |
|
127 |
||
128 |
definition |
|
221 | 129 |
"SUPSEQ A \<equiv> {x. \<exists>y \<in> A. y \<preceq> x}" |
220 | 130 |
|
221 | 131 |
lemma SUPSEQ_simps [simp]: |
132 |
shows "SUPSEQ {} = {}" |
|
133 |
and "SUPSEQ {[]} = UNIV" |
|
134 |
unfolding SUPSEQ_def by auto |
|
220 | 135 |
|
221 | 136 |
lemma SUPSEQ_atom [simp]: |
223 | 137 |
shows "SUPSEQ {[c]} = UNIV \<cdot> {[c]} \<cdot> UNIV" |
221 | 138 |
unfolding SUPSEQ_def conc_def |
139 |
by (auto) (metis append_Cons emb_cons_leftD) |
|
220 | 140 |
|
221 | 141 |
lemma SUPSEQ_union [simp]: |
142 |
shows "SUPSEQ (A \<union> B) = SUPSEQ A \<union> SUPSEQ B" |
|
143 |
unfolding SUPSEQ_def by auto |
|
220 | 144 |
|
221 | 145 |
lemma SUPSEQ_conc [simp]: |
146 |
shows "SUPSEQ (A \<cdot> B) = SUPSEQ A \<cdot> SUPSEQ B" |
|
147 |
unfolding SUPSEQ_def conc_def |
|
148 |
by (auto) (metis emb_append_leftD) |
|
220 | 149 |
|
221 | 150 |
lemma SUPSEQ_star [simp]: |
151 |
shows "SUPSEQ (A\<star>) = UNIV" |
|
220 | 152 |
apply(subst star_unfold_left) |
221 | 153 |
apply(simp only: SUPSEQ_union) |
220 | 154 |
apply(simp) |
155 |
done |
|
156 |
||
157 |
definition |
|
158 |
Allreg :: "'a::finite rexp" |
|
159 |
where |
|
160 |
"Allreg \<equiv> \<Uplus>(Atom ` UNIV)" |
|
161 |
||
162 |
lemma Allreg_lang [simp]: |
|
221 | 163 |
shows "lang Allreg = (\<Union>a. {[a]})" |
164 |
unfolding Allreg_def by auto |
|
220 | 165 |
|
166 |
lemma [simp]: |
|
221 | 167 |
shows "(\<Union>a. {[a]})\<star> = UNIV" |
220 | 168 |
apply(auto) |
169 |
apply(induct_tac x rule: list.induct) |
|
170 |
apply(auto) |
|
171 |
apply(subgoal_tac "[a] @ list \<in> (\<Union>a. {[a]})\<star>") |
|
172 |
apply(simp) |
|
173 |
apply(rule append_in_starI) |
|
174 |
apply(auto) |
|
175 |
done |
|
176 |
||
177 |
lemma Star_Allreg_lang [simp]: |
|
221 | 178 |
shows "lang (Star Allreg) = UNIV" |
179 |
by simp |
|
220 | 180 |
|
221 | 181 |
fun |
182 |
UP :: "'a::finite rexp \<Rightarrow> 'a rexp" |
|
183 |
where |
|
184 |
"UP (Zero) = Zero" |
|
185 |
| "UP (One) = Star Allreg" |
|
186 |
| "UP (Atom c) = Times (Star Allreg) (Times (Atom c) (Star Allreg))" |
|
187 |
| "UP (Plus r1 r2) = Plus (UP r1) (UP r2)" |
|
188 |
| "UP (Times r1 r2) = Times (UP r1) (UP r2)" |
|
189 |
| "UP (Star r) = Star Allreg" |
|
220 | 190 |
|
221 | 191 |
lemma lang_UP: |
222
191769fc68c3
included Higman's lemma from the Isabelle repository
urbanc
parents:
221
diff
changeset
|
192 |
fixes r::"letter rexp" |
221 | 193 |
shows "lang (UP r) = SUPSEQ (lang r)" |
194 |
by (induct r) (simp_all) |
|
195 |
||
196 |
lemma regular_SUPSEQ: |
|
222
191769fc68c3
included Higman's lemma from the Isabelle repository
urbanc
parents:
221
diff
changeset
|
197 |
fixes A::"letter lang" |
220 | 198 |
assumes "regular A" |
199 |
shows "regular (SUPSEQ A)" |
|
200 |
proof - |
|
222
191769fc68c3
included Higman's lemma from the Isabelle repository
urbanc
parents:
221
diff
changeset
|
201 |
from assms obtain r::"letter rexp" where "lang r = A" by auto |
221 | 202 |
then have "lang (UP r) = SUPSEQ A" by (simp add: lang_UP) |
203 |
then show "regular (SUPSEQ A)" by auto |
|
220 | 204 |
qed |
221 | 205 |
|
206 |
lemma SUPSEQ_subset: |
|
207 |
shows "A \<subseteq> SUPSEQ A" |
|
208 |
unfolding SUPSEQ_def by auto |
|
209 |
||
223 | 210 |
lemma SUBSEQ_complement: |
211 |
shows "- (SUBSEQ A) = SUPSEQ (- (SUBSEQ A))" |
|
212 |
proof - |
|
213 |
have "- (SUBSEQ A) \<subseteq> SUPSEQ (- (SUBSEQ A))" |
|
214 |
by (rule SUPSEQ_subset) |
|
215 |
moreover |
|
216 |
have "SUPSEQ (- (SUBSEQ A)) \<subseteq> - (SUBSEQ A)" |
|
217 |
proof (rule ccontr) |
|
218 |
assume "\<not> (SUPSEQ (- (SUBSEQ A)) \<subseteq> - (SUBSEQ A))" |
|
219 |
then obtain x where |
|
220 |
a: "x \<in> SUPSEQ (- (SUBSEQ A))" and |
|
221 |
b: "x \<notin> - (SUBSEQ A)" by auto |
|
222 |
||
223 |
from a obtain y where c: "y \<in> - (SUBSEQ A)" and d: "y \<preceq> x" |
|
224 |
by (auto simp add: SUPSEQ_def) |
|
221 | 225 |
|
223 | 226 |
from b have "x \<in> SUBSEQ A" by simp |
227 |
then obtain x' where f: "x' \<in> A" and e: "x \<preceq> x'" |
|
228 |
by (auto simp add: SUBSEQ_def) |
|
229 |
||
230 |
from d e have "y \<preceq> x'" by (rule emb_trans) |
|
231 |
then have "y \<in> SUBSEQ A" using f |
|
232 |
by (auto simp add: SUBSEQ_def) |
|
233 |
with c show "False" by simp |
|
234 |
qed |
|
235 |
ultimately show "- (SUBSEQ A) = SUPSEQ (- (SUBSEQ A))" by simp |
|
236 |
qed |
|
237 |
||
238 |
lemma Higman_antichains: |
|
239 |
assumes a: "\<forall>x \<in> A. \<forall>y \<in> A. x \<noteq> y \<longrightarrow> \<not>(x \<preceq> y) \<and> \<not>(y \<preceq> x)" |
|
240 |
shows "finite A" |
|
241 |
proof (rule ccontr) |
|
242 |
assume "infinite A" |
|
243 |
then obtain f::"nat \<Rightarrow> letter list" where b: "inj f" and c: "range f \<subseteq> A" |
|
244 |
by (auto simp add: infinite_iff_countable_subset) |
|
245 |
from higman_idx obtain i j where d: "i < j" and e: "f i \<preceq> f j" by blast |
|
246 |
have "f i \<noteq> f j" using b d by (auto simp add: inj_on_def) |
|
247 |
moreover |
|
248 |
have "f i \<in> A" sorry |
|
249 |
moreover |
|
250 |
have "f j \<in> A" sorry |
|
251 |
ultimately have "\<not>(f i \<preceq> f j)" using a by simp |
|
252 |
with e show "False" by simp |
|
253 |
qed |
|
221 | 254 |
|
255 |
definition |
|
223 | 256 |
minimal :: "letter list \<Rightarrow> letter lang \<Rightarrow> bool" |
222
191769fc68c3
included Higman's lemma from the Isabelle repository
urbanc
parents:
221
diff
changeset
|
257 |
where |
223 | 258 |
"minimal x A = (\<forall>y \<in> A. y \<preceq> x \<longrightarrow> x \<preceq> y)" |
220 | 259 |
|
221 | 260 |
lemma main_lemma: |
223 | 261 |
shows "\<exists>M. M \<subseteq> A \<and> finite M \<and> SUPSEQ A = SUPSEQ M" |
221 | 262 |
proof - |
223 | 263 |
def M \<equiv> "{x \<in> A. minimal x A}" |
264 |
have "M \<subseteq> A" unfolding M_def minimal_def by auto |
|
221 | 265 |
moreover |
266 |
have "finite M" |
|
223 | 267 |
unfolding M_def minimal_def |
268 |
by (rule Higman_antichains) (auto simp add: emb_antisym) |
|
221 | 269 |
moreover |
270 |
have "SUPSEQ A \<subseteq> SUPSEQ M" |
|
223 | 271 |
proof |
272 |
fix x |
|
273 |
assume "x \<in> SUPSEQ A" |
|
274 |
then obtain y where "y \<in> A" and "y \<preceq> x" by (auto simp add: SUPSEQ_def) |
|
275 |
then have a: "y \<in> {y' \<in> A. y' \<preceq> x}" by simp |
|
276 |
obtain z where b: "z \<in> A" "z \<preceq> x" and c: "\<forall>y. y \<preceq> z \<and> y \<noteq> z \<longrightarrow> y \<notin> {y' \<in> A. y' \<preceq> x}" |
|
277 |
using wfE_min[OF emb_wf a] by auto |
|
278 |
then have "z \<in> M" |
|
279 |
unfolding M_def minimal_def |
|
280 |
by (auto intro: emb_trans) |
|
281 |
with b show "x \<in> SUPSEQ M" |
|
282 |
by (auto simp add: SUPSEQ_def) |
|
283 |
qed |
|
221 | 284 |
moreover |
285 |
have "SUPSEQ M \<subseteq> SUPSEQ A" |
|
286 |
by (auto simp add: SUPSEQ_def M_def) |
|
287 |
ultimately |
|
288 |
show "\<exists>M. M \<subseteq> A \<and> finite M \<and> SUPSEQ A = SUPSEQ M" by blast |
|
289 |
qed |
|
290 |
||
291 |
lemma closure_SUPSEQ: |
|
222
191769fc68c3
included Higman's lemma from the Isabelle repository
urbanc
parents:
221
diff
changeset
|
292 |
fixes A::"letter lang" |
221 | 293 |
shows "regular (SUPSEQ A)" |
294 |
proof - |
|
295 |
obtain M where a: "finite M" and b: "SUPSEQ A = SUPSEQ M" |
|
296 |
using main_lemma by blast |
|
297 |
have "regular M" using a by (rule finite_regular) |
|
298 |
then have "regular (SUPSEQ M)" by (rule regular_SUPSEQ) |
|
299 |
then show "regular (SUPSEQ A)" using b by simp |
|
300 |
qed |
|
301 |
||
302 |
lemma closure_SUBSEQ: |
|
222
191769fc68c3
included Higman's lemma from the Isabelle repository
urbanc
parents:
221
diff
changeset
|
303 |
fixes A::"letter lang" |
221 | 304 |
shows "regular (SUBSEQ A)" |
305 |
proof - |
|
306 |
have "regular (SUPSEQ (- SUBSEQ A))" by (rule closure_SUPSEQ) |
|
223 | 307 |
then have "regular (- SUBSEQ A)" by (subst SUBSEQ_complement) (simp) |
221 | 308 |
then have "regular (- (- (SUBSEQ A)))" by (rule closure_complement) |
309 |
then show "regular (SUBSEQ A)" by simp |
|
310 |
qed |
|
311 |
||
220 | 312 |
end |