thys/Spec.thy
author Christian Urban <christian.urban@kcl.ac.uk>
Sat, 24 Oct 2020 12:13:39 +0100
changeset 359 fedc16924b76
parent 311 8b8db9558ecf
child 361 8bb064045b4e
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
   
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     2
theory Spec
311
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
     3
  imports RegLangs
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
begin
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
359
fedc16924b76 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 311
diff changeset
     7
fedc16924b76 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 311
diff changeset
     8
311
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
     9
section {* "Plain" Values *}
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
datatype val = 
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
  Void
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
| Char char
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
| Seq val val
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
| Right val
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
| Left val
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
| Stars "val list"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
section {* The string behind a value *}
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
fun 
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
  flat :: "val \<Rightarrow> string"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
where
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
  "flat (Void) = []"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
| "flat (Char c) = [c]"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    27
| "flat (Left v) = flat v"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
| "flat (Right v) = flat v"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
| "flat (Seq v1 v2) = (flat v1) @ (flat v2)"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
| "flat (Stars []) = []"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
| "flat (Stars (v#vs)) = (flat v) @ (flat (Stars vs))" 
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
    33
abbreviation
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
    34
  "flats vs \<equiv> concat (map flat vs)"
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
    35
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
lemma flat_Stars [simp]:
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
    37
 "flat (Stars vs) = flats vs"
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
by (induct vs) (auto)
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
    41
section {* Lexical Values *}
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    43
inductive 
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
    44
  Prf :: "val \<Rightarrow> rexp \<Rightarrow> bool" ("\<Turnstile> _ : _" [100, 100] 100)
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
where
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
 "\<lbrakk>\<Turnstile> v1 : r1; \<Turnstile> v2 : r2\<rbrakk> \<Longrightarrow> \<Turnstile>  Seq v1 v2 : SEQ r1 r2"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
| "\<Turnstile> v1 : r1 \<Longrightarrow> \<Turnstile> Left v1 : ALT r1 r2"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
| "\<Turnstile> v2 : r2 \<Longrightarrow> \<Turnstile> Right v2 : ALT r1 r2"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
| "\<Turnstile> Void : ONE"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
| "\<Turnstile> Char c : CHAR c"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
| "\<forall>v \<in> set vs. \<Turnstile> v : r \<and> flat v \<noteq> [] \<Longrightarrow> \<Turnstile> Stars vs : STAR r"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
    53
inductive_cases Prf_elims:
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
    54
  "\<Turnstile> v : ZERO"
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
    55
  "\<Turnstile> v : SEQ r1 r2"
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
    56
  "\<Turnstile> v : ALT r1 r2"
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
    57
  "\<Turnstile> v : ONE"
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
    58
  "\<Turnstile> v : CHAR c"
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
    59
  "\<Turnstile> vs : STAR r"
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
    61
lemma Prf_Stars_appendE:
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
  assumes "\<Turnstile> Stars (vs1 @ vs2) : STAR r"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
  shows "\<Turnstile> Stars vs1 : STAR r \<and> \<Turnstile> Stars vs2 : STAR r" 
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
using assms
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
    65
by (auto intro: Prf.intros elim!: Prf_elims)
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
    66
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
    67
311
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    68
lemma flats_Prf_value:
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
    69
  assumes "\<forall>s\<in>set ss. \<exists>v. s = flat v \<and> \<Turnstile> v : r"
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
    70
  shows "\<exists>vs. flats vs = concat ss \<and> (\<forall>v\<in>set vs. \<Turnstile> v : r \<and> flat v \<noteq> [])"
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
    71
using assms
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
    72
apply(induct ss)
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
    73
apply(auto)
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
    74
apply(rule_tac x="[]" in exI)
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
    75
apply(simp)
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
    76
apply(case_tac "flat v = []")
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
    77
apply(rule_tac x="vs" in exI)
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
    78
apply(simp)
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
    79
apply(rule_tac x="v#vs" in exI)
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
    80
apply(simp)
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    81
done
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
    83
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
    84
lemma L_flat_Prf1:
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
    85
  assumes "\<Turnstile> v : r" 
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
    86
  shows "flat v \<in> L r"
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
    87
using assms
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
    88
by (induct) (auto simp add: Sequ_def Star_concat)
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    89
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
    90
lemma L_flat_Prf2:
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
    91
  assumes "s \<in> L r" 
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
    92
  shows "\<exists>v. \<Turnstile> v : r \<and> flat v = s"
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
    93
using assms
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
    94
proof(induct r arbitrary: s)
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
    95
  case (STAR r s)
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
    96
  have IH: "\<And>s. s \<in> L r \<Longrightarrow> \<exists>v. \<Turnstile> v : r \<and> flat v = s" by fact
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
    97
  have "s \<in> L (STAR r)" by fact
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
    98
  then obtain ss where "concat ss = s" "\<forall>s \<in> set ss. s \<in> L r \<and> s \<noteq> []"
311
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
    99
  using Star_split by auto  
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   100
  then obtain vs where "flats vs = s" "\<forall>v\<in>set vs. \<Turnstile> v : r \<and> flat v \<noteq> []"
311
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   101
  using IH flats_Prf_value by metis 
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   102
  then show "\<exists>v. \<Turnstile> v : STAR r \<and> flat v = s"
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   103
  using Prf.intros(6) flat_Stars by blast
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   104
next 
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   105
  case (SEQ r1 r2 s)
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   106
  then show "\<exists>v. \<Turnstile> v : SEQ r1 r2 \<and> flat v = s"
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   107
  unfolding Sequ_def L.simps by (fastforce intro: Prf.intros)
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   108
next
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   109
  case (ALT r1 r2 s)
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   110
  then show "\<exists>v. \<Turnstile> v : ALT r1 r2 \<and> flat v = s"
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   111
  unfolding L.simps by (fastforce intro: Prf.intros)
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   112
qed (auto intro: Prf.intros)
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   113
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   114
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   115
lemma L_flat_Prf:
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   116
  shows "L(r) = {flat v | v. \<Turnstile> v : r}"
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   117
using L_flat_Prf1 L_flat_Prf2 by blast
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   118
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   119
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   120
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   121
section {* Sets of Lexical Values *}
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   122
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   123
text {*
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   124
  Shows that lexical values are finite for a given regex and string.
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   125
*}
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   126
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   127
definition
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   128
  LV :: "rexp \<Rightarrow> string \<Rightarrow> val set"
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   129
where  "LV r s \<equiv> {v. \<Turnstile> v : r \<and> flat v = s}"
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   130
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   131
lemma LV_simps:
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   132
  shows "LV ZERO s = {}"
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   133
  and   "LV ONE s = (if s = [] then {Void} else {})"
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   134
  and   "LV (CHAR c) s = (if s = [c] then {Char c} else {})"
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   135
  and   "LV (ALT r1 r2) s = Left ` LV r1 s \<union> Right ` LV r2 s"
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   136
unfolding LV_def
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   137
by (auto intro: Prf.intros elim: Prf.cases)
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   138
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   139
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   140
abbreviation
274
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   141
  "Prefixes s \<equiv> {s'. prefix s' s}"
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   142
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   143
abbreviation
274
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   144
  "Suffixes s \<equiv> {s'. suffix s' s}"
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   145
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   146
abbreviation
274
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   147
  "SSuffixes s \<equiv> {s'. strict_suffix s' s}"
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   148
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   149
lemma Suffixes_cons [simp]:
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   150
  shows "Suffixes (c # s) = Suffixes s \<union> {c # s}"
274
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   151
by (auto simp add: suffix_def Cons_eq_append_conv)
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   152
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   153
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   154
lemma finite_Suffixes: 
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   155
  shows "finite (Suffixes s)"
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   156
by (induct s) (simp_all)
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   157
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   158
lemma finite_SSuffixes: 
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   159
  shows "finite (SSuffixes s)"
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   160
proof -
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   161
  have "SSuffixes s \<subseteq> Suffixes s"
274
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   162
   unfolding strict_suffix_def suffix_def by auto
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   163
  then show "finite (SSuffixes s)"
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   164
   using finite_Suffixes finite_subset by blast
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   165
qed
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   166
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   167
lemma finite_Prefixes: 
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   168
  shows "finite (Prefixes s)"
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   169
proof -
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   170
  have "finite (Suffixes (rev s))" 
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   171
    by (rule finite_Suffixes)
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   172
  then have "finite (rev ` Suffixes (rev s))" by simp
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   173
  moreover
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   174
  have "rev ` (Suffixes (rev s)) = Prefixes s"
274
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   175
  unfolding suffix_def prefix_def image_def
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   176
   by (auto)(metis rev_append rev_rev_ident)+
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   177
  ultimately show "finite (Prefixes s)" by simp
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   178
qed
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   179
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   180
lemma LV_STAR_finite:
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   181
  assumes "\<forall>s. finite (LV r s)"
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   182
  shows "finite (LV (STAR r) s)"
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   183
proof(induct s rule: length_induct)
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   184
  fix s::"char list"
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   185
  assume "\<forall>s'. length s' < length s \<longrightarrow> finite (LV (STAR r) s')"
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   186
  then have IH: "\<forall>s' \<in> SSuffixes s. finite (LV (STAR r) s')"
279
f754a10875c7 updated for Isabelle 2017
cu
parents: 274
diff changeset
   187
    by (force simp add: strict_suffix_def suffix_def) 
274
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   188
  define f where "f \<equiv> \<lambda>(v, vs). Stars (v # vs)"
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   189
  define S1 where "S1 \<equiv> \<Union>s' \<in> Prefixes s. LV r s'"
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   190
  define S2 where "S2 \<equiv> \<Union>s2 \<in> SSuffixes s. Stars -` (LV (STAR r) s2)"
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   191
  have "finite S1" using assms
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   192
    unfolding S1_def by (simp_all add: finite_Prefixes)
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   193
  moreover 
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   194
  with IH have "finite S2" unfolding S2_def
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   195
    by (auto simp add: finite_SSuffixes inj_on_def finite_vimageI)
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   196
  ultimately 
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   197
  have "finite ({Stars []} \<union> f ` (S1 \<times> S2))" by simp
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   198
  moreover 
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   199
  have "LV (STAR r) s \<subseteq> {Stars []} \<union> f ` (S1 \<times> S2)" 
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   200
  unfolding S1_def S2_def f_def
289
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 287
diff changeset
   201
  unfolding LV_def image_def prefix_def strict_suffix_def 
274
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   202
  apply(auto)
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   203
  apply(case_tac x)
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   204
  apply(auto elim: Prf_elims)
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   205
  apply(erule Prf_elims)
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   206
  apply(auto)
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   207
  apply(case_tac vs)
274
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   208
  apply(auto intro: Prf.intros)  
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   209
  apply(rule exI)
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   210
  apply(rule conjI)
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   211
  apply(rule_tac x="flat a" in exI)
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   212
  apply(rule conjI)
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   213
  apply(rule_tac x="flats list" in exI)
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   214
  apply(simp)
279
f754a10875c7 updated for Isabelle 2017
cu
parents: 274
diff changeset
   215
   apply(blast)
f754a10875c7 updated for Isabelle 2017
cu
parents: 274
diff changeset
   216
  apply(simp add: suffix_def)
274
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   217
  using Prf.intros(6) by blast  
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   218
  ultimately
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   219
  show "finite (LV (STAR r) s)" by (simp add: finite_subset)
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   220
qed  
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   221
    
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   222
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   223
lemma LV_finite:
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   224
  shows "finite (LV r s)"
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   225
proof(induct r arbitrary: s)
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   226
  case (ZERO s) 
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   227
  show "finite (LV ZERO s)" by (simp add: LV_simps)
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   228
next
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   229
  case (ONE s)
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   230
  show "finite (LV ONE s)" by (simp add: LV_simps)
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   231
next
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   232
  case (CHAR c s)
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   233
  show "finite (LV (CHAR c) s)" by (simp add: LV_simps)
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   234
next 
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   235
  case (ALT r1 r2 s)
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   236
  then show "finite (LV (ALT r1 r2) s)" by (simp add: LV_simps)
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   237
next 
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   238
  case (SEQ r1 r2 s)
274
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   239
  define f where "f \<equiv> \<lambda>(v1, v2). Seq v1 v2"
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   240
  define S1 where "S1 \<equiv> \<Union>s' \<in> Prefixes s. LV r1 s'"
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   241
  define S2 where "S2 \<equiv> \<Union>s' \<in> Suffixes s. LV r2 s'"
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   242
  have IHs: "\<And>s. finite (LV r1 s)" "\<And>s. finite (LV r2 s)" by fact+
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   243
  then have "finite S1" "finite S2" unfolding S1_def S2_def
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   244
    by (simp_all add: finite_Prefixes finite_Suffixes)
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   245
  moreover
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   246
  have "LV (SEQ r1 r2) s \<subseteq> f ` (S1 \<times> S2)"
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   247
    unfolding f_def S1_def S2_def 
274
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   248
    unfolding LV_def image_def prefix_def suffix_def
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   249
    apply (auto elim!: Prf_elims)
692b62426677 updated
Christian Urban <urbanc@in.tum.de>
parents: 272
diff changeset
   250
    by (metis (mono_tags, lifting) mem_Collect_eq)  
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   251
  ultimately 
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   252
  show "finite (LV (SEQ r1 r2) s)"
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   253
    by (simp add: finite_subset)
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   254
next
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   255
  case (STAR r s)
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   256
  then show "finite (LV (STAR r) s)" by (simp add: LV_STAR_finite)
267
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   257
qed
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   258
32b222d77fa0 updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
   259
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   260
311
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   261
section {* Our inductive POSIX Definition *}
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   262
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   263
inductive 
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   264
  Posix :: "string \<Rightarrow> rexp \<Rightarrow> val \<Rightarrow> bool" ("_ \<in> _ \<rightarrow> _" [100, 100, 100] 100)
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   265
where
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   266
  Posix_ONE: "[] \<in> ONE \<rightarrow> Void"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   267
| Posix_CHAR: "[c] \<in> (CHAR c) \<rightarrow> (Char c)"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   268
| Posix_ALT1: "s \<in> r1 \<rightarrow> v \<Longrightarrow> s \<in> (ALT r1 r2) \<rightarrow> (Left v)"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   269
| Posix_ALT2: "\<lbrakk>s \<in> r2 \<rightarrow> v; s \<notin> L(r1)\<rbrakk> \<Longrightarrow> s \<in> (ALT r1 r2) \<rightarrow> (Right v)"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   270
| Posix_SEQ: "\<lbrakk>s1 \<in> r1 \<rightarrow> v1; s2 \<in> r2 \<rightarrow> v2;
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   271
    \<not>(\<exists>s\<^sub>3 s\<^sub>4. s\<^sub>3 \<noteq> [] \<and> s\<^sub>3 @ s\<^sub>4 = s2 \<and> (s1 @ s\<^sub>3) \<in> L r1 \<and> s\<^sub>4 \<in> L r2)\<rbrakk> \<Longrightarrow> 
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   272
    (s1 @ s2) \<in> (SEQ r1 r2) \<rightarrow> (Seq v1 v2)"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   273
| Posix_STAR1: "\<lbrakk>s1 \<in> r \<rightarrow> v; s2 \<in> STAR r \<rightarrow> Stars vs; flat v \<noteq> [];
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   274
    \<not>(\<exists>s\<^sub>3 s\<^sub>4. s\<^sub>3 \<noteq> [] \<and> s\<^sub>3 @ s\<^sub>4 = s2 \<and> (s1 @ s\<^sub>3) \<in> L r \<and> s\<^sub>4 \<in> L (STAR r))\<rbrakk>
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   275
    \<Longrightarrow> (s1 @ s2) \<in> STAR r \<rightarrow> Stars (v # vs)"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   276
| Posix_STAR2: "[] \<in> STAR r \<rightarrow> Stars []"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   277
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   278
inductive_cases Posix_elims:
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   279
  "s \<in> ZERO \<rightarrow> v"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   280
  "s \<in> ONE \<rightarrow> v"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   281
  "s \<in> CHAR c \<rightarrow> v"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   282
  "s \<in> ALT r1 r2 \<rightarrow> v"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   283
  "s \<in> SEQ r1 r2 \<rightarrow> v"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   284
  "s \<in> STAR r \<rightarrow> v"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   285
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   286
lemma Posix1:
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   287
  assumes "s \<in> r \<rightarrow> v"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   288
  shows "s \<in> L r" "flat v = s"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   289
using assms
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   290
by (induct s r v rule: Posix.induct)
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   291
   (auto simp add: Sequ_def)
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   292
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   293
text {*
311
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   294
  For a give value and string, our Posix definition 
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   295
  determines a unique value.
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   296
*}
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   297
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   298
lemma Posix_determ:
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   299
  assumes "s \<in> r \<rightarrow> v1" "s \<in> r \<rightarrow> v2"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   300
  shows "v1 = v2"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   301
using assms
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   302
proof (induct s r v1 arbitrary: v2 rule: Posix.induct)
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   303
  case (Posix_ONE v2)
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   304
  have "[] \<in> ONE \<rightarrow> v2" by fact
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   305
  then show "Void = v2" by cases auto
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   306
next 
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   307
  case (Posix_CHAR c v2)
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   308
  have "[c] \<in> CHAR c \<rightarrow> v2" by fact
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   309
  then show "Char c = v2" by cases auto
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   310
next 
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   311
  case (Posix_ALT1 s r1 v r2 v2)
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   312
  have "s \<in> ALT r1 r2 \<rightarrow> v2" by fact
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   313
  moreover
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   314
  have "s \<in> r1 \<rightarrow> v" by fact
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   315
  then have "s \<in> L r1" by (simp add: Posix1)
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   316
  ultimately obtain v' where eq: "v2 = Left v'" "s \<in> r1 \<rightarrow> v'" by cases auto 
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   317
  moreover
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   318
  have IH: "\<And>v2. s \<in> r1 \<rightarrow> v2 \<Longrightarrow> v = v2" by fact
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   319
  ultimately have "v = v'" by simp
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   320
  then show "Left v = v2" using eq by simp
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   321
next 
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   322
  case (Posix_ALT2 s r2 v r1 v2)
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   323
  have "s \<in> ALT r1 r2 \<rightarrow> v2" by fact
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   324
  moreover
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   325
  have "s \<notin> L r1" by fact
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   326
  ultimately obtain v' where eq: "v2 = Right v'" "s \<in> r2 \<rightarrow> v'" 
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   327
    by cases (auto simp add: Posix1) 
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   328
  moreover
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   329
  have IH: "\<And>v2. s \<in> r2 \<rightarrow> v2 \<Longrightarrow> v = v2" by fact
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   330
  ultimately have "v = v'" by simp
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   331
  then show "Right v = v2" using eq by simp
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   332
next
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   333
  case (Posix_SEQ s1 r1 v1 s2 r2 v2 v')
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   334
  have "(s1 @ s2) \<in> SEQ r1 r2 \<rightarrow> v'" 
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   335
       "s1 \<in> r1 \<rightarrow> v1" "s2 \<in> r2 \<rightarrow> v2"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   336
       "\<not> (\<exists>s\<^sub>3 s\<^sub>4. s\<^sub>3 \<noteq> [] \<and> s\<^sub>3 @ s\<^sub>4 = s2 \<and> s1 @ s\<^sub>3 \<in> L r1 \<and> s\<^sub>4 \<in> L r2)" by fact+
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   337
  then obtain v1' v2' where "v' = Seq v1' v2'" "s1 \<in> r1 \<rightarrow> v1'" "s2 \<in> r2 \<rightarrow> v2'"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   338
  apply(cases) apply (auto simp add: append_eq_append_conv2)
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   339
  using Posix1(1) by fastforce+
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   340
  moreover
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   341
  have IHs: "\<And>v1'. s1 \<in> r1 \<rightarrow> v1' \<Longrightarrow> v1 = v1'"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   342
            "\<And>v2'. s2 \<in> r2 \<rightarrow> v2' \<Longrightarrow> v2 = v2'" by fact+
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   343
  ultimately show "Seq v1 v2 = v'" by simp
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   344
next
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   345
  case (Posix_STAR1 s1 r v s2 vs v2)
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   346
  have "(s1 @ s2) \<in> STAR r \<rightarrow> v2" 
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   347
       "s1 \<in> r \<rightarrow> v" "s2 \<in> STAR r \<rightarrow> Stars vs" "flat v \<noteq> []"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   348
       "\<not> (\<exists>s\<^sub>3 s\<^sub>4. s\<^sub>3 \<noteq> [] \<and> s\<^sub>3 @ s\<^sub>4 = s2 \<and> s1 @ s\<^sub>3 \<in> L r \<and> s\<^sub>4 \<in> L (STAR r))" by fact+
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   349
  then obtain v' vs' where "v2 = Stars (v' # vs')" "s1 \<in> r \<rightarrow> v'" "s2 \<in> (STAR r) \<rightarrow> (Stars vs')"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   350
  apply(cases) apply (auto simp add: append_eq_append_conv2)
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   351
  using Posix1(1) apply fastforce
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   352
  apply (metis Posix1(1) Posix_STAR1.hyps(6) append_Nil append_Nil2)
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   353
  using Posix1(2) by blast
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   354
  moreover
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   355
  have IHs: "\<And>v2. s1 \<in> r \<rightarrow> v2 \<Longrightarrow> v = v2"
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   356
            "\<And>v2. s2 \<in> STAR r \<rightarrow> v2 \<Longrightarrow> Stars vs = v2" by fact+
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   357
  ultimately show "Stars (v # vs) = v2" by auto
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   358
next
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   359
  case (Posix_STAR2 r v2)
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   360
  have "[] \<in> STAR r \<rightarrow> v2" by fact
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   361
  then show "Stars [] = v2" by cases (auto simp add: Posix1)
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   362
qed
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   363
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   364
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   365
text {*
289
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 287
diff changeset
   366
  Our POSIX values are lexical values.
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   367
*}
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   368
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   369
lemma Posix_LV:
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   370
  assumes "s \<in> r \<rightarrow> v"
268
6746f5e1f1f8 updated
Christian Urban <urbanc@in.tum.de>
parents: 267
diff changeset
   371
  shows "v \<in> LV r s"
289
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 287
diff changeset
   372
  using assms unfolding LV_def
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 287
diff changeset
   373
  apply(induct rule: Posix.induct)
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 287
diff changeset
   374
  apply(auto simp add: intro!: Prf.intros elim!: Prf_elims)
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 287
diff changeset
   375
  done
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   376
289
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 287
diff changeset
   377
lemma Posix_Prf:
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 287
diff changeset
   378
  assumes "s \<in> r \<rightarrow> v"
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 287
diff changeset
   379
  shows "\<Turnstile> v : r"
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 287
diff changeset
   380
  using assms Posix_LV LV_def
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 287
diff changeset
   381
  by simp
286
804fbb227568 added proof for bitcoded algorithm
Christian Urban <urbanc@in.tum.de>
parents: 279
diff changeset
   382
266
fff2e1b40dfc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   383
end