14 | "at (Right v) (Suc 0#ps)= at v ps" |
13 | "at (Right v) (Suc 0#ps)= at v ps" |
15 | "at (Seq v1 v2) (0#ps)= at v1 ps" |
14 | "at (Seq v1 v2) (0#ps)= at v1 ps" |
16 | "at (Seq v1 v2) (Suc 0#ps)= at v2 ps" |
15 | "at (Seq v1 v2) (Suc 0#ps)= at v2 ps" |
17 | "at (Stars vs) (n#ps)= at (nth vs n) ps" |
16 | "at (Stars vs) (n#ps)= at (nth vs n) ps" |
18 |
17 |
|
18 |
|
19 |
19 fun Pos :: "val \<Rightarrow> (nat list) set" |
20 fun Pos :: "val \<Rightarrow> (nat list) set" |
20 where |
21 where |
21 "Pos (Void) = {[]}" |
22 "Pos (Void) = {[]}" |
22 | "Pos (Char c) = {[]}" |
23 | "Pos (Char c) = {[]}" |
23 | "Pos (Left v) = {[]} \<union> {0#ps | ps. ps \<in> Pos v}" |
24 | "Pos (Left v) = {[]} \<union> {0#ps | ps. ps \<in> Pos v}" |
24 | "Pos (Right v) = {[]} \<union> {1#ps | ps. ps \<in> Pos v}" |
25 | "Pos (Right v) = {[]} \<union> {1#ps | ps. ps \<in> Pos v}" |
25 | "Pos (Seq v1 v2) = {[]} \<union> {0#ps | ps. ps \<in> Pos v1} \<union> {1#ps | ps. ps \<in> Pos v2}" |
26 | "Pos (Seq v1 v2) = {[]} \<union> {0#ps | ps. ps \<in> Pos v1} \<union> {1#ps | ps. ps \<in> Pos v2}" |
26 | "Pos (Stars []) = {[]}" |
27 | "Pos (Stars []) = {[]}" |
27 | "Pos (Stars (v#vs)) = {[]} \<union> {0#ps | ps. ps \<in> Pos v} \<union> {Suc n#ps | n ps. n#ps \<in> Pos (Stars vs)}" |
28 | "Pos (Stars (v#vs)) = {[]} \<union> {0#ps | ps. ps \<in> Pos v} \<union> {Suc n#ps | n ps. n#ps \<in> Pos (Stars vs)}" |
28 |
29 |
|
30 |
29 lemma Pos_stars: |
31 lemma Pos_stars: |
30 "Pos (Stars vs) = {[]} \<union> (\<Union>n < length vs. {n#ps | ps. ps \<in> Pos (vs ! n)})" |
32 "Pos (Stars vs) = {[]} \<union> (\<Union>n < length vs. {n#ps | ps. ps \<in> Pos (vs ! n)})" |
31 apply(induct vs) |
33 apply(induct vs) |
32 apply(simp) |
34 apply(simp) |
33 apply(simp) |
|
34 apply(simp add: insert_ident) |
35 apply(simp add: insert_ident) |
35 apply(rule subset_antisym) |
36 apply(rule subset_antisym) |
36 apply(auto) |
|
37 apply(auto)[1] |
|
38 using less_Suc_eq_0_disj by auto |
37 using less_Suc_eq_0_disj by auto |
39 |
38 |
40 lemma Pos_empty: |
39 lemma Pos_empty: |
41 shows "[] \<in> Pos v" |
40 shows "[] \<in> Pos v" |
42 by (induct v rule: Pos.induct)(auto) |
41 by (induct v rule: Pos.induct)(auto) |
43 |
42 |
44 fun intlen :: "'a list \<Rightarrow> int" |
43 fun intlen :: "'a list \<Rightarrow> int" |
45 where |
44 where |
46 "intlen [] = 0" |
45 "intlen [] = 0" |
47 | "intlen (x#xs) = 1 + intlen xs" |
46 | "intlen (x # xs) = 1 + intlen xs" |
48 |
47 |
49 lemma intlen_bigger: |
48 lemma intlen_bigger: |
50 shows "0 \<le> intlen xs" |
49 shows "0 \<le> intlen xs" |
51 by (induct xs)(auto) |
50 by (induct xs)(auto) |
52 |
51 |
137 |
143 |
138 lemma lex_trichotomous: |
144 lemma lex_trichotomous: |
139 fixes p q :: "nat list" |
145 fixes p q :: "nat list" |
140 shows "p = q \<or> p \<sqsubset>lex q \<or> q \<sqsubset>lex p" |
146 shows "p = q \<or> p \<sqsubset>lex q \<or> q \<sqsubset>lex p" |
141 apply(induct p arbitrary: q) |
147 apply(induct p arbitrary: q) |
142 apply(auto) |
148 apply(auto elim: lex_list.cases) |
143 apply(case_tac q) |
149 apply(case_tac q) |
144 apply(auto) |
150 apply(auto) |
145 done |
151 done |
146 |
152 |
147 |
153 |
148 |
154 |
149 |
155 |
150 section {* Ordering of values according to Okui & Suzuki *} |
156 section {* POSIX Ordering of Values According to Okui & Suzuki *} |
151 |
157 |
152 |
158 |
153 definition PosOrd:: "val \<Rightarrow> nat list \<Rightarrow> val \<Rightarrow> bool" ("_ \<sqsubset>val _ _" [60, 60, 59] 60) |
159 definition PosOrd:: "val \<Rightarrow> nat list \<Rightarrow> val \<Rightarrow> bool" ("_ \<sqsubset>val _ _" [60, 60, 59] 60) |
154 where |
160 where |
155 "v1 \<sqsubset>val p v2 \<equiv> pflat_len v1 p > pflat_len v2 p \<and> |
161 "v1 \<sqsubset>val p v2 \<equiv> pflat_len v1 p > pflat_len v2 p \<and> |
156 (\<forall>q \<in> Pos v1 \<union> Pos v2. q \<sqsubset>lex p \<longrightarrow> pflat_len v1 q = pflat_len v2 q)" |
162 (\<forall>q \<in> Pos v1 \<union> Pos v2. q \<sqsubset>lex p \<longrightarrow> pflat_len v1 q = pflat_len v2 q)" |
157 |
163 |
|
164 |
|
165 |
|
166 definition pflat_len2 :: "val \<Rightarrow> nat list => (bool * nat)" |
|
167 where |
|
168 "pflat_len2 v p \<equiv> (if p \<in> Pos v then (True, length (flat (at v p))) else (False, 0))" |
|
169 |
|
170 instance prod :: (ord, ord) ord |
|
171 by (rule Orderings.class.Orderings.ord.of_class.intro) |
|
172 |
|
173 |
|
174 lemma "(0, 0) < (3::nat, 2::nat)" |
|
175 |
|
176 |
|
177 |
|
178 |
158 definition PosOrd2:: "val \<Rightarrow> nat list \<Rightarrow> val \<Rightarrow> bool" ("_ \<sqsubset>val2 _ _" [60, 60, 59] 60) |
179 definition PosOrd2:: "val \<Rightarrow> nat list \<Rightarrow> val \<Rightarrow> bool" ("_ \<sqsubset>val2 _ _" [60, 60, 59] 60) |
159 where |
180 where |
160 "v1 \<sqsubset>val2 p v2 \<equiv> p \<in> Pos v1 \<and> |
181 "v1 \<sqsubset>val2 p v2 \<equiv> (fst (pflat_len2 v1 p) > fst (pflat_len2 v2 p) \<or> |
161 pflat_len v1 p > pflat_len v2 p \<and> |
182 snd (pflat_len2 v1 p) > fst (pflat_len2 v2 p)) \<and> |
162 (\<forall>q \<in> Pos v1 \<union> Pos v2. q \<sqsubset>lex p \<longrightarrow> pflat_len v1 q = pflat_len v2 q)" |
183 (\<forall>q \<in> Pos v1 \<union> Pos v2. q \<sqsubset>lex p \<longrightarrow> pflat_len v1 q = pflat_len v2 q)" |
163 |
|
164 lemma XXX: |
|
165 "v1 \<sqsubset>val p v2 \<longleftrightarrow> v1 \<sqsubset>val2 p v2" |
|
166 apply(auto simp add: PosOrd_def PosOrd2_def) |
|
167 apply(auto simp add: pflat_len_def split: if_splits) |
|
168 by (smt intlen_bigger) |
|
169 |
|
170 |
|
171 (* some tests *) |
|
172 |
|
173 definition ValFlat_ord:: "val \<Rightarrow> nat list \<Rightarrow> val \<Rightarrow> bool" ("_ \<sqsubset>fval _ _") |
|
174 where |
|
175 "v1 \<sqsubset>fval p v2 \<equiv> p \<in> Pos v1 \<and> |
|
176 (p \<notin> Pos v2 \<or> flat (at v2 p) \<sqsubset>spre flat (at v1 p)) \<and> |
|
177 (\<forall>q \<in> Pos v1 \<union> Pos v2. q \<sqsubset>lex p \<longrightarrow> (pflat_len v1 q = pflat_len v2 q))" |
|
178 |
|
179 lemma |
|
180 assumes "v1 \<sqsubset>fval p v2" |
|
181 shows "v1 \<sqsubset>val p v2" |
|
182 using assms |
|
183 unfolding ValFlat_ord_def PosOrd_def |
|
184 apply(clarify) |
|
185 apply(simp add: pflat_len_def) |
|
186 apply(auto)[1] |
|
187 apply(smt intlen_bigger) |
|
188 apply(simp add: sprefix_list_def prefix_list_def) |
|
189 apply(auto)[1] |
|
190 apply(drule sym) |
|
191 apply(simp add: intlen_append) |
|
192 apply (metis intlen.simps(1) intlen_length length_greater_0_conv list.size(3)) |
|
193 apply(smt intlen_bigger) |
|
194 done |
|
195 |
|
196 lemma |
|
197 assumes "v1 \<sqsubset>val p v2" "flat (at v2 p) \<sqsubset>spre flat (at v1 p)" |
|
198 shows "v1 \<sqsubset>fval p v2" |
|
199 using assms |
|
200 unfolding ValFlat_ord_def PosOrd_def |
|
201 apply(clarify) |
|
202 oops |
|
203 |
184 |
204 |
185 |
205 definition PosOrd_ex:: "val \<Rightarrow> val \<Rightarrow> bool" ("_ :\<sqsubset>val _" [60, 59] 60) |
186 definition PosOrd_ex:: "val \<Rightarrow> val \<Rightarrow> bool" ("_ :\<sqsubset>val _" [60, 59] 60) |
206 where |
187 where |
207 "v1 :\<sqsubset>val v2 \<equiv> (\<exists>p. v1 \<sqsubset>val p v2)" |
188 "v1 :\<sqsubset>val v2 \<equiv> \<exists>p. v1 \<sqsubset>val p v2" |
208 |
189 |
209 definition PosOrd_ex1:: "val \<Rightarrow> val \<Rightarrow> bool" ("_ :\<sqsubseteq>val _" [60, 59] 60) |
190 definition PosOrd_ex_eq:: "val \<Rightarrow> val \<Rightarrow> bool" ("_ :\<sqsubseteq>val _" [60, 59] 60) |
210 where |
191 where |
211 "v1 :\<sqsubseteq>val v2 \<equiv> v1 :\<sqsubset>val v2 \<or> v1 = v2" |
192 "v1 :\<sqsubseteq>val v2 \<equiv> v1 :\<sqsubset>val v2 \<or> v1 = v2" |
|
193 |
212 |
194 |
213 lemma PosOrd_shorterE: |
195 lemma PosOrd_shorterE: |
214 assumes "v1 :\<sqsubset>val v2" |
196 assumes "v1 :\<sqsubset>val v2" |
215 shows "length (flat v2) \<le> length (flat v1)" |
197 shows "length (flat v2) \<le> length (flat v1)" |
216 using assms |
198 using assms |
217 apply(auto simp add: PosOrd_ex_def PosOrd_def) |
199 apply(auto simp add: pflat_len_simps PosOrd_ex_def PosOrd_def) |
218 apply(case_tac p) |
200 apply(case_tac p) |
219 apply(simp add: pflat_len_simps) |
201 apply(simp add: pflat_len_simps intlen_length) |
220 apply(simp add: intlen_length) |
|
221 apply(simp) |
202 apply(simp) |
222 apply(drule_tac x="[]" in bspec) |
203 apply(drule_tac x="[]" in bspec) |
223 apply(simp add: Pos_empty) |
204 apply(simp add: Pos_empty) |
224 apply(simp add: pflat_len_simps) |
205 apply(simp add: pflat_len_simps le_less intlen_length_eq) |
225 by (metis intlen_length le_less less_irrefl linear) |
206 done |
226 |
|
227 |
207 |
228 lemma PosOrd_shorterI: |
208 lemma PosOrd_shorterI: |
229 assumes "length (flat v') < length (flat v)" |
209 assumes "length (flat v2) < length (flat v1)" |
230 shows "v :\<sqsubset>val v'" |
210 shows "v1 :\<sqsubset>val v2" |
231 using assms |
211 using assms |
232 unfolding PosOrd_ex_def |
212 unfolding PosOrd_ex_def |
233 by (metis intlen_length lex_simps(2) pflat_len_simps(9) PosOrd_def) |
213 by (metis intlen_length lex_simps(2) pflat_len_simps(9) PosOrd_def) |
234 |
214 |
235 lemma PosOrd_spreI: |
215 lemma PosOrd_spreI: |
236 assumes "(flat v') \<sqsubset>spre (flat v)" |
216 assumes "flat v' \<sqsubset>spre flat v" |
237 shows "v :\<sqsubset>val v'" |
217 shows "v :\<sqsubset>val v'" |
238 using assms |
218 using assms |
239 apply(rule_tac PosOrd_shorterI) |
219 apply(rule_tac PosOrd_shorterI) |
240 by (metis append_eq_conv_conj le_less_linear prefix_list_def sprefix_list_def take_all) |
220 by (metis append_eq_conv_conj le_less_linear prefix_list_def sprefix_list_def take_all) |
|
221 |
241 |
222 |
242 lemma PosOrd_Left_Right: |
223 lemma PosOrd_Left_Right: |
243 assumes "flat v1 = flat v2" |
224 assumes "flat v1 = flat v2" |
244 shows "Left v1 :\<sqsubset>val Right v2" |
225 shows "Left v1 :\<sqsubset>val Right v2" |
245 unfolding PosOrd_ex_def |
226 unfolding PosOrd_ex_def |
246 apply(rule_tac x="[0]" in exI) |
227 apply(rule_tac x="[0]" in exI) |
247 using assms |
228 using assms |
248 apply(auto simp add: PosOrd_def pflat_len_simps) |
229 apply(auto simp add: PosOrd_def pflat_len_simps) |
249 apply(smt intlen_bigger) |
230 apply(smt intlen_bigger) |
250 done |
231 done |
251 |
232 |
252 lemma PosOrd_LeftI: |
233 lemma PosOrd_Left_eq: |
253 assumes "v :\<sqsubset>val v'" "flat v = flat v'" |
234 assumes "flat v = flat v'" |
254 shows "(Left v) :\<sqsubset>val (Left v')" |
235 shows "Left v :\<sqsubset>val Left v' \<longleftrightarrow> v :\<sqsubset>val v'" |
255 using assms(1) |
236 using assms |
256 unfolding PosOrd_ex_def |
237 unfolding PosOrd_ex_def |
257 apply(auto) |
238 apply(auto) |
|
239 apply(case_tac p) |
|
240 apply(simp add: PosOrd_def pflat_len_simps) |
|
241 apply(case_tac a) |
|
242 apply(simp add: PosOrd_def pflat_len_simps) |
|
243 apply(rule_tac x="list" in exI) |
|
244 apply(auto simp add: PosOrd_def pflat_len_simps)[1] |
|
245 apply (smt Un_def lex_list.intros(2) mem_Collect_eq pflat_len_simps(3)) |
|
246 apply (smt Collect_disj_eq lex_list.intros(2) mem_Collect_eq pflat_len_simps(3)) |
|
247 apply(auto simp add: PosOrd_def pflat_len_outside)[1] |
258 apply(rule_tac x="0#p" in exI) |
248 apply(rule_tac x="0#p" in exI) |
259 using assms(2) |
|
260 apply(auto simp add: PosOrd_def pflat_len_simps) |
249 apply(auto simp add: PosOrd_def pflat_len_simps) |
261 done |
250 done |
|
251 |
262 |
252 |
263 lemma PosOrd_RightI: |
253 lemma PosOrd_RightI: |
264 assumes "v :\<sqsubset>val v'" "flat v = flat v'" |
254 assumes "v :\<sqsubset>val v'" "flat v = flat v'" |
265 shows "(Right v) :\<sqsubset>val (Right v')" |
255 shows "(Right v) :\<sqsubset>val (Right v')" |
266 using assms(1) |
256 using assms(1) |
267 unfolding PosOrd_ex_def |
257 unfolding PosOrd_ex_def |
268 apply(auto) |
258 apply(auto) |
269 apply(rule_tac x="Suc 0#p" in exI) |
259 apply(rule_tac x="Suc 0#p" in exI) |
270 using assms(2) |
260 using assms(2) |
271 apply(auto simp add: PosOrd_def pflat_len_simps) |
261 apply(auto simp add: PosOrd_def pflat_len_simps) |
272 done |
|
273 |
|
274 lemma PosOrd_LeftE: |
|
275 assumes "(Left v1) :\<sqsubset>val (Left v2)" |
|
276 shows "v1 :\<sqsubset>val v2" |
|
277 using assms |
|
278 apply(simp add: PosOrd_ex_def) |
|
279 apply(erule exE) |
|
280 apply(case_tac p) |
|
281 apply(simp add: PosOrd_def) |
|
282 apply(auto simp add: pflat_len_simps) |
|
283 apply(rule_tac x="[]" in exI) |
|
284 apply(simp add: Pos_empty pflat_len_simps) |
|
285 apply(auto simp add: pflat_len_simps PosOrd_def) |
|
286 apply(case_tac a) |
|
287 apply(auto simp add: pflat_len_simps)[1] |
|
288 apply(rule_tac x="list" in exI) |
|
289 apply(auto) |
|
290 apply(drule_tac x="0#q" in bspec) |
|
291 apply(simp) |
|
292 apply(simp add: pflat_len_simps) |
|
293 apply(drule_tac x="0#q" in bspec) |
|
294 apply(simp) |
|
295 apply(simp add: pflat_len_simps) |
|
296 apply(simp add: pflat_len_def) |
|
297 done |
262 done |
298 |
263 |
299 lemma PosOrd_RightE: |
264 lemma PosOrd_RightE: |
300 assumes "(Right v1) :\<sqsubset>val (Right v2)" |
265 assumes "(Right v1) :\<sqsubset>val (Right v2)" |
301 shows "v1 :\<sqsubset>val v2" |
266 shows "v1 :\<sqsubset>val v2" |
590 "\<lbrakk>\<Turnstile> v1 : r1; \<Turnstile> v2 : r2\<rbrakk> \<Longrightarrow> \<Turnstile> Seq v1 v2 : SEQ r1 r2" |
576 "\<lbrakk>\<Turnstile> v1 : r1; \<Turnstile> v2 : r2\<rbrakk> \<Longrightarrow> \<Turnstile> Seq v1 v2 : SEQ r1 r2" |
591 | "\<Turnstile> v1 : r1 \<Longrightarrow> \<Turnstile> Left v1 : ALT r1 r2" |
577 | "\<Turnstile> v1 : r1 \<Longrightarrow> \<Turnstile> Left v1 : ALT r1 r2" |
592 | "\<Turnstile> v2 : r2 \<Longrightarrow> \<Turnstile> Right v2 : ALT r1 r2" |
578 | "\<Turnstile> v2 : r2 \<Longrightarrow> \<Turnstile> Right v2 : ALT r1 r2" |
593 | "\<Turnstile> Void : ONE" |
579 | "\<Turnstile> Void : ONE" |
594 | "\<Turnstile> Char c : CHAR c" |
580 | "\<Turnstile> Char c : CHAR c" |
595 | "\<Turnstile> Stars [] : STAR r" |
581 | "\<forall>v \<in> set vs. \<Turnstile> v : r \<and> flat v \<noteq> [] \<Longrightarrow> \<Turnstile> Stars vs : STAR r" |
596 | "\<lbrakk>\<Turnstile> v : r; flat v \<noteq> []; \<Turnstile> Stars vs : STAR r\<rbrakk> \<Longrightarrow> \<Turnstile> Stars (v # vs) : STAR r" |
|
597 |
582 |
598 lemma Prf_CPrf: |
583 lemma Prf_CPrf: |
599 assumes "\<Turnstile> v : r" |
584 assumes "\<Turnstile> v : r" |
600 shows "\<turnstile> v : r" |
585 shows "\<turnstile> v : r" |
601 using assms |
586 using assms |
602 by (induct) (auto intro: Prf.intros) |
587 by (induct)(auto intro: Prf.intros) |
603 |
|
604 lemma pflat_len_equal_iff: |
|
605 assumes "\<Turnstile> v1 : r" "\<Turnstile> v2 : r" |
|
606 and "\<forall>p. pflat_len v1 p = pflat_len v2 p" |
|
607 shows "v1 = v2" |
|
608 using assms |
|
609 apply(induct v1 r arbitrary: v2 rule: CPrf.induct) |
|
610 apply(rotate_tac 4) |
|
611 apply(erule CPrf.cases) |
|
612 apply(simp_all)[7] |
|
613 apply (metis pflat_len_simps(1) pflat_len_simps(2)) |
|
614 apply(rotate_tac 2) |
|
615 apply(erule CPrf.cases) |
|
616 apply(simp_all)[7] |
|
617 apply (metis pflat_len_simps(3)) |
|
618 apply (metis intlen.simps(1) intlen_length length_greater_0_conv list.size(3) neg_0_le_iff_le not_less not_less_iff_gr_or_eq not_one_le_zero pflat_len_simps(3) pflat_len_simps(6) pflat_len_simps(9)) |
|
619 apply(rotate_tac 2) |
|
620 apply(erule CPrf.cases) |
|
621 apply(simp_all)[7] |
|
622 apply (metis intlen.simps(1) intlen_length length_greater_0_conv list.size(3) neg_0_le_iff_le not_less not_less_iff_gr_or_eq not_one_le_zero pflat_len_simps(3) pflat_len_simps(6) pflat_len_simps(9)) |
|
623 apply (metis pflat_len_simps(5)) |
|
624 apply(erule CPrf.cases) |
|
625 apply(simp_all)[7] |
|
626 apply(erule CPrf.cases) |
|
627 apply(simp_all)[7] |
|
628 apply(erule CPrf.cases) |
|
629 apply(simp_all)[7] |
|
630 apply (metis append_Cons flat.simps(6) flat.simps(7) intlen_length length_greater_0_conv neq_Nil_conv not_less_iff_gr_or_eq pflat_len_simps(9)) |
|
631 apply(rotate_tac 5) |
|
632 apply(erule CPrf.cases) |
|
633 apply(simp_all)[7] |
|
634 apply (metis append_Cons flat.simps(6) flat.simps(7) intlen_length length_greater_0_conv list.distinct(1) list.exhaust not_less_iff_gr_or_eq pflat_len_simps(9)) |
|
635 apply(auto) |
|
636 apply (metis pflat_len_simps(8)) |
|
637 apply(subgoal_tac "v = va") |
|
638 prefer 2 |
|
639 apply (metis pflat_len_simps(8)) |
|
640 apply(simp) |
|
641 apply(rotate_tac 3) |
|
642 apply(drule_tac x="Stars vsa" in meta_spec) |
|
643 apply(simp) |
|
644 apply(drule_tac meta_mp) |
|
645 apply(rule allI) |
|
646 apply(case_tac p) |
|
647 apply(simp add: pflat_len_simps) |
|
648 apply(drule_tac x="[]" in spec) |
|
649 apply(simp add: pflat_len_simps intlen_append) |
|
650 apply(drule_tac x="Suc a#list" in spec) |
|
651 apply(simp add: pflat_len_simps intlen_append) |
|
652 apply(simp) |
|
653 done |
|
654 |
|
655 lemma PosOrd_trichotomous_stronger: |
|
656 assumes "\<Turnstile> v1 : r" "\<Turnstile> v2 : r" |
|
657 shows "v1 :\<sqsubset>val v2 \<or> v2 :\<sqsubset>val v1 \<or> (v1 = v2)" |
|
658 oops |
|
659 |
588 |
660 lemma CPrf_stars: |
589 lemma CPrf_stars: |
661 assumes "\<Turnstile> Stars vs : STAR r" |
590 assumes "\<Turnstile> Stars vs : STAR r" |
662 shows "\<forall>v \<in> set vs. flat v \<noteq> [] \<and> \<Turnstile> v : r" |
591 shows "\<forall>v \<in> set vs. flat v \<noteq> [] \<and> \<Turnstile> v : r" |
663 using assms |
592 using assms |
664 apply(induct vs) |
593 apply(erule_tac CPrf.cases) |
665 apply(auto) |
|
666 apply(erule CPrf.cases) |
|
667 apply(simp_all) |
|
668 apply(erule CPrf.cases) |
|
669 apply(simp_all) |
|
670 apply(erule CPrf.cases) |
|
671 apply(simp_all) |
|
672 apply(erule CPrf.cases) |
|
673 apply(simp_all) |
594 apply(simp_all) |
674 done |
595 done |
675 |
596 |
676 lemma CPrf_Stars_appendE: |
597 lemma CPrf_Stars_appendE: |
677 assumes "\<Turnstile> Stars (vs1 @ vs2) : STAR r" |
598 assumes "\<Turnstile> Stars (vs1 @ vs2) : STAR r" |
678 shows "\<Turnstile> Stars vs1 : STAR r \<and> \<Turnstile> Stars vs2 : STAR r" |
599 shows "\<Turnstile> Stars vs1 : STAR r \<and> \<Turnstile> Stars vs2 : STAR r" |
679 using assms |
600 using assms |
680 apply(induct vs1 arbitrary: vs2) |
601 apply(erule_tac CPrf.cases) |
681 apply(auto intro: CPrf.intros)[1] |
602 apply(auto intro: CPrf.intros elim: Prf.cases) |
682 apply(erule CPrf.cases) |
|
683 apply(simp_all) |
|
684 apply(auto intro: CPrf.intros) |
|
685 done |
603 done |
686 |
604 |
687 definition PT :: "rexp \<Rightarrow> string \<Rightarrow> val set" |
605 definition PT :: "rexp \<Rightarrow> string \<Rightarrow> val set" |
688 where "PT r s \<equiv> {v. flat v = s \<and> \<turnstile> v : r}" |
606 where "PT r s \<equiv> {v. flat v = s \<and> \<turnstile> v : r}" |
689 |
607 |
694 "CPTpre r s = {v. \<exists>s'. flat v @ s' = s \<and> \<Turnstile> v : r}" |
612 "CPTpre r s = {v. \<exists>s'. flat v @ s' = s \<and> \<Turnstile> v : r}" |
695 |
613 |
696 lemma CPT_CPTpre_subset: |
614 lemma CPT_CPTpre_subset: |
697 shows "CPT r s \<subseteq> CPTpre r s" |
615 shows "CPT r s \<subseteq> CPTpre r s" |
698 by(auto simp add: CPT_def CPTpre_def) |
616 by(auto simp add: CPT_def CPTpre_def) |
|
617 |
|
618 lemma CPT_simps: |
|
619 shows "CPT ZERO s = {}" |
|
620 and "CPT ONE s = (if s = [] then {Void} else {})" |
|
621 and "CPT (CHAR c) s = (if s = [c] then {Char c} else {})" |
|
622 and "CPT (ALT r1 r2) s = Left ` CPT r1 s \<union> Right ` CPT r2 s" |
|
623 and "CPT (SEQ r1 r2) s = |
|
624 {Seq v1 v2 | v1 v2. flat v1 @ flat v2 = s \<and> v1 \<in> CPT r1 (flat v1) \<and> v2 \<in> CPT r2 (flat v2)}" |
|
625 and "CPT (STAR r) s = |
|
626 Stars ` {vs. concat (map flat vs) = s \<and> (\<forall>v \<in> set vs. v \<in> CPT r (flat v) \<and> flat v \<noteq> [])}" |
|
627 apply - |
|
628 apply(auto simp add: CPT_def intro: CPrf.intros)[1] |
|
629 apply(erule CPrf.cases) |
|
630 apply(simp_all)[6] |
|
631 apply(auto simp add: CPT_def intro: CPrf.intros)[1] |
|
632 apply(erule CPrf.cases) |
|
633 apply(simp_all)[6] |
|
634 apply(erule CPrf.cases) |
|
635 apply(simp_all)[6] |
|
636 apply(auto simp add: CPT_def intro: CPrf.intros)[1] |
|
637 apply(erule CPrf.cases) |
|
638 apply(simp_all)[6] |
|
639 apply(erule CPrf.cases) |
|
640 apply(simp_all)[6] |
|
641 apply(auto simp add: CPT_def intro: CPrf.intros)[1] |
|
642 apply(erule CPrf.cases) |
|
643 apply(simp_all)[6] |
|
644 apply(auto simp add: CPT_def intro: CPrf.intros)[1] |
|
645 apply(erule CPrf.cases) |
|
646 apply(simp_all)[6] |
|
647 (* STAR case *) |
|
648 apply(auto simp add: CPT_def intro: CPrf.intros)[1] |
|
649 apply(erule CPrf.cases) |
|
650 apply(simp_all)[6] |
|
651 done |
|
652 |
|
653 (* |
|
654 lemma CPTpre_STAR_finite: |
|
655 assumes "\<And>s. finite (CPT r s)" |
|
656 shows "finite (CPT (STAR r) s)" |
|
657 apply(induct s rule: length_induct) |
|
658 apply(case_tac xs) |
|
659 apply(simp) |
|
660 apply(simp add: CPT_simps) |
|
661 apply(auto) |
|
662 apply(rule finite_imageI) |
|
663 using assms |
|
664 thm finite_Un |
|
665 prefer 2 |
|
666 apply(simp add: CPT_simps) |
|
667 apply(rule finite_imageI) |
|
668 apply(rule finite_subset) |
|
669 apply(rule CPTpre_subsets) |
|
670 apply(simp) |
|
671 apply(rule_tac B="(\<lambda>(v, vs). Stars (v#vs)) ` {(v, vs). v \<in> CPTpre r (a#list) \<and> flat v \<noteq> [] \<and> Stars vs \<in> CPTpre (STAR r) (drop (length (flat v)) (a#list))}" in finite_subset) |
|
672 apply(auto)[1] |
|
673 apply(rule finite_imageI) |
|
674 apply(simp add: Collect_case_prod_Sigma) |
|
675 apply(rule finite_SigmaI) |
|
676 apply(rule assms) |
|
677 apply(case_tac "flat v = []") |
|
678 apply(simp) |
|
679 apply(drule_tac x="drop (length (flat v)) (a # list)" in spec) |
|
680 apply(simp) |
|
681 apply(auto)[1] |
|
682 apply(rule test) |
|
683 apply(simp) |
|
684 done |
699 |
685 |
700 lemma CPTpre_subsets: |
686 lemma CPTpre_subsets: |
701 "CPTpre ZERO s = {}" |
687 "CPTpre ZERO s = {}" |
702 "CPTpre ONE s \<subseteq> {Void}" |
688 "CPTpre ONE s \<subseteq> {Void}" |
703 "CPTpre (CHAR c) s \<subseteq> {Char c}" |
689 "CPTpre (CHAR c) s \<subseteq> {Char c}" |
959 using PosOrd_spreI as1(1) eqs by blast |
954 using PosOrd_spreI as1(1) eqs by blast |
960 then have "v1 :\<sqsubset>val v3a \<or> (v3a \<in> CPT r1 s1 \<and> v3b \<in> CPT r2 s2)" using eqs(2,3) |
955 then have "v1 :\<sqsubset>val v3a \<or> (v3a \<in> CPT r1 s1 \<and> v3b \<in> CPT r2 s2)" using eqs(2,3) |
961 by (auto simp add: CPT_def) |
956 by (auto simp add: CPT_def) |
962 then have "v1 :\<sqsubset>val v3a \<or> (v1 :\<sqsubseteq>val v3a \<and> v2 :\<sqsubseteq>val v3b)" using IH1 IH2 by blast |
957 then have "v1 :\<sqsubset>val v3a \<or> (v1 :\<sqsubseteq>val v3a \<and> v2 :\<sqsubseteq>val v3b)" using IH1 IH2 by blast |
963 then have "Seq v1 v2 :\<sqsubseteq>val Seq v3a v3b" using eqs q2 as1 |
958 then have "Seq v1 v2 :\<sqsubseteq>val Seq v3a v3b" using eqs q2 as1 |
964 unfolding PosOrd_ex1_def by (auto simp add: PosOrd_SeqI1 PosOrd_SeqI2) |
959 unfolding PosOrd_ex_eq_def by (auto simp add: PosOrd_SeqI1 PosOrd_SeqI2) |
965 then show "Seq v1 v2 :\<sqsubseteq>val v3" unfolding eqs by blast |
960 then show "Seq v1 v2 :\<sqsubseteq>val v3" unfolding eqs by blast |
966 next |
961 next |
967 case (Posix_STAR1 s1 r v s2 vs v3) |
962 case (Posix_STAR1 s1 r v s2 vs v3) |
968 have "s1 \<in> r \<rightarrow> v" "s2 \<in> STAR r \<rightarrow> Stars vs" by fact+ |
963 have "s1 \<in> r \<rightarrow> v" "s2 \<in> STAR r \<rightarrow> Stars vs" by fact+ |
969 then have as1: "s1 = flat v" "s2 = flat (Stars vs)" by (auto dest: Posix1(2)) |
964 then have as1: "s1 = flat v" "s2 = flat (Stars vs)" by (auto dest: Posix1(2)) |
970 have IH1: "\<And>v3. v3 \<in> CPT r s1 \<Longrightarrow> v :\<sqsubseteq>val v3" by fact |
965 have IH1: "\<And>v3. v3 \<in> CPT r s1 \<Longrightarrow> v :\<sqsubseteq>val v3" by fact |
971 have IH2: "\<And>v3. v3 \<in> CPT (STAR r) s2 \<Longrightarrow> Stars vs :\<sqsubseteq>val v3" by fact |
966 have IH2: "\<And>v3. v3 \<in> CPT (STAR r) s2 \<Longrightarrow> Stars vs :\<sqsubseteq>val v3" by fact |
972 have cond: "\<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 |
967 have cond: "\<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 |
973 have cond2: "flat v \<noteq> []" by fact |
968 have cond2: "flat v \<noteq> []" by fact |
974 have "v3 \<in> CPT (STAR r) (s1 @ s2)" by fact |
969 have "v3 \<in> CPT (STAR r) (s1 @ s2)" by fact |
975 then consider |
970 then consider |
976 (NonEmpty) v3a vs3 where |
971 (NonEmpty) v3a vs3 where "v3 = Stars (v3a # vs3)" |
977 "v3 = Stars (v3a # vs3)" "\<Turnstile> v3a : r" "\<Turnstile> Stars vs3 : STAR r" |
972 "\<Turnstile> v3a : r" "\<Turnstile> Stars vs3 : STAR r" |
978 "flat (Stars (v3a # vs3)) = s1 @ s2" |
973 "flat (Stars (v3a # vs3)) = s1 @ s2" |
979 | (Empty) "v3 = Stars []" |
974 | (Empty) "v3 = Stars []" |
980 by (force simp add: CPT_def elim: CPrf.cases) |
975 unfolding CPT_def |
981 then show "Stars (v # vs) :\<sqsubseteq>val v3" |
976 apply(auto) |
|
977 apply(erule CPrf.cases) |
|
978 apply(simp_all) |
|
979 apply(auto)[1] |
|
980 apply(case_tac vs) |
|
981 apply(auto) |
|
982 using CPrf.intros(6) by blast |
|
983 then show "Stars (v # vs) :\<sqsubseteq>val v3" (* HERE *) |
982 proof (cases) |
984 proof (cases) |
983 case (NonEmpty v3a vs3) |
985 case (NonEmpty v3a vs3) |
984 have "flat (Stars (v3a # vs3)) = s1 @ s2" using NonEmpty(4) . |
986 have "flat (Stars (v3a # vs3)) = s1 @ s2" using NonEmpty(4) . |
985 with cond have "flat v3a \<sqsubseteq>pre s1" using NonEmpty(2,3) |
987 with cond have "flat v3a \<sqsubseteq>pre s1" using NonEmpty(2,3) |
986 unfolding prefix_list_def |
988 unfolding prefix_list_def |
991 using PosOrd_spreI as1(1) NonEmpty(4) by blast |
993 using PosOrd_spreI as1(1) NonEmpty(4) by blast |
992 then have "v :\<sqsubset>val v3a \<or> (v3a \<in> CPT r s1 \<and> Stars vs3 \<in> CPT (STAR r) s2)" |
994 then have "v :\<sqsubset>val v3a \<or> (v3a \<in> CPT r s1 \<and> Stars vs3 \<in> CPT (STAR r) s2)" |
993 using NonEmpty(2,3) by (auto simp add: CPT_def) |
995 using NonEmpty(2,3) by (auto simp add: CPT_def) |
994 then have "v :\<sqsubset>val v3a \<or> (v :\<sqsubseteq>val v3a \<and> Stars vs :\<sqsubseteq>val Stars vs3)" using IH1 IH2 by blast |
996 then have "v :\<sqsubset>val v3a \<or> (v :\<sqsubseteq>val v3a \<and> Stars vs :\<sqsubseteq>val Stars vs3)" using IH1 IH2 by blast |
995 then have "v :\<sqsubset>val v3a \<or> (v = v3a \<and> Stars vs :\<sqsubseteq>val Stars vs3)" |
997 then have "v :\<sqsubset>val v3a \<or> (v = v3a \<and> Stars vs :\<sqsubseteq>val Stars vs3)" |
996 unfolding PosOrd_ex1_def by auto |
998 unfolding PosOrd_ex_eq_def by auto |
997 then have "Stars (v # vs) :\<sqsubseteq>val Stars (v3a # vs3)" using NonEmpty(4) q2 as1 |
999 then have "Stars (v # vs) :\<sqsubseteq>val Stars (v3a # vs3)" using NonEmpty(4) q2 as1 |
998 unfolding PosOrd_ex1_def |
1000 unfolding PosOrd_ex_eq_def |
999 by (metis PosOrd_StarsI PosOrd_StarsI2 flat.simps(7) val.inject(5)) |
1001 by (metis PosOrd_StarsI PosOrd_StarsI2 flat.simps(7) val.inject(5)) |
1000 then show "Stars (v # vs) :\<sqsubseteq>val v3" unfolding NonEmpty by blast |
1002 then show "Stars (v # vs) :\<sqsubseteq>val v3" unfolding NonEmpty by blast |
1001 next |
1003 next |
1002 case Empty |
1004 case Empty |
1003 have "v3 = Stars []" by fact |
1005 have "v3 = Stars []" by fact |
1004 then show "Stars (v # vs) :\<sqsubseteq>val v3" |
1006 then show "Stars (v # vs) :\<sqsubseteq>val v3" |
1005 unfolding PosOrd_ex1_def using cond2 |
1007 unfolding PosOrd_ex_eq_def using cond2 |
1006 by (simp add: PosOrd_shorterI) |
1008 by (simp add: PosOrd_shorterI) |
1007 qed |
1009 qed |
1008 next |
1010 next |
1009 case (Posix_STAR2 r v2) |
1011 case (Posix_STAR2 r v2) |
1010 have "v2 \<in> CPT (STAR r) []" by fact |
1012 have "v2 \<in> CPT (STAR r) []" by fact |
1011 then have "v2 = Stars []" |
1013 then have "v2 = Stars []" |
1012 unfolding CPT_def by (auto elim: CPrf.cases) |
1014 unfolding CPT_def by (auto elim: CPrf.cases) |
1013 then show "Stars [] :\<sqsubseteq>val v2" |
1015 then show "Stars [] :\<sqsubseteq>val v2" |
1014 by (simp add: PosOrd_ex1_def) |
1016 by (simp add: PosOrd_ex_eq_def) |
1015 qed |
1017 qed |
1016 |
1018 |
1017 lemma Posix_PosOrd_stronger: |
1019 lemma Posix_PosOrd_stronger: |
1018 assumes "s \<in> r \<rightarrow> v1" "v2 \<in> CPTpre r s" |
1020 assumes "s \<in> r \<rightarrow> v1" "v2 \<in> CPTpre r s" |
1019 shows "v1 :\<sqsubseteq>val v2" |
1021 shows "v1 :\<sqsubseteq>val v2" |
1113 apply(simp) |
1115 apply(simp) |
1114 apply(subst (asm) (2) PosOrd_ex_def) |
1116 apply(subst (asm) (2) PosOrd_ex_def) |
1115 apply(simp) |
1117 apply(simp) |
1116 apply (metis flat.simps(7) flat_Stars PosOrd_StarsI2 PosOrd_ex_def) |
1118 apply (metis flat.simps(7) flat_Stars PosOrd_StarsI2 PosOrd_ex_def) |
1117 by (metis PosOrd_StarsI PosOrd_ex_def PosOrd_spreI append_assoc append_self_conv flat.simps(7) flat_Stars prefix_list_def sprefix_list_def) |
1119 by (metis PosOrd_StarsI PosOrd_ex_def PosOrd_spreI append_assoc append_self_conv flat.simps(7) flat_Stars prefix_list_def sprefix_list_def) |
|
1120 *) |
|
1121 |
|
1122 |
|
1123 lemma test2: |
|
1124 assumes "\<forall>v \<in> set vs. flat v \<in> r \<rightarrow> v \<and> flat v \<noteq> []" |
|
1125 shows "(Stars vs) \<in> CPT (STAR r) (flat (Stars vs))" |
|
1126 using assms |
|
1127 apply(induct vs) |
|
1128 apply(auto simp add: CPT_def) |
|
1129 apply(rule CPrf.intros) |
|
1130 apply(simp) |
|
1131 apply(rule CPrf.intros) |
|
1132 apply(simp_all) |
|
1133 by (metis (no_types, lifting) CPT_def Posix_CPT mem_Collect_eq) |
|
1134 |
|
1135 |
|
1136 lemma PosOrd_Posix_Stars: |
|
1137 assumes "\<forall>v \<in> set vs. flat v \<in> r \<rightarrow> v \<and> flat v \<noteq> []" |
|
1138 and "\<not>(\<exists>vs2 \<in> PT (STAR r) (flat (Stars vs)). vs2 :\<sqsubset>val (Stars vs))" |
|
1139 shows "(flat (Stars vs)) \<in> (STAR r) \<rightarrow> Stars vs" |
|
1140 using assms |
|
1141 proof(induct vs) |
|
1142 case Nil |
|
1143 show "flat (Stars []) \<in> STAR r \<rightarrow> Stars []" |
|
1144 by(simp add: Posix.intros) |
|
1145 next |
|
1146 case (Cons v vs) |
|
1147 have IH: "\<lbrakk>\<forall>v\<in>set vs. flat v \<in> r \<rightarrow> v \<and> flat v \<noteq> []; |
|
1148 \<not> (\<exists>vs2\<in>PT (STAR r) (flat (Stars vs)). vs2 :\<sqsubset>val Stars vs)\<rbrakk> |
|
1149 \<Longrightarrow> flat (Stars vs) \<in> STAR r \<rightarrow> Stars vs" by fact |
|
1150 have as2: "\<forall>v\<in>set (v # vs). flat v \<in> r \<rightarrow> v \<and> flat v \<noteq> []" by fact |
|
1151 have as3: "\<not> (\<exists>vs2\<in>PT (STAR r) (flat (Stars (v # vs))). vs2 :\<sqsubset>val Stars (v # vs))" by fact |
|
1152 have "flat v \<in> r \<rightarrow> v" using as2 by simp |
|
1153 moreover |
|
1154 have "flat (Stars vs) \<in> STAR r \<rightarrow> Stars vs" |
|
1155 proof (rule IH) |
|
1156 show "\<forall>v\<in>set vs. flat v \<in> r \<rightarrow> v \<and> flat v \<noteq> []" using as2 by simp |
|
1157 next |
|
1158 show "\<not> (\<exists>vs2\<in>PT (STAR r) (flat (Stars vs)). vs2 :\<sqsubset>val Stars vs)" using as3 |
|
1159 apply(auto) |
|
1160 apply(subst (asm) (2) PT_def) |
|
1161 apply(auto) |
|
1162 apply(erule Prf.cases) |
|
1163 apply(simp_all) |
|
1164 apply(drule_tac x="Stars (v # vs)" in bspec) |
|
1165 apply(simp add: PT_def CPT_def) |
|
1166 using Posix1a Prf.intros(6) calculation |
|
1167 apply(rule_tac Prf.intros) |
|
1168 apply(simp add:) |
|
1169 apply (simp add: PosOrd_StarsI2) |
|
1170 done |
|
1171 qed |
|
1172 moreover |
|
1173 have "flat v \<noteq> []" using as2 by simp |
|
1174 moreover |
|
1175 have "\<not> (\<exists>s\<^sub>3 s\<^sub>4. s\<^sub>3 \<noteq> [] \<and> s\<^sub>3 @ s\<^sub>4 = flat (Stars vs) \<and> flat v @ s\<^sub>3 \<in> L r \<and> s\<^sub>4 \<in> L (STAR r))" |
|
1176 using as3 |
|
1177 apply(auto) |
|
1178 apply(drule L_flat_Prf2) |
|
1179 apply(erule exE) |
|
1180 apply(simp only: L.simps[symmetric]) |
|
1181 apply(drule L_flat_Prf2) |
|
1182 apply(erule exE) |
|
1183 apply(clarify) |
|
1184 apply(rotate_tac 5) |
|
1185 apply(erule Prf.cases) |
|
1186 apply(simp_all) |
|
1187 apply(clarify) |
|
1188 apply(drule_tac x="Stars (va#vs)" in bspec) |
|
1189 apply(auto simp add: PT_def)[1] |
|
1190 apply(rule Prf.intros) |
|
1191 apply(simp) |
|
1192 by (simp add: PosOrd_StarsI PosOrd_shorterI) |
|
1193 ultimately show "flat (Stars (v # vs)) \<in> STAR r \<rightarrow> Stars (v # vs)" |
|
1194 by (simp add: Posix.intros) |
|
1195 qed |
|
1196 |
1118 |
1197 |
1119 |
1198 |
1120 section {* The Smallest Value is indeed the Posix Value *} |
1199 section {* The Smallest Value is indeed the Posix Value *} |
1121 |
1200 |
|
1201 text {* |
|
1202 The next lemma seems to require PT instead of CPT in the Star-case. |
|
1203 *} |
|
1204 |
1122 lemma PosOrd_Posix: |
1205 lemma PosOrd_Posix: |
1123 assumes "v1 \<in> CPT r s" "\<forall>v2 \<in> PT r s. \<not> v2 :\<sqsubset>val v1" |
1206 assumes "v1 \<in> CPT r s" "\<forall>v\<^sub>2 \<in> PT r s. \<not> v\<^sub>2 :\<sqsubset>val v1" |
1124 shows "s \<in> r \<rightarrow> v1" |
1207 shows "s \<in> r \<rightarrow> v1" |
1125 using assms |
1208 using assms |
1126 proof(induct r arbitrary: s v1) |
1209 proof(induct r arbitrary: s v1) |
1127 case (ZERO s v1) |
1210 case (ZERO s v1) |
1128 have "v1 \<in> CPT ZERO s" by fact |
1211 have "v1 \<in> CPT ZERO s" by fact |