thys2/SpecAlts.thy
author Chengsong
Fri, 24 Jun 2022 21:49:23 +0100
changeset 553 0f00d440f484
parent 365 ec5e4fe4cc70
permissions -rw-r--r--
more changes
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 SpecAlts
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
     3
  imports Main "~~/src/HOL/Library/Sublist"
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 {* Sequential Composition of Languages *}
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
     7
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
     8
definition
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
     9
  Sequ :: "string set \<Rightarrow> string set \<Rightarrow> string set" ("_ ;; _" [100,100] 100)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    10
where 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    11
  "A ;; B = {s1 @ s2 | s1 s2. s1 \<in> A \<and> s2 \<in> B}"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    12
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    13
text {* Two Simple Properties about Sequential Composition *}
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    14
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    15
lemma Sequ_empty_string [simp]:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    16
  shows "A ;; {[]} = A"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    17
  and   "{[]} ;; A = A"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    18
by (simp_all add: Sequ_def)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    19
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    20
lemma Sequ_empty [simp]:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    21
  shows "A ;; {} = {}"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    22
  and   "{} ;; A = {}"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    23
by (simp_all add: Sequ_def)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    24
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    25
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    26
section {* Semantic Derivative (Left Quotient) of Languages *}
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    27
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    28
definition
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    29
  Der :: "char \<Rightarrow> string set \<Rightarrow> string set"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    30
where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    31
  "Der c A \<equiv> {s. c # s \<in> A}"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    32
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    33
definition
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    34
  Ders :: "string \<Rightarrow> string set \<Rightarrow> string set"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    35
where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    36
  "Ders s A \<equiv> {s'. s @ s' \<in> A}"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    37
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    38
lemma Der_null [simp]:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    39
  shows "Der c {} = {}"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    40
unfolding Der_def
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    41
by auto
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    42
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    43
lemma Der_empty [simp]:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    44
  shows "Der c {[]} = {}"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    45
unfolding Der_def
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    46
by auto
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    47
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    48
lemma Der_char [simp]:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    49
  shows "Der c {[d]} = (if c = d then {[]} else {})"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    50
unfolding Der_def
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    51
by auto
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    52
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    53
lemma Der_union [simp]:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    54
  shows "Der c (A \<union> B) = Der c A \<union> Der c B"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    55
unfolding Der_def
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    56
  by auto
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    57
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    58
lemma Der_Union [simp]:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    59
  shows "Der c (\<Union>B. A) = (\<Union>B. Der c A)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    60
unfolding Der_def
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    61
by auto
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    62
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    63
lemma Der_Sequ [simp]:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    64
  shows "Der c (A ;; B) = (Der c A) ;; B \<union> (if [] \<in> A then Der c B else {})"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    65
unfolding Der_def Sequ_def
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    66
by (auto simp add: Cons_eq_append_conv)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    67
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    68
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    69
section {* Kleene Star for Languages *}
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    70
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    71
inductive_set
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    72
  Star :: "string set \<Rightarrow> string set" ("_\<star>" [101] 102)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    73
  for A :: "string set"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    74
where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    75
  start[intro]: "[] \<in> A\<star>"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    76
| step[intro]:  "\<lbrakk>s1 \<in> A; s2 \<in> A\<star>\<rbrakk> \<Longrightarrow> s1 @ s2 \<in> A\<star>"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    77
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    78
(* Arden's lemma *)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    79
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    80
lemma Star_cases:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    81
  shows "A\<star> = {[]} \<union> A ;; A\<star>"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    82
unfolding Sequ_def
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    83
by (auto) (metis Star.simps)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    84
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    85
lemma Star_decomp: 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    86
  assumes "c # x \<in> A\<star>" 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    87
  shows "\<exists>s1 s2. x = s1 @ s2 \<and> c # s1 \<in> A \<and> s2 \<in> A\<star>"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    88
using assms
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    89
by (induct x\<equiv>"c # x" rule: Star.induct) 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    90
   (auto simp add: append_eq_Cons_conv)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    91
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    92
lemma Star_Der_Sequ: 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    93
  shows "Der c (A\<star>) \<subseteq> (Der c A) ;; A\<star>"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    94
unfolding Der_def Sequ_def
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    95
by(auto simp add: Star_decomp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    96
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    97
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    98
lemma Der_star [simp]:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    99
  shows "Der c (A\<star>) = (Der c A) ;; A\<star>"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   100
proof -    
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   101
  have "Der c (A\<star>) = Der c ({[]} \<union> A ;; A\<star>)"  
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   102
    by (simp only: Star_cases[symmetric])
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   103
  also have "... = Der c (A ;; A\<star>)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   104
    by (simp only: Der_union Der_empty) (simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   105
  also have "... = (Der c A) ;; A\<star> \<union> (if [] \<in> A then Der c (A\<star>) else {})"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   106
    by simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   107
  also have "... =  (Der c A) ;; A\<star>"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   108
    using Star_Der_Sequ by auto
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   109
  finally show "Der c (A\<star>) = (Der c A) ;; A\<star>" .
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   110
qed
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   111
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   112
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   113
section {* Regular Expressions *}
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   114
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   115
datatype rexp =
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   116
  ZERO
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   117
| ONE
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   118
| CHAR char
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   119
| SEQ rexp rexp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   120
| ALTS "rexp list"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   121
| STAR rexp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   122
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   123
section {* Semantics of Regular Expressions *}
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   124
 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   125
fun
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   126
  L :: "rexp \<Rightarrow> string set"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   127
where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   128
  "L (ZERO) = {}"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   129
| "L (ONE) = {[]}"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   130
| "L (CHAR c) = {[c]}"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   131
| "L (SEQ r1 r2) = (L r1) ;; (L r2)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   132
| "L (ALTS rs) = (\<Union>r \<in> set rs. L r)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   133
| "L (STAR r) = (L r)\<star>"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   134
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   135
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   136
section {* Nullable, Derivatives *}
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   137
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   138
fun
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   139
 nullable :: "rexp \<Rightarrow> bool"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   140
where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   141
  "nullable (ZERO) = False"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   142
| "nullable (ONE) = True"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   143
| "nullable (CHAR c) = False"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   144
| "nullable (ALTS rs) = (\<exists>r \<in> set rs. nullable r)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   145
| "nullable (SEQ r1 r2) = (nullable r1 \<and> nullable r2)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   146
| "nullable (STAR r) = True"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   147
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   148
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   149
fun
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   150
 der :: "char \<Rightarrow> rexp \<Rightarrow> rexp"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   151
where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   152
  "der c (ZERO) = ZERO"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   153
| "der c (ONE) = ZERO"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   154
| "der c (CHAR d) = (if c = d then ONE else ZERO)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   155
| "der c (ALTS rs) = ALTS (map (der c) rs)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   156
| "der c (SEQ r1 r2) = 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   157
     (if nullable r1
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   158
      then ALTS [SEQ (der c r1) r2, der c r2]
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   159
      else SEQ (der c r1) r2)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   160
| "der c (STAR r) = SEQ (der c r) (STAR r)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   161
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   162
fun 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   163
 ders :: "string \<Rightarrow> rexp \<Rightarrow> rexp"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   164
where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   165
  "ders [] r = r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   166
| "ders (c # s) r = ders s (der c r)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   167
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   168
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   169
lemma nullable_correctness:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   170
  shows "nullable r  \<longleftrightarrow> [] \<in> (L r)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   171
by (induct r) (auto simp add: Sequ_def) 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   172
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   173
lemma der_correctness:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   174
  shows "L (der c r) = Der c (L r)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   175
  apply(induct r) 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   176
       apply(simp_all add: nullable_correctness)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   177
  apply(auto simp add: Der_def)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   178
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   179
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   180
lemma ders_correctness:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   181
  shows "L (ders s r) = Ders s (L r)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   182
by (induct s arbitrary: r)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   183
   (simp_all add: Ders_def der_correctness Der_def)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   184
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   185
fun flats :: "rexp list \<Rightarrow> rexp list"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   186
  where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   187
  "flats [] = []"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   188
| "flats (ZERO # rs1) = flats(rs1)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   189
| "flats ((ALTS rs1) #rs2) = rs1 @ (flats rs2)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   190
| "flats (r1 # rs2) = r1 # flats rs2"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   191
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   192
fun simp_SEQ where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   193
  "simp_SEQ ONE r\<^sub>2 = r\<^sub>2"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   194
| "simp_SEQ r\<^sub>1 ONE = r\<^sub>1"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   195
| "simp_SEQ r\<^sub>1 r\<^sub>2 = SEQ r\<^sub>1 r\<^sub>2"  
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   196
 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   197
fun 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   198
  simp :: "rexp \<Rightarrow> rexp"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   199
where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   200
  "simp (ALTS rs) = ALTS (remdups (flats (map simp rs)))" 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   201
| "simp (SEQ r1 r2) = simp_SEQ (simp r1) (simp r2)" 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   202
| "simp r = r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   203
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   204
lemma simp_SEQ_correctness:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   205
  shows "L (simp_SEQ r1 r2) = L (SEQ r1 r2)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   206
  apply(induct r1 r2 rule: simp_SEQ.induct)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   207
  apply(simp_all)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   208
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   209
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   210
lemma flats_correctness:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   211
  shows "(\<Union>r \<in> set (flats rs). L r) = L (ALTS rs)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   212
  apply(induct rs rule: flats.induct)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   213
  apply(simp_all)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   214
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   215
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   216
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   217
lemma simp_correctness:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   218
  shows "L (simp r) = L r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   219
  apply(induct r)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   220
  apply(simp_all)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   221
  apply(simp add: simp_SEQ_correctness)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   222
  apply(simp add: flats_correctness)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   223
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   224
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   225
fun 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   226
 ders2 :: "string \<Rightarrow> rexp \<Rightarrow> rexp"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   227
where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   228
  "ders2 [] r = r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   229
| "ders2 (c # s) r = ders2 s (simp (der c r))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   230
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   231
lemma ders2_ZERO:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   232
  shows "ders2 s ZERO = ZERO"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   233
  apply(induct s)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   234
  apply(simp_all)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   235
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   236
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   237
lemma ders2_ONE:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   238
  shows "ders2 s ONE \<in> {ZERO, ONE}"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   239
  apply(induct s)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   240
  apply(simp_all)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   241
  apply(auto)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   242
  apply(case_tac s)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   243
  apply(auto)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   244
  apply(case_tac s)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   245
  apply(auto)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   246
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   247
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   248
lemma ders2_CHAR:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   249
  shows "ders2 s (CHAR c) \<in> {ZERO, ONE, CHAR c}"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   250
  apply(induct s)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   251
  apply(simp_all)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   252
  apply(auto simp add: ders2_ZERO)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   253
  apply(case_tac s)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   254
  apply(auto simp add: ders2_ZERO)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   255
  using ders2_ONE
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   256
  apply(auto)[1]
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   257
  using ders2_ONE
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   258
  apply(auto)[1]
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   259
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   260
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   261
lemma remdup_size:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   262
  shows "size_list f (remdups rs) \<le> size_list f rs"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   263
  apply(induct rs)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   264
   apply(simp_all)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   265
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   266
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   267
lemma flats_append:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   268
  shows "flats (rs1 @ rs2) = (flats rs1) @ (flats rs2)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   269
  apply(induct rs1 arbitrary: rs2)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   270
   apply(auto)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   271
  apply(case_tac a)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   272
       apply(auto)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   273
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   274
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   275
lemma flats_Cons:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   276
  shows "flats (r # rs) = (flats [r]) @ (flats rs)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   277
  apply(subst flats_append[symmetric])
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   278
  apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   279
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   280
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   281
lemma flats_size:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   282
  shows "size_list (\<lambda>x. size (ders2 s x)) (flats rs) \<le> size_list (\<lambda>x. size (ders2 s x))  rs"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   283
  apply(induct rs arbitrary: s rule: flats.induct)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   284
   apply(simp_all)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   285
   apply(simp add: ders2_ZERO)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   286
   apply (simp add: le_SucI)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   287
  
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   288
   apply(subst flats_Cons)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   289
  apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   290
  apply(case_tac a)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   291
       apply(auto)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   292
   apply(simp add: ders2_ZERO)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   293
   apply (simp add: le_SucI)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   294
  sorry
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   295
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   296
lemma ders2_ALTS:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   297
  shows "size (ders2 s (ALTS rs)) \<le> size (ALTS (map (ders2 s) rs))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   298
  apply(induct s arbitrary: rs)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   299
   apply(simp_all)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   300
  thm size_list_pointwise
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   301
  apply (simp add: size_list_pointwise)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   302
  apply(drule_tac x="remdups (flats (map (simp \<circ> der a) rs))" in meta_spec)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   303
  apply(rule le_trans)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   304
   apply(assumption)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   305
  apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   306
  apply(rule le_trans)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   307
   apply(rule remdup_size)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   308
  apply(simp add: comp_def)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   309
  apply(rule le_trans)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   310
  apply(rule flats_size)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   311
  by (simp add: size_list_pointwise)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   312
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   313
definition
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   314
 "derss2 A r = {ders2 s r | s. s \<in> A}"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   315
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   316
lemma
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   317
  "\<forall>rd \<in> derss2 (UNIV) r. size rd \<le> Suc (size r)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   318
  apply(induct r)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   319
  apply(auto simp add: derss2_def ders2_ZERO)[1]
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   320
      apply(auto simp add: derss2_def ders2_ZERO)[1]
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   321
  using ders2_ONE
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   322
      apply(auto)[1]
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   323
  apply (metis rexp.size(7) rexp.size(8) zero_le)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   324
  using ders2_CHAR
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   325
     apply(auto)[1]
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   326
  apply (smt derss2_def le_SucI le_zero_eq mem_Collect_eq rexp.size(7) rexp.size(8) rexp.size(9))
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   327
    defer  
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   328
    apply(auto simp add: derss2_def)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   329
    apply(rule le_trans)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   330
     apply(rule ders2_ALTS)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   331
    apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   332
    apply(simp add: comp_def)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   333
  
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   334
    apply(simp add: size_list_pointwise)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   335
    apply(case_tac s)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   336
     apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   337
  apply(simp only:)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   338
  apply(auto)[1]
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   339
   
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   340
  apply(case_tac s)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   341
        apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   342
  apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   343
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   344
section {* Values *}
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   345
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   346
datatype val = 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   347
  Void
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   348
| Char char
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   349
| Seq val val
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   350
| Nth nat val
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   351
| Stars "val list"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   352
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   353
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   354
section {* The string behind a value *}
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   355
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   356
fun 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   357
  flat :: "val \<Rightarrow> string"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   358
where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   359
  "flat (Void) = []"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   360
| "flat (Char c) = [c]"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   361
| "flat (Nth n v) = flat v"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   362
| "flat (Seq v1 v2) = (flat v1) @ (flat v2)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   363
| "flat (Stars []) = []"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   364
| "flat (Stars (v#vs)) = (flat v) @ (flat (Stars vs))" 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   366
abbreviation
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   367
  "flats vs \<equiv> concat (map flat vs)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   368
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   369
lemma flat_Stars [simp]:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   370
 "flat (Stars vs) = flats vs"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   371
by (induct vs) (auto)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   372
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   373
lemma Star_concat:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   374
  assumes "\<forall>s \<in> set ss. s \<in> A"  
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   375
  shows "concat ss \<in> A\<star>"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   376
using assms by (induct ss) (auto)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   377
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   378
lemma Star_cstring:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   379
  assumes "s \<in> A\<star>"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   380
  shows "\<exists>ss. concat ss = s \<and> (\<forall>s \<in> set ss. s \<in> A \<and> s \<noteq> [])"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   381
using assms
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   382
apply(induct rule: Star.induct)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   383
apply(auto)[1]
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   384
apply(rule_tac x="[]" in exI)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   385
apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   386
apply(erule exE)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   387
apply(clarify)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   388
apply(case_tac "s1 = []")
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   389
apply(rule_tac x="ss" in exI)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   390
apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   391
apply(rule_tac x="s1#ss" in exI)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   392
apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   393
done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   394
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   395
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   396
section {* Lexical Values *}
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   397
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   398
inductive 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   399
  Prf :: "val \<Rightarrow> rexp \<Rightarrow> bool" ("\<Turnstile> _ : _" [100, 100] 100)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   400
where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   401
  "\<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
   402
| "\<lbrakk>\<Turnstile> v1 : (nth rs n); n < length rs\<rbrakk> \<Longrightarrow> \<Turnstile> (Nth n v1) : ALTS rs"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   403
| "\<Turnstile> Void : ONE"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   404
| "\<Turnstile> Char c : CHAR c"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   405
| "\<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
   406
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   407
inductive_cases Prf_elims:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   408
  "\<Turnstile> v : ZERO"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   409
  "\<Turnstile> v : SEQ r1 r2"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   410
  "\<Turnstile> v : ALTS rs"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   411
  "\<Turnstile> v : ONE"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   412
  "\<Turnstile> v : CHAR c"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   413
  "\<Turnstile> vs : STAR r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   414
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   415
lemma Prf_Stars_appendE:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   416
  assumes "\<Turnstile> Stars (vs1 @ vs2) : STAR r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   417
  shows "\<Turnstile> Stars vs1 : STAR r \<and> \<Turnstile> Stars vs2 : STAR r" 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   418
using assms
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   419
by (auto intro: Prf.intros elim!: Prf_elims)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   420
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   421
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   422
lemma Star_cval:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   423
  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
   424
  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
   425
using assms
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   426
apply(induct ss)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   427
apply(auto)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   428
apply(rule_tac x="[]" in exI)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   429
apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   430
apply(case_tac "flat v = []")
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   431
apply(rule_tac x="vs" in exI)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   432
apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   433
apply(rule_tac x="v#vs" in exI)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   434
apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   435
done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   436
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   437
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   438
lemma L_flat_Prf1:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   439
  assumes "\<Turnstile> v : r" 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   440
  shows "flat v \<in> L r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   441
using assms
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   442
  apply(induct) 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   443
  apply(auto simp add: Sequ_def Star_concat)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   444
  done  
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   445
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   446
lemma L_flat_Prf2:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   447
  assumes "s \<in> L r" 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   448
  shows "\<exists>v. \<Turnstile> v : r \<and> flat v = s"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   449
using assms
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   450
proof(induct r arbitrary: s)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   451
  case (STAR r s)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   452
  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
   453
  have "s \<in> L (STAR r)" by fact
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   454
  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
   455
  using Star_cstring by auto  
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   456
  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
   457
  using IH Star_cval by metis 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   458
  then show "\<exists>v. \<Turnstile> v : STAR r \<and> flat v = s"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   459
  using Prf.intros(5) flat_Stars by blast
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   460
next 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   461
  case (SEQ r1 r2 s)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   462
  then show "\<exists>v. \<Turnstile> v : SEQ r1 r2 \<and> flat v = s"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   463
  unfolding Sequ_def L.simps by (fastforce intro: Prf.intros)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   464
next
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   465
  case (ALTS rs s)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   466
  then show "\<exists>v. \<Turnstile> v : ALTS rs \<and> flat v = s"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   467
    unfolding L.simps 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   468
    apply(auto)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   469
    apply(case_tac rs)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   470
     apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   471
    apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   472
    apply(auto)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   473
     apply(drule_tac x="a" in meta_spec)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   474
     apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   475
     apply(drule_tac x="s" in meta_spec)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   476
     apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   477
     apply(erule exE)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   478
     apply(rule_tac x="Nth 0 v" in exI)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   479
     apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   480
     apply(rule Prf.intros)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   481
      apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   482
     apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   483
    apply(drule_tac x="x" in meta_spec)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   484
    apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   485
    apply(drule_tac x="s" in meta_spec)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   486
    apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   487
    apply(erule exE)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   488
    apply(subgoal_tac "\<exists>n. nth list n = x \<and> n < length list")
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   489
    apply(erule exE)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   490
     apply(rule_tac x="Nth (Suc n) v" in exI)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   491
     apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   492
     apply(rule Prf.intros)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   493
      apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   494
     apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   495
    by (meson in_set_conv_nth)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   496
qed (auto intro: Prf.intros)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   497
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   498
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   499
lemma L_flat_Prf:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   500
  shows "L(r) = {flat v | v. \<Turnstile> v : r}"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   501
using L_flat_Prf1 L_flat_Prf2 by blast
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   502
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   503
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   504
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   505
section {* Sets of Lexical Values *}
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   506
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   507
text {*
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   508
  Shows that lexical values are finite for a given regex and string.
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   509
*}
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   510
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   511
definition
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   512
  LV :: "rexp \<Rightarrow> string \<Rightarrow> val set"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   513
where  "LV r s \<equiv> {v. \<Turnstile> v : r \<and> flat v = s}"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   514
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   515
lemma LV_simps:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   516
  shows "LV ZERO s = {}"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   517
  and   "LV ONE s = (if s = [] then {Void} else {})"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   518
  and   "LV (CHAR c) s = (if s = [c] then {Char c} else {})"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   519
unfolding LV_def
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   520
by (auto intro: Prf.intros elim: Prf.cases)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   521
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   522
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   523
abbreviation
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   524
  "Prefixes s \<equiv> {s'. prefix s' s}"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   525
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   526
abbreviation
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   527
  "Suffixes s \<equiv> {s'. suffix s' s}"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   528
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   529
abbreviation
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   530
  "SSuffixes s \<equiv> {s'. strict_suffix s' s}"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   531
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   532
lemma Suffixes_cons [simp]:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   533
  shows "Suffixes (c # s) = Suffixes s \<union> {c # s}"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   534
by (auto simp add: suffix_def Cons_eq_append_conv)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   535
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   536
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   537
lemma finite_Suffixes: 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   538
  shows "finite (Suffixes s)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   539
by (induct s) (simp_all)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   540
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   541
lemma finite_SSuffixes: 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   542
  shows "finite (SSuffixes s)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   543
proof -
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   544
  have "SSuffixes s \<subseteq> Suffixes s"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   545
   unfolding strict_suffix_def suffix_def by auto
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   546
  then show "finite (SSuffixes s)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   547
   using finite_Suffixes finite_subset by blast
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   548
qed
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   549
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   550
lemma finite_Prefixes: 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   551
  shows "finite (Prefixes s)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   552
proof -
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   553
  have "finite (Suffixes (rev s))" 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   554
    by (rule finite_Suffixes)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   555
  then have "finite (rev ` Suffixes (rev s))" by simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   556
  moreover
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   557
  have "rev ` (Suffixes (rev s)) = Prefixes s"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   558
  unfolding suffix_def prefix_def image_def
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   559
   by (auto)(metis rev_append rev_rev_ident)+
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   560
  ultimately show "finite (Prefixes s)" by simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   561
qed
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   562
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   563
lemma LV_STAR_finite:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   564
  assumes "\<forall>s. finite (LV r s)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   565
  shows "finite (LV (STAR r) s)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   566
proof(induct s rule: length_induct)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   567
  fix s::"char list"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   568
  assume "\<forall>s'. length s' < length s \<longrightarrow> finite (LV (STAR r) s')"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   569
  then have IH: "\<forall>s' \<in> SSuffixes s. finite (LV (STAR r) s')"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   570
    by (force simp add: strict_suffix_def suffix_def) 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   571
  define f where "f \<equiv> \<lambda>(v, vs). Stars (v # vs)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   572
  define S1 where "S1 \<equiv> \<Union>s' \<in> Prefixes s. LV r s'"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   573
  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
   574
  have "finite S1" using assms
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   575
    unfolding S1_def by (simp_all add: finite_Prefixes)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   576
  moreover 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   577
  with IH have "finite S2" unfolding S2_def
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   578
    by (auto simp add: finite_SSuffixes inj_on_def finite_vimageI)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   579
  ultimately 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   580
  have "finite ({Stars []} \<union> f ` (S1 \<times> S2))" by simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   581
  moreover 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   582
  have "LV (STAR r) s \<subseteq> {Stars []} \<union> f ` (S1 \<times> S2)" 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   583
  unfolding S1_def S2_def f_def
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   584
  unfolding LV_def image_def prefix_def strict_suffix_def
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   585
  apply(auto)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   586
  apply(case_tac x)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   587
  apply(auto elim: Prf_elims)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   588
  apply(erule Prf_elims)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   589
  apply(auto)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   590
  apply(case_tac vs)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   591
  apply(auto intro: Prf.intros)  
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   592
  apply(rule exI)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   593
  apply(rule conjI)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   594
  apply(rule_tac x="flat a" in exI)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   595
  apply(rule conjI)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   596
  apply(rule_tac x="flats list" in exI)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   597
  apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   598
   apply(blast)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   599
  apply(simp add: suffix_def)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   600
  using Prf.intros(5) by blast  
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   601
  ultimately
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   602
  show "finite (LV (STAR r) s)" by (simp add: finite_subset)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   603
qed  
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   604
    
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   605
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   606
lemma LV_finite:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   607
  shows "finite (LV r s)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   608
proof(induct r arbitrary: s)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   609
  case (ZERO s) 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   610
  show "finite (LV ZERO s)" by (simp add: LV_simps)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   611
next
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   612
  case (ONE s)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   613
  show "finite (LV ONE s)" by (simp add: LV_simps)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   614
next
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   615
  case (CHAR c s)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   616
  show "finite (LV (CHAR c) s)" by (simp add: LV_simps)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   617
next 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   618
  case (ALTS rs s)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   619
  then show "finite (LV (ALTS rs) s)" 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   620
    sorry
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   621
next 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   622
  case (SEQ r1 r2 s)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   623
  define f where "f \<equiv> \<lambda>(v1, v2). Seq v1 v2"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   624
  define S1 where "S1 \<equiv> \<Union>s' \<in> Prefixes s. LV r1 s'"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   625
  define S2 where "S2 \<equiv> \<Union>s' \<in> Suffixes s. LV r2 s'"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   626
  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
   627
  then have "finite S1" "finite S2" unfolding S1_def S2_def
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   628
    by (simp_all add: finite_Prefixes finite_Suffixes)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   629
  moreover
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   630
  have "LV (SEQ r1 r2) s \<subseteq> f ` (S1 \<times> S2)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   631
    unfolding f_def S1_def S2_def 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   632
    unfolding LV_def image_def prefix_def suffix_def
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   633
    apply (auto elim!: Prf_elims)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   634
    by (metis (mono_tags, lifting) mem_Collect_eq)  
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   635
  ultimately 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   636
  show "finite (LV (SEQ r1 r2) s)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   637
    by (simp add: finite_subset)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   638
next
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   639
  case (STAR r s)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   640
  then show "finite (LV (STAR r) s)" by (simp add: LV_STAR_finite)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   641
qed
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   642
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   643
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   644
(*
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   645
section {* Our POSIX Definition *}
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   646
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   647
inductive 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   648
  Posix :: "string \<Rightarrow> rexp \<Rightarrow> val \<Rightarrow> bool" ("_ \<in> _ \<rightarrow> _" [100, 100, 100] 100)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   649
where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   650
  Posix_ONE: "[] \<in> ONE \<rightarrow> Void"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   651
| Posix_CHAR: "[c] \<in> (CHAR c) \<rightarrow> (Char c)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   652
| 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
   653
| 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
   654
| Posix_SEQ: "\<lbrakk>s1 \<in> r1 \<rightarrow> v1; s2 \<in> r2 \<rightarrow> v2;
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   655
    \<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
   656
    (s1 @ s2) \<in> (SEQ r1 r2) \<rightarrow> (Seq v1 v2)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   657
| 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
   658
    \<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
   659
    \<Longrightarrow> (s1 @ s2) \<in> STAR r \<rightarrow> Stars (v # vs)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   660
| Posix_STAR2: "[] \<in> STAR r \<rightarrow> Stars []"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   661
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   662
inductive_cases Posix_elims:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   663
  "s \<in> ZERO \<rightarrow> v"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   664
  "s \<in> ONE \<rightarrow> v"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   665
  "s \<in> CHAR c \<rightarrow> v"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   666
  "s \<in> ALT r1 r2 \<rightarrow> v"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   667
  "s \<in> SEQ r1 r2 \<rightarrow> v"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   668
  "s \<in> STAR r \<rightarrow> v"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   669
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   670
lemma Posix1:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   671
  assumes "s \<in> r \<rightarrow> v"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   672
  shows "s \<in> L r" "flat v = s"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   673
using assms
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   674
by (induct s r v rule: Posix.induct)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   675
   (auto simp add: Sequ_def)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   676
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   677
text {*
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   678
  Our Posix definition determines a unique value.
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   679
*}
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   680
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   681
lemma Posix_determ:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   682
  assumes "s \<in> r \<rightarrow> v1" "s \<in> r \<rightarrow> v2"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   683
  shows "v1 = v2"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   684
using assms
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   685
proof (induct s r v1 arbitrary: v2 rule: Posix.induct)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   686
  case (Posix_ONE v2)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   687
  have "[] \<in> ONE \<rightarrow> v2" by fact
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   688
  then show "Void = v2" by cases auto
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   689
next 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   690
  case (Posix_CHAR c v2)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   691
  have "[c] \<in> CHAR c \<rightarrow> v2" by fact
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   692
  then show "Char c = v2" by cases auto
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   693
next 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   694
  case (Posix_ALT1 s r1 v r2 v2)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   695
  have "s \<in> ALT r1 r2 \<rightarrow> v2" by fact
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   696
  moreover
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   697
  have "s \<in> r1 \<rightarrow> v" by fact
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   698
  then have "s \<in> L r1" by (simp add: Posix1)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   699
  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
   700
  moreover
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   701
  have IH: "\<And>v2. s \<in> r1 \<rightarrow> v2 \<Longrightarrow> v = v2" by fact
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   702
  ultimately have "v = v'" by simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   703
  then show "Left v = v2" using eq by simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   704
next 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   705
  case (Posix_ALT2 s r2 v r1 v2)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   706
  have "s \<in> ALT r1 r2 \<rightarrow> v2" by fact
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   707
  moreover
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   708
  have "s \<notin> L r1" by fact
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   709
  ultimately obtain v' where eq: "v2 = Right v'" "s \<in> r2 \<rightarrow> v'" 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   710
    by cases (auto simp add: Posix1) 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   711
  moreover
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   712
  have IH: "\<And>v2. s \<in> r2 \<rightarrow> v2 \<Longrightarrow> v = v2" by fact
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   713
  ultimately have "v = v'" by simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   714
  then show "Right v = v2" using eq by simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   715
next
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   716
  case (Posix_SEQ s1 r1 v1 s2 r2 v2 v')
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   717
  have "(s1 @ s2) \<in> SEQ r1 r2 \<rightarrow> v'" 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   718
       "s1 \<in> r1 \<rightarrow> v1" "s2 \<in> r2 \<rightarrow> v2"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   719
       "\<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
   720
  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
   721
  apply(cases) apply (auto simp add: append_eq_append_conv2)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   722
  using Posix1(1) by fastforce+
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   723
  moreover
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   724
  have IHs: "\<And>v1'. s1 \<in> r1 \<rightarrow> v1' \<Longrightarrow> v1 = v1'"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   725
            "\<And>v2'. s2 \<in> r2 \<rightarrow> v2' \<Longrightarrow> v2 = v2'" by fact+
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   726
  ultimately show "Seq v1 v2 = v'" by simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   727
next
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   728
  case (Posix_STAR1 s1 r v s2 vs v2)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   729
  have "(s1 @ s2) \<in> STAR r \<rightarrow> v2" 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   730
       "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
   731
       "\<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
   732
  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
   733
  apply(cases) apply (auto simp add: append_eq_append_conv2)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   734
  using Posix1(1) apply fastforce
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   735
  apply (metis Posix1(1) Posix_STAR1.hyps(6) append_Nil append_Nil2)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   736
  using Posix1(2) by blast
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   737
  moreover
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   738
  have IHs: "\<And>v2. s1 \<in> r \<rightarrow> v2 \<Longrightarrow> v = v2"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   739
            "\<And>v2. s2 \<in> STAR r \<rightarrow> v2 \<Longrightarrow> Stars vs = v2" by fact+
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   740
  ultimately show "Stars (v # vs) = v2" by auto
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   741
next
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   742
  case (Posix_STAR2 r v2)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   743
  have "[] \<in> STAR r \<rightarrow> v2" by fact
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   744
  then show "Stars [] = v2" by cases (auto simp add: Posix1)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   745
qed
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   746
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   747
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   748
text {*
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   749
  Our POSIX value is a lexical value.
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   750
*}
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   751
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   752
lemma Posix_LV:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   753
  assumes "s \<in> r \<rightarrow> v"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   754
  shows "v \<in> LV r s"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   755
using assms unfolding LV_def
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   756
apply(induct rule: Posix.induct)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   757
apply(auto simp add: intro!: Prf.intros elim!: Prf_elims)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   758
done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   759
*)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   760
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   761
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   762
end