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