@@ -120,7 +120,7 @@ signature BMV_MONAD_DEF = sig
120120 -> { frees: typ list, deads: typ list, lives: typ list } option list -> local_theory
121121 -> (bmv_monad * thm list) * local_theory
122122
123- val seal_bmv_monad: (binding -> binding) -> thm list -> binding -> typ list -> bmv_monad
123+ val seal_bmv_monad: (binding -> binding) -> thm list -> binding -> (var_type * typ) list -> bmv_monad
124124 -> (string * Typedef.info) option -> local_theory
125125 -> (bmv_monad * thm list * thm list * (string * Typedef.info)) * local_theory
126126end
@@ -505,7 +505,7 @@ fun mk_bmv_monad_axioms ops consts bmv_ops lthy =
505505 ) (List.find (curry (op =) (body_type (fastype_of RVr)) o body_type o fastype_of) RVrs) end
506506 ) Vrs rhos in fold_rev Logic.all (fs @ rhos @ [x]) (
507507 fold_rev (curry Logic.mk_implies) small_prems (mk_Trueprop_eq (
508- RVr $ (Term.list_comb (Sb, fs @ rhos) $ x), foldr1 mk_Un ((mk_image f $ (RVr $ x)) :: UNs)
508+ RVr $ (Term.list_comb (Sb, fs @ rhos) $ x), foldl1 mk_Un ((mk_image f $ (RVr $ x)) :: UNs)
509509 ))
510510 ) end
511511 ) fs RVrs @ map2 (fn Vr => fn Inj =>
@@ -2106,17 +2106,30 @@ fun seal_bmv_monad qualify unfolds name tys bmv info_opt lthy =
21062106 val rep_T = leader ops_of_bmv_monad bmv;
21072107 val ((T_name, info), lthy) = (case info_opt of
21082108 SOME info => (info, lthy)
2109- | NONE => BNF_Util.typedef (name, map dest_TFree tys, NoSyn)
2109+ | NONE => BNF_Util.typedef (name, map ( dest_TFree o snd) tys, NoSyn)
21102110 (HOLogic.mk_UNIV rep_T) NONE (fn ctxt => rtac ctxt @{thm UNIV_witness} 1 ) lthy)
21112111
21122112 val T = #abs_type (fst info);
21132113 val abs = Const (#Abs_name (fst info), rep_T --> #abs_type (fst info));
21142114 val rep = Const (#Rep_name (fst info), #abs_type (fst info) --> rep_T);
21152115
2116+ val frees = map_filter (fn (Free_Var, a) => SOME a | _ => NONE ) tys;
2117+ val lives = map_filter (fn (Live_Var, a) => SOME a | _ => NONE ) tys;
2118+ val deads = map_filter (fn (Dead_Var, a) => SOME a | _ => NONE ) tys;
2119+ val lives' = map (the o AList.lookup (op =) (leader lives_of_bmv_monad bmv ~~ leader lives'_of_bmv_monad bmv)) lives;
2120+
2121+ val (ifrees, rfrees) = partition (
2122+ member (op =) (map (domain_type o fastype_of) (leader Injs_of_bmv_monad bmv))
2123+ ) frees;
2124+
21162125 val (((fs, rhos), gs), _) = lthy
2117- |> mk_Frees " f" (map (( fn a => a --> a) o HOLogic.dest_setT o body_type o fastype_of) (leader RVrs_of_bmv_monad bmv) )
2126+ |> mk_Frees " f" (map (fn a => a --> a) rfrees )
21182127 ||>> mk_Frees " \< rho>" (map ((fn T' => if body_type T' = rep_T then domain_type T' --> T else T') o fastype_of) (leader Injs_of_bmv_monad bmv))
2119- ||>> mk_Frees " g" (the_default [] (Option.map (fst o split_last o binder_types o fastype_of) (leader Maps_of_bmv_monad bmv)))
2128+ ||>> mk_Frees " g" (map2 (curry (op -->)) lives lives')
2129+
2130+ val rep_fs = map (fn RVrs => the (List.find (fn f =>
2131+ domain_type (fastype_of f) = HOLogic.dest_setT (range_type (fastype_of RVrs))
2132+ ) fs)) (leader RVrs_of_bmv_monad bmv);
21202133
21212134 val mk_def_t = mk_def_t false Binding.empty qualify
21222135 val mk_defs_t = mk_defs_t false Binding.empty qualify
@@ -2127,9 +2140,12 @@ fun seal_bmv_monad qualify unfolds name tys bmv info_opt lthy =
21272140 val (((((Sb, RVrs), Injs), Vrs), extra_Vrs), lthy) = lthy
21282141 |> mk_def_t (mk_name " Sb" ) 0 (fold_rev (Term.absfree o dest_Free) (fs @ rhos) (
21292142 HOLogic.mk_comp (HOLogic.mk_comp (abs, Term.list_comb (leader Sbs_of_bmv_monad bmv,
2130- fs @ map (fn rho => if body_type (fastype_of rho) = T then HOLogic.mk_comp (rep, rho) else rho) rhos
2143+ rep_fs @ map (fn rho => if body_type (fastype_of rho) = T then HOLogic.mk_comp (rep, rho) else rho) rhos
21312144 )), rep)))
2132- ||>> mk_defs_t (mk_name " RVrs" ) 0 (map (fn RVrs => HOLogic.mk_comp (RVrs, rep)) (leader RVrs_of_bmv_monad bmv))
2145+ ||>> mk_defs_t (mk_name " RVrs" ) 0 (map (fn free => case List.find (fn RVrs => HOLogic.dest_setT (range_type (fastype_of RVrs)) = free) (leader RVrs_of_bmv_monad bmv) of
2146+ SOME RVrs => HOLogic.mk_comp (RVrs, rep)
2147+ | NONE => Term.abs (" _" , T) (mk_bot free)
2148+ ) rfrees)
21332149 ||>> mk_defs_t (mk_name " Inj" ) 0 (map_filter (fn Inj =>
21342150 if body_type (fastype_of Inj) = rep_T then SOME (HOLogic.mk_comp (abs, Inj)) else NONE
21352151 ) (leader Injs_of_bmv_monad bmv))
@@ -2142,9 +2158,13 @@ fun seal_bmv_monad qualify unfolds name tys bmv info_opt lthy =
21422158 | SOME Map =>
21432159 lthy
21442160 |> apfst SOME o mk_def_t (mk_name " Map" ) 0 (fold_rev (Term.absfree o dest_Free) gs (
2145- HOLogic.mk_comp (HOLogic.mk_comp (subst abs, Term.list_comb (Map, gs)), rep)
2161+ HOLogic.mk_comp (HOLogic.mk_comp (subst abs, Term.list_comb (Map, map (fn live =>
2162+ the (List.find (fn g => domain_type (fastype_of g) = live) gs)
2163+ ) (leader lives_of_bmv_monad bmv))), rep)
21462164 ))
2147- ||>> apfst SOME o mk_defs_t (mk_name " Supp" ) 0 (map (fn Supp => HOLogic.mk_comp (Supp, rep)) (the (leader Supps_of_bmv_monad bmv)))
2165+ ||>> apfst SOME o mk_defs_t (mk_name " Supp" ) 0 (map (fn live => HOLogic.mk_comp (
2166+ the (List.find (fn Supp => HOLogic.dest_setT (range_type (fastype_of Supp)) = live) (the (leader Supps_of_bmv_monad bmv))),
2167+ rep)) lives)
21482168
21492169 val (lthy, old_lthy) = `Local_Theory.end_nested lthy;
21502170 val phi = Proof_Context.export_morphism old_lthy lthy;
@@ -2188,10 +2208,10 @@ fun seal_bmv_monad qualify unfolds name tys bmv info_opt lthy =
21882208 bmv_ops = map_filter (fn i => if i = leader_of_bmv_monad bmv then NONE else SOME (unsafe_slice_bmv_monad i bmv)) (0 upto length (ops_of_bmv_monad bmv) - 1 ),
21892209 bd_infinite_regular_card_order = fn ctxt => rtac ctxt (bd_infinite_regular_card_order_of_bmv_monad bmv) 1 ,
21902210 var_class = var_class_of_bmv_monad bmv,
2191- frees = [leader frees_of_bmv_monad bmv ],
2192- lives = [leader lives_of_bmv_monad bmv ],
2193- lives' = [leader lives'_of_bmv_monad bmv ],
2194- deads = [map TFree (rev (fold Term.add_tfreesT (leader deads_of_bmv_monad bmv) [])) ],
2211+ frees = [frees ],
2212+ lives = [lives ],
2213+ lives' = [lives'],
2214+ deads = [deads ],
21952215 consts = consts,
21962216 leader = 0 ,
21972217 params = [Option.map (fn Supps => {
@@ -2255,13 +2275,13 @@ fun seal_bmv_monad qualify unfolds name tys bmv info_opt lthy =
22552275 rtac ctxt refl
22562276 ]) Supps,
22572277 Vrs_Map = map (fn _ => fn ctxt => EVERY1 [
2258- K (Local_Defs.unfold0_tac ctxt ([
2278+ K (Local_Defs.unfold0_tac ctxt (@{thms image_empty} @ [
22592279 snd (the Map_opt), #Abs_inverse (snd info) OF @{thms UNIV_I},
22602280 infer_instantiate' ctxt [NONE , SOME (Thm.cterm_of ctxt rep)] @{thm comp_apply},
22612281 infer_instantiate' ctxt [NONE , SOME (Thm.cterm_of ctxt (subst rep))] @{thm comp_apply},
22622282 infer_instantiate' ctxt [SOME (Thm.cterm_of ctxt (subst abs))] @{thm comp_apply}
22632283 ] @ map snd Vrs @ map snd RVrs)),
2264- resolve_tac ctxt (#Vrs_Map (the params))
2284+ resolve_tac ctxt (@{thms refl} @ #Vrs_Map (the params))
22652285 ]) (RVrs @ Vrs),
22662286 Map_Injs = map_filter (fn Inj => if body_type (fastype_of Inj) <> T then NONE else
22672287 SOME (fn ctxt => EVERY1 [
@@ -2308,7 +2328,8 @@ fun seal_bmv_monad qualify unfolds name tys bmv info_opt lthy =
23082328 ],
23092329 Vrs_bds = map (K (fn ctxt => EVERY1 [
23102330 K (Local_Defs.unfold0_tac ctxt (@{thms comp_def} @ map snd Vrs @ map snd RVrs)),
2311- resolve_tac ctxt (#Vrs_bds axioms)
2331+ resolve_tac ctxt (@{thms Cinfinite_gt_empty} @ #Vrs_bds axioms),
2332+ TRY o rtac ctxt (@{thm infinite_regular_card_order.Cinfinite} OF [bd_infinite_regular_card_order_of_bmv_monad bmv])
23122333 ])) (RVrs @ Vrs),
23132334 Vrs_Injss = map (K (map_filter (fn Inj => if body_type (fastype_of Inj) <> T then NONE else
23142335 SOME (fn ctxt => EVERY1 [
@@ -2317,15 +2338,17 @@ fun seal_bmv_monad qualify unfolds name tys bmv info_opt lthy =
23172338 ])
23182339 ) Injs)) (RVrs @ Vrs @ extra_Vrs),
23192340 Vrs_Sbs = map (K (fn ctxt => EVERY1 [
2320- K (Local_Defs.unfold0_tac ctxt ([
2341+ K (Local_Defs.unfold0_tac ctxt (@{thms image_empty} @ [
23212342 snd Sb, @{thm SSupp_type_copy} OF [copy], @{thm IImsupp_type_copy} OF [copy],
23222343 #Abs_inverse (snd info) OF @{thms UNIV_I},
23232344 infer_instantiate' ctxt [NONE , SOME (Thm.cterm_of ctxt rep)] @{thm comp_apply},
23242345 infer_instantiate' ctxt [SOME (Thm.cterm_of ctxt abs)] @{thm comp_apply}
23252346 ] @ defs)),
2326- rtac ctxt trans,
2327- resolve_tac ctxt (#Vrs_Sbs axioms) THEN_ALL_NEW assume_tac ctxt,
2328- K (Local_Defs.unfold0_tac ctxt @{thms comp_def}),
2347+ TRY o EVERY' [
2348+ rtac ctxt trans,
2349+ resolve_tac ctxt (#Vrs_Sbs axioms) THEN_ALL_NEW assume_tac ctxt,
2350+ K (Local_Defs.unfold0_tac ctxt @{thms comp_def})
2351+ ],
23292352 rtac ctxt refl
23302353 ])) (RVrs @ Vrs),
23312354 Sb_cong = fn ctxt => EVERY1 [
0 commit comments