thys2/SizeBound3.thy
changeset 493 1481f465e6ea
parent 492 61eff2abb0b6
child 543 b2bea5968b89
equal deleted inserted replaced
492:61eff2abb0b6 493:1481f465e6ea
   115 | "erase (AALTs _ [r]) = (erase r)"
   115 | "erase (AALTs _ [r]) = (erase r)"
   116 | "erase (AALTs bs (r#rs)) = ALT (erase r) (erase (AALTs bs rs))"
   116 | "erase (AALTs bs (r#rs)) = ALT (erase r) (erase (AALTs bs rs))"
   117 | "erase (ASEQ _ r1 r2) = SEQ (erase r1) (erase r2)"
   117 | "erase (ASEQ _ r1 r2) = SEQ (erase r1) (erase r2)"
   118 | "erase (ASTAR _ r) = STAR (erase r)"
   118 | "erase (ASTAR _ r) = STAR (erase r)"
   119 
   119 
       
   120 fun rerase :: "arexp \<Rightarrow> rrexp"
       
   121 where
       
   122   "rerase AZERO = RZERO"
       
   123 | "rerase (AONE _) = RONE"
       
   124 | "rerase (ACHAR _ c) = RCHAR c"
       
   125 | "rerase (AALTs bs rs) = RALTS (map rerase rs)"
       
   126 | "rerase (ASEQ _ r1 r2) = RSEQ (rerase r1) (rerase r2)"
       
   127 | "rerase (ASTAR _ r) = RSTAR (rerase r)"
       
   128 
       
   129 
   120 
   130 
   121 fun fuse :: "bit list \<Rightarrow> arexp \<Rightarrow> arexp" where
   131 fun fuse :: "bit list \<Rightarrow> arexp \<Rightarrow> arexp" where
   122   "fuse bs AZERO = AZERO"
   132   "fuse bs AZERO = AZERO"
   123 | "fuse bs (AONE cs) = AONE (bs @ cs)" 
   133 | "fuse bs (AONE cs) = AONE (bs @ cs)" 
   124 | "fuse bs (ACHAR cs c) = ACHAR (bs @ cs) c"
   134 | "fuse bs (ACHAR cs c) = ACHAR (bs @ cs) c"
   234   shows "nullable (erase r) = bnullable r"
   244   shows "nullable (erase r) = bnullable r"
   235   apply(induct r rule: erase.induct)
   245   apply(induct r rule: erase.induct)
   236   apply(simp_all)
   246   apply(simp_all)
   237   done
   247   done
   238 
   248 
       
   249 lemma rbnullable_correctness:
       
   250   shows "rnullable (rerase r) = bnullable r"
       
   251   apply(induct r rule: rerase.induct)
       
   252        apply simp+
       
   253   done
       
   254 
       
   255 
   239 lemma erase_fuse:
   256 lemma erase_fuse:
   240   shows "erase (fuse bs r) = erase r"
   257   shows "erase (fuse bs r) = erase r"
   241   apply(induct r rule: erase.induct)
   258   apply(induct r rule: erase.induct)
   242   apply(simp_all)
   259   apply(simp_all)
   243   done
   260   done
   244 
   261 
       
   262 lemma rerase_fuse:
       
   263   shows "rerase (fuse bs r) = rerase r"
       
   264   apply(induct r)
       
   265        apply simp+
       
   266   done
       
   267 
       
   268 
       
   269 
       
   270 
   245 lemma erase_intern [simp]:
   271 lemma erase_intern [simp]:
   246   shows "erase (intern r) = r"
   272   shows "erase (intern r) = r"
   247   apply(induct r)
   273   apply(induct r)
   248   apply(simp_all add: erase_fuse)
   274   apply(simp_all add: erase_fuse)
   249   done
   275   done
   251 lemma erase_bder [simp]:
   277 lemma erase_bder [simp]:
   252   shows "erase (bder a r) = der a (erase r)"
   278   shows "erase (bder a r) = der a (erase r)"
   253   apply(induct r rule: erase.induct)
   279   apply(induct r rule: erase.induct)
   254   apply(simp_all add: erase_fuse bnullable_correctness)
   280   apply(simp_all add: erase_fuse bnullable_correctness)
   255   done
   281   done
       
   282 
       
   283 
       
   284   
       
   285 
   256 
   286 
   257 lemma erase_bders [simp]:
   287 lemma erase_bders [simp]:
   258   shows "erase (bders r s) = ders s (erase r)"
   288   shows "erase (bders r s) = ders s (erase r)"
   259   apply(induct s arbitrary: r )
   289   apply(induct s arbitrary: r )
   260   apply(simp_all)
   290   apply(simp_all)
   374   apply (metis (no_types, opaque_lifting) bmkepss.cases bnullable_correctness erase.simps(5) erase.simps(6) mkeps.simps(3) retrieve.simps(3) retrieve.simps(4))
   404   apply (metis (no_types, opaque_lifting) bmkepss.cases bnullable_correctness erase.simps(5) erase.simps(6) mkeps.simps(3) retrieve.simps(3) retrieve.simps(4))
   375   apply (metis r3)
   405   apply (metis r3)
   376   apply (metis (no_types, lifting) bmkepss.cases bnullable_correctness empty_iff erase.simps(6) list.set(1) mkeps.simps(3) retrieve.simps(4))
   406   apply (metis (no_types, lifting) bmkepss.cases bnullable_correctness empty_iff erase.simps(6) list.set(1) mkeps.simps(3) retrieve.simps(4))
   377   apply (metis r3)
   407   apply (metis r3)
   378   done
   408   done
   379       
   409 
       
   410 
   380 lemma bmkeps_retrieve:
   411 lemma bmkeps_retrieve:
   381   assumes "bnullable r"
   412   assumes "bnullable r"
   382   shows "bmkeps r = retrieve r (mkeps (erase r))"
   413   shows "bmkeps r = retrieve r (mkeps (erase r))"
   383   using assms
   414   using assms
   384   apply(induct r)
   415   apply(induct r)
   554   "bsimp_AALTs _ [] = AZERO"
   585   "bsimp_AALTs _ [] = AZERO"
   555 | "bsimp_AALTs bs1 [r] = fuse bs1 r"
   586 | "bsimp_AALTs bs1 [r] = fuse bs1 r"
   556 | "bsimp_AALTs bs1 rs = AALTs bs1 rs"
   587 | "bsimp_AALTs bs1 rs = AALTs bs1 rs"
   557 
   588 
   558 
   589 
       
   590 
       
   591 
   559 fun bsimp :: "arexp \<Rightarrow> arexp" 
   592 fun bsimp :: "arexp \<Rightarrow> arexp" 
   560   where
   593   where
   561   "bsimp (ASEQ bs1 r1 r2) = bsimp_ASEQ bs1 (bsimp r1) (bsimp r2)"
   594   "bsimp (ASEQ bs1 r1 r2) = bsimp_ASEQ bs1 (bsimp r1) (bsimp r2)"
   562 | "bsimp (AALTs bs1 rs) = bsimp_AALTs bs1 (distinctBy (flts (map bsimp rs)) erase {}) "
   595 | "bsimp (AALTs bs1 rs) = bsimp_AALTs bs1 (distinctBy (flts (map bsimp rs)) rerase {}) "
   563 | "bsimp r = r"
   596 | "bsimp r = r"
   564 
   597 
   565 
   598 
   566 fun 
   599 fun 
   567   bders_simp :: "arexp \<Rightarrow> string \<Rightarrow> arexp"
   600   bders_simp :: "arexp \<Rightarrow> string \<Rightarrow> arexp"
   585   "L (erase (ASEQ bs r1 r2)) = L (erase (bsimp_ASEQ bs r1 r2))"
   618   "L (erase (ASEQ bs r1 r2)) = L (erase (bsimp_ASEQ bs r1 r2))"
   586   apply(induct bs r1 r2 rule: bsimp_ASEQ.induct)
   619   apply(induct bs r1 r2 rule: bsimp_ASEQ.induct)
   587   apply(simp_all)
   620   apply(simp_all)
   588   by (metis erase_fuse fuse.simps(4))
   621   by (metis erase_fuse fuse.simps(4))
   589 
   622 
       
   623 lemma RL_bsimp_ASEQ:
       
   624   "RL (rerase (ASEQ bs r1 r2)) = RL (rerase (bsimp_ASEQ bs r1 r2))"
       
   625   apply(induct bs r1 r2 rule: bsimp_ASEQ.induct)
       
   626   apply simp+
       
   627   done
       
   628 
   590 lemma L_bsimp_AALTs:
   629 lemma L_bsimp_AALTs:
   591   "L (erase (AALTs bs rs)) = L (erase (bsimp_AALTs bs rs))"
   630   "L (erase (AALTs bs rs)) = L (erase (bsimp_AALTs bs rs))"
   592   apply(induct bs rs rule: bsimp_AALTs.induct)
   631   apply(induct bs rs rule: bsimp_AALTs.induct)
   593   apply(simp_all add: erase_fuse)
   632   apply(simp_all add: erase_fuse)
   594   done
   633   done
   595 
   634 
       
   635 lemma RL_bsimp_AALTs:
       
   636  "RL (rerase (AALTs bs rs)) = RL (rerase (bsimp_AALTs bs rs))"
       
   637   apply(induct bs rs rule: bsimp_AALTs.induct)
       
   638   apply(simp_all add: rerase_fuse)
       
   639   done
       
   640 
       
   641 lemma RL_rerase_AALTs:
       
   642   shows "RL (rerase (AALTs bs rs)) = \<Union> (RL ` rerase ` (set rs))"
       
   643   apply(induct rs)
       
   644    apply(simp)
       
   645   apply(simp)
       
   646   done
       
   647 
   596 lemma L_erase_AALTs:
   648 lemma L_erase_AALTs:
   597   shows "L (erase (AALTs bs rs)) = \<Union> (L ` erase ` (set rs))"
   649   shows "L (erase (AALTs bs rs)) = \<Union> (L ` erase ` (set rs))"
   598   apply(induct rs)
   650   apply(induct rs)
   599    apply(simp)
   651    apply(simp)
   600   apply(simp)
   652   apply(simp)
   601   apply(case_tac rs)
   653   apply(case_tac rs)
   602    apply(simp)
   654    apply(simp)
   603   apply(simp)
   655   apply(simp)
   604   done
   656   done
       
   657 
       
   658 
   605 
   659 
   606 lemma L_erase_flts:
   660 lemma L_erase_flts:
   607   shows "\<Union> (L ` erase ` (set (flts rs))) = \<Union> (L ` erase ` (set rs))"
   661   shows "\<Union> (L ` erase ` (set (flts rs))) = \<Union> (L ` erase ` (set rs))"
   608   apply(induct rs rule: flts.induct)
   662   apply(induct rs rule: flts.induct)
   609   apply(simp_all)
   663   apply(simp_all)
   610   apply(auto)
   664   apply(auto)
   611   using L_erase_AALTs erase_fuse apply auto[1]
   665   using L_erase_AALTs erase_fuse apply auto[1]
   612   by (simp add: L_erase_AALTs erase_fuse)
   666   by (simp add: L_erase_AALTs erase_fuse)
   613 
   667 
       
   668 
       
   669 lemma RL_erase_flts:
       
   670   shows "\<Union> (RL ` rerase ` (set (flts rs))) =
       
   671          \<Union> (RL ` rerase ` (set rs))"
       
   672   apply(induct rs rule: flts.induct)
       
   673         apply simp+
       
   674       apply auto
       
   675   apply (smt (verit) fuse.elims rerase.simps(2) rerase.simps(3) rerase.simps(4) rerase.simps(5) rerase.simps(6))
       
   676   by (smt (verit, best) fuse.elims rerase.simps(2) rerase.simps(3) rerase.simps(4) rerase.simps(5) rerase.simps(6))
       
   677 
       
   678 
       
   679 
       
   680 
   614 lemma L_erase_dB_acc:
   681 lemma L_erase_dB_acc:
   615   shows "(\<Union> (L ` acc) \<union> (\<Union> (L ` erase ` (set (distinctBy rs erase acc))))) 
   682   shows "(\<Union> (L ` acc) \<union> (\<Union> (L ` erase ` (set (distinctBy rs erase acc))))) 
   616             = \<Union> (L ` acc) \<union>  \<Union> (L ` erase ` (set rs))"
   683             = \<Union> (L ` acc) \<union>  \<Union> (L ` erase ` (set rs))"
   617   apply(induction rs arbitrary: acc)
   684   apply(induction rs arbitrary: acc)
   618   apply simp_all
   685   apply simp_all
   619   by (smt (z3) SUP_absorb UN_insert sup_assoc sup_commute)
   686   by (smt (z3) SUP_absorb UN_insert sup_assoc sup_commute)
   620 
   687 
       
   688 lemma RL_rerase_dB_acc:
       
   689   shows "(\<Union> (RL ` acc) \<union> (\<Union> (RL ` rerase ` (set (distinctBy rs rerase acc)))))
       
   690            = \<Union> (RL ` acc) \<union> \<Union> (RL ` rerase ` (set rs))"
       
   691   apply(induction rs arbitrary: acc)
       
   692    apply simp_all
       
   693     by (smt (z3) SUP_absorb UN_insert sup_assoc sup_commute)
       
   694 
       
   695 
       
   696 
   621 
   697 
   622 lemma L_erase_dB:
   698 lemma L_erase_dB:
   623   shows "(\<Union> (L ` erase ` (set (distinctBy rs erase {})))) = \<Union> (L ` erase ` (set rs))"
   699   shows "(\<Union> (L ` erase ` (set (distinctBy rs erase {})))) = \<Union> (L ` erase ` (set rs))"
   624   by (metis L_erase_dB_acc Un_commute Union_image_empty)
   700   by (metis L_erase_dB_acc Un_commute Union_image_empty)
   625 
   701 
       
   702 lemma RL_rerase_dB:
       
   703   shows "(\<Union> (RL ` rerase ` (set (distinctBy rs rerase {})))) = \<Union> (RL ` rerase ` (set rs))"
       
   704   by (metis RL_rerase_dB_acc Un_commute Union_image_empty)
       
   705 
       
   706 (*
   626 lemma L_bsimp_erase:
   707 lemma L_bsimp_erase:
   627   shows "L (erase r) = L (erase (bsimp r))"
   708   shows "L (erase r) = L (erase (bsimp r))"
   628   apply(induct r)
   709   apply(induct r)
   629   apply(simp)
   710   apply(simp)
   630   apply(simp)
   711   apply(simp)
   641   apply(subst (2)L_erase_AALTs)  
   722   apply(subst (2)L_erase_AALTs)  
   642   apply(subst L_erase_dB)
   723   apply(subst L_erase_dB)
   643   apply(subst L_erase_flts)
   724   apply(subst L_erase_flts)
   644   apply (simp add: L_erase_AALTs)
   725   apply (simp add: L_erase_AALTs)
   645   done
   726   done
   646 
   727 *)
   647 lemma L_bders_simp:
   728 
   648   shows "L (erase (bders_simp r s)) = L (erase (bders r s))"
   729 lemma RL_bsimp_rerase:
       
   730   shows "RL (rerase r) = RL (rerase (bsimp r))"
       
   731   apply(induct r)
       
   732   apply(simp)
       
   733   apply(simp)
       
   734   apply(simp)
       
   735   apply(auto simp add: Sequ_def)[1]
       
   736   apply(subst RL_bsimp_ASEQ[symmetric])
       
   737   apply(auto simp add: Sequ_def)[1]
       
   738   apply(subst (asm)  RL_bsimp_ASEQ[symmetric])
       
   739   apply(auto simp add: Sequ_def)[1]
       
   740   apply(simp)
       
   741   apply(subst RL_bsimp_AALTs[symmetric])
       
   742   defer
       
   743   apply(simp)
       
   744   using RL_erase_flts RL_rerase_dB by force
       
   745 
       
   746 lemma rder_correctness:
       
   747   shows "RL (rder c r) = Der c (RL r)"
       
   748   by (simp add: RL_rder)
       
   749 
       
   750 
       
   751 
       
   752 
       
   753 lemma asize_rsize:
       
   754   shows "rsize (rerase r) = asize r"
       
   755   apply(induct r)
       
   756        apply simp+
       
   757   
       
   758   apply (metis (mono_tags, lifting) comp_apply map_eq_conv)
       
   759   by simp
       
   760 
       
   761 lemma rb_nullability:
       
   762   shows " rnullable (rerase a) = bnullable a"
       
   763   apply(induct a)
       
   764        apply simp+
       
   765   done
       
   766 
       
   767 lemma fuse_anything_doesnt_matter:
       
   768   shows "rerase a = rerase (fuse bs a)"
       
   769   by (smt (verit) fuse.elims rerase.simps(2) rerase.simps(3) rerase.simps(4) rerase.simps(5) rerase.simps(6))
       
   770 
       
   771 
       
   772 
       
   773 lemma rder_bder_rerase:
       
   774   shows "rder c (rerase r ) = rerase (bder c r)"
       
   775   apply (induct r)
       
   776        apply simp+
       
   777     apply(case_tac "bnullable r1")
       
   778      apply simp
       
   779   apply (simp add: rb_nullability rerase_fuse)
       
   780   using rb_nullability apply presburger
       
   781    apply simp
       
   782   apply simp
       
   783   using rerase_fuse by presburger
       
   784 
       
   785 
       
   786 
       
   787 
       
   788 lemma RL_bder_preserved:
       
   789   shows "RL (rerase a1) = RL (rerase a2) \<Longrightarrow> RL (rerase (bder c a1 )) = RL (rerase (bder c a2))"
       
   790   by (metis rder_bder_rerase rder_correctness)
       
   791 
       
   792 
       
   793 lemma RL_bders_simp:
       
   794   shows "RL (rerase (bders_simp r s)) = RL (rerase (bders r s))"
   649   apply(induct s arbitrary: r rule: rev_induct)
   795   apply(induct s arbitrary: r rule: rev_induct)
   650   apply(simp)
   796   apply(simp)
   651   apply(simp)
   797   apply(simp add: bders_append)
   652   apply(simp add: ders_append)
       
   653   apply(simp add: bders_simp_append)
   798   apply(simp add: bders_simp_append)
   654   apply(simp add: L_bsimp_erase[symmetric])
   799   apply(simp add: RL_bsimp_rerase[symmetric])
   655   by (simp add: der_correctness)
   800   using RL_bder_preserved by blast
       
   801 
   656 
   802 
   657 
   803 
   658 lemma bmkeps_fuse:
   804 lemma bmkeps_fuse:
   659   assumes "bnullable r"
   805   assumes "bnullable r"
   660   shows "bmkeps (fuse bs r) = bs @ bmkeps r"
   806   shows "bmkeps (fuse bs r) = bs @ bmkeps r"
   670 
   816 
   671 
   817 
   672 lemma b4:
   818 lemma b4:
   673   shows "bnullable (bders_simp r s) = bnullable (bders r s)"
   819   shows "bnullable (bders_simp r s) = bnullable (bders r s)"
   674 proof -
   820 proof -
   675   have "L (erase (bders_simp r s)) = L (erase (bders r s))"
   821   have "RL (rerase (bders_simp r s)) = RL (rerase (bders r s))"
   676     using L_bders_simp by force
   822     by (simp add: RL_bders_simp)
   677   then show "bnullable (bders_simp r s) = bnullable (bders r s)"
   823   then show "bnullable (bders_simp r s) = bnullable (bders r s)"
   678     using bnullable_correctness nullable_correctness by blast
   824     using RL_rnullable rb_nullability by blast
   679 qed
   825 qed
   680 
   826 
   681 
   827 
   682 lemma bder_fuse:
   828 lemma bder_fuse:
   683   shows "bder c (fuse bs a) = fuse bs  (bder c a)"
   829   shows "bder c (fuse bs a) = fuse bs  (bder c a)"
   704 | ss1:  "[] s\<leadsto> []"
   850 | ss1:  "[] s\<leadsto> []"
   705 | ss2:  "rs1 s\<leadsto> rs2 \<Longrightarrow> (r # rs1) s\<leadsto> (r # rs2)"
   851 | ss2:  "rs1 s\<leadsto> rs2 \<Longrightarrow> (r # rs1) s\<leadsto> (r # rs2)"
   706 | ss3:  "r1 \<leadsto> r2 \<Longrightarrow> (r1 # rs) s\<leadsto> (r2 # rs)"
   852 | ss3:  "r1 \<leadsto> r2 \<Longrightarrow> (r1 # rs) s\<leadsto> (r2 # rs)"
   707 | ss4:  "(AZERO # rs) s\<leadsto> rs"
   853 | ss4:  "(AZERO # rs) s\<leadsto> rs"
   708 | ss5:  "(AALTs bs1 rs1 # rsb) s\<leadsto> ((map (fuse bs1) rs1) @ rsb)"
   854 | ss5:  "(AALTs bs1 rs1 # rsb) s\<leadsto> ((map (fuse bs1) rs1) @ rsb)"
   709 | ss6:  "erase a1 = erase a2 \<Longrightarrow> (rsa@[a1]@rsb@[a2]@rsc) s\<leadsto> (rsa@[a1]@rsb@rsc)"
   855 | ss6:  "rerase a1 = rerase a2 \<Longrightarrow> (rsa@[a1]@rsb@[a2]@rsc) s\<leadsto> (rsa@[a1]@rsb@rsc)"
   710 
   856 
   711 
   857 
   712 inductive 
   858 inductive 
   713   rrewrites:: "arexp \<Rightarrow> arexp \<Rightarrow> bool" ("_ \<leadsto>* _" [100, 100] 100)
   859   rrewrites:: "arexp \<Rightarrow> arexp \<Rightarrow> bool" ("_ \<leadsto>* _" [100, 100] 100)
   714 where 
   860 where 
   808   shows "(r1 # rs3) s\<leadsto>* (r2 # rs4)"
   954   shows "(r1 # rs3) s\<leadsto>* (r2 # rs4)"
   809   using assms
   955   using assms
   810   by (smt (verit, best) append_Cons append_Nil srewrites1 srewrites3 srewrites6 srewrites_trans)
   956   by (smt (verit, best) append_Cons append_Nil srewrites1 srewrites3 srewrites6 srewrites_trans)
   811 
   957 
   812 lemma ss6_stronger_aux:
   958 lemma ss6_stronger_aux:
   813   shows "(rs1 @ rs2) s\<leadsto>* (rs1 @ distinctBy rs2 erase (set (map erase rs1)))"
   959   shows "(rs1 @ rs2) s\<leadsto>* (rs1 @ distinctBy rs2 rerase (set (map rerase rs1)))"
   814   apply(induct rs2 arbitrary: rs1)
   960   apply(induct rs2 arbitrary: rs1)
   815    apply(auto)
   961    apply(auto)
   816   apply (smt (verit, best) append.assoc append.right_neutral append_Cons append_Nil split_list srewrite2(2) srewrites_trans ss6)
   962   apply (smt (verit, best) append.assoc append.right_neutral append_Cons append_Nil split_list srewrite2(2) srewrites_trans ss6)
   817   apply(drule_tac x="rs1 @ [a]" in meta_spec)
   963   apply(drule_tac x="rs1 @ [a]" in meta_spec)
   818   apply(simp)
   964   apply(simp)
   819   done
   965   done
   820 
   966 
   821 lemma ss6_stronger:
   967 lemma ss6_stronger:
   822   shows "rs1 s\<leadsto>* distinctBy rs1 erase {}"
   968   shows "rs1 s\<leadsto>* distinctBy rs1 rerase {}"
   823   using ss6_stronger_aux[of "[]" _] by auto
   969   by (metis append_Nil list.set(1) list.simps(8) ss6_stronger_aux)
   824 
   970 
   825 
   971 
   826 lemma rewrite_preserves_fuse: 
   972 lemma rewrite_preserves_fuse: 
   827   shows "r2 \<leadsto> r3 \<Longrightarrow> fuse bs r2 \<leadsto> fuse bs r3"
   973   shows "r2 \<leadsto> r3 \<Longrightarrow> fuse bs r2 \<leadsto> fuse bs r3"
   828   and   "rs2 s\<leadsto> rs3 \<Longrightarrow> map (fuse bs) rs2 s\<leadsto>* map (fuse bs) rs3"
   974   and   "rs2 s\<leadsto> rs3 \<Longrightarrow> map (fuse bs) rs2 s\<leadsto>* map (fuse bs) rs3"
   848     by (metis (mono_tags, lifting) comp_def fuse_append map_eq_conv rrewrite_srewrite.ss5 srewrites.simps)
   994     by (metis (mono_tags, lifting) comp_def fuse_append map_eq_conv rrewrite_srewrite.ss5 srewrites.simps)
   849 next
   995 next
   850   case (ss6 a1 a2 rsa rsb rsc)
   996   case (ss6 a1 a2 rsa rsb rsc)
   851   then show ?case 
   997   then show ?case 
   852     apply(simp only: map_append)
   998     apply(simp only: map_append)
   853     by (smt (verit, ccfv_threshold) erase_fuse list.simps(8) list.simps(9) rrewrite_srewrite.ss6 srewrites.simps)  
   999     by (smt (verit, ccfv_threshold) rerase_fuse list.simps(8) list.simps(9) rrewrite_srewrite.ss6 srewrites.simps)  
   854 qed (auto intro: rrewrite_srewrite.intros)
  1000 qed (auto intro: rrewrite_srewrite.intros)
   855 
  1001 
   856 
  1002 
   857 lemma rewrites_fuse:  
  1003 lemma rewrites_fuse:  
   858   assumes "r1 \<leadsto>* r2"
  1004   assumes "r1 \<leadsto>* r2"
   922 lemma bnullable0:
  1068 lemma bnullable0:
   923 shows "r1 \<leadsto> r2 \<Longrightarrow> bnullable r1 = bnullable r2" 
  1069 shows "r1 \<leadsto> r2 \<Longrightarrow> bnullable r1 = bnullable r2" 
   924   and "rs1 s\<leadsto> rs2 \<Longrightarrow> bnullables rs1 = bnullables rs2" 
  1070   and "rs1 s\<leadsto> rs2 \<Longrightarrow> bnullables rs1 = bnullables rs2" 
   925   apply(induct rule: rrewrite_srewrite.inducts)
  1071   apply(induct rule: rrewrite_srewrite.inducts)
   926   apply(auto simp add:  bnullable_fuse)
  1072   apply(auto simp add:  bnullable_fuse)
   927   apply (meson UnCI bnullable_fuse imageI)
  1073    apply (meson UnCI bnullable_fuse imageI)
   928   by (metis bnullable_correctness)
  1074   by (metis rb_nullability)
   929 
  1075 
   930 
  1076 
   931 lemma rewritesnullable: 
  1077 lemma rewritesnullable: 
   932   assumes "r1 \<leadsto>* r2" 
  1078   assumes "r1 \<leadsto>* r2" 
   933   shows "bnullable r1 = bnullable r2"
  1079   shows "bnullable r1 = bnullable r2"
   954   then show ?case
  1100   then show ?case
   955     by (simp add: bmkepss1 bmkepss2 bmkepss_fuse bnullable_fuse)
  1101     by (simp add: bmkepss1 bmkepss2 bmkepss_fuse bnullable_fuse)
   956 next
  1102 next
   957   case (ss6 a1 a2 rsa rsb rsc)
  1103   case (ss6 a1 a2 rsa rsb rsc)
   958   then show ?case
  1104   then show ?case
   959     by (smt (verit, best) append_Cons bmkeps.simps(3) bmkepss.simps(2) bmkepss1 bmkepss2 bnullable_correctness)
  1105     by (smt (z3) append_is_Nil_conv bmkepss1 bmkepss2 in_set_conv_decomp_first list.set_intros(1) rb_nullability set_ConsD)
   960 qed (auto)
  1106 qed (auto)
   961 
  1107 
   962 lemma rewrites_bmkeps: 
  1108 lemma rewrites_bmkeps: 
   963   assumes "r1 \<leadsto>* r2" "bnullable r1" 
  1109   assumes "r1 \<leadsto>* r2" "bnullable r1" 
   964   shows "bmkeps r1 = bmkeps r2"
  1110   shows "bmkeps r1 = bmkeps r2"
  1013 next
  1159 next
  1014   case (2 bs1 rs)
  1160   case (2 bs1 rs)
  1015   have IH: "\<And>x. x \<in> set rs \<Longrightarrow> x \<leadsto>* bsimp x" by fact
  1161   have IH: "\<And>x. x \<in> set rs \<Longrightarrow> x \<leadsto>* bsimp x" by fact
  1016   then have "rs s\<leadsto>* (map bsimp rs)" by (simp add: trivialbsimp_srewrites)
  1162   then have "rs s\<leadsto>* (map bsimp rs)" by (simp add: trivialbsimp_srewrites)
  1017   also have "... s\<leadsto>* flts (map bsimp rs)" by (simp add: fltsfrewrites) 
  1163   also have "... s\<leadsto>* flts (map bsimp rs)" by (simp add: fltsfrewrites) 
  1018   also have "... s\<leadsto>* distinctBy (flts (map bsimp rs)) erase {}" by (simp add: ss6_stronger) 
  1164   also have "... s\<leadsto>* distinctBy (flts (map bsimp rs)) rerase {}" by (simp add: ss6_stronger) 
  1019   finally have "AALTs bs1 rs \<leadsto>* AALTs bs1 (distinctBy (flts (map bsimp rs)) erase {})"
  1165   finally have "AALTs bs1 rs \<leadsto>* AALTs bs1 (distinctBy (flts (map bsimp rs)) rerase {})"
  1020     using contextrewrites0 by blast
  1166     using contextrewrites0 by auto
  1021   also have "... \<leadsto>* bsimp_AALTs  bs1 (distinctBy (flts (map bsimp rs)) erase {})"
  1167   also have "... \<leadsto>* bsimp_AALTs  bs1 (distinctBy (flts (map bsimp rs)) rerase {})"
  1022     by (simp add: bsimp_AALTs_rewrites)     
  1168     by (simp add: bsimp_AALTs_rewrites)     
  1023   finally show "AALTs bs1 rs \<leadsto>* bsimp (AALTs bs1 rs)" by simp
  1169   finally show "AALTs bs1 rs \<leadsto>* bsimp (AALTs bs1 rs)" by simp
  1024 qed (simp_all)
  1170 qed (simp_all)
  1025 
  1171 
  1026 
  1172 
  1105     using bder_fuse_list map_map rrewrite_srewrite.ss5 srewrites.simps by blast
  1251     using bder_fuse_list map_map rrewrite_srewrite.ss5 srewrites.simps by blast
  1106 next
  1252 next
  1107   case (ss6 a1 a2 bs rsa rsb)
  1253   case (ss6 a1 a2 bs rsa rsb)
  1108   then show ?case
  1254   then show ?case
  1109     apply(simp only: map_append)
  1255     apply(simp only: map_append)
  1110     by (smt (verit, best) erase_bder list.simps(8) list.simps(9) local.ss6 rrewrite_srewrite.ss6 srewrites.simps)
  1256     by (smt (verit, best) rder_bder_rerase list.simps(8) list.simps(9) local.ss6 rrewrite_srewrite.ss6 srewrites.simps)
  1111 qed
  1257 qed
  1112 
  1258 
  1113 lemma rewrites_preserves_bder: 
  1259 lemma rewrites_preserves_bder: 
  1114   assumes "r1 \<leadsto>* r2"
  1260   assumes "r1 \<leadsto>* r2"
  1115   shows "bder c r1 \<leadsto>* bder c r2"
  1261   shows "bder c r1 \<leadsto>* bder c r2"
  1157 
  1303 
  1158 theorem blexersimp_correctness: 
  1304 theorem blexersimp_correctness: 
  1159   shows "lexer r s = blexer_simp r s"
  1305   shows "lexer r s = blexer_simp r s"
  1160   using blexer_correctness main_blexer_simp by simp
  1306   using blexer_correctness main_blexer_simp by simp
  1161 
  1307 
  1162 
       
  1163 fun 
       
  1164   rerase :: "arexp \<Rightarrow> rrexp"
       
  1165 where
       
  1166   "rerase AZERO = RZERO"
       
  1167 | "rerase (AONE _) = RONE"
       
  1168 | "rerase (ACHAR _ c) = RCHAR c"
       
  1169 | "rerase (AALTs bs rs) = RALTS (map rerase rs)"
       
  1170 | "rerase (ASEQ _ r1 r2) = RSEQ (rerase r1) (rerase r2)"
       
  1171 | "rerase (ASTAR _ r) = RSTAR (rerase r)"
       
  1172 
       
  1173 
       
  1174 
       
  1175 lemma asize_rsize:
       
  1176   shows "rsize (rerase r) = asize r"
       
  1177   apply(induct r)
       
  1178        apply simp+
       
  1179   
       
  1180   apply (metis (mono_tags, lifting) comp_apply map_eq_conv)
       
  1181   by simp
       
  1182 
       
  1183 lemma rb_nullability:
       
  1184   shows " rnullable (rerase a) = bnullable a"
       
  1185   apply(induct a)
       
  1186        apply simp+
       
  1187   done
       
  1188 
       
  1189 lemma fuse_anything_doesnt_matter:
       
  1190   shows "rerase a = rerase (fuse bs a)"
       
  1191   by (smt (verit) fuse.elims rerase.simps(2) rerase.simps(3) rerase.simps(4) rerase.simps(5) rerase.simps(6))
       
  1192 
  1308 
  1193 
  1309 
  1194 lemma rerase_preimage:
  1310 lemma rerase_preimage:
  1195   shows "rerase r = RZERO \<Longrightarrow> r = AZERO"
  1311   shows "rerase r = RZERO \<Longrightarrow> r = AZERO"
  1196   apply(case_tac r)
  1312   apply(case_tac r)
  1305   "agood AZERO = False"
  1421   "agood AZERO = False"
  1306 | "agood (AONE cs) = True" 
  1422 | "agood (AONE cs) = True" 
  1307 | "agood (ACHAR cs c) = True"
  1423 | "agood (ACHAR cs c) = True"
  1308 | "agood (AALTs cs []) = False"
  1424 | "agood (AALTs cs []) = False"
  1309 | "agood (AALTs cs [r]) = False"
  1425 | "agood (AALTs cs [r]) = False"
  1310 | "agood (AALTs cs (r1#r2#rs)) = (distinct (map erase (r1 # r2 # rs)) \<and>(\<forall>r' \<in> set (r1#r2#rs). agood r' \<and> anonalt r'))"
  1426 | "agood (AALTs cs (r1#r2#rs)) = (distinct (map rerase (r1 # r2 # rs)) \<and>(\<forall>r' \<in> set (r1#r2#rs). agood r' \<and> anonalt r'))"
  1311 | "agood (ASEQ _ AZERO _) = False"
  1427 | "agood (ASEQ _ AZERO _) = False"
  1312 | "agood (ASEQ _ (AONE _) _) = False"
  1428 | "agood (ASEQ _ (AONE _) _) = False"
  1313 | "agood (ASEQ _ _ AZERO) = False"
  1429 | "agood (ASEQ _ _ AZERO) = False"
  1314 | "agood (ASEQ cs r1 r2) = (agood r1 \<and> agood r2)"
  1430 | "agood (ASEQ cs r1 r2) = (agood r1 \<and> agood r2)"
  1315 | "agood (ASTAR cs r) = True"
  1431 | "agood (ASTAR cs r) = True"
  1381   apply(case_tac list)
  1497   apply(case_tac list)
  1382     apply(simp_all)
  1498     apply(simp_all)
  1383   done
  1499   done
  1384 
  1500 
  1385 lemma good0:
  1501 lemma good0:
  1386   assumes "rs \<noteq> Nil" "\<forall>r \<in> set rs. anonalt r" "distinct (map erase rs)"
  1502   assumes "rs \<noteq> Nil" "\<forall>r \<in> set rs. anonalt r" "distinct (map rerase rs)"
  1387   shows "agood (bsimp_AALTs bs rs) \<longleftrightarrow> (\<forall>r \<in> set rs. agood r)"
  1503   shows "agood (bsimp_AALTs bs rs) \<longleftrightarrow> (\<forall>r \<in> set rs. agood r)"
  1388   using  assms
  1504   using  assms
  1389   apply(induct bs rs rule: bsimp_AALTs.induct)
  1505   apply(induct bs rs rule: bsimp_AALTs.induct)
  1390     apply simp+
  1506     apply simp+
  1391    apply (simp add: good_fuse)
  1507    apply (simp add: good_fuse)
  1393    prefer 2
  1509    prefer 2
  1394 
  1510 
  1395   
  1511   
  1396   using bsimp_AALTs.simps(3) apply presburger
  1512   using bsimp_AALTs.simps(3) apply presburger
  1397   apply(simp only:)
  1513   apply(simp only:)
  1398   apply(subgoal_tac "agood (AALTs bs1 (v # vb # vc)) = ((\<forall>r \<in> (set (v # vb # vc)). agood r \<and> anonalt r) \<and> distinct (map erase (v # vb # vc)))")
  1514   apply(subgoal_tac "agood (AALTs bs1 (v # vb # vc)) = ((\<forall>r \<in> (set (v # vb # vc)). agood r \<and> anonalt r) \<and> distinct (map rerase (v # vb # vc)))")
  1399   prefer 2
  1515   prefer 2
  1400   using agood.simps(6) apply blast
  1516   using agood.simps(6) apply blast
  1401   apply(simp only:)
  1517   apply(simp only:)
  1402   apply(subgoal_tac "((\<forall>r\<in>set (v # vb # vc). agood r \<and> anonalt r) \<and> distinct (map erase (v # vb # vc))) = ((\<forall>r\<in>set (v # vb # vc). agood r) \<and> distinct (map erase (v # vb # vc)))")
  1518   apply(subgoal_tac "((\<forall>r\<in>set (v # vb # vc). agood r \<and> anonalt r) \<and> distinct (map rerase (v # vb # vc))) = ((\<forall>r\<in>set (v # vb # vc). agood r) \<and> distinct (map rerase (v # vb # vc)))")
  1403   prefer 2
  1519   prefer 2
  1404   apply blast
  1520   apply blast
  1405   apply(simp only:)
  1521   apply(simp only:)
  1406   apply(subgoal_tac "((\<forall>r \<in> set (v # vb # vc). agood r) \<and> distinct (map erase (v # vb # vc))) = (\<forall> r \<in> set (v # vb # vc). agood r) ")
  1522   apply(subgoal_tac "((\<forall>r \<in> set (v # vb # vc). agood r) \<and> distinct (map rerase (v # vb # vc))) = (\<forall> r \<in> set (v # vb # vc). agood r) ")
  1407   prefer 2
  1523   prefer 2
  1408    apply(subgoal_tac "distinct (map erase (v # vb # vc)) = True")
  1524    apply(subgoal_tac "distinct (map rerase (v # vb # vc)) = True")
  1409   prefer 2
  1525     prefer 2
       
  1526   sledgehammer
  1410     apply blast
  1527     apply blast
  1411   prefer 2
  1528   prefer 2
  1412    apply force
  1529    apply force
  1413   apply simp
  1530   apply simp
  1414   done
  1531   done
  1626   apply(induct bs r arbitrary: rule: fuse.induct)
  1743   apply(induct bs r arbitrary: rule: fuse.induct)
  1627        apply(simp_all add: nn10)
  1744        apply(simp_all add: nn10)
  1628   done  
  1745   done  
  1629 
  1746 
  1630 lemma dB_keeps_property:
  1747 lemma dB_keeps_property:
  1631   shows "(\<forall>r \<in> set rs. P r) \<longrightarrow> (\<forall>r \<in> set (distinctBy rs erase rset). P r)"
  1748   shows "(\<forall>r \<in> set rs. P r) \<longrightarrow> (\<forall>r \<in> set (distinctBy rs rerase rset). P r)"
  1632   apply(induct rs arbitrary: rset)
  1749   apply(induct rs arbitrary: rset)
  1633    apply simp+
  1750    apply simp+
  1634   done
  1751   done
  1635 
  1752 
  1636 lemma dB_filters_out:
  1753 lemma dB_filters_out:
  1637   shows "erase a \<in> rset \<Longrightarrow> a \<notin> set (distinctBy rs erase (rset))"
  1754   shows "rerase a \<in> rset \<Longrightarrow> a \<notin> set (distinctBy rs rerase (rset))"
  1638   apply(induct rs arbitrary: rset)
  1755   apply(induct rs arbitrary: rset)
  1639    apply simp
  1756    apply simp
  1640   apply(case_tac "a = aa")
  1757   apply(case_tac "a = aa")
  1641    apply simp+
  1758    apply simp+
  1642   done
  1759   done
  1643 
  1760 
  1644 lemma dB_will_be_distinct:
  1761 lemma dB_will_be_distinct:
  1645   shows "distinct (distinctBy rs erase (insert (erase a) rset)) \<Longrightarrow> distinct (a #  (distinctBy rs erase (insert (erase a) rset)))"
  1762   shows "distinct (distinctBy rs rerase (insert (rerase a) rset)) \<Longrightarrow> distinct (a #  (distinctBy rs rerase (insert (rerase a) rset)))"
  1646   using dB_filters_out by force
  1763   using dB_filters_out by force
  1647   
  1764   
  1648 
  1765 
  1649 
       
  1650 lemma dB_does_the_job2:
  1766 lemma dB_does_the_job2:
  1651   shows "distinct (distinctBy rs erase rset)"
  1767   shows "distinct (distinctBy rs rerase rset)"
  1652   apply(induct rs arbitrary: rset)
  1768   apply(induct rs arbitrary: rset)
  1653    apply simp
  1769    apply simp
  1654   apply(case_tac "erase a \<in> rset")
  1770   apply(case_tac "rerase a \<in> rset")
  1655    apply simp
  1771    apply simp
  1656   apply(drule_tac x = "insert (erase a) rset" in meta_spec)
  1772   apply(drule_tac x = "insert (rerase a) rset" in meta_spec)
  1657   apply(subgoal_tac "distinctBy (a # rs) erase rset = a # distinctBy rs erase (insert (erase a ) rset)")
  1773   apply(subgoal_tac "distinctBy (a # rs) rerase rset = a # distinctBy rs rerase (insert (rerase a ) rset)")
  1658    apply(simp only:)
  1774    apply(simp only:)
  1659   using dB_will_be_distinct apply presburger
  1775   using dB_will_be_distinct apply presburger
  1660   by auto
  1776   by auto
  1661 
  1777 
  1662 lemma dB_does_more_job:
  1778 lemma dB_does_more_job:
  1663   shows "distinct (map erase (distinctBy rs erase rset))"
  1779   shows "distinct (map rerase (distinctBy rs rerase rset))"
  1664   apply(induct rs arbitrary:rset)
  1780   apply(induct rs arbitrary:rset)
  1665    apply simp
  1781    apply simp
  1666   apply(case_tac "erase a \<in> rset")
  1782   apply(case_tac "rerase a \<in> rset")
  1667    apply simp+
  1783    apply simp+
  1668   using dB_filters_out by force
  1784   using dB_filters_out by force
  1669 
  1785 
  1670 lemma dB_mono2:
  1786 lemma dB_mono2:
  1671   shows "rset \<subseteq> rset' \<Longrightarrow> distinctBy rs erase rset = [] \<Longrightarrow> distinctBy rs erase rset' = []"
  1787   shows "rset \<subseteq> rset' \<Longrightarrow> distinctBy rs rerase rset = [] \<Longrightarrow> distinctBy rs rerase rset' = []"
  1672   apply(induct rs arbitrary: rset rset')
  1788   apply(induct rs arbitrary: rset rset')
  1673    apply simp+
  1789    apply simp+
  1674   by (meson in_mono list.discI)
  1790   by (meson in_mono list.discI)
  1675 
  1791 
  1676 
  1792 
  1690   apply(rule nn1bb)
  1806   apply(rule nn1bb)
  1691   apply(auto)
  1807   apply(auto)
  1692   apply(subgoal_tac "\<forall>r \<in> set (flts (map bsimp x2a)). anonalt r")
  1808   apply(subgoal_tac "\<forall>r \<in> set (flts (map bsimp x2a)). anonalt r")
  1693   prefer 2
  1809   prefer 2
  1694   apply (metis (mono_tags, lifting) SizeBound3.nn1c image_iff list.set_map)
  1810   apply (metis (mono_tags, lifting) SizeBound3.nn1c image_iff list.set_map)
  1695   apply(subgoal_tac "\<forall>r \<in> set (distinctBy (flts (map bsimp x2a)) erase {}). anonalt r")
  1811   apply(subgoal_tac "\<forall>r \<in> set (distinctBy (flts (map bsimp x2a)) rerase {}). anonalt r")
  1696   prefer 2
  1812    prefer 2
  1697   using dB_keeps_property apply presburger
  1813   using dB_keeps_property apply presburger
  1698   by blast
  1814   by blast
  1699 
       
  1700 
  1815 
  1701 lemma induct_smaller_elem_list:
  1816 lemma induct_smaller_elem_list:
  1702   shows  "\<forall>r \<in> set list. asize r < Suc (sum_list (map asize list))"
  1817   shows  "\<forall>r \<in> set list. asize r < Suc (sum_list (map asize list))"
  1703   apply(induct list)
  1818   apply(induct list)
  1704    apply simp+
  1819    apply simp+
  1759   using SizeBound3.flts3b distinctBy.elims apply force
  1874   using SizeBound3.flts3b distinctBy.elims apply force
  1760   apply(subgoal_tac " Ball (set ( (flts (bsimp a # map bsimp list)))) anonalt")
  1875   apply(subgoal_tac " Ball (set ( (flts (bsimp a # map bsimp list)))) anonalt")
  1761        prefer 2
  1876        prefer 2
  1762   apply (metis Cons_eq_map_conv SizeBound3.nn1b SizeBound3.nn1c ex_map_conv)
  1877   apply (metis Cons_eq_map_conv SizeBound3.nn1b SizeBound3.nn1c ex_map_conv)
  1763   using dB_keeps_property apply presburger
  1878   using dB_keeps_property apply presburger
       
  1879   sledgehammer
       
  1880 
  1764   using dB_does_more_job apply presburger
  1881   using dB_does_more_job apply presburger
  1765   apply(subgoal_tac " Ball (set ( (flts (bsimp a # map bsimp list)) )) agood")
  1882   apply(subgoal_tac " Ball (set ( (flts (bsimp a # map bsimp list)) )) agood")
  1766   using dB_keeps_property apply presburger
  1883   using dB_keeps_property apply presburger
  1767     apply(subgoal_tac "\<forall>r \<in> (set (bsimp a # map bsimp list)). (agood r) \<or> (r = AZERO)")
  1884     apply(subgoal_tac "\<forall>r \<in> (set (bsimp a # map bsimp list)). (agood r) \<or> (r = AZERO)")
  1768   using SizeBound3.flts3 apply blast
  1885   using SizeBound3.flts3 apply blast
  1818 
  1935 
  1819 
  1936 
  1820 
  1937 
  1821 
  1938 
  1822 lemma good1a:
  1939 lemma good1a:
  1823   assumes "L (erase a) \<noteq> {}"
  1940   assumes "RL (rerase a) \<noteq> {}"
  1824   shows "agood (bsimp a)"
  1941   shows "agood (bsimp a)"
  1825   using good1 assms
  1942   using good1 assms
  1826   using L_bsimp_erase by force
  1943   using RL_bsimp_rerase by force
  1827   
  1944   
  1828 
  1945 
  1829 
  1946 
  1830 lemma flts_append:
  1947 lemma flts_append:
  1831   "flts (xs1 @ xs2) = flts xs1 @ flts xs2"
  1948   "flts (xs1 @ xs2) = flts xs1 @ flts xs2"
  1938 lemma bsimp_idem:
  2055 lemma bsimp_idem:
  1939   shows "bsimp (bsimp r) = bsimp r"
  2056   shows "bsimp (bsimp r) = bsimp r"
  1940   using test good1
  2057   using test good1
  1941   oops
  2058   oops
  1942 
  2059 
  1943 
  2060 (*
  1944 lemma erase_preimage1:
  2061 lemma erase_preimage1:
  1945   assumes "anonalt r"
  2062   assumes "anonalt r"
  1946   shows "erase r = ONE \<Longrightarrow> \<exists>bs. r = AONE bs"
  2063   shows "erase r = ONE \<Longrightarrow> \<exists>bs. r = AONE bs"
  1947   apply(case_tac r)
  2064   apply(case_tac r)
  1948   apply simp+
  2065   apply simp+
  2034         apply(subgoal_tac "agood r'2")
  2151         apply(subgoal_tac "agood r'2")
  2035          apply(subgoal_tac "rerase r'1 = rerase r1")
  2152          apply(subgoal_tac "rerase r'1 = rerase r1")
  2036   apply(subgoal_tac "rerase r'2 = rerase r2")
  2153   apply(subgoal_tac "rerase r'2 = rerase r2")
  2037   
  2154   
  2038   using rerase.simps(5) apply presburger
  2155   using rerase.simps(5) apply presburger
  2039   sledgehammer
  2156   oops
       
  2157 
  2040 
  2158 
  2041 
  2159 
  2042 lemma rerase_erase_good:
  2160 lemma rerase_erase_good:
  2043   assumes "agood r" "\<forall>r \<in> rset. agood r"
  2161   assumes "agood r" "\<forall>r \<in> rset. agood r"
  2044   shows "erase r \<in> erase ` rset \<Longrightarrow> rerase r \<in> rerase ` rset"
  2162   shows "erase r \<in> erase ` rset \<Longrightarrow> rerase r \<in> rerase ` rset"
  2112   assumes "\<forall>r \<in> set rs. anonalt r \<and> agood r"
  2230   assumes "\<forall>r \<in> set rs. anonalt r \<and> agood r"
  2113   shows "map rerase (distinctBy rs erase {}) = rdistinct (map rerase rs) {}"
  2231   shows "map rerase (distinctBy rs erase {}) = rdistinct (map rerase rs) {}"
  2114   apply(insert rerase_erase)
  2232   apply(insert rerase_erase)
  2115   by (metis assms image_empty)
  2233   by (metis assms image_empty)
  2116   
  2234   
  2117 
  2235 *)
  2118 
  2236 
  2119 
  2237 
  2120 
  2238 
  2121 
  2239 
  2122 
  2240 
  2123 lemma nonalt_flts : shows 
  2241 lemma nonalt_flts : shows 
  2124   "\<forall>r \<in> set (flts (map bsimp rs)). r \<noteq> AZERO"
  2242   "\<forall>r \<in> set (flts (map bsimp rs)). r \<noteq> AZERO"
  2125   using SizeBound3.qqq1 by force
  2243   using SizeBound3.qqq1 by force
  2126   
  2244 
  2127 
  2245 
  2128 
  2246 lemma rerase_map_bsimp:
  2129 
  2247   assumes "\<And> r. r \<in> set x2a \<Longrightarrow> rerase (bsimp r) = (rsimp \<circ> rerase) r"
  2130 lemma rerase_list_ders:
  2248   shows "  map rerase (map bsimp x2a) =  map (rsimp \<circ> rerase) x2a "
  2131   shows "\<And>x1 x2a.
  2249   using assms
  2132        (\<And>x2aa. x2aa \<in> set x2a \<Longrightarrow> rerase (bsimp x2aa) = rsimp (rerase x2aa)) \<Longrightarrow>
  2250   
  2133         (map rerase (distinctBy (flts (map bsimp x2a)) erase {})) =  (rdistinct (rflts (map (rsimp \<circ> rerase) x2a)) {})"
  2251   apply(induct x2a)
  2134   apply(subgoal_tac "\<forall>r \<in> set (flts (map bsimp x2a)). anonalt r ")
  2252    apply simp
       
  2253   apply(subgoal_tac "a \<in> set (a # x2a)")
  2135   prefer 2
  2254   prefer 2
  2136   apply (metis SizeBound3.nn1b SizeBound3.nn1c ex_map_conv)
  2255   apply (meson list.set_intros(1))
  2137   sledgehammer
  2256   apply(subgoal_tac "rerase (bsimp a ) = (rsimp \<circ> rerase) a")
  2138 
  2257   apply simp
  2139   sorry
  2258   by presburger
       
  2259 
       
  2260 
       
  2261 
       
  2262 lemma rerase_flts:
       
  2263   shows "map rerase (flts rs) = rflts (map rerase rs)"
       
  2264   apply(induct rs)
       
  2265    apply simp+
       
  2266   apply(case_tac a)
       
  2267        apply simp+
       
  2268    apply(simp add: rerase_fuse)
       
  2269   apply simp
       
  2270   done
       
  2271 
       
  2272 lemma rerase_dB:
       
  2273   shows "map rerase (distinctBy rs rerase acc) = rdistinct (map rerase rs) acc"
       
  2274   apply(induct rs arbitrary: acc)
       
  2275    apply simp+
       
  2276   done
       
  2277   
       
  2278 
       
  2279 
       
  2280 
       
  2281 lemma rerase_earlier_later_same:
       
  2282   assumes " \<And>r. r \<in> set x2a \<Longrightarrow> rerase (bsimp r) = rsimp (rerase r)"
       
  2283   shows " (map rerase (distinctBy (flts (map bsimp x2a)) rerase {})) =
       
  2284           (rdistinct (rflts (map (rsimp \<circ> rerase) x2a)) {})"
       
  2285   apply(subst rerase_dB)
       
  2286   apply(subst rerase_flts)
       
  2287   apply(subst rerase_map_bsimp)
       
  2288    apply auto
       
  2289   using assms
       
  2290   apply simp
       
  2291   done
       
  2292 
  2140 
  2293 
  2141 
  2294 
  2142 lemma simp_rerase:
  2295 lemma simp_rerase:
  2143   shows "rerase (bsimp a) = rsimp (rerase a)"
  2296   shows "rerase (bsimp a) = rsimp (rerase a)"
  2144   apply(induct  a)
  2297   apply(induct  a)
  2145   apply simp+
  2298   apply simp+
  2146   using rerase_bsimp_ASEQ apply presburger
  2299   using rerase_bsimp_ASEQ apply presburger
  2147   apply simp
  2300   apply simp
  2148    apply(subst rerase_bsimp_AALTs)
  2301    apply(subst rerase_bsimp_AALTs)
  2149   apply(subgoal_tac "map rerase (distinctBy (flts (map bsimp x2a)) erase {}) =  rdistinct (rflts (map (rsimp \<circ> rerase) x2a)) {}")  
  2302   apply(subgoal_tac "map rerase (distinctBy (flts (map bsimp x2a)) rerase {}) =  rdistinct (rflts (map (rsimp \<circ> rerase) x2a)) {}")  
       
  2303     apply simp
       
  2304   using rerase_earlier_later_same apply presburger
  2150   apply simp
  2305   apply simp
  2151   using rerase_list_ders apply blast
  2306   done
  2152   by simp
  2307 
       
  2308 
  2153 
  2309 
  2154 lemma rders_simp_size:
  2310 lemma rders_simp_size:
  2155   shows " rders_simp (rerase r) s  = rerase (bders_simp r s)"
  2311   shows " rders_simp (rerase r) s  = rerase (bders_simp r s)"
  2156   apply(induct s rule: rev_induct)
  2312   apply(induct s rule: rev_induct)
  2157    apply simp
  2313    apply simp