thys2/Spec.thy
author Christian Urban <christian.urban@kcl.ac.uk>
Tue, 22 Mar 2022 11:14:02 +0000
changeset 462 d9b672c4c0ac
parent 365 ec5e4fe4cc70
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
     1
   
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
     2
theory Spec
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
     3
  imports RegLangs
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
     4
begin
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
     5
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
     6
section \<open>"Plain" Values\<close>
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
     7
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
     8
datatype val = 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
     9
  Void
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    10
| Char char
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    11
| Seq val val
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    12
| Right val
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    13
| Left val
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    14
| Stars "val list"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    15
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    16
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    17
section \<open>The string behind a value\<close>
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    18
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    19
fun 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    20
  flat :: "val \<Rightarrow> string"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    21
where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    22
  "flat (Void) = []"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    23
| "flat (Char c) = [c]"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    24
| "flat (Left v) = flat v"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    25
| "flat (Right v) = flat v"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    26
| "flat (Seq v1 v2) = (flat v1) @ (flat v2)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    27
| "flat (Stars []) = []"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    28
| "flat (Stars (v#vs)) = (flat v) @ (flat (Stars vs))" 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    29
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    30
abbreviation
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    31
  "flats vs \<equiv> concat (map flat vs)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    32
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    33
lemma flat_Stars [simp]:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    34
 "flat (Stars vs) = flats vs"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    35
by (induct vs) (auto)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    36
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    37
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    38
section \<open>Lexical Values\<close>
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    39
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    40
inductive 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    41
  Prf :: "val \<Rightarrow> rexp \<Rightarrow> bool" ("\<Turnstile> _ : _" [100, 100] 100)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    42
where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    43
 "\<lbrakk>\<Turnstile> v1 : r1; \<Turnstile> v2 : r2\<rbrakk> \<Longrightarrow> \<Turnstile>  Seq v1 v2 : SEQ r1 r2"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    44
| "\<Turnstile> v1 : r1 \<Longrightarrow> \<Turnstile> Left v1 : ALT r1 r2"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    45
| "\<Turnstile> v2 : r2 \<Longrightarrow> \<Turnstile> Right v2 : ALT r1 r2"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    46
| "\<Turnstile> Void : ONE"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    47
| "\<Turnstile> Char c : CH c"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    48
| "\<forall>v \<in> set vs. \<Turnstile> v : r \<and> flat v \<noteq> [] \<Longrightarrow> \<Turnstile> Stars vs : STAR r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    49
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    50
inductive_cases Prf_elims:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    51
  "\<Turnstile> v : ZERO"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    52
  "\<Turnstile> v : SEQ r1 r2"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    53
  "\<Turnstile> v : ALT r1 r2"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    54
  "\<Turnstile> v : ONE"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    55
  "\<Turnstile> v : CH c"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    56
  "\<Turnstile> vs : STAR r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    57
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    58
lemma Prf_Stars_appendE:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    59
  assumes "\<Turnstile> Stars (vs1 @ vs2) : STAR r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    60
  shows "\<Turnstile> Stars vs1 : STAR r \<and> \<Turnstile> Stars vs2 : STAR r" 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    61
using assms
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    62
by (auto intro: Prf.intros elim!: Prf_elims)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    63
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    64
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    65
lemma flats_Prf_value:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    66
  assumes "\<forall>s\<in>set ss. \<exists>v. s = flat v \<and> \<Turnstile> v : r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    67
  shows "\<exists>vs. flats vs = concat ss \<and> (\<forall>v\<in>set vs. \<Turnstile> v : r \<and> flat v \<noteq> [])"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    68
using assms
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    69
apply(induct ss)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    70
apply(auto)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    71
apply(rule_tac x="[]" in exI)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    72
apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    73
apply(case_tac "flat v = []")
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    74
apply(rule_tac x="vs" in exI)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    75
apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    76
apply(rule_tac x="v#vs" in exI)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    77
apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    78
done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    79
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    80
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    81
lemma L_flat_Prf1:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    82
  assumes "\<Turnstile> v : r" 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    83
  shows "flat v \<in> L r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    84
using assms
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    85
by (induct) (auto simp add: Sequ_def Star_concat)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    86
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    87
lemma L_flat_Prf2:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    88
  assumes "s \<in> L r" 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    89
  shows "\<exists>v. \<Turnstile> v : r \<and> flat v = s"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    90
using assms
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    91
proof(induct r arbitrary: s)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    92
  case (STAR r s)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    93
  have IH: "\<And>s. s \<in> L r \<Longrightarrow> \<exists>v. \<Turnstile> v : r \<and> flat v = s" by fact
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    94
  have "s \<in> L (STAR r)" by fact
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    95
  then obtain ss where "concat ss = s" "\<forall>s \<in> set ss. s \<in> L r \<and> s \<noteq> []"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    96
  using Star_split by auto  
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    97
  then obtain vs where "flats vs = s" "\<forall>v\<in>set vs. \<Turnstile> v : r \<and> flat v \<noteq> []"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    98
  using IH flats_Prf_value by metis 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    99
  then show "\<exists>v. \<Turnstile> v : STAR r \<and> flat v = s"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   100
  using Prf.intros(6) flat_Stars by blast
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   101
next 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   102
  case (SEQ r1 r2 s)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   103
  then show "\<exists>v. \<Turnstile> v : SEQ r1 r2 \<and> flat v = s"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   104
  unfolding Sequ_def L.simps by (fastforce intro: Prf.intros)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   105
next
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   106
  case (ALT r1 r2 s)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   107
  then show "\<exists>v. \<Turnstile> v : ALT r1 r2 \<and> flat v = s"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   108
  unfolding L.simps by (fastforce intro: Prf.intros)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   109
qed (auto intro: Prf.intros)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   110
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   111
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   112
lemma L_flat_Prf:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   113
  shows "L(r) = {flat v | v. \<Turnstile> v : r}"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   114
using L_flat_Prf1 L_flat_Prf2 by blast
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   115
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   116
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   117
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   118
section \<open>Sets of Lexical Values\<close>
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   119
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   120
text \<open>
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   121
  Shows that lexical values are finite for a given regex and string.
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   122
\<close>
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   123
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   124
definition
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   125
  LV :: "rexp \<Rightarrow> string \<Rightarrow> val set"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   126
where  "LV r s \<equiv> {v. \<Turnstile> v : r \<and> flat v = s}"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   127
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   128
lemma LV_simps:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   129
  shows "LV ZERO s = {}"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   130
  and   "LV ONE s = (if s = [] then {Void} else {})"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   131
  and   "LV (CH c) s = (if s = [c] then {Char c} else {})"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   132
  and   "LV (ALT r1 r2) s = Left ` LV r1 s \<union> Right ` LV r2 s"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   133
unfolding LV_def
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   134
by (auto intro: Prf.intros elim: Prf.cases)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   135
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   136
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   137
abbreviation
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   138
  "Prefixes s \<equiv> {s'. prefix s' s}"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   139
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   140
abbreviation
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   141
  "Suffixes s \<equiv> {s'. suffix s' s}"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   142
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   143
abbreviation
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   144
  "SSuffixes s \<equiv> {s'. strict_suffix s' s}"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   145
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   146
lemma Suffixes_cons [simp]:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   147
  shows "Suffixes (c # s) = Suffixes s \<union> {c # s}"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   148
by (auto simp add: suffix_def Cons_eq_append_conv)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   149
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   150
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   151
lemma finite_Suffixes: 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   152
  shows "finite (Suffixes s)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   153
by (induct s) (simp_all)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   154
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   155
lemma finite_SSuffixes: 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   156
  shows "finite (SSuffixes s)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   157
proof -
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   158
  have "SSuffixes s \<subseteq> Suffixes s"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   159
   unfolding strict_suffix_def suffix_def by auto
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   160
  then show "finite (SSuffixes s)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   161
   using finite_Suffixes finite_subset by blast
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   162
qed
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   163
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   164
lemma finite_Prefixes: 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   165
  shows "finite (Prefixes s)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   166
proof -
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   167
  have "finite (Suffixes (rev s))" 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   168
    by (rule finite_Suffixes)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   169
  then have "finite (rev ` Suffixes (rev s))" by simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   170
  moreover
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   171
  have "rev ` (Suffixes (rev s)) = Prefixes s"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   172
  unfolding suffix_def prefix_def image_def
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   173
   by (auto)(metis rev_append rev_rev_ident)+
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   174
  ultimately show "finite (Prefixes s)" by simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   175
qed
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   176
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   177
lemma LV_STAR_finite:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   178
  assumes "\<forall>s. finite (LV r s)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   179
  shows "finite (LV (STAR r) s)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   180
proof(induct s rule: length_induct)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   181
  fix s::"char list"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   182
  assume "\<forall>s'. length s' < length s \<longrightarrow> finite (LV (STAR r) s')"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   183
  then have IH: "\<forall>s' \<in> SSuffixes s. finite (LV (STAR r) s')"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   184
    by (force simp add: strict_suffix_def suffix_def) 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   185
  define f where "f \<equiv> \<lambda>(v, vs). Stars (v # vs)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   186
  define S1 where "S1 \<equiv> \<Union>s' \<in> Prefixes s. LV r s'"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   187
  define S2 where "S2 \<equiv> \<Union>s2 \<in> SSuffixes s. Stars -` (LV (STAR r) s2)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   188
  have "finite S1" using assms
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   189
    unfolding S1_def by (simp_all add: finite_Prefixes)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   190
  moreover 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   191
  with IH have "finite S2" unfolding S2_def
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   192
    by (auto simp add: finite_SSuffixes inj_on_def finite_vimageI)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   193
  ultimately 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   194
  have "finite ({Stars []} \<union> f ` (S1 \<times> S2))" by simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   195
  moreover 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   196
  have "LV (STAR r) s \<subseteq> {Stars []} \<union> f ` (S1 \<times> S2)" 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   197
  unfolding S1_def S2_def f_def
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   198
  unfolding LV_def image_def prefix_def strict_suffix_def 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   199
  apply(auto)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   200
  apply(case_tac x)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   201
  apply(auto elim: Prf_elims)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   202
  apply(erule Prf_elims)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   203
  apply(auto)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   204
  apply(case_tac vs)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   205
  apply(auto intro: Prf.intros)  
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   206
  apply(rule exI)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   207
  apply(rule conjI)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   208
  apply(rule_tac x="flat a" in exI)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   209
  apply(rule conjI)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   210
  apply(rule_tac x="flats list" in exI)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   211
  apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   212
   apply(blast)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   213
  apply(simp add: suffix_def)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   214
  using Prf.intros(6) by blast  
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   215
  ultimately
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   216
  show "finite (LV (STAR r) s)" by (simp add: finite_subset)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   217
qed  
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   218
    
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   219
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   220
lemma LV_finite:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   221
  shows "finite (LV r s)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   222
proof(induct r arbitrary: s)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   223
  case (ZERO s) 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   224
  show "finite (LV ZERO s)" by (simp add: LV_simps)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   225
next
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   226
  case (ONE s)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   227
  show "finite (LV ONE s)" by (simp add: LV_simps)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   228
next
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   229
  case (CH c s)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   230
  show "finite (LV (CH c) s)" by (simp add: LV_simps)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   231
next 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   232
  case (ALT r1 r2 s)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   233
  then show "finite (LV (ALT r1 r2) s)" by (simp add: LV_simps)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   234
next 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   235
  case (SEQ r1 r2 s)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   236
  define f where "f \<equiv> \<lambda>(v1, v2). Seq v1 v2"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   237
  define S1 where "S1 \<equiv> \<Union>s' \<in> Prefixes s. LV r1 s'"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   238
  define S2 where "S2 \<equiv> \<Union>s' \<in> Suffixes s. LV r2 s'"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   239
  have IHs: "\<And>s. finite (LV r1 s)" "\<And>s. finite (LV r2 s)" by fact+
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   240
  then have "finite S1" "finite S2" unfolding S1_def S2_def
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   241
    by (simp_all add: finite_Prefixes finite_Suffixes)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   242
  moreover
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   243
  have "LV (SEQ r1 r2) s \<subseteq> f ` (S1 \<times> S2)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   244
    unfolding f_def S1_def S2_def 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   245
    unfolding LV_def image_def prefix_def suffix_def
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   246
    apply (auto elim!: Prf_elims)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   247
    by (metis (mono_tags, lifting) mem_Collect_eq)  
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   248
  ultimately 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   249
  show "finite (LV (SEQ r1 r2) s)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   250
    by (simp add: finite_subset)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   251
next
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   252
  case (STAR r s)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   253
  then show "finite (LV (STAR r) s)" by (simp add: LV_STAR_finite)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   254
qed
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   255
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   256
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   257
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   258
section \<open>Our inductive POSIX Definition\<close>
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   259
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   260
inductive 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   261
  Posix :: "string \<Rightarrow> rexp \<Rightarrow> val \<Rightarrow> bool" ("_ \<in> _ \<rightarrow> _" [100, 100, 100] 100)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   262
where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   263
  Posix_ONE: "[] \<in> ONE \<rightarrow> Void"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   264
| Posix_CH: "[c] \<in> (CH c) \<rightarrow> (Char c)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   265
| Posix_ALT1: "s \<in> r1 \<rightarrow> v \<Longrightarrow> s \<in> (ALT r1 r2) \<rightarrow> (Left v)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   266
| Posix_ALT2: "\<lbrakk>s \<in> r2 \<rightarrow> v; s \<notin> L(r1)\<rbrakk> \<Longrightarrow> s \<in> (ALT r1 r2) \<rightarrow> (Right v)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   267
| Posix_SEQ: "\<lbrakk>s1 \<in> r1 \<rightarrow> v1; s2 \<in> r2 \<rightarrow> v2;
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   268
    \<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> 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   269
    (s1 @ s2) \<in> (SEQ r1 r2) \<rightarrow> (Seq v1 v2)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   270
| Posix_STAR1: "\<lbrakk>s1 \<in> r \<rightarrow> v; s2 \<in> STAR r \<rightarrow> Stars vs; flat v \<noteq> [];
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   271
    \<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>
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   272
    \<Longrightarrow> (s1 @ s2) \<in> STAR r \<rightarrow> Stars (v # vs)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   273
| Posix_STAR2: "[] \<in> STAR r \<rightarrow> Stars []"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   274
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   275
inductive_cases Posix_elims:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   276
  "s \<in> ZERO \<rightarrow> v"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   277
  "s \<in> ONE \<rightarrow> v"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   278
  "s \<in> CH c \<rightarrow> v"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   279
  "s \<in> ALT r1 r2 \<rightarrow> v"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   280
  "s \<in> SEQ r1 r2 \<rightarrow> v"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   281
  "s \<in> STAR r \<rightarrow> v"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   282
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   283
lemma Posix1:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   284
  assumes "s \<in> r \<rightarrow> v"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   285
  shows "s \<in> L r" "flat v = s"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   286
using assms
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   287
  by(induct s r v rule: Posix.induct)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   288
    (auto simp add: Sequ_def)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   289
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   290
text \<open>
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   291
  For a give value and string, our Posix definition 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   292
  determines a unique value.
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   293
\<close>
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   294
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   295
lemma Posix_determ:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   296
  assumes "s \<in> r \<rightarrow> v1" "s \<in> r \<rightarrow> v2"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   297
  shows "v1 = v2"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   298
using assms
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   299
proof (induct s r v1 arbitrary: v2 rule: Posix.induct)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   300
  case (Posix_ONE v2)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   301
  have "[] \<in> ONE \<rightarrow> v2" by fact
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   302
  then show "Void = v2" by cases auto
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   303
next 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   304
  case (Posix_CH c v2)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   305
  have "[c] \<in> CH c \<rightarrow> v2" by fact
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   306
  then show "Char c = v2" by cases auto
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   307
next 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   308
  case (Posix_ALT1 s r1 v r2 v2)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   309
  have "s \<in> ALT r1 r2 \<rightarrow> v2" by fact
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   310
  moreover
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   311
  have "s \<in> r1 \<rightarrow> v" by fact
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   312
  then have "s \<in> L r1" by (simp add: Posix1)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   313
  ultimately obtain v' where eq: "v2 = Left v'" "s \<in> r1 \<rightarrow> v'" by cases auto 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   314
  moreover
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   315
  have IH: "\<And>v2. s \<in> r1 \<rightarrow> v2 \<Longrightarrow> v = v2" by fact
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   316
  ultimately have "v = v'" by simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   317
  then show "Left v = v2" using eq by simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   318
next 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   319
  case (Posix_ALT2 s r2 v r1 v2)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   320
  have "s \<in> ALT r1 r2 \<rightarrow> v2" by fact
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   321
  moreover
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   322
  have "s \<notin> L r1" by fact
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   323
  ultimately obtain v' where eq: "v2 = Right v'" "s \<in> r2 \<rightarrow> v'" 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   324
    by cases (auto simp add: Posix1) 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   325
  moreover
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   326
  have IH: "\<And>v2. s \<in> r2 \<rightarrow> v2 \<Longrightarrow> v = v2" by fact
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   327
  ultimately have "v = v'" by simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   328
  then show "Right v = v2" using eq by simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   329
next
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   330
  case (Posix_SEQ s1 r1 v1 s2 r2 v2 v')
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   331
  have "(s1 @ s2) \<in> SEQ r1 r2 \<rightarrow> v'" 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   332
       "s1 \<in> r1 \<rightarrow> v1" "s2 \<in> r2 \<rightarrow> v2"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   333
       "\<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+
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   334
  then obtain v1' v2' where "v' = Seq v1' v2'" "s1 \<in> r1 \<rightarrow> v1'" "s2 \<in> r2 \<rightarrow> v2'"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   335
  apply(cases) apply (auto simp add: append_eq_append_conv2)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   336
  using Posix1(1) by fastforce+
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   337
  moreover
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   338
  have IHs: "\<And>v1'. s1 \<in> r1 \<rightarrow> v1' \<Longrightarrow> v1 = v1'"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   339
            "\<And>v2'. s2 \<in> r2 \<rightarrow> v2' \<Longrightarrow> v2 = v2'" by fact+
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   340
  ultimately show "Seq v1 v2 = v'" by simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   341
next
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   342
  case (Posix_STAR1 s1 r v s2 vs v2)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   343
  have "(s1 @ s2) \<in> STAR r \<rightarrow> v2" 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   344
       "s1 \<in> r \<rightarrow> v" "s2 \<in> STAR r \<rightarrow> Stars vs" "flat v \<noteq> []"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   345
       "\<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+
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   346
  then obtain v' vs' where "v2 = Stars (v' # vs')" "s1 \<in> r \<rightarrow> v'" "s2 \<in> (STAR r) \<rightarrow> (Stars vs')"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   347
  apply(cases) apply (auto simp add: append_eq_append_conv2)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   348
  using Posix1(1) apply fastforce
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   349
  apply (metis Posix1(1) Posix_STAR1.hyps(6) append_Nil append_Nil2)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   350
  using Posix1(2) by blast
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   351
  moreover
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   352
  have IHs: "\<And>v2. s1 \<in> r \<rightarrow> v2 \<Longrightarrow> v = v2"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   353
            "\<And>v2. s2 \<in> STAR r \<rightarrow> v2 \<Longrightarrow> Stars vs = v2" by fact+
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   354
  ultimately show "Stars (v # vs) = v2" by auto
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   355
next
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   356
  case (Posix_STAR2 r v2)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   357
  have "[] \<in> STAR r \<rightarrow> v2" by fact
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   358
  then show "Stars [] = v2" by cases (auto simp add: Posix1)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   359
qed
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   360
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   361
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   362
text \<open>
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   363
  Our POSIX values are lexical values.
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   364
\<close>
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   366
lemma Posix_LV:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   367
  assumes "s \<in> r \<rightarrow> v"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   368
  shows "v \<in> LV r s"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   369
  using assms unfolding LV_def
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   370
  apply(induct rule: Posix.induct)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   371
  apply(auto simp add: intro!: Prf.intros elim!: Prf_elims)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   372
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   373
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   374
lemma Posix_Prf:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   375
  assumes "s \<in> r \<rightarrow> v"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   376
  shows "\<Turnstile> v : r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   377
  using assms Posix_LV LV_def
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   378
  by simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   379
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   380
end