diff -r 0856fbf8bda7 -r 426a93160f4a thys2/SizeBound6CT.thy --- a/thys2/SizeBound6CT.thy Wed Mar 02 23:53:11 2022 +0000 +++ b/thys2/SizeBound6CT.thy Sat Mar 05 11:31:59 2022 +0000 @@ -116,16 +116,11 @@ *) -datatype cchar = -Achar -|Bchar -|Cchar -|Dchar datatype rrexp = RZERO | RONE -| RCHAR cchar +| RCHAR char | RSEQ rrexp rrexp | RALTS "rrexp list" | RSTAR rrexp @@ -145,19 +140,13 @@ | "rnullable (RSEQ r1 r2) = (rnullable r1 \ rnullable r2)" | "rnullable (RSTAR r) = True" -fun convert_cchar_char :: "cchar \ char" - where -"convert_cchar_char Achar = (CHR 0x41) " -| "convert_cchar_char Bchar = (CHR 0x42) " -| "convert_cchar_char Cchar = (CHR 0x43) " -| "convert_cchar_char Dchar = (CHR 0x44) " fun rder :: "char \ rrexp \ rrexp" where "rder c (RZERO) = RZERO" | "rder c (RONE) = RZERO" -| "rder c (RCHAR d) = (if c = (convert_cchar_char d) then RONE else RZERO)" +| "rder c (RCHAR d) = (if c = d then RONE else RZERO)" | "rder c (RALTS rs) = RALTS (map (rder c) rs)" | "rder c (RSEQ r1 r2) = (if rnullable r1 @@ -879,11 +868,17 @@ |"rexp_enum (Suc n) = [(RSEQ r1 r2). r1 \ set (rexp_enum i) \ r2 \ set (rexp_enum j) \ i + j = n]" *) +definition SEQ_set where + "SEQ_set A n \ {RSEQ r1 r2 | r1 r2. r1 \ A \ r2 \ A \ rsize r1 + rsize r2 \ n}" + +definition ALT_set where +"ALT_set A n \ {RALTS rs | rs. set rs \ A \ sum_list (map rsize rs) \ n}" + context notes rev_conj_cong[fundef_cong] begin function (sequential) rexp_enum :: "nat \ rrexp set" where "rexp_enum 0 = {}" -|"rexp_enum (Suc 0) = {RALTS []} \ {RZERO} \ {RONE} \ { (RCHAR c) |c. c \{Achar, Bchar, Cchar, Dchar} }" +|"rexp_enum (Suc 0) = {RALTS []} \ {RZERO} \ {RONE} \ { (RCHAR c) |c::char. True }" |"rexp_enum (Suc n) = {(RSEQ r1 r2)|r1 r2 i j. r1 \ (rexp_enum i) \ r2 \ (rexp_enum j) \ i + j = n} \ {(RALTS (a # rs)) | a rs i j. a \ (rexp_enum i) \ (RALTS rs) \ (rexp_enum j) \ i + j = Suc n \ i \ n \ j \ n} \ {RSTAR r0 | r0. r0 \ (rexp_enum n)} \ @@ -904,16 +899,146 @@ shows "n \ m \ (rexp_enum n) \ (rexp_enum m)" by (simp add: lift_Suc_mono_le rexp_enum_inclusion) +lemma zero_in_Suc0: + shows "RZERO \ rexp_enum (Suc 0)" +and "RZERO \ rexp_enum 1" + apply simp + by simp + +lemma one_in_Suc0: + shows "RONE \ rexp_enum (Suc 0)" +and "RONE \ rexp_enum 1" + apply simp + by simp + +lemma char_in_Suc0: + shows "RCHAR c \ rexp_enum (Suc 0)" + apply simp + done + + +lemma char_in1: + shows "RCHAR c \ rexp_enum 1" + using One_nat_def char_in_Suc0 by presburger + +lemma alts_nil_in_Suc0: + shows "RALTS [] \ rexp_enum (Suc 0)" + and "RALTS [] \ rexp_enum 1" + apply simp + by simp + + +lemma zero_in_positive: + shows "RZERO \ rexp_enum (Suc N)" + by (metis le_add1 plus_1_eq_Suc rexp_enum_mono subsetD zero_in_Suc0(2)) + +lemma one_in_positive: + shows "RONE \ rexp_enum (Suc N)" + by (metis le_add1 plus_1_eq_Suc rexp_enum_mono subsetD one_in_Suc0(2)) + +lemma alts_in_positive: + shows "RALTS [] \ rexp_enum (Suc N)" + by (metis One_nat_def alts_nil_in_Suc0(1) le_add_same_cancel1 less_Suc_eq_le plus_1_eq_Suc rexp_enum_mono subsetD zero_less_Suc) + +lemma char_in_positive: + shows "RCHAR c \ rexp_enum (Suc N)" + apply(cases c) + apply (metis Suc_eq_plus1 char_in1 le_add2 rexp_enum_mono subsetD)+ + done + lemma enum_inductive_cases: shows "rsize (RSEQ r1 r2) = Suc n \ \i j. rsize r1 = i \ rsize r2 = j\ i + j = n" by (metis Suc_inject rsize.simps(5)) -thm rsize.simps(5) + lemma enumeration_finite: shows "\Nn. card (rexp_enum n) < Nn" apply(simp add:no_top_class.gt_ex) done + +lemma s1: +"{r::rexp . size r = 0} = ({ZERO, ONE} \ {CH c| c. True})" +apply(auto) +apply(case_tac x) +apply(simp_all) +done + + + + +lemma enum_Suc0: + shows " rexp_enum (Suc 0) = {RZERO} \ {RONE} \ {RCHAR c | c. True} \ {RALTS []}" + by auto + +lemma enumeration_chars_finite: + shows "finite {RCHAR c |c. True}" + apply(subgoal_tac "finite (RCHAR ` (UNIV::char set))") + prefer 2 + using finite_code apply blast + by (simp add: full_SetCompr_eq) + +lemma enum_Suc0_finite: + shows "finite (rexp_enum (Suc 0))" + apply(subgoal_tac "finite ( {RZERO} \ {RONE} \ {RCHAR c | c. True} \ {RALTS []})") + using enum_Suc0 apply presburger + using enumeration_chars_finite by blast + +lemma enum_1_finite: + shows "finite (rexp_enum 1)" + using enum_Suc0_finite by force + +lemma enum_stars_finite: + shows " finite (rexp_enum n) \ finite {RSTAR r0 | r0. r0 \ (rexp_enum n)}" + apply(induct n) + apply simp + apply simp + done + +definition RSEQ_set + where + "RSEQ_set A B \ (\(r1, r2) . (RSEQ r1 r2 )) ` (A \ B)" + + +lemma enum_seq_finite: + shows "(\k. k < n \ finite (rexp_enum k)) \ finite +{(RSEQ r1 r2)|r1 r2 i j. r1 \ (rexp_enum i) \ r2 \ (rexp_enum j) \ i + j = n}" + apply(induct n) + apply simp + apply(subgoal_tac "{(RSEQ r1 r2)|r1 r2 i j. r1 \ (rexp_enum i) \ r2 \ (rexp_enum j) \ i + j = Suc n} +\ RSEQ_set (rexp_enum n) (rexp_enum n)") + apply(subgoal_tac "finite ( RSEQ_set (rexp_enum n) (rexp_enum n))") + using rev_finite_subset + apply fastforce + + sorry + + + +lemma enum_induct_finite: + shows " finite ( {(RSEQ r1 r2)|r1 r2 i j. r1 \ (rexp_enum i) \ r2 \ (rexp_enum j) \ i + j = n} \ +{(RALTS (a # rs)) | a rs i j. a \ (rexp_enum i) \ (RALTS rs) \ (rexp_enum j) \ i + j = Suc n \ i \ n \ j \ n} \ +{RSTAR r0 | r0. r0 \ (rexp_enum n)} \ +(rexp_enum n))" + apply(induct n) + apply simp + sorry + +lemma enumeration_finite2: + shows "finite (rexp_enum n)" + apply(cases n) + apply auto[1] + apply(case_tac nat) + using enum_Suc0_finite apply blast + apply(subgoal_tac "rexp_enum ( Suc n) = {(RSEQ r1 r2)|r1 r2 i j. r1 \ (rexp_enum i) \ r2 \ (rexp_enum j) \ i + j = n} \ +{(RALTS (a # rs)) | a rs i j. a \ (rexp_enum i) \ (RALTS rs) \ (rexp_enum j) \ i + j = Suc n \ i \ n \ j \ n} \ +{RSTAR r0 | r0. r0 \ (rexp_enum n)} \ +(rexp_enum n)") + prefer 2 + using rexp_enum.simps(3) apply presburger + using enum_induct_finite by auto + + lemma size1_rexps: shows "RCHAR x \ rexp_enum 1" apply(cases x) @@ -978,15 +1103,14 @@ apply auto[1] apply(subgoal_tac "RALTS (a # list) \ {uu. \a rs i j. uu = RALTS (a # rs) \ a \ rexp_enum i \ RALTS rs \ rexp_enum j \ i + j = Suc N \ i \ N \ j \ N}") - - apply fastforce apply(subgoal_tac "a \ rexp_enum i") prefer 2 - apply linarith by blast +thm rsize.elims + lemma rexp_enum_covers: shows " rsize r \ N \ r \ rexp_enum N \ r \ rexp_enum (rsize r)" apply(induct N arbitrary : r) @@ -1016,14 +1140,77 @@ apply(subgoal_tac "RALTS list \ rexp_enum N") prefer 2 apply presburger + using def_enum_alts rexp_size_induct apply presburger + using rexp_size_induct apply presburger + using rexp_size_induct apply presburger + using rexp_size_induct apply presburger + apply(subgoal_tac "r \ rexp_enum 1") + apply (metis rsize.simps(1)) + apply(subgoal_tac "rsize r = Suc 0") + prefer 2 + using rsize.simps(1) apply presburger + apply(subgoal_tac "r \ rexp_enum (Suc 0)") + apply force + using zero_in_Suc0 apply blast + apply simp - sorry + using one_in_positive apply auto[1] + + apply (metis char_in_positive) + apply(subgoal_tac "rsize x41 \ N") + apply(subgoal_tac "rsize x42 \ N") + prefer 2 + apply auto[1] + prefer 2 + using enum_inductive_cases nat_le_iff_add apply blast + apply(subgoal_tac "x41 \ rexp_enum (rsize x41)") + prefer 2 + apply blast + apply(subgoal_tac "x42 \ rexp_enum (rsize x42)") + prefer 2 + apply blast + apply(subgoal_tac "rsize x42 + rsize x41 = N") + prefer 2 + using add.commute enum_inductive_cases apply blast + apply(subgoal_tac "rexp_enum (Suc N) = {(RSEQ r1 r2)|r1 r2 i j. r1 \ (rexp_enum i) \ r2 \ (rexp_enum j) \ i + j = N} \ +{(RALTS (a # rs)) | a rs i j. a \ (rexp_enum i) \ (RALTS rs) \ (rexp_enum j) \ i + j = Suc N \ i \ N \ j \ N} \ +{RSTAR r0 | r0. r0 \ (rexp_enum N)} \ +(rexp_enum N)") + apply (smt (verit, del_insts) UnCI mem_Collect_eq old.nat.inject rsize.simps(5)) + apply (smt (verit, ccfv_threshold) One_nat_def nle_le not_less_eq_eq rexp_enum_case3 size_geq1) + apply(subgoal_tac "x6 \ rexp_enum N") + prefer 2 + + apply force + apply(subgoal_tac "N \ Suc 0") + prefer 2 + apply (metis less_Suc_eq_le non_zero_size rsize.simps(6)) + apply(subgoal_tac "rexp_enum (Suc N) = {(RSEQ r1 r2)|r1 r2 i j. r1 \ (rexp_enum i) \ r2 \ (rexp_enum j) \ i + j = N} \ +{(RALTS (a # rs)) | a rs i j. a \ (rexp_enum i) \ (RALTS rs) \ (rexp_enum j) \ i + j = Suc N \ i \ N \ j \ N} \ +{RSTAR r0 | r0. r0 \ (rexp_enum N)} \ +(rexp_enum N)") + prefer 2 + using rexp_enum_case3 apply presburger + by (metis (mono_tags, lifting) Un_iff mem_Collect_eq) -lemma finite_size_finite_regx: - shows " \l. \rs. ((\r \ (set rs). rsize r < N) \ (distinct rs) \ (length rs) < l) " + + + +definition + "sizeNregex N \ {r. rsize r \ N}" + + - sorry +lemma sizeNregex_covered: + shows "sizeNregex N \ rexp_enum N" + using rexp_enum_covers sizeNregex_def by auto + +lemma finiteness_of_sizeN_regex: + shows "finite (sizeNregex N)" + by (meson enumeration_finite2 rev_finite_subset sizeNregex_covered) + + (*below probably needs proved concurrently*)