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