| author | Christian Urban <christian.urban@kcl.ac.uk> | 
| Thu, 16 Feb 2023 23:23:22 +0000 | |
| changeset 642 | 6c13f76c070b | 
| parent 495 | f9cdc295ccf7 | 
| permissions | -rw-r--r-- | 
| 495 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 1 | |
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 2 | theory PosixSpec | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 3 | imports RegLangs | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 4 | begin | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 5 | |
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 6 | section \<open>"Plain" Values\<close> | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 7 | |
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 8 | datatype val = | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 9 | Void | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 10 | | Char char | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 11 | | Seq val val | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 12 | | Right val | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 13 | | Left val | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 14 | | Stars "val list" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 15 | |
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 16 | |
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 17 | section \<open>The string behind a value\<close> | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 18 | |
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 19 | fun | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 20 | flat :: "val \<Rightarrow> string" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 21 | where | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 22 | "flat (Void) = []" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 23 | | "flat (Char c) = [c]" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 24 | | "flat (Left v) = flat v" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 25 | | "flat (Right v) = flat v" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 26 | | "flat (Seq v1 v2) = (flat v1) @ (flat v2)" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 27 | | "flat (Stars []) = []" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 28 | | "flat (Stars (v#vs)) = (flat v) @ (flat (Stars vs))" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 29 | |
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 30 | abbreviation | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 31 | "flats vs \<equiv> concat (map flat vs)" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 32 | |
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 33 | lemma flat_Stars [simp]: | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 34 | "flat (Stars vs) = flats vs" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 35 | by (induct vs) (auto) | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 36 | |
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 37 | |
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 38 | section \<open>Lexical Values\<close> | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 39 | |
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 40 | inductive | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 41 |   Prf :: "val \<Rightarrow> rexp \<Rightarrow> bool" ("\<Turnstile> _ : _" [100, 100] 100)
 | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 42 | where | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 43 | "\<lbrakk>\<Turnstile> v1 : r1; \<Turnstile> v2 : r2\<rbrakk> \<Longrightarrow> \<Turnstile> Seq v1 v2 : SEQ r1 r2" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 44 | | "\<Turnstile> v1 : r1 \<Longrightarrow> \<Turnstile> Left v1 : ALT r1 r2" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 45 | | "\<Turnstile> v2 : r2 \<Longrightarrow> \<Turnstile> Right v2 : ALT r1 r2" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 46 | | "\<Turnstile> Void : ONE" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 47 | | "\<Turnstile> Char c : CH c" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 48 | | "\<forall>v \<in> set vs. \<Turnstile> v : r \<and> flat v \<noteq> [] \<Longrightarrow> \<Turnstile> Stars vs : STAR r" | 
| 642 | 49 | | "\<lbrakk>\<forall>v \<in> set vs1. \<Turnstile> v : r \<and> flat v \<noteq> []; | 
| 50 | \<forall>v \<in> set vs2. \<Turnstile> v : r \<and> flat v = []; | |
| 51 | length (vs1 @ vs2) = n\<rbrakk> \<Longrightarrow> \<Turnstile> Stars (vs1 @ vs2) : NTIMES r n" | |
| 495 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 52 | |
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 53 | inductive_cases Prf_elims: | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 54 | "\<Turnstile> v : ZERO" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 55 | "\<Turnstile> v : SEQ r1 r2" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 56 | "\<Turnstile> v : ALT r1 r2" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 57 | "\<Turnstile> v : ONE" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 58 | "\<Turnstile> v : CH c" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 59 | "\<Turnstile> vs : STAR r" | 
| 642 | 60 | "\<Turnstile> vs : NTIMES r n" | 
| 495 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 61 | |
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 62 | lemma Prf_Stars_appendE: | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 63 | assumes "\<Turnstile> Stars (vs1 @ vs2) : STAR r" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 64 | shows "\<Turnstile> Stars vs1 : STAR r \<and> \<Turnstile> Stars vs2 : STAR r" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 65 | using assms | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 66 | by (auto intro: Prf.intros elim!: Prf_elims) | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 67 | |
| 642 | 68 | lemma Pow_cstring: | 
| 69 | fixes A::"string set" | |
| 70 | assumes "s \<in> A ^^ n" | |
| 71 | shows "\<exists>ss1 ss2. concat (ss1 @ ss2) = s \<and> length (ss1 @ ss2) = n \<and> | |
| 72 | (\<forall>s \<in> set ss1. s \<in> A \<and> s \<noteq> []) \<and> (\<forall>s \<in> set ss2. s \<in> A \<and> s = [])" | |
| 73 | using assms | |
| 74 | apply(induct n arbitrary: s) | |
| 75 | apply(auto)[1] | |
| 76 | apply(auto simp add: Sequ_def) | |
| 77 | apply(drule_tac x="s2" in meta_spec) | |
| 78 | apply(simp) | |
| 79 | apply(erule exE)+ | |
| 80 | apply(clarify) | |
| 81 | apply(case_tac "s1 = []") | |
| 82 | apply(simp) | |
| 83 | apply(rule_tac x="ss1" in exI) | |
| 84 | apply(rule_tac x="s1 # ss2" in exI) | |
| 85 | apply(simp) | |
| 86 | apply(rule_tac x="s1 # ss1" in exI) | |
| 87 | apply(rule_tac x="ss2" in exI) | |
| 88 | apply(simp) | |
| 89 | done | |
| 495 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 90 | |
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 91 | lemma flats_Prf_value: | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 92 | assumes "\<forall>s\<in>set ss. \<exists>v. s = flat v \<and> \<Turnstile> v : r" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 93 | shows "\<exists>vs. flats vs = concat ss \<and> (\<forall>v\<in>set vs. \<Turnstile> v : r \<and> flat v \<noteq> [])" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 94 | using assms | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 95 | apply(induct ss) | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 96 | apply(auto) | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 97 | apply(rule_tac x="[]" in exI) | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 98 | apply(simp) | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 99 | apply(case_tac "flat v = []") | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 100 | apply(rule_tac x="vs" in exI) | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 101 | apply(simp) | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 102 | apply(rule_tac x="v#vs" in exI) | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 103 | apply(simp) | 
| 642 | 104 | done | 
| 105 | ||
| 106 | lemma Aux: | |
| 107 | assumes "\<forall>s\<in>set ss. s = []" | |
| 108 | shows "concat ss = []" | |
| 109 | using assms | |
| 110 | by (induct ss) (auto) | |
| 495 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 111 | |
| 642 | 112 | lemma flats_cval: | 
| 113 | assumes "\<forall>s\<in>set ss. \<exists>v. s = flat v \<and> \<Turnstile> v : r" | |
| 114 | shows "\<exists>vs1 vs2. flats (vs1 @ vs2) = concat ss \<and> length (vs1 @ vs2) = length ss \<and> | |
| 115 | (\<forall>v\<in>set vs1. \<Turnstile> v : r \<and> flat v \<noteq> []) \<and> | |
| 116 | (\<forall>v\<in>set vs2. \<Turnstile> v : r \<and> flat v = [])" | |
| 117 | using assms | |
| 118 | apply(induct ss rule: rev_induct) | |
| 119 | apply(rule_tac x="[]" in exI)+ | |
| 120 | apply(simp) | |
| 121 | apply(simp) | |
| 122 | apply(clarify) | |
| 123 | apply(case_tac "flat v = []") | |
| 124 | apply(rule_tac x="vs1" in exI) | |
| 125 | apply(rule_tac x="v#vs2" in exI) | |
| 126 | apply(simp) | |
| 127 | apply(rule_tac x="vs1 @ [v]" in exI) | |
| 128 | apply(rule_tac x="vs2" in exI) | |
| 129 | apply(simp) | |
| 130 | by (simp add: Aux) | |
| 131 | ||
| 132 | lemma pow_Prf: | |
| 133 | assumes "\<forall>v\<in>set vs. \<Turnstile> v : r \<and> flat v \<in> A" | |
| 134 | shows "flats vs \<in> A ^^ (length vs)" | |
| 135 | using assms | |
| 136 | by (induct vs) (auto) | |
| 495 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 137 | |
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 138 | lemma L_flat_Prf1: | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 139 | assumes "\<Turnstile> v : r" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 140 | shows "flat v \<in> L r" | 
| 642 | 141 | using assms | 
| 142 | apply (induct v r rule: Prf.induct) | |
| 143 | apply(auto simp add: Sequ_def Star_concat lang_pow_add) | |
| 144 | by (metis pow_Prf) | |
| 145 | ||
| 495 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 146 | lemma L_flat_Prf2: | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 147 | assumes "s \<in> L r" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 148 | shows "\<exists>v. \<Turnstile> v : r \<and> flat v = s" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 149 | using assms | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 150 | proof(induct r arbitrary: s) | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 151 | case (STAR r s) | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 152 | have IH: "\<And>s. s \<in> L r \<Longrightarrow> \<exists>v. \<Turnstile> v : r \<and> flat v = s" by fact | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 153 | have "s \<in> L (STAR r)" by fact | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 154 | then obtain ss where "concat ss = s" "\<forall>s \<in> set ss. s \<in> L r \<and> s \<noteq> []" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 155 | using Star_split by auto | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 156 | then obtain vs where "flats vs = s" "\<forall>v\<in>set vs. \<Turnstile> v : r \<and> flat v \<noteq> []" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 157 | using IH flats_Prf_value by metis | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 158 | then show "\<exists>v. \<Turnstile> v : STAR r \<and> flat v = s" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 159 | using Prf.intros(6) flat_Stars by blast | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 160 | next | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 161 | case (SEQ r1 r2 s) | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 162 | then show "\<exists>v. \<Turnstile> v : SEQ r1 r2 \<and> flat v = s" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 163 | unfolding Sequ_def L.simps by (fastforce intro: Prf.intros) | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 164 | next | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 165 | case (ALT r1 r2 s) | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 166 | then show "\<exists>v. \<Turnstile> v : ALT r1 r2 \<and> flat v = s" | 
| 642 | 167 | unfolding L.simps by (fastforce intro: Prf.intros) | 
| 168 | next | |
| 169 | case (NTIMES r n) | |
| 170 | have IH: "\<And>s. s \<in> L r \<Longrightarrow> \<exists>v. \<Turnstile> v : r \<and> flat v = s" by fact | |
| 171 | have "s \<in> L (NTIMES r n)" by fact | |
| 172 | then obtain ss1 ss2 where "concat (ss1 @ ss2) = s" "length (ss1 @ ss2) = n" | |
| 173 | "\<forall>s \<in> set ss1. s \<in> L r \<and> s \<noteq> []" "\<forall>s \<in> set ss2. s \<in> L r \<and> s = []" | |
| 174 | using Pow_cstring by force | |
| 175 | then obtain vs1 vs2 where "flats (vs1 @ vs2) = s" "length (vs1 @ vs2) = n" | |
| 176 | "\<forall>v\<in>set vs1. \<Turnstile> v : r \<and> flat v \<noteq> []" "\<forall>v\<in>set vs2. \<Turnstile> v : r \<and> flat v = []" | |
| 177 | using IH flats_cval | |
| 178 | apply - | |
| 179 | apply(drule_tac x="ss1 @ ss2" in meta_spec) | |
| 180 | apply(drule_tac x="r" in meta_spec) | |
| 181 | apply(drule meta_mp) | |
| 182 | apply(simp) | |
| 183 | apply (metis Un_iff) | |
| 184 | apply(clarify) | |
| 185 | apply(drule_tac x="vs1" in meta_spec) | |
| 186 | apply(drule_tac x="vs2" in meta_spec) | |
| 187 | apply(simp) | |
| 188 | done | |
| 189 | then show "\<exists>v. \<Turnstile> v : NTIMES r n \<and> flat v = s" | |
| 190 | using Prf.intros(7) flat_Stars by blast | |
| 495 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 191 | qed (auto intro: Prf.intros) | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 192 | |
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 193 | |
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 194 | lemma L_flat_Prf: | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 195 |   shows "L(r) = {flat v | v. \<Turnstile> v : r}"
 | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 196 | using L_flat_Prf1 L_flat_Prf2 by blast | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 197 | |
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 198 | |
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 199 | |
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 200 | section \<open>Sets of Lexical Values\<close> | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 201 | |
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 202 | text \<open> | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 203 | Shows that lexical values are finite for a given regex and string. | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 204 | \<close> | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 205 | |
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 206 | definition | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 207 | LV :: "rexp \<Rightarrow> string \<Rightarrow> val set" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 208 | where  "LV r s \<equiv> {v. \<Turnstile> v : r \<and> flat v = s}"
 | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 209 | |
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 210 | lemma LV_simps: | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 211 |   shows "LV ZERO s = {}"
 | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 212 |   and   "LV ONE s = (if s = [] then {Void} else {})"
 | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 213 |   and   "LV (CH c) s = (if s = [c] then {Char c} else {})"
 | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 214 | and "LV (ALT r1 r2) s = Left ` LV r1 s \<union> Right ` LV r2 s" | 
| 642 | 215 |   and   "LV (NTIMES r 0) s = (if s = [] then {Stars []} else {})"
 | 
| 495 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 216 | unfolding LV_def | 
| 642 | 217 | apply (auto intro: Prf.intros elim: Prf.cases) | 
| 218 | by (metis Prf.intros(7) append.right_neutral empty_iff list.set(1) list.size(3)) | |
| 219 | ||
| 495 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 220 | |
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 221 | abbreviation | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 222 |   "Prefixes s \<equiv> {s'. prefix s' s}"
 | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 223 | |
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 224 | abbreviation | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 225 |   "Suffixes s \<equiv> {s'. suffix s' s}"
 | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 226 | |
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 227 | abbreviation | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 228 |   "SSuffixes s \<equiv> {s'. strict_suffix s' s}"
 | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 229 | |
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 230 | lemma Suffixes_cons [simp]: | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 231 |   shows "Suffixes (c # s) = Suffixes s \<union> {c # s}"
 | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 232 | by (auto simp add: suffix_def Cons_eq_append_conv) | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 233 | |
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 234 | |
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 235 | lemma finite_Suffixes: | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 236 | shows "finite (Suffixes s)" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 237 | by (induct s) (simp_all) | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 238 | |
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 239 | lemma finite_SSuffixes: | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 240 | shows "finite (SSuffixes s)" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 241 | proof - | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 242 | have "SSuffixes s \<subseteq> Suffixes s" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 243 | unfolding strict_suffix_def suffix_def by auto | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 244 | then show "finite (SSuffixes s)" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 245 | using finite_Suffixes finite_subset by blast | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 246 | qed | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 247 | |
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 248 | lemma finite_Prefixes: | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 249 | shows "finite (Prefixes s)" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 250 | proof - | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 251 | have "finite (Suffixes (rev s))" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 252 | by (rule finite_Suffixes) | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 253 | then have "finite (rev ` Suffixes (rev s))" by simp | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 254 | moreover | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 255 | have "rev ` (Suffixes (rev s)) = Prefixes s" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 256 | unfolding suffix_def prefix_def image_def | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 257 | by (auto)(metis rev_append rev_rev_ident)+ | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 258 | ultimately show "finite (Prefixes s)" by simp | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 259 | qed | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 260 | |
| 642 | 261 | definition | 
| 262 |   "Stars_Append Vs1 Vs2 \<equiv> {Stars (vs1 @ vs2) | vs1 vs2. Stars vs1 \<in> Vs1 \<and> Stars vs2 \<in> Vs2}"
 | |
| 263 | ||
| 264 | lemma finite_Stars_Append: | |
| 265 | assumes "finite Vs1" "finite Vs2" | |
| 266 | shows "finite (Stars_Append Vs1 Vs2)" | |
| 267 | using assms | |
| 268 | proof - | |
| 269 | define UVs1 where "UVs1 \<equiv> Stars -` Vs1" | |
| 270 | define UVs2 where "UVs2 \<equiv> Stars -` Vs2" | |
| 271 | from assms have "finite UVs1" "finite UVs2" | |
| 272 | unfolding UVs1_def UVs2_def | |
| 273 | by(simp_all add: finite_vimageI inj_on_def) | |
| 274 | then have "finite ((\<lambda>(vs1, vs2). Stars (vs1 @ vs2)) ` (UVs1 \<times> UVs2))" | |
| 275 | by simp | |
| 276 | moreover | |
| 277 | have "Stars_Append Vs1 Vs2 = (\<lambda>(vs1, vs2). Stars (vs1 @ vs2)) ` (UVs1 \<times> UVs2)" | |
| 278 | unfolding Stars_Append_def UVs1_def UVs2_def by auto | |
| 279 | ultimately show "finite (Stars_Append Vs1 Vs2)" | |
| 280 | by simp | |
| 281 | qed | |
| 282 | ||
| 283 | lemma LV_NTIMES_subset: | |
| 284 | "LV (NTIMES r n) s \<subseteq> Stars_Append (LV (STAR r) s) (\<Union>i\<le>n. LV (NTIMES r i) [])" | |
| 285 | apply(auto simp add: LV_def) | |
| 286 | apply(auto elim!: Prf_elims) | |
| 287 | apply(auto simp add: Stars_Append_def) | |
| 288 | apply(rule_tac x="vs1" in exI) | |
| 289 | apply(rule_tac x="vs2" in exI) | |
| 290 | apply(auto) | |
| 291 | using Prf.intros(6) apply(auto) | |
| 292 | apply(rule_tac x="length vs2" in bexI) | |
| 293 | thm Prf.intros | |
| 294 | apply(subst append.simps(1)[symmetric]) | |
| 295 | apply(rule Prf.intros) | |
| 296 | apply(auto)[1] | |
| 297 | apply(auto)[1] | |
| 298 | apply(simp) | |
| 299 | apply(simp) | |
| 300 | done | |
| 301 | ||
| 302 | lemma LV_NTIMES_Suc_empty: | |
| 303 | shows "LV (NTIMES r (Suc n)) [] = | |
| 304 | (\<lambda>(v, vs). Stars (v#vs)) ` (LV r [] \<times> (Stars -` (LV (NTIMES r n) [])))" | |
| 305 | unfolding LV_def | |
| 306 | apply(auto elim!: Prf_elims simp add: image_def) | |
| 307 | apply(case_tac vs1) | |
| 308 | apply(auto) | |
| 309 | apply(case_tac vs2) | |
| 310 | apply(auto) | |
| 311 | apply(subst append.simps(1)[symmetric]) | |
| 312 | apply(rule Prf.intros) | |
| 313 | apply(auto) | |
| 314 | apply(subst append.simps(1)[symmetric]) | |
| 315 | apply(rule Prf.intros) | |
| 316 | apply(auto) | |
| 317 | done | |
| 318 | ||
| 495 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 319 | lemma LV_STAR_finite: | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 320 | assumes "\<forall>s. finite (LV r s)" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 321 | shows "finite (LV (STAR r) s)" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 322 | proof(induct s rule: length_induct) | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 323 | fix s::"char list" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 324 | assume "\<forall>s'. length s' < length s \<longrightarrow> finite (LV (STAR r) s')" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 325 | then have IH: "\<forall>s' \<in> SSuffixes s. finite (LV (STAR r) s')" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 326 | by (force simp add: strict_suffix_def suffix_def) | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 327 | define f where "f \<equiv> \<lambda>(v, vs). Stars (v # vs)" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 328 | define S1 where "S1 \<equiv> \<Union>s' \<in> Prefixes s. LV r s'" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 329 | define S2 where "S2 \<equiv> \<Union>s2 \<in> SSuffixes s. Stars -` (LV (STAR r) s2)" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 330 | have "finite S1" using assms | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 331 | unfolding S1_def by (simp_all add: finite_Prefixes) | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 332 | moreover | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 333 | with IH have "finite S2" unfolding S2_def | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 334 | by (auto simp add: finite_SSuffixes inj_on_def finite_vimageI) | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 335 | ultimately | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 336 |   have "finite ({Stars []} \<union> f ` (S1 \<times> S2))" by simp
 | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 337 | moreover | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 338 |   have "LV (STAR r) s \<subseteq> {Stars []} \<union> f ` (S1 \<times> S2)" 
 | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 339 | unfolding S1_def S2_def f_def | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 340 | unfolding LV_def image_def prefix_def strict_suffix_def | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 341 | apply(auto) | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 342 | apply(case_tac x) | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 343 | apply(auto elim: Prf_elims) | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 344 | apply(erule Prf_elims) | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 345 | apply(auto) | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 346 | apply(case_tac vs) | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 347 | apply(auto intro: Prf.intros) | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 348 | apply(rule exI) | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 349 | apply(rule conjI) | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 350 | apply(rule_tac x="flat a" in exI) | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 351 | apply(rule conjI) | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 352 | apply(rule_tac x="flats list" in exI) | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 353 | apply(simp) | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 354 | apply(blast) | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 355 | apply(simp add: suffix_def) | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 356 | using Prf.intros(6) by blast | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 357 | ultimately | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 358 | show "finite (LV (STAR r) s)" by (simp add: finite_subset) | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 359 | qed | 
| 642 | 360 | |
| 361 | lemma finite_NTimes_empty: | |
| 362 | assumes "\<And>s. finite (LV r s)" | |
| 363 | shows "finite (LV (NTIMES r n) [])" | |
| 364 | using assms | |
| 365 | apply(induct n) | |
| 366 | apply(auto simp add: LV_simps) | |
| 367 | apply(subst LV_NTIMES_Suc_empty) | |
| 368 | apply(rule finite_imageI) | |
| 369 | apply(rule finite_cartesian_product) | |
| 370 | using assms apply simp | |
| 371 | apply(rule finite_vimageI) | |
| 372 | apply(simp) | |
| 373 | apply(simp add: inj_on_def) | |
| 374 | done | |
| 375 | ||
| 495 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 376 | |
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 377 | lemma LV_finite: | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 378 | shows "finite (LV r s)" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 379 | proof(induct r arbitrary: s) | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 380 | case (ZERO s) | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 381 | show "finite (LV ZERO s)" by (simp add: LV_simps) | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 382 | next | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 383 | case (ONE s) | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 384 | show "finite (LV ONE s)" by (simp add: LV_simps) | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 385 | next | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 386 | case (CH c s) | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 387 | show "finite (LV (CH c) s)" by (simp add: LV_simps) | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 388 | next | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 389 | case (ALT r1 r2 s) | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 390 | then show "finite (LV (ALT r1 r2) s)" by (simp add: LV_simps) | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 391 | next | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 392 | case (SEQ r1 r2 s) | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 393 | define f where "f \<equiv> \<lambda>(v1, v2). Seq v1 v2" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 394 | define S1 where "S1 \<equiv> \<Union>s' \<in> Prefixes s. LV r1 s'" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 395 | define S2 where "S2 \<equiv> \<Union>s' \<in> Suffixes s. LV r2 s'" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 396 | have IHs: "\<And>s. finite (LV r1 s)" "\<And>s. finite (LV r2 s)" by fact+ | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 397 | then have "finite S1" "finite S2" unfolding S1_def S2_def | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 398 | by (simp_all add: finite_Prefixes finite_Suffixes) | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 399 | moreover | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 400 | have "LV (SEQ r1 r2) s \<subseteq> f ` (S1 \<times> S2)" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 401 | unfolding f_def S1_def S2_def | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 402 | unfolding LV_def image_def prefix_def suffix_def | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 403 | apply (auto elim!: Prf_elims) | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 404 | by (metis (mono_tags, lifting) mem_Collect_eq) | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 405 | ultimately | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 406 | show "finite (LV (SEQ r1 r2) s)" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 407 | by (simp add: finite_subset) | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 408 | next | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 409 | case (STAR r s) | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 410 | then show "finite (LV (STAR r) s)" by (simp add: LV_STAR_finite) | 
| 642 | 411 | next | 
| 412 | case (NTIMES r n s) | |
| 413 | have "\<And>s. finite (LV r s)" by fact | |
| 414 | then have "finite (Stars_Append (LV (STAR r) s) (\<Union>i\<le>n. LV (NTIMES r i) []))" | |
| 415 | apply(rule_tac finite_Stars_Append) | |
| 416 | apply (simp add: LV_STAR_finite) | |
| 417 | using finite_NTimes_empty by blast | |
| 418 | then show "finite (LV (NTIMES r n) s)" | |
| 419 | by (metis LV_NTIMES_subset finite_subset) | |
| 495 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 420 | qed | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 421 | |
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 422 | |
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 423 | |
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 424 | section \<open>Our inductive POSIX Definition\<close> | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 425 | |
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 426 | inductive | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 427 |   Posix :: "string \<Rightarrow> rexp \<Rightarrow> val \<Rightarrow> bool" ("_ \<in> _ \<rightarrow> _" [100, 100, 100] 100)
 | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 428 | where | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 429 | Posix_ONE: "[] \<in> ONE \<rightarrow> Void" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 430 | | Posix_CH: "[c] \<in> (CH c) \<rightarrow> (Char c)" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 431 | | Posix_ALT1: "s \<in> r1 \<rightarrow> v \<Longrightarrow> s \<in> (ALT r1 r2) \<rightarrow> (Left v)" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 432 | | Posix_ALT2: "\<lbrakk>s \<in> r2 \<rightarrow> v; s \<notin> L(r1)\<rbrakk> \<Longrightarrow> s \<in> (ALT r1 r2) \<rightarrow> (Right v)" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 433 | | Posix_SEQ: "\<lbrakk>s1 \<in> r1 \<rightarrow> v1; s2 \<in> r2 \<rightarrow> v2; | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 434 | \<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> | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 435 | (s1 @ s2) \<in> (SEQ r1 r2) \<rightarrow> (Seq v1 v2)" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 436 | | Posix_STAR1: "\<lbrakk>s1 \<in> r \<rightarrow> v; s2 \<in> STAR r \<rightarrow> Stars vs; flat v \<noteq> []; | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 437 | \<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> | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 438 | \<Longrightarrow> (s1 @ s2) \<in> STAR r \<rightarrow> Stars (v # vs)" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 439 | | Posix_STAR2: "[] \<in> STAR r \<rightarrow> Stars []" | 
| 642 | 440 | | Posix_NTIMES1: "\<lbrakk>s1 \<in> r \<rightarrow> v; s2 \<in> NTIMES r (n - 1) \<rightarrow> Stars vs; flat v \<noteq> []; 0 < n; | 
| 441 | \<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 (NTIMES r (n - 1)))\<rbrakk> | |
| 442 | \<Longrightarrow> (s1 @ s2) \<in> NTIMES r n \<rightarrow> Stars (v # vs)" | |
| 443 | | Posix_NTIMES2: "\<lbrakk>\<forall>v \<in> set vs. [] \<in> r \<rightarrow> v; length vs = n\<rbrakk> | |
| 444 | \<Longrightarrow> [] \<in> NTIMES r n \<rightarrow> Stars vs" | |
| 495 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 445 | |
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 446 | inductive_cases Posix_elims: | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 447 | "s \<in> ZERO \<rightarrow> v" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 448 | "s \<in> ONE \<rightarrow> v" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 449 | "s \<in> CH c \<rightarrow> v" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 450 | "s \<in> ALT r1 r2 \<rightarrow> v" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 451 | "s \<in> SEQ r1 r2 \<rightarrow> v" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 452 | "s \<in> STAR r \<rightarrow> v" | 
| 642 | 453 | "s \<in> NTIMES r n \<rightarrow> v" | 
| 495 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 454 | |
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 455 | lemma Posix1: | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 456 | assumes "s \<in> r \<rightarrow> v" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 457 | shows "s \<in> L r" "flat v = s" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 458 | using assms | 
| 642 | 459 | apply(induct s r v rule: Posix.induct) | 
| 460 | apply(auto simp add: pow_empty_iff) | |
| 461 | apply (metis Suc_pred concI lang_pow.simps(2)) | |
| 462 | by (meson ex_in_conv set_empty) | |
| 463 | ||
| 464 | lemma Posix1a: | |
| 465 | assumes "s \<in> r \<rightarrow> v" | |
| 466 | shows "\<Turnstile> v : r" | |
| 467 | using assms | |
| 468 | apply(induct s r v rule: Posix.induct) | |
| 469 | apply(auto intro: Prf.intros) | |
| 470 | apply (metis Prf.intros(6) Prf_elims(6) set_ConsD val.inject(5)) | |
| 471 | prefer 2 | |
| 472 | apply (metis Posix1(2) Prf.intros(7) append_Nil empty_iff list.set(1)) | |
| 473 | apply(erule Prf_elims) | |
| 474 | apply(auto) | |
| 475 | apply(subst append.simps(2)[symmetric]) | |
| 476 | apply(rule Prf.intros) | |
| 477 | apply(auto) | |
| 478 | done | |
| 495 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 479 | |
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 480 | text \<open> | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 481 | For a give value and string, our Posix definition | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 482 | determines a unique value. | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 483 | \<close> | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 484 | |
| 642 | 485 | lemma List_eq_zipI: | 
| 486 | assumes "list_all2 (\<lambda>v1 v2. v1 = v2) vs1 vs2" | |
| 487 | and "length vs1 = length vs2" | |
| 488 | shows "vs1 = vs2" | |
| 489 | using assms | |
| 490 | apply(induct vs1 vs2 rule: list_all2_induct) | |
| 491 | apply(auto) | |
| 492 | done | |
| 493 | ||
| 495 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 494 | lemma Posix_determ: | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 495 | assumes "s \<in> r \<rightarrow> v1" "s \<in> r \<rightarrow> v2" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 496 | shows "v1 = v2" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 497 | using assms | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 498 | proof (induct s r v1 arbitrary: v2 rule: Posix.induct) | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 499 | case (Posix_ONE v2) | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 500 | have "[] \<in> ONE \<rightarrow> v2" by fact | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 501 | then show "Void = v2" by cases auto | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 502 | next | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 503 | case (Posix_CH c v2) | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 504 | have "[c] \<in> CH c \<rightarrow> v2" by fact | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 505 | then show "Char c = v2" by cases auto | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 506 | next | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 507 | case (Posix_ALT1 s r1 v r2 v2) | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 508 | have "s \<in> ALT r1 r2 \<rightarrow> v2" by fact | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 509 | moreover | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 510 | have "s \<in> r1 \<rightarrow> v" by fact | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 511 | then have "s \<in> L r1" by (simp add: Posix1) | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 512 | ultimately obtain v' where eq: "v2 = Left v'" "s \<in> r1 \<rightarrow> v'" by cases auto | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 513 | moreover | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 514 | have IH: "\<And>v2. s \<in> r1 \<rightarrow> v2 \<Longrightarrow> v = v2" by fact | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 515 | ultimately have "v = v'" by simp | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 516 | then show "Left v = v2" using eq by simp | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 517 | next | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 518 | case (Posix_ALT2 s r2 v r1 v2) | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 519 | have "s \<in> ALT r1 r2 \<rightarrow> v2" by fact | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 520 | moreover | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 521 | have "s \<notin> L r1" by fact | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 522 | ultimately obtain v' where eq: "v2 = Right v'" "s \<in> r2 \<rightarrow> v'" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 523 | by cases (auto simp add: Posix1) | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 524 | moreover | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 525 | have IH: "\<And>v2. s \<in> r2 \<rightarrow> v2 \<Longrightarrow> v = v2" by fact | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 526 | ultimately have "v = v'" by simp | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 527 | then show "Right v = v2" using eq by simp | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 528 | next | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 529 | case (Posix_SEQ s1 r1 v1 s2 r2 v2 v') | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 530 | have "(s1 @ s2) \<in> SEQ r1 r2 \<rightarrow> v'" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 531 | "s1 \<in> r1 \<rightarrow> v1" "s2 \<in> r2 \<rightarrow> v2" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 532 | "\<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+ | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 533 | then obtain v1' v2' where "v' = Seq v1' v2'" "s1 \<in> r1 \<rightarrow> v1'" "s2 \<in> r2 \<rightarrow> v2'" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 534 | apply(cases) apply (auto simp add: append_eq_append_conv2) | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 535 | using Posix1(1) by fastforce+ | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 536 | moreover | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 537 | have IHs: "\<And>v1'. s1 \<in> r1 \<rightarrow> v1' \<Longrightarrow> v1 = v1'" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 538 | "\<And>v2'. s2 \<in> r2 \<rightarrow> v2' \<Longrightarrow> v2 = v2'" by fact+ | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 539 | ultimately show "Seq v1 v2 = v'" by simp | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 540 | next | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 541 | case (Posix_STAR1 s1 r v s2 vs v2) | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 542 | have "(s1 @ s2) \<in> STAR r \<rightarrow> v2" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 543 | "s1 \<in> r \<rightarrow> v" "s2 \<in> STAR r \<rightarrow> Stars vs" "flat v \<noteq> []" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 544 | "\<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+ | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 545 | then obtain v' vs' where "v2 = Stars (v' # vs')" "s1 \<in> r \<rightarrow> v'" "s2 \<in> (STAR r) \<rightarrow> (Stars vs')" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 546 | apply(cases) apply (auto simp add: append_eq_append_conv2) | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 547 | using Posix1(1) apply fastforce | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 548 | apply (metis Posix1(1) Posix_STAR1.hyps(6) append_Nil append_Nil2) | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 549 | using Posix1(2) by blast | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 550 | moreover | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 551 | have IHs: "\<And>v2. s1 \<in> r \<rightarrow> v2 \<Longrightarrow> v = v2" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 552 | "\<And>v2. s2 \<in> STAR r \<rightarrow> v2 \<Longrightarrow> Stars vs = v2" by fact+ | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 553 | ultimately show "Stars (v # vs) = v2" by auto | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 554 | next | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 555 | case (Posix_STAR2 r v2) | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 556 | have "[] \<in> STAR r \<rightarrow> v2" by fact | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 557 | then show "Stars [] = v2" by cases (auto simp add: Posix1) | 
| 642 | 558 | next | 
| 559 | case (Posix_NTIMES2 vs r n v2) | |
| 560 | then show "Stars vs = v2" | |
| 561 | apply(erule_tac Posix_elims) | |
| 562 | apply(auto) | |
| 563 | apply (simp add: Posix1(2)) | |
| 564 | apply(rule List_eq_zipI) | |
| 565 | apply(auto simp add: list_all2_iff) | |
| 566 | by (meson in_set_zipE) | |
| 567 | next | |
| 568 | case (Posix_NTIMES1 s1 r v s2 n vs) | |
| 569 | have "(s1 @ s2) \<in> NTIMES r n \<rightarrow> v2" | |
| 570 | "s1 \<in> r \<rightarrow> v" "s2 \<in> NTIMES r (n - 1) \<rightarrow> Stars vs" "flat v \<noteq> []" | |
| 571 | "\<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 (NTIMES r (n - 1 )))" by fact+ | |
| 572 | then obtain v' vs' where "v2 = Stars (v' # vs')" "s1 \<in> r \<rightarrow> v'" "s2 \<in> (NTIMES r (n - 1)) \<rightarrow> (Stars vs')" | |
| 573 | apply(cases) apply (auto simp add: append_eq_append_conv2) | |
| 574 | using Posix1(1) apply fastforce | |
| 575 | apply (metis One_nat_def Posix1(1) Posix_NTIMES1.hyps(7) append.right_neutral append_self_conv2) | |
| 576 | using Posix1(2) by blast | |
| 577 | moreover | |
| 578 | have IHs: "\<And>v2. s1 \<in> r \<rightarrow> v2 \<Longrightarrow> v = v2" | |
| 579 | "\<And>v2. s2 \<in> NTIMES r (n - 1) \<rightarrow> v2 \<Longrightarrow> Stars vs = v2" by fact+ | |
| 580 | ultimately show "Stars (v # vs) = v2" by auto | |
| 495 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 581 | qed | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 582 | |
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 583 | |
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 584 | text \<open> | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 585 | Our POSIX values are lexical values. | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 586 | \<close> | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 587 | |
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 588 | lemma Posix_LV: | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 589 | assumes "s \<in> r \<rightarrow> v" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 590 | shows "v \<in> LV r s" | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 591 | using assms unfolding LV_def | 
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 592 | apply(induct rule: Posix.induct) | 
| 642 | 593 | apply(auto simp add: intro!: Prf.intros elim!: Prf_elims Posix1a) | 
| 594 | apply (smt (verit, best) One_nat_def Posix1a Posix_NTIMES1 L.simps(7)) | |
| 595 | using Posix1a Posix_NTIMES2 by blast | |
| 495 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 596 | |
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 597 | |
| 
f9cdc295ccf7
a fresh directory with cleaned up code
 Christian Urban <christian.urban@kcl.ac.uk> parents: diff
changeset | 598 | end |