diff --git a/thys/Posix-Lexing/Extensions/Derivatives3.thy b/thys/Posix-Lexing/Extensions/Derivatives3.thy new file mode 100644 --- /dev/null +++ b/thys/Posix-Lexing/Extensions/Derivatives3.thy @@ -0,0 +1,62 @@ +section "Derivatives of Extended Regular Expressions" + +(* Author: Christian Urban *) + +theory Derivatives3 +imports Regular_Exps3 +begin + +text\This theory is based on work by Brozowski \cite{Brzozowski64}.\ + +subsection \Brzozowski's derivatives of regular expressions\ + +fun + deriv :: "'a \ 'a rexp \ 'a rexp" +where + "deriv c (Zero) = Zero" +| "deriv c (One) = Zero" +| "deriv c (Atom c') = (if c = c' then One else Zero)" +| "deriv c (Plus r1 r2) = Plus (deriv c r1) (deriv c r2)" +| "deriv c (Times r1 r2) = + (if nullable r1 then Plus (Times (deriv c r1) r2) (deriv c r2) else Times (deriv c r1) r2)" +| "deriv c (Star r) = Times (deriv c r) (Star r)" +| "deriv c (NTimes r n) = (if n = 0 then Zero else Times (deriv c r) (NTimes r (n-1)))" + +fun + derivs :: "'a list \ 'a rexp \ 'a rexp" +where + "derivs [] r = r" +| "derivs (c # s) r = derivs s (deriv c r)" + + +lemma atoms_deriv_subset: "atoms (deriv x r) \ atoms r" +by (induction r) (auto) + +lemma atoms_derivs_subset: "atoms (derivs w r) \ atoms r" +by (induction w arbitrary: r) (auto dest: atoms_deriv_subset[THEN subsetD]) + + + +lemma deriv_pow [simp]: + shows "Deriv c (A ^^ n) = (if n = 0 then {} else (Deriv c A) @@ (A ^^ (n - 1)))" + apply(induct n arbitrary: A) + apply(auto) + by (metis Suc_pred concI_if_Nil2 conc_assoc conc_pow_comm lang_pow.simps(2)) + +lemma lang_deriv: "lang (deriv c r) = Deriv c (lang r)" + by (induct r) (simp_all add: nullable_iff) + + +lemma lang_derivs: "lang (derivs s r) = Derivs s (lang r)" +by (induct s arbitrary: r) (simp_all add: lang_deriv) + +text \A regular expression matcher:\ + +definition matcher :: "'a rexp \ 'a list \ bool" where +"matcher r s = nullable (derivs s r)" + +lemma matcher_correctness: "matcher r s \ s \ lang r" +by (induct s arbitrary: r) + (simp_all add: nullable_iff lang_deriv matcher_def Deriv_def) + +end diff --git a/thys/Posix-Lexing/Extensions/Lexer3.thy b/thys/Posix-Lexing/Extensions/Lexer3.thy new file mode 100644 --- /dev/null +++ b/thys/Posix-Lexing/Extensions/Lexer3.thy @@ -0,0 +1,701 @@ +(* Title: POSIX Lexing with Derivatives of Extended Regular Expressions + Author: Christian Urban , 2022 + Maintainer: Christian Urban +*) + +theory Lexer3 + imports "Derivatives3" +begin + +section \Values\ + +datatype 'a val = + Void +| Atm 'a +| Seq "'a val" "'a val" +| Right "'a val" +| Left "'a val" +| Stars "('a val) list" + + +section \The string behind a value\ + +fun + flat :: "'a val \ 'a list" +where + "flat (Void) = []" +| "flat (Atm c) = [c]" +| "flat (Left v) = flat v" +| "flat (Right v) = flat v" +| "flat (Seq v1 v2) = (flat v1) @ (flat v2)" +| "flat (Stars []) = []" +| "flat (Stars (v#vs)) = (flat v) @ (flat (Stars vs))" + +abbreviation + "flats vs \ concat (map flat vs)" + +lemma flat_Stars [simp]: + "flat (Stars vs) = concat (map flat vs)" +by (induct vs) (auto) + +section \Relation between values and regular expressions\ + +inductive + Prf :: "'a val \ 'a rexp \ bool" ("\ _ : _" [100, 100] 100) +where + "\\ v1 : r1; \ v2 : r2\ \ \ Seq v1 v2 : Times r1 r2" +| "\ v1 : r1 \ \ Left v1 : Plus r1 r2" +| "\ v2 : r2 \ \ Right v2 : Plus r1 r2" +| "\ Void : One" +| "\ Atm c : Atom c" +| "\\v \ set vs. \ v : r \ flat v \ []\ \ \ Stars vs : Star r" +| "\\v \ set vs1. \ v : r \ flat v \ []; + \v \ set vs2. \ v : r \ flat v = []; + length (vs1 @ vs2) = n\ \ \ Stars (vs1 @ vs2) : NTimes r n" + +inductive_cases Prf_elims: + "\ v : Zero" + "\ v : Times r1 r2" + "\ v : Plus r1 r2" + "\ v : One" + "\ v : Atom c" + "\ vs : Star r" + "\ vs : NTimes r n" + +lemma Prf_NTimes_empty: + assumes "\v \ set vs. \ v : r \ flat v = []" + and "length vs = n" + shows "\ Stars vs : NTimes r n" + using assms + by (metis Prf.intros(7) empty_iff eq_Nil_appendI list.set(1)) + + +lemma Seq_decomp: + assumes "s \ A @@ B" + shows "\s1 s2. s = s1 @ s2 \ s1 \ A \ s2 \ B" + using assms + by blast + +lemma NTimes_string: + assumes "s \ A ^^ n" + shows "\ss. concat ss = s \ (\s \ set ss. s \ A) \ length ss = n" +using assms + apply(induct n arbitrary: s) + apply(auto dest!: Seq_decomp) + apply(drule_tac x="s2" in meta_spec) + apply(auto) + apply(rule_tac x="s1 # ss" in exI) + apply(simp) + done + +lemma pow_Prf: + assumes "\v\set vs. \ v : r \ flat v \ A" + shows "flats vs \ A ^^ (length vs)" + using assms + by (induct vs) (auto) + +lemma Star_string: + assumes "s \ star A" + shows "\ss. concat ss = s \ (\s \ set ss. s \ A)" +using assms +by (metis in_star_iff_concat subsetD) + +lemma Star_val: + assumes "\s\set ss. \v. s = flat v \ \ v : r" + shows "\vs. flats vs = concat ss \ (\v\set vs. \ v : r \ flat v \ [])" +using assms +apply(induct ss) +apply(auto) +apply (metis empty_iff list.set(1)) +by (metis append.simps(1) flat.simps(7) flat_Stars set_ConsD) + +lemma Aux: + assumes "\s\set ss. s = []" + shows "concat ss = []" +using assms +by (induct ss) (auto) + +lemma Pow_cstring: + assumes "s \ A ^^ n" + shows "\ss1 ss2. concat (ss1 @ ss2) = s \ length (ss1 @ ss2) = n \ + (\s \ set ss1. s \ A \ s \ []) \ (\s \ set ss2. s \ A \ s = [])" +using assms +apply(induct n arbitrary: s) + apply(auto)[1] + apply(auto dest!: Seq_decomp simp add: Seq_def) + apply(drule_tac x="s2" in meta_spec) + apply(simp) +apply(erule exE)+ + apply(clarify) +apply(case_tac "s1 = []") +apply(simp) +apply(rule_tac x="ss1" in exI) +apply(rule_tac x="s1 # ss2" in exI) +apply(simp) +apply(rule_tac x="s1 # ss1" in exI) +apply(rule_tac x="ss2" in exI) + apply(simp) + done + +lemma flats_cval: + assumes "\s\set ss. \v. s = flat v \ \ v : r" + shows "\vs1 vs2. flats (vs1 @ vs2) = concat ss \ length (vs1 @ vs2) = length ss \ + (\v\set vs1. \ v : r \ flat v \ []) \ + (\v\set vs2. \ v : r \ flat v = [])" +using assms +apply(induct ss rule: rev_induct) +apply(rule_tac x="[]" in exI)+ +apply(simp) +apply(simp) +apply(clarify) +apply(case_tac "flat v = []") +apply(rule_tac x="vs1" in exI) +apply(rule_tac x="v#vs2" in exI) +apply(simp) +apply(rule_tac x="vs1 @ [v]" in exI) +apply(rule_tac x="vs2" in exI) +apply(simp) +by (simp add: Aux) + +lemma Prf_flat_lang: + assumes "\ v : r" shows "flat v \ lang r" +using assms + apply (induct v r rule: Prf.induct) + apply (auto simp add: concat_in_star subset_eq lang_pow_add) + by (meson concI pow_Prf) + +lemma L_flat_Prf2: + assumes "s \ lang r" + shows "\v. \ v : r \ flat v = s" +using assms +proof(induct r arbitrary: s) + case (Star r s) + have IH: "\s. s \ lang r \ \v.\ v : r \ flat v = s" by fact + have "s \ lang (Star r)" by fact + then obtain ss where "concat ss = s" "\s \ set ss. s \ lang r \ s \ []" + by (smt (z3) IH Prf_flat_lang Star_val imageE in_star_iff_concat lang.simps(6) list.set_map subset_iff) + then obtain vs where "flats vs = s" "\v\set vs. \ v : r \ flat v \ []" + using IH by (metis Star_val) + then show "\v. \ v : Star r \ flat v = s" + using Prf.intros(6) flat_Stars by blast +next + case (Times r1 r2 s) + then show "\v. \ v : Times r1 r2 \ flat v = s" + unfolding Seq_def lang.simps by (fastforce intro: Prf.intros) +next + case (Plus r1 r2 s) + then show "\v. \ v : Plus r1 r2 \ flat v = s" + unfolding lang.simps by (fastforce intro: Prf.intros) +next + case (NTimes r n) + have IH: "\s. s \ lang r \ \v. \ v : r \ flat v = s" by fact + have "s \ lang (NTimes r n)" by fact + then obtain ss1 ss2 where "concat (ss1 @ ss2) = s" "length (ss1 @ ss2) = n" + "\s \ set ss1. s \ lang r \ s \ []" "\s \ set ss2. s \ lang r \ s = []" + using Pow_cstring by force + then obtain vs1 vs2 where "flats (vs1 @ vs2) = s" "length (vs1 @ vs2) = n" + "\v\set vs1. \ v : r \ flat v \ []" "\v\set vs2. \ v : r \ flat v = []" + using IH flats_cval + apply - + apply(drule_tac x="ss1 @ ss2" in meta_spec) + apply(drule_tac x="r" in meta_spec) + apply(drule meta_mp) + apply(simp) + apply (metis Un_iff) + apply(clarify) + apply(drule_tac x="vs1" in meta_spec) + apply(drule_tac x="vs2" in meta_spec) + apply(simp) + done + then show "\v. \ v : NTimes r n \ flat v = s" + using Prf.intros(7) flat_Stars by blast +qed (auto intro: Prf.intros) + +lemma L_flat_Prf: + "lang r = {flat v | v. \ v : r}" + using L_flat_Prf2 Prf_flat_lang by blast + + +section \Sulzmann and Lu functions\ + +fun + mkeps :: "'a rexp \ 'a val" +where + "mkeps(One) = Void" +| "mkeps(Times r1 r2) = Seq (mkeps r1) (mkeps r2)" +| "mkeps(Plus r1 r2) = (if nullable(r1) then Left (mkeps r1) else Right (mkeps r2))" +| "mkeps(Star r) = Stars []" +| "mkeps(NTimes r n) = Stars (replicate n (mkeps r))" + +fun injval :: "'a rexp \ 'a \ 'a val \ 'a val" +where + "injval (Atom d) c Void = Atm d" +| "injval (Plus r1 r2) c (Left v1) = Left(injval r1 c v1)" +| "injval (Plus r1 r2) c (Right v2) = Right(injval r2 c v2)" +| "injval (Times r1 r2) c (Seq v1 v2) = Seq (injval r1 c v1) v2" +| "injval (Times r1 r2) c (Left (Seq v1 v2)) = Seq (injval r1 c v1) v2" +| "injval (Times r1 r2) c (Right v2) = Seq (mkeps r1) (injval r2 c v2)" +| "injval (Star r) c (Seq v (Stars vs)) = Stars ((injval r c v) # vs)" +| "injval (NTimes r n) c (Seq v (Stars vs)) = Stars ((injval r c v) # vs)" + +section \Mkeps, injval\ + +lemma mkeps_flat: + assumes "nullable(r)" + shows "flat (mkeps r) = []" +using assms + by (induct rule: mkeps.induct) (auto) + +lemma mkeps_nullable: + assumes "nullable r" + shows "\ mkeps r : r" +using assms + apply (induct r) + apply (auto intro: Prf.intros split: if_splits) + apply (metis Prf.intros(7) append_Nil2 in_set_replicate list.size(3) replicate_0) + apply(rule Prf_NTimes_empty) + apply(auto simp add: mkeps_flat) + done + +lemma Prf_injval_flat: + assumes "\ v : deriv c r" + shows "flat (injval r c v) = c # (flat v)" +using assms +apply(induct c r arbitrary: v rule: deriv.induct) +apply(auto elim!: Prf_elims intro: mkeps_flat split: if_splits) +done + +lemma Prf_injval: + assumes "\ v : deriv c r" + shows "\ (injval r c v) : r" +using assms +apply(induct r arbitrary: c v rule: rexp.induct) +apply(auto intro!: Prf.intros mkeps_nullable elim!: Prf_elims split: if_splits) +(* Star *) +apply (simp add: Prf_injval_flat) +(* NTimes *) + apply(case_tac x2) + apply(simp) + apply(simp) + apply(subst append.simps(2)[symmetric]) + apply(rule Prf.intros) + apply(auto simp add: Prf_injval_flat) + done + +section \Our Alternative Posix definition\ + +inductive + Posix :: "'a list \ 'a rexp \ 'a val \ bool" ("_ \ _ \ _" [100, 100, 100] 100) +where + Posix_One: "[] \ One \ Void" +| Posix_Atom: "[c] \ (Atom c) \ (Atm c)" +| Posix_Plus1: "s \ r1 \ v \ s \ (Plus r1 r2) \ (Left v)" +| Posix_Plus2: "\s \ r2 \ v; s \ lang r1\ \ s \ (Plus r1 r2) \ (Right v)" +| Posix_Times: "\s1 \ r1 \ v1; s2 \ r2 \ v2; + \(\s\<^sub>3 s\<^sub>4. s\<^sub>3 \ [] \ s\<^sub>3 @ s\<^sub>4 = s2 \ (s1 @ s\<^sub>3) \ lang r1 \ s\<^sub>4 \ lang r2)\ \ + (s1 @ s2) \ (Times r1 r2) \ (Seq v1 v2)" +| Posix_Star1: "\s1 \ r \ v; s2 \ Star r \ Stars vs; flat v \ []; + \(\s\<^sub>3 s\<^sub>4. s\<^sub>3 \ [] \ s\<^sub>3 @ s\<^sub>4 = s2 \ (s1 @ s\<^sub>3) \ lang r \ s\<^sub>4 \ lang (Star r))\ + \ (s1 @ s2) \ Star r \ Stars (v # vs)" +| Posix_Star2: "[] \ Star r \ Stars []" +| Posix_NTimes1: "\s1 \ r \ v; s2 \ NTimes r (n - 1) \ Stars vs; flat v \ []; 0 < n; + \(\s\<^sub>3 s\<^sub>4. s\<^sub>3 \ [] \ s\<^sub>3 @ s\<^sub>4 = s2 \ (s1 @ s\<^sub>3) \ lang r \ s\<^sub>4 \ lang (NTimes r (n - 1)))\ + \ (s1 @ s2) \ NTimes r n \ Stars (v # vs)" +| Posix_NTimes2: "\\v \ set vs. [] \ r \ v; length vs = n\ + \ [] \ NTimes r n \ Stars vs" + +inductive_cases Posix_elims: + "s \ Zero \ v" + "s \ One \ v" + "s \ Atom c \ v" + "s \ Plus r1 r2 \ v" + "s \ Times r1 r2 \ v" + "s \ Star r \ v" + "s \ NTimes r n \ v" + +lemma Posix1: + assumes "s \ r \ v" + shows "s \ lang r" "flat v = s" +using assms + apply (induct s r v rule: Posix.induct) + apply(auto simp add: pow_empty_iff) + apply (metis Suc_pred concI lang_pow.simps(2)) + by (meson ex_in_conv set_empty) + +lemma Posix1a: + assumes "s \ r \ v" + shows "\ v : r" +using assms + apply(induct s r v rule: Posix.induct) + apply(auto intro: Prf.intros) + apply (metis Prf.intros(6) Prf_elims(6) set_ConsD val.inject(5)) + prefer 2 + using Posix1(2) Prf_NTimes_empty apply blast + apply(erule Prf_elims) + apply(auto) + apply(subst append.simps(2)[symmetric]) + apply(rule Prf.intros) + apply(auto) + done + + +lemma Posix_mkeps: + assumes "nullable r" + shows "[] \ r \ mkeps r" +using assms +apply(induct r) +apply(auto intro: Posix.intros simp add: nullable_iff) +apply(subst append.simps(1)[symmetric]) +apply(rule Posix.intros) +apply(auto) + by (simp add: Posix_NTimes2 pow_empty_iff) + +lemma List_eq_zipI: + assumes "\(v1, v2) \ set (zip vs1 vs2). v1 = v2" + and "length vs1 = length vs2" + shows "vs1 = vs2" + using assms + apply(induct vs1 arbitrary: vs2) + apply(case_tac vs2) + apply(simp) + apply(simp) + apply(case_tac vs2) + apply(simp) + apply(simp) +done + + +text \Our Posix definition determines a unique value.\ + +lemma Posix_determ: + assumes "s \ r \ v1" "s \ r \ v2" + shows "v1 = v2" +using assms +proof (induct s r v1 arbitrary: v2 rule: Posix.induct) + case (Posix_One v2) + have "[] \ One \ v2" by fact + then show "Void = v2" by cases auto +next + case (Posix_Atom c v2) + have "[c] \ Atom c \ v2" by fact + then show "Atm c = v2" by cases auto +next + case (Posix_Plus1 s r1 v r2 v2) + have "s \ Plus r1 r2 \ v2" by fact + moreover + have "s \ r1 \ v" by fact + then have "s \ lang r1" by (simp add: Posix1) + ultimately obtain v' where eq: "v2 = Left v'" "s \ r1 \ v'" by cases auto + moreover + have IH: "\v2. s \ r1 \ v2 \ v = v2" by fact + ultimately have "v = v'" by simp + then show "Left v = v2" using eq by simp +next + case (Posix_Plus2 s r2 v r1 v2) + have "s \ Plus r1 r2 \ v2" by fact + moreover + have "s \ lang r1" by fact + ultimately obtain v' where eq: "v2 = Right v'" "s \ r2 \ v'" + by cases (auto simp add: Posix1) + moreover + have IH: "\v2. s \ r2 \ v2 \ v = v2" by fact + ultimately have "v = v'" by simp + then show "Right v = v2" using eq by simp +next + case (Posix_Times s1 r1 v1 s2 r2 v2 v') + have "(s1 @ s2) \ Times r1 r2 \ v'" + "s1 \ r1 \ v1" "s2 \ r2 \ v2" + "\ (\s\<^sub>3 s\<^sub>4. s\<^sub>3 \ [] \ s\<^sub>3 @ s\<^sub>4 = s2 \ s1 @ s\<^sub>3 \ lang r1 \ s\<^sub>4 \ lang r2)" by fact+ + then obtain v1' v2' where "v' = Seq v1' v2'" "s1 \ r1 \ v1'" "s2 \ r2 \ v2'" + apply(cases) apply (auto simp add: append_eq_append_conv2) + using Posix1(1) by fastforce+ + moreover + have IHs: "\v1'. s1 \ r1 \ v1' \ v1 = v1'" + "\v2'. s2 \ r2 \ v2' \ v2 = v2'" by fact+ + ultimately show "Seq v1 v2 = v'" by simp +next + case (Posix_Star1 s1 r v s2 vs v2) + have "(s1 @ s2) \ Star r \ v2" + "s1 \ r \ v" "s2 \ Star r \ Stars vs" "flat v \ []" + "\ (\s\<^sub>3 s\<^sub>4. s\<^sub>3 \ [] \ s\<^sub>3 @ s\<^sub>4 = s2 \ s1 @ s\<^sub>3 \ lang r \ s\<^sub>4 \ lang (Star r))" by fact+ + then obtain v' vs' where "v2 = Stars (v' # vs')" "s1 \ r \ v'" "s2 \ (Star r) \ (Stars vs')" + apply(cases) apply (auto simp add: append_eq_append_conv2) + using Posix1(1) apply fastforce + apply (metis Posix1(1) Posix_Star1.hyps(6) append_Nil append_Nil2) + using Posix1(2) by blast + moreover + have IHs: "\v2. s1 \ r \ v2 \ v = v2" + "\v2. s2 \ Star r \ v2 \ Stars vs = v2" by fact+ + ultimately show "Stars (v # vs) = v2" by auto +next + case (Posix_Star2 r v2) + have "[] \ Star r \ v2" by fact + then show "Stars [] = v2" by cases (auto simp add: Posix1) +next + case (Posix_NTimes2 vs r n v2) + then show "Stars vs = v2" + apply(erule_tac Posix_elims) + apply(auto) + apply (simp add: Posix1(2)) + apply(rule List_eq_zipI) + apply(auto) + by (meson in_set_zipE) +next + case (Posix_NTimes1 s1 r v s2 n vs) + have "(s1 @ s2) \ NTimes r n \ v2" + "s1 \ r \ v" "s2 \ NTimes r (n - 1) \ Stars vs" "flat v \ []" + "\ (\s\<^sub>3 s\<^sub>4. s\<^sub>3 \ [] \ s\<^sub>3 @ s\<^sub>4 = s2 \ s1 @ s\<^sub>3 \ lang r \ s\<^sub>4 \ lang (NTimes r (n - 1 )))" by fact+ + then obtain v' vs' where "v2 = Stars (v' # vs')" "s1 \ r \ v'" "s2 \ (NTimes r (n - 1)) \ (Stars vs')" + apply(cases) apply (auto simp add: append_eq_append_conv2) + using Posix1(1) apply fastforce + apply (metis One_nat_def Posix1(1) Posix_NTimes1.hyps(7) append.right_neutral append_self_conv2) + using Posix1(2) by blast + moreover + have IHs: "\v2. s1 \ r \ v2 \ v = v2" + "\v2. s2 \ NTimes r (n - 1) \ v2 \ Stars vs = v2" by fact+ + ultimately show "Stars (v # vs) = v2" by auto +qed + + +lemma Posix_injval: + assumes "s \ (deriv c r) \ v" + shows "(c # s) \ r \ (injval r c v)" +using assms +proof(induct r arbitrary: s v rule: rexp.induct) + case Zero + have "s \ deriv c Zero \ v" by fact + then have "s \ Zero \ v" by simp + then have "False" by cases + then show "(c # s) \ Zero \ (injval Zero c v)" by simp +next + case One + have "s \ deriv c One \ v" by fact + then have "s \ Zero \ v" by simp + then have "False" by cases + then show "(c # s) \ One \ (injval One c v)" by simp +next + case (Atom d) + consider (eq) "c = d" | (ineq) "c \ d" by blast + then show "(c # s) \ (Atom d) \ (injval (Atom d) c v)" + proof (cases) + case eq + have "s \ deriv c (Atom d) \ v" by fact + then have "s \ One \ v" using eq by simp + then have eqs: "s = [] \ v = Void" by cases simp + show "(c # s) \ Atom d \ injval (Atom d) c v" using eq eqs + by (auto intro: Posix.intros) + next + case ineq + have "s \ deriv c (Atom d) \ v" by fact + then have "s \ Zero \ v" using ineq by simp + then have "False" by cases + then show "(c # s) \ Atom d \ injval (Atom d) c v" by simp + qed +next + case (Plus r1 r2) + have IH1: "\s v. s \ deriv c r1 \ v \ (c # s) \ r1 \ injval r1 c v" by fact + have IH2: "\s v. s \ deriv c r2 \ v \ (c # s) \ r2 \ injval r2 c v" by fact + have "s \ deriv c (Plus r1 r2) \ v" by fact + then have "s \ Plus (deriv c r1) (deriv c r2) \ v" by simp + then consider (left) v' where "v = Left v'" "s \ deriv c r1 \ v'" + | (right) v' where "v = Right v'" "s \ lang (deriv c r1)" "s \ deriv c r2 \ v'" + by cases auto + then show "(c # s) \ Plus r1 r2 \ injval (Plus r1 r2) c v" + proof (cases) + case left + have "s \ deriv c r1 \ v'" by fact + then have "(c # s) \ r1 \ injval r1 c v'" using IH1 by simp + then have "(c # s) \ Plus r1 r2 \ injval (Plus r1 r2) c (Left v')" by (auto intro: Posix.intros) + then show "(c # s) \ Plus r1 r2 \ injval (Plus r1 r2) c v" using left by simp + next + case right + have "s \ lang (deriv c r1)" by fact + then have "c # s \ lang r1" by (simp add: lang_deriv Deriv_def) + moreover + have "s \ deriv c r2 \ v'" by fact + then have "(c # s) \ r2 \ injval r2 c v'" using IH2 by simp + ultimately have "(c # s) \ Plus r1 r2 \ injval (Plus r1 r2) c (Right v')" + by (auto intro: Posix.intros) + then show "(c # s) \ Plus r1 r2 \ injval (Plus r1 r2) c v" using right by simp + qed +next + case (Times r1 r2) + have IH1: "\s v. s \ deriv c r1 \ v \ (c # s) \ r1 \ injval r1 c v" by fact + have IH2: "\s v. s \ deriv c r2 \ v \ (c # s) \ r2 \ injval r2 c v" by fact + have "s \ deriv c (Times r1 r2) \ v" by fact + then consider + (left_nullable) v1 v2 s1 s2 where + "v = Left (Seq v1 v2)" "s = s1 @ s2" + "s1 \ deriv c r1 \ v1" "s2 \ r2 \ v2" "nullable r1" + "\ (\s\<^sub>3 s\<^sub>4. s\<^sub>3 \ [] \ s\<^sub>3 @ s\<^sub>4 = s2 \ s1 @ s\<^sub>3 \ lang (deriv c r1) \ s\<^sub>4 \ lang r2)" + | (right_nullable) v1 s1 s2 where + "v = Right v1" "s = s1 @ s2" + "s \ deriv c r2 \ v1" "nullable r1" "s1 @ s2 \ lang (Times (deriv c r1) r2)" + | (not_nullable) v1 v2 s1 s2 where + "v = Seq v1 v2" "s = s1 @ s2" + "s1 \ deriv c r1 \ v1" "s2 \ r2 \ v2" "\nullable r1" + "\ (\s\<^sub>3 s\<^sub>4. s\<^sub>3 \ [] \ s\<^sub>3 @ s\<^sub>4 = s2 \ s1 @ s\<^sub>3 \ lang (deriv c r1) \ s\<^sub>4 \ lang r2)" + by (force split: if_splits elim!: Posix_elims simp add: lang_deriv Deriv_def) + then show "(c # s) \ Times r1 r2 \ injval (Times r1 r2) c v" + proof (cases) + case left_nullable + have "s1 \ deriv c r1 \ v1" by fact + then have "(c # s1) \ r1 \ injval r1 c v1" using IH1 by simp + moreover + have "\ (\s\<^sub>3 s\<^sub>4. s\<^sub>3 \ [] \ s\<^sub>3 @ s\<^sub>4 = s2 \ s1 @ s\<^sub>3 \ lang (deriv c r1) \ s\<^sub>4 \ lang r2)" by fact + then have "\ (\s\<^sub>3 s\<^sub>4. s\<^sub>3 \ [] \ s\<^sub>3 @ s\<^sub>4 = s2 \ (c # s1) @ s\<^sub>3 \ lang r1 \ s\<^sub>4 \ lang r2)" + by (simp add: lang_deriv Deriv_def) + ultimately have "((c # s1) @ s2) \ Times r1 r2 \ Seq (injval r1 c v1) v2" using left_nullable by (rule_tac Posix.intros) + then show "(c # s) \ Times r1 r2 \ injval (Times r1 r2) c v" using left_nullable by simp + next + case right_nullable + have "nullable r1" by fact + then have "[] \ r1 \ (mkeps r1)" by (rule Posix_mkeps) + moreover + have "s \ deriv c r2 \ v1" by fact + then have "(c # s) \ r2 \ (injval r2 c v1)" using IH2 by simp + moreover + have "s1 @ s2 \ lang (Times (deriv c r1) r2)" by fact + then have "\ (\s\<^sub>3 s\<^sub>4. s\<^sub>3 \ [] \ s\<^sub>3 @ s\<^sub>4 = c # s \ [] @ s\<^sub>3 \ lang r1 \ s\<^sub>4 \ lang r2)" + using right_nullable + apply (auto simp add: lang_deriv Deriv_def append_eq_Cons_conv) + by (metis concI mem_Collect_eq) + ultimately have "([] @ (c # s)) \ Times r1 r2 \ Seq (mkeps r1) (injval r2 c v1)" + by(rule Posix.intros) + then show "(c # s) \ Times r1 r2 \ injval (Times r1 r2) c v" using right_nullable by simp + next + case not_nullable + have "s1 \ deriv c r1 \ v1" by fact + then have "(c # s1) \ r1 \ injval r1 c v1" using IH1 by simp + moreover + have "\ (\s\<^sub>3 s\<^sub>4. s\<^sub>3 \ [] \ s\<^sub>3 @ s\<^sub>4 = s2 \ s1 @ s\<^sub>3 \ lang (deriv c r1) \ s\<^sub>4 \ lang r2)" by fact + then have "\ (\s\<^sub>3 s\<^sub>4. s\<^sub>3 \ [] \ s\<^sub>3 @ s\<^sub>4 = s2 \ (c # s1) @ s\<^sub>3 \ lang r1 \ s\<^sub>4 \ lang r2)" by (simp add: lang_deriv Deriv_def) + ultimately have "((c # s1) @ s2) \ Times r1 r2 \ Seq (injval r1 c v1) v2" using not_nullable + by (rule_tac Posix.intros) (simp_all) + then show "(c # s) \ Times r1 r2 \ injval (Times r1 r2) c v" using not_nullable by simp + qed +next + case (Star r) + have IH: "\s v. s \ deriv c r \ v \ (c # s) \ r \ injval r c v" by fact + have "s \ deriv c (Star r) \ v" by fact + then consider + (cons) v1 vs s1 s2 where + "v = Seq v1 (Stars vs)" "s = s1 @ s2" + "s1 \ deriv c r \ v1" "s2 \ (Star r) \ (Stars vs)" + "\ (\s\<^sub>3 s\<^sub>4. s\<^sub>3 \ [] \ s\<^sub>3 @ s\<^sub>4 = s2 \ s1 @ s\<^sub>3 \ lang (deriv c r) \ s\<^sub>4 \ lang (Star r))" + apply(auto elim!: Posix_elims(1-5) simp add: lang_deriv Deriv_def intro: Posix.intros) + apply(rotate_tac 3) + apply(erule_tac Posix_elims(6)) + apply (simp add: Posix.intros(6)) + using Posix.intros(7) by blast + then show "(c # s) \ Star r \ injval (Star r) c v" + proof (cases) + case cons + have "s1 \ deriv c r \ v1" by fact + then have "(c # s1) \ r \ injval r c v1" using IH by simp + moreover + have "s2 \ Star r \ Stars vs" by fact + moreover + have "(c # s1) \ r \ injval r c v1" by fact + then have "flat (injval r c v1) = (c # s1)" by (rule Posix1) + then have "flat (injval r c v1) \ []" by simp + moreover + have "\ (\s\<^sub>3 s\<^sub>4. s\<^sub>3 \ [] \ s\<^sub>3 @ s\<^sub>4 = s2 \ s1 @ s\<^sub>3 \ lang (deriv c r) \ s\<^sub>4 \ lang (Star r))" by fact + then have "\ (\s\<^sub>3 s\<^sub>4. s\<^sub>3 \ [] \ s\<^sub>3 @ s\<^sub>4 = s2 \ (c # s1) @ s\<^sub>3 \ lang r \ s\<^sub>4 \ lang (Star r))" + by (simp add: lang_deriv Deriv_def) + ultimately + have "((c # s1) @ s2) \ Star r \ Stars (injval r c v1 # vs)" by (rule Posix.intros) + then show "(c # s) \ Star r \ injval (Star r) c v" using cons by(simp) + qed +next + case (NTimes r n) + have IH: "\s v. s \ deriv c r \ v \ (c # s) \ r \ injval r c v" by fact + have "s \ deriv c (NTimes r n) \ v" by fact + then consider + (cons) v1 vs s1 s2 where + "v = Seq v1 (Stars vs)" "s = s1 @ s2" + "s1 \ deriv c r \ v1" "s2 \ (NTimes r (n - 1)) \ (Stars vs)" "0 < n" + "\ (\s\<^sub>3 s\<^sub>4. s\<^sub>3 \ [] \ s\<^sub>3 @ s\<^sub>4 = s2 \ s1 @ s\<^sub>3 \ lang (deriv c r) \ s\<^sub>4 \ lang (NTimes r (n - 1)))" + apply(auto elim: Posix_elims simp add: lang_derivs Deriv_def intro: Posix.intros split: if_splits) + apply(erule Posix_elims) + apply(simp) + apply(subgoal_tac "\vss. v2 = Stars vss") + apply(clarify) + apply(drule_tac x="vss" in meta_spec) + apply(drule_tac x="s1" in meta_spec) + apply(drule_tac x="s2" in meta_spec) + apply(simp add: lang_derivs Deriv_def) + apply(erule Posix_elims) + apply(auto) + done + then show "(c # s) \ (NTimes r n) \ injval (NTimes r n) c v" + proof (cases) + case cons + have "s1 \ deriv c r \ v1" by fact + then have "(c # s1) \ r \ injval r c v1" using IH by simp + moreover + have "s2 \ (NTimes r (n - 1)) \ Stars vs" by fact + moreover + have "(c # s1) \ r \ injval r c v1" by fact + then have "flat (injval r c v1) = (c # s1)" by (rule Posix1) + then have "flat (injval r c v1) \ []" by simp + moreover + have "\ (\s\<^sub>3 s\<^sub>4. s\<^sub>3 \ [] \ s\<^sub>3 @ s\<^sub>4 = s2 \ s1 @ s\<^sub>3 \ lang (deriv c r) \ s\<^sub>4 \ lang (NTimes r (n - 1)))" by fact + then have "\ (\s\<^sub>3 s\<^sub>4. s\<^sub>3 \ [] \ s\<^sub>3 @ s\<^sub>4 = s2 \ (c # s1) @ s\<^sub>3 \ lang r \ s\<^sub>4 \ lang (NTimes r (n - 1)))" + by (simp add: lang_deriv Deriv_def) + ultimately + have "((c # s1) @ s2) \ NTimes r n \ Stars (injval r c v1 # vs)" + apply (rule_tac Posix.intros) + apply(simp_all) + apply(case_tac n) + apply(simp) + using Posix_elims(1) NTimes.prems apply auto[1] + apply(simp) + done + then show "(c # s) \ NTimes r n \ injval (NTimes r n) c v" using cons by(simp) + qed +qed + + +section \The Lexer by Sulzmann and Lu\ + +fun + lexer :: "'a rexp \ 'a list \ ('a val) option" +where + "lexer r [] = (if nullable r then Some(mkeps r) else None)" +| "lexer r (c#s) = (case (lexer (deriv c r) s) of + None \ None + | Some(v) \ Some(injval r c v))" + + +lemma lexer_correct_None: + shows "s \ lang r \ lexer r s = None" +apply(induct s arbitrary: r) +apply(simp add: nullable_iff) +apply(drule_tac x="deriv a r" in meta_spec) +apply(auto simp add: lang_deriv Deriv_def) +done + +lemma lexer_correct_Some: + shows "s \ lang r \ (\v. lexer r s = Some(v) \ s \ r \ v)" +apply(induct s arbitrary: r) +apply(auto simp add: Posix_mkeps nullable_iff)[1] +apply(drule_tac x="deriv a r" in meta_spec) +apply(simp add: lang_deriv Deriv_def) +apply(rule iffI) +apply(auto intro: Posix_injval simp add: Posix1(1)) +done + +lemma lexer_correctness: + shows "(lexer r s = Some v) \ s \ r \ v" + and "(lexer r s = None) \ \(\v. s \ r \ v)" +apply(auto) +using lexer_correct_None lexer_correct_Some apply fastforce +using Posix1(1) Posix_determ lexer_correct_Some apply blast +using Posix1(1) lexer_correct_None apply blast +using lexer_correct_None lexer_correct_Some by blast + + + + +end diff --git a/thys/Posix-Lexing/Extensions/LexicalVals3.thy b/thys/Posix-Lexing/Extensions/LexicalVals3.thy new file mode 100644 --- /dev/null +++ b/thys/Posix-Lexing/Extensions/LexicalVals3.thy @@ -0,0 +1,248 @@ +theory LexicalVals3 + imports Lexer3 "HOL-Library.Sublist" +begin + +section \ Sets of Lexical Values \ + +text \ + Shows that lexical values are finite for a given regex and string. +\ + +definition + LV :: "'a rexp \ 'a list \ ('a val) set" +where "LV r s \ {v. \ v : r \ flat v = s}" + +lemma LV_simps: + shows "LV Zero s = {}" + and "LV One s = (if s = [] then {Void} else {})" + and "LV (Atom c) s = (if s = [c] then {Atm c} else {})" + and "LV (Plus r1 r2) s = Left ` LV r1 s \ Right ` LV r2 s" + and "LV (NTimes r 0) s = (if s = [] then {Stars []} else {})" +unfolding LV_def + apply(auto intro: Prf.intros elim: Prf.cases) + by (simp add: Prf_NTimes_empty) + + +abbreviation + "Prefixes s \ {s'. prefix s' s}" + +abbreviation + "Suffixes s \ {s'. suffix s' s}" + +abbreviation + "SSuffixes s \ {s'. strict_suffix s' s}" + +lemma Suffixes_cons [simp]: + shows "Suffixes (c # s) = Suffixes s \ {c # s}" +by (auto simp add: suffix_def Cons_eq_append_conv) + + +lemma finite_Suffixes: + shows "finite (Suffixes s)" +by (induct s) (simp_all) + +lemma finite_SSuffixes: + shows "finite (SSuffixes s)" +proof - + have "SSuffixes s \ Suffixes s" + unfolding strict_suffix_def suffix_def by auto + then show "finite (SSuffixes s)" + using finite_Suffixes finite_subset by blast +qed + +lemma finite_Prefixes: + shows "finite (Prefixes s)" +proof - + have "finite (Suffixes (rev s))" + by (rule finite_Suffixes) + then have "finite (rev ` Suffixes (rev s))" by simp + moreover + have "rev ` (Suffixes (rev s)) = Prefixes s" + unfolding suffix_def prefix_def image_def + by (auto)(metis rev_append rev_rev_ident)+ + ultimately show "finite (Prefixes s)" by simp +qed + +lemma LV_STAR_finite: + assumes "\s. finite (LV r s)" + shows "finite (LV (Star r) s)" +proof(induct s rule: length_induct) + fix s::"'a list" + assume "\s'. length s' < length s \ finite (LV (Star r) s')" + then have IH: "\s' \ SSuffixes s. finite (LV (Star r) s')" + by (force simp add: strict_suffix_def suffix_def) + define f where "f \ \(v::'a val, vs). Stars (v # vs)" + define S1 where "S1 \ \s' \ Prefixes s. LV r s'" + define S2 where "S2 \ \s2 \ SSuffixes s. Stars -` (LV (Star r) s2)" + have "finite S1" using assms + unfolding S1_def by (simp_all add: finite_Prefixes) + moreover + with IH have "finite S2" unfolding S2_def + by (auto simp add: finite_SSuffixes inj_on_def finite_vimageI) + ultimately + have "finite ({Stars []} \ f ` (S1 \ S2))" by simp + moreover + have "LV (Star r) s \ {Stars []} \ f ` (S1 \ S2)" + unfolding S1_def S2_def f_def + unfolding LV_def image_def prefix_def strict_suffix_def + apply(auto) + apply(case_tac x) + apply(auto elim: Prf_elims) + apply(erule Prf_elims) + apply(auto) + apply(case_tac vs) + apply(auto intro: Prf.intros) + apply(rule exI) + apply(rule conjI) + apply(rule_tac x="flat a" in exI) + apply(rule conjI) + apply(rule_tac x="flats list" in exI) + apply(simp) + apply(blast) + apply(simp add: suffix_def) + using Prf.intros(6) by blast + ultimately + show "finite (LV (Star r) s)" by (simp add: finite_subset) +qed + +definition + "Stars_Append Vs1 Vs2 \ {Stars (vs1 @ vs2) | vs1 vs2. Stars vs1 \ Vs1 \ Stars vs2 \ Vs2}" + +lemma finite_Stars_Append: + assumes "finite Vs1" "finite Vs2" + shows "finite (Stars_Append Vs1 Vs2)" + using assms +proof - + define UVs1 where "UVs1 \ Stars -` Vs1" + define UVs2 where "UVs2 \ Stars -` Vs2" + from assms have "finite UVs1" "finite UVs2" + unfolding UVs1_def UVs2_def + by(simp_all add: finite_vimageI inj_on_def) + then have "finite ((\(vs1, vs2). Stars (vs1 @ vs2)) ` (UVs1 \ UVs2))" + by simp + moreover + have "Stars_Append Vs1 Vs2 = (\(vs1, vs2). Stars (vs1 @ vs2)) ` (UVs1 \ UVs2)" + unfolding Stars_Append_def UVs1_def UVs2_def by auto + ultimately show "finite (Stars_Append Vs1 Vs2)" + by simp +qed + +lemma LV_NTimes_5: + "LV (NTimes r n) s \ Stars_Append (LV (Star r) s) (\i\n. LV (NTimes r i) [])" +apply(auto simp add: LV_def) +apply(auto elim!: Prf_elims) + apply(auto simp add: Stars_Append_def) + apply(rule_tac x="vs1" in exI) + apply(rule_tac x="vs2" in exI) + apply(auto) + using Prf.intros(6) apply(auto) + apply(rule_tac x="length vs2" in bexI) + thm Prf.intros + apply(subst append.simps(1)[symmetric]) + apply(rule Prf.intros) + apply(auto)[1] + apply(auto)[1] + apply(simp) + apply(simp) + done + +lemma LV_NTIMES_3: + shows "LV (NTimes r (Suc n)) [] = + (\(v, vs). Stars (v#vs)) ` (LV r [] \ (Stars -` (LV (NTimes r n) [])))" +unfolding LV_def +apply(auto elim!: Prf_elims simp add: image_def) +apply(case_tac vs1) +apply(auto) +apply(case_tac vs2) +apply(auto) +apply(subst append.simps(1)[symmetric]) +apply(rule Prf.intros) +apply(auto) +apply(subst append.simps(1)[symmetric]) +apply(rule Prf.intros) +apply(auto) + done + +lemma finite_NTimes_empty: + assumes "\s. finite (LV r s)" + shows "finite (LV (NTimes r n) [])" + using assms + apply(induct n) + apply(auto simp add: LV_simps) + apply(subst LV_NTIMES_3) + apply(rule finite_imageI) + apply(rule finite_cartesian_product) + using assms apply simp + apply(rule finite_vimageI) + apply(simp) + apply(simp add: inj_on_def) + done + +lemma LV_finite: + shows "finite (LV r s)" +proof(induct r arbitrary: s) + case (Zero s) + show "finite (LV Zero s)" by (simp add: LV_simps) +next + case (One s) + show "finite (LV One s)" by (simp add: LV_simps) +next + case (Atom c s) + show "finite (LV (Atom c) s)" by (simp add: LV_simps) +next + case (Plus r1 r2 s) + then show "finite (LV (Plus r1 r2) s)" by (simp add: LV_simps) +next + case (Times r1 r2 s) + define f where "f \ \(v1::'a val, v2). Seq v1 v2" + define S1 where "S1 \ \s' \ Prefixes s. LV r1 s'" + define S2 where "S2 \ \s' \ Suffixes s. LV r2 s'" + have IHs: "\s. finite (LV r1 s)" "\s. finite (LV r2 s)" by fact+ + then have "finite S1" "finite S2" unfolding S1_def S2_def + by (simp_all add: finite_Prefixes finite_Suffixes) + moreover + have "LV (Times r1 r2) s \ f ` (S1 \ S2)" + unfolding f_def S1_def S2_def + unfolding LV_def image_def prefix_def suffix_def + apply (auto elim!: Prf_elims) + by (metis (mono_tags, lifting) mem_Collect_eq) + ultimately + show "finite (LV (Times r1 r2) s)" + by (simp add: finite_subset) +next + case (Star r s) + then show "finite (LV (Star r) s)" by (simp add: LV_STAR_finite) +next + case (NTimes r n s) + have "\s. finite (LV r s)" by fact + then have "finite (Stars_Append (LV (Star r) s) (\i\n. LV (NTimes r i) []))" + apply(rule_tac finite_Stars_Append) + apply (simp add: LV_STAR_finite) + using finite_NTimes_empty by blast + then show "finite (LV (NTimes r n) s)" + by (metis LV_NTimes_5 finite_subset) +qed + + + +text \ + Our POSIX values are lexical values. +\ + +lemma Posix_LV: + assumes "s \ r \ v" + shows "v \ LV r s" + using assms unfolding LV_def + apply(induct rule: Posix.induct) + apply(auto simp add: intro!: Prf.intros elim!: Prf_elims Posix1a) + apply (smt (verit, best) One_nat_def Posix1a Posix_NTimes1 lang.simps(7)) + using Prf_NTimes_empty by blast + +lemma Posix_Prf: + assumes "s \ r \ v" + shows "\ v : r" + using assms Posix_LV LV_def + by blast + + +end \ No newline at end of file diff --git a/thys/Posix-Lexing/Extensions/Positions3.thy b/thys/Posix-Lexing/Extensions/Positions3.thy new file mode 100644 --- /dev/null +++ b/thys/Posix-Lexing/Extensions/Positions3.thy @@ -0,0 +1,861 @@ + +theory Positions3 + imports Lexer3 LexicalVals3 +begin + +section \An alternative definition for POSIX values by Okui \& Suzuki\ + +section \Positions in Values\ + +fun + at :: "'a val \ nat list \ 'a val" +where + "at v [] = v" +| "at (Left v) (0#ps)= at v ps" +| "at (Right v) (Suc 0#ps)= at v ps" +| "at (Seq v1 v2) (0#ps)= at v1 ps" +| "at (Seq v1 v2) (Suc 0#ps)= at v2 ps" +| "at (Stars vs) (n#ps)= at (nth vs n) ps" + + + +fun Pos :: "'a val \ (nat list) set" +where + "Pos (Void) = {[]}" +| "Pos (Atm c) = {[]}" +| "Pos (Left v) = {[]} \ {0#ps | ps. ps \ Pos v}" +| "Pos (Right v) = {[]} \ {1#ps | ps. ps \ Pos v}" +| "Pos (Seq v1 v2) = {[]} \ {0#ps | ps. ps \ Pos v1} \ {1#ps | ps. ps \ Pos v2}" +| "Pos (Stars []) = {[]}" +| "Pos (Stars (v#vs)) = {[]} \ {0#ps | ps. ps \ Pos v} \ {Suc n#ps | n ps. n#ps \ Pos (Stars vs)}" + + +lemma Pos_stars: + "Pos (Stars vs) = {[]} \ (\n < length vs. {n#ps | ps. ps \ Pos (vs ! n)})" +apply(induct vs) +apply(auto simp add: insert_ident less_Suc_eq_0_disj) +done + +lemma Pos_empty: + shows "[] \ Pos v" +by (induct v rule: Pos.induct)(auto) + + +abbreviation + "intlen vs \ int (length vs)" + + +definition pflat_len :: "'a val \ nat list => int" +where + "pflat_len v p \ (if p \ Pos v then intlen (flat (at v p)) else -1)" + +lemma pflat_len_simps: + shows "pflat_len (Seq v1 v2) (0#p) = pflat_len v1 p" + and "pflat_len (Seq v1 v2) (Suc 0#p) = pflat_len v2 p" + and "pflat_len (Left v) (0#p) = pflat_len v p" + and "pflat_len (Left v) (Suc 0#p) = -1" + and "pflat_len (Right v) (Suc 0#p) = pflat_len v p" + and "pflat_len (Right v) (0#p) = -1" + and "pflat_len (Stars (v#vs)) (Suc n#p) = pflat_len (Stars vs) (n#p)" + and "pflat_len (Stars (v#vs)) (0#p) = pflat_len v p" + and "pflat_len v [] = intlen (flat v)" +by (auto simp add: pflat_len_def Pos_empty) + +lemma pflat_len_Stars_simps: + assumes "n < length vs" + shows "pflat_len (Stars vs) (n#p) = pflat_len (vs!n) p" +using assms +apply(induct vs arbitrary: n p) +apply(auto simp add: less_Suc_eq_0_disj pflat_len_simps) +done + +lemma pflat_len_outside: + assumes "p \ Pos v1" + shows "pflat_len v1 p = -1 " +using assms by (simp add: pflat_len_def) + + + +section \Orderings\ + + +definition prefix_list:: "'a list \ 'a list \ bool" ("_ \pre _" [60,59] 60) +where + "ps1 \pre ps2 \ \ps'. ps1 @ps' = ps2" + +definition sprefix_list:: "'a list \ 'a list \ bool" ("_ \spre _" [60,59] 60) +where + "ps1 \spre ps2 \ ps1 \pre ps2 \ ps1 \ ps2" + +inductive lex_list :: "nat list \ nat list \ bool" ("_ \lex _" [60,59] 60) +where + "[] \lex (p#ps)" +| "ps1 \lex ps2 \ (p#ps1) \lex (p#ps2)" +| "p1 < p2 \ (p1#ps1) \lex (p2#ps2)" + +lemma lex_irrfl: + fixes ps1 ps2 :: "nat list" + assumes "ps1 \lex ps2" + shows "ps1 \ ps2" +using assms +by(induct rule: lex_list.induct)(auto) + +lemma lex_simps [simp]: + fixes xs ys :: "nat list" + shows "[] \lex ys \ ys \ []" + and "xs \lex [] \ False" + and "(x # xs) \lex (y # ys) \ (x < y \ (x = y \ xs \lex ys))" +by (auto simp add: neq_Nil_conv elim: lex_list.cases intro: lex_list.intros) + +lemma lex_trans: + fixes ps1 ps2 ps3 :: "nat list" + assumes "ps1 \lex ps2" "ps2 \lex ps3" + shows "ps1 \lex ps3" +using assms +by (induct arbitrary: ps3 rule: lex_list.induct) + (auto elim: lex_list.cases) + + +lemma lex_trichotomous: + fixes p q :: "nat list" + shows "p = q \ p \lex q \ q \lex p" +apply(induct p arbitrary: q) +apply(auto elim: lex_list.cases) +apply(case_tac q) +apply(auto) +done + + + + +section \POSIX Ordering of Values According to Okui \& Suzuki\ + + +definition PosOrd:: "'a val \ nat list \ 'a val \ bool" ("_ \val _ _" [60, 60, 59] 60) +where + "v1 \val p v2 \ pflat_len v1 p > pflat_len v2 p \ + (\q \ Pos v1 \ Pos v2. q \lex p \ pflat_len v1 q = pflat_len v2 q)" + +lemma PosOrd_def2: + shows "v1 \val p v2 \ + pflat_len v1 p > pflat_len v2 p \ + (\q \ Pos v1. q \lex p \ pflat_len v1 q = pflat_len v2 q) \ + (\q \ Pos v2. q \lex p \ pflat_len v1 q = pflat_len v2 q)" +unfolding PosOrd_def +apply(auto) +done + + +definition PosOrd_ex:: "'a val \ 'a val \ bool" ("_ :\val _" [60, 59] 60) +where + "v1 :\val v2 \ \p. v1 \val p v2" + +definition PosOrd_ex_eq:: "'a val \ 'a val \ bool" ("_ :\val _" [60, 59] 60) +where + "v1 :\val v2 \ v1 :\val v2 \ v1 = v2" + + +lemma PosOrd_trans: + assumes "v1 :\val v2" "v2 :\val v3" + shows "v1 :\val v3" +proof - + from assms obtain p p' + where as: "v1 \val p v2" "v2 \val p' v3" unfolding PosOrd_ex_def by blast + then have pos: "p \ Pos v1" "p' \ Pos v2" unfolding PosOrd_def pflat_len_def + by (smt not_int_zless_negative)+ + have "p = p' \ p \lex p' \ p' \lex p" + by (rule lex_trichotomous) + moreover + { assume "p = p'" + with as have "v1 \val p v3" unfolding PosOrd_def pflat_len_def + by (smt Un_iff) + then have " v1 :\val v3" unfolding PosOrd_ex_def by blast + } + moreover + { assume "p \lex p'" + with as have "v1 \val p v3" unfolding PosOrd_def pflat_len_def + by (smt Un_iff lex_trans) + then have " v1 :\val v3" unfolding PosOrd_ex_def by blast + } + moreover + { assume "p' \lex p" + with as have "v1 \val p' v3" unfolding PosOrd_def + by (smt Un_iff lex_trans pflat_len_def) + then have "v1 :\val v3" unfolding PosOrd_ex_def by blast + } + ultimately show "v1 :\val v3" by blast +qed + +lemma PosOrd_irrefl: + assumes "v :\val v" + shows "False" +using assms unfolding PosOrd_ex_def PosOrd_def +by auto + +lemma PosOrd_assym: + assumes "v1 :\val v2" + shows "\(v2 :\val v1)" +using assms +using PosOrd_irrefl PosOrd_trans by blast + +(* + :\val and :\val are partial orders. +*) + +lemma PosOrd_ordering: + shows "ordering (\v1 v2. v1 :\val v2) (\ v1 v2. v1 :\val v2)" +unfolding ordering_def PosOrd_ex_eq_def +apply(auto) +using PosOrd_trans partial_preordering_def apply blast +using PosOrd_assym ordering_axioms_def by blast + +lemma PosOrd_order: + shows "class.order (\v1 v2. v1 :\val v2) (\ v1 v2. v1 :\val v2)" + using PosOrd_ordering + apply(simp add: class.order_def class.preorder_def class.order_axioms_def) + by (smt (verit) PosOrd_ex_eq_def PosOrd_irrefl PosOrd_trans) + + +lemma PosOrd_ex_eq2: + shows "v1 :\val v2 \ (v1 :\val v2 \ v1 \ v2)" + using PosOrd_ordering + using PosOrd_ex_eq_def PosOrd_irrefl by blast + +lemma PosOrdeq_trans: + assumes "v1 :\val v2" "v2 :\val v3" + shows "v1 :\val v3" +using assms PosOrd_ordering + unfolding ordering_def + by (metis partial_preordering.trans) + +lemma PosOrdeq_antisym: + assumes "v1 :\val v2" "v2 :\val v1" + shows "v1 = v2" +using assms PosOrd_ordering + by (metis ordering.eq_iff) + +lemma PosOrdeq_refl: + shows "v :\val v" +unfolding PosOrd_ex_eq_def +by auto + + +lemma PosOrd_shorterE: + assumes "v1 :\val v2" + shows "length (flat v2) \ length (flat v1)" +using assms unfolding PosOrd_ex_def PosOrd_def +apply(auto) +apply(case_tac p) +apply(simp add: pflat_len_simps) +apply(drule_tac x="[]" in bspec) +apply(simp add: Pos_empty) +apply(simp add: pflat_len_simps) +done + +lemma PosOrd_shorterI: + assumes "length (flat v2) < length (flat v1)" + shows "v1 :\val v2" +unfolding PosOrd_ex_def PosOrd_def pflat_len_def +using assms Pos_empty by force + +lemma PosOrd_spreI: + assumes "flat v' \spre flat v" + shows "v :\val v'" +using assms +apply(rule_tac PosOrd_shorterI) +unfolding prefix_list_def sprefix_list_def +by (metis append_Nil2 append_eq_conv_conj drop_all le_less_linear) + +lemma pflat_len_inside: + assumes "pflat_len v2 p < pflat_len v1 p" + shows "p \ Pos v1" +using assms +unfolding pflat_len_def +by (auto split: if_splits) + + +lemma PosOrd_Left_Right: + assumes "flat v1 = flat v2" + shows "Left v1 :\val Right v2" +unfolding PosOrd_ex_def +apply(rule_tac x="[0]" in exI) +apply(auto simp add: PosOrd_def pflat_len_simps assms) +done + +lemma PosOrd_LeftE: + assumes "Left v1 :\val Left v2" "flat v1 = flat v2" + shows "v1 :\val v2" +using assms +unfolding PosOrd_ex_def PosOrd_def2 +apply(auto simp add: pflat_len_simps) +apply(frule pflat_len_inside) +apply(auto simp add: pflat_len_simps) +by (metis lex_simps(3) pflat_len_simps(3)) + +lemma PosOrd_LeftI: + assumes "v1 :\val v2" "flat v1 = flat v2" + shows "Left v1 :\val Left v2" +using assms +unfolding PosOrd_ex_def PosOrd_def2 +apply(auto simp add: pflat_len_simps) +by (metis less_numeral_extra(3) lex_simps(3) pflat_len_simps(3)) + +lemma PosOrd_Left_eq: + assumes "flat v1 = flat v2" + shows "Left v1 :\val Left v2 \ v1 :\val v2" +using assms PosOrd_LeftE PosOrd_LeftI +by blast + + +lemma PosOrd_RightE: + assumes "Right v1 :\val Right v2" "flat v1 = flat v2" + shows "v1 :\val v2" +using assms +unfolding PosOrd_ex_def PosOrd_def2 +apply(auto simp add: pflat_len_simps) +apply(frule pflat_len_inside) +apply(auto simp add: pflat_len_simps) +by (metis lex_simps(3) pflat_len_simps(5)) + +lemma PosOrd_RightI: + assumes "v1 :\val v2" "flat v1 = flat v2" + shows "Right v1 :\val Right v2" +using assms +unfolding PosOrd_ex_def PosOrd_def2 +apply(auto simp add: pflat_len_simps) +by (metis lex_simps(3) nat_neq_iff pflat_len_simps(5)) + + +lemma PosOrd_Right_eq: + assumes "flat v1 = flat v2" + shows "Right v1 :\val Right v2 \ v1 :\val v2" +using assms PosOrd_RightE PosOrd_RightI +by blast + + +lemma PosOrd_SeqI1: + assumes "v1 :\val w1" "flat (Seq v1 v2) = flat (Seq w1 w2)" + shows "Seq v1 v2 :\val Seq w1 w2" +using assms(1) +apply(subst (asm) PosOrd_ex_def) +apply(subst (asm) PosOrd_def) +apply(clarify) +apply(subst PosOrd_ex_def) +apply(rule_tac x="0#p" in exI) +apply(subst PosOrd_def) +apply(rule conjI) +apply(simp add: pflat_len_simps) +apply(rule ballI) +apply(rule impI) +apply(simp only: Pos.simps) +apply(auto)[1] +apply(simp add: pflat_len_simps) +apply(auto simp add: pflat_len_simps) +using assms(2) +apply(simp) +apply(metis length_append of_nat_add) +done + +lemma PosOrd_SeqI2: + assumes "v2 :\val w2" "flat v2 = flat w2" + shows "Seq v v2 :\val Seq v w2" +using assms(1) +apply(subst (asm) PosOrd_ex_def) +apply(subst (asm) PosOrd_def) +apply(clarify) +apply(subst PosOrd_ex_def) +apply(rule_tac x="Suc 0#p" in exI) +apply(subst PosOrd_def) +apply(rule conjI) +apply(simp add: pflat_len_simps) +apply(rule ballI) +apply(rule impI) +apply(simp only: Pos.simps) +apply(auto)[1] +apply(simp add: pflat_len_simps) +using assms(2) +apply(simp) +apply(auto simp add: pflat_len_simps) +done + +lemma PosOrd_Seq_eq: + assumes "flat v2 = flat w2" + shows "(Seq v v2) :\val (Seq v w2) \ v2 :\val w2" +using assms +apply(auto) +prefer 2 +apply(simp add: PosOrd_SeqI2) +apply(simp add: PosOrd_ex_def) +apply(auto) +apply(case_tac p) +apply(simp add: PosOrd_def pflat_len_simps) +apply(case_tac a) +apply(simp add: PosOrd_def pflat_len_simps) +apply(clarify) +apply(case_tac nat) +prefer 2 +apply(simp add: PosOrd_def pflat_len_simps pflat_len_outside) +apply(rule_tac x="list" in exI) +apply(auto simp add: PosOrd_def2 pflat_len_simps) +apply(smt Collect_disj_eq lex_list.intros(2) mem_Collect_eq pflat_len_simps(2)) +apply(smt Collect_disj_eq lex_list.intros(2) mem_Collect_eq pflat_len_simps(2)) +done + + + +lemma PosOrd_StarsI: + assumes "v1 :\val v2" "flats (v1#vs1) = flats (v2#vs2)" + shows "Stars (v1#vs1) :\val Stars (v2#vs2)" +using assms(1) +apply(subst (asm) PosOrd_ex_def) +apply(subst (asm) PosOrd_def) +apply(clarify) +apply(subst PosOrd_ex_def) +apply(subst PosOrd_def) +apply(rule_tac x="0#p" in exI) +apply(simp add: pflat_len_Stars_simps pflat_len_simps) +using assms(2) +apply(simp add: pflat_len_simps) +apply(auto simp add: pflat_len_Stars_simps pflat_len_simps) +by (metis length_append of_nat_add) + +lemma PosOrd_StarsI2: + assumes "Stars vs1 :\val Stars vs2" "flats vs1 = flats vs2" + shows "Stars (v#vs1) :\val Stars (v#vs2)" +using assms(1) +apply(subst (asm) PosOrd_ex_def) +apply(subst (asm) PosOrd_def) +apply(clarify) +apply(subst PosOrd_ex_def) +apply(subst PosOrd_def) +apply(case_tac p) +apply(simp add: pflat_len_simps) +apply(rule_tac x="Suc a#list" in exI) +apply(auto simp add: pflat_len_Stars_simps pflat_len_simps assms(2)) +done + +lemma PosOrd_Stars_appendI: + assumes "Stars vs1 :\val Stars vs2" "flat (Stars vs1) = flat (Stars vs2)" + shows "Stars (vs @ vs1) :\val Stars (vs @ vs2)" +using assms +apply(induct vs) +apply(simp) +apply(simp add: PosOrd_StarsI2) +done + +lemma PosOrd_StarsE2: + assumes "Stars (v # vs1) :\val Stars (v # vs2)" + shows "Stars vs1 :\val Stars vs2" +using assms +apply(subst (asm) PosOrd_ex_def) +apply(erule exE) +apply(case_tac p) +apply(simp) +apply(simp add: PosOrd_def pflat_len_simps) +apply(subst PosOrd_ex_def) +apply(rule_tac x="[]" in exI) +apply(simp add: PosOrd_def pflat_len_simps Pos_empty) +apply(simp) +apply(case_tac a) +apply(clarify) +apply(auto simp add: pflat_len_simps PosOrd_def pflat_len_def split: if_splits)[1] +apply(clarify) +apply(simp add: PosOrd_ex_def) +apply(rule_tac x="nat#list" in exI) +apply(auto simp add: PosOrd_def pflat_len_simps)[1] +apply(case_tac q) +apply(simp add: PosOrd_def pflat_len_simps) +apply(clarify) +apply(drule_tac x="Suc a # lista" in bspec) +apply(simp) +apply(auto simp add: PosOrd_def pflat_len_simps)[1] +apply(case_tac q) +apply(simp add: PosOrd_def pflat_len_simps) +apply(clarify) +apply(drule_tac x="Suc a # lista" in bspec) +apply(simp) +apply(auto simp add: PosOrd_def pflat_len_simps)[1] +done + +lemma PosOrd_Stars_appendE: + assumes "Stars (vs @ vs1) :\val Stars (vs @ vs2)" + shows "Stars vs1 :\val Stars vs2" +using assms +apply(induct vs) +apply(simp) +apply(simp add: PosOrd_StarsE2) +done + +lemma PosOrd_Stars_append_eq: + assumes "flats vs1 = flats vs2" + shows "Stars (vs @ vs1) :\val Stars (vs @ vs2) \ Stars vs1 :\val Stars vs2" +using assms +apply(rule_tac iffI) +apply(erule PosOrd_Stars_appendE) +apply(rule PosOrd_Stars_appendI) +apply(auto) + done + +lemma PosOrd_Stars_equalsI: + assumes "flats vs1 = flats vs2" "length vs1 = length vs2" + and "list_all2 (\v1 v2. v1 :\val v2) vs1 vs2" + shows "Stars vs1 :\val Stars vs2" + using assms(3) assms(2,1) + apply(induct rule: list_all2_induct) + apply (simp add: PosOrdeq_refl) + apply(case_tac "Stars (x # xs) = Stars (y # ys)") + apply (simp add: PosOrdeq_refl) + apply(case_tac "x = y") + apply(subgoal_tac "Stars xs :\val Stars ys") + apply (simp add: PosOrd_StarsI2 PosOrd_ex_eq_def) + apply (simp add: PosOrd_ex_eq2) + by (meson PosOrd_StarsI PosOrd_ex_eq_def) + +lemma PosOrd_almost_trichotomous: + shows "v1 :\val v2 \ v2 :\val v1 \ (length (flat v1) = length (flat v2))" +apply(auto simp add: PosOrd_ex_def) +apply(auto simp add: PosOrd_def) +apply(rule_tac x="[]" in exI) +apply(auto simp add: Pos_empty pflat_len_simps) +apply(drule_tac x="[]" in spec) +apply(auto simp add: Pos_empty pflat_len_simps) +done + + +section \The Posix Value is smaller than any other lexical value\ + + +lemma Posix_PosOrd: + assumes "s \ r \ v1" "v2 \ LV r s" + shows "v1 :\val v2" +using assms +proof (induct arbitrary: v2 rule: Posix.induct) + case (Posix_One v) + have "v \ LV One []" by fact + then have "v = Void" + by (simp add: LV_simps) + then show "Void :\val v" + by (simp add: PosOrd_ex_eq_def) +next + case (Posix_Atom c v) + have "v \ LV (Atom c) [c]" by fact + then have "v = Atm c" + by (simp add: LV_simps) + then show "Atm c :\val v" + by (simp add: PosOrd_ex_eq_def) +next + case (Posix_Plus1 s r1 v r2 v2) + have as1: "s \ r1 \ v" by fact + have IH: "\v2. v2 \ LV r1 s \ v :\val v2" by fact + have "v2 \ LV (Plus r1 r2) s" by fact + then have "\ v2 : Plus r1 r2" "flat v2 = s" + by(auto simp add: LV_def prefix_list_def) + then consider + (Left) v3 where "v2 = Left v3" "\ v3 : r1" "flat v3 = s" + | (Right) v3 where "v2 = Right v3" "\ v3 : r2" "flat v3 = s" + by (auto elim: Prf.cases) + then show "Left v :\val v2" + proof(cases) + case (Left v3) + have "v3 \ LV r1 s" using Left(2,3) + by (auto simp add: LV_def prefix_list_def) + with IH have "v :\val v3" by simp + moreover + have "flat v3 = flat v" using as1 Left(3) + by (simp add: Posix1(2)) + ultimately have "Left v :\val Left v3" + by (simp add: PosOrd_ex_eq_def PosOrd_Left_eq) + then show "Left v :\val v2" unfolding Left . + next + case (Right v3) + have "flat v3 = flat v" using as1 Right(3) + by (simp add: Posix1(2)) + then have "Left v :\val Right v3" + unfolding PosOrd_ex_eq_def + by (simp add: PosOrd_Left_Right) + then show "Left v :\val v2" unfolding Right . + qed +next + case (Posix_Plus2 s r2 v r1 v2) + have as1: "s \ r2 \ v" by fact + have as2: "s \ lang r1" by fact + have IH: "\v2. v2 \ LV r2 s \ v :\val v2" by fact + have "v2 \ LV (Plus r1 r2) s" by fact + then have "\ v2 : Plus r1 r2" "flat v2 = s" + by(auto simp add: LV_def prefix_list_def) + then consider + (Left) v3 where "v2 = Left v3" "\ v3 : r1" "flat v3 = s" + | (Right) v3 where "v2 = Right v3" "\ v3 : r2" "flat v3 = s" + by (auto elim: Prf.cases) + then show "Right v :\val v2" + proof (cases) + case (Right v3) + have "v3 \ LV r2 s" using Right(2,3) + by (auto simp add: LV_def prefix_list_def) + with IH have "v :\val v3" by simp + moreover + have "flat v3 = flat v" using as1 Right(3) + by (simp add: Posix1(2)) + ultimately have "Right v :\val Right v3" + by (auto simp add: PosOrd_ex_eq_def PosOrd_RightI) + then show "Right v :\val v2" unfolding Right . + next + case (Left v3) + have "v3 \ LV r1 s" using Left(2,3) as2 + by (auto simp add: LV_def prefix_list_def) + then have "flat v3 = flat v \ \ v3 : r1" using as1 Left(3) + by (simp add: Posix1(2) LV_def) + then have "False" using as1 as2 Left + using Prf_flat_lang by blast + then show "Right v :\val v2" by simp + qed +next + case (Posix_Times s1 r1 v1 s2 r2 v2 v3) + have "s1 \ r1 \ v1" "s2 \ r2 \ v2" by fact+ + then have as1: "s1 = flat v1" "s2 = flat v2" by (simp_all add: Posix1(2)) + have IH1: "\v3. v3 \ LV r1 s1 \ v1 :\val v3" by fact + have IH2: "\v3. v3 \ LV r2 s2 \ v2 :\val v3" by fact + have cond: "\ (\s\<^sub>3 s\<^sub>4. s\<^sub>3 \ [] \ s\<^sub>3 @ s\<^sub>4 = s2 \ s1 @ s\<^sub>3 \ lang r1 \ s\<^sub>4 \ lang r2)" by fact + have "v3 \ LV (Times r1 r2) (s1 @ s2)" by fact + then obtain v3a v3b where eqs: + "v3 = Seq v3a v3b" "\ v3a : r1" "\ v3b : r2" + "flat v3a @ flat v3b = s1 @ s2" + by (force simp add: prefix_list_def LV_def elim: Prf.cases) + with cond have "flat v3a \pre s1" unfolding prefix_list_def + by (smt Prf_flat_lang append_eq_append_conv2 append_self_conv) + then have "flat v3a \spre s1 \ (flat v3a = s1 \ flat v3b = s2)" using eqs + by (simp add: sprefix_list_def append_eq_conv_conj) + then have q2: "v1 :\val v3a \ (flat v3a = s1 \ flat v3b = s2)" + using PosOrd_spreI as1(1) eqs by blast + then have "v1 :\val v3a \ (v3a \ LV r1 s1 \ v3b \ LV r2 s2)" using eqs(2,3) + by (auto simp add: LV_def) + then have "v1 :\val v3a \ (v1 :\val v3a \ v2 :\val v3b)" using IH1 IH2 by blast + then have "Seq v1 v2 :\val Seq v3a v3b" using eqs q2 as1 + unfolding PosOrd_ex_eq_def by (auto simp add: PosOrd_SeqI1 PosOrd_Seq_eq) + then show "Seq v1 v2 :\val v3" unfolding eqs by blast +next + case (Posix_Star1 s1 r v s2 vs v3) + have "s1 \ r \ v" "s2 \ Star r \ Stars vs" by fact+ + then have as1: "s1 = flat v" "s2 = flat (Stars vs)" by (auto dest: Posix1(2)) + have IH1: "\v3. v3 \ LV r s1 \ v :\val v3" by fact + have IH2: "\v3. v3 \ LV (Star r) s2 \ Stars vs :\val v3" by fact + have cond: "\ (\s\<^sub>3 s\<^sub>4. s\<^sub>3 \ [] \ s\<^sub>3 @ s\<^sub>4 = s2 \ s1 @ s\<^sub>3 \ lang r \ s\<^sub>4 \ lang (Star r))" by fact + have cond2: "flat v \ []" by fact + have "v3 \ LV (Star r) (s1 @ s2)" by fact + then consider + (NonEmpty) v3a vs3 where "v3 = Stars (v3a # vs3)" + "\ v3a : r" "\ Stars vs3 : Star r" + "flat (Stars (v3a # vs3)) = s1 @ s2" + | (Empty) "v3 = Stars []" + unfolding LV_def + apply(auto) + apply(erule Prf_elims) + by (metis NonEmpty Prf.intros(6) list.set_intros(1) list.set_intros(2) neq_Nil_conv) + then show "Stars (v # vs) :\val v3" + proof (cases) + case (NonEmpty v3a vs3) + have "flat (Stars (v3a # vs3)) = s1 @ s2" using NonEmpty(4) . + with cond have "flat v3a \pre s1" using NonEmpty(2,3) + unfolding prefix_list_def + by (smt Prf_flat_lang append_Nil2 append_eq_append_conv2 flat.simps(7)) + then have "flat v3a \spre s1 \ (flat v3a = s1 \ flat (Stars vs3) = s2)" using NonEmpty(4) + by (simp add: sprefix_list_def append_eq_conv_conj) + then have q2: "v :\val v3a \ (flat v3a = s1 \ flat (Stars vs3) = s2)" + using PosOrd_spreI as1(1) NonEmpty(4) by blast + then have "v :\val v3a \ (v3a \ LV r s1 \ Stars vs3 \ LV (Star r) s2)" + using NonEmpty(2,3) by (auto simp add: LV_def) + then have "v :\val v3a \ (v :\val v3a \ Stars vs :\val Stars vs3)" using IH1 IH2 by blast + then have "v :\val v3a \ (v = v3a \ Stars vs :\val Stars vs3)" + unfolding PosOrd_ex_eq_def by auto + then have "Stars (v # vs) :\val Stars (v3a # vs3)" using NonEmpty(4) q2 as1 + unfolding PosOrd_ex_eq_def + using PosOrd_StarsI PosOrd_StarsI2 + by (metis flat.simps(7) flat_Stars val.inject(5)) + then show "Stars (v # vs) :\val v3" unfolding NonEmpty by blast + next + case Empty + have "v3 = Stars []" by fact + then show "Stars (v # vs) :\val v3" + unfolding PosOrd_ex_eq_def using cond2 + by (simp add: PosOrd_shorterI) + qed +next + case (Posix_Star2 r v2) + have "v2 \ LV (Star r) []" by fact + then have "v2 = Stars []" + unfolding LV_def by (auto elim: Prf.cases) + then show "Stars [] :\val v2" + by (simp add: PosOrd_ex_eq_def) +next + case (Posix_NTimes2 vs r n v2) + have IH: "\v\set vs. [] \ r \ v \ (\x. x \ LV r [] \ v :\val x)" by fact + then have "flats vs = []" + by (metis Posix.Posix_NTimes2 Posix1(2) flat_Stars) + have "v2 \ LV (NTimes r n) []" by fact + then obtain vs' where eq: "v2 = Stars vs'" and "length vs' = n" and as: "\v \ set vs'. v \ LV r [] \ flat v = []" + unfolding LV_def by (auto elim!: Prf_elims) + then have "Stars vs :\val Stars vs'" + apply(rule_tac PosOrd_Stars_equalsI) + apply (simp add: \flats vs = []\) + using Posix_NTimes2.hyps(2) apply blast + using IH apply(simp add: list_all2_iff) + apply(auto) + using Posix_NTimes2.hyps(2) apply blast + by (meson in_set_zipE) + then show "Stars vs :\val v2" using eq by simp +next + case (Posix_NTimes1 s1 r v s2 n vs) + have "s1 \ r \ v" "s2 \ NTimes r (n - 1) \ Stars vs" by fact+ + then have as1: "s1 = flat v" "s2 = flat (Stars vs)" by (auto dest: Posix1(2)) + have IH1: "\v3. v3 \ LV r s1 \ v :\val v3" by fact + have IH2: "\v3. v3 \ LV (NTimes r (n - 1)) s2 \ Stars vs :\val v3" by fact + have cond: "\ (\s\<^sub>3 s\<^sub>4. s\<^sub>3 \ [] \ s\<^sub>3 @ s\<^sub>4 = s2 \ s1 @ s\<^sub>3 \ lang r \ s\<^sub>4 \ lang (NTimes r (n - 1)))" by fact + have cond2: "flat v \ []" by fact + have "v2 \ LV (NTimes r n) (s1 @ s2)" by fact + then consider + (NonEmpty) v3a vs3 where "v2 = Stars (v3a # vs3)" + "\ v3a : r" "\ Stars vs3 : NTimes r (n - 1)" + "flat (Stars (v3a # vs3)) = s1 @ s2" + | (Empty) "v2 = Stars []" + unfolding LV_def + apply(auto) + apply(erule Prf_elims) + apply(case_tac vs1) + apply(simp) + defer + apply(simp) + using Prf.simps apply fastforce + by (simp add: Aux as1(1) cond2) + then show "Stars (v # vs) :\val v2" + proof (cases) + case (NonEmpty v3a vs3) + have "flat (Stars (v3a # vs3)) = s1 @ s2" using NonEmpty(4) . + with cond have "flat v3a \pre s1" using NonEmpty(2,3) + unfolding prefix_list_def + by (smt Prf_flat_lang append_Nil2 append_eq_append_conv2 flat.simps(7)) + then have "flat v3a \spre s1 \ (flat v3a = s1 \ flat (Stars vs3) = s2)" using NonEmpty(4) + by (simp add: sprefix_list_def append_eq_conv_conj) + then have q2: "v :\val v3a \ (flat v3a = s1 \ flat (Stars vs3) = s2)" + using PosOrd_spreI as1(1) NonEmpty(4) by blast + then have "v :\val v3a \ (v3a \ LV r s1 \ Stars vs3 \ LV (NTimes r (n - 1)) s2)" + using NonEmpty(2,3) by (auto simp add: LV_def) + then have "v :\val v3a \ (v :\val v3a \ Stars vs :\val Stars vs3)" using IH1 IH2 by blast + then have "v :\val v3a \ (v = v3a \ Stars vs :\val Stars vs3)" + unfolding PosOrd_ex_eq_def by auto + then have "Stars (v # vs) :\val Stars (v3a # vs3)" using NonEmpty(4) q2 as1 + unfolding PosOrd_ex_eq_def + using PosOrd_StarsI PosOrd_StarsI2 + by (metis flat.simps(7) flat_Stars val.inject(5)) + then show "Stars (v # vs) :\val v2" unfolding NonEmpty by blast + next + case Empty + have "v2 = Stars []" by fact + then show "Stars (v # vs) :\val v2" + unfolding PosOrd_ex_eq_def using cond2 + by (simp add: PosOrd_shorterI) + qed +qed + + +lemma Posix_PosOrd_reverse: + assumes "s \ r \ v1" + shows "\(\v2 \ LV r s. v2 :\val v1)" +using assms +by (metis Posix_PosOrd less_irrefl PosOrd_def + PosOrd_ex_eq_def PosOrd_ex_def PosOrd_trans) + +lemma PosOrd_Posix: + assumes "v1 \ LV r s" "\v\<^sub>2 \ LV r s. \ v\<^sub>2 :\val v1" + shows "s \ r \ v1" +proof - + have "s \ lang r" using assms(1) unfolding LV_def + using Prf_flat_lang by blast + then obtain vposix where vp: "s \ r \ vposix" + using lexer_correct_Some by blast + with assms(1) have "vposix :\val v1" by (simp add: Posix_PosOrd) + then have "vposix = v1 \ vposix :\val v1" unfolding PosOrd_ex_eq2 by auto + moreover + { assume "vposix :\val v1" + moreover + have "vposix \ LV r s" using vp + using Posix_LV by blast + ultimately have "False" using assms(2) by blast + } + ultimately show "s \ r \ v1" using vp by blast +qed + +lemma Least_existence: + assumes "LV r s \ {}" + shows " \vmin \ LV r s. \v \ LV r s. vmin :\val v" +proof - + from assms + obtain vposix where "s \ r \ vposix" + unfolding LV_def + using Prf_flat_lang lexer_correct_Some by blast + then have "\v \ LV r s. vposix :\val v" + by (simp add: Posix_PosOrd) + then show "\vmin \ LV r s. \v \ LV r s. vmin :\val v" + using Posix_LV \s \ r \ vposix\ by blast +qed + +lemma Least_existence1: + assumes "LV r s \ {}" + shows " \! v\<^sub>m\<^sub>i\<^sub>n \ LV r s. \v \ LV r s. v\<^sub>m\<^sub>i\<^sub>n :\val v" +using Least_existence[OF assms] assms +using PosOrdeq_antisym by blast + +lemma Least_existence2: + assumes "LV r s \ {}" + shows " \!vmin \ LV r s. lexer r s = Some vmin \ (\v \ LV r s. vmin :\val v)" +using Least_existence[OF assms] assms +using PosOrdeq_antisym +using PosOrd_Posix PosOrd_ex_eq2 lexer_correctness(1) + by (metis (mono_tags, lifting)) + + +lemma Least_existence1_pre: + assumes "LV r s \ {}" + shows " \!vmin \ LV r s. \v \ (LV r s \ {v'. flat v' \spre s}). vmin :\val v" +using Least_existence[OF assms] assms +apply - +apply(erule bexE) +apply(rule_tac a="vmin" in ex1I) +apply(auto)[1] +apply (metis PosOrd_Posix PosOrd_ex_eq2 PosOrd_spreI PosOrdeq_antisym Posix1(2)) +apply(auto)[1] +apply(simp add: PosOrdeq_antisym) +done + +lemma PosOrd_partial: + shows "partial_order_on UNIV {(v1, v2). v1 :\val v2}" +apply(simp add: partial_order_on_def) +apply(simp add: preorder_on_def refl_on_def) +apply(simp add: PosOrdeq_refl) +apply(auto) +apply(rule transI) +apply(auto intro: PosOrdeq_trans)[1] +apply(rule antisymI) +apply(simp add: PosOrdeq_antisym) +done + +lemma PosOrd_wf: + shows "wf {(v1, v2). v1 :\val v2 \ v1 \ LV r s \ v2 \ LV r s}" +proof - + have "finite {(v1, v2). v1 \ LV r s \ v2 \ LV r s}" + by (simp add: LV_finite) + moreover + have "{(v1, v2). v1 :\val v2 \ v1 \ LV r s \ v2 \ LV r s} \ {(v1, v2). v1 \ LV r s \ v2 \ LV r s}" + by auto + ultimately have "finite {(v1, v2). v1 :\val v2 \ v1 \ LV r s \ v2 \ LV r s}" + using finite_subset by blast + moreover + have "acyclicP (\v1 v2. v1 :\val v2 \ v1 \ LV r s \ v2 \ LV r s)" + unfolding acyclic_def + by (smt (verit, ccfv_threshold) PosOrd_irrefl PosOrd_trans tranclp_trans_induct tranclp_unfold) + ultimately show "wf {(v1, v2). v1 :\val v2 \ v1 \ LV r s \ v2 \ LV r s}" + using finite_acyclic_wf by blast +qed + +unused_thms + +end \ No newline at end of file diff --git a/thys/Posix-Lexing/Extensions/Regular_Exps3.thy b/thys/Posix-Lexing/Extensions/Regular_Exps3.thy new file mode 100644 --- /dev/null +++ b/thys/Posix-Lexing/Extensions/Regular_Exps3.thy @@ -0,0 +1,54 @@ +(* Adapted from Tobias Nipkow in order to accommodate + bounded regular expressions *) + +section "Extended Regular Expressions 3" + +theory Regular_Exps3 +imports "Regular-Sets.Regular_Set" +begin + +datatype (atoms: 'a) rexp = + is_Zero: Zero | + is_One: One | + Atom 'a | + Plus "('a rexp)" "('a rexp)" | + Times "('a rexp)" "('a rexp)" | + Star "('a rexp)" | + NTimes "('a rexp)" "nat" + + +primrec lang :: "'a rexp => 'a lang" where +"lang Zero = {}" | +"lang One = {[]}" | +"lang (Atom a) = {[a]}" | +"lang (Plus r s) = (lang r) Un (lang s)" | +"lang (Times r s) = conc (lang r) (lang s)" | +"lang (Star r) = star(lang r)" | +"lang (NTimes r n) = ((lang r) ^^ n)" + + +lemma lang_subset_lists: + "atoms r \ A \ lang r \ lists A" + by (induction r) + (auto simp: conc_subset_lists star_subset_lists lang_pow_subset_lists) + + +primrec nullable :: "'a rexp \ bool" where +"nullable Zero = False" | +"nullable One = True" | +"nullable (Atom c) = False" | +"nullable (Plus r1 r2) = (nullable r1 \ nullable r2)" | +"nullable (Times r1 r2) = (nullable r1 \ nullable r2)" | +"nullable (Star r) = True" | +"nullable (NTimes r n) = (if n = 0 then True else nullable r)" + + +lemma pow_empty_iff: + shows "[] \ (lang r) ^^ n \ (if n = 0 then True else [] \ (lang r))" + by (induct n)(auto) + +lemma nullable_iff: + shows "nullable r \ [] \ lang r" + by (induct r) (auto simp add: conc_def pow_empty_iff split: if_splits) + +end diff --git a/thys/Posix-Lexing/Extensions/Simplifying3.thy b/thys/Posix-Lexing/Extensions/Simplifying3.thy new file mode 100644 --- /dev/null +++ b/thys/Posix-Lexing/Extensions/Simplifying3.thy @@ -0,0 +1,236 @@ +(* Title: POSIX Lexing with Derivatives of Extended Regular Expressions + Author: Christian Urban , 2022 + Maintainer: Christian Urban +*) + +theory Simplifying3 + imports Lexer3 +begin + +section \Lexer including simplifications\ + + +fun F_RIGHT where + "F_RIGHT f v = Right (f v)" + +fun F_LEFT where + "F_LEFT f v = Left (f v)" + +fun F_Plus where + "F_Plus f\<^sub>1 f\<^sub>2 (Right v) = Right (f\<^sub>2 v)" +| "F_Plus f\<^sub>1 f\<^sub>2 (Left v) = Left (f\<^sub>1 v)" +| "F_Plus f1 f2 v = v" + + +fun F_Times1 where + "F_Times1 f\<^sub>1 f\<^sub>2 v = Seq (f\<^sub>1 Void) (f\<^sub>2 v)" + +fun F_Times2 where + "F_Times2 f\<^sub>1 f\<^sub>2 v = Seq (f\<^sub>1 v) (f\<^sub>2 Void)" + +fun F_Times where + "F_Times f\<^sub>1 f\<^sub>2 (Seq v\<^sub>1 v\<^sub>2) = Seq (f\<^sub>1 v\<^sub>1) (f\<^sub>2 v\<^sub>2)" +| "F_Times f1 f2 v = v" + +fun simp_Plus where + "simp_Plus (Zero, f\<^sub>1) (r\<^sub>2, f\<^sub>2) = (r\<^sub>2, F_RIGHT f\<^sub>2)" +| "simp_Plus (r\<^sub>1, f\<^sub>1) (Zero, f\<^sub>2) = (r\<^sub>1, F_LEFT f\<^sub>1)" +| "simp_Plus (r\<^sub>1, f\<^sub>1) (r\<^sub>2, f\<^sub>2) = (Plus r\<^sub>1 r\<^sub>2, F_Plus f\<^sub>1 f\<^sub>2)" + +fun simp_Times where + "simp_Times (One, f\<^sub>1) (r\<^sub>2, f\<^sub>2) = (r\<^sub>2, F_Times1 f\<^sub>1 f\<^sub>2)" +| "simp_Times (r\<^sub>1, f\<^sub>1) (One, f\<^sub>2) = (r\<^sub>1, F_Times2 f\<^sub>1 f\<^sub>2)" +| "simp_Times (r\<^sub>1, f\<^sub>1) (r\<^sub>2, f\<^sub>2) = (Times r\<^sub>1 r\<^sub>2, F_Times f\<^sub>1 f\<^sub>2)" + +lemma simp_Times_simps[simp]: + "simp_Times p1 p2 = (if (fst p1 = One) then (fst p2, F_Times1 (snd p1) (snd p2)) + else (if (fst p2 = One) then (fst p1, F_Times2 (snd p1) (snd p2)) + else (Times (fst p1) (fst p2), F_Times (snd p1) (snd p2))))" +by (induct p1 p2 rule: simp_Times.induct) (auto) + +lemma simp_Plus_simps[simp]: + "simp_Plus p1 p2 = (if (fst p1 = Zero) then (fst p2, F_RIGHT (snd p2)) + else (if (fst p2 = Zero) then (fst p1, F_LEFT (snd p1)) + else (Plus (fst p1) (fst p2), F_Plus (snd p1) (snd p2))))" +by (induct p1 p2 rule: simp_Plus.induct) (auto) + +fun + simp :: "'a rexp \ 'a rexp * ('a val \ 'a val)" +where + "simp (Plus r1 r2) = simp_Plus (simp r1) (simp r2)" +| "simp (Times r1 r2) = simp_Times (simp r1) (simp r2)" +| "simp r = (r, id)" + +fun + slexer :: "'a rexp \ 'a list \ ('a val) option" +where + "slexer r [] = (if nullable r then Some(mkeps r) else None)" +| "slexer r (c#s) = (let (rs, fr) = simp (deriv c r) in + (case (slexer rs s) of + None \ None + | Some(v) \ Some(injval r c (fr v))))" + +lemma slexer_better_simp: + "slexer r (c#s) = (case (slexer (fst (simp (deriv c r))) s) of + None \ None + | Some(v) \ Some(injval r c ((snd (simp (deriv c r))) v)))" +by (auto split: prod.split option.split) + + +lemma L_fst_simp: + shows "lang r = lang (fst (simp r))" +by (induct r) (auto) + +lemma Posix_simp: + assumes "s \ (fst (simp r)) \ v" + shows "s \ r \ ((snd (simp r)) v)" +using assms +proof(induct r arbitrary: s v rule: rexp.induct) + case (Plus r1 r2 s v) + have IH1: "\s v. s \ fst (simp r1) \ v \ s \ r1 \ snd (simp r1) v" by fact + have IH2: "\s v. s \ fst (simp r2) \ v \ s \ r2 \ snd (simp r2) v" by fact + have as: "s \ fst (simp (Plus r1 r2)) \ v" by fact + consider (Zero_Zero) "fst (simp r1) = Zero" "fst (simp r2) = Zero" + | (Zero_NZero) "fst (simp r1) = Zero" "fst (simp r2) \ Zero" + | (NZero_Zero) "fst (simp r1) \ Zero" "fst (simp r2) = Zero" + | (NZero_NZero) "fst (simp r1) \ Zero" "fst (simp r2) \ Zero" by auto + then show "s \ Plus r1 r2 \ snd (simp (Plus r1 r2)) v" + proof(cases) + case (Zero_Zero) + with as have "s \ Zero \ v" by simp + then show "s \ Plus r1 r2 \ snd (simp (Plus r1 r2)) v" by (rule Posix_elims(1)) + next + case (Zero_NZero) + with as have "s \ fst (simp r2) \ v" by simp + with IH2 have "s \ r2 \ snd (simp r2) v" by simp + moreover + from Zero_NZero have "fst (simp r1) = Zero" by simp + then have "lang (fst (simp r1)) = {}" by simp + then have "lang r1 = {}" using L_fst_simp by auto + then have "s \ lang r1" by simp + ultimately have "s \ Plus r1 r2 \ Right (snd (simp r2) v)" by (rule Posix_Plus2) + then show "s \ Plus r1 r2 \ snd (simp (Plus r1 r2)) v" + using Zero_NZero by simp + next + case (NZero_Zero) + with as have "s \ fst (simp r1) \ v" by simp + with IH1 have "s \ r1 \ snd (simp r1) v" by simp + then have "s \ Plus r1 r2 \ Left (snd (simp r1) v)" by (rule Posix_Plus1) + then show "s \ Plus r1 r2 \ snd (simp (Plus r1 r2)) v" using NZero_Zero by simp + next + case (NZero_NZero) + with as have "s \ Plus (fst (simp r1)) (fst (simp r2)) \ v" by simp + then consider (Left) v1 where "v = Left v1" "s \ (fst (simp r1)) \ v1" + | (Right) v2 where "v = Right v2" "s \ (fst (simp r2)) \ v2" "s \ lang (fst (simp r1))" + by (erule_tac Posix_elims(4)) + then show "s \ Plus r1 r2 \ snd (simp (Plus r1 r2)) v" + proof(cases) + case (Left) + then have "v = Left v1" "s \ r1 \ (snd (simp r1) v1)" using IH1 by simp_all + then show "s \ Plus r1 r2 \ snd (simp (Plus r1 r2)) v" using NZero_NZero + by (simp_all add: Posix_Plus1) + next + case (Right) + then have "v = Right v2" "s \ r2 \ (snd (simp r2) v2)" "s \ lang r1" using IH2 L_fst_simp by auto + then show "s \ Plus r1 r2 \ snd (simp (Plus r1 r2)) v" using NZero_NZero + by (simp_all add: Posix_Plus2) + qed + qed +next + case (Times r1 r2 s v) + have IH1: "\s v. s \ fst (simp r1) \ v \ s \ r1 \ snd (simp r1) v" by fact + have IH2: "\s v. s \ fst (simp r2) \ v \ s \ r2 \ snd (simp r2) v" by fact + have as: "s \ fst (simp (Times r1 r2)) \ v" by fact + consider (One_One) "fst (simp r1) = One" "fst (simp r2) = One" + | (One_NOne) "fst (simp r1) = One" "fst (simp r2) \ One" + | (NOne_One) "fst (simp r1) \ One" "fst (simp r2) = One" + | (NOne_NOne) "fst (simp r1) \ One" "fst (simp r2) \ One" by auto + then show "s \ Times r1 r2 \ snd (simp (Times r1 r2)) v" + proof(cases) + case (One_One) + with as have b: "s \ One \ v" by simp + from b have "s \ r1 \ snd (simp r1) v" using IH1 One_One by simp + moreover + from b have c: "s = []" "v = Void" using Posix_elims(2) by auto + moreover + have "[] \ One \ Void" by (simp add: Posix_One) + then have "[] \ fst (simp r2) \ Void" using One_One by simp + then have "[] \ r2 \ snd (simp r2) Void" using IH2 by simp + ultimately have "([] @ []) \ Times r1 r2 \ Seq (snd (simp r1) Void) (snd (simp r2) Void)" + using Posix_Times by blast + then show "s \ Times r1 r2 \ snd (simp (Times r1 r2)) v" using c One_One by simp + next + case (One_NOne) + with as have b: "s \ fst (simp r2) \ v" by simp + from b have "s \ r2 \ snd (simp r2) v" using IH2 One_NOne by simp + moreover + have "[] \ One \ Void" by (simp add: Posix_One) + then have "[] \ fst (simp r1) \ Void" using One_NOne by simp + then have "[] \ r1 \ snd (simp r1) Void" using IH1 by simp + moreover + from One_NOne(1) have "lang (fst (simp r1)) = {[]}" by simp + then have "lang r1 = {[]}" by (simp add: L_fst_simp[symmetric]) + ultimately have "([] @ s) \ Times r1 r2 \ Seq (snd (simp r1) Void) (snd (simp r2) v)" + by(rule_tac Posix_Times) auto + then show "s \ Times r1 r2 \ snd (simp (Times r1 r2)) v" using One_NOne by simp + next + case (NOne_One) + with as have "s \ fst (simp r1) \ v" by simp + with IH1 have "s \ r1 \ snd (simp r1) v" by simp + moreover + have "[] \ One \ Void" by (simp add: Posix_One) + then have "[] \ fst (simp r2) \ Void" using NOne_One by simp + then have "[] \ r2 \ snd (simp r2) Void" using IH2 by simp + ultimately have "(s @ []) \ Times r1 r2 \ Seq (snd (simp r1) v) (snd (simp r2) Void)" + by(rule_tac Posix_Times) auto + then show "s \ Times r1 r2 \ snd (simp (Times r1 r2)) v" using NOne_One by simp + next + case (NOne_NOne) + with as have "s \ Times (fst (simp r1)) (fst (simp r2)) \ v" by simp + then obtain s1 s2 v1 v2 where eqs: "s = s1 @ s2" "v = Seq v1 v2" + "s1 \ (fst (simp r1)) \ v1" "s2 \ (fst (simp r2)) \ v2" + "\ (\s\<^sub>3 s\<^sub>4. s\<^sub>3 \ [] \ s\<^sub>3 @ s\<^sub>4 = s2 \ s1 @ s\<^sub>3 \ lang r1 \ s\<^sub>4 \ lang r2)" + by (erule_tac Posix_elims(5)) (auto simp add: L_fst_simp[symmetric]) + then have "s1 \ r1 \ (snd (simp r1) v1)" "s2 \ r2 \ (snd (simp r2) v2)" + using IH1 IH2 by auto + then show "s \ Times r1 r2 \ snd (simp (Times r1 r2)) v" using eqs NOne_NOne + by(auto intro: Posix_Times) + qed +qed (simp_all) + + +lemma slexer_correctness: + shows "slexer r s = lexer r s" +proof(induct s arbitrary: r) + case Nil + show "slexer r [] = lexer r []" by simp +next + case (Cons c s r) + have IH: "\r. slexer r s = lexer r s" by fact + show "slexer r (c # s) = lexer r (c # s)" + proof (cases "s \ lang (deriv c r)") + case True + assume a1: "s \ lang (deriv c r)" + then obtain v1 where a2: "lexer (deriv c r) s = Some v1" "s \ deriv c r \ v1" + using lexer_correct_Some by auto + from a1 have "s \ lang (fst (simp (deriv c r)))" using L_fst_simp[symmetric] by auto + then obtain v2 where a3: "lexer (fst (simp (deriv c r))) s = Some v2" "s \ (fst (simp (deriv c r))) \ v2" + using lexer_correct_Some by auto + then have a4: "slexer (fst (simp (deriv c r))) s = Some v2" using IH by simp + from a3(2) have "s \ deriv c r \ (snd (simp (deriv c r))) v2" using Posix_simp by auto + with a2(2) have "v1 = (snd (simp (deriv c r))) v2" using Posix_determ by auto + with a2(1) a4 show "slexer r (c # s) = lexer r (c # s)" by (auto split: prod.split) + next + case False + assume b1: "s \ lang (deriv c r)" + then have "lexer (deriv c r) s = None" using lexer_correct_None by auto + moreover + from b1 have "s \ lang (fst (simp (deriv c r)))" using L_fst_simp[symmetric] by auto + then have "lexer (fst (simp (deriv c r))) s = None" using lexer_correct_None by auto + then have "slexer (fst (simp (deriv c r))) s = None" using IH by simp + ultimately show "slexer r (c # s) = lexer r (c # s)" + by (simp del: slexer.simps add: slexer_better_simp) + qed +qed + +end diff --git a/thys/Posix-Lexing/ROOT b/thys/Posix-Lexing/ROOT --- a/thys/Posix-Lexing/ROOT +++ b/thys/Posix-Lexing/ROOT @@ -1,16 +1,25 @@ chapter AFP session "Posix-Lexing" (AFP) = "Regular-Sets" + options [timeout = 600] + directories + "Extensions" + theories Lexer LexicalVals Simplifying Positions + "Extensions/Regular_Exps3" + "Extensions/Derivatives3" + "Extensions/Lexer3" + "Extensions/LexicalVals3" + "Extensions/Simplifying3" + "Extensions/Positions3" document_files "root.bib" "root.tex"