273
+ − 1
+ − 2
theory SpecExt
+ − 3
imports Main "~~/src/HOL/Library/Sublist"
+ − 4
begin
+ − 5
+ − 6
section {* Sequential Composition of Languages *}
+ − 7
+ − 8
definition
+ − 9
Sequ :: "string set \<Rightarrow> string set \<Rightarrow> string set" ("_ ;; _" [100,100] 100)
+ − 10
where
+ − 11
"A ;; B = {s1 @ s2 | s1 s2. s1 \<in> A \<and> s2 \<in> B}"
+ − 12
+ − 13
text {* Two Simple Properties about Sequential Composition *}
+ − 14
+ − 15
lemma Sequ_empty_string [simp]:
+ − 16
shows "A ;; {[]} = A"
+ − 17
and "{[]} ;; A = A"
+ − 18
by (simp_all add: Sequ_def)
+ − 19
+ − 20
lemma Sequ_empty [simp]:
+ − 21
shows "A ;; {} = {}"
+ − 22
and "{} ;; A = {}"
+ − 23
by (simp_all add: Sequ_def)
+ − 24
+ − 25
lemma Sequ_assoc:
+ − 26
shows "(A ;; B) ;; C = A ;; (B ;; C)"
+ − 27
apply(auto simp add: Sequ_def)
+ − 28
apply blast
+ − 29
by (metis append_assoc)
+ − 30
+ − 31
lemma Sequ_Union_in:
+ − 32
shows "(A ;; (\<Union>x\<in> B. C x)) = (\<Union>x\<in> B. A ;; C x)"
+ − 33
by (auto simp add: Sequ_def)
+ − 34
+ − 35
section {* Semantic Derivative (Left Quotient) of Languages *}
+ − 36
+ − 37
definition
+ − 38
Der :: "char \<Rightarrow> string set \<Rightarrow> string set"
+ − 39
where
+ − 40
"Der c A \<equiv> {s. c # s \<in> A}"
+ − 41
+ − 42
definition
+ − 43
Ders :: "string \<Rightarrow> string set \<Rightarrow> string set"
+ − 44
where
+ − 45
"Ders s A \<equiv> {s'. s @ s' \<in> A}"
+ − 46
+ − 47
lemma Der_null [simp]:
+ − 48
shows "Der c {} = {}"
+ − 49
unfolding Der_def
+ − 50
by auto
+ − 51
+ − 52
lemma Der_empty [simp]:
+ − 53
shows "Der c {[]} = {}"
+ − 54
unfolding Der_def
+ − 55
by auto
+ − 56
+ − 57
lemma Der_char [simp]:
+ − 58
shows "Der c {[d]} = (if c = d then {[]} else {})"
+ − 59
unfolding Der_def
+ − 60
by auto
+ − 61
+ − 62
lemma Der_union [simp]:
+ − 63
shows "Der c (A \<union> B) = Der c A \<union> Der c B"
+ − 64
unfolding Der_def
+ − 65
by auto
+ − 66
+ − 67
lemma Der_UNION [simp]:
+ − 68
shows "Der c (\<Union>x\<in>A. B x) = (\<Union>x\<in>A. Der c (B x))"
+ − 69
by (auto simp add: Der_def)
+ − 70
+ − 71
lemma Der_Sequ [simp]:
+ − 72
shows "Der c (A ;; B) = (Der c A) ;; B \<union> (if [] \<in> A then Der c B else {})"
+ − 73
unfolding Der_def Sequ_def
+ − 74
by (auto simp add: Cons_eq_append_conv)
+ − 75
+ − 76
+ − 77
section {* Kleene Star for Languages *}
+ − 78
+ − 79
inductive_set
+ − 80
Star :: "string set \<Rightarrow> string set" ("_\<star>" [101] 102)
+ − 81
for A :: "string set"
+ − 82
where
+ − 83
start[intro]: "[] \<in> A\<star>"
+ − 84
| step[intro]: "\<lbrakk>s1 \<in> A; s2 \<in> A\<star>\<rbrakk> \<Longrightarrow> s1 @ s2 \<in> A\<star>"
+ − 85
+ − 86
(* Arden's lemma *)
+ − 87
+ − 88
lemma Star_cases:
+ − 89
shows "A\<star> = {[]} \<union> A ;; A\<star>"
+ − 90
unfolding Sequ_def
+ − 91
by (auto) (metis Star.simps)
+ − 92
+ − 93
lemma Star_decomp:
+ − 94
assumes "c # x \<in> A\<star>"
+ − 95
shows "\<exists>s1 s2. x = s1 @ s2 \<and> c # s1 \<in> A \<and> s2 \<in> A\<star>"
+ − 96
using assms
+ − 97
by (induct x\<equiv>"c # x" rule: Star.induct)
+ − 98
(auto simp add: append_eq_Cons_conv)
+ − 99
+ − 100
lemma Star_Der_Sequ:
+ − 101
shows "Der c (A\<star>) \<subseteq> (Der c A) ;; A\<star>"
+ − 102
unfolding Der_def Sequ_def
+ − 103
by(auto simp add: Star_decomp)
+ − 104
+ − 105
+ − 106
lemma Der_star [simp]:
+ − 107
shows "Der c (A\<star>) = (Der c A) ;; A\<star>"
+ − 108
proof -
+ − 109
have "Der c (A\<star>) = Der c ({[]} \<union> A ;; A\<star>)"
+ − 110
by (simp only: Star_cases[symmetric])
+ − 111
also have "... = Der c (A ;; A\<star>)"
+ − 112
by (simp only: Der_union Der_empty) (simp)
+ − 113
also have "... = (Der c A) ;; A\<star> \<union> (if [] \<in> A then Der c (A\<star>) else {})"
+ − 114
by simp
+ − 115
also have "... = (Der c A) ;; A\<star>"
+ − 116
using Star_Der_Sequ by auto
+ − 117
finally show "Der c (A\<star>) = (Der c A) ;; A\<star>" .
+ − 118
qed
+ − 119
+ − 120
section {* Power operation for Sets *}
+ − 121
+ − 122
fun
+ − 123
Pow :: "string set \<Rightarrow> nat \<Rightarrow> string set" ("_ \<up> _" [101, 102] 101)
+ − 124
where
+ − 125
"A \<up> 0 = {[]}"
+ − 126
| "A \<up> (Suc n) = A ;; (A \<up> n)"
+ − 127
+ − 128
lemma Pow_empty [simp]:
+ − 129
shows "[] \<in> A \<up> n \<longleftrightarrow> (n = 0 \<or> [] \<in> A)"
+ − 130
by(induct n) (auto simp add: Sequ_def)
+ − 131
+ − 132
lemma Pow_Suc_rev:
+ − 133
"A \<up> (Suc n) = (A \<up> n) ;; A"
+ − 134
apply(induct n arbitrary: A)
+ − 135
apply(simp_all)
+ − 136
by (metis Sequ_assoc)
+ − 137
+ − 138
+ − 139
lemma Pow_decomp:
+ − 140
assumes "c # x \<in> A \<up> n"
+ − 141
shows "\<exists>s1 s2. x = s1 @ s2 \<and> c # s1 \<in> A \<and> s2 \<in> A \<up> (n - 1)"
+ − 142
using assms
+ − 143
apply(induct n)
+ − 144
apply(auto simp add: Cons_eq_append_conv Sequ_def)
+ − 145
apply(case_tac n)
+ − 146
apply(auto simp add: Sequ_def)
+ − 147
apply(blast)
+ − 148
done
+ − 149
+ − 150
lemma Star_Pow:
+ − 151
assumes "s \<in> A\<star>"
+ − 152
shows "\<exists>n. s \<in> A \<up> n"
+ − 153
using assms
+ − 154
apply(induct)
+ − 155
apply(auto)
+ − 156
apply(rule_tac x="Suc n" in exI)
+ − 157
apply(auto simp add: Sequ_def)
+ − 158
done
+ − 159
+ − 160
lemma Pow_Star:
+ − 161
assumes "s \<in> A \<up> n"
+ − 162
shows "s \<in> A\<star>"
+ − 163
using assms
+ − 164
apply(induct n arbitrary: s)
+ − 165
apply(auto simp add: Sequ_def)
+ − 166
done
+ − 167
+ − 168
lemma Der_Pow_0:
+ − 169
shows "Der c (A \<up> 0) = {}"
+ − 170
by(simp add: Der_def)
+ − 171
+ − 172
lemma Der_Pow_Suc:
+ − 173
shows "Der c (A \<up> (Suc n)) = (Der c A) ;; (A \<up> n)"
+ − 174
unfolding Der_def Sequ_def
+ − 175
apply(auto simp add: Cons_eq_append_conv Sequ_def dest!: Pow_decomp)
+ − 176
apply(case_tac n)
+ − 177
apply(force simp add: Sequ_def)+
+ − 178
done
+ − 179
+ − 180
lemma Der_Pow [simp]:
+ − 181
shows "Der c (A \<up> n) = (if n = 0 then {} else (Der c A) ;; (A \<up> (n - 1)))"
+ − 182
apply(case_tac n)
+ − 183
apply(simp_all del: Pow.simps add: Der_Pow_0 Der_Pow_Suc)
+ − 184
done
+ − 185
+ − 186
lemma Der_Pow_Sequ [simp]:
+ − 187
shows "Der c (A ;; A \<up> n) = (Der c A) ;; (A \<up> n)"
+ − 188
by (simp only: Pow.simps[symmetric] Der_Pow) (simp)
+ − 189
+ − 190
+ − 191
lemma Pow_Sequ_Un:
+ − 192
assumes "0 < x"
+ − 193
shows "(\<Union>n \<in> {..x}. (A \<up> n)) = ({[]} \<union> (\<Union>n \<in> {..x - Suc 0}. A ;; (A \<up> n)))"
+ − 194
using assms
+ − 195
apply(auto simp add: Sequ_def)
+ − 196
apply(smt Pow.elims Sequ_def Suc_le_mono Suc_pred atMost_iff empty_iff insert_iff mem_Collect_eq)
+ − 197
apply(rule_tac x="Suc xa" in bexI)
+ − 198
apply(auto simp add: Sequ_def)
+ − 199
done
+ − 200
+ − 201
lemma Pow_Sequ_Un2:
+ − 202
assumes "0 < x"
+ − 203
shows "(\<Union>n \<in> {x..}. (A \<up> n)) = (\<Union>n \<in> {x - Suc 0..}. A ;; (A \<up> n))"
+ − 204
using assms
+ − 205
apply(auto simp add: Sequ_def)
+ − 206
apply(case_tac n)
+ − 207
apply(auto simp add: Sequ_def)
+ − 208
apply fastforce
+ − 209
apply(case_tac x)
+ − 210
apply(auto)
+ − 211
apply(rule_tac x="Suc xa" in bexI)
+ − 212
apply(auto simp add: Sequ_def)
+ − 213
done
+ − 214
+ − 215
section {* Regular Expressions *}
+ − 216
+ − 217
datatype rexp =
+ − 218
ZERO
+ − 219
| ONE
+ − 220
| CHAR char
+ − 221
| SEQ rexp rexp
+ − 222
| ALT rexp rexp
+ − 223
| STAR rexp
+ − 224
| UPNTIMES rexp nat
+ − 225
| NTIMES rexp nat
+ − 226
| FROMNTIMES rexp nat
+ − 227
| NMTIMES rexp nat nat
+ − 228
+ − 229
section {* Semantics of Regular Expressions *}
+ − 230
+ − 231
fun
+ − 232
L :: "rexp \<Rightarrow> string set"
+ − 233
where
+ − 234
"L (ZERO) = {}"
+ − 235
| "L (ONE) = {[]}"
+ − 236
| "L (CHAR c) = {[c]}"
+ − 237
| "L (SEQ r1 r2) = (L r1) ;; (L r2)"
+ − 238
| "L (ALT r1 r2) = (L r1) \<union> (L r2)"
+ − 239
| "L (STAR r) = (L r)\<star>"
+ − 240
| "L (UPNTIMES r n) = (\<Union>i\<in> {..n} . (L r) \<up> i)"
+ − 241
| "L (NTIMES r n) = (L r) \<up> n"
+ − 242
| "L (FROMNTIMES r n) = (\<Union>i\<in> {n..} . (L r) \<up> i)"
+ − 243
| "L (NMTIMES r n m) = (\<Union>i\<in>{n..m} . (L r) \<up> i)"
+ − 244
+ − 245
section {* Nullable, Derivatives *}
+ − 246
+ − 247
fun
+ − 248
nullable :: "rexp \<Rightarrow> bool"
+ − 249
where
+ − 250
"nullable (ZERO) = False"
+ − 251
| "nullable (ONE) = True"
+ − 252
| "nullable (CHAR c) = False"
+ − 253
| "nullable (ALT r1 r2) = (nullable r1 \<or> nullable r2)"
+ − 254
| "nullable (SEQ r1 r2) = (nullable r1 \<and> nullable r2)"
+ − 255
| "nullable (STAR r) = True"
+ − 256
| "nullable (UPNTIMES r n) = True"
+ − 257
| "nullable (NTIMES r n) = (if n = 0 then True else nullable r)"
+ − 258
| "nullable (FROMNTIMES r n) = (if n = 0 then True else nullable r)"
+ − 259
| "nullable (NMTIMES r n m) = (if m < n then False else (if n = 0 then True else nullable r))"
+ − 260
+ − 261
fun
+ − 262
der :: "char \<Rightarrow> rexp \<Rightarrow> rexp"
+ − 263
where
+ − 264
"der c (ZERO) = ZERO"
+ − 265
| "der c (ONE) = ZERO"
+ − 266
| "der c (CHAR d) = (if c = d then ONE else ZERO)"
+ − 267
| "der c (ALT r1 r2) = ALT (der c r1) (der c r2)"
+ − 268
| "der c (SEQ r1 r2) =
+ − 269
(if nullable r1
+ − 270
then ALT (SEQ (der c r1) r2) (der c r2)
+ − 271
else SEQ (der c r1) r2)"
+ − 272
| "der c (STAR r) = SEQ (der c r) (STAR r)"
+ − 273
| "der c (UPNTIMES r n) = (if n = 0 then ZERO else SEQ (der c r) (UPNTIMES r (n - 1)))"
+ − 274
| "der c (NTIMES r n) = (if n = 0 then ZERO else SEQ (der c r) (NTIMES r (n - 1)))"
277
+ − 275
| "der c (FROMNTIMES r n) =
+ − 276
(if n = 0
+ − 277
then SEQ (der c r) (STAR r)
+ − 278
else SEQ (der c r) (FROMNTIMES r (n - 1)))"
273
+ − 279
| "der c (NMTIMES r n m) =
+ − 280
(if m < n then ZERO
+ − 281
else (if n = 0 then (if m = 0 then ZERO else
+ − 282
SEQ (der c r) (UPNTIMES r (m - 1))) else
+ − 283
SEQ (der c r) (NMTIMES r (n - 1) (m - 1))))"
+ − 284
+ − 285
fun
+ − 286
ders :: "string \<Rightarrow> rexp \<Rightarrow> rexp"
+ − 287
where
+ − 288
"ders [] r = r"
+ − 289
| "ders (c # s) r = ders s (der c r)"
+ − 290
+ − 291
+ − 292
lemma nullable_correctness:
+ − 293
shows "nullable r \<longleftrightarrow> [] \<in> (L r)"
+ − 294
by(induct r) (auto simp add: Sequ_def)
+ − 295
+ − 296
+ − 297
lemma der_correctness:
+ − 298
shows "L (der c r) = Der c (L r)"
+ − 299
apply(induct r)
+ − 300
apply(simp add: nullable_correctness del: Der_UNION)
+ − 301
apply(simp add: nullable_correctness del: Der_UNION)
+ − 302
apply(simp add: nullable_correctness del: Der_UNION)
+ − 303
apply(simp add: nullable_correctness del: Der_UNION)
+ − 304
apply(simp add: nullable_correctness del: Der_UNION)
+ − 305
apply(simp add: nullable_correctness del: Der_UNION)
+ − 306
prefer 2
+ − 307
apply(simp add: nullable_correctness del: Der_UNION)
+ − 308
apply(simp add: nullable_correctness del: Der_UNION)
+ − 309
apply(rule impI)
+ − 310
apply(subst Sequ_Union_in)
+ − 311
apply(subst Der_Pow_Sequ[symmetric])
+ − 312
apply(subst Pow.simps[symmetric])
+ − 313
apply(subst Der_UNION[symmetric])
+ − 314
apply(subst Pow_Sequ_Un)
+ − 315
apply(simp)
+ − 316
apply(simp only: Der_union Der_empty)
276
+ − 317
apply(simp)
+ − 318
(* FROMNTIMES *)
+ − 319
apply(simp add: nullable_correctness del: Der_UNION)
277
+ − 320
apply(rule conjI)
+ − 321
prefer 2
273
+ − 322
apply(subst Sequ_Union_in)
+ − 323
apply(subst Der_Pow_Sequ[symmetric])
+ − 324
apply(subst Pow.simps[symmetric])
+ − 325
apply(case_tac x2)
+ − 326
prefer 2
+ − 327
apply(subst Pow_Sequ_Un2)
+ − 328
apply(simp)
+ − 329
apply(simp)
277
+ − 330
apply(auto simp add: Sequ_def Der_def)[1]
+ − 331
apply(auto simp add: Sequ_def split: if_splits)[1]
+ − 332
using Star_Pow apply fastforce
+ − 333
using Pow_Star apply blast
276
+ − 334
(* NMTIMES *)
273
+ − 335
apply(simp add: nullable_correctness del: Der_UNION)
+ − 336
apply(rule impI)
+ − 337
apply(rule conjI)
+ − 338
apply(rule impI)
+ − 339
apply(subst Sequ_Union_in)
+ − 340
apply(subst Der_Pow_Sequ[symmetric])
+ − 341
apply(subst Pow.simps[symmetric])
+ − 342
apply(subst Der_UNION[symmetric])
+ − 343
apply(case_tac x3a)
+ − 344
apply(simp)
+ − 345
apply(clarify)
+ − 346
apply(auto simp add: Sequ_def Der_def Cons_eq_append_conv)[1]
+ − 347
apply(rule_tac x="Suc xa" in bexI)
+ − 348
apply(auto simp add: Sequ_def)[2]
+ − 349
apply (metis append_Cons)
+ − 350
apply (metis (no_types, hide_lams) Pow_decomp atMost_iff diff_Suc_eq_diff_pred diff_is_0_eq)
+ − 351
apply(rule impI)+
+ − 352
apply(subst Sequ_Union_in)
+ − 353
apply(subst Der_Pow_Sequ[symmetric])
+ − 354
apply(subst Pow.simps[symmetric])
+ − 355
apply(subst Der_UNION[symmetric])
+ − 356
apply(case_tac x2)
+ − 357
apply(simp)
+ − 358
apply(simp del: Pow.simps)
+ − 359
apply(auto simp add: Sequ_def Der_def)
+ − 360
apply (metis One_nat_def Suc_le_D Suc_le_mono atLeastAtMost_iff diff_Suc_1 not_le)
+ − 361
by fastforce
+ − 362
+ − 363
+ − 364
+ − 365
lemma ders_correctness:
+ − 366
shows "L (ders s r) = Ders s (L r)"
+ − 367
by (induct s arbitrary: r)
+ − 368
(simp_all add: Ders_def der_correctness Der_def)
+ − 369
+ − 370
+ − 371
+ − 372
section {* Values *}
+ − 373
+ − 374
datatype val =
+ − 375
Void
+ − 376
| Char char
+ − 377
| Seq val val
+ − 378
| Right val
+ − 379
| Left val
+ − 380
| Stars "val list"
+ − 381
+ − 382
+ − 383
section {* The string behind a value *}
+ − 384
+ − 385
fun
+ − 386
flat :: "val \<Rightarrow> string"
+ − 387
where
+ − 388
"flat (Void) = []"
+ − 389
| "flat (Char c) = [c]"
+ − 390
| "flat (Left v) = flat v"
+ − 391
| "flat (Right v) = flat v"
+ − 392
| "flat (Seq v1 v2) = (flat v1) @ (flat v2)"
+ − 393
| "flat (Stars []) = []"
+ − 394
| "flat (Stars (v#vs)) = (flat v) @ (flat (Stars vs))"
+ − 395
+ − 396
abbreviation
+ − 397
"flats vs \<equiv> concat (map flat vs)"
+ − 398
+ − 399
lemma flat_Stars [simp]:
+ − 400
"flat (Stars vs) = flats vs"
+ − 401
by (induct vs) (auto)
+ − 402
+ − 403
lemma Star_concat:
+ − 404
assumes "\<forall>s \<in> set ss. s \<in> A"
+ − 405
shows "concat ss \<in> A\<star>"
+ − 406
using assms by (induct ss) (auto)
+ − 407
+ − 408
lemma Star_cstring:
+ − 409
assumes "s \<in> A\<star>"
+ − 410
shows "\<exists>ss. concat ss = s \<and> (\<forall>s \<in> set ss. s \<in> A \<and> s \<noteq> [])"
+ − 411
using assms
+ − 412
apply(induct rule: Star.induct)
+ − 413
apply(auto)[1]
+ − 414
apply(rule_tac x="[]" in exI)
+ − 415
apply(simp)
+ − 416
apply(erule exE)
+ − 417
apply(clarify)
+ − 418
apply(case_tac "s1 = []")
+ − 419
apply(rule_tac x="ss" in exI)
+ − 420
apply(simp)
+ − 421
apply(rule_tac x="s1#ss" in exI)
+ − 422
apply(simp)
+ − 423
done
+ − 424
+ − 425
lemma Aux:
+ − 426
assumes "\<forall>s\<in>set ss. s = []"
+ − 427
shows "concat ss = []"
+ − 428
using assms
+ − 429
by (induct ss) (auto)
+ − 430
+ − 431
lemma Pow_cstring_nonempty:
+ − 432
assumes "s \<in> A \<up> n"
+ − 433
shows "\<exists>ss. concat ss = s \<and> length ss \<le> n \<and> (\<forall>s \<in> set ss. s \<in> A \<and> s \<noteq> [])"
+ − 434
using assms
+ − 435
apply(induct n arbitrary: s)
+ − 436
apply(auto)
+ − 437
apply(simp add: Sequ_def)
+ − 438
apply(erule exE)+
+ − 439
apply(clarify)
+ − 440
apply(drule_tac x="s2" in meta_spec)
+ − 441
apply(simp)
+ − 442
apply(clarify)
+ − 443
apply(case_tac "s1 = []")
+ − 444
apply(simp)
+ − 445
apply(rule_tac x="ss" in exI)
+ − 446
apply(simp)
+ − 447
apply(rule_tac x="s1 # ss" in exI)
+ − 448
apply(simp)
+ − 449
done
+ − 450
+ − 451
lemma Pow_cstring:
+ − 452
assumes "s \<in> A \<up> n"
+ − 453
shows "\<exists>ss1 ss2. concat (ss1 @ ss2) = s \<and> length (ss1 @ ss2) = n \<and>
+ − 454
(\<forall>s \<in> set ss1. s \<in> A \<and> s \<noteq> []) \<and> (\<forall>s \<in> set ss2. s \<in> A \<and> s = [])"
+ − 455
using assms
+ − 456
apply(induct n arbitrary: s)
+ − 457
apply(auto)[1]
+ − 458
apply(simp only: Pow_Suc_rev)
+ − 459
apply(simp add: Sequ_def)
+ − 460
apply(erule exE)+
+ − 461
apply(clarify)
+ − 462
apply(drule_tac x="s1" in meta_spec)
+ − 463
apply(simp)
+ − 464
apply(erule exE)+
+ − 465
apply(clarify)
+ − 466
apply(case_tac "s2 = []")
+ − 467
apply(simp)
+ − 468
apply(rule_tac x="ss1" in exI)
+ − 469
apply(rule_tac x="s2#ss2" in exI)
+ − 470
apply(simp)
+ − 471
apply(rule_tac x="ss1 @ [s2]" in exI)
+ − 472
apply(rule_tac x="ss2" in exI)
+ − 473
apply(simp)
+ − 474
apply(subst Aux)
+ − 475
apply(auto)[1]
+ − 476
apply(subst Aux)
+ − 477
apply(auto)[1]
+ − 478
apply(simp)
+ − 479
done
+ − 480
+ − 481
+ − 482
section {* Lexical Values *}
+ − 483
+ − 484
+ − 485
+ − 486
inductive
+ − 487
Prf :: "val \<Rightarrow> rexp \<Rightarrow> bool" ("\<Turnstile> _ : _" [100, 100] 100)
+ − 488
where
+ − 489
"\<lbrakk>\<Turnstile> v1 : r1; \<Turnstile> v2 : r2\<rbrakk> \<Longrightarrow> \<Turnstile> Seq v1 v2 : SEQ r1 r2"
+ − 490
| "\<Turnstile> v1 : r1 \<Longrightarrow> \<Turnstile> Left v1 : ALT r1 r2"
+ − 491
| "\<Turnstile> v2 : r2 \<Longrightarrow> \<Turnstile> Right v2 : ALT r1 r2"
+ − 492
| "\<Turnstile> Void : ONE"
+ − 493
| "\<Turnstile> Char c : CHAR c"
+ − 494
| "\<lbrakk>\<forall>v \<in> set vs. \<Turnstile> v : r \<and> flat v \<noteq> []\<rbrakk> \<Longrightarrow> \<Turnstile> Stars vs : STAR r"
+ − 495
| "\<lbrakk>\<forall>v \<in> set vs. \<Turnstile> v : r \<and> flat v \<noteq> []; length vs \<le> n\<rbrakk> \<Longrightarrow> \<Turnstile> Stars vs : UPNTIMES r n"
+ − 496
| "\<lbrakk>\<forall>v \<in> set vs1. \<Turnstile> v : r \<and> flat v \<noteq> [];
+ − 497
\<forall>v \<in> set vs2. \<Turnstile> v : r \<and> flat v = [];
+ − 498
length (vs1 @ vs2) = n\<rbrakk> \<Longrightarrow> \<Turnstile> Stars (vs1 @ vs2) : NTIMES r n"
+ − 499
| "\<lbrakk>\<forall>v \<in> set vs1. \<Turnstile> v : r \<and> flat v \<noteq> [];
+ − 500
\<forall>v \<in> set vs2. \<Turnstile> v : r \<and> flat v = [];
275
+ − 501
length (vs1 @ vs2) = n\<rbrakk> \<Longrightarrow> \<Turnstile> Stars (vs1 @ vs2) : FROMNTIMES r n"
+ − 502
| "\<lbrakk>\<forall>v \<in> set vs. \<Turnstile> v : r \<and> flat v \<noteq> []; length vs > n\<rbrakk> \<Longrightarrow> \<Turnstile> Stars vs : FROMNTIMES r n"
273
+ − 503
| "\<lbrakk>\<forall>v \<in> set vs1. \<Turnstile> v : r \<and> flat v \<noteq> [];
+ − 504
\<forall>v \<in> set vs2. \<Turnstile> v : r \<and> flat v = [];
275
+ − 505
length (vs1 @ vs2) = n; length (vs1 @ vs2) \<le> m\<rbrakk> \<Longrightarrow> \<Turnstile> Stars (vs1 @ vs2) : NMTIMES r n m"
+ − 506
| "\<lbrakk>\<forall>v \<in> set vs. \<Turnstile> v : r \<and> flat v \<noteq> [];
+ − 507
length vs > n; length vs \<le> m\<rbrakk> \<Longrightarrow> \<Turnstile> Stars vs : NMTIMES r n m"
273
+ − 508
275
+ − 509
273
+ − 510
inductive_cases Prf_elims:
+ − 511
"\<Turnstile> v : ZERO"
+ − 512
"\<Turnstile> v : SEQ r1 r2"
+ − 513
"\<Turnstile> v : ALT r1 r2"
+ − 514
"\<Turnstile> v : ONE"
+ − 515
"\<Turnstile> v : CHAR c"
+ − 516
"\<Turnstile> vs : STAR r"
+ − 517
"\<Turnstile> vs : UPNTIMES r n"
+ − 518
"\<Turnstile> vs : NTIMES r n"
+ − 519
"\<Turnstile> vs : FROMNTIMES r n"
+ − 520
"\<Turnstile> vs : NMTIMES r n m"
+ − 521
+ − 522
lemma Prf_Stars_appendE:
+ − 523
assumes "\<Turnstile> Stars (vs1 @ vs2) : STAR r"
+ − 524
shows "\<Turnstile> Stars vs1 : STAR r \<and> \<Turnstile> Stars vs2 : STAR r"
+ − 525
using assms
+ − 526
by (auto intro: Prf.intros elim!: Prf_elims)
+ − 527
274
+ − 528
+ − 529
273
+ − 530
lemma flats_empty:
+ − 531
assumes "(\<forall>v\<in>set vs. flat v = [])"
+ − 532
shows "flats vs = []"
+ − 533
using assms
+ − 534
by(induct vs) (simp_all)
+ − 535
+ − 536
lemma Star_cval:
+ − 537
assumes "\<forall>s\<in>set ss. \<exists>v. s = flat v \<and> \<Turnstile> v : r"
+ − 538
shows "\<exists>vs. flats vs = concat ss \<and> (\<forall>v\<in>set vs. \<Turnstile> v : r \<and> flat v \<noteq> [])"
+ − 539
using assms
+ − 540
apply(induct ss)
+ − 541
apply(auto)
+ − 542
apply(rule_tac x="[]" in exI)
+ − 543
apply(simp)
+ − 544
apply(case_tac "flat v = []")
+ − 545
apply(rule_tac x="vs" in exI)
+ − 546
apply(simp)
+ − 547
apply(rule_tac x="v#vs" in exI)
+ − 548
apply(simp)
+ − 549
done
+ − 550
+ − 551
+ − 552
lemma flats_cval:
+ − 553
assumes "\<forall>s\<in>set ss. \<exists>v. s = flat v \<and> \<Turnstile> v : r"
+ − 554
shows "\<exists>vs1 vs2. flats (vs1 @ vs2) = concat ss \<and> length (vs1 @ vs2) = length ss \<and>
+ − 555
(\<forall>v\<in>set vs1. \<Turnstile> v : r \<and> flat v \<noteq> []) \<and>
+ − 556
(\<forall>v\<in>set vs2. \<Turnstile> v : r \<and> flat v = [])"
+ − 557
using assms
+ − 558
apply(induct ss rule: rev_induct)
+ − 559
apply(rule_tac x="[]" in exI)+
+ − 560
apply(simp)
+ − 561
apply(simp)
+ − 562
apply(clarify)
+ − 563
apply(case_tac "flat v = []")
+ − 564
apply(rule_tac x="vs1" in exI)
+ − 565
apply(rule_tac x="v#vs2" in exI)
+ − 566
apply(simp)
+ − 567
apply(rule_tac x="vs1 @ [v]" in exI)
+ − 568
apply(rule_tac x="vs2" in exI)
+ − 569
apply(simp)
+ − 570
apply(subst (asm) (2) flats_empty)
+ − 571
apply(simp)
+ − 572
apply(simp)
+ − 573
done
+ − 574
+ − 575
lemma flats_cval_nonempty:
+ − 576
assumes "\<forall>s\<in>set ss. \<exists>v. s = flat v \<and> \<Turnstile> v : r"
+ − 577
shows "\<exists>vs. flats vs = concat ss \<and> length vs \<le> length ss \<and>
+ − 578
(\<forall>v\<in>set vs. \<Turnstile> v : r \<and> flat v \<noteq> [])"
+ − 579
using assms
+ − 580
apply(induct ss)
+ − 581
apply(rule_tac x="[]" in exI)
+ − 582
apply(simp)
+ − 583
apply(simp)
+ − 584
apply(clarify)
+ − 585
apply(case_tac "flat v = []")
+ − 586
apply(rule_tac x="vs" in exI)
+ − 587
apply(simp)
+ − 588
apply(rule_tac x="v # vs" in exI)
+ − 589
apply(simp)
+ − 590
done
+ − 591
+ − 592
lemma Pow_flats:
+ − 593
assumes "\<forall>v \<in> set vs. flat v \<in> A"
+ − 594
shows "flats vs \<in> A \<up> length vs"
+ − 595
using assms
+ − 596
by(induct vs)(auto simp add: Sequ_def)
+ − 597
+ − 598
lemma Pow_flats_appends:
+ − 599
assumes "\<forall>v \<in> set vs1. flat v \<in> A" "\<forall>v \<in> set vs2. flat v \<in> A"
+ − 600
shows "flats vs1 @ flats vs2 \<in> A \<up> (length vs1 + length vs2)"
+ − 601
using assms
+ − 602
apply(induct vs1)
+ − 603
apply(auto simp add: Sequ_def Pow_flats)
+ − 604
done
+ − 605
+ − 606
lemma L_flat_Prf1:
+ − 607
assumes "\<Turnstile> v : r"
+ − 608
shows "flat v \<in> L r"
+ − 609
using assms
+ − 610
apply(induct)
+ − 611
apply(auto simp add: Sequ_def Star_concat Pow_flats)
+ − 612
apply(meson Pow_flats atMost_iff)
+ − 613
using Pow_flats_appends apply blast
275
+ − 614
using Pow_flats_appends apply blast
+ − 615
apply (meson Pow_flats atLeast_iff less_imp_le)
+ − 616
apply(rule_tac x="length vs1 + length vs2" in bexI)
273
+ − 617
apply(meson Pow_flats_appends atLeastAtMost_iff)
275
+ − 618
apply(simp)
+ − 619
apply(meson Pow_flats atLeastAtMost_iff less_or_eq_imp_le)
273
+ − 620
done
+ − 621
+ − 622
lemma L_flat_Prf2:
+ − 623
assumes "s \<in> L r"
+ − 624
shows "\<exists>v. \<Turnstile> v : r \<and> flat v = s"
+ − 625
using assms
+ − 626
proof(induct r arbitrary: s)
+ − 627
case (STAR r s)
+ − 628
have IH: "\<And>s. s \<in> L r \<Longrightarrow> \<exists>v. \<Turnstile> v : r \<and> flat v = s" by fact
+ − 629
have "s \<in> L (STAR r)" by fact
+ − 630
then obtain ss where "concat ss = s" "\<forall>s \<in> set ss. s \<in> L r \<and> s \<noteq> []"
+ − 631
using Star_cstring by auto
+ − 632
then obtain vs where "flats vs = s" "\<forall>v\<in>set vs. \<Turnstile> v : r \<and> flat v \<noteq> []"
+ − 633
using IH Star_cval by metis
+ − 634
then show "\<exists>v. \<Turnstile> v : STAR r \<and> flat v = s"
+ − 635
using Prf.intros(6) flat_Stars by blast
+ − 636
next
+ − 637
case (SEQ r1 r2 s)
+ − 638
then show "\<exists>v. \<Turnstile> v : SEQ r1 r2 \<and> flat v = s"
+ − 639
unfolding Sequ_def L.simps by (fastforce intro: Prf.intros)
+ − 640
next
+ − 641
case (ALT r1 r2 s)
+ − 642
then show "\<exists>v. \<Turnstile> v : ALT r1 r2 \<and> flat v = s"
+ − 643
unfolding L.simps by (fastforce intro: Prf.intros)
+ − 644
next
+ − 645
case (NTIMES r n)
+ − 646
have IH: "\<And>s. s \<in> L r \<Longrightarrow> \<exists>v. \<Turnstile> v : r \<and> flat v = s" by fact
+ − 647
have "s \<in> L (NTIMES r n)" by fact
+ − 648
then obtain ss1 ss2 where "concat (ss1 @ ss2) = s" "length (ss1 @ ss2) = n"
+ − 649
"\<forall>s \<in> set ss1. s \<in> L r \<and> s \<noteq> []" "\<forall>s \<in> set ss2. s \<in> L r \<and> s = []"
+ − 650
using Pow_cstring by force
+ − 651
then obtain vs1 vs2 where "flats (vs1 @ vs2) = s" "length (vs1 @ vs2) = n"
+ − 652
"\<forall>v\<in>set vs1. \<Turnstile> v : r \<and> flat v \<noteq> []" "\<forall>v\<in>set vs2. \<Turnstile> v : r \<and> flat v = []"
+ − 653
using IH flats_cval
+ − 654
apply -
+ − 655
apply(drule_tac x="ss1 @ ss2" in meta_spec)
+ − 656
apply(drule_tac x="r" in meta_spec)
+ − 657
apply(drule meta_mp)
+ − 658
apply(simp)
+ − 659
apply (metis Un_iff)
+ − 660
apply(clarify)
+ − 661
apply(drule_tac x="vs1" in meta_spec)
+ − 662
apply(drule_tac x="vs2" in meta_spec)
+ − 663
apply(simp)
+ − 664
done
+ − 665
then show "\<exists>v. \<Turnstile> v : NTIMES r n \<and> flat v = s"
+ − 666
using Prf.intros(8) flat_Stars by blast
+ − 667
next
+ − 668
case (FROMNTIMES r n)
+ − 669
have IH: "\<And>s. s \<in> L r \<Longrightarrow> \<exists>v. \<Turnstile> v : r \<and> flat v = s" by fact
+ − 670
have "s \<in> L (FROMNTIMES r n)" by fact
276
+ − 671
then obtain ss1 ss2 k where "concat (ss1 @ ss2) = s" "length (ss1 @ ss2) = k" "n \<le> k"
273
+ − 672
"\<forall>s \<in> set ss1. s \<in> L r \<and> s \<noteq> []" "\<forall>s \<in> set ss2. s \<in> L r \<and> s = []"
275
+ − 673
using Pow_cstring by force
276
+ − 674
then obtain vs1 vs2 where "flats (vs1 @ vs2) = s" "length (vs1 @ vs2) = k" "n \<le> k"
273
+ − 675
"\<forall>v\<in>set vs1. \<Turnstile> v : r \<and> flat v \<noteq> []" "\<forall>v\<in>set vs2. \<Turnstile> v : r \<and> flat v = []"
+ − 676
using IH flats_cval
+ − 677
apply -
+ − 678
apply(drule_tac x="ss1 @ ss2" in meta_spec)
+ − 679
apply(drule_tac x="r" in meta_spec)
+ − 680
apply(drule meta_mp)
+ − 681
apply(simp)
+ − 682
apply (metis Un_iff)
+ − 683
apply(clarify)
+ − 684
apply(drule_tac x="vs1" in meta_spec)
+ − 685
apply(drule_tac x="vs2" in meta_spec)
+ − 686
apply(simp)
+ − 687
done
+ − 688
then show "\<exists>v. \<Turnstile> v : FROMNTIMES r n \<and> flat v = s"
275
+ − 689
apply(case_tac "length vs1 \<le> n")
+ − 690
apply(rule_tac x="Stars (vs1 @ take (n - length vs1) vs2)" in exI)
+ − 691
apply(simp)
+ − 692
apply(subgoal_tac "flats (take (n - length vs1) vs2) = []")
+ − 693
prefer 2
+ − 694
apply (meson flats_empty in_set_takeD)
+ − 695
apply(clarify)
+ − 696
apply(rule conjI)
+ − 697
apply(rule Prf.intros)
+ − 698
apply(simp)
+ − 699
apply (meson in_set_takeD)
+ − 700
apply(simp)
+ − 701
apply(simp)
+ − 702
apply (simp add: flats_empty)
+ − 703
apply(rule_tac x="Stars vs1" in exI)
+ − 704
apply(simp)
+ − 705
apply(rule conjI)
+ − 706
apply(rule Prf.intros(10))
+ − 707
apply(auto)
+ − 708
done
273
+ − 709
next
+ − 710
case (NMTIMES r n m)
+ − 711
have IH: "\<And>s. s \<in> L r \<Longrightarrow> \<exists>v. \<Turnstile> v : r \<and> flat v = s" by fact
+ − 712
have "s \<in> L (NMTIMES r n m)" by fact
+ − 713
then obtain ss1 ss2 k where "concat (ss1 @ ss2) = s" "length (ss1 @ ss2) = k" "n \<le> k" "k \<le> m"
+ − 714
"\<forall>s \<in> set ss1. s \<in> L r \<and> s \<noteq> []" "\<forall>s \<in> set ss2. s \<in> L r \<and> s = []"
+ − 715
using Pow_cstring by (auto, blast)
+ − 716
then obtain vs1 vs2 where "flats (vs1 @ vs2) = s" "length (vs1 @ vs2) = k" "n \<le> k" "k \<le> m"
+ − 717
"\<forall>v\<in>set vs1. \<Turnstile> v : r \<and> flat v \<noteq> []" "\<forall>v\<in>set vs2. \<Turnstile> v : r \<and> flat v = []"
+ − 718
using IH flats_cval
+ − 719
apply -
+ − 720
apply(drule_tac x="ss1 @ ss2" in meta_spec)
+ − 721
apply(drule_tac x="r" in meta_spec)
+ − 722
apply(drule meta_mp)
+ − 723
apply(simp)
+ − 724
apply (metis Un_iff)
+ − 725
apply(clarify)
+ − 726
apply(drule_tac x="vs1" in meta_spec)
+ − 727
apply(drule_tac x="vs2" in meta_spec)
+ − 728
apply(simp)
+ − 729
done
+ − 730
then show "\<exists>v. \<Turnstile> v : NMTIMES r n m \<and> flat v = s"
276
+ − 731
apply(case_tac "length vs1 \<le> n")
+ − 732
apply(rule_tac x="Stars (vs1 @ take (n - length vs1) vs2)" in exI)
273
+ − 733
apply(simp)
276
+ − 734
apply(subgoal_tac "flats (take (n - length vs1) vs2) = []")
+ − 735
prefer 2
+ − 736
apply (meson flats_empty in_set_takeD)
+ − 737
apply(clarify)
+ − 738
apply(rule conjI)
+ − 739
apply(rule Prf.intros)
+ − 740
apply(simp)
+ − 741
apply (meson in_set_takeD)
+ − 742
apply(simp)
+ − 743
apply(simp)
+ − 744
apply (simp add: flats_empty)
+ − 745
apply(rule_tac x="Stars vs1" in exI)
+ − 746
apply(simp)
+ − 747
apply(rule conjI)
+ − 748
apply(rule Prf.intros)
+ − 749
apply(auto)
+ − 750
done
273
+ − 751
next
+ − 752
case (UPNTIMES r n s)
+ − 753
have IH: "\<And>s. s \<in> L r \<Longrightarrow> \<exists>v. \<Turnstile> v : r \<and> flat v = s" by fact
+ − 754
have "s \<in> L (UPNTIMES r n)" by fact
+ − 755
then obtain ss where "concat ss = s" "\<forall>s \<in> set ss. s \<in> L r \<and> s \<noteq> []" "length ss \<le> n"
+ − 756
using Pow_cstring_nonempty by force
+ − 757
then obtain vs where "flats vs = s" "\<forall>v\<in>set vs. \<Turnstile> v : r \<and> flat v \<noteq> []" "length vs \<le> n"
+ − 758
using IH flats_cval_nonempty by (smt order.trans)
+ − 759
then show "\<exists>v. \<Turnstile> v : UPNTIMES r n \<and> flat v = s"
+ − 760
using Prf.intros(7) flat_Stars by blast
+ − 761
qed (auto intro: Prf.intros)
+ − 762
+ − 763
+ − 764
lemma L_flat_Prf:
+ − 765
shows "L(r) = {flat v | v. \<Turnstile> v : r}"
+ − 766
using L_flat_Prf1 L_flat_Prf2 by blast
+ − 767
+ − 768
+ − 769
+ − 770
section {* Sets of Lexical Values *}
+ − 771
+ − 772
text {*
+ − 773
Shows that lexical values are finite for a given regex and string.
+ − 774
*}
+ − 775
+ − 776
definition
+ − 777
LV :: "rexp \<Rightarrow> string \<Rightarrow> val set"
+ − 778
where "LV r s \<equiv> {v. \<Turnstile> v : r \<and> flat v = s}"
+ − 779
+ − 780
lemma LV_simps:
+ − 781
shows "LV ZERO s = {}"
+ − 782
and "LV ONE s = (if s = [] then {Void} else {})"
+ − 783
and "LV (CHAR c) s = (if s = [c] then {Char c} else {})"
+ − 784
and "LV (ALT r1 r2) s = Left ` LV r1 s \<union> Right ` LV r2 s"
+ − 785
unfolding LV_def
274
+ − 786
apply(auto intro: Prf.intros elim: Prf.cases)
+ − 787
done
273
+ − 788
+ − 789
abbreviation
275
+ − 790
"Prefixes s \<equiv> {s'. prefix s' s}"
273
+ − 791
+ − 792
abbreviation
275
+ − 793
"Suffixes s \<equiv> {s'. suffix s' s}"
273
+ − 794
+ − 795
abbreviation
275
+ − 796
"SSuffixes s \<equiv> {s'. strict_suffix s' s}"
273
+ − 797
+ − 798
lemma Suffixes_cons [simp]:
+ − 799
shows "Suffixes (c # s) = Suffixes s \<union> {c # s}"
275
+ − 800
by (auto simp add: suffix_def Cons_eq_append_conv)
273
+ − 801
+ − 802
+ − 803
lemma finite_Suffixes:
+ − 804
shows "finite (Suffixes s)"
+ − 805
by (induct s) (simp_all)
+ − 806
+ − 807
lemma finite_SSuffixes:
+ − 808
shows "finite (SSuffixes s)"
+ − 809
proof -
+ − 810
have "SSuffixes s \<subseteq> Suffixes s"
275
+ − 811
unfolding suffix_def strict_suffix_def by auto
273
+ − 812
then show "finite (SSuffixes s)"
+ − 813
using finite_Suffixes finite_subset by blast
+ − 814
qed
+ − 815
+ − 816
lemma finite_Prefixes:
+ − 817
shows "finite (Prefixes s)"
+ − 818
proof -
+ − 819
have "finite (Suffixes (rev s))"
+ − 820
by (rule finite_Suffixes)
+ − 821
then have "finite (rev ` Suffixes (rev s))" by simp
+ − 822
moreover
+ − 823
have "rev ` (Suffixes (rev s)) = Prefixes s"
275
+ − 824
unfolding suffix_def prefix_def image_def
273
+ − 825
by (auto)(metis rev_append rev_rev_ident)+
+ − 826
ultimately show "finite (Prefixes s)" by simp
+ − 827
qed
+ − 828
276
+ − 829
definition
+ − 830
"Stars_Cons V Vs \<equiv> {Stars (v # vs) | v vs. v \<in> V \<and> Stars vs \<in> Vs}"
+ − 831
+ − 832
definition
+ − 833
"Stars_Append Vs1 Vs2 \<equiv> {Stars (vs1 @ vs2) | vs1 vs2. Stars vs1 \<in> Vs1 \<and> Stars vs2 \<in> Vs2}"
+ − 834
+ − 835
fun Stars_Pow :: "val set \<Rightarrow> nat \<Rightarrow> val set"
+ − 836
where
+ − 837
"Stars_Pow Vs 0 = {Stars []}"
+ − 838
| "Stars_Pow Vs (Suc n) = Stars_Cons Vs (Stars_Pow Vs n)"
+ − 839
+ − 840
lemma finite_Stars_Cons:
+ − 841
assumes "finite V" "finite Vs"
+ − 842
shows "finite (Stars_Cons V Vs)"
+ − 843
using assms
+ − 844
proof -
+ − 845
from assms(2) have "finite (Stars -` Vs)"
+ − 846
by(simp add: finite_vimageI inj_on_def)
+ − 847
with assms(1) have "finite (V \<times> (Stars -` Vs))"
+ − 848
by(simp)
+ − 849
then have "finite ((\<lambda>(v, vs). Stars (v # vs)) ` (V \<times> (Stars -` Vs)))"
+ − 850
by simp
+ − 851
moreover have "Stars_Cons V Vs = (\<lambda>(v, vs). Stars (v # vs)) ` (V \<times> (Stars -` Vs))"
+ − 852
unfolding Stars_Cons_def by auto
+ − 853
ultimately show "finite (Stars_Cons V Vs)"
+ − 854
by simp
+ − 855
qed
+ − 856
+ − 857
lemma finite_Stars_Append:
+ − 858
assumes "finite Vs1" "finite Vs2"
+ − 859
shows "finite (Stars_Append Vs1 Vs2)"
+ − 860
using assms
+ − 861
proof -
+ − 862
define UVs1 where "UVs1 \<equiv> Stars -` Vs1"
+ − 863
define UVs2 where "UVs2 \<equiv> Stars -` Vs2"
+ − 864
from assms have "finite UVs1" "finite UVs2"
+ − 865
unfolding UVs1_def UVs2_def
+ − 866
by(simp_all add: finite_vimageI inj_on_def)
+ − 867
then have "finite ((\<lambda>(vs1, vs2). Stars (vs1 @ vs2)) ` (UVs1 \<times> UVs2))"
+ − 868
by simp
+ − 869
moreover
+ − 870
have "Stars_Append Vs1 Vs2 = (\<lambda>(vs1, vs2). Stars (vs1 @ vs2)) ` (UVs1 \<times> UVs2)"
+ − 871
unfolding Stars_Append_def UVs1_def UVs2_def by auto
+ − 872
ultimately show "finite (Stars_Append Vs1 Vs2)"
+ − 873
by simp
+ − 874
qed
+ − 875
+ − 876
lemma finite_Stars_Pow:
+ − 877
assumes "finite Vs"
+ − 878
shows "finite (Stars_Pow Vs n)"
+ − 879
by (induct n) (simp_all add: finite_Stars_Cons assms)
+ − 880
273
+ − 881
lemma LV_STAR_finite:
+ − 882
assumes "\<forall>s. finite (LV r s)"
+ − 883
shows "finite (LV (STAR r) s)"
+ − 884
proof(induct s rule: length_induct)
+ − 885
fix s::"char list"
+ − 886
assume "\<forall>s'. length s' < length s \<longrightarrow> finite (LV (STAR r) s')"
+ − 887
then have IH: "\<forall>s' \<in> SSuffixes s. finite (LV (STAR r) s')"
275
+ − 888
by (auto simp add: strict_suffix_def)
+ − 889
define f where "f \<equiv> \<lambda>(v, vs). Stars (v # vs)"
+ − 890
define S1 where "S1 \<equiv> \<Union>s' \<in> Prefixes s. LV r s'"
276
+ − 891
define S2 where "S2 \<equiv> \<Union>s2 \<in> SSuffixes s. LV (STAR r) s2"
273
+ − 892
have "finite S1" using assms
+ − 893
unfolding S1_def by (simp_all add: finite_Prefixes)
+ − 894
moreover
+ − 895
with IH have "finite S2" unfolding S2_def
276
+ − 896
by (auto simp add: finite_SSuffixes)
273
+ − 897
ultimately
276
+ − 898
have "finite ({Stars []} \<union> Stars_Cons S1 S2)"
+ − 899
by (simp add: finite_Stars_Cons)
273
+ − 900
moreover
276
+ − 901
have "LV (STAR r) s \<subseteq> {Stars []} \<union> (Stars_Cons S1 S2)"
+ − 902
unfolding S1_def S2_def f_def LV_def Stars_Cons_def
+ − 903
unfolding prefix_def strict_suffix_def
+ − 904
unfolding image_def
275
+ − 905
apply(auto)
+ − 906
apply(case_tac x)
273
+ − 907
apply(auto elim: Prf_elims)
+ − 908
apply(erule Prf_elims)
+ − 909
apply(auto)
+ − 910
apply(case_tac vs)
275
+ − 911
apply(auto intro: Prf.intros)
+ − 912
apply(rule exI)
+ − 913
apply(rule conjI)
276
+ − 914
apply(rule_tac x="flats list" in exI)
275
+ − 915
apply(rule conjI)
276
+ − 916
apply(rule_tac x="flat a" in exI)
275
+ − 917
apply(simp)
+ − 918
apply(blast)
276
+ − 919
using Prf.intros(6) flat_Stars by blast
273
+ − 920
ultimately
+ − 921
show "finite (LV (STAR r) s)" by (simp add: finite_subset)
+ − 922
qed
+ − 923
+ − 924
lemma LV_UPNTIMES_STAR:
+ − 925
"LV (UPNTIMES r n) s \<subseteq> LV (STAR r) s"
+ − 926
by(auto simp add: LV_def intro: Prf.intros elim: Prf_elims)
+ − 927
274
+ − 928
lemma LV_NTIMES_3:
+ − 929
shows "LV (NTIMES r (Suc n)) [] = (\<lambda>(v,vs). Stars (v#vs)) ` (LV r [] \<times> (Stars -` (LV (NTIMES r n) [])))"
+ − 930
unfolding LV_def
+ − 931
apply(auto elim!: Prf_elims simp add: image_def)
+ − 932
apply(case_tac vs1)
+ − 933
apply(auto)
+ − 934
apply(case_tac vs2)
+ − 935
apply(auto)
+ − 936
apply(subst append.simps(1)[symmetric])
+ − 937
apply(rule Prf.intros)
+ − 938
apply(auto)
+ − 939
apply(subst append.simps(1)[symmetric])
+ − 940
apply(rule Prf.intros)
+ − 941
apply(auto)
276
+ − 942
done
275
+ − 943
276
+ − 944
lemma LV_FROMNTIMES_3:
+ − 945
shows "LV (FROMNTIMES r (Suc n)) [] =
+ − 946
(\<lambda>(v,vs). Stars (v#vs)) ` (LV r [] \<times> (Stars -` (LV (FROMNTIMES r n) [])))"
+ − 947
unfolding LV_def
+ − 948
apply(auto elim!: Prf_elims simp add: image_def)
+ − 949
apply(case_tac vs1)
+ − 950
apply(auto)
+ − 951
apply(case_tac vs2)
+ − 952
apply(auto)
+ − 953
apply(subst append.simps(1)[symmetric])
+ − 954
apply(rule Prf.intros)
+ − 955
apply(auto)
+ − 956
apply (metis le_imp_less_Suc length_greater_0_conv less_antisym list.exhaust list.set_intros(1) not_less_eq zero_le)
+ − 957
prefer 2
+ − 958
using nth_mem apply blast
+ − 959
apply(case_tac vs1)
+ − 960
apply (smt Groups.add_ac(2) Prf.intros(9) add.right_neutral add_Suc_right append.simps(1) insert_iff length_append list.set(2) list.size(3) list.size(4))
275
+ − 961
apply(auto)
276
+ − 962
done
+ − 963
+ − 964
lemma LV_NTIMES_4:
+ − 965
"LV (NTIMES r n) [] = Stars_Pow (LV r []) n"
+ − 966
apply(induct n)
+ − 967
apply(simp add: LV_def)
+ − 968
apply(auto elim!: Prf_elims simp add: image_def)[1]
+ − 969
apply(subst append.simps[symmetric])
+ − 970
apply(rule Prf.intros)
+ − 971
apply(simp_all)
+ − 972
apply(simp add: LV_NTIMES_3 image_def Stars_Cons_def)
+ − 973
apply blast
+ − 974
done
274
+ − 975
276
+ − 976
lemma LV_NTIMES_5:
+ − 977
"LV (NTIMES r n) s \<subseteq> Stars_Append (LV (STAR r) s) (\<Union>i\<le>n. LV (NTIMES r i) [])"
+ − 978
apply(auto simp add: LV_def)
+ − 979
apply(auto elim!: Prf_elims)
+ − 980
apply(auto simp add: Stars_Append_def)
+ − 981
apply(rule_tac x="vs1" in exI)
+ − 982
apply(rule_tac x="vs2" in exI)
+ − 983
apply(auto)
+ − 984
using Prf.intros(6) apply(auto)
+ − 985
apply(rule_tac x="length vs2" in bexI)
+ − 986
thm Prf.intros
+ − 987
apply(subst append.simps(1)[symmetric])
+ − 988
apply(rule Prf.intros)
+ − 989
apply(auto)[1]
+ − 990
apply(auto)[1]
+ − 991
apply(simp)
+ − 992
apply(simp)
+ − 993
done
+ − 994
+ − 995
lemma ttty:
+ − 996
"LV (FROMNTIMES r n) [] = Stars_Pow (LV r []) n"
+ − 997
apply(induct n)
+ − 998
apply(simp add: LV_def)
+ − 999
apply(auto elim: Prf_elims simp add: image_def)[1]
+ − 1000
prefer 2
+ − 1001
apply(subst append.simps[symmetric])
+ − 1002
apply(rule Prf.intros)
+ − 1003
apply(simp_all)
+ − 1004
apply(erule Prf_elims)
+ − 1005
apply(case_tac vs1)
+ − 1006
apply(simp)
+ − 1007
apply(simp)
+ − 1008
apply(case_tac x)
+ − 1009
apply(simp_all)
+ − 1010
apply(simp add: LV_FROMNTIMES_3 image_def Stars_Cons_def)
+ − 1011
apply blast
+ − 1012
done
+ − 1013
+ − 1014
lemma LV_FROMNTIMES_5:
+ − 1015
"LV (FROMNTIMES r n) s \<subseteq> Stars_Append (LV (STAR r) s) (\<Union>i\<le>n. LV (FROMNTIMES r i) [])"
+ − 1016
apply(auto simp add: LV_def)
+ − 1017
apply(auto elim!: Prf_elims)
+ − 1018
apply(auto simp add: Stars_Append_def)
+ − 1019
apply(rule_tac x="vs1" in exI)
+ − 1020
apply(rule_tac x="vs2" in exI)
+ − 1021
apply(auto)
+ − 1022
using Prf.intros(6) apply(auto)
+ − 1023
apply(rule_tac x="length vs2" in bexI)
+ − 1024
thm Prf.intros
+ − 1025
apply(subst append.simps(1)[symmetric])
+ − 1026
apply(rule Prf.intros)
+ − 1027
apply(auto)[1]
+ − 1028
apply(auto)[1]
+ − 1029
apply(simp)
+ − 1030
apply(simp)
+ − 1031
apply(rule_tac x="vs" in exI)
+ − 1032
apply(rule_tac x="[]" in exI)
+ − 1033
apply(auto)
+ − 1034
by (metis Prf.intros(9) append_Nil atMost_iff empty_iff le_imp_less_Suc less_antisym list.set(1) nth_mem zero_le)
+ − 1035
+ − 1036
lemma LV_FROMNTIMES_6:
+ − 1037
assumes "\<forall>s. finite (LV r s)"
+ − 1038
shows "finite (LV (FROMNTIMES r n) s)"
275
+ − 1039
apply(rule finite_subset)
276
+ − 1040
apply(rule LV_FROMNTIMES_5)
+ − 1041
apply(rule finite_Stars_Append)
+ − 1042
apply(rule LV_STAR_finite)
+ − 1043
apply(rule assms)
+ − 1044
apply(rule finite_UN_I)
+ − 1045
apply(auto)
+ − 1046
by (simp add: assms finite_Stars_Pow ttty)
275
+ − 1047
276
+ − 1048
lemma LV_NMTIMES_5:
+ − 1049
"LV (NMTIMES r n m) s \<subseteq> Stars_Append (LV (STAR r) s) (\<Union>i\<le>n. LV (FROMNTIMES r i) [])"
+ − 1050
apply(auto simp add: LV_def)
+ − 1051
apply(auto elim!: Prf_elims)
+ − 1052
apply(auto simp add: Stars_Append_def)
+ − 1053
apply(rule_tac x="vs1" in exI)
+ − 1054
apply(rule_tac x="vs2" in exI)
+ − 1055
apply(auto)
+ − 1056
using Prf.intros(6) apply(auto)
+ − 1057
apply(rule_tac x="length vs2" in bexI)
+ − 1058
thm Prf.intros
+ − 1059
apply(subst append.simps(1)[symmetric])
+ − 1060
apply(rule Prf.intros)
+ − 1061
apply(auto)[1]
+ − 1062
apply(auto)[1]
+ − 1063
apply(simp)
+ − 1064
apply(simp)
+ − 1065
apply(rule_tac x="vs" in exI)
+ − 1066
apply(rule_tac x="[]" in exI)
+ − 1067
apply(auto)
+ − 1068
by (metis Prf.intros(9) append_Nil atMost_iff empty_iff le_imp_less_Suc less_antisym list.set(1) nth_mem zero_le)
274
+ − 1069
276
+ − 1070
lemma LV_NMTIMES_6:
+ − 1071
assumes "\<forall>s. finite (LV r s)"
+ − 1072
shows "finite (LV (NMTIMES r n m) s)"
+ − 1073
apply(rule finite_subset)
+ − 1074
apply(rule LV_NMTIMES_5)
+ − 1075
apply(rule finite_Stars_Append)
+ − 1076
apply(rule LV_STAR_finite)
+ − 1077
apply(rule assms)
+ − 1078
apply(rule finite_UN_I)
+ − 1079
apply(auto)
+ − 1080
by (simp add: assms finite_Stars_Pow ttty)
+ − 1081
+ − 1082
273
+ − 1083
lemma LV_finite:
+ − 1084
shows "finite (LV r s)"
+ − 1085
proof(induct r arbitrary: s)
+ − 1086
case (ZERO s)
+ − 1087
show "finite (LV ZERO s)" by (simp add: LV_simps)
+ − 1088
next
+ − 1089
case (ONE s)
+ − 1090
show "finite (LV ONE s)" by (simp add: LV_simps)
+ − 1091
next
+ − 1092
case (CHAR c s)
+ − 1093
show "finite (LV (CHAR c) s)" by (simp add: LV_simps)
+ − 1094
next
+ − 1095
case (ALT r1 r2 s)
+ − 1096
then show "finite (LV (ALT r1 r2) s)" by (simp add: LV_simps)
+ − 1097
next
+ − 1098
case (SEQ r1 r2 s)
275
+ − 1099
define f where "f \<equiv> \<lambda>(v1, v2). Seq v1 v2"
+ − 1100
define S1 where "S1 \<equiv> \<Union>s' \<in> Prefixes s. LV r1 s'"
+ − 1101
define S2 where "S2 \<equiv> \<Union>s' \<in> Suffixes s. LV r2 s'"
273
+ − 1102
have IHs: "\<And>s. finite (LV r1 s)" "\<And>s. finite (LV r2 s)" by fact+
+ − 1103
then have "finite S1" "finite S2" unfolding S1_def S2_def
+ − 1104
by (simp_all add: finite_Prefixes finite_Suffixes)
+ − 1105
moreover
+ − 1106
have "LV (SEQ r1 r2) s \<subseteq> f ` (S1 \<times> S2)"
+ − 1107
unfolding f_def S1_def S2_def
275
+ − 1108
unfolding LV_def image_def prefix_def suffix_def
+ − 1109
apply (auto elim!: Prf_elims)
+ − 1110
by (metis (mono_tags, lifting) mem_Collect_eq)
273
+ − 1111
ultimately
+ − 1112
show "finite (LV (SEQ r1 r2) s)"
+ − 1113
by (simp add: finite_subset)
+ − 1114
next
+ − 1115
case (STAR r s)
+ − 1116
then show "finite (LV (STAR r) s)" by (simp add: LV_STAR_finite)
+ − 1117
next
274
+ − 1118
case (UPNTIMES r n s)
273
+ − 1119
have "\<And>s. finite (LV r s)" by fact
274
+ − 1120
then show "finite (LV (UPNTIMES r n) s)"
+ − 1121
by (meson LV_STAR_finite LV_UPNTIMES_STAR rev_finite_subset)
+ − 1122
next
+ − 1123
case (FROMNTIMES r n s)
+ − 1124
have "\<And>s. finite (LV r s)" by fact
+ − 1125
then show "finite (LV (FROMNTIMES r n) s)"
276
+ − 1126
by (simp add: LV_FROMNTIMES_6)
+ − 1127
next
+ − 1128
case (NTIMES r n s)
+ − 1129
have "\<And>s. finite (LV r s)" by fact
+ − 1130
then show "finite (LV (NTIMES r n) s)"
+ − 1131
by (metis (no_types, lifting) LV_NTIMES_4 LV_NTIMES_5 LV_STAR_finite finite_Stars_Append finite_Stars_Pow finite_UN_I finite_atMost finite_subset)
+ − 1132
next
+ − 1133
case (NMTIMES r n m s)
+ − 1134
have "\<And>s. finite (LV r s)" by fact
+ − 1135
then show "finite (LV (NMTIMES r n m) s)"
+ − 1136
by (simp add: LV_NMTIMES_6)
273
+ − 1137
qed
+ − 1138
+ − 1139
+ − 1140
+ − 1141
section {* Our POSIX Definition *}
+ − 1142
+ − 1143
inductive
+ − 1144
Posix :: "string \<Rightarrow> rexp \<Rightarrow> val \<Rightarrow> bool" ("_ \<in> _ \<rightarrow> _" [100, 100, 100] 100)
+ − 1145
where
+ − 1146
Posix_ONE: "[] \<in> ONE \<rightarrow> Void"
+ − 1147
| Posix_CHAR: "[c] \<in> (CHAR c) \<rightarrow> (Char c)"
+ − 1148
| Posix_ALT1: "s \<in> r1 \<rightarrow> v \<Longrightarrow> s \<in> (ALT r1 r2) \<rightarrow> (Left v)"
+ − 1149
| Posix_ALT2: "\<lbrakk>s \<in> r2 \<rightarrow> v; s \<notin> L(r1)\<rbrakk> \<Longrightarrow> s \<in> (ALT r1 r2) \<rightarrow> (Right v)"
+ − 1150
| Posix_SEQ: "\<lbrakk>s1 \<in> r1 \<rightarrow> v1; s2 \<in> r2 \<rightarrow> v2;
+ − 1151
\<not>(\<exists>s\<^sub>3 s\<^sub>4. s\<^sub>3 \<noteq> [] \<and> s\<^sub>3 @ s\<^sub>4 = s2 \<and> (s1 @ s\<^sub>3) \<in> L r1 \<and> s\<^sub>4 \<in> L r2)\<rbrakk> \<Longrightarrow>
+ − 1152
(s1 @ s2) \<in> (SEQ r1 r2) \<rightarrow> (Seq v1 v2)"
+ − 1153
| Posix_STAR1: "\<lbrakk>s1 \<in> r \<rightarrow> v; s2 \<in> STAR r \<rightarrow> Stars vs; flat v \<noteq> [];
+ − 1154
\<not>(\<exists>s\<^sub>3 s\<^sub>4. s\<^sub>3 \<noteq> [] \<and> s\<^sub>3 @ s\<^sub>4 = s2 \<and> (s1 @ s\<^sub>3) \<in> L r \<and> s\<^sub>4 \<in> L (STAR r))\<rbrakk>
+ − 1155
\<Longrightarrow> (s1 @ s2) \<in> STAR r \<rightarrow> Stars (v # vs)"
+ − 1156
| Posix_STAR2: "[] \<in> STAR r \<rightarrow> Stars []"
276
+ − 1157
| Posix_NTIMES1: "\<lbrakk>s1 \<in> r \<rightarrow> v; s2 \<in> NTIMES r (n - 1) \<rightarrow> Stars vs; flat v \<noteq> []; 0 < n;
+ − 1158
\<not>(\<exists>s\<^sub>3 s\<^sub>4. s\<^sub>3 \<noteq> [] \<and> s\<^sub>3 @ s\<^sub>4 = s2 \<and> (s1 @ s\<^sub>3) \<in> L r \<and> s\<^sub>4 \<in> L (NTIMES r (n - 1)))\<rbrakk>
+ − 1159
\<Longrightarrow> (s1 @ s2) \<in> NTIMES r n \<rightarrow> Stars (v # vs)"
+ − 1160
| Posix_NTIMES2: "\<lbrakk>\<forall>v \<in> set vs. [] \<in> r \<rightarrow> v; length vs = n\<rbrakk>
+ − 1161
\<Longrightarrow> [] \<in> NTIMES r n \<rightarrow> Stars vs"
+ − 1162
| Posix_UPNTIMES1: "\<lbrakk>s1 \<in> r \<rightarrow> v; s2 \<in> UPNTIMES r (n - 1) \<rightarrow> Stars vs; flat v \<noteq> []; 0 < n;
+ − 1163
\<not>(\<exists>s\<^sub>3 s\<^sub>4. s\<^sub>3 \<noteq> [] \<and> s\<^sub>3 @ s\<^sub>4 = s2 \<and> (s1 @ s\<^sub>3) \<in> L r \<and> s\<^sub>4 \<in> L (UPNTIMES r (n - 1)))\<rbrakk>
+ − 1164
\<Longrightarrow> (s1 @ s2) \<in> UPNTIMES r n \<rightarrow> Stars (v # vs)"
+ − 1165
| Posix_UPNTIMES2: "[] \<in> UPNTIMES r n \<rightarrow> Stars []"
+ − 1166
| Posix_FROMNTIMES2: "\<lbrakk>\<forall>v \<in> set vs. [] \<in> r \<rightarrow> v; length vs = n\<rbrakk>
+ − 1167
\<Longrightarrow> [] \<in> FROMNTIMES r n \<rightarrow> Stars vs"
+ − 1168
| Posix_FROMNTIMES1: "\<lbrakk>s1 \<in> r \<rightarrow> v; s2 \<in> FROMNTIMES r (n - 1) \<rightarrow> Stars vs; flat v \<noteq> []; 0 < n;
+ − 1169
\<not>(\<exists>s\<^sub>3 s\<^sub>4. s\<^sub>3 \<noteq> [] \<and> s\<^sub>3 @ s\<^sub>4 = s2 \<and> (s1 @ s\<^sub>3) \<in> L r \<and> s\<^sub>4 \<in> L (FROMNTIMES r (n - 1)))\<rbrakk>
+ − 1170
\<Longrightarrow> (s1 @ s2) \<in> FROMNTIMES r n \<rightarrow> Stars (v # vs)"
277
+ − 1171
| Posix_FROMNTIMES3: "\<lbrakk>s1 \<in> r \<rightarrow> v; s2 \<in> STAR r \<rightarrow> Stars vs; flat v \<noteq> [];
+ − 1172
\<not>(\<exists>s\<^sub>3 s\<^sub>4. s\<^sub>3 \<noteq> [] \<and> s\<^sub>3 @ s\<^sub>4 = s2 \<and> (s1 @ s\<^sub>3) \<in> L r \<and> s\<^sub>4 \<in> L (STAR r))\<rbrakk>
+ − 1173
\<Longrightarrow> (s1 @ s2) \<in> FROMNTIMES r 0 \<rightarrow> Stars (v # vs)"
276
+ − 1174
| Posix_NMTIMES2: "\<lbrakk>\<forall>v \<in> set vs. [] \<in> r \<rightarrow> v; length vs = n; n \<le> m\<rbrakk>
+ − 1175
\<Longrightarrow> [] \<in> NMTIMES r n m \<rightarrow> Stars vs"
+ − 1176
| Posix_NMTIMES1: "\<lbrakk>s1 \<in> r \<rightarrow> v; s2 \<in> NMTIMES r n m \<rightarrow> Stars vs; flat v \<noteq> []; n \<le> m;
+ − 1177
\<not>(\<exists>s\<^sub>3 s\<^sub>4. s\<^sub>3 \<noteq> [] \<and> s\<^sub>3 @ s\<^sub>4 = s2 \<and> (s1 @ s\<^sub>3) \<in> L r \<and> s\<^sub>4 \<in> L (NMTIMES r n m))\<rbrakk>
+ − 1178
\<Longrightarrow> (s1 @ s2) \<in> NMTIMES r (Suc n) (Suc m) \<rightarrow> Stars (v # vs)"
+ − 1179
273
+ − 1180
inductive_cases Posix_elims:
+ − 1181
"s \<in> ZERO \<rightarrow> v"
+ − 1182
"s \<in> ONE \<rightarrow> v"
+ − 1183
"s \<in> CHAR c \<rightarrow> v"
+ − 1184
"s \<in> ALT r1 r2 \<rightarrow> v"
+ − 1185
"s \<in> SEQ r1 r2 \<rightarrow> v"
+ − 1186
"s \<in> STAR r \<rightarrow> v"
276
+ − 1187
"s \<in> NTIMES r n \<rightarrow> v"
+ − 1188
"s \<in> UPNTIMES r n \<rightarrow> v"
+ − 1189
"s \<in> FROMNTIMES r n \<rightarrow> v"
+ − 1190
"s \<in> NMTIMES r n m \<rightarrow> v"
+ − 1191
273
+ − 1192
lemma Posix1:
+ − 1193
assumes "s \<in> r \<rightarrow> v"
+ − 1194
shows "s \<in> L r" "flat v = s"
+ − 1195
using assms
276
+ − 1196
apply(induct s r v rule: Posix.induct)
+ − 1197
apply(auto simp add: Sequ_def)[18]
+ − 1198
apply(case_tac n)
+ − 1199
apply(simp)
+ − 1200
apply(simp add: Sequ_def)
+ − 1201
apply(auto)[1]
+ − 1202
apply(simp)
+ − 1203
apply(clarify)
+ − 1204
apply(rule_tac x="Suc x" in bexI)
+ − 1205
apply(simp add: Sequ_def)
+ − 1206
apply(auto)[5]
+ − 1207
using nth_mem nullable.simps(9) nullable_correctness apply auto[1]
+ − 1208
apply simp
+ − 1209
apply(simp)
+ − 1210
apply(clarify)
+ − 1211
apply(rule_tac x="Suc x" in bexI)
+ − 1212
apply(simp add: Sequ_def)
+ − 1213
apply(auto)[3]
277
+ − 1214
defer
276
+ − 1215
apply(simp)
+ − 1216
apply fastforce
+ − 1217
apply(simp)
+ − 1218
apply(simp)
+ − 1219
apply(clarify)
+ − 1220
apply(rule_tac x="Suc x" in bexI)
+ − 1221
apply(auto simp add: Sequ_def)[2]
+ − 1222
apply(simp)
277
+ − 1223
apply(simp)
+ − 1224
by (simp add: Star.step Star_Pow)
276
+ − 1225
273
+ − 1226
text {*
+ − 1227
Our Posix definition determines a unique value.
+ − 1228
*}
276
+ − 1229
+ − 1230
lemma List_eq_zipI:
+ − 1231
assumes "\<forall>(v1, v2) \<in> set (zip vs1 vs2). v1 = v2"
+ − 1232
and "length vs1 = length vs2"
+ − 1233
shows "vs1 = vs2"
+ − 1234
using assms
+ − 1235
apply(induct vs1 arbitrary: vs2)
+ − 1236
apply(case_tac vs2)
+ − 1237
apply(simp)
+ − 1238
apply(simp)
+ − 1239
apply(case_tac vs2)
+ − 1240
apply(simp)
+ − 1241
apply(simp)
+ − 1242
done
273
+ − 1243
+ − 1244
lemma Posix_determ:
+ − 1245
assumes "s \<in> r \<rightarrow> v1" "s \<in> r \<rightarrow> v2"
+ − 1246
shows "v1 = v2"
+ − 1247
using assms
+ − 1248
proof (induct s r v1 arbitrary: v2 rule: Posix.induct)
+ − 1249
case (Posix_ONE v2)
+ − 1250
have "[] \<in> ONE \<rightarrow> v2" by fact
+ − 1251
then show "Void = v2" by cases auto
+ − 1252
next
+ − 1253
case (Posix_CHAR c v2)
+ − 1254
have "[c] \<in> CHAR c \<rightarrow> v2" by fact
+ − 1255
then show "Char c = v2" by cases auto
+ − 1256
next
+ − 1257
case (Posix_ALT1 s r1 v r2 v2)
+ − 1258
have "s \<in> ALT r1 r2 \<rightarrow> v2" by fact
+ − 1259
moreover
+ − 1260
have "s \<in> r1 \<rightarrow> v" by fact
+ − 1261
then have "s \<in> L r1" by (simp add: Posix1)
+ − 1262
ultimately obtain v' where eq: "v2 = Left v'" "s \<in> r1 \<rightarrow> v'" by cases auto
+ − 1263
moreover
+ − 1264
have IH: "\<And>v2. s \<in> r1 \<rightarrow> v2 \<Longrightarrow> v = v2" by fact
+ − 1265
ultimately have "v = v'" by simp
+ − 1266
then show "Left v = v2" using eq by simp
+ − 1267
next
+ − 1268
case (Posix_ALT2 s r2 v r1 v2)
+ − 1269
have "s \<in> ALT r1 r2 \<rightarrow> v2" by fact
+ − 1270
moreover
+ − 1271
have "s \<notin> L r1" by fact
+ − 1272
ultimately obtain v' where eq: "v2 = Right v'" "s \<in> r2 \<rightarrow> v'"
+ − 1273
by cases (auto simp add: Posix1)
+ − 1274
moreover
+ − 1275
have IH: "\<And>v2. s \<in> r2 \<rightarrow> v2 \<Longrightarrow> v = v2" by fact
+ − 1276
ultimately have "v = v'" by simp
+ − 1277
then show "Right v = v2" using eq by simp
+ − 1278
next
+ − 1279
case (Posix_SEQ s1 r1 v1 s2 r2 v2 v')
+ − 1280
have "(s1 @ s2) \<in> SEQ r1 r2 \<rightarrow> v'"
+ − 1281
"s1 \<in> r1 \<rightarrow> v1" "s2 \<in> r2 \<rightarrow> v2"
+ − 1282
"\<not> (\<exists>s\<^sub>3 s\<^sub>4. s\<^sub>3 \<noteq> [] \<and> s\<^sub>3 @ s\<^sub>4 = s2 \<and> s1 @ s\<^sub>3 \<in> L r1 \<and> s\<^sub>4 \<in> L r2)" by fact+
+ − 1283
then obtain v1' v2' where "v' = Seq v1' v2'" "s1 \<in> r1 \<rightarrow> v1'" "s2 \<in> r2 \<rightarrow> v2'"
+ − 1284
apply(cases) apply (auto simp add: append_eq_append_conv2)
+ − 1285
using Posix1(1) by fastforce+
+ − 1286
moreover
+ − 1287
have IHs: "\<And>v1'. s1 \<in> r1 \<rightarrow> v1' \<Longrightarrow> v1 = v1'"
+ − 1288
"\<And>v2'. s2 \<in> r2 \<rightarrow> v2' \<Longrightarrow> v2 = v2'" by fact+
+ − 1289
ultimately show "Seq v1 v2 = v'" by simp
+ − 1290
next
+ − 1291
case (Posix_STAR1 s1 r v s2 vs v2)
+ − 1292
have "(s1 @ s2) \<in> STAR r \<rightarrow> v2"
+ − 1293
"s1 \<in> r \<rightarrow> v" "s2 \<in> STAR r \<rightarrow> Stars vs" "flat v \<noteq> []"
+ − 1294
"\<not> (\<exists>s\<^sub>3 s\<^sub>4. s\<^sub>3 \<noteq> [] \<and> s\<^sub>3 @ s\<^sub>4 = s2 \<and> s1 @ s\<^sub>3 \<in> L r \<and> s\<^sub>4 \<in> L (STAR r))" by fact+
+ − 1295
then obtain v' vs' where "v2 = Stars (v' # vs')" "s1 \<in> r \<rightarrow> v'" "s2 \<in> (STAR r) \<rightarrow> (Stars vs')"
+ − 1296
apply(cases) apply (auto simp add: append_eq_append_conv2)
+ − 1297
using Posix1(1) apply fastforce
+ − 1298
apply (metis Posix1(1) Posix_STAR1.hyps(6) append_Nil append_Nil2)
+ − 1299
using Posix1(2) by blast
+ − 1300
moreover
+ − 1301
have IHs: "\<And>v2. s1 \<in> r \<rightarrow> v2 \<Longrightarrow> v = v2"
+ − 1302
"\<And>v2. s2 \<in> STAR r \<rightarrow> v2 \<Longrightarrow> Stars vs = v2" by fact+
+ − 1303
ultimately show "Stars (v # vs) = v2" by auto
+ − 1304
next
+ − 1305
case (Posix_STAR2 r v2)
+ − 1306
have "[] \<in> STAR r \<rightarrow> v2" by fact
+ − 1307
then show "Stars [] = v2" by cases (auto simp add: Posix1)
276
+ − 1308
next
+ − 1309
case (Posix_NTIMES2 vs r n v2)
+ − 1310
then show "Stars vs = v2"
+ − 1311
apply(erule_tac Posix_elims)
+ − 1312
apply(auto)
+ − 1313
apply (simp add: Posix1(2))
+ − 1314
apply(rule List_eq_zipI)
+ − 1315
apply(auto)
+ − 1316
by (meson in_set_zipE)
+ − 1317
next
+ − 1318
case (Posix_NTIMES1 s1 r v s2 n vs v2)
+ − 1319
have "(s1 @ s2) \<in> NTIMES r n \<rightarrow> v2"
+ − 1320
"s1 \<in> r \<rightarrow> v" "s2 \<in> NTIMES r (n - 1) \<rightarrow> Stars vs" "flat v \<noteq> []"
+ − 1321
"\<not> (\<exists>s\<^sub>3 s\<^sub>4. s\<^sub>3 \<noteq> [] \<and> s\<^sub>3 @ s\<^sub>4 = s2 \<and> s1 @ s\<^sub>3 \<in> L r \<and> s\<^sub>4 \<in> L (NTIMES r (n - 1 )))" by fact+
+ − 1322
then obtain v' vs' where "v2 = Stars (v' # vs')" "s1 \<in> r \<rightarrow> v'" "s2 \<in> (NTIMES r (n - 1)) \<rightarrow> (Stars vs')"
+ − 1323
apply(cases) apply (auto simp add: append_eq_append_conv2)
+ − 1324
using Posix1(1) apply fastforce
+ − 1325
apply (metis One_nat_def Posix1(1) Posix_NTIMES1.hyps(7) append.right_neutral append_self_conv2)
+ − 1326
using Posix1(2) by blast
+ − 1327
moreover
+ − 1328
have IHs: "\<And>v2. s1 \<in> r \<rightarrow> v2 \<Longrightarrow> v = v2"
+ − 1329
"\<And>v2. s2 \<in> NTIMES r (n - 1) \<rightarrow> v2 \<Longrightarrow> Stars vs = v2" by fact+
+ − 1330
ultimately show "Stars (v # vs) = v2" by auto
+ − 1331
next
+ − 1332
case (Posix_UPNTIMES1 s1 r v s2 n vs v2)
+ − 1333
have "(s1 @ s2) \<in> UPNTIMES r n \<rightarrow> v2"
+ − 1334
"s1 \<in> r \<rightarrow> v" "s2 \<in> UPNTIMES r (n - 1) \<rightarrow> Stars vs" "flat v \<noteq> []"
+ − 1335
"\<not> (\<exists>s\<^sub>3 s\<^sub>4. s\<^sub>3 \<noteq> [] \<and> s\<^sub>3 @ s\<^sub>4 = s2 \<and> s1 @ s\<^sub>3 \<in> L r \<and> s\<^sub>4 \<in> L (UPNTIMES r (n - 1 )))" by fact+
+ − 1336
then obtain v' vs' where "v2 = Stars (v' # vs')" "s1 \<in> r \<rightarrow> v'" "s2 \<in> (UPNTIMES r (n - 1)) \<rightarrow> (Stars vs')"
+ − 1337
apply(cases) apply (auto simp add: append_eq_append_conv2)
+ − 1338
using Posix1(1) apply fastforce
+ − 1339
apply (metis One_nat_def Posix1(1) Posix_UPNTIMES1.hyps(7) append.right_neutral append_self_conv2)
+ − 1340
using Posix1(2) by blast
+ − 1341
moreover
+ − 1342
have IHs: "\<And>v2. s1 \<in> r \<rightarrow> v2 \<Longrightarrow> v = v2"
+ − 1343
"\<And>v2. s2 \<in> UPNTIMES r (n - 1) \<rightarrow> v2 \<Longrightarrow> Stars vs = v2" by fact+
+ − 1344
ultimately show "Stars (v # vs) = v2" by auto
+ − 1345
next
+ − 1346
case (Posix_UPNTIMES2 r n v2)
+ − 1347
then show "Stars [] = v2"
+ − 1348
apply(erule_tac Posix_elims)
+ − 1349
apply(auto)
+ − 1350
by (simp add: Posix1(2))
+ − 1351
next
+ − 1352
case (Posix_FROMNTIMES1 s1 r v s2 n vs v2)
+ − 1353
have "(s1 @ s2) \<in> FROMNTIMES r n \<rightarrow> v2"
277
+ − 1354
"s1 \<in> r \<rightarrow> v" "s2 \<in> FROMNTIMES r (n - 1) \<rightarrow> Stars vs" "flat v \<noteq> []" "0 < n"
276
+ − 1355
"\<not> (\<exists>s\<^sub>3 s\<^sub>4. s\<^sub>3 \<noteq> [] \<and> s\<^sub>3 @ s\<^sub>4 = s2 \<and> s1 @ s\<^sub>3 \<in> L r \<and> s\<^sub>4 \<in> L (FROMNTIMES r (n - 1 )))" by fact+
+ − 1356
then obtain v' vs' where "v2 = Stars (v' # vs')" "s1 \<in> r \<rightarrow> v'" "s2 \<in> (FROMNTIMES r (n - 1)) \<rightarrow> (Stars vs')"
+ − 1357
apply(cases) apply (auto simp add: append_eq_append_conv2)
+ − 1358
using Posix1(1) Posix1(2) apply blast
+ − 1359
apply(case_tac n)
+ − 1360
apply(simp)
277
+ − 1361
apply(simp)
+ − 1362
apply(drule_tac x="va" in meta_spec)
+ − 1363
apply(drule_tac x="vs" in meta_spec)
+ − 1364
apply(simp)
+ − 1365
apply(drule meta_mp)
+ − 1366
apply (metis L.simps(9) Posix1(1) UN_E append.right_neutral append_Nil diff_Suc_1 local.Posix_FROMNTIMES1(4) val.inject(5))
+ − 1367
apply (metis L.simps(9) Posix1(1) UN_E append.right_neutral append_Nil)
+ − 1368
by (metis One_nat_def Posix1(1) Posix_FROMNTIMES1.hyps(7) self_append_conv self_append_conv2)
276
+ − 1369
moreover
+ − 1370
have IHs: "\<And>v2. s1 \<in> r \<rightarrow> v2 \<Longrightarrow> v = v2"
+ − 1371
"\<And>v2. s2 \<in> FROMNTIMES r (n - 1) \<rightarrow> v2 \<Longrightarrow> Stars vs = v2" by fact+
+ − 1372
ultimately show "Stars (v # vs) = v2" by auto
+ − 1373
next
+ − 1374
case (Posix_FROMNTIMES2 vs r n v2)
+ − 1375
then show "Stars vs = v2"
+ − 1376
apply(erule_tac Posix_elims)
+ − 1377
apply(auto)
+ − 1378
apply(rule List_eq_zipI)
+ − 1379
apply(auto)
277
+ − 1380
apply(meson in_set_zipE)
+ − 1381
apply (simp add: Posix1(2))
+ − 1382
using Posix1(2) by blast
276
+ − 1383
next
277
+ − 1384
case (Posix_FROMNTIMES3 s1 r v s2 vs v2)
+ − 1385
have "(s1 @ s2) \<in> FROMNTIMES r 0 \<rightarrow> v2"
+ − 1386
"s1 \<in> r \<rightarrow> v" "s2 \<in> STAR r \<rightarrow> Stars vs" "flat v \<noteq> []"
+ − 1387
"\<not> (\<exists>s\<^sub>3 s\<^sub>4. s\<^sub>3 \<noteq> [] \<and> s\<^sub>3 @ s\<^sub>4 = s2 \<and> s1 @ s\<^sub>3 \<in> L r \<and> s\<^sub>4 \<in> L (STAR r))" by fact+
+ − 1388
then obtain v' vs' where "v2 = Stars (v' # vs')" "s1 \<in> r \<rightarrow> v'" "s2 \<in> (STAR r) \<rightarrow> (Stars vs')"
+ − 1389
apply(cases) apply (auto simp add: append_eq_append_conv2)
+ − 1390
using Posix1(2) apply fastforce
+ − 1391
using Posix1(1) apply fastforce
+ − 1392
by (metis Posix1(1) Posix_FROMNTIMES3.hyps(6) append.right_neutral append_Nil)
+ − 1393
moreover
+ − 1394
have IHs: "\<And>v2. s1 \<in> r \<rightarrow> v2 \<Longrightarrow> v = v2"
+ − 1395
"\<And>v2. s2 \<in> STAR r \<rightarrow> v2 \<Longrightarrow> Stars vs = v2" by fact+
+ − 1396
ultimately show "Stars (v # vs) = v2" by auto
+ − 1397
next
276
+ − 1398
case (Posix_NMTIMES1 s1 r v s2 n m vs v2)
+ − 1399
then show "Stars (v # vs) = v2"
+ − 1400
sorry
+ − 1401
next
+ − 1402
case (Posix_NMTIMES2 vs r n m v2)
+ − 1403
then show "Stars vs = v2"
+ − 1404
sorry
273
+ − 1405
qed
+ − 1406
+ − 1407
+ − 1408
text {*
+ − 1409
Our POSIX value is a lexical value.
+ − 1410
*}
+ − 1411
+ − 1412
lemma Posix_LV:
+ − 1413
assumes "s \<in> r \<rightarrow> v"
+ − 1414
shows "v \<in> LV r s"
+ − 1415
using assms unfolding LV_def
+ − 1416
apply(induct rule: Posix.induct)
276
+ − 1417
apply(auto simp add: intro!: Prf.intros elim!: Prf_elims)[7]
+ − 1418
defer
+ − 1419
defer
+ − 1420
apply(auto simp add: intro!: Prf.intros elim!: Prf_elims)[2]
+ − 1421
apply (metis (mono_tags, lifting) Prf.intros(9) append_Nil empty_iff flat_Stars flats_empty list.set(1) mem_Collect_eq)
277
+ − 1422
apply(simp)
+ − 1423
apply(clarify)
+ − 1424
apply(case_tac n)
+ − 1425
apply(simp)
+ − 1426
apply(simp)
+ − 1427
apply(erule Prf_elims)
+ − 1428
apply(simp)
276
+ − 1429
apply(subst append.simps(2)[symmetric])
277
+ − 1430
apply(rule Prf.intros)
+ − 1431
apply(simp)
+ − 1432
apply(simp)
+ − 1433
apply(simp)
+ − 1434
apply(simp)
+ − 1435
apply(rule Prf.intros)
+ − 1436
apply(simp)
+ − 1437
apply(simp)
+ − 1438
apply(simp)
+ − 1439
apply(clarify)
+ − 1440
apply(erule Prf_elims)
+ − 1441
apply(simp)
+ − 1442
apply(rule Prf.intros)
+ − 1443
apply(simp)
+ − 1444
apply(simp)
+ − 1445
(* NMTIMES *)
+ − 1446
sorry
276
+ − 1447
+ − 1448
273
+ − 1449
end