diff -r dabd25e8e4e9 -r 7a016eeb118d thys2/ClosedFormsBounds.thy --- a/thys2/ClosedFormsBounds.thy Sat Mar 12 14:33:54 2022 +0000 +++ b/thys2/ClosedFormsBounds.thy Tue Mar 15 16:37:41 2022 +0000 @@ -1,14 +1,11 @@ - +(**) theory ClosedFormsBounds imports "GeneralRegexBound" "ClosedForms" begin - lemma alts_ders_lambda_shape_ders: shows "\r \ set (map (\r. rders_simp r ( s)) rs ). \r1 \ set rs. r = rders_simp r1 s" by (simp add: image_iff) - - lemma rlist_bound: shows "\r \ set rs. rsize r \ N \ sum_list (map rsize rs) \ N * (length rs)" apply(induct rs) @@ -46,20 +43,391 @@ shows "rsize (rsimp (RALTS rs)) \ Suc (sum_list (map rsize (rdistinct (rflts (map rsimp rs)) {})))" using rsimp_aalts_smaller by auto +lemma no_elem_distinct : + shows "a \ set rs \ rdistinct rs rset = rdistinct rs (insert a rset)" + apply(induct rs arbitrary: rset) + apply simp + by force + + + + +inductive good :: "rrexp \ bool" + where +"RZERO \ set rs \ good (RALTS rs)" +|"good RZERO" +|"good RONE" +|"good (RCHAR c)" +|"good (RSEQ r1 r2)" +|"good (RSTAR r0)" + + +lemma after_flts_no0: + shows "\r \ set rs. good r \ RZERO \ set (rflts rs)" + apply(induct rs) + apply simp + apply(case_tac a) + apply simp + apply simp + apply simp + apply simp + apply simp + using good.simps apply blast + apply simp + done + lemma flts_has_no_zero: - shows "rdistinct (rflts rs) rset = rdistinct (rflts rs) (insert RZERO rset)" + shows "\r \ set rs. good r \ rdistinct (rflts rs) rset = rdistinct (rflts rs) (insert RZERO rset)" + apply(subgoal_tac "RZERO \ set (rflts rs)") + apply (meson no_elem_distinct) + apply(insert after_flts_no0) + by blast + +lemma shape_of_alts: + shows "\a \ alts_set. (\xs. a = RALTS xs) \ RZERO \ alts_set \ RONE \ alts_set" + by fastforce + +lemma quantified2_implies1: + shows "\r. P \ Q \ \r. P" + by auto + +lemma quantified_quantifiedAB_A: + shows " (\a\alts_set. \xs. a = RALTS xs \ set xs \ corr_set) \ \a \ alts_set. \xs. a = RALTS xs" + by fastforce + + + + +lemma list_distinct_removal: + shows "set rs \ rset \ rdistinct (rs @ rs1) rset = rdistinct rs1 rset" + apply(induct rs arbitrary: rset) + apply simp + by simp + + +lemma rdistinct_mono_list: + shows " sum_list (map rsize (rdistinct (x5 @ rs) rset )) \ + ( sum_list (map rsize x5)) + (sum_list (map rsize (rdistinct rs ((set x5 ) \ rset))))" + apply(induct x5 arbitrary: rs rset) + apply simp + apply(case_tac "a \ rset") + apply simp + apply (simp add: add.assoc insert_absorb trans_le_add2) + apply simp + by (metis Un_insert_right) + + +lemma flts_size_reduction_alts: + shows " \a rs noalts_set alts_set corr_set x5. + \\noalts_set alts_set corr_set. + (\r\noalts_set. \xs. r \ RALTS xs) \ + (\a\alts_set. \xs. a = RALTS xs \ set xs \ corr_set) \ + Suc (sum_list (map rsize (rdistinct (rflts rs) (noalts_set \ corr_set)))) + \ Suc (sum_list (map rsize (rdistinct rs (insert RZERO (noalts_set \ alts_set))))); + (\r\noalts_set. \xs. r \ RALTS xs) \ + (\a\alts_set. \xs. a = RALTS xs \ set xs \ corr_set); + a = RALTS x5\ + \ Suc (sum_list (map rsize (rdistinct (rflts (a # rs)) (noalts_set \ corr_set)))) + \ Suc (sum_list + (map rsize (rdistinct (a # rs) (insert RZERO (noalts_set \ alts_set)))))" + apply(case_tac "a \ alts_set") + apply simp + apply(subgoal_tac "set x5 \ corr_set") + apply(subst list_distinct_removal) + apply auto[1] + apply presburger + apply fastforce + apply (subgoal_tac "a \ noalts_set") + prefer 2 + apply blast + apply simp + apply(subgoal_tac "sum_list (map rsize (rdistinct (x5 @ rflts rs) (noalts_set \ corr_set))) + \ sum_list (map rsize x5 ) + sum_list (map rsize (rdistinct (rflts rs) ((set x5) \ (noalts_set \ corr_set))))") + prefer 2 + using rdistinct_mono_list apply presburger + apply(subgoal_tac "insert (RALTS x5) (noalts_set \ alts_set) = noalts_set \ (insert (RALTS x5) alts_set)") + apply(simp only:) + apply(subgoal_tac "sum_list (map rsize x5) + +sum_list (map rsize (rdistinct (rflts rs) (noalts_set \ (corr_set \ (set x5))))) \ +Suc (sum_list (map rsize x5) + + sum_list + (map rsize + (rdistinct rs (insert RZERO (noalts_set \ insert (RALTS x5) alts_set)))))") + + apply (simp add: Un_left_commute inf_sup_aci(5)) + apply(subgoal_tac "sum_list (map rsize (rdistinct (rflts rs) (noalts_set \ (corr_set \ set x5)))) +\ sum_list + (map rsize + (rdistinct rs (insert RZERO (noalts_set \ insert (RALTS x5) alts_set))))") + apply linarith + apply(subgoal_tac "\r \ insert (RALTS x5) alts_set. \xs1.( r = RALTS xs1 \ set xs1 \ corr_set \ set x5)") + apply presburger + apply (meson insert_iff sup.cobounded2 sup.coboundedI1) + by blast + + + - sorry +lemma flts_vs_nflts1: + shows "(\r \ noalts_set. \xs. r \ RALTS xs) + \ (\a \ alts_set. (\xs. a = RALTS xs \ set xs \ corr_set)) +\ (sum_list (map rsize (rdistinct ( rflts rs) (noalts_set \ corr_set) ))) + \ (sum_list (map rsize (rdistinct rs (insert RZERO (noalts_set \ alts_set) ))))" + apply(induct rs arbitrary: noalts_set alts_set corr_set) + apply simp + apply(case_tac a) + apply(case_tac "RZERO \ noalts_set") + apply simp + apply(subgoal_tac "RZERO \ alts_set") + apply simp + apply fastforce + apply(case_tac "RONE \ noalts_set") + apply simp + apply(subgoal_tac "RONE \ alts_set") + prefer 2 + apply fastforce + apply(case_tac "RONE \ corr_set") + apply(subgoal_tac "rflts (a # rs) = RONE # rflts rs") + apply(simp only:) + apply(subgoal_tac "rdistinct (RONE # rflts rs) (noalts_set \ corr_set) = + rdistinct (rflts rs) (noalts_set \ corr_set)") + apply(simp only:) + apply(subgoal_tac "rdistinct (RONE # rs) (insert RZERO (noalts_set \ alts_set)) = + RONE # (rdistinct rs (insert RONE (insert RZERO (noalts_set \ alts_set)))) ") + apply(simp only:) + apply(subgoal_tac "rdistinct (rflts rs) (noalts_set \ corr_set) = + rdistinct (rflts rs) (insert RONE (noalts_set \ corr_set))") + apply (simp only:) + apply(subgoal_tac "insert RONE (noalts_set \ corr_set) = (insert RONE noalts_set) \ corr_set") + apply(simp only:) + apply(subgoal_tac "insert RONE (insert RZERO (noalts_set \ alts_set)) = + insert RZERO ((insert RONE noalts_set) \ alts_set)") + apply(simp only:) + apply(subgoal_tac " (sum_list + (map rsize ( rdistinct rs (insert RZERO (insert RONE noalts_set \ alts_set))))) + \ (sum_list + (map rsize (RONE # rdistinct rs (insert RZERO (insert RONE noalts_set \ alts_set)))))") + apply (smt (verit, best) dual_order.trans insert_iff rrexp.distinct(15)) + apply (metis (no_types, opaque_lifting) add_Suc_right le_add_same_cancel2 list.simps(9) sum_list.Cons zero_le) + apply fastforce + apply fastforce + apply (metis Un_iff insert_absorb) + apply (metis UnE insertE insert_is_Un rdistinct.simps(2) rrexp.distinct(1)) + apply (meson UnCI rdistinct.simps(2)) + using rflts.simps(4) apply presburger + apply simp + apply(subgoal_tac "insert RONE (noalts_set \ corr_set) = (insert RONE noalts_set) \ corr_set") + apply(simp only:) + apply (metis Un_insert_left insertE rrexp.distinct(15)) + apply fastforce + apply(case_tac "a \ noalts_set") + apply simp + apply(subgoal_tac "a \ alts_set") + prefer 2 + apply blast + apply(case_tac "a \ corr_set") + apply(subgoal_tac "noalts_set \ corr_set = insert a ( noalts_set \ corr_set)") + prefer 2 + apply fastforce + apply(simp only:) + apply(subgoal_tac " sum_list + (map rsize (rdistinct (a # rs) (insert RZERO ((insert a noalts_set) \ alts_set)))) +\ + sum_list + (map rsize (rdistinct (a # rs) (insert RZERO (noalts_set \ alts_set))))") + + apply(subgoal_tac +"sum_list (map rsize (rdistinct (rflts (a # rs)) ((insert a noalts_set) \ corr_set))) +\ + sum_list (map rsize (rdistinct (a # rs) (insert RZERO ((insert a noalts_set) \ alts_set))))") + apply fastforce + apply simp + apply(subgoal_tac "(insert a (noalts_set \ alts_set)) = (insert a noalts_set) \ alts_set") + apply(simp only:) + apply(subgoal_tac "noalts_set \ corr_set = (insert a noalts_set) \ corr_set") + apply(simp only:) + apply (metis insertE rrexp.distinct(21)) + apply blast + + apply fastforce + apply force + apply simp + apply (metis Un_insert_left insert_iff rrexp.distinct(21)) + apply(case_tac "a \ noalts_set") + apply simp + apply(subgoal_tac "a \ alts_set") + prefer 2 + apply blast + apply(case_tac "a \ corr_set") + apply(subgoal_tac "noalts_set \ corr_set = insert a ( noalts_set \ corr_set)") + prefer 2 + apply fastforce + apply(simp only:) + apply(subgoal_tac " sum_list + (map rsize (rdistinct (a # rs) (insert RZERO ((insert a noalts_set) \ alts_set)))) +\ + sum_list + (map rsize (rdistinct (a # rs) (insert RZERO (noalts_set \ alts_set))))") + + apply(subgoal_tac +"sum_list (map rsize (rdistinct (rflts (a # rs)) ((insert a noalts_set) \ corr_set))) +\ + sum_list (map rsize (rdistinct (a # rs) (insert RZERO ((insert a noalts_set) \ alts_set))))") + apply fastforce + apply simp + apply(subgoal_tac "(insert a (noalts_set \ alts_set)) = (insert a noalts_set) \ alts_set") + apply(simp only:) + apply(subgoal_tac "noalts_set \ corr_set = (insert a noalts_set) \ corr_set") + apply(simp only:) + + + apply (metis insertE rrexp.distinct(25)) + apply blast + apply fastforce + apply force + apply simp + + apply (metis Un_insert_left insertE rrexp.distinct(25)) + + using Suc_le_mono flts_size_reduction_alts apply presburger + apply(case_tac "a \ noalts_set") + apply simp + apply(subgoal_tac "a \ alts_set") + prefer 2 + apply blast + apply(case_tac "a \ corr_set") + apply(subgoal_tac "noalts_set \ corr_set = insert a ( noalts_set \ corr_set)") + prefer 2 + apply fastforce + apply(simp only:) + apply(subgoal_tac " sum_list + (map rsize (rdistinct (a # rs) (insert RZERO ((insert a noalts_set) \ alts_set)))) +\ + sum_list + (map rsize (rdistinct (a # rs) (insert RZERO (noalts_set \ alts_set))))") + + apply(subgoal_tac +"sum_list (map rsize (rdistinct (rflts (a # rs)) ((insert a noalts_set) \ corr_set))) +\ + sum_list (map rsize (rdistinct (a # rs) (insert RZERO ((insert a noalts_set) \ alts_set))))") + apply fastforce + apply simp + apply(subgoal_tac "(insert a (noalts_set \ alts_set)) = (insert a noalts_set) \ alts_set") + apply(simp only:) + apply(subgoal_tac "noalts_set \ corr_set = (insert a noalts_set) \ corr_set") + apply(simp only:) + apply (metis insertE rrexp.distinct(29)) + + apply blast + + apply fastforce + apply force + apply simp + apply (metis Un_insert_left insert_iff rrexp.distinct(29)) + done + + + + lemma flts_vs_nflts: - shows "\r \ noalts_set. \xs. r \ RALTS xs - \ (\a \ alts_set. \xs. a = RALTS xs \ set xs \ corr_set) + shows "(\r \ noalts_set. \xs. r \ RALTS xs) + \ (\a \ alts_set. (\xs. a = RALTS xs \ set xs \ corr_set)) \ Suc (sum_list (map rsize (rdistinct ( rflts rs) (noalts_set \ corr_set) ))) - \ Suc (sum_list (map rsize (rdistinct rs (noalts_set \ alts_set) )))" - apply(induct rs arbitrary: noalts_set) + \ Suc (sum_list (map rsize (rdistinct rs (insert RZERO (noalts_set \ alts_set) ))))" + apply(induct rs arbitrary: noalts_set alts_set corr_set) apply simp + apply(case_tac a) + apply(case_tac "RZERO \ noalts_set") + apply simp + apply(subgoal_tac "RZERO \ alts_set") + apply simp + apply fastforce + apply(case_tac "RONE \ noalts_set") + apply simp + apply(subgoal_tac "RONE \ alts_set") + prefer 2 + apply fastforce + apply(case_tac "RONE \ corr_set") + apply(subgoal_tac "rflts (a # rs) = RONE # rflts rs") + apply(simp only:) + apply(subgoal_tac "rdistinct (RONE # rflts rs) (noalts_set \ corr_set) = + rdistinct (rflts rs) (noalts_set \ corr_set)") + apply(simp only:) + apply(subgoal_tac "rdistinct (RONE # rs) (insert RZERO (noalts_set \ alts_set)) = + RONE # (rdistinct rs (insert RONE (insert RZERO (noalts_set \ alts_set)))) ") + apply(simp only:) + apply(subgoal_tac "rdistinct (rflts rs) (noalts_set \ corr_set) = + rdistinct (rflts rs) (insert RONE (noalts_set \ corr_set))") + apply (simp only:) + apply(subgoal_tac "insert RONE (noalts_set \ corr_set) = (insert RONE noalts_set) \ corr_set") + apply(simp only:) + apply(subgoal_tac "insert RONE (insert RZERO (noalts_set \ alts_set)) = + insert RZERO ((insert RONE noalts_set) \ alts_set)") + apply(simp only:) + apply(subgoal_tac " Suc (sum_list + (map rsize ( rdistinct rs (insert RZERO (insert RONE noalts_set \ alts_set))))) + \ Suc (sum_list + (map rsize (RONE # rdistinct rs (insert RZERO (insert RONE noalts_set \ alts_set)))))") + apply (smt (verit, best) dual_order.trans insert_iff rrexp.distinct(15)) + apply (metis (no_types, opaque_lifting) add_Suc_right le_add_same_cancel2 list.simps(9) sum_list.Cons zero_le) + apply fastforce + apply fastforce + apply (metis Un_iff insert_absorb) + apply (metis UnE insertE insert_is_Un rdistinct.simps(2) rrexp.distinct(1)) + apply (meson UnCI rdistinct.simps(2)) + using rflts.simps(4) apply presburger + apply simp + apply(subgoal_tac "insert RONE (noalts_set \ corr_set) = (insert RONE noalts_set) \ corr_set") + apply(simp only:) + apply (metis Un_insert_left insertE rrexp.distinct(15)) + apply fastforce + apply(case_tac "a \ noalts_set") + apply simp + apply(subgoal_tac "a \ alts_set") + prefer 2 + apply blast + apply(case_tac "a \ corr_set") + apply(subgoal_tac "noalts_set \ corr_set = insert a ( noalts_set \ corr_set)") + prefer 2 + apply fastforce + apply(simp only:) + apply (metis add_mono_thms_linordered_semiring(1) flts_vs_nflts1 le_numeral_extra(4) plus_1_eq_Suc) + apply (metis add_mono_thms_linordered_semiring(1) flts_vs_nflts1 le_numeral_extra(4) plus_1_eq_Suc) + apply(case_tac "a \ noalts_set") + apply simp + apply(subgoal_tac "a \ alts_set") + prefer 2 + apply blast + apply(case_tac "a \ corr_set") + apply(subgoal_tac "noalts_set \ corr_set = insert a ( noalts_set \ corr_set)") + prefer 2 + apply fastforce + apply(simp only:) + apply (metis add_mono_thms_linordered_semiring(1) flts_vs_nflts1 le_numeral_extra(4) plus_1_eq_Suc) + apply (metis add_mono_thms_linordered_semiring(1) flts_vs_nflts1 le_numeral_extra(4) plus_1_eq_Suc) + prefer 2 + apply(case_tac "a \ noalts_set") + apply simp + apply(subgoal_tac "a \ alts_set") + prefer 2 + apply blast + apply(case_tac "a \ corr_set") + apply(subgoal_tac "noalts_set \ corr_set = insert a ( noalts_set \ corr_set)") + prefer 2 + apply fastforce + apply(simp only:) + apply (metis add_mono_thms_linordered_semiring(1) flts_vs_nflts1 le_numeral_extra(4) plus_1_eq_Suc) + apply (metis add_mono_thms_linordered_semiring(1) flts_vs_nflts1 le_numeral_extra(4) plus_1_eq_Suc) + using flts_size_reduction_alts apply presburger + done - sorry + + + + +(* apply(rutac x = "\a rs noalts_set alts_set corr_set. set xs ")*) + lemma distinct_simp_ineq_general: shows "rsimp ` no_simp = has_simp \ finite no_simp \Suc (sum_list (map rsize (rdistinct (map rsimp rs) has_simp))) @@ -73,10 +441,14 @@ apply(case_tac "rsimp a \ no_simp") apply(subgoal_tac "rsimp a \ has_simp") prefer 2 - apply (simp add: rev_image_eqI rsimp_idem) - sledgehammer[timeout = 100] - - sorry + apply (simp add: rev_image_eqI rsimp_idem) + apply simp + apply (metis finite_insert image_insert insert_absorb trans_le_add2) + apply(case_tac "rsimp a \ has_simp") + apply simp + apply (metis add_mono_thms_linordered_semiring(1) finite.insertI image_insert rsimp_mono) + apply simp + by (metis finite.insertI image_insert insert_absorb trans_le_add2) lemma not_mentioned_elem_distinct_strong: @@ -92,13 +464,40 @@ - +lemma larger_acc_smaller_distinct_res0: + shows " ss \ SS \ sum_list (map rsize (rdistinct rs SS)) \ sum_list (map rsize (rdistinct rs ss))" + apply(induct rs arbitrary: ss SS) + apply simp + apply(case_tac "a \ ss") + apply(subgoal_tac "a \ SS") + apply simp + apply blast + apply(case_tac "a \ SS") + apply simp + apply(subgoal_tac "insert a ss \ SS") + apply simp + apply (simp add: trans_le_add2) + apply blast + apply(simp) + apply(subgoal_tac "insert a ss \ insert a SS") + apply blast + by blast lemma without_flts_ineq: shows " Suc (sum_list (map rsize (rdistinct (rflts rs) {}) )) \ Suc (sum_list (map rsize (rdistinct ( rs ) {} )))" - by (metis empty_iff flts_vs_nflts sup_bot_left) +proof - + have " Suc (sum_list (map rsize (rdistinct (rflts rs) {}) )) \ + Suc (sum_list (map rsize (rdistinct rs (insert RZERO {}))))" + by (metis empty_iff flts_vs_nflts sup_bot_left) + also have "... \ Suc (sum_list (map rsize (rdistinct rs {})))" + by (simp add: larger_acc_smaller_distinct_res0) + finally show ?thesis sledgehammer + by blast +qed + + @@ -131,24 +530,7 @@ shows "a \ ss \ rdistinct (a # rs) ss = a # rdistinct rs (insert a ss) " by auto -lemma larger_acc_smaller_distinct_res0: - shows " ss \ SS \ sum_list (map rsize (rdistinct rs SS)) \ sum_list (map rsize (rdistinct rs ss))" - apply(induct rs arbitrary: ss SS) - apply simp - apply(case_tac "a \ ss") - apply(subgoal_tac "a \ SS") - apply simp - apply blast - apply(case_tac "a \ SS") - apply simp - apply(subgoal_tac "insert a ss \ SS") - apply simp - apply (simp add: trans_le_add2) - apply blast - apply(simp) - apply(subgoal_tac "insert a ss \ insert a SS") - apply blast - by blast + lemma larger_acc_smaller_distinct_res: @@ -393,7 +775,7 @@ - +unused_thms