thys2/ClosedForms.thy
changeset 471 23818853a710
parent 469 e5dd8cc0aa82
child 472 6953d2786e7c
equal deleted inserted replaced
470:7a8cef3f5234 471:23818853a710
   492   apply simp  
   492   apply simp  
   493   by (smt (verit, ccfv_threshold) Un_insert_right insert_iff list.simps(9) rdistinct.simps(2) rflts.simps(2) rflts.simps(3) rflts_def_idiot rrexp.distinct(7))
   493   by (smt (verit, ccfv_threshold) Un_insert_right insert_iff list.simps(9) rdistinct.simps(2) rflts.simps(2) rflts.simps(3) rflts_def_idiot rrexp.distinct(7))
   494 
   494 
   495 
   495 
   496 
   496 
       
   497 
       
   498 inductive frewrite:: "rrexp list \<Rightarrow> rrexp list \<Rightarrow> bool" ("_ \<leadsto>f _" [10, 10] 10)
       
   499   where
       
   500   "(RZERO # rs) \<leadsto>f rs"
       
   501 | "((RALTS rs) # rsa) \<leadsto>f (rs @ rsa)"
       
   502 | "rs1 \<leadsto>f rs2 \<Longrightarrow> (r # rs1) \<leadsto>f (r # rs2)"
       
   503 
       
   504 
       
   505 inductive 
       
   506   frewrites:: "rrexp list \<Rightarrow> rrexp list \<Rightarrow> bool" ("_ \<leadsto>f* _" [10, 10] 10)
       
   507 where 
       
   508   rs1[intro, simp]:"rs \<leadsto>f* rs"
       
   509 | rs2[intro]: "\<lbrakk>rs1 \<leadsto>f* rs2; rs2 \<leadsto>f rs3\<rbrakk> \<Longrightarrow> rs1 \<leadsto>f* rs3"
       
   510 
       
   511 lemma fr_in_rstar : "r1 \<leadsto>f r2 \<Longrightarrow> r1 \<leadsto>f* r2"
       
   512   using frewrites.intros(1) frewrites.intros(2) by blast
       
   513  
       
   514 lemma freal_trans[trans]: 
       
   515   assumes a1: "r1 \<leadsto>f* r2"  and a2: "r2 \<leadsto>f* r3"
       
   516   shows "r1 \<leadsto>f* r3"
       
   517   using a2 a1
       
   518   apply(induct r2 r3 arbitrary: r1 rule: frewrites.induct) 
       
   519   apply(auto)
       
   520   done
       
   521 
       
   522 
       
   523 lemma  many_steps_later: "\<lbrakk>r1 \<leadsto>f r2; r2 \<leadsto>f* r3 \<rbrakk> \<Longrightarrow> r1 \<leadsto>f* r3"
       
   524   by (meson fr_in_rstar freal_trans)
       
   525 
       
   526 
       
   527 lemma frewrite_append:
       
   528   shows "\<lbrakk> rsa \<leadsto>f rsb \<rbrakk> \<Longrightarrow> rs @ rsa \<leadsto>f rs @ rsb"
       
   529   apply(induct rs)
       
   530   apply simp+
       
   531   oops
       
   532 
       
   533 
       
   534 lemma frewrites_cons:
       
   535   shows "\<lbrakk> rsa \<leadsto>f* rsb \<rbrakk> \<Longrightarrow> r # rsa \<leadsto>f* r # rsb"
       
   536 
       
   537   oops
       
   538 
       
   539 lemma frewrites_append:
       
   540   shows " \<lbrakk>rsa \<leadsto>f* rsb\<rbrakk> \<Longrightarrow> (rs @ rsa) \<leadsto>f* (rs @ rsb)"
       
   541   apply(induct rsa rsb rule: frewrites.induct)
       
   542    apply simp
       
   543   oops
       
   544 
       
   545 
       
   546 
       
   547 lemma frewrites_concat:
       
   548   shows "\<lbrakk>rs1 \<leadsto>f rs2; rsa \<leadsto>f* rsb \<rbrakk> \<Longrightarrow> (rs1 @ rsa) \<leadsto>f* (rs2 @ rsb)"
       
   549   apply(induct rs1 rs2 rule: frewrite.induct)
       
   550     apply(simp)
       
   551   apply(subgoal_tac "(RZERO # rs @ rsa) \<leadsto>f (rs @ rsa)")
       
   552   prefer 2
       
   553   using frewrite.intros(1) apply blast
       
   554     apply(subgoal_tac "(rs @ rsa) \<leadsto>f* (rs @ rsb)")
       
   555   using many_steps_later apply blast
       
   556 
       
   557 
       
   558 
       
   559 
       
   560 
       
   561 
       
   562 
       
   563 lemma many_steps_later1:
       
   564   shows " \<lbrakk>rs1 \<leadsto>f* rs2\<rbrakk>
       
   565        \<Longrightarrow> (RONE # rs1) \<leadsto>f* (RONE # rs2)"
       
   566   oops
       
   567 
       
   568 lemma early_late_der_frewrites:
       
   569   shows "map (rder x) (rflts rs) \<leadsto>f* rflts (map (rder x) rs)"
       
   570   apply(induct rs)
       
   571    apply simp
       
   572   apply(case_tac a)
       
   573        apply simp+
       
   574   using frewrite.intros(1) many_steps_later apply blast
       
   575      apply(case_tac "x = x3")
       
   576      apply simp
       
   577   
       
   578 
       
   579 
       
   580 
       
   581 
       
   582 fun alt_set:: "rrexp \<Rightarrow> rrexp set"
       
   583   where
       
   584   "alt_set (RALTS rs) = set rs"
       
   585 | "alt_set r = {r}"
       
   586 
       
   587 
       
   588 
       
   589 lemma rd_flts_set:
       
   590   shows "rs1 \<leadsto>f* rs2 \<Longrightarrow> rdistinct rs1 (insert RZERO (rset \<union> (\<Union>(alt_set ` rset)))) \<leadsto>f*  
       
   591                           rdistinct rs2 (rset \<union> (\<Union>(alt_set ` rset)))"
       
   592   by (meson frewrite.intros(2) frewrites.simps)
       
   593   
       
   594 lemma rd_flts_set2:
       
   595   shows "rs1 \<leadsto>f* rs2 \<Longrightarrow> rdistinct rs1 ((rset \<union> (\<Union>(alt_set ` rset)))) \<leadsto>f*  
       
   596                           rdistinct rs2 (rset \<union> (\<Union>(alt_set ` rset)))"
       
   597   using frewrite.intros(2) by blast
       
   598 
       
   599 lemma rd_flts_incorrect:
       
   600   shows "rs1 \<leadsto>f* rs2 \<Longrightarrow> rdistinct rs1 rset \<leadsto>f* rdistinct rs2 rset"
       
   601   sledgehammer
       
   602   by (smt (verit, ccfv_threshold) frewrites.simps)
       
   603 
       
   604 lemma flts_does_rewrite:
       
   605   shows "rs1 \<leadsto>f* rs2 \<Longrightarrow> rflts rs1 = rflts rs2"
       
   606   oops
       
   607 
   497 lemma rflts_fltsder_derflts:
   608 lemma rflts_fltsder_derflts:
   498   shows "rflts (map rsimp (rdistinct (map (rder x3) (rflts rs)) rset)) = 
   609   shows "rflts (map rsimp (rdistinct (map (rder x3) (rflts rs)) rset)) = 
   499          rflts (map rsimp (rdistinct (rflts (map (rder x3) rs)) rset))"
   610          rflts (map rsimp (rdistinct (rflts (map (rder x3) rs)) rset))"
   500   sorry
   611   sorry
   501 
   612 
   502 
   613 
   503 lemma simp_der_flts:
   614 lemma simp_der_flts:
   504   shows "rsimp (RALTS (rdistinct (map (rder x) (rflts rs)) rset))= 
   615   shows "rsimp (RALTS (rdistinct (map (rder x) (rflts rs)) {})) = 
   505          rsimp (RALTS (rdistinct (rflts (map (rder x) rs)) rset))"
   616          rsimp (RALTS (rdistinct (rflts (map (rder x) rs)) {}))"
   506 
   617 
   507   apply(induct rs arbitrary: rset)
   618   apply(induct rs)
   508    apply simp
   619    apply simp
   509   apply(case_tac a)
   620   apply(case_tac a)
   510        apply simp
   621        apply simp+
       
   622       prefer 2
       
   623   apply simp
   511       apply(case_tac "RZERO \<in> rset")
   624       apply(case_tac "RZERO \<in> rset")
   512        apply simp+
   625        apply simp+
   513   using distinct_flts_no0 apply presburger
   626   using distinct_flts_no0 apply presburger
   514      apply (case_tac "x = x3")
   627      apply (case_tac "x = x3")
   515   prefer 2
   628   prefer 2
   520   
   633   
   521   sorry
   634   sorry
   522 
   635 
   523 
   636 
   524 lemma simp_der_pierce_flts:
   637 lemma simp_der_pierce_flts:
   525   shows " rsimp (rsimp_ALTs (rdistinct (map (rder x) (rflts (map (rsimp \<circ> (\<lambda>r. rders_simp r xs)) rs))) {})) =
   638   shows " rsimp (
   526            rsimp (rsimp_ALTs (rdistinct (rflts (map (rder x) (map (rsimp \<circ> (\<lambda>r. rders_simp r xs)) rs))) {}))"
   639 rsimp_ALTs (rdistinct (map (rder x) (rflts (map (rsimp \<circ> (\<lambda>r. rders_simp r xs)) rs))) {})
       
   640 ) =
       
   641           rsimp (
       
   642 rsimp_ALTs (rdistinct (rflts (map (rder x) (map (rsimp \<circ> (\<lambda>r. rders_simp r xs)) rs))) {})
       
   643 )"
       
   644   
   527   sorry
   645   sorry
   528 
   646 
   529 
   647 
   530 
   648 
   531 
   649