thys2/Re1.thy
changeset 365 ec5e4fe4cc70
equal deleted inserted replaced
364:232aa2f19a75 365:ec5e4fe4cc70
       
     1    
       
     2 theory Re1
       
     3   imports "Main" 
       
     4 begin
       
     5 
       
     6 
       
     7 section {* Sequential Composition of Sets *}
       
     8 
       
     9 definition
       
    10   Sequ :: "string set \<Rightarrow> string set \<Rightarrow> string set" ("_ ;; _" [100,100] 100)
       
    11 where 
       
    12   "A ;; B = {s1 @ s2 | s1 s2. s1 \<in> A \<and> s2 \<in> B}"
       
    13 
       
    14 text {* Two Simple Properties about Sequential Composition *}
       
    15 
       
    16 lemma seq_empty [simp]:
       
    17   shows "A ;; {[]} = A"
       
    18   and   "{[]} ;; A = A"
       
    19 by (simp_all add: Sequ_def)
       
    20 
       
    21 lemma seq_null [simp]:
       
    22   shows "A ;; {} = {}"
       
    23   and   "{} ;; A = {}"
       
    24 by (simp_all add: Sequ_def)
       
    25 
       
    26 section {* Regular Expressions *}
       
    27 
       
    28 datatype rexp =
       
    29   NULL
       
    30 | EMPTY
       
    31 | CHAR char
       
    32 | SEQ rexp rexp
       
    33 | ALT rexp rexp
       
    34 
       
    35 fun SEQS :: "rexp \<Rightarrow> rexp list \<Rightarrow> rexp"
       
    36 where
       
    37   "SEQS r [] = r"
       
    38 | "SEQS r (r'#rs) = SEQ r (SEQS r' rs)"
       
    39 
       
    40 section {* Semantics of Regular Expressions *}
       
    41  
       
    42 fun
       
    43   L :: "rexp \<Rightarrow> string set"
       
    44 where
       
    45   "L (NULL) = {}"
       
    46 | "L (EMPTY) = {[]}"
       
    47 | "L (CHAR c) = {[c]}"
       
    48 | "L (SEQ r1 r2) = (L r1) ;; (L r2)"
       
    49 | "L (ALT r1 r2) = (L r1) \<union> (L r2)"
       
    50 
       
    51 fun zeroable where
       
    52   "zeroable NULL = True"
       
    53 | "zeroable EMPTY = False"
       
    54 | "zeroable (CHAR c) = False"
       
    55 | "zeroable (ALT r1 r2) = (zeroable r1 \<and> zeroable r2)"
       
    56 | "zeroable (SEQ r1 r2) = (zeroable r1 \<or> zeroable r2)"
       
    57 
       
    58 lemma L_ALT_cases:
       
    59   "L (ALT r1 r2) \<noteq> {} \<Longrightarrow> (L r1 \<noteq> {}) \<or> (L r1 = {} \<and> L r2 \<noteq> {})"
       
    60 by(auto)
       
    61 
       
    62 fun
       
    63  nullable :: "rexp \<Rightarrow> bool"
       
    64 where
       
    65   "nullable (NULL) = False"
       
    66 | "nullable (EMPTY) = True"
       
    67 | "nullable (CHAR c) = False"
       
    68 | "nullable (ALT r1 r2) = (nullable r1 \<or> nullable r2)"
       
    69 | "nullable (SEQ r1 r2) = (nullable r1 \<and> nullable r2)"
       
    70 
       
    71 lemma nullable_correctness:
       
    72   shows "nullable r  \<longleftrightarrow> [] \<in> (L r)"
       
    73 apply (induct r) 
       
    74 apply(auto simp add: Sequ_def) 
       
    75 done
       
    76 
       
    77 section {* Values *}
       
    78 
       
    79 datatype val = 
       
    80   Void
       
    81 | Char char
       
    82 | Seq val val
       
    83 | Right val
       
    84 | Left val
       
    85 
       
    86 
       
    87 fun Seqs :: "val \<Rightarrow> val list \<Rightarrow> val"
       
    88 where
       
    89   "Seqs v [] = v"
       
    90 | "Seqs v (v'#vs) = Seqs (Seq v v') vs"
       
    91 
       
    92 section {* The string behind a value *}
       
    93 
       
    94 fun flat :: "val \<Rightarrow> string"
       
    95 where
       
    96   "flat(Void) = []"
       
    97 | "flat(Char c) = [c]"
       
    98 | "flat(Left v) = flat(v)"
       
    99 | "flat(Right v) = flat(v)"
       
   100 | "flat(Seq v1 v2) = flat(v1) @ flat(v2)"
       
   101 
       
   102 fun flats :: "val \<Rightarrow> string list"
       
   103 where
       
   104   "flats(Void) = [[]]"
       
   105 | "flats(Char c) = [[c]]"
       
   106 | "flats(Left v) = flats(v)"
       
   107 | "flats(Right v) = flats(v)"
       
   108 | "flats(Seq v1 v2) = (flats v1) @ (flats v2)"
       
   109 
       
   110 value "flats(Seq(Char c)(Char b))"
       
   111 
       
   112 section {* Relation between values and regular expressions *}
       
   113 
       
   114 
       
   115 inductive Prfs :: "string \<Rightarrow> val \<Rightarrow> rexp \<Rightarrow> bool" ("\<Turnstile>_ _ : _" [100, 100, 100] 100)
       
   116 where
       
   117  "\<lbrakk>\<Turnstile>s1 v1 : r1; \<Turnstile>s2 v2 : r2\<rbrakk> \<Longrightarrow> \<Turnstile>(s1 @ s2) (Seq v1 v2) : SEQ r1 r2"
       
   118 | "\<Turnstile>s v1 : r1 \<Longrightarrow> \<Turnstile>s (Left v1) : ALT r1 r2"
       
   119 | "\<Turnstile>s v2 : r2 \<Longrightarrow> \<Turnstile>s (Right v2) : ALT r1 r2"
       
   120 | "\<Turnstile>[] Void : EMPTY"
       
   121 | "\<Turnstile>[c] (Char c) : CHAR c"
       
   122 
       
   123 lemma Prfs_flat:
       
   124   "\<Turnstile>s v : r \<Longrightarrow> flat v = s"
       
   125 apply(induct s v r rule: Prfs.induct)
       
   126 apply(auto)
       
   127 done
       
   128 
       
   129 inductive Prfn :: "nat \<Rightarrow> val \<Rightarrow> rexp \<Rightarrow> bool" ("\<TTurnstile>_ _ : _" [100, 100, 100] 100)
       
   130 where
       
   131  "\<lbrakk>\<TTurnstile>n1 v1 : r1; \<TTurnstile>n2 v2 : r2\<rbrakk> \<Longrightarrow> \<TTurnstile>(n1 + n2) (Seq v1 v2) : SEQ r1 r2"
       
   132 | "\<TTurnstile>n v1 : r1 \<Longrightarrow> \<TTurnstile>n (Left v1) : ALT r1 r2"
       
   133 | "\<TTurnstile>n v2 : r2 \<Longrightarrow> \<TTurnstile>n (Right v2) : ALT r1 r2"
       
   134 | "\<TTurnstile>0 Void : EMPTY"
       
   135 | "\<TTurnstile>1 (Char c) : CHAR c"
       
   136 
       
   137 lemma Prfn_flat:
       
   138   "\<TTurnstile>n v : r \<Longrightarrow> length (flat v) = n"
       
   139 apply(induct rule: Prfn.induct)
       
   140 apply(auto)
       
   141 done
       
   142 
       
   143 inductive Prf :: "val \<Rightarrow> rexp \<Rightarrow> bool" ("\<turnstile> _ : _" [100, 100] 100)
       
   144 where
       
   145  "\<lbrakk>\<turnstile> v1 : r1; \<turnstile> v2 : r2\<rbrakk> \<Longrightarrow> \<turnstile> Seq v1 v2 : SEQ r1 r2"
       
   146 | "\<turnstile> v1 : r1 \<Longrightarrow> \<turnstile> Left v1 : ALT r1 r2"
       
   147 | "\<turnstile> v2 : r2 \<Longrightarrow> \<turnstile> Right v2 : ALT r1 r2"
       
   148 | "\<turnstile> Void : EMPTY"
       
   149 | "\<turnstile> Char c : CHAR c"
       
   150 
       
   151 lemma Prf_Prfn:
       
   152   shows "\<turnstile> v : r \<Longrightarrow> \<TTurnstile>(length (flat v)) v : r"
       
   153 apply(induct v r rule: Prf.induct)
       
   154 apply(auto intro: Prfn.intros)
       
   155 by (metis One_nat_def Prfn.intros(5))
       
   156 
       
   157 lemma Prfn_Prf:
       
   158   shows "\<TTurnstile>n v : r \<Longrightarrow> \<turnstile> v : r"
       
   159 apply(induct n v r rule: Prfn.induct)
       
   160 apply(auto intro: Prf.intros)
       
   161 done
       
   162 
       
   163 lemma Prf_Prfs:
       
   164   shows "\<turnstile> v : r \<Longrightarrow> \<Turnstile>(flat v) v : r"
       
   165 apply(induct v r rule: Prf.induct)
       
   166 apply(auto intro: Prfs.intros)
       
   167 done
       
   168 
       
   169 lemma Prfs_Prf:
       
   170   shows "\<Turnstile>s v : r \<Longrightarrow> \<turnstile> v : r"
       
   171 apply(induct s v r rule: Prfs.induct)
       
   172 apply(auto intro: Prf.intros)
       
   173 done
       
   174 
       
   175 lemma not_nullable_flat:
       
   176   assumes "\<turnstile> v : r" "\<not>nullable r"
       
   177   shows "flat v \<noteq> []"
       
   178 using assms
       
   179 apply(induct)
       
   180 apply(auto)
       
   181 done
       
   182 
       
   183 
       
   184 fun mkeps :: "rexp \<Rightarrow> val"
       
   185 where
       
   186   "mkeps(EMPTY) = Void"
       
   187 | "mkeps(SEQ r1 r2) = Seq (mkeps r1) (mkeps r2)"
       
   188 | "mkeps(ALT r1 r2) = (if nullable(r1) then Left (mkeps r1) else Right (mkeps r2))"
       
   189 
       
   190 lemma mkeps_nullable:
       
   191   assumes "nullable(r)" shows "\<turnstile> mkeps r : r"
       
   192 using assms
       
   193 apply(induct rule: nullable.induct)
       
   194 apply(auto intro: Prf.intros)
       
   195 done
       
   196 
       
   197 lemma mkeps_nullable_n:
       
   198   assumes "nullable(r)" shows "\<TTurnstile>0 (mkeps r) : r"
       
   199 using assms
       
   200 apply(induct rule: nullable.induct)
       
   201 apply(auto intro: Prfn.intros)
       
   202 apply(drule Prfn.intros(1))
       
   203 apply(assumption)
       
   204 apply(simp)
       
   205 done
       
   206 
       
   207 lemma mkeps_nullable_s:
       
   208   assumes "nullable(r)" shows "\<Turnstile>[] (mkeps r) : r"
       
   209 using assms
       
   210 apply(induct rule: nullable.induct)
       
   211 apply(auto intro: Prfs.intros)
       
   212 apply(drule Prfs.intros(1))
       
   213 apply(assumption)
       
   214 apply(simp)
       
   215 done
       
   216 
       
   217 lemma mkeps_flat:
       
   218   assumes "nullable(r)" shows "flat (mkeps r) = []"
       
   219 using assms
       
   220 apply(induct rule: nullable.induct)
       
   221 apply(auto)
       
   222 done
       
   223 
       
   224 text {*
       
   225   The value mkeps returns is always the correct POSIX
       
   226   value.
       
   227 *}
       
   228 
       
   229 lemma Prf_flat_L:
       
   230   assumes "\<turnstile> v : r" shows "flat v \<in> L r"
       
   231 using assms
       
   232 apply(induct v r rule: Prf.induct)
       
   233 apply(auto simp add: Sequ_def)
       
   234 done
       
   235 
       
   236 lemma L_flat_Prf:
       
   237   "L(r) = {flat v | v. \<turnstile> v : r}"
       
   238 apply(induct r)
       
   239 apply(auto dest: Prf_flat_L simp add: Sequ_def)
       
   240 apply (metis Prf.intros(4) flat.simps(1))
       
   241 apply (metis Prf.intros(5) flat.simps(2))
       
   242 apply (metis Prf.intros(1) flat.simps(5))
       
   243 apply (metis Prf.intros(2) flat.simps(3))
       
   244 apply (metis Prf.intros(3) flat.simps(4))
       
   245 apply(erule Prf.cases)
       
   246 apply(auto)
       
   247 done
       
   248 
       
   249 
       
   250 definition prefix :: "string \<Rightarrow> string \<Rightarrow> bool" ("_ \<sqsubseteq> _" [100, 100] 100)
       
   251 where
       
   252   "s1 \<sqsubseteq> s2 \<equiv> \<exists>s3. s1 @ s3 = s2"
       
   253 
       
   254 definition sprefix :: "string \<Rightarrow> string \<Rightarrow> bool" ("_ \<sqsubset> _" [100, 100] 100)
       
   255 where
       
   256   "s1 \<sqsubset> s2 \<equiv> (s1 \<sqsubseteq> s2 \<and> s1 \<noteq> s2)"
       
   257 
       
   258 lemma length_sprefix:
       
   259   "s1 \<sqsubset> s2 \<Longrightarrow> length s1 < length s2"
       
   260 unfolding sprefix_def prefix_def
       
   261 by (auto)
       
   262 
       
   263 definition Prefixes :: "string \<Rightarrow> string set" where
       
   264   "Prefixes s \<equiv> {sp. sp \<sqsubseteq> s}"
       
   265 
       
   266 definition Suffixes :: "string \<Rightarrow> string set" where
       
   267   "Suffixes s \<equiv> rev ` (Prefixes (rev s))"
       
   268 
       
   269 lemma Suffixes_in: 
       
   270   "\<exists>s1. s1 @ s2 = s3 \<Longrightarrow> s2 \<in> Suffixes s3"
       
   271 unfolding Suffixes_def Prefixes_def prefix_def image_def
       
   272 apply(auto)
       
   273 by (metis rev_rev_ident)
       
   274 
       
   275 lemma Prefixes_Cons:
       
   276   "Prefixes (c # s) = {[]} \<union> {c # sp | sp. sp \<in> Prefixes s}"
       
   277 unfolding Prefixes_def prefix_def
       
   278 apply(auto simp add: append_eq_Cons_conv) 
       
   279 done
       
   280 
       
   281 lemma finite_Prefixes:
       
   282   "finite (Prefixes s)"
       
   283 apply(induct s)
       
   284 apply(auto simp add: Prefixes_def prefix_def)[1]
       
   285 apply(simp add: Prefixes_Cons)
       
   286 done
       
   287 
       
   288 lemma finite_Suffixes:
       
   289   "finite (Suffixes s)"
       
   290 unfolding Suffixes_def
       
   291 apply(rule finite_imageI)
       
   292 apply(rule finite_Prefixes)
       
   293 done
       
   294 
       
   295 lemma prefix_Cons:
       
   296   "((c # s1) \<sqsubseteq> (c # s2)) = (s1 \<sqsubseteq> s2)"
       
   297 apply(auto simp add: prefix_def)
       
   298 done
       
   299 
       
   300 lemma prefix_append:
       
   301   "((s @ s1) \<sqsubseteq> (s @ s2)) = (s1 \<sqsubseteq> s2)"
       
   302 apply(induct s)
       
   303 apply(simp)
       
   304 apply(simp add: prefix_Cons)
       
   305 done
       
   306 
       
   307 
       
   308 
       
   309 definition Values :: "rexp \<Rightarrow> string \<Rightarrow> val set" where
       
   310   "Values r s \<equiv> {v. \<turnstile> v : r \<and> flat v \<sqsubseteq> s}"
       
   311 
       
   312 definition rest :: "val \<Rightarrow> string \<Rightarrow> string" where
       
   313   "rest v s \<equiv> drop (length (flat v)) s"
       
   314 
       
   315 lemma rest_Suffixes:
       
   316   "rest v s \<in> Suffixes s"
       
   317 unfolding rest_def
       
   318 by (metis Suffixes_in append_take_drop_id)
       
   319 
       
   320 
       
   321 lemma Values_recs:
       
   322   "Values (NULL) s = {}"
       
   323   "Values (EMPTY) s = {Void}"
       
   324   "Values (CHAR c) s = (if [c] \<sqsubseteq> s then {Char c} else {})" 
       
   325   "Values (ALT r1 r2) s = {Left v | v. v \<in> Values r1 s} \<union> {Right v | v. v \<in> Values r2 s}"
       
   326   "Values (SEQ r1 r2) s = {Seq v1 v2 | v1 v2. v1 \<in> Values r1 s \<and> v2 \<in> Values r2 (rest v1 s)}"
       
   327 unfolding Values_def
       
   328 apply(auto)
       
   329 (*NULL*)
       
   330 apply(erule Prf.cases)
       
   331 apply(simp_all)[5]
       
   332 (*EMPTY*)
       
   333 apply(erule Prf.cases)
       
   334 apply(simp_all)[5]
       
   335 apply(rule Prf.intros)
       
   336 apply (metis append_Nil prefix_def)
       
   337 (*CHAR*)
       
   338 apply(erule Prf.cases)
       
   339 apply(simp_all)[5]
       
   340 apply(rule Prf.intros)
       
   341 apply(erule Prf.cases)
       
   342 apply(simp_all)[5]
       
   343 (*ALT*)
       
   344 apply(erule Prf.cases)
       
   345 apply(simp_all)[5]
       
   346 apply (metis Prf.intros(2))
       
   347 apply (metis Prf.intros(3))
       
   348 (*SEQ*)
       
   349 apply(erule Prf.cases)
       
   350 apply(simp_all)[5]
       
   351 apply (simp add: append_eq_conv_conj prefix_def rest_def)
       
   352 apply (metis Prf.intros(1))
       
   353 apply (simp add: append_eq_conv_conj prefix_def rest_def)
       
   354 done
       
   355 
       
   356 lemma Values_finite:
       
   357   "finite (Values r s)"
       
   358 apply(induct r arbitrary: s)
       
   359 apply(simp_all add: Values_recs)
       
   360 thm finite_surj
       
   361 apply(rule_tac f="\<lambda>(x, y). Seq x y" and 
       
   362                A="{(v1, v2) | v1 v2. v1 \<in> Values r1 s \<and> v2 \<in> Values r2 (rest v1 s)}" in finite_surj)
       
   363 prefer 2
       
   364 apply(auto)[1]
       
   365 apply(rule_tac B="\<Union>sp \<in> Suffixes s. {(v1, v2). v1 \<in> Values r1 s \<and> v2 \<in> Values r2 sp}" in finite_subset)
       
   366 apply(auto)[1]
       
   367 apply (metis rest_Suffixes)
       
   368 apply(rule finite_UN_I)
       
   369 apply(rule finite_Suffixes)
       
   370 apply(simp)
       
   371 done
       
   372 
       
   373 section {* Greedy Ordering according to Frisch/Cardelli *}
       
   374 
       
   375 inductive GrOrd :: "val \<Rightarrow> val \<Rightarrow> bool" ("_ \<prec> _")
       
   376 where 
       
   377   "v1 \<prec> v1' \<Longrightarrow> (Seq v1 v2) \<prec> (Seq v1' v2')"
       
   378 | "v2 \<prec> v2' \<Longrightarrow> (Seq v1 v2) \<prec> (Seq v1 v2')"
       
   379 | "v1 \<prec> v2 \<Longrightarrow> (Left v1) \<prec> (Left v2)"
       
   380 | "v1 \<prec> v2 \<Longrightarrow> (Right v1) \<prec> (Right v2)"
       
   381 | "(Right v1) \<prec> (Left v2)"
       
   382 | "(Char c) \<prec> (Char c)"
       
   383 | "(Void) \<prec> (Void)"
       
   384 
       
   385 lemma Gr_refl:
       
   386   assumes "\<turnstile> v : r"
       
   387   shows "v \<prec> v"
       
   388 using assms
       
   389 apply(induct)
       
   390 apply(auto intro: GrOrd.intros)
       
   391 done
       
   392 
       
   393 lemma Gr_total:
       
   394   assumes "\<turnstile> v1 : r" "\<turnstile> v2 : r"
       
   395   shows "v1 \<prec> v2 \<or> v2 \<prec> v1"
       
   396 using assms
       
   397 apply(induct v1 r arbitrary: v2 rule: Prf.induct)
       
   398 apply(rotate_tac 4)
       
   399 apply(erule Prf.cases)
       
   400 apply(simp_all)[5]
       
   401 apply(clarify)
       
   402 apply (metis GrOrd.intros(1) GrOrd.intros(2))
       
   403 apply(rotate_tac 2)
       
   404 apply(erule Prf.cases)
       
   405 apply(simp_all)
       
   406 apply(clarify)
       
   407 apply (metis GrOrd.intros(3))
       
   408 apply(clarify)
       
   409 apply (metis GrOrd.intros(5))
       
   410 apply(rotate_tac 2)
       
   411 apply(erule Prf.cases)
       
   412 apply(simp_all)
       
   413 apply(clarify)
       
   414 apply (metis GrOrd.intros(5))
       
   415 apply(clarify)
       
   416 apply (metis GrOrd.intros(4))
       
   417 apply(erule Prf.cases)
       
   418 apply(simp_all)
       
   419 apply (metis GrOrd.intros(7))
       
   420 apply(erule Prf.cases)
       
   421 apply(simp_all)
       
   422 apply (metis GrOrd.intros(6))
       
   423 done
       
   424 
       
   425 lemma Gr_trans: 
       
   426   assumes "v1 \<prec> v2" "v2 \<prec> v3" "\<turnstile> v1 : r" "\<turnstile> v2 : r" "\<turnstile> v3 : r"
       
   427   shows "v1 \<prec> v3"
       
   428 using assms
       
   429 apply(induct r arbitrary: v1 v2 v3)
       
   430 apply(erule Prf.cases)
       
   431 apply(simp_all)[5]
       
   432 apply(erule Prf.cases)
       
   433 apply(simp_all)[5]
       
   434 apply(erule Prf.cases)
       
   435 apply(simp_all)[5]
       
   436 apply(erule Prf.cases)
       
   437 apply(simp_all)[5]
       
   438 apply(erule Prf.cases)
       
   439 apply(simp_all)[5]
       
   440 defer
       
   441 (* ALT case *)
       
   442 apply(erule Prf.cases)
       
   443 apply(simp_all (no_asm_use))[5]
       
   444 apply(erule Prf.cases)
       
   445 apply(simp_all (no_asm_use))[5]
       
   446 apply(erule Prf.cases)
       
   447 apply(simp_all (no_asm_use))[5]
       
   448 apply(clarify)
       
   449 apply(erule GrOrd.cases)
       
   450 apply(simp_all (no_asm_use))[7]
       
   451 apply(erule GrOrd.cases)
       
   452 apply(simp_all (no_asm_use))[7]
       
   453 apply (metis GrOrd.intros(3))
       
   454 apply(clarify)
       
   455 apply(erule GrOrd.cases)
       
   456 apply(simp_all (no_asm_use))[7]
       
   457 apply(erule GrOrd.cases)
       
   458 apply(simp_all (no_asm_use))[7]
       
   459 apply(erule Prf.cases)
       
   460 apply(simp_all (no_asm_use))[5]
       
   461 apply(clarify)
       
   462 apply(erule GrOrd.cases)
       
   463 apply(simp_all (no_asm_use))[7]
       
   464 apply(clarify)
       
   465 apply(erule GrOrd.cases)
       
   466 apply(simp_all (no_asm_use))[7]
       
   467 apply(erule Prf.cases)
       
   468 apply(simp_all (no_asm_use))[5]
       
   469 apply(erule Prf.cases)
       
   470 apply(simp_all (no_asm_use))[5]
       
   471 apply(clarify)
       
   472 apply(erule GrOrd.cases)
       
   473 apply(simp_all (no_asm_use))[7]
       
   474 apply(erule GrOrd.cases)
       
   475 apply(simp_all (no_asm_use))[7]
       
   476 apply (metis GrOrd.intros(5))
       
   477 apply(clarify)
       
   478 apply(erule GrOrd.cases)
       
   479 apply(simp_all (no_asm_use))[7]
       
   480 apply(erule GrOrd.cases)
       
   481 apply(simp_all (no_asm_use))[7]
       
   482 apply(erule Prf.cases)
       
   483 apply(simp_all (no_asm_use))[5]
       
   484 apply(clarify)
       
   485 apply(erule GrOrd.cases)
       
   486 apply(simp_all (no_asm_use))[7]
       
   487 apply(erule GrOrd.cases)
       
   488 apply(simp_all (no_asm_use))[7]
       
   489 apply (metis GrOrd.intros(5))
       
   490 apply(clarify)
       
   491 apply(erule GrOrd.cases)
       
   492 apply(simp_all (no_asm_use))[7]
       
   493 apply(erule GrOrd.cases)
       
   494 apply(simp_all (no_asm_use))[7]
       
   495 apply (metis GrOrd.intros(4))
       
   496 (* seq case *)
       
   497 apply(erule Prf.cases)
       
   498 apply(simp_all (no_asm_use))[5]
       
   499 apply(erule Prf.cases)
       
   500 apply(simp_all (no_asm_use))[5]
       
   501 apply(erule Prf.cases)
       
   502 apply(simp_all (no_asm_use))[5]
       
   503 apply(clarify)
       
   504 apply(erule GrOrd.cases)
       
   505 apply(simp_all (no_asm_use))[7]
       
   506 apply(erule GrOrd.cases)
       
   507 apply(simp_all (no_asm_use))[7]
       
   508 apply(clarify)
       
   509 apply (metis GrOrd.intros(1))
       
   510 apply (metis GrOrd.intros(1))
       
   511 apply(erule GrOrd.cases)
       
   512 apply(simp_all (no_asm_use))[7]
       
   513 apply (metis GrOrd.intros(1))
       
   514 by (metis GrOrd.intros(1) Gr_refl)
       
   515 
       
   516 definition
       
   517   GrMaxM :: "val set => val" where
       
   518   "GrMaxM S == SOME v.  v \<in> S \<and> (\<forall>v' \<in> S. v' \<prec> v)"
       
   519 
       
   520 definition
       
   521   "GrMax r s \<equiv> GrMaxM {v. \<turnstile> v : r \<and> flat v = s}"
       
   522 
       
   523 inductive ValOrd3 :: "val \<Rightarrow> val \<Rightarrow> bool" ("_ 3\<succ> _" [100, 100] 100)
       
   524 where
       
   525   "v2 3\<succ> v2' \<Longrightarrow> (Seq v1 v2) 3\<succ> (Seq v1 v2')" 
       
   526 | "v1 3\<succ> v1' \<Longrightarrow> (Seq v1 v2) 3\<succ> (Seq v1' v2')" 
       
   527 | "length (flat v1) \<ge> length (flat v2) \<Longrightarrow> (Left v1) 3\<succ> (Right v2)"
       
   528 | "length (flat v2) > length (flat v1) \<Longrightarrow> (Right v2) 3\<succ> (Left v1)"
       
   529 | "v2 3\<succ> v2' \<Longrightarrow> (Right v2) 3\<succ> (Right v2')"
       
   530 | "v1 3\<succ> v1' \<Longrightarrow> (Left v1) 3\<succ> (Left v1')"
       
   531 | "Void 3\<succ> Void"
       
   532 | "(Char c) 3\<succ> (Char c)"
       
   533 
       
   534 
       
   535 section {* Sulzmann's Ordering of values *}
       
   536 
       
   537 inductive ValOrd :: "val \<Rightarrow> rexp \<Rightarrow> val \<Rightarrow> bool" ("_ \<succ>_ _" [100, 100, 100] 100)
       
   538 where
       
   539   "v2 \<succ>r2 v2' \<Longrightarrow> (Seq v1 v2) \<succ>(SEQ r1 r2) (Seq v1 v2')" 
       
   540 | "\<lbrakk>v1 \<succ>r1 v1'; v1 \<noteq> v1'\<rbrakk> \<Longrightarrow> (Seq v1 v2) \<succ>(SEQ r1 r2) (Seq v1' v2')" 
       
   541 | "length (flat v1) \<ge> length (flat v2) \<Longrightarrow> (Left v1) \<succ>(ALT r1 r2) (Right v2)"
       
   542 | "length (flat v2) > length (flat v1) \<Longrightarrow> (Right v2) \<succ>(ALT r1 r2) (Left v1)"
       
   543 | "v2 \<succ>r2 v2' \<Longrightarrow> (Right v2) \<succ>(ALT r1 r2) (Right v2')"
       
   544 | "v1 \<succ>r1 v1' \<Longrightarrow> (Left v1) \<succ>(ALT r1 r2) (Left v1')"
       
   545 | "Void \<succ>EMPTY Void"
       
   546 | "(Char c) \<succ>(CHAR c) (Char c)"
       
   547 
       
   548 inductive ValOrdStr :: "string \<Rightarrow> val \<Rightarrow> val \<Rightarrow> bool" ("_ \<turnstile> _ \<succ>_" [100, 100, 100] 100)
       
   549 where
       
   550   "\<lbrakk>s \<turnstile> v1 \<succ> v1'; rest v1 s \<turnstile> v2 \<succ> v2'\<rbrakk> \<Longrightarrow> s \<turnstile> (Seq v1 v2) \<succ> (Seq v1' v2')" 
       
   551 | "\<lbrakk>flat v2 \<sqsubseteq> flat v1; flat v1 \<sqsubseteq> s\<rbrakk> \<Longrightarrow> s \<turnstile> (Left v1) \<succ> (Right v2)"
       
   552 | "\<lbrakk>flat v1 \<sqsubset> flat v2; flat v2 \<sqsubseteq> s\<rbrakk> \<Longrightarrow> s \<turnstile> (Right v2) \<succ> (Left v1)"
       
   553 | "s \<turnstile> v2 \<succ> v2' \<Longrightarrow> s \<turnstile> (Right v2) \<succ> (Right v2')"
       
   554 | "s \<turnstile> v1 \<succ> v1' \<Longrightarrow> s \<turnstile> (Left v1) \<succ> (Left v1')"
       
   555 | "s \<turnstile> Void \<succ> Void"
       
   556 | "(c#s) \<turnstile> (Char c) \<succ> (Char c)"
       
   557 
       
   558 inductive ValOrd2 :: "val \<Rightarrow> val \<Rightarrow> bool" ("_ 2\<succ> _" [100, 100] 100)
       
   559 where
       
   560   "v2 2\<succ> v2' \<Longrightarrow> (Seq v1 v2) 2\<succ> (Seq v1 v2')" 
       
   561 | "\<lbrakk>v1 2\<succ> v1'; v1 \<noteq> v1'\<rbrakk> \<Longrightarrow> (Seq v1 v2) 2\<succ> (Seq v1' v2')" 
       
   562 | "length (flat v1) \<ge> length (flat v2) \<Longrightarrow> (Left v1) 2\<succ> (Right v2)"
       
   563 | "length (flat v2) > length (flat v1) \<Longrightarrow> (Right v2) 2\<succ> (Left v1)"
       
   564 | "v2 2\<succ> v2' \<Longrightarrow> (Right v2) 2\<succ> (Right v2')"
       
   565 | "v1 2\<succ> v1' \<Longrightarrow> (Left v1) 2\<succ> (Left v1')"
       
   566 | "Void 2\<succ> Void"
       
   567 | "(Char c) 2\<succ> (Char c)"
       
   568 
       
   569 lemma Ord1:
       
   570   "v1 \<succ>r v2 \<Longrightarrow> v1 2\<succ> v2"
       
   571 apply(induct rule: ValOrd.induct)
       
   572 apply(auto intro: ValOrd2.intros)
       
   573 done
       
   574 
       
   575 lemma Ord2:
       
   576   "v1 2\<succ> v2 \<Longrightarrow> \<exists>r. v1 \<succ>r v2"
       
   577 apply(induct v1 v2 rule: ValOrd2.induct)
       
   578 apply(auto intro: ValOrd.intros)
       
   579 done
       
   580 
       
   581 lemma Ord3:
       
   582   "\<lbrakk>v1 2\<succ> v2; \<turnstile> v1 : r\<rbrakk> \<Longrightarrow> v1 \<succ>r v2"
       
   583 apply(induct v1 v2 arbitrary: r rule: ValOrd2.induct)
       
   584 apply(auto intro: ValOrd.intros elim: Prf.cases)
       
   585 done
       
   586 
       
   587 
       
   588 lemma ValOrd_refl:
       
   589   assumes "\<turnstile> v : r"
       
   590   shows "v \<succ>r v"
       
   591 using assms
       
   592 apply(induct)
       
   593 apply(auto intro: ValOrd.intros)
       
   594 done
       
   595 
       
   596 lemma 
       
   597   "flat Void = []"
       
   598   "flat (Seq Void Void) = []"
       
   599 apply(simp_all)
       
   600 done
       
   601 
       
   602 
       
   603 lemma ValOrd_total:
       
   604   shows "\<lbrakk>\<turnstile> v1 : r; \<turnstile> v2 : r\<rbrakk>  \<Longrightarrow> v1 \<succ>r v2 \<or> v2 \<succ>r v1"
       
   605 apply(induct r arbitrary: v1 v2)
       
   606 apply(auto)
       
   607 apply(erule Prf.cases)
       
   608 apply(simp_all)[5]
       
   609 apply(erule Prf.cases)
       
   610 apply(simp_all)[5]
       
   611 apply(erule Prf.cases)
       
   612 apply(simp_all)[5]
       
   613 apply (metis ValOrd.intros(7))
       
   614 apply(erule Prf.cases)
       
   615 apply(simp_all)[5]
       
   616 apply(erule Prf.cases)
       
   617 apply(simp_all)[5]
       
   618 apply (metis ValOrd.intros(8))
       
   619 apply(erule Prf.cases)
       
   620 apply(simp_all)[5]
       
   621 apply(erule Prf.cases)
       
   622 apply(simp_all)[5]
       
   623 apply(clarify)
       
   624 apply(case_tac "v1a = v1b")
       
   625 apply(simp)
       
   626 apply(rule ValOrd.intros(1))
       
   627 apply (metis ValOrd.intros(1))
       
   628 apply(rule ValOrd.intros(2))
       
   629 apply(auto)[2]
       
   630 apply(erule contrapos_np)
       
   631 apply(rule ValOrd.intros(2))
       
   632 apply(auto)
       
   633 apply(erule Prf.cases)
       
   634 apply(simp_all)[5]
       
   635 apply(erule Prf.cases)
       
   636 apply(simp_all)[5]
       
   637 apply (metis Ord1 Ord3 Prf.intros(2) ValOrd2.intros(6))
       
   638 apply(rule ValOrd.intros)
       
   639 apply(erule contrapos_np)
       
   640 apply(rule ValOrd.intros)
       
   641 apply (metis le_eq_less_or_eq neq_iff)
       
   642 apply(erule Prf.cases)
       
   643 apply(simp_all)[5]
       
   644 apply(rule ValOrd.intros)
       
   645 apply(erule contrapos_np)
       
   646 apply(rule ValOrd.intros)
       
   647 apply (metis le_eq_less_or_eq neq_iff)
       
   648 apply(rule ValOrd.intros)
       
   649 apply(erule contrapos_np)
       
   650 apply(rule ValOrd.intros)
       
   651 by metis
       
   652 
       
   653 lemma ValOrd_anti:
       
   654   shows "\<lbrakk>\<turnstile> v1 : r; \<turnstile> v2 : r; v1 \<succ>r v2; v2 \<succ>r v1\<rbrakk> \<Longrightarrow> v1 = v2"
       
   655 apply(induct r arbitrary: v1 v2)
       
   656 apply(erule Prf.cases)
       
   657 apply(simp_all)[5]
       
   658 apply(erule Prf.cases)
       
   659 apply(simp_all)[5]
       
   660 apply(erule Prf.cases)
       
   661 apply(simp_all)[5]
       
   662 apply(erule Prf.cases)
       
   663 apply(simp_all)[5]
       
   664 apply(erule Prf.cases)
       
   665 apply(simp_all)[5]
       
   666 apply(erule Prf.cases)
       
   667 apply(simp_all)[5]
       
   668 apply(erule Prf.cases)
       
   669 apply(simp_all)[5]
       
   670 apply(erule ValOrd.cases)
       
   671 apply(simp_all)[8]
       
   672 apply(erule ValOrd.cases)
       
   673 apply(simp_all)[8]
       
   674 apply(erule ValOrd.cases)
       
   675 apply(simp_all)[8]
       
   676 apply(erule Prf.cases)
       
   677 apply(simp_all)[5]
       
   678 apply(erule Prf.cases)
       
   679 apply(simp_all)[5]
       
   680 apply(erule ValOrd.cases)
       
   681 apply(simp_all)[8]
       
   682 apply(erule ValOrd.cases)
       
   683 apply(simp_all)[8]
       
   684 apply(erule ValOrd.cases)
       
   685 apply(simp_all)[8]
       
   686 apply(erule ValOrd.cases)
       
   687 apply(simp_all)[8]
       
   688 apply(erule Prf.cases)
       
   689 apply(simp_all)[5]
       
   690 apply(erule ValOrd.cases)
       
   691 apply(simp_all)[8]
       
   692 apply(erule ValOrd.cases)
       
   693 apply(simp_all)[8]
       
   694 apply(erule ValOrd.cases)
       
   695 apply(simp_all)[8]
       
   696 apply(erule ValOrd.cases)
       
   697 apply(simp_all)[8]
       
   698 done
       
   699 
       
   700 lemma refl_on_ValOrd:
       
   701   "refl_on (Values r s) {(v1, v2). v1 \<succ>r v2 \<and> v1 \<in> Values r s \<and> v2 \<in> Values r s}"
       
   702 unfolding refl_on_def
       
   703 apply(auto)
       
   704 apply(rule ValOrd_refl)
       
   705 apply(simp add: Values_def)
       
   706 done
       
   707 
       
   708 (*
       
   709 inductive ValOrd3 :: "val \<Rightarrow> rexp \<Rightarrow> val \<Rightarrow> bool" ("_ 3\<succ>_ _" [100, 100, 100] 100)
       
   710 where
       
   711   "\<lbrakk>v2 3\<succ>r2 v2'; \<turnstile> v1 : r1\<rbrakk> \<Longrightarrow> (Seq v1 v2) 3\<succ>(SEQ r1 r2) (Seq v1 v2')" 
       
   712 | "\<lbrakk>v1 3\<succ>r1 v1'; v1 \<noteq> v1'; flat v2 = flat v2'; \<turnstile> v2 : r2; \<turnstile> v2' : r2\<rbrakk> 
       
   713       \<Longrightarrow> (Seq v1 v2) 3\<succ>(SEQ r1 r2) (Seq v1' v2')" 
       
   714 | "length (flat v1) \<ge> length (flat v2) \<Longrightarrow> (Left v1) 3\<succ>(ALT r1 r2) (Right v2)"
       
   715 | "length (flat v2) > length (flat v1) \<Longrightarrow> (Right v2) 3\<succ>(ALT r1 r2) (Left v1)"
       
   716 | "v2 3\<succ>r2 v2' \<Longrightarrow> (Right v2) 3\<succ>(ALT r1 r2) (Right v2')"
       
   717 | "v1 3\<succ>r1 v1' \<Longrightarrow> (Left v1) 3\<succ>(ALT r1 r2) (Left v1')"
       
   718 | "Void 3\<succ>EMPTY Void"
       
   719 | "(Char c) 3\<succ>(CHAR c) (Char c)"
       
   720 *)
       
   721 
       
   722 section {* Posix definition *}
       
   723 
       
   724 definition POSIX :: "val \<Rightarrow> rexp \<Rightarrow> bool" 
       
   725 where
       
   726   "POSIX v r \<equiv> (\<turnstile> v : r \<and> (\<forall>v'. (\<turnstile> v' : r \<and> flat v = flat v') \<longrightarrow> v \<succ>r v'))"
       
   727 
       
   728 definition POSIX2 :: "val \<Rightarrow> rexp \<Rightarrow> bool" 
       
   729 where
       
   730   "POSIX2 v r \<equiv> (\<turnstile> v : r \<and> (\<forall>v'. (\<turnstile> v' : r \<and> flat v = flat v') \<longrightarrow> v 2\<succ> v'))"
       
   731 
       
   732 lemma "POSIX v r = POSIX2 v r"
       
   733 unfolding POSIX_def POSIX2_def
       
   734 apply(auto)
       
   735 apply(rule Ord1)
       
   736 apply(auto)
       
   737 apply(rule Ord3)
       
   738 apply(auto)
       
   739 done
       
   740 
       
   741 definition POSIXs :: "val \<Rightarrow> rexp \<Rightarrow> string \<Rightarrow> bool" 
       
   742 where
       
   743   "POSIXs v r s \<equiv> (\<Turnstile>s v : r \<and> (\<forall>v'. (\<Turnstile>s v' : r \<longrightarrow> v 2\<succ> v')))"
       
   744 
       
   745 definition POSIXn :: "val \<Rightarrow> rexp \<Rightarrow> nat \<Rightarrow> bool" 
       
   746 where
       
   747   "POSIXn v r n \<equiv> (\<TTurnstile>n v : r \<and> (\<forall>v'. (\<TTurnstile>n v' : r \<longrightarrow> v 2\<succ> v')))"
       
   748 
       
   749 lemma "POSIXn v r (length (flat v)) \<Longrightarrow> POSIX2 v r"
       
   750 unfolding POSIXn_def POSIX2_def
       
   751 apply(auto)
       
   752 apply (metis Prfn_Prf)
       
   753 by (metis Prf_Prfn)
       
   754 
       
   755 lemma Prfs_POSIX:
       
   756   "POSIXs v r s \<Longrightarrow> \<Turnstile>s v: r \<and> flat v = s"
       
   757 apply(simp add: POSIXs_def)
       
   758 by (metis Prfs_flat)
       
   759 
       
   760 
       
   761 lemma "POSIXs v r (flat v) =  POSIX2 v r"
       
   762 unfolding POSIXs_def POSIX2_def
       
   763 apply(auto)
       
   764 apply (metis Prfs_Prf)
       
   765 apply (metis Prf_Prfs)
       
   766 apply (metis Prf_Prfs)
       
   767 by (metis Prfs_Prf Prfs_flat)
       
   768 
       
   769 section {* POSIX for some constructors *}
       
   770 
       
   771 lemma POSIX_SEQ1:
       
   772   assumes "POSIX (Seq v1 v2) (SEQ r1 r2)" "\<turnstile> v1 : r1" "\<turnstile> v2 : r2"
       
   773   shows "POSIX v1 r1"
       
   774 using assms
       
   775 unfolding POSIX_def
       
   776 apply(auto)
       
   777 apply(drule_tac x="Seq v' v2" in spec)
       
   778 apply(simp)
       
   779 apply(erule impE)
       
   780 apply(rule Prf.intros)
       
   781 apply(simp)
       
   782 apply(simp)
       
   783 apply(erule ValOrd.cases)
       
   784 apply(simp_all)
       
   785 apply(clarify)
       
   786 by (metis ValOrd_refl)
       
   787 
       
   788 lemma POSIXn_SEQ1:
       
   789   assumes "POSIXn (Seq v1 v2) (SEQ r1 r2) (n1 + n2)" "\<TTurnstile>n1 v1 : r1" "\<TTurnstile>n2 v2 : r2"
       
   790   shows "POSIXn v1 r1 n1"
       
   791 using assms
       
   792 unfolding POSIXn_def
       
   793 apply(auto)
       
   794 apply(drule_tac x="Seq v' v2" in spec)
       
   795 apply(erule impE)
       
   796 apply(rule Prfn.intros)
       
   797 apply(simp)
       
   798 apply(simp)
       
   799 apply(erule ValOrd2.cases)
       
   800 apply(simp_all)
       
   801 apply(clarify)
       
   802 by (metis Ord1 Prfn_Prf ValOrd_refl)
       
   803 
       
   804 lemma POSIXs_SEQ1:
       
   805   assumes "POSIXs (Seq v1 v2) (SEQ r1 r2) (s1 @ s2)" "\<Turnstile>s1 v1 : r1" "\<Turnstile>s2 v2 : r2"
       
   806   shows "POSIXs v1 r1 s1"
       
   807 using assms
       
   808 unfolding POSIXs_def
       
   809 apply(auto)
       
   810 apply(drule_tac x="Seq v' v2" in spec)
       
   811 apply(erule impE)
       
   812 apply(rule Prfs.intros)
       
   813 apply(simp)
       
   814 apply(simp)
       
   815 apply(erule ValOrd2.cases)
       
   816 apply(simp_all)
       
   817 apply(clarify)
       
   818 by (metis Ord1 Prfs_Prf ValOrd_refl)
       
   819 
       
   820 lemma POSIX_SEQ2:
       
   821   assumes "POSIX (Seq v1 v2) (SEQ r1 r2)" "\<turnstile> v1 : r1" "\<turnstile> v2 : r2" 
       
   822   shows "POSIX v2 r2"
       
   823 using assms
       
   824 unfolding POSIX_def
       
   825 apply(auto)
       
   826 apply(drule_tac x="Seq v1 v'" in spec)
       
   827 apply(simp)
       
   828 apply(erule impE)
       
   829 apply(rule Prf.intros)
       
   830 apply(simp)
       
   831 apply(simp)
       
   832 apply(erule ValOrd.cases)
       
   833 apply(simp_all)
       
   834 done
       
   835 
       
   836 lemma POSIXn_SEQ2:
       
   837   assumes "POSIXn (Seq v1 v2) (SEQ r1 r2) (n1 + n2)" "\<TTurnstile>n1 v1 : r1" "\<TTurnstile>n2 v2 : r2" 
       
   838   shows "POSIXn v2 r2 n2"
       
   839 using assms
       
   840 unfolding POSIXn_def
       
   841 apply(auto)
       
   842 apply(drule_tac x="Seq v1 v'" in spec)
       
   843 apply(erule impE)
       
   844 apply(rule Prfn.intros)
       
   845 apply(simp)
       
   846 apply(simp)
       
   847 apply(erule ValOrd2.cases)
       
   848 apply(simp_all)
       
   849 done
       
   850 
       
   851 lemma POSIXs_SEQ2:
       
   852   assumes "POSIXs (Seq v1 v2) (SEQ r1 r2) (s1 @ s2)" "\<Turnstile>s1 v1 : r1" "\<Turnstile>s2 v2 : r2" 
       
   853   shows "POSIXs v2 r2 s2"
       
   854 using assms
       
   855 unfolding POSIXs_def
       
   856 apply(auto)
       
   857 apply(drule_tac x="Seq v1 v'" in spec)
       
   858 apply(erule impE)
       
   859 apply(rule Prfs.intros)
       
   860 apply(simp)
       
   861 apply(simp)
       
   862 apply(erule ValOrd2.cases)
       
   863 apply(simp_all)
       
   864 done
       
   865 
       
   866 lemma POSIX_ALT2:
       
   867   assumes "POSIX (Left v1) (ALT r1 r2)"
       
   868   shows "POSIX v1 r1"
       
   869 using assms
       
   870 unfolding POSIX_def
       
   871 apply(auto)
       
   872 apply(erule Prf.cases)
       
   873 apply(simp_all)[5]
       
   874 apply(drule_tac x="Left v'" in spec)
       
   875 apply(simp)
       
   876 apply(drule mp)
       
   877 apply(rule Prf.intros)
       
   878 apply(auto)
       
   879 apply(erule ValOrd.cases)
       
   880 apply(simp_all)
       
   881 done
       
   882 
       
   883 lemma POSIXn_ALT2:
       
   884   assumes "POSIXn (Left v1) (ALT r1 r2) n"
       
   885   shows "POSIXn v1 r1 n"
       
   886 using assms
       
   887 unfolding POSIXn_def
       
   888 apply(auto)
       
   889 apply(erule Prfn.cases)
       
   890 apply(simp_all)[5]
       
   891 apply(drule_tac x="Left v'" in spec)
       
   892 apply(drule mp)
       
   893 apply(rule Prfn.intros)
       
   894 apply(auto)
       
   895 apply(erule ValOrd2.cases)
       
   896 apply(simp_all)
       
   897 done
       
   898 
       
   899 lemma POSIXs_ALT2:
       
   900   assumes "POSIXs (Left v1) (ALT r1 r2) s"
       
   901   shows "POSIXs v1 r1 s"
       
   902 using assms
       
   903 unfolding POSIXs_def
       
   904 apply(auto)
       
   905 apply(erule Prfs.cases)
       
   906 apply(simp_all)[5]
       
   907 apply(drule_tac x="Left v'" in spec)
       
   908 apply(drule mp)
       
   909 apply(rule Prfs.intros)
       
   910 apply(auto)
       
   911 apply(erule ValOrd2.cases)
       
   912 apply(simp_all)
       
   913 done
       
   914 
       
   915 lemma POSIX_ALT1a:
       
   916   assumes "POSIX (Right v2) (ALT r1 r2)"
       
   917   shows "POSIX v2 r2"
       
   918 using assms
       
   919 unfolding POSIX_def
       
   920 apply(auto)
       
   921 apply(erule Prf.cases)
       
   922 apply(simp_all)[5]
       
   923 apply(drule_tac x="Right v'" in spec)
       
   924 apply(simp)
       
   925 apply(drule mp)
       
   926 apply(rule Prf.intros)
       
   927 apply(auto)
       
   928 apply(erule ValOrd.cases)
       
   929 apply(simp_all)
       
   930 done
       
   931 
       
   932 lemma POSIXn_ALT1a:
       
   933   assumes "POSIXn (Right v2) (ALT r1 r2) n"
       
   934   shows "POSIXn v2 r2 n"
       
   935 using assms
       
   936 unfolding POSIXn_def
       
   937 apply(auto)
       
   938 apply(erule Prfn.cases)
       
   939 apply(simp_all)[5]
       
   940 apply(drule_tac x="Right v'" in spec)
       
   941 apply(drule mp)
       
   942 apply(rule Prfn.intros)
       
   943 apply(auto)
       
   944 apply(erule ValOrd2.cases)
       
   945 apply(simp_all)
       
   946 done
       
   947 
       
   948 lemma POSIXs_ALT1a:
       
   949   assumes "POSIXs (Right v2) (ALT r1 r2) s"
       
   950   shows "POSIXs v2 r2 s"
       
   951 using assms
       
   952 unfolding POSIXs_def
       
   953 apply(auto)
       
   954 apply(erule Prfs.cases)
       
   955 apply(simp_all)[5]
       
   956 apply(drule_tac x="Right v'" in spec)
       
   957 apply(drule mp)
       
   958 apply(rule Prfs.intros)
       
   959 apply(auto)
       
   960 apply(erule ValOrd2.cases)
       
   961 apply(simp_all)
       
   962 done
       
   963 
       
   964 lemma POSIX_ALT1b:
       
   965   assumes "POSIX (Right v2) (ALT r1 r2)"
       
   966   shows "(\<forall>v'. (\<turnstile> v' : r2 \<and> flat v' = flat v2) \<longrightarrow> v2 \<succ>r2 v')"
       
   967 using assms
       
   968 apply(drule_tac POSIX_ALT1a)
       
   969 unfolding POSIX_def
       
   970 apply(auto)
       
   971 done
       
   972 
       
   973 lemma POSIXn_ALT1b:
       
   974   assumes "POSIXn (Right v2) (ALT r1 r2) n"
       
   975   shows "(\<forall>v'. (\<TTurnstile>n v' : r2 \<longrightarrow> v2 2\<succ> v'))"
       
   976 using assms
       
   977 apply(drule_tac POSIXn_ALT1a)
       
   978 unfolding POSIXn_def
       
   979 apply(auto)
       
   980 done
       
   981 
       
   982 lemma POSIXs_ALT1b:
       
   983   assumes "POSIXs (Right v2) (ALT r1 r2) s"
       
   984   shows "(\<forall>v'. (\<Turnstile>s v' : r2 \<longrightarrow> v2 2\<succ> v'))"
       
   985 using assms
       
   986 apply(drule_tac POSIXs_ALT1a)
       
   987 unfolding POSIXs_def
       
   988 apply(auto)
       
   989 done
       
   990 
       
   991 lemma POSIX_ALT_I1:
       
   992   assumes "POSIX v1 r1" 
       
   993   shows "POSIX (Left v1) (ALT r1 r2)"
       
   994 using assms
       
   995 unfolding POSIX_def
       
   996 apply(auto)
       
   997 apply (metis Prf.intros(2))
       
   998 apply(rotate_tac 2)
       
   999 apply(erule Prf.cases)
       
  1000 apply(simp_all)[5]
       
  1001 apply(auto)
       
  1002 apply(rule ValOrd.intros)
       
  1003 apply(auto)
       
  1004 apply(rule ValOrd.intros)
       
  1005 by simp
       
  1006 
       
  1007 lemma POSIXn_ALT_I1:
       
  1008   assumes "POSIXn v1 r1 n" 
       
  1009   shows "POSIXn (Left v1) (ALT r1 r2) n"
       
  1010 using assms
       
  1011 unfolding POSIXn_def
       
  1012 apply(auto)
       
  1013 apply (metis Prfn.intros(2))
       
  1014 apply(rotate_tac 2)
       
  1015 apply(erule Prfn.cases)
       
  1016 apply(simp_all)[5]
       
  1017 apply(auto)
       
  1018 apply(rule ValOrd2.intros)
       
  1019 apply(auto)
       
  1020 apply(rule ValOrd2.intros)
       
  1021 by (metis Prfn_flat order_refl)
       
  1022 
       
  1023 lemma POSIXs_ALT_I1:
       
  1024   assumes "POSIXs v1 r1 s" 
       
  1025   shows "POSIXs (Left v1) (ALT r1 r2) s"
       
  1026 using assms
       
  1027 unfolding POSIXs_def
       
  1028 apply(auto)
       
  1029 apply (metis Prfs.intros(2))
       
  1030 apply(rotate_tac 2)
       
  1031 apply(erule Prfs.cases)
       
  1032 apply(simp_all)[5]
       
  1033 apply(auto)
       
  1034 apply(rule ValOrd2.intros)
       
  1035 apply(auto)
       
  1036 apply(rule ValOrd2.intros)
       
  1037 by (metis Prfs_flat order_refl)
       
  1038 
       
  1039 lemma POSIX_ALT_I2:
       
  1040   assumes "POSIX v2 r2" "\<forall>v'. \<turnstile> v' : r1 \<longrightarrow> length (flat v2) > length (flat v')"
       
  1041   shows "POSIX (Right v2) (ALT r1 r2)"
       
  1042 using assms
       
  1043 unfolding POSIX_def
       
  1044 apply(auto)
       
  1045 apply (metis Prf.intros)
       
  1046 apply(rotate_tac 3)
       
  1047 apply(erule Prf.cases)
       
  1048 apply(simp_all)[5]
       
  1049 apply(auto)
       
  1050 apply(rule ValOrd.intros)
       
  1051 apply metis
       
  1052 done
       
  1053 
       
  1054 lemma POSIXs_ALT_I2:
       
  1055   assumes "POSIXs v2 r2 s" "\<forall>s' v'. \<Turnstile>s' v' : r1 \<longrightarrow> length s > length s'"
       
  1056   shows "POSIXs (Right v2) (ALT r1 r2) s"
       
  1057 using assms
       
  1058 unfolding POSIXs_def
       
  1059 apply(auto)
       
  1060 apply (metis Prfs.intros)
       
  1061 apply(rotate_tac 3)
       
  1062 apply(erule Prfs.cases)
       
  1063 apply(simp_all)[5]
       
  1064 apply(auto)
       
  1065 apply(rule ValOrd2.intros)
       
  1066 apply metis
       
  1067 done
       
  1068 
       
  1069 lemma 
       
  1070   "\<lbrakk>POSIX (mkeps r2) r2; nullable r2; \<not> nullable r1\<rbrakk>
       
  1071    \<Longrightarrow> POSIX (Right (mkeps r2)) (ALT r1 r2)" 
       
  1072 apply(auto simp add: POSIX_def)
       
  1073 apply(rule Prf.intros(3))
       
  1074 apply(auto)
       
  1075 apply(rotate_tac 3)
       
  1076 apply(erule Prf.cases)
       
  1077 apply(simp_all)[5]
       
  1078 apply(simp add: mkeps_flat)
       
  1079 apply(auto)[1]
       
  1080 apply (metis Prf_flat_L nullable_correctness)
       
  1081 apply(rule ValOrd.intros)
       
  1082 apply(auto)
       
  1083 done
       
  1084 
       
  1085 lemma mkeps_POSIX:
       
  1086   assumes "nullable r"
       
  1087   shows "POSIX (mkeps r) r"
       
  1088 using assms
       
  1089 apply(induct r)
       
  1090 apply(auto)[1]
       
  1091 apply(simp add: POSIX_def)
       
  1092 apply(auto)[1]
       
  1093 apply (metis Prf.intros(4))
       
  1094 apply(erule Prf.cases)
       
  1095 apply(simp_all)[5]
       
  1096 apply (metis ValOrd.intros)
       
  1097 apply(simp)
       
  1098 apply(auto)[1]
       
  1099 apply(simp add: POSIX_def)
       
  1100 apply(auto)[1]
       
  1101 apply (metis mkeps.simps(2) mkeps_nullable nullable.simps(5))
       
  1102 apply(rotate_tac 6)
       
  1103 apply(erule Prf.cases)
       
  1104 apply(simp_all)[5]
       
  1105 apply (simp add: mkeps_flat)
       
  1106 apply(case_tac "mkeps r1a = v1")
       
  1107 apply(simp)
       
  1108 apply (metis ValOrd.intros(1))
       
  1109 apply (rule ValOrd.intros(2))
       
  1110 apply metis
       
  1111 apply(simp)
       
  1112 (* ALT case *)
       
  1113 thm mkeps.simps
       
  1114 apply(simp)
       
  1115 apply(erule disjE)
       
  1116 apply(simp)
       
  1117 apply (metis POSIX_ALT_I1)
       
  1118 (* *)
       
  1119 apply(auto)[1]
       
  1120 thm  POSIX_ALT_I1
       
  1121 apply (metis POSIX_ALT_I1)
       
  1122 apply(simp (no_asm) add: POSIX_def)
       
  1123 apply(auto)[1]
       
  1124 apply(rule Prf.intros(3))
       
  1125 apply(simp only: POSIX_def)
       
  1126 apply(rotate_tac 4)
       
  1127 apply(erule Prf.cases)
       
  1128 apply(simp_all)[5]
       
  1129 thm mkeps_flat
       
  1130 apply(simp add: mkeps_flat)
       
  1131 apply(auto)[1]
       
  1132 thm Prf_flat_L nullable_correctness
       
  1133 apply (metis Prf_flat_L nullable_correctness)
       
  1134 apply(rule ValOrd.intros)
       
  1135 apply(subst (asm) POSIX_def)
       
  1136 apply(clarify)
       
  1137 apply(drule_tac x="v2" in spec)
       
  1138 by simp
       
  1139 
       
  1140 
       
  1141 section {* Derivatives *}
       
  1142 
       
  1143 fun
       
  1144  der :: "char \<Rightarrow> rexp \<Rightarrow> rexp"
       
  1145 where
       
  1146   "der c (NULL) = NULL"
       
  1147 | "der c (EMPTY) = NULL"
       
  1148 | "der c (CHAR c') = (if c = c' then EMPTY else NULL)"
       
  1149 | "der c (ALT r1 r2) = ALT (der c r1) (der c r2)"
       
  1150 | "der c (SEQ r1 r2) = 
       
  1151      (if nullable r1
       
  1152       then ALT (SEQ (der c r1) r2) (der c r2)
       
  1153       else SEQ (der c r1) r2)"
       
  1154 
       
  1155 fun 
       
  1156  ders :: "string \<Rightarrow> rexp \<Rightarrow> rexp"
       
  1157 where
       
  1158   "ders [] r = r"
       
  1159 | "ders (c # s) r = ders s (der c r)"
       
  1160 
       
  1161 fun
       
  1162  red :: "char \<Rightarrow> rexp \<Rightarrow> rexp"
       
  1163 where
       
  1164   "red c (NULL) = NULL"
       
  1165 | "red c (EMPTY) = CHAR c"
       
  1166 | "red c (CHAR c') = SEQ (CHAR c) (CHAR c')"
       
  1167 | "red c (ALT r1 r2) = ALT (red c r1) (red c r2)"
       
  1168 | "red c (SEQ r1 r2) = 
       
  1169      (if nullable r1
       
  1170       then ALT (SEQ (red c r1) r2) (red c r2)
       
  1171       else SEQ (red c r1) r2)"
       
  1172 
       
  1173 lemma L_der:
       
  1174   shows "L (der c r) = {s. c#s \<in> L r}"
       
  1175 apply(induct r)
       
  1176 apply(simp_all)
       
  1177 apply(simp add: Sequ_def)
       
  1178 apply(auto)[1]
       
  1179 apply (metis append_Cons)
       
  1180 apply (metis append_Nil nullable_correctness)
       
  1181 apply (metis append_eq_Cons_conv)
       
  1182 apply (metis append_Cons)
       
  1183 apply (metis Cons_eq_append_conv nullable_correctness)
       
  1184 apply(auto)
       
  1185 done
       
  1186 
       
  1187 lemma L_red:
       
  1188   shows "L (red c r) = {c#s | s. s \<in> L r}"
       
  1189 apply(induct r)
       
  1190 apply(simp_all)
       
  1191 apply(simp add: Sequ_def)
       
  1192 apply(simp add: Sequ_def)
       
  1193 apply(auto)[1]
       
  1194 apply (metis append_Nil nullable_correctness)
       
  1195 apply (metis append_Cons)
       
  1196 apply (metis append_Cons)
       
  1197 apply(auto)
       
  1198 done
       
  1199 
       
  1200 lemma L_red_der:
       
  1201   "L(red c (der c r)) = {c#s | s. c#s \<in> L r}"
       
  1202 apply(simp add: L_red)
       
  1203 apply(simp add: L_der)
       
  1204 done
       
  1205 
       
  1206 lemma L_der_red:
       
  1207   "L(der c (red c r)) = L r"
       
  1208 apply(simp add: L_der)
       
  1209 apply(simp add: L_red)
       
  1210 done
       
  1211 
       
  1212 section {* Injection function *}
       
  1213 
       
  1214 fun injval :: "rexp \<Rightarrow> char \<Rightarrow> val \<Rightarrow> val"
       
  1215 where
       
  1216   "injval (EMPTY) c Void = Char c"
       
  1217 | "injval (CHAR d) c Void = Char d"
       
  1218 | "injval (CHAR d) c (Char c') = Seq (Char d) (Char c')"
       
  1219 | "injval (ALT r1 r2) c (Left v1) = Left(injval r1 c v1)"
       
  1220 | "injval (ALT r1 r2) c (Right v2) = Right(injval r2 c v2)"
       
  1221 | "injval (SEQ r1 r2) c (Char c') = Seq (Char c) (Char c')"
       
  1222 | "injval (SEQ r1 r2) c (Seq v1 v2) = Seq (injval r1 c v1) v2"
       
  1223 | "injval (SEQ r1 r2) c (Left (Seq v1 v2)) = Seq (injval r1 c v1) v2"
       
  1224 | "injval (SEQ r1 r2) c (Right v2) = Seq (mkeps r1) (injval r2 c v2)"
       
  1225 
       
  1226 
       
  1227 section {* Projection function *}
       
  1228 
       
  1229 fun projval :: "rexp \<Rightarrow> char \<Rightarrow> val \<Rightarrow> val"
       
  1230 where
       
  1231   "projval (CHAR d) c _ = Void"
       
  1232 | "projval (ALT r1 r2) c (Left v1) = Left (projval r1 c v1)"
       
  1233 | "projval (ALT r1 r2) c (Right v2) = Right (projval r2 c v2)"
       
  1234 | "projval (SEQ r1 r2) c (Seq v1 v2) = 
       
  1235      (if flat v1 = [] then Right(projval r2 c v2) 
       
  1236       else if nullable r1 then Left (Seq (projval r1 c v1) v2)
       
  1237                           else Seq (projval r1 c v1) v2)"
       
  1238 
       
  1239 text {*
       
  1240   Injection value is related to r
       
  1241 *}
       
  1242 
       
  1243 lemma v3:
       
  1244   assumes "\<turnstile> v : der c r" shows "\<turnstile> (injval r c v) : r"
       
  1245 using assms
       
  1246 apply(induct arbitrary: v rule: der.induct)
       
  1247 apply(simp)
       
  1248 apply(erule Prf.cases)
       
  1249 apply(simp_all)[5]
       
  1250 apply(simp)
       
  1251 apply(erule Prf.cases)
       
  1252 apply(simp_all)[5]
       
  1253 apply(case_tac "c = c'")
       
  1254 apply(simp)
       
  1255 apply(erule Prf.cases)
       
  1256 apply(simp_all)[5]
       
  1257 apply (metis Prf.intros(5))
       
  1258 apply(simp)
       
  1259 apply(erule Prf.cases)
       
  1260 apply(simp_all)[5]
       
  1261 apply(simp)
       
  1262 apply(erule Prf.cases)
       
  1263 apply(simp_all)[5]
       
  1264 apply (metis Prf.intros(2))
       
  1265 apply (metis Prf.intros(3))
       
  1266 apply(simp)
       
  1267 apply(case_tac "nullable r1")
       
  1268 apply(simp)
       
  1269 apply(erule Prf.cases)
       
  1270 apply(simp_all)[5]
       
  1271 apply(auto)[1]
       
  1272 apply(erule Prf.cases)
       
  1273 apply(simp_all)[5]
       
  1274 apply(auto)[1]
       
  1275 apply (metis Prf.intros(1))
       
  1276 apply(auto)[1]
       
  1277 apply (metis Prf.intros(1) mkeps_nullable)
       
  1278 apply(simp)
       
  1279 apply(erule Prf.cases)
       
  1280 apply(simp_all)[5]
       
  1281 apply(auto)[1]
       
  1282 apply(rule Prf.intros)
       
  1283 apply(auto)[2]
       
  1284 done
       
  1285 
       
  1286 lemma v3_red:
       
  1287   assumes "\<turnstile> v : r" shows "\<turnstile> (injval (red c r) c v) : (red c r)"
       
  1288 using assms
       
  1289 apply(induct c r arbitrary: v rule: red.induct)
       
  1290 apply(simp)
       
  1291 apply(erule Prf.cases)
       
  1292 apply(simp_all)[5]
       
  1293 apply(simp)
       
  1294 apply(erule Prf.cases)
       
  1295 apply(simp_all)[5]
       
  1296 apply (metis Prf.intros(5))
       
  1297 apply(erule Prf.cases)
       
  1298 apply(simp_all)[5]
       
  1299 apply (metis Prf.intros(1) Prf.intros(5))
       
  1300 apply(erule Prf.cases)
       
  1301 apply(simp_all)[5]
       
  1302 apply (metis Prf.intros(2))
       
  1303 apply (metis Prf.intros(3))
       
  1304 apply(erule Prf.cases)
       
  1305 apply(simp_all)[5]
       
  1306 apply(auto)
       
  1307 prefer 2
       
  1308 apply (metis Prf.intros(1))
       
  1309 oops
       
  1310 
       
  1311 lemma v3s:
       
  1312   assumes "\<Turnstile>s v : der c r" shows "\<Turnstile>(c#s) (injval r c v) : r"
       
  1313 using assms
       
  1314 apply(induct arbitrary: s v rule: der.induct)
       
  1315 apply(simp)
       
  1316 apply(erule Prfs.cases)
       
  1317 apply(simp_all)[5]
       
  1318 apply(simp)
       
  1319 apply(erule Prfs.cases)
       
  1320 apply(simp_all)[5]
       
  1321 apply(case_tac "c = c'")
       
  1322 apply(simp)
       
  1323 apply(erule Prfs.cases)
       
  1324 apply(simp_all)[5]
       
  1325 apply (metis Prfs.intros(5))
       
  1326 apply(simp)
       
  1327 apply(erule Prfs.cases)
       
  1328 apply(simp_all)[5]
       
  1329 apply(simp)
       
  1330 apply(erule Prfs.cases)
       
  1331 apply(simp_all)[5]
       
  1332 apply (metis Prfs.intros(2))
       
  1333 apply (metis Prfs.intros(3))
       
  1334 apply(simp)
       
  1335 apply(case_tac "nullable r1")
       
  1336 apply(simp)
       
  1337 apply(erule Prfs.cases)
       
  1338 apply(simp_all)[5]
       
  1339 apply(auto)[1]
       
  1340 apply(erule Prfs.cases)
       
  1341 apply(simp_all)[5]
       
  1342 apply(auto)[1]
       
  1343 apply (metis Prfs.intros(1) append_Cons)
       
  1344 apply(auto)[1]
       
  1345 apply (metis Prfs.intros(1) append_Nil mkeps_nullable_s)
       
  1346 apply(simp)
       
  1347 apply(erule Prfs.cases)
       
  1348 apply(simp_all)[5]
       
  1349 apply(auto)[1]
       
  1350 by (metis Prfs.intros(1) append_Cons)
       
  1351 
       
  1352 lemma v3n:
       
  1353   assumes "\<TTurnstile>n v : der c r" shows "\<TTurnstile>(Suc n) (injval r c v) : r"
       
  1354 using assms
       
  1355 apply(induct arbitrary: n v rule: der.induct)
       
  1356 apply(simp)
       
  1357 apply(erule Prfn.cases)
       
  1358 apply(simp_all)[5]
       
  1359 apply(simp)
       
  1360 apply(erule Prfn.cases)
       
  1361 apply(simp_all)[5]
       
  1362 apply(case_tac "c = c'")
       
  1363 apply(simp)
       
  1364 apply(erule Prfn.cases)
       
  1365 apply(simp_all)[5]
       
  1366 apply (metis One_nat_def Prfn.intros(5))
       
  1367 apply(simp)
       
  1368 apply(erule Prfn.cases)
       
  1369 apply(simp_all)[5]
       
  1370 apply(simp)
       
  1371 apply(erule Prfn.cases)
       
  1372 apply(simp_all)[5]
       
  1373 apply (metis Prfn.intros(2))
       
  1374 apply (metis Prfn.intros(3))
       
  1375 apply(simp)
       
  1376 apply(case_tac "nullable r1")
       
  1377 apply(simp)
       
  1378 apply(erule Prfn.cases)
       
  1379 apply(simp_all)[5]
       
  1380 apply(auto)[1]
       
  1381 apply(erule Prfn.cases)
       
  1382 apply(simp_all)[5]
       
  1383 apply(auto)[1]
       
  1384 apply (metis Prfn.intros(1) add.commute add_Suc_right)
       
  1385 apply(auto)[1]
       
  1386 apply (metis Prfn.intros(1) mkeps_nullable_n plus_nat.add_0)
       
  1387 apply(simp)
       
  1388 apply(erule Prfn.cases)
       
  1389 apply(simp_all)[5]
       
  1390 apply(auto)[1]
       
  1391 by (metis Prfn.intros(1) add_Suc)
       
  1392 
       
  1393 lemma v3_proj:
       
  1394   assumes "\<turnstile> v : r" and "\<exists>s. (flat v) = c # s"
       
  1395   shows "\<turnstile> (projval r c v) : der c r"
       
  1396 using assms
       
  1397 apply(induct rule: Prf.induct)
       
  1398 prefer 4
       
  1399 apply(simp)
       
  1400 prefer 4
       
  1401 apply(simp)
       
  1402 apply (metis Prf.intros(4))
       
  1403 prefer 2
       
  1404 apply(simp)
       
  1405 apply (metis Prf.intros(2))
       
  1406 prefer 2
       
  1407 apply(simp)
       
  1408 apply (metis Prf.intros(3))
       
  1409 apply(auto)
       
  1410 apply(rule Prf.intros)
       
  1411 apply(simp)
       
  1412 apply (metis Prf_flat_L nullable_correctness)
       
  1413 apply(rule Prf.intros)
       
  1414 apply(rule Prf.intros)
       
  1415 apply (metis Cons_eq_append_conv)
       
  1416 apply(simp)
       
  1417 apply(rule Prf.intros)
       
  1418 apply (metis Cons_eq_append_conv)
       
  1419 apply(simp)
       
  1420 done
       
  1421 
       
  1422 lemma v3s_proj:
       
  1423   assumes "\<Turnstile>(c#s) v : r"
       
  1424   shows "\<Turnstile>s (projval r c v) : der c r"
       
  1425 using assms
       
  1426 apply(induct s\<equiv>"c#s" v r arbitrary: s rule: Prfs.induct)
       
  1427 prefer 4
       
  1428 apply(simp)
       
  1429 apply (metis Prfs.intros(4))
       
  1430 prefer 2
       
  1431 apply(simp)
       
  1432 apply (metis Prfs.intros(2))
       
  1433 prefer 2
       
  1434 apply(simp)
       
  1435 apply (metis Prfs.intros(3))
       
  1436 apply(auto)
       
  1437 apply(rule Prfs.intros)
       
  1438 apply (metis Prfs_flat append_Nil)
       
  1439 prefer 2
       
  1440 apply(rule Prfs.intros)
       
  1441 apply(subst (asm) append_eq_Cons_conv)
       
  1442 apply(auto)[1]
       
  1443 apply (metis Prfs_flat)
       
  1444 apply(rule Prfs.intros)
       
  1445 apply metis
       
  1446 apply(simp)
       
  1447 apply(subst (asm) append_eq_Cons_conv)
       
  1448 apply(auto)[1]
       
  1449 apply (metis Prf_flat_L Prfs_Prf nullable_correctness)
       
  1450 apply (metis Prfs_flat list.distinct(1))
       
  1451 apply(subst (asm) append_eq_Cons_conv)
       
  1452 apply(auto)[1]
       
  1453 apply (metis Prfs_flat)
       
  1454 by (metis Prfs.intros(1))
       
  1455 
       
  1456 text {*
       
  1457   The string behind the injection value is an added c
       
  1458 *}
       
  1459 
       
  1460 lemma v4s:
       
  1461   assumes "\<Turnstile>s v : der c r" shows "flat (injval r c v) = c # (flat v)"
       
  1462 using assms
       
  1463 apply(induct arbitrary: s v rule: der.induct)
       
  1464 apply(simp)
       
  1465 apply(erule Prfs.cases)
       
  1466 apply(simp_all)[5]
       
  1467 apply(simp)
       
  1468 apply(erule Prfs.cases)
       
  1469 apply(simp_all)[5]
       
  1470 apply(simp)
       
  1471 apply(case_tac "c = c'")
       
  1472 apply(simp)
       
  1473 apply(auto)[1]
       
  1474 apply(erule Prfs.cases)
       
  1475 apply(simp_all)[5]
       
  1476 apply(simp)
       
  1477 apply(erule Prfs.cases)
       
  1478 apply(simp_all)[5]
       
  1479 apply(simp)
       
  1480 apply(erule Prfs.cases)
       
  1481 apply(simp_all)[5]
       
  1482 apply(simp)
       
  1483 apply(case_tac "nullable r1")
       
  1484 apply(simp)
       
  1485 apply(erule Prfs.cases)
       
  1486 apply(simp_all (no_asm_use))[5]
       
  1487 apply(auto)[1]
       
  1488 apply(erule Prfs.cases)
       
  1489 apply(simp_all)[5]
       
  1490 apply(clarify)
       
  1491 apply(simp only: injval.simps flat.simps)
       
  1492 apply(auto)[1]
       
  1493 apply (metis mkeps_flat)
       
  1494 apply(simp)
       
  1495 apply(erule Prfs.cases)
       
  1496 apply(simp_all)[5]
       
  1497 done
       
  1498 
       
  1499 lemma v4:
       
  1500   assumes "\<turnstile> v : der c r" shows "flat (injval r c v) = c # (flat v)"
       
  1501 using assms
       
  1502 apply(induct arbitrary: v rule: der.induct)
       
  1503 apply(simp)
       
  1504 apply(erule Prf.cases)
       
  1505 apply(simp_all)[5]
       
  1506 apply(simp)
       
  1507 apply(erule Prf.cases)
       
  1508 apply(simp_all)[5]
       
  1509 apply(simp)
       
  1510 apply(case_tac "c = c'")
       
  1511 apply(simp)
       
  1512 apply(auto)[1]
       
  1513 apply(erule Prf.cases)
       
  1514 apply(simp_all)[5]
       
  1515 apply(simp)
       
  1516 apply(erule Prf.cases)
       
  1517 apply(simp_all)[5]
       
  1518 apply(simp)
       
  1519 apply(erule Prf.cases)
       
  1520 apply(simp_all)[5]
       
  1521 apply(simp)
       
  1522 apply(case_tac "nullable r1")
       
  1523 apply(simp)
       
  1524 apply(erule Prf.cases)
       
  1525 apply(simp_all (no_asm_use))[5]
       
  1526 apply(auto)[1]
       
  1527 apply(erule Prf.cases)
       
  1528 apply(simp_all)[5]
       
  1529 apply(clarify)
       
  1530 apply(simp only: injval.simps flat.simps)
       
  1531 apply(auto)[1]
       
  1532 apply (metis mkeps_flat)
       
  1533 apply(simp)
       
  1534 apply(erule Prf.cases)
       
  1535 apply(simp_all)[5]
       
  1536 done
       
  1537 
       
  1538 lemma v4_proj:
       
  1539   assumes "\<turnstile> v : r" and "\<exists>s. (flat v) = c # s"
       
  1540   shows "c # flat (projval r c v) = flat v"
       
  1541 using assms
       
  1542 apply(induct rule: Prf.induct)
       
  1543 prefer 4
       
  1544 apply(simp)
       
  1545 prefer 4
       
  1546 apply(simp)
       
  1547 prefer 2
       
  1548 apply(simp)
       
  1549 prefer 2
       
  1550 apply(simp)
       
  1551 apply(auto)
       
  1552 by (metis Cons_eq_append_conv)
       
  1553 
       
  1554 lemma v4_proj2:
       
  1555   assumes "\<turnstile> v : r" and "(flat v) = c # s"
       
  1556   shows "flat (projval r c v) = s"
       
  1557 using assms
       
  1558 by (metis list.inject v4_proj)
       
  1559 
       
  1560 lemma injval_inj: "inj_on (injval r c) {v. \<turnstile> v : der c r}"
       
  1561 apply(induct c r rule: der.induct)
       
  1562 unfolding inj_on_def
       
  1563 apply(auto)[1]
       
  1564 apply(erule Prf.cases)
       
  1565 apply(simp_all)[5]
       
  1566 apply(auto)[1]
       
  1567 apply(erule Prf.cases)
       
  1568 apply(simp_all)[5]
       
  1569 apply(auto)[1]
       
  1570 apply(erule Prf.cases)
       
  1571 apply(simp_all)[5]
       
  1572 apply(erule Prf.cases)
       
  1573 apply(simp_all)[5]
       
  1574 apply(erule Prf.cases)
       
  1575 apply(simp_all)[5]
       
  1576 apply(auto)[1]
       
  1577 apply(erule Prf.cases)
       
  1578 apply(simp_all)[5]
       
  1579 apply(erule Prf.cases)
       
  1580 apply(simp_all)[5]
       
  1581 apply(erule Prf.cases)
       
  1582 apply(simp_all)[5]
       
  1583 apply(auto)[1]
       
  1584 apply(erule Prf.cases)
       
  1585 apply(simp_all)[5]
       
  1586 apply(erule Prf.cases)
       
  1587 apply(simp_all)[5]
       
  1588 apply(clarify)
       
  1589 apply(erule Prf.cases)
       
  1590 apply(simp_all)[5]
       
  1591 apply(erule Prf.cases)
       
  1592 apply(simp_all)[5]
       
  1593 apply(clarify)
       
  1594 apply(erule Prf.cases)
       
  1595 apply(simp_all)[5]
       
  1596 apply(clarify)
       
  1597 apply (metis list.distinct(1) mkeps_flat v4)
       
  1598 apply(erule Prf.cases)
       
  1599 apply(simp_all)[5]
       
  1600 apply(clarify)
       
  1601 apply(rotate_tac 6)
       
  1602 apply(erule Prf.cases)
       
  1603 apply(simp_all)[5]
       
  1604 apply (metis list.distinct(1) mkeps_flat v4)
       
  1605 apply(erule Prf.cases)
       
  1606 apply(simp_all)[5]
       
  1607 apply(erule Prf.cases)
       
  1608 apply(simp_all)[5]
       
  1609 done
       
  1610 
       
  1611 lemma Values_nullable:
       
  1612   assumes "nullable r1"
       
  1613   shows "mkeps r1 \<in> Values r1 s"
       
  1614 using assms
       
  1615 apply(induct r1 arbitrary: s)
       
  1616 apply(simp_all)
       
  1617 apply(simp add: Values_recs)
       
  1618 apply(simp add: Values_recs)
       
  1619 apply(simp add: Values_recs)
       
  1620 apply(auto)[1]
       
  1621 done
       
  1622 
       
  1623 lemma Values_injval:
       
  1624   assumes "v \<in> Values (der c r) s"
       
  1625   shows "injval r c v \<in> Values r (c#s)"
       
  1626 using assms
       
  1627 apply(induct c r arbitrary: v s rule: der.induct)
       
  1628 apply(simp add: Values_recs)
       
  1629 apply(simp add: Values_recs)
       
  1630 apply(case_tac "c = c'")
       
  1631 apply(simp)
       
  1632 apply(simp add: Values_recs)
       
  1633 apply(simp add: prefix_def)
       
  1634 apply(simp)
       
  1635 apply(simp add: Values_recs)
       
  1636 apply(simp)
       
  1637 apply(simp add: Values_recs)
       
  1638 apply(auto)[1]
       
  1639 apply(case_tac "nullable r1")
       
  1640 apply(simp)
       
  1641 apply(simp add: Values_recs)
       
  1642 apply(auto)[1]
       
  1643 apply(simp add: rest_def)
       
  1644 apply(subst v4)
       
  1645 apply(simp add: Values_def)
       
  1646 apply(simp add: Values_def)
       
  1647 apply(rule Values_nullable)
       
  1648 apply(assumption)
       
  1649 apply(simp add: rest_def)
       
  1650 apply(subst mkeps_flat)
       
  1651 apply(assumption)
       
  1652 apply(simp)
       
  1653 apply(simp)
       
  1654 apply(simp add: Values_recs)
       
  1655 apply(auto)[1]
       
  1656 apply(simp add: rest_def)
       
  1657 apply(subst v4)
       
  1658 apply(simp add: Values_def)
       
  1659 apply(simp add: Values_def)
       
  1660 done
       
  1661 
       
  1662 lemma Values_projval:
       
  1663   assumes "v \<in> Values r (c#s)" "\<exists>s. flat v = c # s"
       
  1664   shows "projval r c v \<in> Values (der c r) s"
       
  1665 using assms
       
  1666 apply(induct r arbitrary: v s c rule: rexp.induct)
       
  1667 apply(simp add: Values_recs)
       
  1668 apply(simp add: Values_recs)
       
  1669 apply(case_tac "c = x")
       
  1670 apply(simp)
       
  1671 apply(simp add: Values_recs)
       
  1672 apply(simp)
       
  1673 apply(simp add: Values_recs)
       
  1674 apply(simp add: prefix_def)
       
  1675 apply(case_tac "nullable x1")
       
  1676 apply(simp)
       
  1677 apply(simp add: Values_recs)
       
  1678 apply(auto)[1]
       
  1679 apply(simp add: rest_def)
       
  1680 apply (metis hd_Cons_tl hd_append2 list.sel(1))
       
  1681 apply(simp add: rest_def)
       
  1682 apply(simp add: append_eq_Cons_conv)
       
  1683 apply(auto)[1]
       
  1684 apply(subst v4_proj2)
       
  1685 apply(simp add: Values_def)
       
  1686 apply(assumption)
       
  1687 apply(simp)
       
  1688 apply(simp)
       
  1689 apply(simp add: Values_recs)
       
  1690 apply(auto)[1]
       
  1691 apply(auto simp add: Values_def not_nullable_flat)[1]
       
  1692 apply(simp add: append_eq_Cons_conv)
       
  1693 apply(auto)[1]
       
  1694 apply(simp add: append_eq_Cons_conv)
       
  1695 apply(auto)[1]
       
  1696 apply(simp add: rest_def)
       
  1697 apply(subst v4_proj2)
       
  1698 apply(simp add: Values_def)
       
  1699 apply(assumption)
       
  1700 apply(simp)
       
  1701 apply(simp add: Values_recs)
       
  1702 apply(auto)[1]
       
  1703 done
       
  1704 
       
  1705 
       
  1706 definition "MValue v r s \<equiv> (v \<in> Values r s \<and> (\<forall>v' \<in> Values r s. v 2\<succ> v'))"
       
  1707 
       
  1708 lemma 
       
  1709   assumes "MValue v1 r1 s"
       
  1710   shows "MValue (Seq v1 v2) (SEQ r1 r2) s
       
  1711 
       
  1712 
       
  1713 lemma MValue_SEQE:
       
  1714   assumes "MValue v (SEQ r1 r2) s"
       
  1715   shows "(\<exists>v1 v2. MValue v1 r1 s \<and> MValue v2 r2 (rest v1 s) \<and> v = Seq v1 v2)"
       
  1716 using assms
       
  1717 apply(simp add: MValue_def)
       
  1718 apply(simp add: Values_recs)
       
  1719 apply(erule conjE)
       
  1720 apply(erule exE)+
       
  1721 apply(erule conjE)+
       
  1722 apply(simp)
       
  1723 apply(auto)
       
  1724 apply(drule_tac x="Seq x v2" in spec)
       
  1725 apply(drule mp)
       
  1726 apply(rule_tac x="x" in exI)
       
  1727 apply(rule_tac x="v2" in exI)
       
  1728 apply(simp)
       
  1729 oops
       
  1730 
       
  1731 
       
  1732 lemma MValue_ALTE:
       
  1733   assumes "MValue v (ALT r1 r2) s"
       
  1734   shows "(\<exists>vl. v = Left vl \<and> MValue vl r1 s \<and> (\<forall>vr \<in> Values r2 s. length (flat vr) \<le> length (flat vl))) \<or> 
       
  1735          (\<exists>vr. v = Right vr \<and> MValue vr r2 s \<and> (\<forall>vl \<in> Values r1 s. length (flat vl) < length (flat vr)))"
       
  1736 using assms
       
  1737 apply(simp add: MValue_def)
       
  1738 apply(simp add: Values_recs)
       
  1739 apply(auto)
       
  1740 apply(drule_tac x="Left x" in bspec)
       
  1741 apply(simp)
       
  1742 apply(erule ValOrd2.cases)
       
  1743 apply(simp_all)
       
  1744 apply(drule_tac x="Right vr" in bspec)
       
  1745 apply(simp)
       
  1746 apply(erule ValOrd2.cases)
       
  1747 apply(simp_all)
       
  1748 apply(drule_tac x="Right x" in bspec)
       
  1749 apply(simp)
       
  1750 apply(erule ValOrd2.cases)
       
  1751 apply(simp_all)
       
  1752 apply(drule_tac x="Left vl" in bspec)
       
  1753 apply(simp)
       
  1754 apply(erule ValOrd2.cases)
       
  1755 apply(simp_all)
       
  1756 done
       
  1757 
       
  1758 lemma MValue_ALTI1:
       
  1759   assumes "MValue vl r1 s"  "\<forall>vr \<in> Values r2 s. length (flat vr) \<le> length (flat vl)"
       
  1760   shows "MValue (Left vl) (ALT r1 r2) s"
       
  1761 using assms
       
  1762 apply(simp add: MValue_def)
       
  1763 apply(simp add: Values_recs)
       
  1764 apply(auto)
       
  1765 apply(rule ValOrd2.intros)
       
  1766 apply metis
       
  1767 apply(rule ValOrd2.intros)
       
  1768 apply metis
       
  1769 done
       
  1770 
       
  1771 lemma MValue_ALTI2:
       
  1772   assumes "MValue vr r2 s"  "\<forall>vl \<in> Values r1 s. length (flat vl) < length (flat vr)"
       
  1773   shows "MValue (Right vr) (ALT r1 r2) s"
       
  1774 using assms
       
  1775 apply(simp add: MValue_def)
       
  1776 apply(simp add: Values_recs)
       
  1777 apply(auto)
       
  1778 apply(rule ValOrd2.intros)
       
  1779 apply metis
       
  1780 apply(rule ValOrd2.intros)
       
  1781 apply metis
       
  1782 done
       
  1783 
       
  1784 lemma MValue_injval:
       
  1785   assumes "MValue v (der c r) s"
       
  1786   shows "MValue (injval r c v) r (c#s)"
       
  1787 using assms
       
  1788 apply(induct c r arbitrary: v s rule: der.induct)
       
  1789 apply(simp add: MValue_def)
       
  1790 apply(simp add: Values_recs)
       
  1791 apply(simp add: MValue_def)
       
  1792 apply(simp add: Values_recs)
       
  1793 apply(case_tac "c = c'")
       
  1794 apply(simp)
       
  1795 apply(simp add: MValue_def)
       
  1796 apply(simp add: Values_recs)
       
  1797 apply(simp add: prefix_def)
       
  1798 apply(rule ValOrd2.intros)
       
  1799 apply(simp)
       
  1800 apply(simp add: MValue_def)
       
  1801 apply(simp add: Values_recs)
       
  1802 apply(simp)
       
  1803 apply(drule MValue_ALTE)
       
  1804 apply(erule disjE)
       
  1805 apply(auto)[1]
       
  1806 apply(rule MValue_ALTI1)
       
  1807 apply(simp)
       
  1808 apply(subst v4)
       
  1809 apply(simp add: MValue_def Values_def)
       
  1810 apply(rule ballI)
       
  1811 apply(simp)
       
  1812 apply(case_tac "flat vr = []")
       
  1813 apply(simp)
       
  1814 apply(drule_tac x="projval r2 c vr" in bspec)
       
  1815 apply(rule Values_projval)
       
  1816 apply(simp)
       
  1817 apply(simp add: Values_def prefix_def)
       
  1818 apply(auto)[1]
       
  1819 apply(simp add: append_eq_Cons_conv)
       
  1820 apply(auto)[1]
       
  1821 apply(simp add: Values_def prefix_def)
       
  1822 apply(auto)[1]
       
  1823 apply(simp add: append_eq_Cons_conv)
       
  1824 apply(auto)[1]
       
  1825 apply(subst (asm) v4_proj2)
       
  1826 apply(assumption)
       
  1827 apply(assumption)
       
  1828 apply(simp)
       
  1829 apply(auto)[1]
       
  1830 apply(rule MValue_ALTI2)
       
  1831 apply(simp)
       
  1832 apply(subst v4)
       
  1833 apply(simp add: MValue_def Values_def)
       
  1834 apply(rule ballI)
       
  1835 apply(simp)
       
  1836 apply(case_tac "flat vl = []")
       
  1837 apply(simp)
       
  1838 apply(drule_tac x="projval r1 c vl" in bspec)
       
  1839 apply(rule Values_projval)
       
  1840 apply(simp)
       
  1841 apply(simp add: Values_def prefix_def)
       
  1842 apply(auto)[1]
       
  1843 apply(simp add: append_eq_Cons_conv)
       
  1844 apply(auto)[1]
       
  1845 apply(simp add: Values_def prefix_def)
       
  1846 apply(auto)[1]
       
  1847 apply(simp add: append_eq_Cons_conv)
       
  1848 apply(auto)[1]
       
  1849 apply(subst (asm) v4_proj2)
       
  1850 apply(simp add: MValue_def Values_def)
       
  1851 apply(assumption)
       
  1852 apply(assumption)
       
  1853 apply(case_tac "nullable r1")
       
  1854 defer
       
  1855 apply(simp)
       
  1856 apply(frule MValue_SEQE)
       
  1857 apply(auto)[1]
       
  1858 
       
  1859 
       
  1860 apply(simp add: MValue_def)
       
  1861 apply(simp add: Values_recs)
       
  1862 
       
  1863 lemma nullable_red:
       
  1864   "\<not>nullable (red c r)"
       
  1865 apply(induct r)
       
  1866 apply(auto)
       
  1867 done
       
  1868 
       
  1869 lemma twq:
       
  1870   assumes "\<turnstile> v : r" 
       
  1871   shows "\<turnstile> injval r c v : red c r"
       
  1872 using assms
       
  1873 apply(induct)
       
  1874 apply(auto)
       
  1875 oops
       
  1876 
       
  1877 lemma injval_inj_red: "inj_on (injval (red c r) c) {v. \<turnstile> v : r}"
       
  1878 using injval_inj
       
  1879 apply(auto simp add: inj_on_def)
       
  1880 apply(drule_tac x="red c r" in meta_spec)
       
  1881 apply(drule_tac x="c" in meta_spec)
       
  1882 apply(drule_tac x="x" in spec)
       
  1883 apply(drule mp)
       
  1884 oops
       
  1885 
       
  1886 lemma 
       
  1887   assumes "POSIXs v (der c r) s" 
       
  1888   shows "POSIXs (injval r c v) r (c # s)"
       
  1889 using assms
       
  1890 apply(induct c r arbitrary: v s rule: der.induct)
       
  1891 apply(auto simp add: POSIXs_def)[1]
       
  1892 apply(erule Prfs.cases)
       
  1893 apply(simp_all)[5]
       
  1894 apply(erule Prfs.cases)
       
  1895 apply(simp_all)[5]
       
  1896 apply(auto simp add: POSIXs_def)[1]
       
  1897 apply(erule Prfs.cases)
       
  1898 apply(simp_all)[5]
       
  1899 apply(erule Prfs.cases)
       
  1900 apply(simp_all)[5]
       
  1901 apply(case_tac "c = c'")
       
  1902 apply(auto simp add: POSIXs_def)[1]
       
  1903 apply(erule Prfs.cases)
       
  1904 apply(simp_all)[5]
       
  1905 apply (metis Prfs.intros(5))
       
  1906 apply(erule Prfs.cases)
       
  1907 apply(simp_all)[5]
       
  1908 apply(erule Prfs.cases)
       
  1909 apply(simp_all)[5]
       
  1910 apply (metis ValOrd2.intros(8))
       
  1911 apply(auto simp add: POSIXs_def)[1]
       
  1912 apply(erule Prfs.cases)
       
  1913 apply(simp_all)[5]
       
  1914 apply(erule Prfs.cases)
       
  1915 apply(simp_all)[5]
       
  1916 apply(frule Prfs_POSIX)
       
  1917 apply(drule conjunct1)
       
  1918 apply(erule Prfs.cases)
       
  1919 apply(simp_all)[5]
       
  1920 apply(rule POSIXs_ALT_I1)
       
  1921 apply (metis POSIXs_ALT2)
       
  1922 apply(rule POSIXs_ALT_I2)
       
  1923 apply (metis POSIXs_ALT1a)
       
  1924 apply(frule POSIXs_ALT1b)
       
  1925 apply(auto)
       
  1926 apply(frule POSIXs_ALT1a)
       
  1927 (* HERE *)
       
  1928 oops
       
  1929 
       
  1930 lemma t: "(c#xs = c#ys) \<Longrightarrow> xs = ys"
       
  1931 by (metis list.sel(3))
       
  1932 
       
  1933 lemma t2: "(xs = ys) \<Longrightarrow> (c#xs) = (c#ys)"
       
  1934 by (metis)
       
  1935 
       
  1936 lemma "\<not>(nullable r) \<Longrightarrow> \<not>(\<exists>v. \<turnstile> v : r \<and> flat v = [])"
       
  1937 by (metis Prf_flat_L nullable_correctness)
       
  1938 
       
  1939 
       
  1940 lemma LeftRight:
       
  1941   assumes "(Left v1) \<succ>(der c (ALT r1 r2)) (Right v2)"
       
  1942   and "\<turnstile> v1 : der c r1" "\<turnstile> v2 : der c r2" 
       
  1943   shows "(injval (ALT r1 r2) c (Left v1)) \<succ>(ALT r1 r2) (injval (ALT r1 r2) c (Right v2))"
       
  1944 using assms
       
  1945 apply(simp)
       
  1946 apply(erule ValOrd.cases)
       
  1947 apply(simp_all)[8]
       
  1948 apply(rule ValOrd.intros)
       
  1949 apply(clarify)
       
  1950 apply(subst v4)
       
  1951 apply(simp)
       
  1952 apply(subst v4)
       
  1953 apply(simp)
       
  1954 apply(simp)
       
  1955 done
       
  1956 
       
  1957 lemma RightLeft:
       
  1958   assumes "(Right v1) \<succ>(der c (ALT r1 r2)) (Left v2)"
       
  1959   and "\<turnstile> v1 : der c r2" "\<turnstile> v2 : der c r1" 
       
  1960   shows "(injval (ALT r1 r2) c (Right v1)) \<succ>(ALT r1 r2) (injval (ALT r1 r2) c (Left v2))"
       
  1961 using assms
       
  1962 apply(simp)
       
  1963 apply(erule ValOrd.cases)
       
  1964 apply(simp_all)[8]
       
  1965 apply(rule ValOrd.intros)
       
  1966 apply(clarify)
       
  1967 apply(subst v4)
       
  1968 apply(simp)
       
  1969 apply(subst v4)
       
  1970 apply(simp)
       
  1971 apply(simp)
       
  1972 done
       
  1973 
       
  1974 lemma h: 
       
  1975   assumes "nullable r1" "\<turnstile> v1 : der c r1"
       
  1976   shows "injval r1 c v1 \<succ>r1 mkeps r1"
       
  1977 using assms
       
  1978 apply(induct r1 arbitrary: v1 rule: der.induct)
       
  1979 apply(simp)
       
  1980 apply(simp)
       
  1981 apply(erule Prf.cases)
       
  1982 apply(simp_all)[5]
       
  1983 apply(simp)
       
  1984 apply(simp)
       
  1985 apply(erule Prf.cases)
       
  1986 apply(simp_all)[5]
       
  1987 apply(clarify)
       
  1988 apply(auto)[1]
       
  1989 apply (metis ValOrd.intros(6))
       
  1990 apply (metis ValOrd.intros(6))
       
  1991 apply (metis ValOrd.intros(3) le_add2 list.size(3) mkeps_flat monoid_add_class.add.right_neutral)
       
  1992 apply(auto)[1]
       
  1993 apply (metis ValOrd.intros(4) length_greater_0_conv list.distinct(1) list.size(3) mkeps_flat v4)
       
  1994 apply (metis ValOrd.intros(4) length_greater_0_conv list.distinct(1) list.size(3) mkeps_flat v4)
       
  1995 apply (metis ValOrd.intros(5))
       
  1996 apply(simp)
       
  1997 apply(erule Prf.cases)
       
  1998 apply(simp_all)[5]
       
  1999 apply(clarify)
       
  2000 apply(erule Prf.cases)
       
  2001 apply(simp_all)[5]
       
  2002 apply(clarify)
       
  2003 apply (metis ValOrd.intros(2) list.distinct(1) mkeps_flat v4)
       
  2004 apply(clarify)
       
  2005 by (metis ValOrd.intros(1))
       
  2006 
       
  2007 lemma LeftRightSeq:
       
  2008   assumes "(Left (Seq v1 v2)) \<succ>(der c (SEQ r1 r2)) (Right v3)"
       
  2009   and "nullable r1" "\<turnstile> v1 : der c r1"
       
  2010   shows "(injval (SEQ r1 r2) c (Seq v1 v2)) \<succ>(SEQ r1 r2) (injval (SEQ r1 r2) c (Right v2))"
       
  2011 using assms
       
  2012 apply(simp)
       
  2013 apply(erule ValOrd.cases)
       
  2014 apply(simp_all)[8]
       
  2015 apply(clarify)
       
  2016 apply(simp)
       
  2017 apply(rule ValOrd.intros(2))
       
  2018 prefer 2
       
  2019 apply (metis list.distinct(1) mkeps_flat v4)
       
  2020 by (metis h)
       
  2021 
       
  2022 lemma rr1: 
       
  2023   assumes "\<turnstile> v : r" "\<not>nullable r" 
       
  2024   shows "flat v \<noteq> []"
       
  2025 using assms
       
  2026 by (metis Prf_flat_L nullable_correctness)
       
  2027 
       
  2028 section {* TESTTEST *}
       
  2029 
       
  2030 inductive ValOrdA :: "val \<Rightarrow> rexp \<Rightarrow> val \<Rightarrow> bool" ("_ A\<succ>_ _" [100, 100, 100] 100)
       
  2031 where
       
  2032   "v2 A\<succ>r2 v2' \<Longrightarrow> (Seq v1 v2) A\<succ>(SEQ r1 r2) (Seq v1 v2')" 
       
  2033 | "v1 A\<succ>r1 v1' \<Longrightarrow> (Seq v1 v2) A\<succ>(SEQ r1 r2) (Seq v1' v2')" 
       
  2034 | "length (flat v1) \<ge> length (flat v2) \<Longrightarrow> (Left v1) A\<succ>(ALT r1 r2) (Right v2)"
       
  2035 | "length (flat v2) > length (flat v1) \<Longrightarrow> (Right v2) A\<succ>(ALT r1 r2) (Left v1)"
       
  2036 | "v2 A\<succ>r2 v2' \<Longrightarrow> (Right v2) A\<succ>(ALT r1 r2) (Right v2')"
       
  2037 | "v1 A\<succ>r1 v1' \<Longrightarrow> (Left v1) A\<succ>(ALT r1 r2) (Left v1')"
       
  2038 | "Void A\<succ>EMPTY Void"
       
  2039 | "(Char c) A\<succ>(CHAR c) (Char c)"
       
  2040 
       
  2041 inductive ValOrd4 :: "val \<Rightarrow> rexp \<Rightarrow> val \<Rightarrow> bool" ("_ 4\<succ> _ _" [100, 100] 100)
       
  2042 where
       
  2043   (*"v1 4\<succ>(der c r) v1' \<Longrightarrow> (injval r c v1) 4\<succ>r (injval r c v1')" 
       
  2044 | "\<lbrakk>v1 4\<succ>r v2; v2 4\<succ>r v3\<rbrakk> \<Longrightarrow> v1 4\<succ>r v3" 
       
  2045 |*) 
       
  2046   "\<lbrakk>v1 4\<succ>r1 v1'; flat v2 = flat v2'; \<turnstile> v2 : r2; \<turnstile> v2' : r2\<rbrakk> \<Longrightarrow> (Seq v1 v2) 4\<succ>(SEQ r1 r2)  (Seq v1' v2')"
       
  2047 | "\<lbrakk>v2 4\<succ>r2 v2'; \<turnstile> v1 : r1\<rbrakk> \<Longrightarrow> (Seq v1 v2) 4\<succ>(SEQ r1 r2)  (Seq v1 v2')"
       
  2048 | "\<lbrakk>flat v1 = flat v2; \<turnstile> v1 : r1; \<turnstile> v2 : r2\<rbrakk> \<Longrightarrow> (Left v1) 4\<succ>(ALT r1 r2) (Right v2)"
       
  2049 | "v2 4\<succ>r2 v2' \<Longrightarrow> (Right v2) 4\<succ>(ALT r1 r2) (Right v2')"
       
  2050 | "v1 4\<succ>r1 v1' \<Longrightarrow> (Left v1) 4\<succ>(ALT r1 r2) (Left v1')"
       
  2051 | "Void 4\<succ>(EMPTY) Void"
       
  2052 | "(Char c) 4\<succ>(CHAR c) (Char c)"
       
  2053 
       
  2054 lemma ValOrd4_Prf:
       
  2055   assumes "v1 4\<succ>r v2"
       
  2056   shows "\<turnstile> v1 : r \<and> \<turnstile> v2 : r"
       
  2057 using assms
       
  2058 apply(induct v1 r v2)
       
  2059 apply(auto intro: Prf.intros)
       
  2060 done
       
  2061 
       
  2062 lemma ValOrd4_flat:
       
  2063   assumes "v1 4\<succ>r v2"
       
  2064   shows "flat v1 = flat v2"
       
  2065 using assms
       
  2066 apply(induct v1 r v2)
       
  2067 apply(simp_all)
       
  2068 done
       
  2069 
       
  2070 lemma ValOrd4_refl:
       
  2071   assumes "\<turnstile> v : r"
       
  2072   shows "v 4\<succ>r v"
       
  2073 using assms
       
  2074 apply(induct v r)
       
  2075 apply(auto intro: ValOrd4.intros)
       
  2076 done
       
  2077 
       
  2078 lemma 
       
  2079   assumes "v1 4\<succ>r v2" "v2 4\<succ>r v3" 
       
  2080   shows "v1 A\<succ>r v3"
       
  2081 using assms
       
  2082 apply(induct v1 r v2 arbitrary: v3)
       
  2083 apply(rotate_tac 5)
       
  2084 apply(erule ValOrd4.cases)
       
  2085 apply(simp_all)
       
  2086 apply(clarify)
       
  2087 apply (metis ValOrdA.intros(2))
       
  2088 apply(clarify)
       
  2089 apply (metis ValOrd4_refl ValOrdA.intros(2))
       
  2090 apply(rotate_tac 3)
       
  2091 apply(erule ValOrd4.cases)
       
  2092 apply(simp_all)
       
  2093 apply(clarify)
       
  2094 
       
  2095 apply (metis ValOrdA.intros(2))
       
  2096 apply (metis ValOrdA.intros(1))
       
  2097 apply (metis ValOrdA.intros(3) order_refl)
       
  2098 apply (auto intro: ValOrdA.intros)
       
  2099 done
       
  2100 
       
  2101 lemma 
       
  2102   assumes "v1 4\<succ>r v2"
       
  2103   shows "v1 A\<succ>r v2"
       
  2104 using assms
       
  2105 apply(induct v1 r v2 arbitrary:)
       
  2106 apply (metis ValOrdA.intros(2))
       
  2107 apply (metis ValOrdA.intros(1))
       
  2108 apply (metis ValOrdA.intros(3) order_refl)
       
  2109 apply (auto intro: ValOrdA.intros)
       
  2110 done
       
  2111 
       
  2112 lemma 
       
  2113   assumes "v1 \<succ>r v2" "\<turnstile> v1 : r" "\<turnstile> v2 : r" "flat v1 = flat v2"
       
  2114   shows "v1 4\<succ>r v2"
       
  2115 using assms
       
  2116 apply(induct v1 r v2 arbitrary:)
       
  2117 apply(erule Prf.cases)
       
  2118 apply(simp_all (no_asm_use))[5]
       
  2119 apply(erule Prf.cases)
       
  2120 apply(simp_all (no_asm_use))[5]
       
  2121 apply(clarify)
       
  2122 apply (metis ValOrd4.intros(4) ValOrd4_flat ValOrd4_refl)
       
  2123 apply(simp)
       
  2124 apply(erule Prf.cases)
       
  2125 apply(simp_all (no_asm_use))[5]
       
  2126 apply(erule Prf.cases)
       
  2127 apply(simp_all (no_asm_use))[5]
       
  2128 apply(clarify)
       
  2129 
       
  2130 lemma 
       
  2131   assumes "v1 \<succ>r v2" "\<turnstile> v1 : r" "\<turnstile> v2 : r" "flat v1 = flat v2"
       
  2132   shows "v1 4\<succ>r v2"
       
  2133 using assms
       
  2134 apply(induct v1 r v2 arbitrary:)
       
  2135 apply(erule Prf.cases)
       
  2136 apply(simp_all (no_asm_use))[5]
       
  2137 apply(erule Prf.cases)
       
  2138 apply(simp_all (no_asm_use))[5]
       
  2139 apply(clarify)
       
  2140 apply (metis ValOrd4.intros(4) ValOrd4_flat ValOrd4_refl)
       
  2141 apply(simp)
       
  2142 apply(erule Prf.cases)
       
  2143 apply(simp_all (no_asm_use))[5]
       
  2144 apply(erule Prf.cases)
       
  2145 apply(simp_all (no_asm_use))[5]
       
  2146 apply(clarify)
       
  2147 
       
  2148 
       
  2149 apply(simp)
       
  2150 apply(erule Prf.cases)
       
  2151 
       
  2152 
       
  2153 
       
  2154 
       
  2155 lemma rr2: "hd (flats v) \<noteq> [] \<Longrightarrow> flats v \<noteq> []"
       
  2156 apply(induct v)
       
  2157 apply(auto)
       
  2158 done
       
  2159 
       
  2160 lemma rr3: "flats v = [] \<Longrightarrow> flat v = []"
       
  2161 apply(induct v)
       
  2162 apply(auto)
       
  2163 done
       
  2164 
       
  2165 lemma POSIXs_der:
       
  2166   assumes "POSIXs v (der c r) s" "\<Turnstile>s v : der c r"
       
  2167   shows "POSIXs (injval r c v) r (c#s)"
       
  2168 using assms
       
  2169 unfolding POSIXs_def
       
  2170 apply(auto)
       
  2171 thm v3s 
       
  2172 apply (erule v3s)
       
  2173 apply(drule_tac x="projval r c v'" in spec)
       
  2174 apply(drule mp)
       
  2175 thm v3s_proj
       
  2176 apply(rule v3s_proj)
       
  2177 apply(simp)
       
  2178 thm v3s_proj
       
  2179 apply(drule v3s_proj)
       
  2180 oops
       
  2181 
       
  2182 term Values
       
  2183 (* HERE *)
       
  2184 
       
  2185 lemma Prf_inj_test:
       
  2186   assumes "v1 \<succ>(der c r) v2" 
       
  2187           "v1 \<in> Values (der c r) s"
       
  2188           "v2 \<in> Values (der c r) s"
       
  2189           "injval r c v1 \<in> Values r (c#s)"
       
  2190           "injval r c v2 \<in> Values r (c#s)"
       
  2191   shows "(injval r c v1) 2\<succ>  (injval r c v2)"
       
  2192 using assms
       
  2193 apply(induct c r arbitrary: v1 v2 s rule: der.induct)
       
  2194 (* NULL case *)
       
  2195 apply(simp add: Values_recs)
       
  2196 (* EMPTY case *)
       
  2197 apply(simp add: Values_recs)
       
  2198 (* CHAR case *)
       
  2199 apply(case_tac "c = c'")
       
  2200 apply(simp)
       
  2201 apply(simp add: Values_recs)
       
  2202 apply (metis ValOrd2.intros(8))
       
  2203 apply(simp add: Values_recs)
       
  2204 (* ALT case *)
       
  2205 apply(simp)
       
  2206 apply(simp add: Values_recs)
       
  2207 apply(auto)[1]
       
  2208 apply(erule ValOrd.cases)
       
  2209 apply(simp_all)[8]
       
  2210 apply (metis ValOrd2.intros(6))
       
  2211 apply(erule ValOrd.cases)
       
  2212 apply(simp_all)[8]
       
  2213 apply(rule ValOrd2.intros)
       
  2214 apply(subst v4)
       
  2215 apply(simp add: Values_def)
       
  2216 apply(subst v4)
       
  2217 apply(simp add: Values_def)
       
  2218 apply(simp)
       
  2219 apply(erule ValOrd.cases)
       
  2220 apply(simp_all)[8]
       
  2221 apply(rule ValOrd2.intros)
       
  2222 apply(subst v4)
       
  2223 apply(simp add: Values_def)
       
  2224 apply(subst v4)
       
  2225 apply(simp add: Values_def)
       
  2226 apply(simp)
       
  2227 apply(erule ValOrd.cases)
       
  2228 apply(simp_all)[8]
       
  2229 apply (metis ValOrd2.intros(5))
       
  2230 (* SEQ case*)
       
  2231 apply(simp)
       
  2232 apply(case_tac "nullable r1")
       
  2233 apply(simp)
       
  2234 defer
       
  2235 apply(simp)
       
  2236 apply(simp add: Values_recs)
       
  2237 apply(auto)[1]
       
  2238 apply(erule ValOrd.cases)
       
  2239 apply(simp_all)[8]
       
  2240 apply(clarify)
       
  2241 apply(rule ValOrd2.intros)
       
  2242 apply(simp)
       
  2243 apply (metis Ord1)
       
  2244 apply(clarify)
       
  2245 apply(rule ValOrd2.intros)
       
  2246 apply(subgoal_tac "rest v1 (flat v1 @ flat v2) = flat v2")
       
  2247 apply(simp)
       
  2248 apply(subgoal_tac "rest (injval r1 c v1) (c # flat v1 @ flat v2) = flat v2")
       
  2249 apply(simp)
       
  2250 
       
  2251 apply metis
       
  2252 using injval_inj
       
  2253 apply(simp add: Values_def inj_on_def)
       
  2254 apply metis
       
  2255 apply(simp add: Values_recs)
       
  2256 apply(auto)[1]
       
  2257 apply(erule ValOrd.cases)
       
  2258 apply(simp_all)[8]
       
  2259 apply(clarify)
       
  2260 apply(erule ValOrd.cases)
       
  2261 apply(simp_all)[8]
       
  2262 apply(clarify)
       
  2263 apply (metis Ord1 ValOrd2.intros(1))
       
  2264 apply(clarify)
       
  2265 apply(rule ValOrd2.intros(2))
       
  2266 apply metis
       
  2267 using injval_inj
       
  2268 apply(simp add: Values_def inj_on_def)
       
  2269 apply metis
       
  2270 apply(erule ValOrd.cases)
       
  2271 apply(simp_all)[8]
       
  2272 apply(rule ValOrd2.intros(2))
       
  2273 thm h
       
  2274 apply(rule Ord1)
       
  2275 apply(rule h)
       
  2276 apply(simp)
       
  2277 apply(simp add: Values_def)
       
  2278 apply(simp add: Values_def)
       
  2279 apply (metis list.distinct(1) mkeps_flat v4)
       
  2280 apply(erule ValOrd.cases)
       
  2281 apply(simp_all)[8]
       
  2282 apply(clarify)
       
  2283 apply(simp add: Values_def)
       
  2284 defer
       
  2285 apply(erule ValOrd.cases)
       
  2286 apply(simp_all)[8]
       
  2287 apply(clarify)
       
  2288 apply(rule ValOrd2.intros(1))
       
  2289 apply(rotate_tac 1)
       
  2290 apply(drule_tac x="v2" in meta_spec)
       
  2291 apply(rotate_tac 8)
       
  2292 apply(drule_tac x="v2'" in meta_spec)
       
  2293 apply(rotate_tac 8)
       
  2294 apply(drule_tac x="s" in meta_spec)
       
  2295 apply(simp)
       
  2296 apply(drule_tac meta_mp)
       
  2297 apply(simp add: rest_def mkeps_flat)
       
  2298 apply(drule_tac meta_mp)
       
  2299 apply(simp add: rest_def mkeps_flat)
       
  2300 apply(simp)
       
  2301 apply(simp add: rest_def mkeps_flat)
       
  2302 apply(subst (asm) (5) v4)
       
  2303 apply(simp)
       
  2304 apply(subst (asm) (5) v4)
       
  2305 apply(simp)
       
  2306 apply(subst (asm) (5) v4)
       
  2307 apply(simp)
       
  2308 apply(simp)
       
  2309 apply(clarify)
       
  2310 apply(simp add: prefix_Cons)
       
  2311 apply(subgoal_tac "((flat v1c) @ (flat v2b)) \<sqsubseteq> (flat v2)")
       
  2312 prefer 2
       
  2313 apply(simp add: prefix_def)
       
  2314 apply(auto)[1]
       
  2315 (* HEREHERE *)
       
  2316 
       
  2317 
       
  2318 lemma Prf_inj_test:
       
  2319   assumes "v1 \<succ>r v2" 
       
  2320           "v1 \<in> Values r s"
       
  2321           "v2 \<in> Values r s"
       
  2322           "injval r c v1 \<in> Values (red c r) (c#s)"
       
  2323           "injval r c v2 \<in> Values (red c r) (c#s)"
       
  2324   shows "(injval r c v1) \<succ>(red c r)  (injval r c v2)"
       
  2325 using assms
       
  2326 apply(induct v1 r v2 arbitrary: s rule: ValOrd.induct)
       
  2327 apply(simp add: Values_recs)
       
  2328 apply (metis ValOrd.intros(1))
       
  2329 apply(simp add: Values_recs)
       
  2330 apply(rule ValOrd.intros(2))
       
  2331 apply(metis)
       
  2332 defer
       
  2333 apply(simp add: Values_recs)
       
  2334 apply(rule ValOrd.intros)
       
  2335 apply(subst v4)
       
  2336 apply(simp add: Values_def)
       
  2337 apply(subst v4)
       
  2338 apply(simp add: Values_def)
       
  2339 using injval_inj_red
       
  2340 apply(simp add: Values_def inj_on_def)
       
  2341 apply(rule notI)
       
  2342 apply(drule_tac x="r1" in meta_spec)
       
  2343 apply(drule_tac x="c" in meta_spec)
       
  2344 apply(drule_tac x="injval r1 c v1" in spec)
       
  2345 apply(simp)
       
  2346 
       
  2347 apply(drule_tac x="c" in meta_spec)
       
  2348 
       
  2349 apply metis
       
  2350 apply (metis ValOrd.intros(1))
       
  2351 
       
  2352 
       
  2353 
       
  2354 done
       
  2355 (* EMPTY case *)
       
  2356 apply(simp add: Values_recs)
       
  2357 (* CHAR case *)
       
  2358 apply(case_tac "c = c'")
       
  2359 apply(simp)
       
  2360 apply(simp add: Values_recs)
       
  2361 apply (metis ValOrd2.intros(8))
       
  2362 apply(simp add: Values_recs)
       
  2363 (* ALT case *)
       
  2364 apply(simp)
       
  2365 apply(simp add: Values_recs)
       
  2366 apply(auto)[1]
       
  2367 apply(erule ValOrd.cases)
       
  2368 apply(simp_all)[8]
       
  2369 apply (metis ValOrd2.intros(6))
       
  2370 apply(erule ValOrd.cases)
       
  2371 apply(simp_all)[8]
       
  2372 apply(rule ValOrd2.intros)
       
  2373 apply(subst v4)
       
  2374 apply(simp add: Values_def)
       
  2375 apply(subst v4)
       
  2376 apply(simp add: Values_def)
       
  2377 apply(simp)
       
  2378 apply(erule ValOrd.cases)
       
  2379 apply(simp_all)[8]
       
  2380 apply(rule ValOrd2.intros)
       
  2381 apply(subst v4)
       
  2382 apply(simp add: Values_def)
       
  2383 apply(subst v4)
       
  2384 apply(simp add: Values_def)
       
  2385 apply(simp)
       
  2386 apply(erule ValOrd.cases)
       
  2387 apply(simp_all)[8]
       
  2388 apply (metis ValOrd2.intros(5))
       
  2389 (* SEQ case*)
       
  2390 apply(simp)
       
  2391 apply(case_tac "nullable r1")
       
  2392 apply(simp)
       
  2393 defer
       
  2394 apply(simp)
       
  2395 apply(simp add: Values_recs)
       
  2396 apply(auto)[1]
       
  2397 apply(erule ValOrd.cases)
       
  2398 apply(simp_all)[8]
       
  2399 apply(clarify)
       
  2400 apply(rule ValOrd2.intros)
       
  2401 apply(simp)
       
  2402 apply (metis Ord1)
       
  2403 apply(clarify)
       
  2404 apply(rule ValOrd2.intros)
       
  2405 apply metis
       
  2406 using injval_inj
       
  2407 apply(simp add: Values_def inj_on_def)
       
  2408 apply metis
       
  2409 apply(simp add: Values_recs)
       
  2410 apply(auto)[1]
       
  2411 apply(erule ValOrd.cases)
       
  2412 apply(simp_all)[8]
       
  2413 apply(clarify)
       
  2414 apply(erule ValOrd.cases)
       
  2415 apply(simp_all)[8]
       
  2416 apply(clarify)
       
  2417 apply (metis Ord1 ValOrd2.intros(1))
       
  2418 apply(clarify)
       
  2419 apply(rule ValOrd2.intros(2))
       
  2420 apply metis
       
  2421 using injval_inj
       
  2422 apply(simp add: Values_def inj_on_def)
       
  2423 apply metis
       
  2424 apply(erule ValOrd.cases)
       
  2425 apply(simp_all)[8]
       
  2426 apply(rule ValOrd2.intros(2))
       
  2427 thm h
       
  2428 apply(rule Ord1)
       
  2429 apply(rule h)
       
  2430 apply(simp)
       
  2431 apply(simp add: Values_def)
       
  2432 apply(simp add: Values_def)
       
  2433 apply (metis list.distinct(1) mkeps_flat v4)
       
  2434 apply(erule ValOrd.cases)
       
  2435 apply(simp_all)[8]
       
  2436 apply(clarify)
       
  2437 apply(simp add: Values_def)
       
  2438 defer
       
  2439 apply(erule ValOrd.cases)
       
  2440 apply(simp_all)[8]
       
  2441 apply(clarify)
       
  2442 apply(rule ValOrd2.intros(1))
       
  2443 apply(rotate_tac 1)
       
  2444 apply(drule_tac x="v2" in meta_spec)
       
  2445 apply(rotate_tac 8)
       
  2446 apply(drule_tac x="v2'" in meta_spec)
       
  2447 apply(rotate_tac 8)
       
  2448 apply(drule_tac x="s" in meta_spec)
       
  2449 apply(simp)
       
  2450 apply(drule_tac meta_mp)
       
  2451 apply(simp add: rest_def mkeps_flat)
       
  2452 apply(drule_tac meta_mp)
       
  2453 apply(simp add: rest_def mkeps_flat)
       
  2454 apply(simp)
       
  2455 apply(simp add: rest_def mkeps_flat)
       
  2456 apply(subst (asm) (5) v4)
       
  2457 apply(simp)
       
  2458 apply(subst (asm) (5) v4)
       
  2459 apply(simp)
       
  2460 apply(subst (asm) (5) v4)
       
  2461 apply(simp)
       
  2462 apply(simp)
       
  2463 apply(clarify)
       
  2464 apply(simp add: prefix_Cons)
       
  2465 apply(subgoal_tac "((flat v1c) @ (flat v2b)) \<sqsubseteq> (flat v2)")
       
  2466 prefer 2
       
  2467 apply(simp add: prefix_def)
       
  2468 apply(auto)[1]
       
  2469 (* HEREHERE *)
       
  2470 
       
  2471 lemma Prf_inj_test:
       
  2472   assumes "v1 \<succ>(der c r) v2" 
       
  2473           "v1 \<in> Values (der c r) s"
       
  2474           "v2 \<in> Values (der c r) s"
       
  2475           "injval r c v1 \<in> Values r (c#s)"
       
  2476           "injval r c v2 \<in> Values r (c#s)"
       
  2477   shows "(injval r c v1) 2\<succ>  (injval r c v2)"
       
  2478 using assms
       
  2479 apply(induct c r arbitrary: v1 v2 s rule: der.induct)
       
  2480 (* NULL case *)
       
  2481 apply(simp add: Values_recs)
       
  2482 (* EMPTY case *)
       
  2483 apply(simp add: Values_recs)
       
  2484 (* CHAR case *)
       
  2485 apply(case_tac "c = c'")
       
  2486 apply(simp)
       
  2487 apply(simp add: Values_recs)
       
  2488 apply (metis ValOrd2.intros(8))
       
  2489 apply(simp add: Values_recs)
       
  2490 (* ALT case *)
       
  2491 apply(simp)
       
  2492 apply(simp add: Values_recs)
       
  2493 apply(auto)[1]
       
  2494 apply(erule ValOrd.cases)
       
  2495 apply(simp_all)[8]
       
  2496 apply (metis ValOrd2.intros(6))
       
  2497 apply(erule ValOrd.cases)
       
  2498 apply(simp_all)[8]
       
  2499 apply(rule ValOrd2.intros)
       
  2500 apply(subst v4)
       
  2501 apply(simp add: Values_def)
       
  2502 apply(subst v4)
       
  2503 apply(simp add: Values_def)
       
  2504 apply(simp)
       
  2505 apply(erule ValOrd.cases)
       
  2506 apply(simp_all)[8]
       
  2507 apply(rule ValOrd2.intros)
       
  2508 apply(subst v4)
       
  2509 apply(simp add: Values_def)
       
  2510 apply(subst v4)
       
  2511 apply(simp add: Values_def)
       
  2512 apply(simp)
       
  2513 apply(erule ValOrd.cases)
       
  2514 apply(simp_all)[8]
       
  2515 apply (metis ValOrd2.intros(5))
       
  2516 (* SEQ case*)
       
  2517 apply(simp)
       
  2518 apply(case_tac "nullable r1")
       
  2519 apply(simp)
       
  2520 defer
       
  2521 apply(simp)
       
  2522 apply(simp add: Values_recs)
       
  2523 apply(auto)[1]
       
  2524 apply(erule ValOrd.cases)
       
  2525 apply(simp_all)[8]
       
  2526 apply(clarify)
       
  2527 apply(rule ValOrd2.intros)
       
  2528 apply(simp)
       
  2529 apply (metis Ord1)
       
  2530 apply(clarify)
       
  2531 apply(rule ValOrd2.intros)
       
  2532 apply metis
       
  2533 using injval_inj
       
  2534 apply(simp add: Values_def inj_on_def)
       
  2535 apply metis
       
  2536 apply(simp add: Values_recs)
       
  2537 apply(auto)[1]
       
  2538 apply(erule ValOrd.cases)
       
  2539 apply(simp_all)[8]
       
  2540 apply(clarify)
       
  2541 apply(erule ValOrd.cases)
       
  2542 apply(simp_all)[8]
       
  2543 apply(clarify)
       
  2544 apply (metis Ord1 ValOrd2.intros(1))
       
  2545 apply(clarify)
       
  2546 apply(rule ValOrd2.intros(2))
       
  2547 apply metis
       
  2548 using injval_inj
       
  2549 apply(simp add: Values_def inj_on_def)
       
  2550 apply metis
       
  2551 apply(erule ValOrd.cases)
       
  2552 apply(simp_all)[8]
       
  2553 apply(rule ValOrd2.intros(2))
       
  2554 thm h
       
  2555 apply(rule Ord1)
       
  2556 apply(rule h)
       
  2557 apply(simp)
       
  2558 apply(simp add: Values_def)
       
  2559 apply(simp add: Values_def)
       
  2560 apply (metis list.distinct(1) mkeps_flat v4)
       
  2561 apply(erule ValOrd.cases)
       
  2562 apply(simp_all)[8]
       
  2563 apply(clarify)
       
  2564 apply(simp add: Values_def)
       
  2565 defer
       
  2566 apply(erule ValOrd.cases)
       
  2567 apply(simp_all)[8]
       
  2568 apply(clarify)
       
  2569 apply(rule ValOrd2.intros(1))
       
  2570 apply(rotate_tac 1)
       
  2571 apply(drule_tac x="v2" in meta_spec)
       
  2572 apply(rotate_tac 8)
       
  2573 apply(drule_tac x="v2'" in meta_spec)
       
  2574 apply(rotate_tac 8)
       
  2575 apply(drule_tac x="s" in meta_spec)
       
  2576 apply(simp)
       
  2577 apply(drule_tac meta_mp)
       
  2578 apply(simp add: rest_def mkeps_flat)
       
  2579 apply(drule_tac meta_mp)
       
  2580 apply(simp add: rest_def mkeps_flat)
       
  2581 apply(simp)
       
  2582 apply(simp add: rest_def mkeps_flat)
       
  2583 apply(subst (asm) (5) v4)
       
  2584 apply(simp)
       
  2585 apply(subst (asm) (5) v4)
       
  2586 apply(simp)
       
  2587 apply(subst (asm) (5) v4)
       
  2588 apply(simp)
       
  2589 apply(simp)
       
  2590 apply(clarify)
       
  2591 apply(simp add: prefix_Cons)
       
  2592 apply(subgoal_tac "((flat v1c) @ (flat v2b)) \<sqsubseteq> (flat v2)")
       
  2593 prefer 2
       
  2594 apply(simp add: prefix_def)
       
  2595 apply(auto)[1]
       
  2596 (* HEREHERE *)
       
  2597 
       
  2598 apply(subst (asm) (7) v4)
       
  2599 apply(simp)
       
  2600 
       
  2601 
       
  2602 (* HEREHERE *)
       
  2603 
       
  2604 apply(simp add: Values_def)
       
  2605 apply(simp add: Values_recs)
       
  2606 apply(simp add: Values_recs)
       
  2607 done
       
  2608 
       
  2609 lemma POSIX_der:
       
  2610   assumes "POSIX v (der c r)" "\<turnstile> v : der c r"
       
  2611   shows "POSIX (injval r c v) r"
       
  2612 using assms
       
  2613 unfolding POSIX_def
       
  2614 apply(auto)
       
  2615 thm v3
       
  2616 apply (erule v3)
       
  2617 thm v4
       
  2618 apply(subst (asm) v4)
       
  2619 apply(assumption)
       
  2620 apply(drule_tac x="projval r c v'" in spec)
       
  2621 apply(drule mp)
       
  2622 apply(rule conjI)
       
  2623 thm v3_proj
       
  2624 apply(rule v3_proj)
       
  2625 apply(simp)
       
  2626 apply(rule_tac x="flat v" in exI)
       
  2627 apply(simp)
       
  2628 thm t
       
  2629 apply(rule_tac c="c" in  t)
       
  2630 apply(simp)
       
  2631 thm v4_proj
       
  2632 apply(subst v4_proj)
       
  2633 apply(simp)
       
  2634 apply(rule_tac x="flat v" in exI)
       
  2635 apply(simp)
       
  2636 apply(simp)
       
  2637 thm  Prf_inj_test
       
  2638 apply(drule_tac r="r" in Prf_inj_test)
       
  2639 oops
       
  2640 
       
  2641 lemma POSIX_der:
       
  2642   assumes "POSIX v (der c r)" "\<turnstile> v : der c r"
       
  2643   shows "POSIX (injval r c v) r"
       
  2644 using assms
       
  2645 apply(induct c r arbitrary: v rule: der.induct)
       
  2646 (* null case*)
       
  2647 apply(simp add: POSIX_def)
       
  2648 apply(auto)[1]
       
  2649 apply(erule Prf.cases)
       
  2650 apply(simp_all)[5]
       
  2651 apply(erule Prf.cases)
       
  2652 apply(simp_all)[5]
       
  2653 (* empty case *)
       
  2654 apply(simp add: POSIX_def)
       
  2655 apply(auto)[1]
       
  2656 apply(erule Prf.cases)
       
  2657 apply(simp_all)[5]
       
  2658 apply(erule Prf.cases)
       
  2659 apply(simp_all)[5]
       
  2660 (* char case *)
       
  2661 apply(simp add: POSIX_def)
       
  2662 apply(case_tac "c = c'")
       
  2663 apply(auto)[1]
       
  2664 apply(erule Prf.cases)
       
  2665 apply(simp_all)[5]
       
  2666 apply (metis Prf.intros(5))
       
  2667 apply(erule Prf.cases)
       
  2668 apply(simp_all)[5]
       
  2669 apply(erule Prf.cases)
       
  2670 apply(simp_all)[5]
       
  2671 apply (metis ValOrd.intros(8))
       
  2672 apply(auto)[1]
       
  2673 apply(erule Prf.cases)
       
  2674 apply(simp_all)[5]
       
  2675 apply(erule Prf.cases)
       
  2676 apply(simp_all)[5]
       
  2677 (* alt case *)
       
  2678 apply(erule Prf.cases)
       
  2679 apply(simp_all)[5]
       
  2680 apply(clarify)
       
  2681 apply(simp (no_asm) add: POSIX_def)
       
  2682 apply(auto)[1]
       
  2683 apply (metis Prf.intros(2) v3)
       
  2684 apply(rotate_tac 4)
       
  2685 apply(erule Prf.cases)
       
  2686 apply(simp_all)[5]
       
  2687 apply (metis POSIX_ALT2 POSIX_def ValOrd.intros(6))
       
  2688 apply (metis ValOrd.intros(3) order_refl)
       
  2689 apply(simp (no_asm) add: POSIX_def)
       
  2690 apply(auto)[1]
       
  2691 apply (metis Prf.intros(3) v3)
       
  2692 apply(rotate_tac 4)
       
  2693 apply(erule Prf.cases)
       
  2694 apply(simp_all)[5]
       
  2695 defer
       
  2696 apply (metis POSIX_ALT1a POSIX_def ValOrd.intros(5))
       
  2697 prefer 2
       
  2698 apply(subst (asm) (5) POSIX_def)
       
  2699 apply(auto)[1]
       
  2700 apply(rotate_tac 5)
       
  2701 apply(erule Prf.cases)
       
  2702 apply(simp_all)[5]
       
  2703 apply(rule ValOrd.intros)
       
  2704 apply(subst (asm) v4)
       
  2705 apply(simp)
       
  2706 apply(drule_tac x="Left (projval r1a c v1)" in spec)
       
  2707 apply(clarify)
       
  2708 apply(drule mp)
       
  2709 apply(rule conjI)
       
  2710 apply (metis Prf.intros(2) v3_proj)
       
  2711 apply(simp)
       
  2712 apply (metis v4_proj2)
       
  2713 apply(erule ValOrd.cases)
       
  2714 apply(simp_all)[8]
       
  2715 apply (metis less_not_refl v4_proj2)
       
  2716 (* seq case *)
       
  2717 apply(case_tac "nullable r1")
       
  2718 defer
       
  2719 apply(simp add: POSIX_def)
       
  2720 apply(auto)[1]
       
  2721 apply(erule Prf.cases)
       
  2722 apply(simp_all)[5]
       
  2723 apply (metis Prf.intros(1) v3)
       
  2724 apply(erule Prf.cases)
       
  2725 apply(simp_all)[5]
       
  2726 apply(erule Prf.cases)
       
  2727 apply(simp_all)[5]
       
  2728 apply(clarify)
       
  2729 apply(subst (asm) (3) v4)
       
  2730 apply(simp)
       
  2731 apply(simp)
       
  2732 apply(subgoal_tac "flat v1a \<noteq> []")
       
  2733 prefer 2
       
  2734 apply (metis Prf_flat_L nullable_correctness)
       
  2735 apply(subgoal_tac "\<exists>s. flat v1a = c # s")
       
  2736 prefer 2
       
  2737 apply (metis append_eq_Cons_conv)
       
  2738 apply(auto)[1]
       
  2739  
       
  2740 
       
  2741 apply(auto)
       
  2742 thm v3
       
  2743 apply (erule v3)
       
  2744 thm v4
       
  2745 apply(subst (asm) v4)
       
  2746 apply(assumption)
       
  2747 apply(drule_tac x="projval r c v'" in spec)
       
  2748 apply(drule mp)
       
  2749 apply(rule conjI)
       
  2750 thm v3_proj
       
  2751 apply(rule v3_proj)
       
  2752 apply(simp)
       
  2753 apply(rule_tac x="flat v" in exI)
       
  2754 apply(simp)
       
  2755 thm t
       
  2756 apply(rule_tac c="c" in  t)
       
  2757 apply(simp)
       
  2758 thm v4_proj
       
  2759 apply(subst v4_proj)
       
  2760 apply(simp)
       
  2761 apply(rule_tac x="flat v" in exI)
       
  2762 apply(simp)
       
  2763 apply(simp)
       
  2764 oops
       
  2765 
       
  2766 
       
  2767 lemma POSIX_ex: "\<turnstile> v : r \<Longrightarrow> \<exists>v. POSIX v r"
       
  2768 apply(induct r arbitrary: v)
       
  2769 apply(erule Prf.cases)
       
  2770 apply(simp_all)[5]
       
  2771 apply(erule Prf.cases)
       
  2772 apply(simp_all)[5]
       
  2773 apply(rule_tac x="Void" in exI)
       
  2774 apply(simp add: POSIX_def)
       
  2775 apply(auto)[1]
       
  2776 apply (metis Prf.intros(4))
       
  2777 apply(erule Prf.cases)
       
  2778 apply(simp_all)[5]
       
  2779 apply (metis ValOrd.intros(7))
       
  2780 apply(erule Prf.cases)
       
  2781 apply(simp_all)[5]
       
  2782 apply(rule_tac x="Char c" in exI)
       
  2783 apply(simp add: POSIX_def)
       
  2784 apply(auto)[1]
       
  2785 apply (metis Prf.intros(5))
       
  2786 apply(erule Prf.cases)
       
  2787 apply(simp_all)[5]
       
  2788 apply (metis ValOrd.intros(8))
       
  2789 apply(erule Prf.cases)
       
  2790 apply(simp_all)[5]
       
  2791 apply(auto)[1]
       
  2792 apply(drule_tac x="v1" in meta_spec)
       
  2793 apply(drule_tac x="v2" in meta_spec)
       
  2794 apply(auto)[1]
       
  2795 defer
       
  2796 apply(erule Prf.cases)
       
  2797 apply(simp_all)[5]
       
  2798 apply(auto)[1]
       
  2799 apply (metis POSIX_ALT_I1)
       
  2800 apply (metis POSIX_ALT_I1 POSIX_ALT_I2)
       
  2801 apply(case_tac "nullable r1a")
       
  2802 apply(rule_tac x="Seq (mkeps r1a) va" in exI)
       
  2803 apply(auto simp add: POSIX_def)[1]
       
  2804 apply (metis Prf.intros(1) mkeps_nullable)
       
  2805 apply(simp add: mkeps_flat)
       
  2806 apply(rotate_tac 7)
       
  2807 apply(erule Prf.cases)
       
  2808 apply(simp_all)[5]
       
  2809 apply(case_tac "mkeps r1 = v1a")
       
  2810 apply(simp)
       
  2811 apply (rule ValOrd.intros(1))
       
  2812 apply (metis append_Nil mkeps_flat)
       
  2813 apply (rule ValOrd.intros(2))
       
  2814 apply(drule mkeps_POSIX)
       
  2815 apply(simp add: POSIX_def)
       
  2816 
       
  2817 apply metis
       
  2818 apply(simp)
       
  2819 apply(simp)
       
  2820 apply(erule disjE)
       
  2821 apply(simp)
       
  2822 
       
  2823 apply(drule_tac x="v2" in spec)
       
  2824 
       
  2825 lemma POSIX_ex2: "\<turnstile> v : r \<Longrightarrow> \<exists>v. POSIX v r \<and> \<turnstile> v : r"
       
  2826 apply(induct r arbitrary: v)
       
  2827 apply(erule Prf.cases)
       
  2828 apply(simp_all)[5]
       
  2829 apply(erule Prf.cases)
       
  2830 apply(simp_all)[5]
       
  2831 apply(rule_tac x="Void" in exI)
       
  2832 apply(simp add: POSIX_def)
       
  2833 apply(auto)[1]
       
  2834 apply(erule Prf.cases)
       
  2835 apply(simp_all)[5]
       
  2836 apply (metis ValOrd.intros(7))
       
  2837 apply (metis Prf.intros(4))
       
  2838 apply(erule Prf.cases)
       
  2839 apply(simp_all)[5]
       
  2840 apply(rule_tac x="Char c" in exI)
       
  2841 apply(simp add: POSIX_def)
       
  2842 apply(auto)[1]
       
  2843 apply(erule Prf.cases)
       
  2844 apply(simp_all)[5]
       
  2845 apply (metis ValOrd.intros(8))
       
  2846 apply (metis Prf.intros(5))
       
  2847 apply(erule Prf.cases)
       
  2848 apply(simp_all)[5]
       
  2849 apply(auto)[1]
       
  2850 apply(drule_tac x="v1" in meta_spec)
       
  2851 apply(drule_tac x="v2" in meta_spec)
       
  2852 apply(auto)[1]
       
  2853 apply(simp add: POSIX_def)
       
  2854 apply(auto)[1]
       
  2855 apply(rule ccontr)
       
  2856 apply(simp)
       
  2857 apply(drule_tac x="Seq v va" in spec)
       
  2858 apply(drule mp)
       
  2859 defer
       
  2860 apply (metis Prf.intros(1))
       
  2861 oops
       
  2862 
       
  2863 lemma POSIX_ALT_cases:
       
  2864   assumes "\<turnstile> v : (ALT r1 r2)" "POSIX v (ALT r1 r2)"
       
  2865   shows "(\<exists>v1. v = Left v1 \<and> POSIX v1 r1) \<or> (\<exists>v2. v = Right v2 \<and> POSIX v2 r2)"
       
  2866 using assms
       
  2867 apply(erule_tac Prf.cases)
       
  2868 apply(simp_all)
       
  2869 unfolding POSIX_def
       
  2870 apply(auto)
       
  2871 apply (metis POSIX_ALT2 POSIX_def assms(2))
       
  2872 by (metis POSIX_ALT1b assms(2))
       
  2873 
       
  2874 lemma POSIX_ALT_cases2:
       
  2875   assumes "POSIX v (ALT r1 r2)" "\<turnstile> v : (ALT r1 r2)" 
       
  2876   shows "(\<exists>v1. v = Left v1 \<and> POSIX v1 r1) \<or> (\<exists>v2. v = Right v2 \<and> POSIX v2 r2)"
       
  2877 using assms POSIX_ALT_cases by auto
       
  2878 
       
  2879 lemma Prf_flat_empty:
       
  2880   assumes "\<turnstile> v : r" "flat v = []"
       
  2881   shows "nullable r"
       
  2882 using assms
       
  2883 apply(induct)
       
  2884 apply(auto)
       
  2885 done
       
  2886 
       
  2887 lemma POSIX_proj:
       
  2888   assumes "POSIX v r" "\<turnstile> v : r" "\<exists>s. flat v = c#s"
       
  2889   shows "POSIX (projval r c v) (der c r)"
       
  2890 using assms
       
  2891 apply(induct r c v arbitrary: rule: projval.induct)
       
  2892 defer
       
  2893 defer
       
  2894 defer
       
  2895 defer
       
  2896 apply(erule Prf.cases)
       
  2897 apply(simp_all)[5]
       
  2898 apply(erule Prf.cases)
       
  2899 apply(simp_all)[5]
       
  2900 apply(erule Prf.cases)
       
  2901 apply(simp_all)[5]
       
  2902 apply(erule Prf.cases)
       
  2903 apply(simp_all)[5]
       
  2904 apply(erule Prf.cases)
       
  2905 apply(simp_all)[5]
       
  2906 apply(erule Prf.cases)
       
  2907 apply(simp_all)[5]
       
  2908 apply(erule Prf.cases)
       
  2909 apply(simp_all)[5]
       
  2910 apply(erule Prf.cases)
       
  2911 apply(simp_all)[5]
       
  2912 apply(erule Prf.cases)
       
  2913 apply(simp_all)[5]
       
  2914 apply(erule Prf.cases)
       
  2915 apply(simp_all)[5]
       
  2916 apply(simp add: POSIX_def)
       
  2917 apply(auto)[1]
       
  2918 apply(erule Prf.cases)
       
  2919 apply(simp_all)[5]
       
  2920 apply (metis ValOrd.intros(7))
       
  2921 apply(erule_tac [!] exE)
       
  2922 prefer 3
       
  2923 apply(frule POSIX_SEQ1)
       
  2924 apply(erule Prf.cases)
       
  2925 apply(simp_all)[5]
       
  2926 apply(erule Prf.cases)
       
  2927 apply(simp_all)[5]
       
  2928 apply(case_tac "flat v1 = []")
       
  2929 apply(subgoal_tac "nullable r1")
       
  2930 apply(simp)
       
  2931 prefer 2
       
  2932 apply(rule_tac v="v1" in Prf_flat_empty)
       
  2933 apply(erule Prf.cases)
       
  2934 apply(simp_all)[5]
       
  2935 apply(simp)
       
  2936 apply(frule POSIX_SEQ2)
       
  2937 apply(erule Prf.cases)
       
  2938 apply(simp_all)[5]
       
  2939 apply(erule Prf.cases)
       
  2940 apply(simp_all)[5]
       
  2941 apply(simp)
       
  2942 apply(drule meta_mp)
       
  2943 apply(erule Prf.cases)
       
  2944 apply(simp_all)[5]
       
  2945 apply(rule ccontr)
       
  2946 apply(subgoal_tac "\<turnstile> val.Right (projval r2 c v2) : (ALT (SEQ (der c r1) r2) (der c r2))")
       
  2947 apply(rotate_tac 11)
       
  2948 apply(frule POSIX_ex)
       
  2949 apply(erule exE)
       
  2950 apply(drule POSIX_ALT_cases2)
       
  2951 apply(erule Prf.cases)
       
  2952 apply(simp_all)[5]
       
  2953 apply(drule v3_proj)
       
  2954 apply(simp)
       
  2955 apply(simp)
       
  2956 apply(drule POSIX_ex)
       
  2957 apply(erule exE)
       
  2958 apply(frule POSIX_ALT_cases2)
       
  2959 apply(simp)
       
  2960 apply(simp)
       
  2961 apply(erule 
       
  2962 prefer 2
       
  2963 apply(case_tac "nullable r1")
       
  2964 prefer 2
       
  2965 apply(simp)
       
  2966 apply(rotate_tac 1)
       
  2967 apply(drule meta_mp)
       
  2968 apply(rule POSIX_SEQ1)
       
  2969 apply(assumption)
       
  2970 apply(erule Prf.cases)
       
  2971 apply(simp_all)[5]
       
  2972 apply(erule Prf.cases)
       
  2973 apply(simp_all)[5]
       
  2974 apply(rotate_tac 7)
       
  2975 apply(drule meta_mp)
       
  2976 apply(erule Prf.cases)
       
  2977 apply(simp_all)[5]
       
  2978 apply(rotate_tac 7)
       
  2979 apply(drule meta_mp)
       
  2980 apply (metis Cons_eq_append_conv)
       
  2981 
       
  2982 
       
  2983 apply(erule Prf.cases)
       
  2984 apply(simp_all)[5]
       
  2985 apply(simp add: POSIX_def)
       
  2986 apply(simp)
       
  2987 apply(simp)
       
  2988 apply(simp_all)[5]
       
  2989 apply(simp add: POSIX_def)
       
  2990 
       
  2991 
       
  2992 lemma POSIX_proj:
       
  2993   assumes "POSIX v r" "\<turnstile> v : r" "\<exists>s. flat v = c#s"
       
  2994   shows "POSIX (projval r c v) (der c r)"
       
  2995 using assms
       
  2996 apply(induct r arbitrary: c v rule: rexp.induct)
       
  2997 apply(erule Prf.cases)
       
  2998 apply(simp_all)[5]
       
  2999 apply(erule Prf.cases)
       
  3000 apply(simp_all)[5]
       
  3001 apply(erule Prf.cases)
       
  3002 apply(simp_all)[5]
       
  3003 apply(simp add: POSIX_def)
       
  3004 apply(auto)[1]
       
  3005 apply(erule Prf.cases)
       
  3006 apply(simp_all)[5]
       
  3007 apply (metis ValOrd.intros(7))
       
  3008 
       
  3009 apply(erule Prf.cases)
       
  3010 apply(simp_all)[5]
       
  3011 apply(erule Prf.cases)
       
  3012 apply(simp_all)[5]
       
  3013 apply(erule Prf.cases)
       
  3014 apply(simp_all)[5]
       
  3015 apply(erule Prf.cases)
       
  3016 apply(simp_all)[5]
       
  3017 apply(erule Prf.cases)
       
  3018 apply(simp_all)[5]
       
  3019 apply(erule Prf.cases)
       
  3020 apply(simp_all)[5]
       
  3021 apply(simp add: POSIX_def)
       
  3022 apply(auto)[1]
       
  3023 apply(erule Prf.cases)
       
  3024 apply(simp_all)[5]
       
  3025 apply (metis ValOrd.intros(7))
       
  3026 apply(erule_tac [!] exE)
       
  3027 prefer 3
       
  3028 apply(frule POSIX_SEQ1)
       
  3029 apply(erule Prf.cases)
       
  3030 apply(simp_all)[5]
       
  3031 apply(erule Prf.cases)
       
  3032 apply(simp_all)[5]
       
  3033 apply(case_tac "flat v1 = []")
       
  3034 apply(subgoal_tac "nullable r1")
       
  3035 apply(simp)
       
  3036 prefer 2
       
  3037 apply(rule_tac v="v1" in Prf_flat_empty)
       
  3038 apply(erule Prf.cases)
       
  3039 apply(simp_all)[5]
       
  3040 
       
  3041 
       
  3042 lemma POSIX_proj:
       
  3043   assumes "POSIX v r" "\<turnstile> v : r" "\<exists>s. flat v = c#s"
       
  3044   shows "POSIX (projval r c v) (der c r)"
       
  3045 using assms
       
  3046 apply(induct r c v arbitrary: rule: projval.induct)
       
  3047 defer
       
  3048 defer
       
  3049 defer
       
  3050 defer
       
  3051 apply(erule Prf.cases)
       
  3052 apply(simp_all)[5]
       
  3053 apply(erule Prf.cases)
       
  3054 apply(simp_all)[5]
       
  3055 apply(erule Prf.cases)
       
  3056 apply(simp_all)[5]
       
  3057 apply(erule Prf.cases)
       
  3058 apply(simp_all)[5]
       
  3059 apply(erule Prf.cases)
       
  3060 apply(simp_all)[5]
       
  3061 apply(erule Prf.cases)
       
  3062 apply(simp_all)[5]
       
  3063 apply(erule Prf.cases)
       
  3064 apply(simp_all)[5]
       
  3065 apply(erule Prf.cases)
       
  3066 apply(simp_all)[5]
       
  3067 apply(erule Prf.cases)
       
  3068 apply(simp_all)[5]
       
  3069 apply(erule Prf.cases)
       
  3070 apply(simp_all)[5]
       
  3071 apply(simp add: POSIX_def)
       
  3072 apply(auto)[1]
       
  3073 apply(erule Prf.cases)
       
  3074 apply(simp_all)[5]
       
  3075 apply (metis ValOrd.intros(7))
       
  3076 apply(erule_tac [!] exE)
       
  3077 prefer 3
       
  3078 apply(frule POSIX_SEQ1)
       
  3079 apply(erule Prf.cases)
       
  3080 apply(simp_all)[5]
       
  3081 apply(erule Prf.cases)
       
  3082 apply(simp_all)[5]
       
  3083 apply(case_tac "flat v1 = []")
       
  3084 apply(subgoal_tac "nullable r1")
       
  3085 apply(simp)
       
  3086 prefer 2
       
  3087 apply(rule_tac v="v1" in Prf_flat_empty)
       
  3088 apply(erule Prf.cases)
       
  3089 apply(simp_all)[5]
       
  3090 apply(simp)
       
  3091 apply(rule ccontr)
       
  3092 apply(drule v3_proj)
       
  3093 apply(simp)
       
  3094 apply(simp)
       
  3095 apply(drule POSIX_ex)
       
  3096 apply(erule exE)
       
  3097 apply(frule POSIX_ALT_cases2)
       
  3098 apply(simp)
       
  3099 apply(simp)
       
  3100 apply(erule 
       
  3101 prefer 2
       
  3102 apply(case_tac "nullable r1")
       
  3103 prefer 2
       
  3104 apply(simp)
       
  3105 apply(rotate_tac 1)
       
  3106 apply(drule meta_mp)
       
  3107 apply(rule POSIX_SEQ1)
       
  3108 apply(assumption)
       
  3109 apply(erule Prf.cases)
       
  3110 apply(simp_all)[5]
       
  3111 apply(erule Prf.cases)
       
  3112 apply(simp_all)[5]
       
  3113 apply(rotate_tac 7)
       
  3114 apply(drule meta_mp)
       
  3115 apply(erule Prf.cases)
       
  3116 apply(simp_all)[5]
       
  3117 apply(rotate_tac 7)
       
  3118 apply(drule meta_mp)
       
  3119 apply (metis Cons_eq_append_conv)
       
  3120 
       
  3121 
       
  3122 apply(erule Prf.cases)
       
  3123 apply(simp_all)[5]
       
  3124 apply(simp add: POSIX_def)
       
  3125 apply(simp)
       
  3126 apply(simp)
       
  3127 apply(simp_all)[5]
       
  3128 apply(simp add: POSIX_def)
       
  3129 
       
  3130 done
       
  3131 (* NULL case *)
       
  3132 apply(simp add: POSIX_def)
       
  3133 apply(auto)[1]
       
  3134 apply(erule Prf.cases)
       
  3135 apply(simp_all)[5]
       
  3136 apply(erule Prf.cases)
       
  3137 apply(simp_all)[5]
       
  3138 apply (metis ValOrd.intros(7))
       
  3139 apply(rotate_tac 4)
       
  3140 apply(erule Prf.cases)
       
  3141 apply(simp_all)[5]
       
  3142 apply(simp)
       
  3143 prefer 2
       
  3144 apply(simp)
       
  3145 apply(frule POSIX_ALT1a)
       
  3146 apply(drule meta_mp)
       
  3147 apply(simp)
       
  3148 apply(drule meta_mp)
       
  3149 apply(erule Prf.cases)
       
  3150 apply(simp_all)[5]
       
  3151 apply(rule POSIX_ALT_I2)
       
  3152 apply(assumption)
       
  3153 apply(auto)[1]
       
  3154 
       
  3155 thm v4_proj2
       
  3156 prefer 2
       
  3157 apply(subst (asm) (13) POSIX_def)
       
  3158 
       
  3159 apply(drule_tac x="projval v2" in spec)
       
  3160 apply(auto)[1]
       
  3161 apply(drule mp)
       
  3162 apply(rule conjI)
       
  3163 apply(simp)
       
  3164 apply(simp)
       
  3165 
       
  3166 apply(erule Prf.cases)
       
  3167 apply(simp_all)[5]
       
  3168 apply(erule Prf.cases)
       
  3169 apply(simp_all)[5]
       
  3170 prefer 2
       
  3171 apply(clarify)
       
  3172 apply(subst (asm) (2) POSIX_def)
       
  3173 
       
  3174 apply (metis ValOrd.intros(5))
       
  3175 apply(clarify)
       
  3176 apply(simp)
       
  3177 apply(rotate_tac 3)
       
  3178 apply(drule_tac c="c" in t2)
       
  3179 apply(subst (asm) v4_proj)
       
  3180 apply(simp)
       
  3181 apply(simp)
       
  3182 thm contrapos_np contrapos_nn
       
  3183 apply(erule contrapos_np)
       
  3184 apply(rule ValOrd.intros)
       
  3185 apply(subst  v4_proj2)
       
  3186 apply(simp)
       
  3187 apply(simp)
       
  3188 apply(subgoal_tac "\<not>(length (flat v1) < length (flat (projval r2a c v2a)))")
       
  3189 prefer 2
       
  3190 apply(erule contrapos_nn)
       
  3191 apply (metis nat_less_le v4_proj2)
       
  3192 apply(simp)
       
  3193 
       
  3194 apply(blast)
       
  3195 thm contrapos_nn
       
  3196 
       
  3197 apply(simp add: POSIX_def)
       
  3198 apply(auto)[1]
       
  3199 apply(erule Prf.cases)
       
  3200 apply(simp_all)[5]
       
  3201 apply(erule Prf.cases)
       
  3202 apply(simp_all)[5]
       
  3203 apply(clarify)
       
  3204 apply(rule ValOrd.intros)
       
  3205 apply(drule meta_mp)
       
  3206 apply(auto)[1]
       
  3207 apply (metis POSIX_ALT2 POSIX_def flat.simps(3))
       
  3208 apply metis
       
  3209 apply(clarify)
       
  3210 apply(rule ValOrd.intros)
       
  3211 apply(simp)
       
  3212 apply(simp add: POSIX_def)
       
  3213 apply(auto)[1]
       
  3214 apply(erule Prf.cases)
       
  3215 apply(simp_all)[5]
       
  3216 apply(erule Prf.cases)
       
  3217 apply(simp_all)[5]
       
  3218 apply(clarify)
       
  3219 apply(rule ValOrd.intros)
       
  3220 apply(simp)
       
  3221 
       
  3222 apply(drule meta_mp)
       
  3223 apply(auto)[1]
       
  3224 apply (metis POSIX_ALT2 POSIX_def flat.simps(3))
       
  3225 apply metis
       
  3226 apply(clarify)
       
  3227 apply(rule ValOrd.intros)
       
  3228 apply(simp)
       
  3229 
       
  3230 
       
  3231 done
       
  3232 (* EMPTY case *)
       
  3233 apply(simp add: POSIX_def)
       
  3234 apply(auto)[1]
       
  3235 apply(rotate_tac 3)
       
  3236 apply(erule Prf.cases)
       
  3237 apply(simp_all)[5]
       
  3238 apply(drule_tac c="c" in t2)
       
  3239 apply(subst (asm) v4_proj)
       
  3240 apply(auto)[2]
       
  3241 
       
  3242 apply(erule ValOrd.cases)
       
  3243 apply(simp_all)[8]
       
  3244 (* CHAR case *)
       
  3245 apply(case_tac "c = c'")
       
  3246 apply(simp)
       
  3247 apply(erule ValOrd.cases)
       
  3248 apply(simp_all)[8]
       
  3249 apply(rule ValOrd.intros)
       
  3250 apply(simp)
       
  3251 apply(erule ValOrd.cases)
       
  3252 apply(simp_all)[8]
       
  3253 (* ALT case *)
       
  3254 
       
  3255 
       
  3256 unfolding POSIX_def
       
  3257 apply(auto)
       
  3258 thm v4
       
  3259 
       
  3260 lemma Prf_inj:
       
  3261   assumes "v1 \<succ>(der c r) v2" "\<turnstile> v1 : der c r" "\<turnstile> v2 : der c r" "flat v1 = flat v2"
       
  3262   shows "(injval r c v1) \<succ>r (injval r c v2)"
       
  3263 using assms
       
  3264 apply(induct arbitrary: v1 v2 rule: der.induct)
       
  3265 (* NULL case *)
       
  3266 apply(simp)
       
  3267 apply(erule ValOrd.cases)
       
  3268 apply(simp_all)[8]
       
  3269 (* EMPTY case *)
       
  3270 apply(erule ValOrd.cases)
       
  3271 apply(simp_all)[8]
       
  3272 (* CHAR case *)
       
  3273 apply(case_tac "c = c'")
       
  3274 apply(simp)
       
  3275 apply(erule ValOrd.cases)
       
  3276 apply(simp_all)[8]
       
  3277 apply(rule ValOrd.intros)
       
  3278 apply(simp)
       
  3279 apply(erule ValOrd.cases)
       
  3280 apply(simp_all)[8]
       
  3281 (* ALT case *)
       
  3282 apply(simp)
       
  3283 apply(erule ValOrd.cases)
       
  3284 apply(simp_all)[8]
       
  3285 apply(rule ValOrd.intros)
       
  3286 apply(subst v4)
       
  3287 apply(clarify)
       
  3288 apply(rotate_tac 3)
       
  3289 apply(erule Prf.cases)
       
  3290 apply(simp_all)[5]
       
  3291 apply(subst v4)
       
  3292 apply(clarify)
       
  3293 apply(rotate_tac 2)
       
  3294 apply(erule Prf.cases)
       
  3295 apply(simp_all)[5]
       
  3296 apply(simp)
       
  3297 apply(rule ValOrd.intros)
       
  3298 apply(clarify)
       
  3299 apply(rotate_tac 3)
       
  3300 apply(erule Prf.cases)
       
  3301 apply(simp_all)[5]
       
  3302 apply(clarify)
       
  3303 apply(erule Prf.cases)
       
  3304 apply(simp_all)[5]
       
  3305 apply(rule ValOrd.intros)
       
  3306 apply(clarify)
       
  3307 apply(erule Prf.cases)
       
  3308 apply(simp_all)[5]
       
  3309 apply(erule Prf.cases)
       
  3310 apply(simp_all)[5]
       
  3311 (* SEQ case*)
       
  3312 apply(simp)
       
  3313 apply(case_tac "nullable r1")
       
  3314 defer
       
  3315 apply(simp)
       
  3316 apply(erule ValOrd.cases)
       
  3317 apply(simp_all)[8]
       
  3318 apply(clarify)
       
  3319 apply(erule Prf.cases)
       
  3320 apply(simp_all)[5]
       
  3321 apply(erule Prf.cases)
       
  3322 apply(simp_all)[5]
       
  3323 apply(clarify)
       
  3324 apply(rule ValOrd.intros)
       
  3325 apply(simp)
       
  3326 apply(simp)
       
  3327 apply(rule ValOrd.intros(2))
       
  3328 apply(erule Prf.cases)
       
  3329 apply(simp_all)[5]
       
  3330 apply(erule Prf.cases)
       
  3331 apply(simp_all)[5]
       
  3332 apply(clarify)
       
  3333 defer
       
  3334 apply(simp)
       
  3335 apply(erule ValOrd.cases)
       
  3336 apply(simp_all del: injval.simps)[8]
       
  3337 apply(simp)
       
  3338 apply(clarify)
       
  3339 apply(simp)
       
  3340 apply(erule Prf.cases)
       
  3341 apply(simp_all)[5]
       
  3342 apply(erule Prf.cases)
       
  3343 apply(simp_all)[5]
       
  3344 apply(clarify)
       
  3345 apply(erule Prf.cases)
       
  3346 apply(simp_all)[5]
       
  3347 apply(clarify)
       
  3348 apply(rule ValOrd.intros(2))
       
  3349 
       
  3350 
       
  3351 
       
  3352 
       
  3353 done
       
  3354 
       
  3355 
       
  3356 txt {*
       
  3357 done
       
  3358 (* nullable case - unfinished *)
       
  3359 apply(simp)
       
  3360 apply(erule ValOrd.cases)
       
  3361 apply(simp_all del: injval.simps)[8]
       
  3362 apply(simp)
       
  3363 apply(clarify)
       
  3364 apply(simp)
       
  3365 apply(erule Prf.cases)
       
  3366 apply(simp_all)[5]
       
  3367 apply(erule Prf.cases)
       
  3368 apply(simp_all)[5]
       
  3369 apply(clarify)
       
  3370 apply(erule Prf.cases)
       
  3371 apply(simp_all)[5]
       
  3372 apply(clarify)
       
  3373 apply(simp)
       
  3374 apply(rule ValOrd.intros(2))
       
  3375 oops
       
  3376 *}
       
  3377 oops
       
  3378 
       
  3379 
       
  3380 
       
  3381 text {*
       
  3382   Injection followed by projection is the identity.
       
  3383 *}
       
  3384 
       
  3385 lemma proj_inj_id:
       
  3386   assumes "\<turnstile> v : der c r" 
       
  3387   shows "projval r c (injval r c v) = v"
       
  3388 using assms
       
  3389 apply(induct r arbitrary: c v rule: rexp.induct)
       
  3390 apply(simp)
       
  3391 apply(erule Prf.cases)
       
  3392 apply(simp_all)[5]
       
  3393 apply(simp)
       
  3394 apply(erule Prf.cases)
       
  3395 apply(simp_all)[5]
       
  3396 apply(simp)
       
  3397 apply(case_tac "c = char")
       
  3398 apply(simp)
       
  3399 apply(erule Prf.cases)
       
  3400 apply(simp_all)[5]
       
  3401 apply(simp)
       
  3402 apply(erule Prf.cases)
       
  3403 apply(simp_all)[5]
       
  3404 defer
       
  3405 apply(simp)
       
  3406 apply(erule Prf.cases)
       
  3407 apply(simp_all)[5]
       
  3408 apply(simp)
       
  3409 apply(case_tac "nullable rexp1")
       
  3410 apply(simp)
       
  3411 apply(erule Prf.cases)
       
  3412 apply(simp_all)[5]
       
  3413 apply(auto)[1]
       
  3414 apply(erule Prf.cases)
       
  3415 apply(simp_all)[5]
       
  3416 apply(auto)[1]
       
  3417 apply (metis list.distinct(1) v4)
       
  3418 apply(auto)[1]
       
  3419 apply (metis mkeps_flat)
       
  3420 apply(auto)
       
  3421 apply(erule Prf.cases)
       
  3422 apply(simp_all)[5]
       
  3423 apply(auto)[1]
       
  3424 apply(simp add: v4)
       
  3425 done
       
  3426 
       
  3427 lemma "L r \<noteq> {} \<Longrightarrow> \<exists>v. POSIX3 v r"
       
  3428 apply(induct r)
       
  3429 apply(simp)
       
  3430 apply(simp add: POSIX3_def)
       
  3431 apply(rule_tac x="Void" in exI)
       
  3432 apply(auto)[1]
       
  3433 apply (metis Prf.intros(4))
       
  3434 apply (metis POSIX3_def flat.simps(1) mkeps.simps(1) mkeps_POSIX3 nullable.simps(2) order_refl)
       
  3435 apply(simp add: POSIX3_def)
       
  3436 apply(rule_tac x="Char char" in exI)
       
  3437 apply(auto)[1]
       
  3438 apply (metis Prf.intros(5))
       
  3439 apply(erule Prf.cases)
       
  3440 apply(simp_all)[5]
       
  3441 apply (metis ValOrd.intros(8))
       
  3442 apply(simp add: Sequ_def)
       
  3443 apply(auto)[1]
       
  3444 apply(drule meta_mp)
       
  3445 apply(auto)[2]
       
  3446 apply(drule meta_mp)
       
  3447 apply(auto)[2]
       
  3448 apply(rule_tac x="Seq v va" in exI)
       
  3449 apply(simp (no_asm) add: POSIX3_def)
       
  3450 apply(auto)[1]
       
  3451 apply (metis POSIX3_def Prf.intros(1))
       
  3452 apply(erule Prf.cases)
       
  3453 apply(simp_all)[5]
       
  3454 apply(clarify)
       
  3455 apply(case_tac "v  \<succ>r1a v1")
       
  3456 apply(rule ValOrd.intros(2))
       
  3457 apply(simp)
       
  3458 apply(case_tac "v = v1")
       
  3459 apply(rule ValOrd.intros(1))
       
  3460 apply(simp)
       
  3461 apply(simp)
       
  3462 apply (metis ValOrd_refl)
       
  3463 apply(simp add: POSIX3_def)
       
  3464 oops
       
  3465 
       
  3466 lemma "\<exists>v. POSIX v r"
       
  3467 apply(induct r)
       
  3468 apply(rule exI)
       
  3469 apply(simp add: POSIX_def)
       
  3470 apply (metis (full_types) Prf_flat_L der.simps(1) der.simps(2) der.simps(3) flat.simps(1) nullable.simps(1) nullable_correctness proj_inj_id projval.simps(1) v3 v4)
       
  3471 apply(rule_tac x = "Void" in exI)
       
  3472 apply(simp add: POSIX_def)
       
  3473 apply (metis POSIX_def flat.simps(1) mkeps.simps(1) mkeps_POSIX nullable.simps(2))
       
  3474 apply(rule_tac x = "Char char" in exI)
       
  3475 apply(simp add: POSIX_def)
       
  3476 apply(auto) [1]
       
  3477 apply(erule Prf.cases)
       
  3478 apply(simp_all) [5]
       
  3479 apply (metis ValOrd.intros(8))
       
  3480 defer
       
  3481 apply(auto)
       
  3482 apply (metis POSIX_ALT_I1)
       
  3483 (* maybe it is too early to instantiate this existential quantifier *)
       
  3484 (* potentially this is the wrong POSIX value *)
       
  3485 apply(case_tac "r1 = NULL")
       
  3486 apply(simp add: POSIX_def)
       
  3487 apply(auto)[1]
       
  3488 apply (metis L.simps(1) L.simps(4) Prf_flat_L mkeps_flat nullable.simps(1) nullable.simps(2) nullable_correctness seq_null(2))
       
  3489 apply(case_tac "r1 = EMPTY")
       
  3490 apply(rule_tac x = "Seq Void va" in exI )
       
  3491 apply(simp (no_asm) add: POSIX_def)
       
  3492 apply(auto)
       
  3493 apply(erule Prf.cases)
       
  3494 apply(simp_all)
       
  3495 apply(auto)[1]
       
  3496 apply(erule Prf.cases)
       
  3497 apply(simp_all)
       
  3498 apply(rule ValOrd.intros(2))
       
  3499 apply(rule ValOrd.intros)
       
  3500 apply(case_tac "\<exists>c. r1 = CHAR c")
       
  3501 apply(auto)
       
  3502 apply(rule_tac x = "Seq (Char c) va" in exI )
       
  3503 apply(simp (no_asm) add: POSIX_def)
       
  3504 apply(auto)
       
  3505 apply(erule Prf.cases)
       
  3506 apply(simp_all)
       
  3507 apply(auto)[1]
       
  3508 apply(erule Prf.cases)
       
  3509 apply(simp_all)
       
  3510 apply(auto)[1]
       
  3511 apply(rule ValOrd.intros(2))
       
  3512 apply(rule ValOrd.intros)
       
  3513 apply(case_tac "\<exists>r1a r1b. r1 = ALT r1a r1b")
       
  3514 apply(auto)
       
  3515 oops (* not sure if this can be proved by induction *)
       
  3516 
       
  3517 text {* 
       
  3518 
       
  3519   HERE: Crucial lemma that does not go through in the sequence case. 
       
  3520 
       
  3521 *}
       
  3522 lemma v5:
       
  3523   assumes "\<turnstile> v : der c r" "POSIX v (der c r)"
       
  3524   shows "POSIX (injval r c v) r"
       
  3525 using assms
       
  3526 apply(induct arbitrary: v rule: der.induct)
       
  3527 (* NULL case *)
       
  3528 apply(simp)
       
  3529 apply(erule Prf.cases)
       
  3530 apply(simp_all)[5]
       
  3531 (* EMPTY case *)
       
  3532 apply(simp)
       
  3533 apply(erule Prf.cases)
       
  3534 apply(simp_all)[5]
       
  3535 (* CHAR case *)
       
  3536 apply(simp)
       
  3537 apply(case_tac "c = c'")
       
  3538 apply(auto simp add: POSIX_def)[1]
       
  3539 apply(erule Prf.cases)
       
  3540 apply(simp_all)[5]
       
  3541 apply(erule Prf.cases)
       
  3542 apply(simp_all)[5]
       
  3543 apply(rule ValOrd.intros)
       
  3544 apply(auto)[1]
       
  3545 apply(erule Prf.cases)
       
  3546 apply(simp_all)[5]
       
  3547 (* base cases done *)
       
  3548 (* ALT case *)
       
  3549 apply(erule Prf.cases)
       
  3550 apply(simp_all)[5]
       
  3551 using POSIX_ALT POSIX_ALT_I1 apply blast
       
  3552 apply(clarify)
       
  3553 apply(simp)
       
  3554 apply(rule POSIX_ALT_I2)
       
  3555 apply(drule POSIX_ALT1a)
       
  3556 apply metis
       
  3557 apply(auto)[1]
       
  3558 apply(subst v4)
       
  3559 apply(assumption)
       
  3560 apply(simp)
       
  3561 apply(drule POSIX_ALT1a)
       
  3562 apply(rotate_tac 1)
       
  3563 apply(drule_tac x="v2" in meta_spec)
       
  3564 apply(simp)
       
  3565 
       
  3566 apply(rotate_tac 4)
       
  3567 apply(erule Prf.cases)
       
  3568 apply(simp_all)[5]
       
  3569 apply(rule ValOrd.intros)
       
  3570 apply(simp)
       
  3571 apply(subst (asm) v4)
       
  3572 apply(assumption)
       
  3573 apply(clarify)
       
  3574 thm POSIX_ALT1a POSIX_ALT1b POSIX_ALT_I2
       
  3575 apply(subst (asm) v4)
       
  3576 apply(auto simp add: POSIX_def)[1]
       
  3577 apply(subgoal_tac "POSIX v2 (der c r2)")
       
  3578 prefer 2
       
  3579 apply(auto simp add: POSIX_def)[1]
       
  3580 apply (metis POSIX_ALT1a POSIX_def flat.simps(4))
       
  3581 apply(frule POSIX_ALT1a)
       
  3582 apply(drule POSIX_ALT1b)
       
  3583 apply(rule POSIX_ALT_I2)
       
  3584 apply(rotate_tac 1)
       
  3585 apply(drule_tac x="v2" in meta_spec)
       
  3586 apply(simp)
       
  3587 apply(subgoal_tac "\<turnstile> Right (injval r2 c v2) : (ALT r1 r2)")
       
  3588 prefer 2
       
  3589 apply (metis Prf.intros(3) v3)
       
  3590 apply auto[1]
       
  3591 apply(subst v4)
       
  3592 apply(auto)[2]
       
  3593 apply(subst (asm) (4) POSIX_def)
       
  3594 apply(subst (asm) v4)
       
  3595 apply(drule_tac x="v2" in meta_spec)
       
  3596 apply(simp)
       
  3597 
       
  3598 apply(auto)[2]
       
  3599 
       
  3600 thm POSIX_ALT_I2
       
  3601 apply(rule POSIX_ALT_I2)
       
  3602 
       
  3603 apply(rule ccontr)
       
  3604 apply(auto simp add: POSIX_def)[1]
       
  3605 
       
  3606 apply(rule allI)
       
  3607 apply(rule impI)
       
  3608 apply(erule conjE)
       
  3609 thm POSIX_ALT_I2
       
  3610 apply(frule POSIX_ALT1a)
       
  3611 apply(drule POSIX_ALT1b)
       
  3612 apply(rule POSIX_ALT_I2)
       
  3613 apply auto[1]
       
  3614 apply(subst v4)
       
  3615 apply(auto)[2]
       
  3616 apply(rotate_tac 1)
       
  3617 apply(drule_tac x="v2" in meta_spec)
       
  3618 apply(simp)
       
  3619 apply(subst (asm) (4) POSIX_def)
       
  3620 apply(subst (asm) v4)
       
  3621 apply(auto)[2]
       
  3622 (* stuck in the ALT case *)