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