thys/BitCoded2.thy
changeset 338 c40348a77318
parent 337 50bb2c83eeb1
child 339 9d466b27b054
equal deleted inserted replaced
337:50bb2c83eeb1 338:c40348a77318
   830   assumes "\<Turnstile> v : der c (erase r)"
   830   assumes "\<Turnstile> v : der c (erase r)"
   831   shows "(bder c r) >> retrieve r (injval (erase r) c v)"
   831   shows "(bder c r) >> retrieve r (injval (erase r) c v)"
   832   using bder_retrieve[OF assms(1)] retrieve_code[OF assms(1)]
   832   using bder_retrieve[OF assms(1)] retrieve_code[OF assms(1)]
   833   by (metis assms contains6 erase_bder)
   833   by (metis assms contains6 erase_bder)
   834 
   834 
       
   835 
       
   836 lemma contains7a:
       
   837   assumes "\<Turnstile> v : der c (erase r)"
       
   838   shows "r >> retrieve r (injval (erase r) c v)"
       
   839   using assms
       
   840   apply -
       
   841   apply(drule Prf_injval)
       
   842   apply(drule contains6)
       
   843   apply(simp)
       
   844   done
   835 
   845 
   836 fun 
   846 fun 
   837   bders_simp :: "arexp \<Rightarrow> string \<Rightarrow> arexp"
   847   bders_simp :: "arexp \<Rightarrow> string \<Rightarrow> arexp"
   838 where
   848 where
   839   "bders_simp r [] = r"
   849   "bders_simp r [] = r"
  2019   apply(simp)
  2029   apply(simp)
  2020   apply(auto)[1]
  2030   apply(auto)[1]
  2021    apply (metis bnullable_correctness erase_fuse)+
  2031    apply (metis bnullable_correctness erase_fuse)+
  2022   done
  2032   done
  2023 
  2033 
  2024 lemma qq4:
  2034 
       
  2035 
       
  2036 lemma qq4a:
  2025   assumes "\<exists>x\<in>set list. bnullable x"
  2037   assumes "\<exists>x\<in>set list. bnullable x"
  2026   shows "\<exists>x\<in>set (flts list). bnullable x"
  2038   shows "\<exists>x\<in>set (flts list). bnullable x"
  2027   using assms
  2039   using assms
  2028   apply(induct list rule: flts.induct)
  2040   apply(induct list rule: flts.induct)
  2029         apply(auto)
  2041         apply(auto)
  2077      apply (metis bnullable_correctness erase_fuse imageE set_map)
  2089      apply (metis bnullable_correctness erase_fuse imageE set_map)
  2078   prefer 2
  2090   prefer 2
  2079   apply(case_tac "list")
  2091   apply(case_tac "list")
  2080      apply(simp)
  2092      apply(simp)
  2081     apply(simp)
  2093     apply(simp)
  2082    apply (simp add: qq4)
  2094    apply (simp add: qq4a)
  2083   apply(simp)
  2095   apply(simp)
  2084   apply(auto)
  2096   apply(auto)
  2085    apply(case_tac list)
  2097    apply(case_tac list)
  2086     apply(simp)
  2098     apply(simp)
  2087    apply(simp)
  2099    apply(simp)
  2090    apply(case_tac list)
  2102    apply(case_tac list)
  2091     apply(simp)
  2103     apply(simp)
  2092    apply(simp)
  2104    apply(simp)
  2093    apply (simp add: r0)
  2105    apply (simp add: r0)
  2094   apply(simp)
  2106   apply(simp)
  2095   using qq4 r1 r2 by auto
  2107   using qq4a r1 r2 by auto
  2096 
  2108 
  2097 
  2109 
  2098 
  2110 
  2099 lemma k1:
  2111 lemma k1:
  2100   assumes "\<And>x2aa. \<lbrakk>x2aa \<in> set x2a; bnullable x2aa\<rbrakk> \<Longrightarrow> bmkeps x2aa = bmkeps (bsimp x2aa)"
  2112   assumes "\<And>x2aa. \<lbrakk>x2aa \<in> set x2a; bnullable x2aa\<rbrakk> \<Longrightarrow> bmkeps x2aa = bmkeps (bsimp x2aa)"
  2143    apply(simp)
  2155    apply(simp)
  2144   apply(simp)
  2156   apply(simp)
  2145   thm q3
  2157   thm q3
  2146   apply(subst q3[symmetric])
  2158   apply(subst q3[symmetric])
  2147    apply simp
  2159    apply simp
  2148   using b3 qq4 apply auto[1]
  2160   using b3 qq4a apply auto[1]
  2149   apply(subst qs3)
  2161   apply(subst qs3)
  2150    apply simp
  2162    apply simp
  2151   using k1 by blast
  2163   using k1 by blast
  2152 
  2164 
  2153 thm bmkeps_retrieve bmkeps_simp bder_retrieve
  2165 thm bmkeps_retrieve bmkeps_simp bder_retrieve
  2187 
  2199 
  2188 lemma oo:
  2200 lemma oo:
  2189   shows "(case (blexer (der c r) s) of None \<Rightarrow> None | Some v \<Rightarrow> Some (injval r c v)) = blexer r (c # s)"
  2201   shows "(case (blexer (der c r) s) of None \<Rightarrow> None | Some v \<Rightarrow> Some (injval r c v)) = blexer r (c # s)"
  2190   apply(simp add: blexer_correctness)
  2202   apply(simp add: blexer_correctness)
  2191   done
  2203   done
  2192 
       
  2193 
       
  2194 
       
  2195 
       
  2196 
       
  2197 fun flts2 :: "char \<Rightarrow> arexp list \<Rightarrow> arexp list"
       
  2198   where 
       
  2199   "flts2 _ [] = []"
       
  2200 | "flts2 c (AZERO # rs) = flts2 c rs"
       
  2201 | "flts2 c (AONE _ # rs) = flts2 c rs"
       
  2202 | "flts2 c (ACHAR bs d # rs) = (if c = d then (ACHAR bs d # flts2 c rs) else flts2 c rs)"
       
  2203 | "flts2 c ((AALTs bs rs1) # rs) = (map (fuse bs) rs1) @ flts2 c rs"
       
  2204 | "flts2 c (ASEQ bs r1 r2 # rs) = (if (bnullable(r1) \<and> r2 = AZERO) then 
       
  2205     flts2 c rs
       
  2206     else ASEQ bs r1 r2 # flts2 c rs)"
       
  2207 | "flts2 c (r1 # rs) = r1 # flts2 c rs"
       
  2208 
       
  2209 lemma  flts2_k0:
       
  2210   shows "flts2 c (r # rs1) = flts2 c [r] @ flts2 c rs1"
       
  2211   apply(induct r arbitrary: c rs1)
       
  2212    apply(auto)
       
  2213   done
       
  2214 
       
  2215 lemma  flts2_k00:
       
  2216   shows "flts2 c (rs1 @ rs2) = flts2 c rs1 @ flts2 c rs2"
       
  2217   apply(induct rs1 arbitrary: rs2 c)
       
  2218    apply(auto)
       
  2219   by (metis append.assoc flts2_k0)
       
  2220 
       
  2221 
       
  2222 lemma
       
  2223   shows "flts (map (bder c) rs) = (map (bder c) (flts2 c rs))"
       
  2224   apply(induct c rs rule: flts2.induct)
       
  2225         apply(simp)
       
  2226        apply(simp)
       
  2227       apply(simp)
       
  2228      apply(simp)
       
  2229   apply(simp)
       
  2230     apply(auto simp add: bder_fuse)[1]
       
  2231   defer
       
  2232    apply(simp)
       
  2233   apply(simp del: flts2.simps)
       
  2234   apply(rule conjI)
       
  2235    prefer 2
       
  2236    apply(auto)[1]
       
  2237   apply(rule impI)
       
  2238   apply(subst flts2_k0)
       
  2239   apply(subst map_append)
       
  2240   apply(subst flts2.simps)
       
  2241   apply(simp only: flts2.simps)
       
  2242   apply(auto)
       
  2243 
       
  2244 
       
  2245 
  2204 
  2246 lemma XXX2_helper:
  2205 lemma XXX2_helper:
  2247   assumes "\<forall>y. asize y < Suc (sum_list (map asize rs)) \<longrightarrow> good y \<longrightarrow> bsimp y = y" 
  2206   assumes "\<forall>y. asize y < Suc (sum_list (map asize rs)) \<longrightarrow> good y \<longrightarrow> bsimp y = y" 
  2248           "\<forall>r'\<in>set rs. good r' \<and> nonalt r'"
  2207           "\<forall>r'\<in>set rs. good r' \<and> nonalt r'"
  2249   shows "flts (map (bsimp \<circ> bder c) (flts (map bsimp rs))) = flts (map (bsimp \<circ> bder c) rs)"
  2208   shows "flts (map (bsimp \<circ> bder c) (flts (map bsimp rs))) = flts (map (bsimp \<circ> bder c) rs)"
  2478   assumes "s \<in> L (erase r)"
  2437   assumes "s \<in> L (erase r)"
  2479   shows "retrieve r (flex (erase r) id s (mkeps (ders s (erase r)))) 
  2438   shows "retrieve r (flex (erase r) id s (mkeps (ders s (erase r)))) 
  2480             = retrieve (bders r s) (mkeps (erase (bders r s)))"
  2439             = retrieve (bders r s) (mkeps (erase (bders r s)))"
  2481   using assms
  2440   using assms
  2482   using LB LC lexer_correct_Some by auto
  2441   using LB LC lexer_correct_Some by auto
  2483 
       
  2484 lemma LXXX:
       
  2485   assumes "s \<in> (erase r) \<rightarrow> v" "s \<in> (erase (bsimp r)) \<rightarrow> v'"
       
  2486   shows "retrieve r v = retrieve (bsimp r) v'"
       
  2487   using  assms
       
  2488   apply -
       
  2489   thm LC
       
  2490   apply(subst LC)
       
  2491    apply(assumption)
       
  2492   apply(subst  L0[symmetric])
       
  2493   using bnullable_correctness lexer_correctness(2) lexer_flex apply fastforce
       
  2494   apply(subst (2) LC)
       
  2495    apply(assumption)
       
  2496   apply(subst (2)  L0[symmetric])
       
  2497   using bnullable_correctness lexer_correctness(2) lexer_flex apply fastforce
       
  2498    
       
  2499   oops  
       
  2500 
       
  2501 
       
  2502 lemma L07a:
       
  2503   assumes "s \<in> L (erase r)"
       
  2504   shows "retrieve (bsimp r) (flex (erase (bsimp r)) id s (mkeps (ders s (erase (bsimp r))))) 
       
  2505          = retrieve r (flex (erase r) id s (mkeps (ders s (erase r))))"
       
  2506   using assms
       
  2507   apply(induct s arbitrary: r)
       
  2508    apply(simp)
       
  2509   using L0a apply force
       
  2510   apply(drule_tac x="(bder a r)" in meta_spec)
       
  2511   apply(drule meta_mp)
       
  2512   apply (metis L_bsimp_erase erase_bder lexer.simps(2) lexer_correct_None option.case(1))
       
  2513   apply(drule sym)
       
  2514   apply(simp)
       
  2515   apply(subst (asm) bder_retrieve)
       
  2516    apply (metis Posix_Prf Posix_flex Posix_mkeps ders.simps(2) lexer_correct_None lexer_flex)
       
  2517   apply(simp only: flex_fun_apply)
       
  2518   apply(simp)
       
  2519   using L0[no_vars] bder_retrieve[no_vars] LA[no_vars] LC[no_vars] L07[no_vars]
       
  2520   oops
       
  2521 
       
  2522 lemma L08:
       
  2523   assumes "s \<in> L (erase r)"
       
  2524   shows "retrieve (bders (bsimp r) s) (mkeps (erase (bders (bsimp r) s)))
       
  2525          = retrieve (bders r s) (mkeps (erase (bders r s)))"
       
  2526   using assms
       
  2527   apply(induct s arbitrary: r)
       
  2528    apply(simp)
       
  2529   using L0 bnullable_correctness nullable_correctness apply blast
       
  2530   apply(simp add: bders_append)
       
  2531   apply(drule_tac x="(bder a (bsimp r))" in meta_spec)
       
  2532   apply(drule meta_mp)
       
  2533   apply (metis L_bsimp_erase erase_bder lexer.simps(2) lexer_correct_None option.case(1))
       
  2534   apply(drule sym)
       
  2535   apply(simp)
       
  2536   apply(subst LA)
       
  2537   apply (metis L0aa L_bsimp_erase Posix1(1) ders.simps(2) ders_correctness erase_bder erase_bders mkeps_nullable nullable_correctness)
       
  2538   apply(subst LA)
       
  2539   using lexer_correct_None lexer_flex mkeps_nullable apply force
       
  2540   
       
  2541   using L0[no_vars] bder_retrieve[no_vars] LA[no_vars] LC[no_vars] L07[no_vars]
       
  2542 
       
  2543 thm L0[no_vars] bder_retrieve[no_vars] LA[no_vars] LC[no_vars] L07[no_vars]
       
  2544   oops
       
  2545 
       
  2546 lemma test:
       
  2547   assumes "s = [c]"
       
  2548   shows "retrieve (bders r s) v = XXX" and "YYY = retrieve r (flex (erase r) id s v)"
       
  2549   using assms
       
  2550    apply(simp only: bders.simps)
       
  2551    defer
       
  2552   using assms
       
  2553    apply(simp only: flex.simps id_simps)
       
  2554   using  L0[no_vars] bder_retrieve[no_vars] LA[no_vars] LC[no_vars] 
       
  2555   find_theorems "retrieve (bders _ _) _"
       
  2556   find_theorems "retrieve _ (mkeps _)"
       
  2557   oops
       
  2558 
       
  2559 lemma L06X:
       
  2560   assumes "bnullable (bder c a)"
       
  2561   shows "bmkeps (bder c (bsimp a)) = bmkeps (bder c a)"
       
  2562   using assms
       
  2563   apply(induct a arbitrary: c)
       
  2564        apply(simp)
       
  2565       apply(simp)
       
  2566      apply(simp)
       
  2567     prefer 3
       
  2568     apply(simp)
       
  2569    prefer 2
       
  2570    apply(simp)
       
  2571   
       
  2572    defer
       
  2573   oops
       
  2574 
  2442 
  2575 lemma L06_2:
  2443 lemma L06_2:
  2576   assumes "bnullable (bders a [c,d])"
  2444   assumes "bnullable (bders a [c,d])"
  2577   shows "bmkeps (bders (bsimp a) [c,d]) = bmkeps (bsimp (bders (bsimp a) [c,d]))"
  2445   shows "bmkeps (bders (bsimp a) [c,d]) = bmkeps (bsimp (bders (bsimp a) [c,d]))"
  2578   using assms
  2446   using assms
  2604 
  2472 
  2605 lemma LX0:
  2473 lemma LX0:
  2606   assumes "s \<in> L r"
  2474   assumes "s \<in> L r"
  2607   shows "decode (bmkeps (bders (intern r) s)) r = Some(flex r id s (mkeps (ders s r)))"
  2475   shows "decode (bmkeps (bders (intern r) s)) r = Some(flex r id s (mkeps (ders s r)))"
  2608   by (metis assms blexer_correctness blexer_def lexer_correct_None lexer_flex)
  2476   by (metis assms blexer_correctness blexer_def lexer_correct_None lexer_flex)
  2609 
       
  2610 
       
  2611 lemma L02_bders2:
       
  2612   assumes "bnullable (bders a s)" "s = [c]"
       
  2613   shows "retrieve (bders (bsimp a) s) (mkeps (erase (bders (bsimp a) s)))  =
       
  2614          retrieve (bders a s) (mkeps (erase (bders a s)))"
       
  2615   using assms
       
  2616   apply(simp)
       
  2617   
       
  2618   apply(induct s arbitrary: a)
       
  2619    apply(simp)
       
  2620   using L0 apply auto[1]
       
  2621   oops
       
  2622 
       
  2623 thm bmkeps_retrieve bmkeps_simp Posix_mkeps
       
  2624 
       
  2625 lemma WQ1:
       
  2626   assumes "s \<in> L (der c r)"
       
  2627   shows "s \<in> der c r \<rightarrow> mkeps (ders s (der c r))"
       
  2628   using assms
       
  2629   oops
       
  2630 
       
  2631 lemma L02_bsimp:
       
  2632   assumes "bnullable (bders a s)"
       
  2633   shows "retrieve (bsimp a) (flex (erase (bsimp a)) id s (mkeps (erase (bders (bsimp a) s)))) =
       
  2634          retrieve a (flex (erase a) id s (mkeps (erase (bders a s))))"
       
  2635   using assms
       
  2636   apply(induct s arbitrary: a)
       
  2637    apply(simp)
       
  2638    apply (simp add: L0)
       
  2639   apply(simp)
       
  2640   apply(drule_tac x="bder a aa" in meta_spec)
       
  2641   apply(simp)
       
  2642   apply(subst (asm) bder_retrieve)
       
  2643   using Posix_Prf Posix_flex Posix_mkeps bnullable_correctness apply fastforce
       
  2644   apply(simp add: flex_fun_apply)
       
  2645   apply(drule sym)
       
  2646   apply(simp)
       
  2647   apply(subst flex_injval)
       
  2648   apply(subst bder_retrieve[symmetric])
       
  2649   apply (metis L_bsimp_erase Posix_Prf Posix_flex Posix_mkeps bders.simps(2) bnullable_correctness ders.simps(2) erase_bders lexer_correct_None lexer_flex option.distinct(1))
       
  2650   apply(simp only: erase_bder[symmetric] erase_bders[symmetric])  
       
  2651   apply(subst LB_sym[symmetric])
       
  2652    apply(simp)
       
  2653   oops
       
  2654 
  2477 
  2655 lemma L1:
  2478 lemma L1:
  2656   assumes "s \<in> r \<rightarrow> v" 
  2479   assumes "s \<in> r \<rightarrow> v" 
  2657   shows "decode (bmkeps (bders (intern r) s)) r = Some v"
  2480   shows "decode (bmkeps (bders (intern r) s)) r = Some v"
  2658   using assms
  2481   using assms
  2758   apply (simp add: good_SEQ test2)
  2581   apply (simp add: good_SEQ test2)
  2759   (* AALTs case *)
  2582   (* AALTs case *)
  2760   apply(simp)
  2583   apply(simp)
  2761   using test2 by fastforce
  2584   using test2 by fastforce
  2762 
  2585 
  2763 lemma XXX2a_long_without_good:
       
  2764   assumes "a = AALTs bs0  [AALTs bs1 [AALTs bs2 [ASTAR [] (AONE bs7), AONE bs6, ASEQ bs3 (ACHAR bs4 d) (AONE bs5)]]]" 
       
  2765   shows "bsimp (bder c (bsimp a)) = bsimp (bder c a)"
       
  2766         "bsimp (bder c (bsimp a)) = XXX"
       
  2767         "bsimp (bder c a) = YYY"
       
  2768   using  assms
       
  2769     apply(simp)
       
  2770   using  assms
       
  2771    apply(simp)
       
  2772    prefer 2
       
  2773   using  assms
       
  2774    apply(simp)
       
  2775   oops
       
  2776 
  2586 
  2777 lemma bder_bsimp_AALTs:
  2587 lemma bder_bsimp_AALTs:
  2778   shows "bder c (bsimp_AALTs bs rs) = bsimp_AALTs bs (map (bder c) rs)"
  2588   shows "bder c (bsimp_AALTs bs rs) = bsimp_AALTs bs (map (bder c) rs)"
  2779   apply(induct bs rs rule: bsimp_AALTs.induct)
  2589   apply(induct bs rs rule: bsimp_AALTs.induct)
  2780     apply(simp)
  2590     apply(simp)
  2808    prefer 2
  2618    prefer 2
  2809    apply (metis n0 nn1b test2)
  2619    apply (metis n0 nn1b test2)
  2810   by (metis flts_fuse flts_nothing)
  2620   by (metis flts_fuse flts_nothing)
  2811 
  2621 
  2812 
  2622 
  2813 lemma PP:
       
  2814   assumes "bnullable (bders r s)" 
       
  2815   shows "bmkeps (bders (bsimp r) s) = bmkeps (bders r s)"
       
  2816   using assms
       
  2817   apply(induct s arbitrary: r)
       
  2818    apply(simp)
       
  2819   using bmkeps_simp apply auto[1]
       
  2820   apply(simp add: bders_append bders_simp_append)
       
  2821   oops
       
  2822 
       
  2823 lemma PP:
       
  2824   assumes "bnullable (bders r s)"
       
  2825   shows "bmkeps (bders_simp (bsimp r) s) = bmkeps (bders r s)"
       
  2826   using assms
       
  2827   apply(induct s arbitrary: r rule: rev_induct)
       
  2828    apply(simp)
       
  2829   using bmkeps_simp apply auto[1]
       
  2830   apply(simp add: bders_append bders_simp_append)
       
  2831   apply(drule_tac x="bder a (bsimp r)" in meta_spec)
       
  2832   apply(drule_tac meta_mp)
       
  2833    defer
       
  2834   oops
       
  2835 
       
  2836 
       
  2837 lemma
       
  2838   assumes "asize (bsimp a) = asize a"  "a = AALTs bs [AALTs bs2 [], AZERO, AONE bs3]"
       
  2839   shows "bsimp a = a"
       
  2840   using assms
       
  2841   apply(simp)
       
  2842   oops
       
  2843 
       
  2844 
       
  2845 lemma iii:
  2623 lemma iii:
  2846   assumes "bsimp_AALTs bs rs \<noteq> AZERO"
  2624   assumes "bsimp_AALTs bs rs \<noteq> AZERO"
  2847   shows "rs \<noteq> []"
  2625   shows "rs \<noteq> []"
  2848   using assms
  2626   using assms
  2849   apply(induct bs  rs rule: bsimp_AALTs.induct)
  2627   apply(induct bs  rs rule: bsimp_AALTs.induct)
  2880   
  2658   
  2881   
  2659   
  2882 
  2660 
  2883 
  2661 
  2884 (* CT *)
  2662 (* CT *)
  2885 
       
  2886 lemma CTU:
       
  2887   shows "bsimp_AALTs bs as = li bs as"
       
  2888   apply(induct bs as rule: li.induct)
       
  2889     apply(auto)
       
  2890   done
       
  2891 
       
  2892 find_theorems "bder _ (bsimp_AALTs _ _)"
       
  2893 
  2663 
  2894 lemma CTa:
  2664 lemma CTa:
  2895   assumes "\<forall>r \<in> set as. nonalt r \<and> r \<noteq> AZERO"
  2665   assumes "\<forall>r \<in> set as. nonalt r \<and> r \<noteq> AZERO"
  2896   shows  "flts as = as"
  2666   shows  "flts as = as"
  2897   using assms
  2667   using assms
  2945   shows "asize a < Suc (sum_list (map asize as))"
  2715   shows "asize a < Suc (sum_list (map asize as))"
  2946   using assms
  2716   using assms
  2947   apply(induct as arbitrary: a)
  2717   apply(induct as arbitrary: a)
  2948    apply(auto)
  2718    apply(auto)
  2949   using le_add2 le_less_trans not_less_eq by blast
  2719   using le_add2 le_less_trans not_less_eq by blast
  2950   
  2720 
  2951 
  2721 lemma PPP:
  2952 lemma XXX2a_long_without_good:
  2722   assumes "\<Turnstile> v : ders s r"
  2953   shows "bsimp (bder c (bsimp a)) = bsimp (bder c a)"
  2723   shows "bders (intern r) s >> code v"
  2954   apply(induct a arbitrary: c taking: "\<lambda>a. asize a" rule: measure_induct)
  2724   using  assms
  2955   apply(case_tac x)
  2725   apply(induct s arbitrary: r v rule: rev_induct)
  2956        apply(simp)
  2726    apply(simp)
  2957       apply(simp)
  2727    apply (simp add: Posix_Prf contains2)
  2958      apply(simp)
  2728   apply(simp add: bders_append ders_append flex_append)
  2959   prefer 3
  2729   apply(frule Prf_injval)
  2960     apply(simp)
  2730   apply(drule meta_spec)
  2961   (* AALT case *)
  2731   apply(drule meta_spec)
  2962    prefer 2
  2732   apply(drule meta_mp)
  2963    apply(simp del: bsimp.simps)
  2733    apply(assumption)
  2964    apply(subst (2) CT1)
  2734   apply(subst retrieve_code)
  2965    apply(subst CT_exp)
  2735    apply(assumption)
  2966     apply(auto)[1]
  2736   apply(subst (asm) retrieve_code)
  2967   using asize_set apply blast
  2737    apply(assumption)
  2968    apply(subst CT1[symmetric])
  2738   using contains7 contains7a contains6 retrieve_code
  2969   apply(simp)
  2739   apply(rule contains7)
  2970   oops
  2740   
  2971 
  2741   find_theorems "bder _ _ >> _"
  2972 lemma YY:
  2742   find_theorems "code _ = _"
  2973   assumes "flts (map bsimp as1) = xs"
  2743   find_theorems "\<Turnstile> _ : der _ _"
  2974   shows "flts (map bsimp (map (fuse bs1) as1)) = map (fuse bs1) xs"
  2744   
  2975   using assms
  2745   
  2976   apply(induct as1 arbitrary: bs1 xs)
  2746 
  2977    apply(simp)
  2747   find_theorems "_ >> (code _)"
  2978   apply(auto)
  2748   apply(induct s arbitrary: a bs rule: rev_induct)
  2979   by (metis bsimp_fuse flts_fuse k0 list.simps(9))
  2749    apply(simp)
  2980   
  2750   apply(simp add: bders_simp_append bders_append)
  2981 
  2751   apply(rule contains55)
  2982 lemma flts_nonalt:
  2752   find_theorems "bder _ _ >> _"
  2983   assumes "flts (map bsimp xs) = ys"
  2753   apply(drule_tac x="bder a aa" in meta_spec)
  2984   shows "\<forall>y \<in> set ys. nonalt y"
  2754   apply(drule_tac x="bs" in meta_spec)
  2985   using assms
  2755   apply(simp)
  2986   apply(induct xs arbitrary: ys)
  2756   apply(rule contains55)
  2987    apply(auto)
  2757   find_theorems "bsimp _ >> _"
  2988   apply(case_tac xs)
       
  2989    apply(auto)
       
  2990   using flts2 good1 apply fastforce
       
  2991   by (smt ex_map_conv list.simps(9) nn1b nn1c)
       
  2992 
       
  2993 
       
  2994 lemma WWW3:
       
  2995   shows "flts [bsimp_AALTs bs1 (flts (map bsimp as1))] =
       
  2996          flts (map bsimp (map (fuse bs1) as1))"
       
  2997   by (metis CT0 YY flts_nonalt flts_nothing qqq1)
       
  2998 
       
  2999 
       
  3000 
       
  3001 lemma WWW5:
       
  3002   shows "map (bsimp \<circ> bder c) as1 = map bsimp (map (bder c) as1)"
       
  3003   apply(induct as1)
       
  3004    apply(auto)
       
  3005   done
       
  3006 
       
  3007 lemma big0:
       
  3008   shows "bsimp (AALT x51 (AALTs bs1 as1) (AALTs bs2 as2)) =
       
  3009          bsimp (AALTs x51 ((map (fuse bs1) as1) @ (map (fuse bs2) as2)))"
       
  3010   by (smt WWW3 bsimp.simps(2) k0 k00 list.simps(8) list.simps(9) map_append)
       
  3011 
       
  3012 lemma bignA:
       
  3013   shows "bsimp (AALTs x51 (AALTs bs1 as1 # as2)) =
       
  3014          bsimp (AALTs x51 ((map (fuse bs1) as1) @ as2))"
       
  3015   apply(simp)
       
  3016   apply(subst k0)
       
  3017   apply(subst WWW3)
       
  3018   apply(simp add: flts_append)
       
  3019   done
       
  3020 
       
  3021 lemma XXX2a_long_without_good:
       
  3022   shows "bsimp (bder c (bsimp a)) = bsimp (bder c a)"
       
  3023   apply(induct a arbitrary: c taking: "\<lambda>a. asize a" rule: measure_induct)
       
  3024   apply(case_tac x)
       
  3025        apply(simp)
       
  3026       apply(simp)
       
  3027      apply(simp)
       
  3028   prefer 3
       
  3029     apply(simp)
       
  3030   (* SEQ case *)
       
  3031    apply(simp only:)
       
  3032    apply(subst CT1_SEQ)
       
  3033   apply(simp only: bsimp.simps)
       
  3034 
       
  3035   (* AALT case *)
       
  3036    prefer 2
       
  3037    apply(simp only:)
       
  3038    apply(case_tac "\<exists>a1 a2. x52 = [a1, a2]")
       
  3039     apply(clarify)
       
  3040     apply(simp del: bsimp.simps)
       
  3041   apply(subst (2) CT1) 
       
  3042     apply(simp del: bsimp.simps)
       
  3043   apply(rule_tac t="bsimp (bder c a1)" and  s="bsimp (bder c (bsimp a1))" in subst)
       
  3044   apply(simp del: bsimp.simps)
       
  3045   apply(rule_tac t="bsimp (bder c a2)" and  s="bsimp (bder c (bsimp a2))" in subst)
       
  3046      apply(simp del: bsimp.simps)
       
  3047     apply(subst  CT1a[symmetric])
       
  3048   (* \<rightarrow> *)
       
  3049   apply(rule_tac t="AALT x51 (bder c (bsimp a1)) (bder c (bsimp a2))"
       
  3050             and  s="bder c (AALT x51 (bsimp a1) (bsimp a2))" in subst)
       
  3051      apply(simp)
       
  3052      apply(subst bsimp.simps)
       
  3053     apply(simp del: bsimp.simps bder.simps)
       
  3054 
       
  3055     apply(subst bder_bsimp_AALTs)
       
  3056     apply(subst bsimp.simps)
       
  3057     apply(subst WWW2[symmetric])
       
  3058     apply(subst bsimp_AALTs_qq)
       
  3059   defer 
       
  3060     apply(subst bsimp.simps)
       
  3061     
       
  3062   (* <- *)
       
  3063     apply(subst bsimp.simps)
       
  3064     apply(simp del: bsimp.simps)
       
  3065   apply(case_tac "\<exists>bs1 as1. bsimp a1 = AALTs bs1 as1")
       
  3066   apply(case_tac "\<exists>bs2 as2. bsimp a2 = AALTs bs2 as2")
       
  3067       apply(clarify)
       
  3068   apply(simp only:)
       
  3069       apply(simp del: bsimp.simps bder.simps)
       
  3070       apply(subst bsimp_AALTs_qq)
       
  3071        prefer 2
       
  3072        apply(simp del: bsimp.simps)
       
  3073        apply(subst big0)
       
  3074        apply(simp add: WWW4)
       
  3075   apply (m etis One_nat_def Suc_eq_plus1 Suc_lessI arexp.distinct(7) bsimp.simps(2) bsimp_AALTs.simps(1) bsimp_idem flts.simps(1) length_append length_greater_0_conv length_map not_add_less2 not_less_eq)
       
  3076   oops
       
  3077 
       
  3078 lemma XXX2a_long_without_good:
       
  3079   shows "bsimp (bder c (bsimp a)) = bsimp (bder c a)"
       
  3080   apply(induct a arbitrary: c taking: "\<lambda>a. asize a" rule: measure_induct)
       
  3081   apply(case_tac x)
       
  3082        apply(simp)
       
  3083       apply(simp)
       
  3084      apply(simp)
       
  3085   prefer 3
       
  3086     apply(simp)
       
  3087   (* AALT case *)
       
  3088    prefer 2
       
  3089    apply(subgoal_tac "nonnested (bsimp x)")
       
  3090     prefer 2
       
  3091   using nn1b apply blast
       
  3092    apply(simp only:)
       
  3093   apply(drule_tac x="AALTs x51 (flts x52)" in spec)
       
  3094    apply(drule mp)
       
  3095     defer
       
  3096     apply(drule_tac x="c" in spec)
       
  3097     apply(simp)
       
  3098     apply(rotate_tac 2)
       
  3099   
       
  3100     apply(drule sym)
       
  3101   apply(simp)
       
  3102 
       
  3103    apply(simp only: bder.simps)
       
  3104    apply(simp only: bsimp.simps)
       
  3105    apply(subst bder_bsimp_AALTs)
       
  3106    apply(case_tac x52)
       
  3107     apply(simp)
       
  3108    apply(simp)
       
  3109   apply(case_tac list)
       
  3110     apply(simp)
       
  3111     apply(case_tac a)
       
  3112          apply(simp)
       
  3113         apply(simp)
       
  3114        apply(simp)
       
  3115       defer
       
  3116       apply(simp)
       
  3117   
       
  3118 
       
  3119    (* case AALTs list is not empty *)
       
  3120    apply(simp)
       
  3121    apply(subst k0)
       
  3122    apply(subst (2) k0)
       
  3123    apply(simp)
       
  3124    apply(case_tac "bsimp a = AZERO")
       
  3125     apply(subgoal_tac "bsimp (bder c a) = AZERO")
       
  3126      prefer 2
       
  3127   using less_iff_Suc_add apply auto[1]
       
  3128     apply(simp)
       
  3129   apply(drule_tac x="AALTs x51 list" in  spec)
       
  3130    apply(drule mp)
       
  3131     apply(simp add: asize0)
       
  3132    apply(drule_tac x="c" in spec)
       
  3133     apply(simp add: bder_bsimp_AALTs)
       
  3134    apply(case_tac  "nonalt (bsimp a)")
       
  3135     prefer 2
       
  3136   apply(drule_tac x="bsimp (AALTs x51 (a#list))" in  spec)
       
  3137     apply(drule mp)
       
  3138      apply(rule order_class.order.strict_trans2)
       
  3139       apply(rule bsimp_AALTs_size3)
       
  3140       apply(auto)[1]
       
  3141      apply(simp)
       
  3142     apply(subst (asm) bsimp_idem)
       
  3143   apply(drule_tac x="c" in spec)
       
  3144   apply(simp)  
       
  3145   find_theorems "_ < _ \<Longrightarrow> _ \<le> _ \<Longrightarrow>_ < _"
       
  3146   apply(rule le_trans)
       
  3147   apply(subgoal_tac "flts [bsimp a] = [bsimp a]")
       
  3148      prefer 2
       
  3149   using k0b apply blast
       
  3150     apply(simp)
       
  3151   find_theorems "asize _ < asize _"
       
  3152   
       
  3153   using bder_bsimp_AALTs
       
  3154    apply(case_tac list)
       
  3155     apply(simp)
       
  3156    sledgeha mmer [timeout=6000]  
       
  3157 
       
  3158    apply(case_tac "\<exists>r \<in> set (map bsimp x52). \<not>nonalt r")
       
  3159     apply(drule_tac x="bsimp (AALTs x51 x52)" in spec)
       
  3160     apply(drule mp)
       
  3161   using bsimp_AALTs_size3 apply blast
       
  3162     apply(drule_tac x="c" in spec)
       
  3163   apply(subst (asm) (2) test)
       
  3164   
       
  3165    apply(case_tac x52)
       
  3166     apply(simp)
       
  3167    apply(simp)
       
  3168   apply(case_tac "bsimp a = AZERO")
       
  3169      apply(simp)
       
  3170      apply(subgoal_tac "bsimp (bder c a) = AZERO")
       
  3171       prefer 2
       
  3172      apply auto[1]
       
  3173   apply (metis L.simps(1) L_bsimp_erase der.simps(1) der_correctness erase.simps(1) erase_bder xxx_bder2)
       
  3174     apply(simp)
       
  3175     apply(drule_tac x="AALTs x51 list" in spec)
       
  3176     apply(drule mp)
       
  3177      apply(simp add: asize0)
       
  3178   apply(simp)
       
  3179    apply(case_tac list)
       
  3180     prefer 2
       
  3181     apply(simp)
       
  3182   apply(case_tac "bsimp aa = AZERO")
       
  3183      apply(simp)
       
  3184      apply(subgoal_tac "bsimp (bder c aa) = AZERO")
       
  3185       prefer 2
       
  3186       apply auto[1]
       
  3187       apply (metis add.left_commute bder.simps(1) bsimp.simps(3) less_add_Suc1)
       
  3188      apply(simp)
       
  3189   apply(drule_tac x="AALTs x51 (a#lista)" in spec)
       
  3190     apply(drule mp)
       
  3191      apply(simp  add: asize0)
       
  3192      apply(simp)
       
  3193      apply (metis flts.simps(2) k0)
       
  3194     apply(subst k0)
       
  3195   apply(subst (2) k0)
       
  3196   
       
  3197   
       
  3198   using less_add_Suc1 apply fastforce
       
  3199     apply(subst k0)
       
  3200   
       
  3201 
       
  3202     apply(simp)
       
  3203     apply(case_tac "bsimp a = AZERO")
       
  3204      apply(simp)
       
  3205      apply(subgoal_tac "bsimp (bder c a) = AZERO")
       
  3206       prefer 2
       
  3207   apply auto[1]
       
  3208      apply(simp)
       
  3209   apply(case_tac "nonalt (bsimp a)")
       
  3210      apply(subst bsimp_AALTs1)
       
  3211       apply(simp)
       
  3212   using less_add_Suc1 apply fastforce
       
  3213   
       
  3214      apply(subst bsimp_AALTs1)
       
  3215   
       
  3216   using nn11a apply b last
       
  3217 
       
  3218   (* SEQ case *)
       
  3219    apply(clarify)
       
  3220   apply(subst  bsimp.simps)
       
  3221    apply(simp del: bsimp.simps)
       
  3222    apply(auto simp del: bsimp.simps)[1]
       
  3223     apply(subgoal_tac "bsimp x42 \<noteq> AZERO")
       
  3224   prefer 2
       
  3225   using b3 apply force
       
  3226   apply(case_tac "bsimp x43 = AZERO")
       
  3227      apply(simp)
       
  3228      apply (simp add: bsimp_ASEQ0)
       
  3229   apply (metis bder.simps(1) bsimp.simps(3) bsimp_AALTs.simps(1) bsimp_fuse flts.simps(1) flts.simps(2) fuse.simps(1) less_add_Suc2)
       
  3230     apply(case_tac "\<exists>bs. bsimp x42 = AONE bs")
       
  3231      apply(clarify)
       
  3232      apply(simp)
       
  3233      apply(subst bsimp_ASEQ2)
       
  3234      apply(subgoal_tac "bsimp (bder c x42) = AZERO")
       
  3235       prefer 2
       
  3236   using less_add_Suc1 apply fastforce
       
  3237      apply(simp)
       
  3238      apply(frule_tac x="x43" in spec)
       
  3239   apply(drule mp)
       
  3240      apply(simp)
       
  3241   apply(drule_tac x="c" in spec)
       
  3242      apply(subst bder_fuse)
       
  3243   apply(subst bsimp_fuse[symmetric])
       
  3244      apply(simp)
       
  3245   apply(subgoal_tac "bmkeps x42 = bs")
       
  3246       prefer 2
       
  3247       apply (simp add: bmkeps_simp)
       
  3248      apply(simp)
       
  3249      apply(subst bsimp_fuse[symmetric])
       
  3250   apply(case_tac "nonalt (bsimp (bder c x43))")
       
  3251       apply(subst bsimp_AALTs1)
       
  3252   using nn11a apply blast
       
  3253   using fuse_append apply blast
       
  3254      apply(subgoal_tac "\<exists>bs rs. bsimp (bder c x43) = AALTs bs rs")
       
  3255       prefer 2
       
  3256   using bbbbs1 apply blast
       
  3257   apply(clarify)
       
  3258      apply(simp)
       
  3259      apply(case_tac rs)
       
  3260       apply(simp)
       
  3261       apply (metis arexp.distinct(7) good.simps(4) good1)
       
  3262      apply(simp)
       
  3263      apply(case_tac list)
       
  3264       apply(simp)
       
  3265       apply (metis arexp.distinct(7) good.simps(5) good1)
       
  3266   apply(simp del: bsimp_AALTs.simps)
       
  3267   apply(simp only: bsimp_AALTs.simps)
       
  3268      apply(simp)
       
  3269   
       
  3270   
       
  3271 
       
  3272 
       
  3273 (* HERE *)
       
  3274 apply(case_tac "x42 = AZERO")
       
  3275      apply(simp)
       
  3276    apply(case_tac "bsimp x43 = AZERO")
       
  3277      apply(simp)
       
  3278      apply (simp add: bsimp_ASEQ0)
       
  3279      apply(subgoal_tac "bsimp (fuse (bmkeps x42) (bder c x43)) = AZERO")
       
  3280       apply(simp)
       
  3281   apply (met is bder.simps(1) bsimp.simps(3) bsimp_fuse fuse.simps(1) less_add_Suc2)
       
  3282   apply(case_tac "\<exists>bs. bsimp x42 = AONE bs")
       
  3283      apply(clarify)
       
  3284      apply(simp)
       
  3285      apply(subst bsimp_ASEQ2)
       
  3286      apply(subgoal_tac "bsimp (bder c x42) = AZERO")
       
  3287       apply(simp)
       
  3288   prefer 2
       
  3289   using less_add_Suc1 apply fastforce
       
  3290      apply(subgoal_tac "bmkeps x42 = bs")
       
  3291       prefer 2
       
  3292       apply (simp add: bmkeps_simp)
       
  3293      apply(simp)
       
  3294      apply(case_tac "nonalt (bsimp (bder c x43))")
       
  3295   apply (metis bder_fuse bsimp_AALTs.simps(1) bsimp_AALTs.simps(2) bsimp_fuse flts.simps(1) flts.simps(2) fuse.simps(1) fuse_append k0b less_add_Suc2 nn11a)
       
  3296      apply(subgoal_tac "nonnested (bsimp (bder c x43))")
       
  3297       prefer 2
       
  3298   using nn1b apply blast
       
  3299      apply(case_tac x43)
       
  3300           apply(simp)
       
  3301          apply(simp)
       
  3302         apply(simp)
       
  3303        prefer 3
       
  3304        apply(simp)
       
  3305        apply (metis arexp.distinct(25) arexp.distinct(7) arexp.distinct(9) bsimp_ASEQ.simps(1) bsimp_ASEQ.simps(11) bsimp_ASEQ1 nn11a nonalt.elims(3) nonalt.simps(6)) 
       
  3306       apply(simp)
       
  3307       apply(auto)[1]
       
  3308        apply(case_tac "(bsimp (bder c x42a)) = AZERO")
       
  3309         apply(simp)
       
  3310   
       
  3311        apply(simp)
       
  3312   
       
  3313   
       
  3314   
       
  3315      apply(subgoal_tac "(\<exists>bs1 rs1. 1 < length rs1 \<and> bsimp (bder c x43) =  AALTs bs1 rs1 ) \<or>
       
  3316                         (\<exists>bs1 r. bsimp (bder c x43) =  fuse bs1 r)")
       
  3317       prefer 2
       
  3318   apply (metis fuse_empty)
       
  3319      apply(erule disjE)
       
  3320   prefer 2
       
  3321      apply(clarify)
       
  3322      apply(simp only:)
       
  3323      apply(simp)
       
  3324      apply(simp add: fuse_append)
       
  3325      apply(subst bder_fuse)
       
  3326      apply(subst bsimp_fuse[symmetric])
       
  3327      apply(subst bder_fuse)
       
  3328      apply(subst bsimp_fuse[symmetric])
       
  3329      apply(subgoal_tac "bsimp (bder c (bsimp x43)) = bsimp (bder c x43)")
       
  3330       prefer 2
       
  3331   using less_add_Suc2 apply bl ast
       
  3332      apply(simp only: )
       
  3333      apply(subst bsimp_fuse[symmetric])
       
  3334       apply(simp only: )
       
  3335   
       
  3336      apply(simp only: fuse.simps)
       
  3337   apply(simp)
       
  3338       apply(case_tac rs1)
       
  3339       apply(simp)
       
  3340       apply (me tis arexp.distinct(7) fuse.simps(1) good.simps(4) good1 good_fuse)
       
  3341   apply(simp)
       
  3342   apply(case_tac list)
       
  3343       apply(simp)
       
  3344       apply (me tis arexp.distinct(7) fuse.simps(1) good.simps(5) good1 good_fuse)
       
  3345      apply(simp only: bsimp_AALTs.simps map_cons.simps)
       
  3346      apply(auto)[1]
       
  3347   
       
  3348   
       
  3349       
       
  3350       apply(subst bsimp_fuse[symmetric])
       
  3351   apply(subgoal_tac "bmkeps x42 = bs")
       
  3352       prefer 2
       
  3353       apply (simp add: bmkeps_simp)
       
  3354   
       
  3355   
       
  3356         apply(simp)
       
  3357   
       
  3358   using b3 apply force
       
  3359   using bsimp_ASEQ0 test2 apply fo rce
       
  3360   thm good_SEQ test2
       
  3361      apply (simp add: good_SEQ test2)
       
  3362     apply (simp add: good_SEQ test2)
       
  3363   apply(case_tac "x42 = AZERO")
       
  3364      apply(simp)
       
  3365    apply(case_tac "x43 = AZERO")
       
  3366     apply(simp)
       
  3367   apply (simp add: bsimp_ASEQ0)
       
  3368   apply(case_tac "\<exists>bs. x42 = AONE bs")
       
  3369      apply(clarify)
       
  3370      apply(simp)
       
  3371     apply(subst bsimp_ASEQ1)
       
  3372       apply(simp)
       
  3373   using bsimp_ASEQ0 test2 apply fo rce
       
  3374      apply (simp add: good_SEQ test2)
       
  3375     apply (simp add: good_SEQ test2)
       
  3376   apply (simp add: good_SEQ test2)
       
  3377   (* AALTs case *)
       
  3378   apply(simp)
       
  3379   using test2 by fa st force
       
  3380 
       
  3381 
       
  3382 lemma XXX4ab:
       
  3383   shows "good (bders_simp (bsimp r) s)  \<or> bders_simp (bsimp r) s = AZERO"
       
  3384   apply(induct s arbitrary: r rule:  rev_induct)
       
  3385    apply(simp)
       
  3386   apply (simp add: good1)
       
  3387   apply(simp add: bders_simp_append)
       
  3388   apply (simp add: good1)
       
  3389   done
       
  3390 
  2758 
  3391 lemma XXX4:
  2759 lemma XXX4:
  3392   assumes "good a"
  2760   assumes "good a"
  3393   shows "bders_simp a s = bsimp (bders a s)"
  2761   shows "bders_simp a s = bsimp (bders a s)"
  3394   using  assms
  2762   using  assms