@@ -16,9 +16,6 @@ signature MRSBNF_DEF = sig
1616 map_Sb_strong: thm
1717 };
1818
19- val id_bmv_monad: BMV_Monad_Def.bmv_monad
20- val mk_id_bmv_monad: string * sort -> BMV_Monad_Def.bmv_monad
21-
2219 val bmv_monad_of_mrsbnf: mrsbnf -> BMV_Monad_Def.bmv_monad
2320 val mrbnfs_of_mrsbnf: mrsbnf -> MRBNF_Def.mrbnf list
2421 val axioms_of_mrsbnf: mrsbnf -> thm mrsbnf_axioms list
@@ -28,15 +25,13 @@ signature MRSBNF_DEF = sig
2825
2926 val mrsbnf_def: (theory -> BNF_Def.fact_policy) -> (binding -> binding) -> string option
3027 -> MRBNF_Def.mrbnf list -> BMV_Monad_Def.bmv_monad -> (Proof.context -> tactic) mrsbnf_axioms list
31- -> local_theory -> mrsbnf * local_theory
28+ -> local_theory -> mrsbnf * local_theory;
29+
30+ val mrsbnf_of_bnf: BNF_Def.bnf -> local_theory -> mrsbnf * local_theory;
3231
3332 val register_mrsbnf: string -> mrsbnf -> local_theory -> local_theory;
3433 val mrsbnf_of_generic: Context.generic -> string -> mrsbnf option;
3534 val mrsbnf_of: Proof.context -> string -> mrsbnf option;
36-
37- val pbmv_monad_of_typ: bool -> BNF_Def.inline_policy -> (theory -> BNF_Def.fact_policy)
38- -> (string * sort) list -> (binding -> binding) -> typ -> (thm list * local_theory)
39- -> BMV_Monad_Def.bmv_monad option * (thm list * local_theory)
4035end
4136
4237structure MRSBNF_Def : MRSBNF_DEF = struct
@@ -104,12 +99,6 @@ fun morph_mrsbnf phi (MRSBNF {
10499 facts = map (morph_mrsbnf_facts phi) facts
105100}
106101
107- val id_bmv_monad = the (BMV_Monad_Def.pbmv_monad_of @{context} " BMV_Monad.ID" );
108-
109- fun mk_id_bmv_monad free = BMV_Monad_Def.morph_bmv_monad (
110- MRBNF_Util.subst_typ_morphism [(hd (hd (BMV_Monad_Def.frees_of_bmv_monad id_bmv_monad)), TFree free)]
111- ) id_bmv_monad;
112-
113102fun Rep_mrsbnf (MRSBNF x) = x
114103
115104val bmv_monad_of_mrsbnf = #pbmv_monad o Rep_mrsbnf
@@ -123,9 +112,9 @@ structure Data = Generic_Data (
123112 fun merge data : T = Symtab.merge (K true ) data;
124113);
125114
126- fun register_mrsbnf name bmv =
115+ fun register_mrsbnf name mrsbnf =
127116 Local_Theory.declaration {syntax = false , pervasive = true , pos = Position.none}
128- (fn phi => Data.map (Symtab.update (name, morph_mrsbnf phi bmv )));
117+ (fn phi => Data.map (Symtab.update (name, morph_mrsbnf phi mrsbnf )));
129118
130119fun mrsbnf_of_generic context =
131120 Option.map (morph_mrsbnf (Morphism.transfer_morphism (Context.theory_of context)))
@@ -136,7 +125,7 @@ val mrsbnf_of = mrsbnf_of_generic o Context.Proof;
136125fun note_mrsbnf_thms fact_policy qualify name_opt mrsbnf lthy =
137126 let
138127 val bmv = bmv_monad_of_mrsbnf mrsbnf;
139- val name = case name_opt of
128+ fun name () = case name_opt of
140129 NONE => fst (dest_Type (nth (BMV_Monad_Def.ops_of_bmv_monad bmv) (BMV_Monad_Def.leader_of_bmv_monad bmv)))
141130 | SOME b => b;
142131 val axioms = axioms_of_mrsbnf mrsbnf;
@@ -155,7 +144,7 @@ fun note_mrsbnf_thms fact_policy qualify name_opt mrsbnf lthy =
155144 (" map_Sb_strong" , map #map_Sb_strong facts, [])
156145 ]
157146 |> filter_out (null o #2 )
158- |> map (fn (thmN, thms, attrs) => ((qualify (Binding.qualify true (short_type_name name) (Binding.name thmN)), attrs), [(thms, [])]));
147+ |> map (fn (thmN, thms, attrs) => ((qualify (Binding.qualify true (short_type_name ( name ()) ) (Binding.name thmN)), attrs), [(thms, [])]));
159148 in Local_Theory.notes notes lthy |>> append noted end
160149 val fact_policy = fact_policy (Proof_Context.theory_of lthy);
161150 in ([], lthy)
@@ -362,28 +351,33 @@ fun mk_mrsbnf fact_policy qualify (deads, As, As', Bs, Fs, fs) name_opt mrbnfs b
362351 REPEAT_DETERM o resolve_tac ctxt prems,
363352 rtac ctxt trans,
364353 rtac ctxt (#Sb_comp bmv_axioms),
365- REPEAT_DETERM o resolve_tac ctxt (prems @ #SSupp_comp_bound bmv_facts @ #SSupp_Inj_bound bmv_facts),
366- REPEAT_DETERM o EVERY' [
367- EqSubst.eqsubst_tac ctxt [0 ] (map (fn ax => #map_is_Sb ax RS sym) axioms'),
368- REPEAT_DETERM o resolve_tac ctxt prems
369- ],
370- if count = 0 then K all_tac else rtac ctxt refl,
371- rtac ctxt sym,
372- rtac ctxt trans,
373- rtac ctxt @{thm arg_cong2[OF _ refl, of _ _ " (\< circ>)" ]},
374- rtac ctxt (#Sb_comp_right facts),
375- REPEAT_DETERM o resolve_tac ctxt (@{thms supp_inv_bound}
376- @ maps (map_filter I o #SSupp_map_bound) facts' @ prems @ #SSupp_comp_bound bmv_facts
377- ),
378- K (Local_Defs.unfold0_tac ctxt @{thms comp_assoc}),
379- EqSubst.eqsubst_tac ctxt [0 ] [MRBNF_Def.map_comp0_of_mrbnf mrbnf RS sym],
380- REPEAT_DETERM o resolve_tac ctxt (@{thms supp_id_bound bij_id supp_inv_bound bij_imp_bij_inv} @ prems),
381- REPEAT_DETERM o EVERY' [
382- EqSubst.eqsubst_tac ctxt [0 ] @{thms inv_o_simp1},
383- resolve_tac ctxt prems
384- ],
385- K (Local_Defs.unfold0_tac ctxt (MRBNF_Def.map_id0_of_mrbnf mrbnf :: @{thms id_o o_id})),
386- rtac ctxt refl
354+ EVERY' [
355+ rtac ctxt refl,
356+ rtac ctxt refl
357+ ] ORELSE' EVERY' [
358+ REPEAT_DETERM o resolve_tac ctxt (prems @ #SSupp_comp_bound bmv_facts @ #SSupp_Inj_bound bmv_facts),
359+ REPEAT_DETERM o EVERY' [
360+ EqSubst.eqsubst_tac ctxt [0 ] (map (fn ax => #map_is_Sb ax RS sym) axioms'),
361+ REPEAT_DETERM o resolve_tac ctxt prems
362+ ],
363+ if count = 0 then K all_tac else rtac ctxt refl,
364+ rtac ctxt sym,
365+ rtac ctxt trans,
366+ rtac ctxt @{thm arg_cong2[OF _ refl, of _ _ " (\< circ>)" ]},
367+ rtac ctxt (#Sb_comp_right facts),
368+ REPEAT_DETERM o resolve_tac ctxt (@{thms supp_inv_bound}
369+ @ maps (map_filter I o #SSupp_map_bound) facts' @ prems @ #SSupp_comp_bound bmv_facts
370+ ),
371+ K (Local_Defs.unfold0_tac ctxt @{thms comp_assoc}),
372+ EqSubst.eqsubst_tac ctxt [0 ] [MRBNF_Def.map_comp0_of_mrbnf mrbnf RS sym],
373+ REPEAT_DETERM o resolve_tac ctxt (@{thms supp_id_bound bij_id supp_inv_bound bij_imp_bij_inv} @ prems),
374+ REPEAT_DETERM o EVERY' [
375+ EqSubst.eqsubst_tac ctxt [0 ] @{thms inv_o_simp1},
376+ resolve_tac ctxt prems
377+ ],
378+ K (Local_Defs.unfold0_tac ctxt (MRBNF_Def.map_id0_of_mrbnf mrbnf :: @{thms id_o o_id})),
379+ rtac ctxt refl
380+ ]
387381 ]) end ;
388382 in {
389383 SSupp_map_subset = #SSupp_map_subset facts,
@@ -552,51 +546,16 @@ fun mrsbnf_def fact_policy qualify name_opt mrbnfs bmv tacs lthy =
552546 val (axioms, vars, mrbnfs, bmv) = prove_axioms mrbnfs bmv tacs lthy;
553547 in mk_mrsbnf fact_policy qualify vars name_opt mrbnfs bmv axioms lthy end
554548
555- fun pbmv_monad_of_typ _ _ _ xs _ (TFree x) accum = if member (op =) xs x
556- then (NONE , accum) else (SOME (mk_id_bmv_monad x), accum)
557- | pbmv_monad_of_typ _ _ _ _ _ (TVar _) _ = error " unexpected schematic variable"
558- | pbmv_monad_of_typ optim const_policy inline_policy xs qualify' (T as Type (n, Ts)) (accum, lthy) =
559- let val (bmv_opt, lthy) = case BMV_Monad_Def.pbmv_monad_of lthy n of
560- SOME bmv => (SOME bmv, lthy)
561- | NONE => case BNF_Def.bnf_of lthy n of
562- SOME bnf =>
563- let val (bmv, lthy) = BMV_Monad_Def.pbmv_monad_of_bnf bnf lthy
564- in (SOME bmv, BMV_Monad_Def.register_pbmv_monad n bmv lthy) end
565- | NONE => (NONE , lthy);
566- in case bmv_opt of
567- NONE => (NONE , (accum, lthy))
568- | SOME bmv => if null (nth (BMV_Monad_Def.lives_of_bmv_monad bmv) (BMV_Monad_Def.leader_of_bmv_monad bmv)) then
569- let val T = nth (BMV_Monad_Def.ops_of_bmv_monad bmv) (BMV_Monad_Def.leader_of_bmv_monad bmv)
570- in (SOME (BMV_Monad_Def.morph_bmv_monad (MRBNF_Util.subst_typ_morphism (
571- rev (map TFree (Term.add_tfreesT T []) @ map TVar (Term.add_tvarsT T [])) ~~ Ts
572- )) bmv), (accum, lthy)) end
573- else let
574- val name = Long_Name.base_name n;
575-
576- fun qualify i =
577- let val namei = name ^ nonzero_string_of_int i;
578- in qualify' o Binding.qualify true namei end ;
579-
580- val leader = BMV_Monad_Def.leader_of_bmv_monad bmv;
581- val T = nth (BMV_Monad_Def.ops_of_bmv_monad bmv) leader;
582- val bmv = BMV_Monad_Def.morph_bmv_monad (
583- MRBNF_Util.subst_typ_morphism (snd (dest_Type T) ~~ Ts)
584- ) bmv;
585- val bmv = BMV_Monad_Def.morph_bmv_monad (MRBNF_Util.subst_typ_morphism (
586- nth (BMV_Monad_Def.lives'_of_bmv_monad bmv) leader ~~ nth (BMV_Monad_Def.lives_of_bmv_monad bmv) leader
587- )) bmv;
588- val live_Ts = nth (BMV_Monad_Def.lives_of_bmv_monad bmv) leader;
589-
590- val qualifies = map qualify (1 upto length live_Ts);
591- val (bmv_opts, (accum, lthy)) = @{fold_map 2 } (pbmv_monad_of_typ optim const_policy inline_policy xs) qualifies live_Ts (accum, lthy)
592- val bmvs = map2 (fn T => fn NONE => Inr T | SOME bmv => Inl bmv) live_Ts bmv_opts;
593- in if exists Option.isSome bmv_opts then
594- let val ((bmv, unfold_set), lthy) = BMV_Monad_Def.compose_bmv_monad (qualify 0 ) bmv bmvs lthy;
595- in (SOME bmv, (unfold_set @ accum, lthy)) end
596- else
597- (NONE , (accum, lthy))
598- end
599- end ;
549+ fun mrsbnf_of_bnf bnf lthy =
550+ let
551+ val (mrbnf, lthy) = MRBNF_Def.mrbnf_of_bnf bnf lthy;
552+ val (bmv, lthy) = BMV_Monad_Def.pbmv_monad_of_bnf bnf lthy;
553+ in mrsbnf_def (K BNF_Def.Dont_Note) I NONE [mrbnf] bmv [{
554+ map_Sb = SOME (fn ctxt => Local_Defs.unfold0_tac ctxt @{thms id_o o_id} THEN rtac ctxt refl 1 ),
555+ map_is_Sb = fn ctxt => rtac ctxt (BNF_Def.map_id0_of_bnf bnf) 1 ,
556+ set_Sb = replicate (BNF_Def.live_of_bnf bnf) (fn ctxt => Local_Defs.unfold0_tac ctxt @{thms id_apply} THEN rtac ctxt refl 1 ),
557+ set_Vrs = []
558+ }] lthy end ;
600559
601560fun mrsbnf_cmd (b, Ts) lthy =
602561 let
0 commit comments