thys/Spec.thy
author Christian Urban <urbanc@in.tum.de>
Sun, 27 Aug 2017 00:03:31 +0300
changeset 272 f16019b11179
parent 268 6746f5e1f1f8
child 274 692b62426677
permissions -rw-r--r--
simplified proof
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
   
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     2
theory Spec
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
     3
  imports Main "~~/src/HOL/Library/Sublist"
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
begin
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
section {* Sequential Composition of Languages *}
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
definition
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
  Sequ :: "string set \<Rightarrow> string set \<Rightarrow> string set" ("_ ;; _" [100,100] 100)
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
where 
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
  "A ;; B = {s1 @ s2 | s1 s2. s1 \<in> A \<and> s2 \<in> B}"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
text {* Two Simple Properties about Sequential Composition *}
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
lemma Sequ_empty_string [simp]:
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
  shows "A ;; {[]} = A"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
  and   "{[]} ;; A = A"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
by (simp_all add: Sequ_def)
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
lemma Sequ_empty [simp]:
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
  shows "A ;; {} = {}"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
  and   "{} ;; A = {}"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
by (simp_all add: Sequ_def)
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
section {* Semantic Derivative (Left Quotient) of Languages *}
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    27
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
definition
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
  Der :: "char \<Rightarrow> string set \<Rightarrow> string set"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
where
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
  "Der c A \<equiv> {s. c # s \<in> A}"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
definition
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    34
  Ders :: "string \<Rightarrow> string set \<Rightarrow> string set"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35
where
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
  "Ders s A \<equiv> {s'. s @ s' \<in> A}"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
lemma Der_null [simp]:
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
  shows "Der c {} = {}"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
unfolding Der_def
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    41
by auto
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    43
lemma Der_empty [simp]:
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
  shows "Der c {[]} = {}"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
unfolding Der_def
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
by auto
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
lemma Der_char [simp]:
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
  shows "Der c {[d]} = (if c = d then {[]} else {})"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
unfolding Der_def
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
by auto
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
lemma Der_union [simp]:
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
  shows "Der c (A \<union> B) = Der c A \<union> Der c B"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
unfolding Der_def
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
by auto
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    58
lemma Der_Sequ [simp]:
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
  shows "Der c (A ;; B) = (Der c A) ;; B \<union> (if [] \<in> A then Der c B else {})"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
unfolding Der_def Sequ_def
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
by (auto simp add: Cons_eq_append_conv)
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
section {* Kleene Star for Languages *}
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
inductive_set
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
  Star :: "string set \<Rightarrow> string set" ("_\<star>" [101] 102)
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
  for A :: "string set"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
where
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
  start[intro]: "[] \<in> A\<star>"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    71
| step[intro]:  "\<lbrakk>s1 \<in> A; s2 \<in> A\<star>\<rbrakk> \<Longrightarrow> s1 @ s2 \<in> A\<star>"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
(* Arden's lemma *)
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
lemma Star_cases:
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
  shows "A\<star> = {[]} \<union> A ;; A\<star>"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    77
unfolding Sequ_def
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    78
by (auto) (metis Star.simps)
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    79
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
lemma Star_decomp: 
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    81
  assumes "c # x \<in> A\<star>" 
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
  shows "\<exists>s1 s2. x = s1 @ s2 \<and> c # s1 \<in> A \<and> s2 \<in> A\<star>"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    83
using assms
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
by (induct x\<equiv>"c # x" rule: Star.induct) 
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    85
   (auto simp add: append_eq_Cons_conv)
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    86
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    87
lemma Star_Der_Sequ: 
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    88
  shows "Der c (A\<star>) \<subseteq> (Der c A) ;; A\<star>"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    89
unfolding Der_def Sequ_def
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    90
by(auto simp add: Star_decomp)
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    91
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    92
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    93
lemma Der_star [simp]:
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    94
  shows "Der c (A\<star>) = (Der c A) ;; A\<star>"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    95
proof -    
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    96
  have "Der c (A\<star>) = Der c ({[]} \<union> A ;; A\<star>)"  
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    97
    by (simp only: Star_cases[symmetric])
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    98
  also have "... = Der c (A ;; A\<star>)"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    99
    by (simp only: Der_union Der_empty) (simp)
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   100
  also have "... = (Der c A) ;; A\<star> \<union> (if [] \<in> A then Der c (A\<star>) else {})"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   101
    by simp
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   102
  also have "... =  (Der c A) ;; A\<star>"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   103
    using Star_Der_Sequ by auto
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   104
  finally show "Der c (A\<star>) = (Der c A) ;; A\<star>" .
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   105
qed
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   106
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   107
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   108
section {* Regular Expressions *}
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   109
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   110
datatype rexp =
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   111
  ZERO
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   112
| ONE
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   113
| CHAR char
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   114
| SEQ rexp rexp
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   115
| ALT rexp rexp
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   116
| STAR rexp
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   117
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   118
section {* Semantics of Regular Expressions *}
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   119
 
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   120
fun
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   121
  L :: "rexp \<Rightarrow> string set"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   122
where
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   123
  "L (ZERO) = {}"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   124
| "L (ONE) = {[]}"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   125
| "L (CHAR c) = {[c]}"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   126
| "L (SEQ r1 r2) = (L r1) ;; (L r2)"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   127
| "L (ALT r1 r2) = (L r1) \<union> (L r2)"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   128
| "L (STAR r) = (L r)\<star>"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   129
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   130
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   131
section {* Nullable, Derivatives *}
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   132
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   133
fun
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   134
 nullable :: "rexp \<Rightarrow> bool"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   135
where
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   136
  "nullable (ZERO) = False"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   137
| "nullable (ONE) = True"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   138
| "nullable (CHAR c) = False"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   139
| "nullable (ALT r1 r2) = (nullable r1 \<or> nullable r2)"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   140
| "nullable (SEQ r1 r2) = (nullable r1 \<and> nullable r2)"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   141
| "nullable (STAR r) = True"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   142
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   143
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   144
fun
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   145
 der :: "char \<Rightarrow> rexp \<Rightarrow> rexp"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   146
where
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   147
  "der c (ZERO) = ZERO"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   148
| "der c (ONE) = ZERO"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   149
| "der c (CHAR d) = (if c = d then ONE else ZERO)"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   150
| "der c (ALT r1 r2) = ALT (der c r1) (der c r2)"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   151
| "der c (SEQ r1 r2) = 
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   152
     (if nullable r1
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   153
      then ALT (SEQ (der c r1) r2) (der c r2)
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   154
      else SEQ (der c r1) r2)"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   155
| "der c (STAR r) = SEQ (der c r) (STAR r)"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   156
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   157
fun 
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   158
 ders :: "string \<Rightarrow> rexp \<Rightarrow> rexp"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   159
where
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   160
  "ders [] r = r"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   161
| "ders (c # s) r = ders s (der c r)"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   162
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   163
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   164
lemma nullable_correctness:
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   165
  shows "nullable r  \<longleftrightarrow> [] \<in> (L r)"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   166
by (induct r) (auto simp add: Sequ_def) 
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   167
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   168
lemma der_correctness:
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   169
  shows "L (der c r) = Der c (L r)"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   170
by (induct r) (simp_all add: nullable_correctness)
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   171
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   172
lemma ders_correctness:
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   173
  shows "L (ders s r) = Ders s (L r)"
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   174
by (induct s arbitrary: r)
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   175
   (simp_all add: Ders_def der_correctness Der_def)
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   176
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   177
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   178
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   179
section {* Values *}
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   180
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   181
datatype val = 
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   182
  Void
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   183
| Char char
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   184
| Seq val val
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   185
| Right val
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   186
| Left val
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   187
| Stars "val list"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   188
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   189
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   190
section {* The string behind a value *}
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   191
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   192
fun 
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   193
  flat :: "val \<Rightarrow> string"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   194
where
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   195
  "flat (Void) = []"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   196
| "flat (Char c) = [c]"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   197
| "flat (Left v) = flat v"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   198
| "flat (Right v) = flat v"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   199
| "flat (Seq v1 v2) = (flat v1) @ (flat v2)"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   200
| "flat (Stars []) = []"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   201
| "flat (Stars (v#vs)) = (flat v) @ (flat (Stars vs))" 
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   202
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   203
abbreviation
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   204
  "flats vs \<equiv> concat (map flat vs)"
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   205
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   206
lemma flat_Stars [simp]:
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   207
 "flat (Stars vs) = flats vs"
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   208
by (induct vs) (auto)
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   209
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   210
lemma Star_concat:
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   211
  assumes "\<forall>s \<in> set ss. s \<in> A"  
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   212
  shows "concat ss \<in> A\<star>"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   213
using assms by (induct ss) (auto)
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   214
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   215
lemma Star_cstring:
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   216
  assumes "s \<in> A\<star>"
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   217
  shows "\<exists>ss. concat ss = s \<and> (\<forall>s \<in> set ss. s \<in> A \<and> s \<noteq> [])"
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   218
using assms
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   219
apply(induct rule: Star.induct)
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   220
apply(auto)[1]
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   221
apply(rule_tac x="[]" in exI)
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   222
apply(simp)
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   223
apply(erule exE)
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   224
apply(clarify)
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   225
apply(case_tac "s1 = []")
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   226
apply(rule_tac x="ss" in exI)
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   227
apply(simp)
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   228
apply(rule_tac x="s1#ss" in exI)
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   229
apply(simp)
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   230
done
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   231
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   232
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   233
section {* Lexical Values *}
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   234
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   235
inductive 
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   236
  Prf :: "val \<Rightarrow> rexp \<Rightarrow> bool" ("\<Turnstile> _ : _" [100, 100] 100)
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   237
where
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   238
 "\<lbrakk>\<Turnstile> v1 : r1; \<Turnstile> v2 : r2\<rbrakk> \<Longrightarrow> \<Turnstile>  Seq v1 v2 : SEQ r1 r2"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   239
| "\<Turnstile> v1 : r1 \<Longrightarrow> \<Turnstile> Left v1 : ALT r1 r2"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   240
| "\<Turnstile> v2 : r2 \<Longrightarrow> \<Turnstile> Right v2 : ALT r1 r2"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   241
| "\<Turnstile> Void : ONE"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   242
| "\<Turnstile> Char c : CHAR c"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   243
| "\<forall>v \<in> set vs. \<Turnstile> v : r \<and> flat v \<noteq> [] \<Longrightarrow> \<Turnstile> Stars vs : STAR r"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   244
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   245
inductive_cases Prf_elims:
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   246
  "\<Turnstile> v : ZERO"
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   247
  "\<Turnstile> v : SEQ r1 r2"
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   248
  "\<Turnstile> v : ALT r1 r2"
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   249
  "\<Turnstile> v : ONE"
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   250
  "\<Turnstile> v : CHAR c"
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   251
  "\<Turnstile> vs : STAR r"
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   252
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   253
lemma Prf_Stars_appendE:
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   254
  assumes "\<Turnstile> Stars (vs1 @ vs2) : STAR r"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   255
  shows "\<Turnstile> Stars vs1 : STAR r \<and> \<Turnstile> Stars vs2 : STAR r" 
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   256
using assms
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   257
by (auto intro: Prf.intros elim!: Prf_elims)
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   258
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   259
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   260
lemma Star_cval:
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   261
  assumes "\<forall>s\<in>set ss. \<exists>v. s = flat v \<and> \<Turnstile> v : r"
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   262
  shows "\<exists>vs. flats vs = concat ss \<and> (\<forall>v\<in>set vs. \<Turnstile> v : r \<and> flat v \<noteq> [])"
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   263
using assms
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   264
apply(induct ss)
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   265
apply(auto)
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   266
apply(rule_tac x="[]" in exI)
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   267
apply(simp)
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   268
apply(case_tac "flat v = []")
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   269
apply(rule_tac x="vs" in exI)
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   270
apply(simp)
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   271
apply(rule_tac x="v#vs" in exI)
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   272
apply(simp)
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   273
done
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   274
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   275
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   276
lemma L_flat_Prf1:
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   277
  assumes "\<Turnstile> v : r" 
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   278
  shows "flat v \<in> L r"
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   279
using assms
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   280
by (induct) (auto simp add: Sequ_def Star_concat)
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   281
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   282
lemma L_flat_Prf2:
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   283
  assumes "s \<in> L r" 
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   284
  shows "\<exists>v. \<Turnstile> v : r \<and> flat v = s"
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   285
using assms
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   286
proof(induct r arbitrary: s)
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   287
  case (STAR r s)
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   288
  have IH: "\<And>s. s \<in> L r \<Longrightarrow> \<exists>v. \<Turnstile> v : r \<and> flat v = s" by fact
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   289
  have "s \<in> L (STAR r)" by fact
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   290
  then obtain ss where "concat ss = s" "\<forall>s \<in> set ss. s \<in> L r \<and> s \<noteq> []"
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   291
  using Star_cstring by auto  
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   292
  then obtain vs where "flats vs = s" "\<forall>v\<in>set vs. \<Turnstile> v : r \<and> flat v \<noteq> []"
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   293
  using IH Star_cval by metis 
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   294
  then show "\<exists>v. \<Turnstile> v : STAR r \<and> flat v = s"
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   295
  using Prf.intros(6) flat_Stars by blast
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   296
next 
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   297
  case (SEQ r1 r2 s)
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   298
  then show "\<exists>v. \<Turnstile> v : SEQ r1 r2 \<and> flat v = s"
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   299
  unfolding Sequ_def L.simps by (fastforce intro: Prf.intros)
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   300
next
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   301
  case (ALT r1 r2 s)
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   302
  then show "\<exists>v. \<Turnstile> v : ALT r1 r2 \<and> flat v = s"
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   303
  unfolding L.simps by (fastforce intro: Prf.intros)
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   304
qed (auto intro: Prf.intros)
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   305
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   306
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   307
lemma L_flat_Prf:
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   308
  shows "L(r) = {flat v | v. \<Turnstile> v : r}"
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   309
using L_flat_Prf1 L_flat_Prf2 by blast
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   310
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   311
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   312
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   313
section {* Sets of Lexical Values *}
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   314
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   315
text {*
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   316
  Shows that lexical values are finite for a given regex and string.
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   317
*}
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   318
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   319
definition
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   320
  LV :: "rexp \<Rightarrow> string \<Rightarrow> val set"
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   321
where  "LV r s \<equiv> {v. \<Turnstile> v : r \<and> flat v = s}"
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   322
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   323
lemma LV_simps:
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   324
  shows "LV ZERO s = {}"
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   325
  and   "LV ONE s = (if s = [] then {Void} else {})"
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   326
  and   "LV (CHAR c) s = (if s = [c] then {Char c} else {})"
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   327
  and   "LV (ALT r1 r2) s = Left ` LV r1 s \<union> Right ` LV r2 s"
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   328
unfolding LV_def
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   329
by (auto intro: Prf.intros elim: Prf.cases)
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   330
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   331
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   332
abbreviation
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   333
  "Prefixes s \<equiv> {s'. prefixeq s' s}"
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   334
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   335
abbreviation
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   336
  "Suffixes s \<equiv> {s'. suffixeq s' s}"
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   337
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   338
abbreviation
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   339
  "SSuffixes s \<equiv> {s'. suffix s' s}"
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   340
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   341
lemma Suffixes_cons [simp]:
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   342
  shows "Suffixes (c # s) = Suffixes s \<union> {c # s}"
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   343
by (auto simp add: suffixeq_def Cons_eq_append_conv)
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   344
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   345
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   346
lemma finite_Suffixes: 
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   347
  shows "finite (Suffixes s)"
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   348
by (induct s) (simp_all)
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   349
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   350
lemma finite_SSuffixes: 
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   351
  shows "finite (SSuffixes s)"
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   352
proof -
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   353
  have "SSuffixes s \<subseteq> Suffixes s"
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   354
   unfolding suffix_def suffixeq_def by auto
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   355
  then show "finite (SSuffixes s)"
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   356
   using finite_Suffixes finite_subset by blast
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   357
qed
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   358
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   359
lemma finite_Prefixes: 
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   360
  shows "finite (Prefixes s)"
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   361
proof -
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   362
  have "finite (Suffixes (rev s))" 
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   363
    by (rule finite_Suffixes)
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   364
  then have "finite (rev ` Suffixes (rev s))" by simp
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   365
  moreover
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   366
  have "rev ` (Suffixes (rev s)) = Prefixes s"
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   367
  unfolding suffixeq_def prefixeq_def image_def
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   368
   by (auto)(metis rev_append rev_rev_ident)+
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   369
  ultimately show "finite (Prefixes s)" by simp
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   370
qed
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   371
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   372
lemma LV_STAR_finite:
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   373
  assumes "\<forall>s. finite (LV r s)"
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   374
  shows "finite (LV (STAR r) s)"
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   375
proof(induct s rule: length_induct)
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   376
  fix s::"char list"
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   377
  assume "\<forall>s'. length s' < length s \<longrightarrow> finite (LV (STAR r) s')"
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   378
  then have IH: "\<forall>s' \<in> SSuffixes s. finite (LV (STAR r) s')"
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   379
    by (auto simp add: suffix_def) 
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   380
  def f \<equiv> "\<lambda>(v, vs). Stars (v # vs)"
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   381
  def S1 \<equiv> "\<Union>s' \<in> Prefixes s. LV r s'"
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   382
  def S2 \<equiv> "\<Union>s2 \<in> SSuffixes s. Stars -` (LV (STAR r) s2)"
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   383
  have "finite S1" using assms
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   384
    unfolding S1_def by (simp_all add: finite_Prefixes)
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   385
  moreover 
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   386
  with IH have "finite S2" unfolding S2_def
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   387
    by (auto simp add: finite_SSuffixes inj_on_def finite_vimageI)
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   388
  ultimately 
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   389
  have "finite ({Stars []} \<union> f ` (S1 \<times> S2))" by simp
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   390
  moreover 
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   391
  have "LV (STAR r) s \<subseteq> {Stars []} \<union> f ` (S1 \<times> S2)" 
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   392
  unfolding S1_def S2_def f_def
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   393
  unfolding LV_def image_def prefixeq_def suffix_def
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   394
  apply(auto elim: Prf_elims)
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   395
  apply(erule Prf_elims)
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   396
  apply(auto)
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   397
  apply(case_tac vs)
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   398
  apply(auto intro: Prf.intros)
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   399
  done  
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   400
  ultimately
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   401
  show "finite (LV (STAR r) s)" by (simp add: finite_subset)
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   402
qed  
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   403
    
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   404
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   405
lemma LV_finite:
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   406
  shows "finite (LV r s)"
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   407
proof(induct r arbitrary: s)
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   408
  case (ZERO s) 
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   409
  show "finite (LV ZERO s)" by (simp add: LV_simps)
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   410
next
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   411
  case (ONE s)
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   412
  show "finite (LV ONE s)" by (simp add: LV_simps)
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   413
next
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   414
  case (CHAR c s)
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   415
  show "finite (LV (CHAR c) s)" by (simp add: LV_simps)
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   416
next 
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   417
  case (ALT r1 r2 s)
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   418
  then show "finite (LV (ALT r1 r2) s)" by (simp add: LV_simps)
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   419
next 
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   420
  case (SEQ r1 r2 s)
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   421
  def f \<equiv> "\<lambda>(v1, v2). Seq v1 v2"
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   422
  def S1 \<equiv> "\<Union>s' \<in> Prefixes s. LV r1 s'"
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   423
  def S2 \<equiv> "\<Union>s' \<in> Suffixes s. LV r2 s'"
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   424
  have IHs: "\<And>s. finite (LV r1 s)" "\<And>s. finite (LV r2 s)" by fact+
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   425
  then have "finite S1" "finite S2" unfolding S1_def S2_def
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   426
    by (simp_all add: finite_Prefixes finite_Suffixes)
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   427
  moreover
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   428
  have "LV (SEQ r1 r2) s \<subseteq> f ` (S1 \<times> S2)"
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   429
    unfolding f_def S1_def S2_def 
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   430
    unfolding LV_def image_def prefixeq_def suffixeq_def
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   431
    by (auto elim: Prf.cases)
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   432
  ultimately 
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   433
  show "finite (LV (SEQ r1 r2) s)"
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   434
    by (simp add: finite_subset)
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   435
next
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   436
  case (STAR r s)
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   437
  then show "finite (LV (STAR r) s)" by (simp add: LV_STAR_finite)
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   438
qed
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   439
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   440
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   441
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   442
section {* Our POSIX Definition *}
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   443
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   444
inductive 
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   445
  Posix :: "string \<Rightarrow> rexp \<Rightarrow> val \<Rightarrow> bool" ("_ \<in> _ \<rightarrow> _" [100, 100, 100] 100)
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   446
where
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   447
  Posix_ONE: "[] \<in> ONE \<rightarrow> Void"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   448
| Posix_CHAR: "[c] \<in> (CHAR c) \<rightarrow> (Char c)"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   449
| Posix_ALT1: "s \<in> r1 \<rightarrow> v \<Longrightarrow> s \<in> (ALT r1 r2) \<rightarrow> (Left v)"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   450
| Posix_ALT2: "\<lbrakk>s \<in> r2 \<rightarrow> v; s \<notin> L(r1)\<rbrakk> \<Longrightarrow> s \<in> (ALT r1 r2) \<rightarrow> (Right v)"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   451
| Posix_SEQ: "\<lbrakk>s1 \<in> r1 \<rightarrow> v1; s2 \<in> r2 \<rightarrow> v2;
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   452
    \<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> 
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   453
    (s1 @ s2) \<in> (SEQ r1 r2) \<rightarrow> (Seq v1 v2)"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   454
| Posix_STAR1: "\<lbrakk>s1 \<in> r \<rightarrow> v; s2 \<in> STAR r \<rightarrow> Stars vs; flat v \<noteq> [];
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   455
    \<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>
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   456
    \<Longrightarrow> (s1 @ s2) \<in> STAR r \<rightarrow> Stars (v # vs)"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   457
| Posix_STAR2: "[] \<in> STAR r \<rightarrow> Stars []"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   458
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   459
inductive_cases Posix_elims:
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   460
  "s \<in> ZERO \<rightarrow> v"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   461
  "s \<in> ONE \<rightarrow> v"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   462
  "s \<in> CHAR c \<rightarrow> v"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   463
  "s \<in> ALT r1 r2 \<rightarrow> v"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   464
  "s \<in> SEQ r1 r2 \<rightarrow> v"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   465
  "s \<in> STAR r \<rightarrow> v"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   466
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   467
lemma Posix1:
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   468
  assumes "s \<in> r \<rightarrow> v"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   469
  shows "s \<in> L r" "flat v = s"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   470
using assms
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   471
by (induct s r v rule: Posix.induct)
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   472
   (auto simp add: Sequ_def)
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   473
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   474
text {*
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   475
  Our Posix definition determines a unique value.
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   476
*}
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   477
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   478
lemma Posix_determ:
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   479
  assumes "s \<in> r \<rightarrow> v1" "s \<in> r \<rightarrow> v2"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   480
  shows "v1 = v2"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   481
using assms
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   482
proof (induct s r v1 arbitrary: v2 rule: Posix.induct)
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   483
  case (Posix_ONE v2)
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   484
  have "[] \<in> ONE \<rightarrow> v2" by fact
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   485
  then show "Void = v2" by cases auto
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   486
next 
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   487
  case (Posix_CHAR c v2)
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   488
  have "[c] \<in> CHAR c \<rightarrow> v2" by fact
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   489
  then show "Char c = v2" by cases auto
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   490
next 
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   491
  case (Posix_ALT1 s r1 v r2 v2)
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   492
  have "s \<in> ALT r1 r2 \<rightarrow> v2" by fact
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   493
  moreover
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   494
  have "s \<in> r1 \<rightarrow> v" by fact
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   495
  then have "s \<in> L r1" by (simp add: Posix1)
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   496
  ultimately obtain v' where eq: "v2 = Left v'" "s \<in> r1 \<rightarrow> v'" by cases auto 
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   497
  moreover
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   498
  have IH: "\<And>v2. s \<in> r1 \<rightarrow> v2 \<Longrightarrow> v = v2" by fact
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   499
  ultimately have "v = v'" by simp
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   500
  then show "Left v = v2" using eq by simp
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   501
next 
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   502
  case (Posix_ALT2 s r2 v r1 v2)
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   503
  have "s \<in> ALT r1 r2 \<rightarrow> v2" by fact
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   504
  moreover
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   505
  have "s \<notin> L r1" by fact
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   506
  ultimately obtain v' where eq: "v2 = Right v'" "s \<in> r2 \<rightarrow> v'" 
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   507
    by cases (auto simp add: Posix1) 
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   508
  moreover
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   509
  have IH: "\<And>v2. s \<in> r2 \<rightarrow> v2 \<Longrightarrow> v = v2" by fact
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   510
  ultimately have "v = v'" by simp
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   511
  then show "Right v = v2" using eq by simp
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   512
next
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   513
  case (Posix_SEQ s1 r1 v1 s2 r2 v2 v')
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   514
  have "(s1 @ s2) \<in> SEQ r1 r2 \<rightarrow> v'" 
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   515
       "s1 \<in> r1 \<rightarrow> v1" "s2 \<in> r2 \<rightarrow> v2"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   516
       "\<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+
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   517
  then obtain v1' v2' where "v' = Seq v1' v2'" "s1 \<in> r1 \<rightarrow> v1'" "s2 \<in> r2 \<rightarrow> v2'"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   518
  apply(cases) apply (auto simp add: append_eq_append_conv2)
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   519
  using Posix1(1) by fastforce+
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   520
  moreover
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   521
  have IHs: "\<And>v1'. s1 \<in> r1 \<rightarrow> v1' \<Longrightarrow> v1 = v1'"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   522
            "\<And>v2'. s2 \<in> r2 \<rightarrow> v2' \<Longrightarrow> v2 = v2'" by fact+
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   523
  ultimately show "Seq v1 v2 = v'" by simp
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   524
next
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   525
  case (Posix_STAR1 s1 r v s2 vs v2)
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   526
  have "(s1 @ s2) \<in> STAR r \<rightarrow> v2" 
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   527
       "s1 \<in> r \<rightarrow> v" "s2 \<in> STAR r \<rightarrow> Stars vs" "flat v \<noteq> []"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   528
       "\<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+
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   529
  then obtain v' vs' where "v2 = Stars (v' # vs')" "s1 \<in> r \<rightarrow> v'" "s2 \<in> (STAR r) \<rightarrow> (Stars vs')"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   530
  apply(cases) apply (auto simp add: append_eq_append_conv2)
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   531
  using Posix1(1) apply fastforce
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   532
  apply (metis Posix1(1) Posix_STAR1.hyps(6) append_Nil append_Nil2)
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   533
  using Posix1(2) by blast
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   534
  moreover
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   535
  have IHs: "\<And>v2. s1 \<in> r \<rightarrow> v2 \<Longrightarrow> v = v2"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   536
            "\<And>v2. s2 \<in> STAR r \<rightarrow> v2 \<Longrightarrow> Stars vs = v2" by fact+
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   537
  ultimately show "Stars (v # vs) = v2" by auto
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   538
next
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   539
  case (Posix_STAR2 r v2)
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   540
  have "[] \<in> STAR r \<rightarrow> v2" by fact
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   541
  then show "Stars [] = v2" by cases (auto simp add: Posix1)
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   542
qed
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   543
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   544
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   545
text {*
272
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 268
diff changeset
   546
  Our POSIX value is a lexical value.
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   547
*}
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   548
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   549
lemma Posix_LV:
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   550
  assumes "s \<in> r \<rightarrow> v"
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   551
  shows "v \<in> LV r s"
272
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 268
diff changeset
   552
using assms unfolding LV_def
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   553
apply(induct rule: Posix.induct)
272
f16019b11179 simplified proof
Christian Urban <urbanc@in.tum.de>
parents: 268
diff changeset
   554
apply(auto simp add: intro!: Prf.intros elim!: Prf_elims)
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   555
done
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   556
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   557
end