# HG changeset patch # User Chengsong # Date 1648547822 -3600 # Node ID 37d14cbce020202c094d13aa65096d1f3706762e # Parent 6953d2786e7cdd2c5a36c5038b1bdb82a49cb57a recent diff -r 6953d2786e7c -r 37d14cbce020 thys2/ClosedForms.thy --- a/thys2/ClosedForms.thy Mon Mar 28 20:00:04 2022 +0100 +++ b/thys2/ClosedForms.thy Tue Mar 29 10:57:02 2022 +0100 @@ -505,8 +505,28 @@ inductive frewrites:: "rrexp list \ rrexp list \ bool" ("_ \f* _" [10, 10] 10) where - rs1[intro, simp]:"rs \f* rs" -| rs2[intro]: "\rs1 \f* rs2; rs2 \f rs3\ \ rs1 \f* rs3" + [intro, simp]:"rs \f* rs" +| [intro]: "\rs1 \f* rs2; rs2 \f rs3\ \ rs1 \f* rs3" + +inductive grewrite:: "rrexp list \ rrexp list \ bool" ("_ \g _" [10, 10] 10) + where + "(RZERO # rs) \g rs" +| "((RALTS rs) # rsa) \g (rs @ rsa)" +| "rs1 \g rs2 \ (r # rs1) \g (r # rs2)" +| "rsa @ [a] @ rsb @ [a] @ rsc \g rsa @ [a] @ rsb @ rsc" + + +inductive + grewrites:: "rrexp list \ rrexp list \ bool" ("_ \g* _" [10, 10] 10) +where + [intro, simp]:"rs \g* rs" +| [intro]: "\rs1 \g* rs2; rs2 \g rs3\ \ rs1 \g* rs3" +(* +inductive + frewrites2:: "rrexp list \ rrexp list \ bool" ("_ <\f* _" [10, 10] 10) +where + [intro]: "\rs1 \f* rs2; rs2 \f* rs1\ \ rs1 <\f* rs2" +*) lemma fr_in_rstar : "r1 \f r2 \ r1 \f* r2" using frewrites.intros(1) frewrites.intros(2) by blast @@ -560,8 +580,13 @@ apply (metis append.assoc append_Cons frewrite.intros(2) frewrites_append many_steps_later) using frewrites_cons by auto +lemma frewrites_middle: + shows "rs1 \f* rs2 \ r # (RALTS rs # rs1) \f* r # (rs @ rs1)" + by (simp add: fr_in_rstar frewrite.intros(2) frewrite.intros(3)) - +lemma frewrites_alt: + shows "rs1 \f* rs2 \ (RALT r1 r2) # rs1 \f* r1 # r2 # rs2" + by (metis Cons_eq_appendI append_self_conv2 frewrite.intros(2) frewrites_cons many_steps_later) lemma many_steps_later1: shows " \rs1 \f* rs2\ @@ -577,13 +602,14 @@ using frewrite.intros(1) many_steps_later apply blast apply(case_tac "x = x3") apply simp - using frewrites_cons apply presburger using frewrite.intros(1) many_steps_later apply fastforce apply(case_tac "rnullable x41") - apply simp - - + apply simp+ + apply (simp add: frewrites_alt) + apply (simp add: frewrites_cons) + apply (simp add: frewrites_append) + by (simp add: frewrites_cons) fun alt_set:: "rrexp \ rrexp set" @@ -596,49 +622,134 @@ lemma rd_flts_set: shows "rs1 \f* rs2 \ rdistinct rs1 (insert RZERO (rset \ (\(alt_set ` rset)))) \f* rdistinct rs2 (rset \ (\(alt_set ` rset)))" - by (meson frewrite.intros(2) frewrites.simps) + + oops + + lemma rd_flts_set2: shows "rs1 \f* rs2 \ rdistinct rs1 ((rset \ (\(alt_set ` rset)))) \f* rdistinct rs2 (rset \ (\(alt_set ` rset)))" - using frewrite.intros(2) by blast + oops -lemma rd_flts_incorrect: - shows "rs1 \f* rs2 \ rdistinct rs1 rset \f* rdistinct rs2 rset" - sledgehammer - by (smt (verit, ccfv_threshold) frewrites.simps) + lemma flts_does_rewrite: shows "rs1 \f* rs2 \ rflts rs1 = rflts rs2" oops -lemma rflts_fltsder_derflts: - shows "rflts (map rsimp (rdistinct (map (rder x3) (rflts rs)) rset)) = - rflts (map rsimp (rdistinct (rflts (map (rder x3) rs)) rset))" +lemma with_wo0_distinct: + shows "rdistinct rs rset \f* rdistinct rs (insert RZERO rset)" + apply(induct rs arbitrary: rset) + apply simp + apply(case_tac a) + apply(case_tac "RZERO \ rset") + apply simp+ + using fr_in_rstar frewrite.intros(1) apply presburger + apply (case_tac "RONE \ rset") + apply simp+ + using frewrites_cons apply presburger + apply(case_tac "a \ rset") + apply simp + apply (simp add: frewrites_cons) + apply(case_tac "a \ rset") + apply simp + apply (simp add: frewrites_cons) + apply(case_tac "a \ rset") + apply simp + apply (simp add: frewrites_cons) + apply(case_tac "a \ rset") + apply simp + apply (simp add: frewrites_cons) + done + +lemma rdistinct_concat: + shows "set rs \ rset \ rdistinct (rs @ rsa) rset = rdistinct rsa rset" + apply(induct rs) + apply simp+ + done + +lemma rdistinct_concat2: + shows "\r \ set rs. r \ rset \ rdistinct (rs @ rsa) rset = rdistinct rsa rset" + by (simp add: rdistinct_concat subsetI) + +lemma frewrite_with_distinct: + shows " \rs2 \f rs3\ + \ rdistinct rs2 + (insert RZERO (rset \ \ (alt_set ` rset))) \f* + rdistinct rs3 + (insert RZERO (rset \ \ (alt_set ` rset)))" + apply(induct rs2 rs3 rule: frewrite.induct) + apply(case_tac "RZERO \ (rset \ \ (alt_set ` rset))") + apply simp + apply simp + apply(case_tac "RALTS rs \ rset") + apply simp + apply(subgoal_tac "\r \ set rs. r \ \ (alt_set ` rset)") + apply(subgoal_tac " rdistinct (rs @ rsa) (insert RZERO (rset \ \ (alt_set ` rset))) = + rdistinct rsa (insert RZERO (rset \ \ (alt_set ` rset)))") + using frewrites.intros(1) apply presburger + apply (simp add: rdistinct_concat2) + apply simp + using alt_set.simps(1) apply blast + apply(case_tac "RALTS rs \ rset \ \(alt_set ` rset)") + + sorry +lemma frewrites_with_distinct: + shows "rs1 \f* rs2 \ + rs1 @ (rdistinct rsa (insert RZERO (set rs1 \ \(alt_set ` (set rs1) )))) \f* + rs2 @ (rdistinct rsb (insert RZERO (set rs2 \ \(alt_set ` (set rs2) ))))" + apply(induct rs1 rs2 rule: frewrites.induct) + apply simp + + + sorry + +(*a more refined notion of \* is needed, +this lemma fails when rs1 contains some RALTS rs where elements +of rs appear in later parts of rs1, which will be picked up by rs2 +and deduplicated*) +lemma wrong_frewrites_with_distinct2: + shows "rs1 \f* rs2 \ + (rdistinct rs1 {RZERO}) \f* rdistinct rs2 {RZERO}" + oops + +lemma frewrite_single_step: + shows " rs2 \f rs3 \ rsimp (RALTS rs2) = rsimp (RALTS rs3)" + apply(induct rs2 rs3 rule: frewrite.induct) + apply simp + using simp_flatten apply blast + by (metis (no_types, opaque_lifting) list.simps(9) rsimp.simps(2) simp_flatten2) + +lemma frewrites_equivalent_simp: + shows "rs1 \f* rs2 \ rsimp (RALTS rs1) = rsimp (RALTS rs2)" + apply(induct rs1 rs2 rule: frewrites.induct) + apply simp + using frewrite_single_step by presburger + +lemma frewrites_dB_wwo0_simp: + shows "rdistinct rs1 {RZERO} \f* rdistinct rs2 {RZERO} + \ rsimp (RALTS (rdistinct rs1 {})) = rsimp (RALTS (rdistinct rs2 {}))" + + sorry + + + lemma simp_der_flts: shows "rsimp (RALTS (rdistinct (map (rder x) (rflts rs)) {})) = rsimp (RALTS (rdistinct (rflts (map (rder x) rs)) {}))" - - apply(induct rs) - apply simp - apply(case_tac a) - apply simp+ - prefer 2 - apply simp - apply(case_tac "RZERO \ rset") - apply simp+ - using distinct_flts_no0 apply presburger - apply (case_tac "x = x3") - prefer 2 - apply simp - using distinct_flts_no0 apply presburger - apply(case_tac "RONE \ rset") - apply simp+ - - sorry + apply(subgoal_tac "map (rder x) (rflts rs) \f* rflts (map (rder x) rs)") + apply(subgoal_tac "rdistinct (map (rder x) (rflts rs)) {RZERO} + \f* rdistinct ( rflts (map (rder x) rs)) {RZERO}") + apply(subgoal_tac "rsimp (RALTS (rdistinct (map (rder x) (rflts rs)) {})) + = rsimp (RALTS ( rdistinct ( rflts (map (rder x) rs)) {}))") + apply meson + using frewrites_dB_wwo0_simp apply blast + using frewrites_with_distinct2 apply blast + using early_late_der_frewrites by blast lemma simp_der_pierce_flts: