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