AFP-Submission/Lexer.thy
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Fri, 03 Jun 2016 11:07:10 +0100
changeset 193 1fd7388360b6
parent 191 6bb15b8e6301
permissions -rw-r--r--
typos
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
191
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     1
(*  Title:       POSIX Lexing with Derivatives of Regular Expressions
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     2
    Authors:     Fahad Ausaf <fahad.ausaf at icloud.com>, 2016
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     3
                 Roy Dyckhoff <roy.dyckhoff at st-andrews.ac.uk>, 2016
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     4
                 Christian Urban <christian.urban at kcl.ac.uk>, 2016
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     5
    Maintainer:  Christian Urban <christian.urban at kcl.ac.uk>
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     6
*) 
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     7
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     8
theory Lexer
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     9
  imports Derivatives
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    10
begin
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    11
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    12
section {* Values *}
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    13
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    14
datatype 'a val = 
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    15
  Void
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    16
| Atm 'a
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    17
| Seq "'a val" "'a val"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    18
| Right "'a val"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    19
| Left "'a val"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    20
| Stars "('a val) list"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    21
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    22
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    23
section {* The string behind a value *}
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    24
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    25
fun 
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    26
  flat :: "'a val \<Rightarrow> 'a list"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    27
where
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    28
  "flat (Void) = []"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    29
| "flat (Atm c) = [c]"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    30
| "flat (Left v) = flat v"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    31
| "flat (Right v) = flat v"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    32
| "flat (Seq v1 v2) = (flat v1) @ (flat v2)"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    33
| "flat (Stars []) = []"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    34
| "flat (Stars (v#vs)) = (flat v) @ (flat (Stars vs))" 
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    35
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    36
lemma flat_Stars [simp]:
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    37
 "flat (Stars vs) = concat (map flat vs)"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    38
by (induct vs) (auto)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    39
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    40
section {* Relation between values and regular expressions *}
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    41
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    42
inductive 
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    43
  Prf :: "'a val \<Rightarrow> 'a rexp \<Rightarrow> bool" ("\<turnstile> _ : _" [100, 100] 100)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    44
where
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    45
 "\<lbrakk>\<turnstile> v1 : r1; \<turnstile> v2 : r2\<rbrakk> \<Longrightarrow> \<turnstile> Seq v1 v2 : Times r1 r2"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    46
| "\<turnstile> v1 : r1 \<Longrightarrow> \<turnstile> Left v1 : Plus r1 r2"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    47
| "\<turnstile> v2 : r2 \<Longrightarrow> \<turnstile> Right v2 : Plus r1 r2"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    48
| "\<turnstile> Void : One"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    49
| "\<turnstile> Atm c : Atom c"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    50
| "\<turnstile> Stars [] : Star r"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    51
| "\<lbrakk>\<turnstile> v : r; \<turnstile> Stars vs : Star r\<rbrakk> \<Longrightarrow> \<turnstile> Stars (v # vs) : Star r"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    52
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    53
inductive_cases Prf_elims:
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    54
  "\<turnstile> v : Zero"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    55
  "\<turnstile> v : Times r1 r2"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    56
  "\<turnstile> v : Plus r1 r2"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    57
  "\<turnstile> v : One"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    58
  "\<turnstile> v : Atom c"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    59
(*  "\<turnstile> vs : Star r"*)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    60
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    61
lemma Prf_flat_lang:
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    62
  assumes "\<turnstile> v : r" shows "flat v \<in> lang r"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    63
using assms
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    64
by(induct v r rule: Prf.induct) (auto)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    65
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    66
lemma Prf_Stars:
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    67
  assumes "\<forall>v \<in> set vs. \<turnstile> v : r"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    68
  shows "\<turnstile> Stars vs : Star r"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    69
using assms
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    70
by(induct vs) (auto intro: Prf.intros)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    71
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    72
lemma Star_string:
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    73
  assumes "s \<in> star A"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    74
  shows "\<exists>ss. concat ss = s \<and> (\<forall>s \<in> set ss. s \<in> A)"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    75
using assms
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    76
by (metis in_star_iff_concat set_mp)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    77
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    78
lemma Star_val:
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    79
  assumes "\<forall>s\<in>set ss. \<exists>v. s = flat v \<and> \<turnstile> v : r"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    80
  shows "\<exists>vs. concat (map flat vs) = concat ss \<and> (\<forall>v\<in>set vs. \<turnstile> v : r)"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    81
using assms
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    82
apply(induct ss)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    83
apply(auto)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    84
apply (metis empty_iff list.set(1))
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    85
by (metis concat.simps(2) list.simps(9) set_ConsD)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    86
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    87
lemma L_flat_Prf1:
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    88
  assumes "\<turnstile> v : r" shows "flat v \<in> lang r"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    89
using assms
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    90
by (induct)(auto)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    91
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    92
lemma L_flat_Prf2:
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    93
  assumes "s \<in> lang r" shows "\<exists>v. \<turnstile> v : r \<and> flat v = s"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    94
using assms
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    95
apply(induct r arbitrary: s)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    96
apply(auto intro: Prf.intros)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    97
using Prf.intros(2) flat.simps(3) apply blast
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    98
using Prf.intros(3) flat.simps(4) apply blast
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    99
apply (metis Prf.intros(1) concE flat.simps(5))
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   100
apply(subgoal_tac "\<exists>vs::('a val) list. concat (map flat vs) = s \<and> (\<forall>v \<in> set vs. \<turnstile> v : r)")
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   101
apply(auto)[1]
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   102
apply(rule_tac x="Stars vs" in exI)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   103
apply(simp)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   104
apply (simp add: Prf_Stars)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   105
apply(drule Star_string)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   106
apply(auto)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   107
apply(rule Star_val)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   108
apply(auto)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   109
done
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   110
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   111
lemma L_flat_Prf:
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   112
  "lang r = {flat v | v. \<turnstile> v : r}"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   113
using L_flat_Prf1 L_flat_Prf2 by blast
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   114
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   115
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   116
section {* Sulzmann and Lu functions *}
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   117
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   118
fun 
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   119
  mkeps :: "'a rexp \<Rightarrow> 'a val"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   120
where
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   121
  "mkeps(One) = Void"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   122
| "mkeps(Times r1 r2) = Seq (mkeps r1) (mkeps r2)"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   123
| "mkeps(Plus r1 r2) = (if nullable(r1) then Left (mkeps r1) else Right (mkeps r2))"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   124
| "mkeps(Star r) = Stars []"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   125
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   126
fun injval :: "'a rexp \<Rightarrow> 'a \<Rightarrow> 'a val \<Rightarrow> 'a val"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   127
where
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   128
  "injval (Atom d) c Void = Atm d"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   129
| "injval (Plus r1 r2) c (Left v1) = Left(injval r1 c v1)"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   130
| "injval (Plus r1 r2) c (Right v2) = Right(injval r2 c v2)"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   131
| "injval (Times r1 r2) c (Seq v1 v2) = Seq (injval r1 c v1) v2"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   132
| "injval (Times r1 r2) c (Left (Seq v1 v2)) = Seq (injval r1 c v1) v2"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   133
| "injval (Times r1 r2) c (Right v2) = Seq (mkeps r1) (injval r2 c v2)"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   134
| "injval (Star r) c (Seq v (Stars vs)) = Stars ((injval r c v) # vs)" 
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   135
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   136
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   137
section {* Mkeps, injval *}
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   138
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   139
lemma mkeps_nullable:
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   140
  assumes "nullable r" 
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   141
  shows "\<turnstile> mkeps r : r"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   142
using assms
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   143
by (induct r) 
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   144
   (auto intro: Prf.intros)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   145
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   146
lemma mkeps_flat:
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   147
  assumes "nullable r" 
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   148
  shows "flat (mkeps r) = []"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   149
using assms
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   150
by (induct r) (auto)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   151
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   152
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   153
lemma Prf_injval:
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   154
  assumes "\<turnstile> v : deriv c r" 
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   155
  shows "\<turnstile> (injval r c v) : r"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   156
using assms
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   157
apply(induct r arbitrary: c v rule: rexp.induct)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   158
apply(auto intro!: Prf.intros mkeps_nullable elim!: Prf_elims split: if_splits)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   159
(* Star *)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   160
apply(rotate_tac 2)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   161
apply(erule Prf.cases)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   162
apply(simp_all)[7]
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   163
apply(auto)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   164
apply (metis Prf.intros(6) Prf.intros(7))
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   165
by (metis Prf.intros(7))
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   166
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   167
lemma Prf_injval_flat:
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   168
  assumes "\<turnstile> v : deriv c r" 
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   169
  shows "flat (injval r c v) = c # (flat v)"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   170
using assms
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   171
apply(induct r arbitrary: v c)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   172
apply(auto elim!: Prf_elims split: if_splits)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   173
apply(metis mkeps_flat)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   174
apply(rotate_tac 2)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   175
apply(erule Prf.cases)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   176
apply(simp_all)[7]
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   177
done
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   178
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   179
(* HERE *)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   180
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   181
section {* Our Alternative Posix definition *}
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   182
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   183
inductive 
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   184
  Posix :: "'a list \<Rightarrow> 'a rexp \<Rightarrow> 'a val \<Rightarrow> bool" ("_ \<in> _ \<rightarrow> _" [100, 100, 100] 100)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   185
where
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   186
  Posix_One: "[] \<in> One \<rightarrow> Void"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   187
| Posix_Atom: "[c] \<in> (Atom c) \<rightarrow> (Atm c)"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   188
| Posix_Plus1: "s \<in> r1 \<rightarrow> v \<Longrightarrow> s \<in> (Plus r1 r2) \<rightarrow> (Left v)"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   189
| Posix_Plus2: "\<lbrakk>s \<in> r2 \<rightarrow> v; s \<notin> lang r1\<rbrakk> \<Longrightarrow> s \<in> (Plus r1 r2) \<rightarrow> (Right v)"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   190
| Posix_Times: "\<lbrakk>s1 \<in> r1 \<rightarrow> v1; s2 \<in> r2 \<rightarrow> v2;
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   191
    \<not>(\<exists>s\<^sub>3 s\<^sub>4. s\<^sub>3 \<noteq> [] \<and> s\<^sub>3 @ s\<^sub>4 = s2 \<and> (s1 @ s\<^sub>3) \<in> lang r1 \<and> s\<^sub>4 \<in> lang r2)\<rbrakk> \<Longrightarrow> 
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   192
    (s1 @ s2) \<in> (Times r1 r2) \<rightarrow> (Seq v1 v2)"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   193
| Posix_Star1: "\<lbrakk>s1 \<in> r \<rightarrow> v; s2 \<in> Star r \<rightarrow> Stars vs; flat v \<noteq> [];
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   194
    \<not>(\<exists>s\<^sub>3 s\<^sub>4. s\<^sub>3 \<noteq> [] \<and> s\<^sub>3 @ s\<^sub>4 = s2 \<and> (s1 @ s\<^sub>3) \<in> lang r \<and> s\<^sub>4 \<in> lang (Star r))\<rbrakk>
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   195
    \<Longrightarrow> (s1 @ s2) \<in> Star r \<rightarrow> Stars (v # vs)"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   196
| Posix_Star2: "[] \<in> Star r \<rightarrow> Stars []"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   197
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   198
inductive_cases Posix_elims:
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   199
  "s \<in> Zero \<rightarrow> v"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   200
  "s \<in> One \<rightarrow> v"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   201
  "s \<in> Atom c \<rightarrow> v"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   202
  "s \<in> Plus r1 r2 \<rightarrow> v"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   203
  "s \<in> Times r1 r2 \<rightarrow> v"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   204
  "s \<in> Star r \<rightarrow> v"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   205
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   206
lemma Posix1:
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   207
  assumes "s \<in> r \<rightarrow> v"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   208
  shows "s \<in> lang r" "flat v = s"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   209
using assms
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   210
by (induct s r v rule: Posix.induct) (auto)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   211
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   212
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   213
lemma Posix1a:
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   214
  assumes "s \<in> r \<rightarrow> v"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   215
  shows "\<turnstile> v : r"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   216
using assms
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   217
by (induct s r v rule: Posix.induct)(auto intro: Prf.intros)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   218
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   219
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   220
lemma Posix_mkeps:
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   221
  assumes "nullable r"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   222
  shows "[] \<in> r \<rightarrow> mkeps r"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   223
using assms
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   224
apply(induct r)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   225
apply(auto intro: Posix.intros simp add: nullable_iff)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   226
apply(subst append.simps(1)[symmetric])
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   227
apply(rule Posix.intros)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   228
apply(auto)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   229
done
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   230
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   231
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   232
lemma Posix_determ:
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   233
  assumes "s \<in> r \<rightarrow> v1" "s \<in> r \<rightarrow> v2"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   234
  shows "v1 = v2"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   235
using assms
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   236
proof (induct s r v1 arbitrary: v2 rule: Posix.induct)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   237
  case (Posix_One v2)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   238
  have "[] \<in> One \<rightarrow> v2" by fact
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   239
  then show "Void = v2" by cases auto
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   240
next 
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   241
  case (Posix_Atom c v2)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   242
  have "[c] \<in> Atom c \<rightarrow> v2" by fact
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   243
  then show "Atm c = v2" by cases auto
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   244
next 
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   245
  case (Posix_Plus1 s r1 v r2 v2)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   246
  have "s \<in> Plus r1 r2 \<rightarrow> v2" by fact
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   247
  moreover
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   248
  have "s \<in> r1 \<rightarrow> v" by fact
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   249
  then have "s \<in> lang r1" by (simp add: Posix1)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   250
  ultimately obtain v' where eq: "v2 = Left v'" "s \<in> r1 \<rightarrow> v'" by cases auto 
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   251
  moreover
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   252
  have IH: "\<And>v2. s \<in> r1 \<rightarrow> v2 \<Longrightarrow> v = v2" by fact
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   253
  ultimately have "v = v'" by simp
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   254
  then show "Left v = v2" using eq by simp
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   255
next 
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   256
  case (Posix_Plus2 s r2 v r1 v2)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   257
  have "s \<in> Plus r1 r2 \<rightarrow> v2" by fact
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   258
  moreover
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   259
  have "s \<notin> lang r1" by fact
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   260
  ultimately obtain v' where eq: "v2 = Right v'" "s \<in> r2 \<rightarrow> v'" 
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   261
    by cases (auto simp add: Posix1) 
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   262
  moreover
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   263
  have IH: "\<And>v2. s \<in> r2 \<rightarrow> v2 \<Longrightarrow> v = v2" by fact
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   264
  ultimately have "v = v'" by simp
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   265
  then show "Right v = v2" using eq by simp
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   266
next
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   267
  case (Posix_Times s1 r1 v1 s2 r2 v2 v')
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   268
  have "(s1 @ s2) \<in> Times r1 r2 \<rightarrow> v'" 
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   269
       "s1 \<in> r1 \<rightarrow> v1" "s2 \<in> r2 \<rightarrow> v2"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   270
       "\<not> (\<exists>s\<^sub>3 s\<^sub>4. s\<^sub>3 \<noteq> [] \<and> s\<^sub>3 @ s\<^sub>4 = s2 \<and> s1 @ s\<^sub>3 \<in> lang r1 \<and> s\<^sub>4 \<in> lang r2)" by fact+
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   271
  then obtain v1' v2' where "v' = Seq v1' v2'" "s1 \<in> r1 \<rightarrow> v1'" "s2 \<in> r2 \<rightarrow> v2'"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   272
  apply(cases) apply (auto simp add: append_eq_append_conv2)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   273
  using Posix1(1) by fastforce+
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   274
  moreover
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   275
  have IHs: "\<And>v1'. s1 \<in> r1 \<rightarrow> v1' \<Longrightarrow> v1 = v1'"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   276
            "\<And>v2'. s2 \<in> r2 \<rightarrow> v2' \<Longrightarrow> v2 = v2'" by fact+
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   277
  ultimately show "Seq v1 v2 = v'" by simp
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   278
next
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   279
  case (Posix_Star1 s1 r v s2 vs v2)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   280
  have "(s1 @ s2) \<in> Star r \<rightarrow> v2" 
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   281
       "s1 \<in> r \<rightarrow> v" "s2 \<in> Star r \<rightarrow> Stars vs" "flat v \<noteq> []"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   282
       "\<not> (\<exists>s\<^sub>3 s\<^sub>4. s\<^sub>3 \<noteq> [] \<and> s\<^sub>3 @ s\<^sub>4 = s2 \<and> s1 @ s\<^sub>3 \<in> lang r \<and> s\<^sub>4 \<in> lang (Star r))" by fact+
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   283
  then obtain v' vs' where "v2 = Stars (v' # vs')" "s1 \<in> r \<rightarrow> v'" "s2 \<in> (Star r) \<rightarrow> (Stars vs')"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   284
  apply(cases) apply (auto simp add: append_eq_append_conv2)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   285
  using Posix1(1) apply fastforce
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   286
  apply (metis Posix1(1) Posix_Star1.hyps(6) append_Nil append_Nil2)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   287
  using Posix1(2) by blast
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   288
  moreover
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   289
  have IHs: "\<And>v2. s1 \<in> r \<rightarrow> v2 \<Longrightarrow> v = v2"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   290
            "\<And>v2. s2 \<in> Star r \<rightarrow> v2 \<Longrightarrow> Stars vs = v2" by fact+
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   291
  ultimately show "Stars (v # vs) = v2" by auto
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   292
next
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   293
  case (Posix_Star2 r v2)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   294
  have "[] \<in> Star r \<rightarrow> v2" by fact
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   295
  then show "Stars [] = v2" by cases (auto simp add: Posix1)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   296
qed
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   297
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   298
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   299
lemma Posix_injval:
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   300
  assumes "s \<in> (deriv c r) \<rightarrow> v"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   301
  shows "(c # s) \<in> r \<rightarrow> (injval r c v)"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   302
using assms
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   303
proof(induct r arbitrary: s v rule: rexp.induct)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   304
  case Zero
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   305
  have "s \<in> deriv c Zero \<rightarrow> v" by fact
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   306
  then have "s \<in> Zero \<rightarrow> v" by simp
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   307
  then have "False" by cases
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   308
  then show "(c # s) \<in> Zero \<rightarrow> (injval Zero c v)" by simp
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   309
next
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   310
  case One
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   311
  have "s \<in> deriv c One \<rightarrow> v" by fact
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   312
  then have "s \<in> Zero \<rightarrow> v" by simp
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   313
  then have "False" by cases
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   314
  then show "(c # s) \<in> One \<rightarrow> (injval One c v)" by simp
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   315
next 
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   316
  case (Atom d)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   317
  consider (eq) "c = d" | (ineq) "c \<noteq> d" by blast
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   318
  then show "(c # s) \<in> (Atom d) \<rightarrow> (injval (Atom d) c v)"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   319
  proof (cases)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   320
    case eq
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   321
    have "s \<in> deriv c (Atom d) \<rightarrow> v" by fact
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   322
    then have "s \<in> One \<rightarrow> v" using eq by simp
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   323
    then have eqs: "s = [] \<and> v = Void" by cases simp
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   324
    show "(c # s) \<in> Atom d \<rightarrow> injval (Atom d) c v" using eq eqs 
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   325
    by (auto intro: Posix.intros)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   326
  next
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   327
    case ineq
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   328
    have "s \<in> deriv c (Atom d) \<rightarrow> v" by fact
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   329
    then have "s \<in> Zero \<rightarrow> v" using ineq by simp
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   330
    then have "False" by cases
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   331
    then show "(c # s) \<in> Atom d \<rightarrow> injval (Atom d) c v" by simp
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   332
  qed
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   333
next
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   334
  case (Plus r1 r2)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   335
  have IH1: "\<And>s v. s \<in> deriv c r1 \<rightarrow> v \<Longrightarrow> (c # s) \<in> r1 \<rightarrow> injval r1 c v" by fact
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   336
  have IH2: "\<And>s v. s \<in> deriv c r2 \<rightarrow> v \<Longrightarrow> (c # s) \<in> r2 \<rightarrow> injval r2 c v" by fact
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   337
  have "s \<in> deriv c (Plus r1 r2) \<rightarrow> v" by fact
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   338
  then have "s \<in> Plus (deriv c r1) (deriv c r2) \<rightarrow> v" by simp
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   339
  then consider (left) v' where "v = Left v'" "s \<in> deriv c r1 \<rightarrow> v'" 
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   340
              | (right) v' where "v = Right v'" "s \<notin> lang (deriv c r1)" "s \<in> deriv c r2 \<rightarrow> v'" 
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   341
              by cases auto
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   342
  then show "(c # s) \<in> Plus r1 r2 \<rightarrow> injval (Plus r1 r2) c v"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   343
  proof (cases)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   344
    case left
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   345
    have "s \<in> deriv c r1 \<rightarrow> v'" by fact
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   346
    then have "(c # s) \<in> r1 \<rightarrow> injval r1 c v'" using IH1 by simp
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   347
    then have "(c # s) \<in> Plus r1 r2 \<rightarrow> injval (Plus r1 r2) c (Left v')" by (auto intro: Posix.intros)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   348
    then show "(c # s) \<in> Plus r1 r2 \<rightarrow> injval (Plus r1 r2) c v" using left by simp
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   349
  next 
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   350
    case right
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   351
    have "s \<notin> lang (deriv c r1)" by fact
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   352
    then have "c # s \<notin> lang r1" by (simp add: lang_deriv Deriv_def)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   353
    moreover 
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   354
    have "s \<in> deriv c r2 \<rightarrow> v'" by fact
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   355
    then have "(c # s) \<in> r2 \<rightarrow> injval r2 c v'" using IH2 by simp
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   356
    ultimately have "(c # s) \<in> Plus r1 r2 \<rightarrow> injval (Plus r1 r2) c (Right v')" 
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   357
      by (auto intro: Posix.intros)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   358
    then show "(c # s) \<in> Plus r1 r2 \<rightarrow> injval (Plus r1 r2) c v" using right by simp
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   359
  qed
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   360
next
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   361
  case (Times r1 r2)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   362
  have IH1: "\<And>s v. s \<in> deriv c r1 \<rightarrow> v \<Longrightarrow> (c # s) \<in> r1 \<rightarrow> injval r1 c v" by fact
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   363
  have IH2: "\<And>s v. s \<in> deriv c r2 \<rightarrow> v \<Longrightarrow> (c # s) \<in> r2 \<rightarrow> injval r2 c v" by fact
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   364
  have "s \<in> deriv c (Times r1 r2) \<rightarrow> v" by fact
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   365
  then consider 
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   366
        (left_nullable) v1 v2 s1 s2 where 
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   367
        "v = Left (Seq v1 v2)"  "s = s1 @ s2" 
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   368
        "s1 \<in> deriv c r1 \<rightarrow> v1" "s2 \<in> r2 \<rightarrow> v2" "nullable r1" 
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   369
        "\<not> (\<exists>s\<^sub>3 s\<^sub>4. s\<^sub>3 \<noteq> [] \<and> s\<^sub>3 @ s\<^sub>4 = s2 \<and> s1 @ s\<^sub>3 \<in> lang (deriv c r1) \<and> s\<^sub>4 \<in> lang r2)"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   370
      | (right_nullable) v1 s1 s2 where 
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   371
        "v = Right v1" "s = s1 @ s2"  
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   372
        "s \<in> deriv c r2 \<rightarrow> v1" "nullable r1" "s1 @ s2 \<notin> lang (Times (deriv c r1) r2)"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   373
      | (not_nullable) v1 v2 s1 s2 where
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   374
        "v = Seq v1 v2" "s = s1 @ s2" 
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   375
        "s1 \<in> deriv c r1 \<rightarrow> v1" "s2 \<in> r2 \<rightarrow> v2" "\<not>nullable r1" 
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   376
        "\<not> (\<exists>s\<^sub>3 s\<^sub>4. s\<^sub>3 \<noteq> [] \<and> s\<^sub>3 @ s\<^sub>4 = s2 \<and> s1 @ s\<^sub>3 \<in> lang (deriv c r1) \<and> s\<^sub>4 \<in> lang r2)"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   377
        by (force split: if_splits elim!: Posix_elims simp add: lang_deriv Deriv_def)   
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   378
  then show "(c # s) \<in> Times r1 r2 \<rightarrow> injval (Times r1 r2) c v" 
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   379
    proof (cases)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   380
      case left_nullable
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   381
      have "s1 \<in> deriv c r1 \<rightarrow> v1" by fact
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   382
      then have "(c # s1) \<in> r1 \<rightarrow> injval r1 c v1" using IH1 by simp
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   383
      moreover
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   384
      have "\<not> (\<exists>s\<^sub>3 s\<^sub>4. s\<^sub>3 \<noteq> [] \<and> s\<^sub>3 @ s\<^sub>4 = s2 \<and> s1 @ s\<^sub>3 \<in> lang (deriv c r1) \<and> s\<^sub>4 \<in> lang r2)" by fact
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   385
      then have "\<not> (\<exists>s\<^sub>3 s\<^sub>4. s\<^sub>3 \<noteq> [] \<and> s\<^sub>3 @ s\<^sub>4 = s2 \<and> (c # s1) @ s\<^sub>3 \<in> lang r1 \<and> s\<^sub>4 \<in> lang r2)" 
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   386
         by (simp add: lang_deriv Deriv_def)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   387
      ultimately have "((c # s1) @ s2) \<in> Times r1 r2 \<rightarrow> Seq (injval r1 c v1) v2" using left_nullable by (rule_tac Posix.intros)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   388
      then show "(c # s) \<in> Times r1 r2 \<rightarrow> injval (Times r1 r2) c v" using left_nullable by simp
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   389
    next
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   390
      case right_nullable
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   391
      have "nullable r1" by fact
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   392
      then have "[] \<in> r1 \<rightarrow> (mkeps r1)" by (rule Posix_mkeps)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   393
      moreover
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   394
      have "s \<in> deriv c r2 \<rightarrow> v1" by fact
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   395
      then have "(c # s) \<in> r2 \<rightarrow> (injval r2 c v1)" using IH2 by simp
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   396
      moreover
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   397
      have "s1 @ s2 \<notin> lang (Times (deriv c r1) r2)" by fact
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   398
      then have "\<not> (\<exists>s\<^sub>3 s\<^sub>4. s\<^sub>3 \<noteq> [] \<and> s\<^sub>3 @ s\<^sub>4 = c # s \<and> [] @ s\<^sub>3 \<in> lang r1 \<and> s\<^sub>4 \<in> lang r2)" 
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   399
        using right_nullable 
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   400
        apply (auto simp add: lang_deriv Deriv_def append_eq_Cons_conv)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   401
        by (metis concI mem_Collect_eq)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   402
      ultimately have "([] @ (c # s)) \<in> Times r1 r2 \<rightarrow> Seq (mkeps r1) (injval r2 c v1)"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   403
      by(rule Posix.intros)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   404
      then show "(c # s) \<in> Times r1 r2 \<rightarrow> injval (Times r1 r2) c v" using right_nullable by simp
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   405
    next
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   406
      case not_nullable
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   407
      have "s1 \<in> deriv c r1 \<rightarrow> v1" by fact
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   408
      then have "(c # s1) \<in> r1 \<rightarrow> injval r1 c v1" using IH1 by simp
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   409
      moreover
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   410
      have "\<not> (\<exists>s\<^sub>3 s\<^sub>4. s\<^sub>3 \<noteq> [] \<and> s\<^sub>3 @ s\<^sub>4 = s2 \<and> s1 @ s\<^sub>3 \<in> lang (deriv c r1) \<and> s\<^sub>4 \<in> lang r2)" by fact
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   411
      then have "\<not> (\<exists>s\<^sub>3 s\<^sub>4. s\<^sub>3 \<noteq> [] \<and> s\<^sub>3 @ s\<^sub>4 = s2 \<and> (c # s1) @ s\<^sub>3 \<in> lang r1 \<and> s\<^sub>4 \<in> lang r2)" by (simp add: lang_deriv Deriv_def)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   412
      ultimately have "((c # s1) @ s2) \<in> Times r1 r2 \<rightarrow> Seq (injval r1 c v1) v2" using not_nullable 
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   413
        by (rule_tac Posix.intros) (simp_all) 
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   414
      then show "(c # s) \<in> Times r1 r2 \<rightarrow> injval (Times r1 r2) c v" using not_nullable by simp
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   415
    qed
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   416
next
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   417
  case (Star r)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   418
  have IH: "\<And>s v. s \<in> deriv c r \<rightarrow> v \<Longrightarrow> (c # s) \<in> r \<rightarrow> injval r c v" by fact
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   419
  have "s \<in> deriv c (Star r) \<rightarrow> v" by fact
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   420
  then consider
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   421
      (cons) v1 vs s1 s2 where 
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   422
        "v = Seq v1 (Stars vs)" "s = s1 @ s2" 
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   423
        "s1 \<in> deriv c r \<rightarrow> v1" "s2 \<in> (Star r) \<rightarrow> (Stars vs)"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   424
        "\<not> (\<exists>s\<^sub>3 s\<^sub>4. s\<^sub>3 \<noteq> [] \<and> s\<^sub>3 @ s\<^sub>4 = s2 \<and> s1 @ s\<^sub>3 \<in> lang (deriv c r) \<and> s\<^sub>4 \<in> lang (Star r))" 
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   425
        apply(auto elim!: Posix_elims(1-5) simp add: lang_deriv Deriv_def intro: Posix.intros)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   426
        apply(rotate_tac 3)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   427
        apply(erule_tac Posix_elims(6))
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   428
        apply (simp add: Posix.intros(6))
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   429
        using Posix.intros(7) by blast
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   430
    then show "(c # s) \<in> Star r \<rightarrow> injval (Star r) c v" 
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   431
    proof (cases)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   432
      case cons
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   433
          have "s1 \<in> deriv c r \<rightarrow> v1" by fact
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   434
          then have "(c # s1) \<in> r \<rightarrow> injval r c v1" using IH by simp
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   435
        moreover
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   436
          have "s2 \<in> Star r \<rightarrow> Stars vs" by fact
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   437
        moreover 
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   438
          have "(c # s1) \<in> r \<rightarrow> injval r c v1" by fact 
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   439
          then have "flat (injval r c v1) = (c # s1)" by (rule Posix1)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   440
          then have "flat (injval r c v1) \<noteq> []" by simp
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   441
        moreover 
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   442
          have "\<not> (\<exists>s\<^sub>3 s\<^sub>4. s\<^sub>3 \<noteq> [] \<and> s\<^sub>3 @ s\<^sub>4 = s2 \<and> s1 @ s\<^sub>3 \<in> lang (deriv c r) \<and> s\<^sub>4 \<in> lang (Star r))" by fact
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   443
          then have "\<not> (\<exists>s\<^sub>3 s\<^sub>4. s\<^sub>3 \<noteq> [] \<and> s\<^sub>3 @ s\<^sub>4 = s2 \<and> (c # s1) @ s\<^sub>3 \<in> lang r \<and> s\<^sub>4 \<in> lang (Star r))" 
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   444
            by (simp add: lang_deriv Deriv_def)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   445
        ultimately 
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   446
        have "((c # s1) @ s2) \<in> Star r \<rightarrow> Stars (injval r c v1 # vs)" by (rule Posix.intros)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   447
        then show "(c # s) \<in> Star r \<rightarrow> injval (Star r) c v" using cons by(simp)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   448
    qed
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   449
qed
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   450
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   451
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   452
section {* The Lexer by Sulzmann and Lu  *}
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   453
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   454
fun 
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   455
  lexer :: "'a rexp \<Rightarrow> 'a list \<Rightarrow> ('a val) option"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   456
where
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   457
  "lexer r [] = (if nullable r then Some(mkeps r) else None)"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   458
| "lexer r (c#s) = (case (lexer (deriv c r) s) of  
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   459
                    None \<Rightarrow> None
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   460
                  | Some(v) \<Rightarrow> Some(injval r c v))"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   461
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   462
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   463
lemma lexer_correct_None:
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   464
  shows "s \<notin> lang r \<longleftrightarrow> lexer r s = None"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   465
using assms
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   466
apply(induct s arbitrary: r)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   467
apply(simp add: nullable_iff)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   468
apply(drule_tac x="deriv a r" in meta_spec)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   469
apply(auto simp add: lang_deriv Deriv_def)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   470
done
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   471
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   472
lemma lexer_correct_Some:
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   473
  shows "s \<in> lang r \<longleftrightarrow> (\<exists>v. lexer r s = Some(v) \<and> s \<in> r \<rightarrow> v)"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   474
using assms
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   475
apply(induct s arbitrary: r)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   476
apply(auto simp add: Posix_mkeps nullable_iff)[1]
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   477
apply(drule_tac x="deriv a r" in meta_spec)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   478
apply(simp add: lang_deriv Deriv_def)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   479
apply(rule iffI)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   480
apply(auto intro: Posix_injval simp add: Posix1(1))
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   481
done 
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   482
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   483
lemma lexer_correctness:
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   484
  shows "(lexer r s = Some v) \<longleftrightarrow> s \<in> r \<rightarrow> v"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   485
  and   "(lexer r s = None) \<longleftrightarrow> \<not>(\<exists>v. s \<in> r \<rightarrow> v)"
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   486
apply(auto)
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   487
using lexer_correct_None lexer_correct_Some apply fastforce
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   488
using Posix1(1) Posix_determ lexer_correct_Some apply blast
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   489
using Posix1(1) lexer_correct_None apply blast
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   490
using lexer_correct_None lexer_correct_Some by blast
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   491
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   492
6bb15b8e6301 added files that were submitted to afp
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   493
end