thys/Simplifying.thy
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Fri, 18 Mar 2016 01:26:14 +0000
changeset 154 2de3cf684ba0
parent 151 5a1196466a9c
child 179 85766e408c66
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
150
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     1
theory Simplifying
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     2
  imports "ReStar" 
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     3
begin
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     4
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     5
section {* Lexer including simplifications *}
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     6
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     7
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     8
fun F_RIGHT where
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     9
  "F_RIGHT f v = Right (f v)"
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    10
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    11
fun F_LEFT where
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    12
  "F_LEFT f v = Left (f v)"
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    13
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    14
fun F_ALT where
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    15
  "F_ALT f\<^sub>1 f\<^sub>2 (Right v) = Right (f\<^sub>2 v)"
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    16
| "F_ALT f\<^sub>1 f\<^sub>2 (Left v) = Left (f\<^sub>1 v)"  
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    17
| "F_ALT f1 f2 v = v"
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    18
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    19
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    20
fun F_SEQ1 where
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    21
  "F_SEQ1 f\<^sub>1 f\<^sub>2 v = Seq (f\<^sub>1 Void) (f\<^sub>2 v)"
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    22
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    23
fun F_SEQ2 where 
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    24
  "F_SEQ2 f\<^sub>1 f\<^sub>2 v = Seq (f\<^sub>1 v) (f\<^sub>2 Void)"
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    25
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    26
fun F_SEQ where 
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    27
  "F_SEQ f\<^sub>1 f\<^sub>2 (Seq v\<^sub>1 v\<^sub>2) = Seq (f\<^sub>1 v\<^sub>1) (f\<^sub>2 v\<^sub>2)"
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    28
| "F_SEQ f1 f2 v = v"
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    29
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    30
fun simp_ALT where
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    31
  "simp_ALT (ZERO, f\<^sub>1) (r\<^sub>2, f\<^sub>2) = (r\<^sub>2, F_RIGHT f\<^sub>2)"
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    32
| "simp_ALT (r\<^sub>1, f\<^sub>1) (ZERO, f\<^sub>2) = (r\<^sub>1, F_LEFT f\<^sub>1)"
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    33
| "simp_ALT (r\<^sub>1, f\<^sub>1) (r\<^sub>2, f\<^sub>2) = (ALT r\<^sub>1 r\<^sub>2, F_ALT f\<^sub>1 f\<^sub>2)"
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    34
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    35
fun simp_SEQ where
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    36
  "simp_SEQ (ONE, f\<^sub>1) (r\<^sub>2, f\<^sub>2) = (r\<^sub>2, F_SEQ1 f\<^sub>1 f\<^sub>2)"
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    37
| "simp_SEQ (r\<^sub>1, f\<^sub>1) (ONE, f\<^sub>2) = (r\<^sub>1, F_SEQ2 f\<^sub>1 f\<^sub>2)"
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    38
| "simp_SEQ (r\<^sub>1, f\<^sub>1) (r\<^sub>2, f\<^sub>2) = (SEQ r\<^sub>1 r\<^sub>2, F_SEQ f\<^sub>1 f\<^sub>2)"  
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    39
 
154
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
    40
lemma simp_SEQ_simps[simp]:
150
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    41
  "simp_SEQ p1 p2 = (if (fst p1 = ONE) then (fst p2, F_SEQ1 (snd p1) (snd p2))
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    42
                    else (if (fst p2 = ONE) then (fst p1, F_SEQ2 (snd p1) (snd p2))
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    43
                    else (SEQ (fst p1) (fst p2), F_SEQ (snd p1) (snd p2))))"
154
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
    44
by (induct p1 p2 rule: simp_SEQ.induct) (auto)
150
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    45
154
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
    46
lemma simp_ALT_simps[simp]:
150
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    47
  "simp_ALT p1 p2 = (if (fst p1 = ZERO) then (fst p2, F_RIGHT (snd p2))
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    48
                    else (if (fst p2 = ZERO) then (fst p1, F_LEFT (snd p1))
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    49
                    else (ALT (fst p1) (fst p2), F_ALT (snd p1) (snd p2))))"
154
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
    50
by (induct p1 p2 rule: simp_ALT.induct) (auto)
150
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    51
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    52
fun 
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    53
  simp :: "rexp \<Rightarrow> rexp * (val \<Rightarrow> val)"
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    54
where
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    55
  "simp (ALT r1 r2) = simp_ALT (simp r1) (simp r2)" 
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    56
| "simp (SEQ r1 r2) = simp_SEQ (simp r1) (simp r2)" 
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    57
| "simp r = (r, id)"
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    58
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    59
fun 
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    60
  slexer :: "rexp \<Rightarrow> string \<Rightarrow> val option"
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    61
where
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    62
  "slexer r [] = (if nullable r then Some(mkeps r) else None)"
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    63
| "slexer r (c#s) = (let (rs, fr) = simp (der c r) in
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    64
                         (case (slexer rs s) of  
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    65
                            None \<Rightarrow> None
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    66
                          | Some(v) \<Rightarrow> Some(injval r c (fr v))))"
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    67
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    68
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    69
lemma L_fst_simp:
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    70
  shows "L(r) = L(fst (simp r))"
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    71
using assms
154
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
    72
by (induct r) (auto)
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
    73
150
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    74
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    75
lemma 
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    76
  shows "\<turnstile> ((snd (simp r)) v) : r \<longleftrightarrow> \<turnstile> v : (fst (simp r))"
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    77
using assms
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    78
apply(induct r arbitrary: v rule: simp.induct)
154
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
    79
apply(auto intro: Prf.intros)
150
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    80
using Prf_elims(3) apply blast
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    81
apply(erule Prf_elims)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    82
apply(simp)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    83
apply(clarify)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    84
apply(blast)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    85
apply(simp)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    86
apply(erule Prf_elims)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    87
apply(simp)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    88
apply(simp)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    89
apply(clarify)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    90
apply(blast)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    91
apply(erule Prf_elims)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    92
apply(case_tac v)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    93
apply(simp_all)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    94
apply(rule Prf.intros)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    95
apply(clarify)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    96
apply(simp)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    97
apply(case_tac v)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    98
apply(simp_all)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    99
apply(rule Prf.intros)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   100
apply(clarify)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   101
apply(simp)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   102
apply(erule Prf_elims)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   103
apply(simp)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   104
apply(rule Prf.intros)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   105
apply(simp)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   106
apply(simp)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   107
apply(rule Prf.intros)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   108
apply(simp)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   109
apply(erule Prf_elims)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   110
apply(simp)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   111
apply(blast)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   112
apply(rule Prf.intros)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   113
apply(erule Prf_elims)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   114
apply(simp)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   115
apply(rule Prf.intros)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   116
apply(erule Prf_elims)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   117
apply(simp)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   118
apply(rule Prf.intros)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   119
apply(erule Prf_elims)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   120
apply(simp)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   121
apply(clarify)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   122
apply(blast)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   123
apply(rule Prf.intros)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   124
apply(blast)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   125
using Prf.intros(4) apply blast
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   126
apply(erule Prf_elims)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   127
apply(simp)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   128
apply(clarify)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   129
apply(blast)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   130
apply(rule Prf.intros)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   131
using Prf.intros(4) apply blast
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   132
apply blast
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   133
apply(erule Prf_elims)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   134
apply(case_tac v)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   135
apply(simp_all)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   136
apply(rule Prf.intros)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   137
apply(clarify)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   138
apply(simp)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   139
apply(clarify)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   140
apply(blast)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   141
apply(erule Prf_elims)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   142
apply(case_tac v)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   143
apply(simp_all)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   144
apply(rule Prf.intros)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   145
apply(clarify)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   146
apply(simp)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   147
apply(simp)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   148
done
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   149
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   150
lemma Posix_simp_nullable:
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   151
  assumes "nullable r" "[] \<in> (fst (simp r)) \<rightarrow> v"
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   152
  shows "((snd (simp r)) v) = mkeps r"
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   153
using assms 
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   154
apply(induct r arbitrary: v)
154
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   155
apply(auto)
150
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   156
apply(erule Posix_elims)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   157
apply(simp)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   158
apply(erule Posix_elims)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   159
apply(clarify)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   160
using Posix.intros(1) apply blast
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   161
using Posix.intros(1) apply blast
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   162
using Posix.intros(1) apply blast
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   163
apply(erule Posix_elims)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   164
apply(simp)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   165
apply(erule Posix_elims)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   166
apply (metis L_fst_simp nullable.simps(1) nullable_correctness)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   167
apply(erule Posix_elims)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   168
apply(clarify)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   169
apply(simp)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   170
apply(clarify)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   171
apply(simp)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   172
apply(simp only: L_fst_simp[symmetric])
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   173
apply (simp add: nullable_correctness)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   174
apply(erule Posix_elims)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   175
using L_fst_simp Posix1(1) nullable_correctness apply blast
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   176
apply (metis L.simps(1) L_fst_simp Prf_flat_L empty_iff mkeps_nullable)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   177
apply(erule Posix_elims)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   178
apply(clarify)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   179
apply(simp)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   180
apply(simp only: L_fst_simp[symmetric])
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   181
apply (simp add: nullable_correctness)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   182
apply(erule Posix_elims)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   183
apply(clarify)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   184
apply(simp)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   185
using L_fst_simp Posix1(1) nullable_correctness apply blast
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   186
apply(simp)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   187
apply(erule Posix_elims)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   188
apply(clarify)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   189
apply(simp)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   190
using Posix1(2) apply auto[1]
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   191
apply(simp)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   192
done
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   193
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   194
lemma Posix_simp:
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   195
  assumes "s \<in> (fst (simp r)) \<rightarrow> v" 
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   196
  shows "s \<in> r \<rightarrow> ((snd (simp r)) v)"
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   197
using assms
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   198
apply(induct r arbitrary: s v rule: rexp.induct) 
154
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   199
apply(auto split: if_splits)
150
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   200
prefer 3
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   201
apply(erule Posix_elims)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   202
apply(clarify)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   203
apply(simp)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   204
apply(rule Posix.intros)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   205
apply(blast)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   206
apply(blast)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   207
apply(auto)[1]
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   208
apply(simp add: L_fst_simp[symmetric])
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   209
apply(auto)[1]
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   210
prefer 3
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   211
apply(rule Posix.intros)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   212
apply(blast)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   213
apply (metis L.simps(1) L_fst_simp equals0D)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   214
prefer 3
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   215
apply(rule Posix.intros)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   216
apply(blast)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   217
prefer 3
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   218
apply(erule Posix_elims)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   219
apply(clarify)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   220
apply(simp)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   221
apply(rule Posix.intros)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   222
apply(blast)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   223
apply(simp)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   224
apply(rule Posix.intros)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   225
apply(blast)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   226
apply(simp add: L_fst_simp[symmetric])
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   227
apply(subst append.simps[symmetric])
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   228
apply(rule Posix.intros)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   229
prefer 2
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   230
apply(blast)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   231
prefer 2
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   232
apply(auto)[1]
151
5a1196466a9c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 150
diff changeset
   233
apply (metis L_fst_simp Posix_elims(2) lexer_correct_Some)
150
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   234
apply(subst Posix_simp_nullable)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   235
using Posix.intros(1) Posix1(1) nullable_correctness apply blast
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   236
apply(simp)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   237
apply(rule Posix.intros)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   238
apply(rule Posix_mkeps)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   239
using Posix.intros(1) Posix1(1) nullable_correctness apply blast
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   240
apply(subst append_Nil2[symmetric])
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   241
apply(rule Posix.intros)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   242
apply(blast)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   243
apply(subst Posix_simp_nullable)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   244
using Posix.intros(1) Posix1(1) nullable_correctness apply blast
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   245
apply(simp)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   246
apply(rule Posix.intros)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   247
apply(rule Posix_mkeps)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   248
using Posix.intros(1) Posix1(1) nullable_correctness apply blast
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   249
apply(auto)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   250
done
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   251
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   252
lemma slexer_correctness:
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   253
  shows "slexer r s = lexer r s"
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   254
apply(induct s arbitrary: r)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   255
apply(simp)
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   256
apply(auto split: option.split prod.split)
151
5a1196466a9c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 150
diff changeset
   257
apply (metis L_fst_simp fst_conv lexer_correct_None)
5a1196466a9c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 150
diff changeset
   258
using L_fst_simp lexer_correct_None apply fastforce
5a1196466a9c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 150
diff changeset
   259
by (metis Posix_determ Posix_simp fst_conv lexer_correct_None lexer_correct_Some option.distinct(1) option.inject snd_conv)
150
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   260
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   261
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   262
09f81fee11ce updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   263
end