Skip to content

Commit c7f8671

Browse files
committed
Introduce RVrs to BMV Monads
1 parent f115e10 commit c7f8671

File tree

8 files changed

+269
-260
lines changed

8 files changed

+269
-260
lines changed

Tools/binder_induction.ML

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ fun gen_binder_context_tactic mod_cases simp def_insts arbitrary avoiding taking
448448
REPEAT_DETERM o rtac ctxt @{thm induct_forallI},
449449
rtac ctxt inner_prem ORELSE'
450450
EVERY' [
451-
Method.insert_tac ctxt [inner_prem],
451+
Method.insert_tac ctxt inner_prems,
452452
let
453453
val simpset = Simplifier.add_cong @{thm imp_cong} (
454454
(BNF_Util.ss_only @{thms

Tools/binder_inductive.ML

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ fun binder_inductive_cmd (((options, pred_name), binds_opt: (string * string lis
119119
val intro = unvarify_global (Term.subst_TVars subst (Thm.prop_of intro));
120120
val binderss = map (distinct (op=)) (collect_binders intro);
121121
val xs_binders = map (fn binders => fold_rev (fn t => fn (a, b) => case t of
122-
Const (@{const_name insert}, _) $ x $ Const (@{const_name bot}, _) => (x::a, b)
122+
Const (@{const_name insert}, _) $ x $ Const (@{const_name bot}, _) => (case x of
123+
Bound _ => (a, b) | _ => (x::a, b))
123124
| _ => (a, t::b)
124125
) binders ([], [])) binderss;
125126
val binders = map (fn (xs, binders) =>

Tools/bmv_monad_def.ML

Lines changed: 102 additions & 91 deletions
Large diffs are not rendered by default.

Tools/mrsbnf_def.ML

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ fun note_mrsbnf_thms fact_policy qualify name_opt mrsbnf lthy =
154154
fun mk_mrsbnf fact_policy qualify (deads, As, As', Bs, Fs, fs) name_opt mrbnfs bmv axioms' lthy =
155155
let
156156
val names = map (fst o dest_Free);
157-
val facts' = @{map 7} (fn axioms => fn mrbnf => fn bmv_axioms => fn bmv_facts => fn Sb => fn Injs => fn SSupps =>
157+
val facts' = @{map 8} (fn axioms => fn mrbnf => fn bmv_axioms => fn bmv_facts => fn Sb => fn Injs => fn RVrs => fn SSupps =>
158158
let
159159
val mapx = MRBNF_Def.map_of_mrbnf mrbnf;
160160
val var_types = MRBNF_Def.var_types_of_mrbnf mrbnf;
@@ -168,8 +168,11 @@ fun mk_mrsbnf fact_policy qualify (deads, As, As', Bs, Fs, fs) name_opt mrbnfs b
168168
) fs var_types));
169169
val (live_fs, bound_fs, free_fs) = MRBNF_Def.deinterlace fs var_types;
170170

171-
val (((gs, aa), x), _) = lthy
172-
|> mk_Frees "g" (map fastype_of Injs)
171+
val RVrs_aTs = map (HOLogic.dest_setT o body_type o fastype_of) RVrs;
172+
173+
val ((((hs, gs), aa), x), _) = lthy
174+
|> mk_Frees "h" (map (fn a => a --> a) RVrs_aTs)
175+
||>> mk_Frees "g" (map fastype_of Injs)
173176
||>> mk_Frees "a" (map (domain_type o fastype_of) Injs)
174177
||>> apfst hd o mk_Frees "x" [T];
175178
val frees = inter (op=) Fs (MRBNF_Def.frees_of_mrbnf mrbnf);
@@ -182,20 +185,23 @@ fun mk_mrsbnf fact_policy qualify (deads, As, As', Bs, Fs, fs) name_opt mrbnfs b
182185
)) SSupps gs;
183186
fun find_f T = List.find (fn f => T = domain_type (fastype_of f)) fs;
184187

188+
val h_fs = map (the o find_f o domain_type o fastype_of) hs;
189+
val h_prems = map (HOLogic.mk_Trueprop o mk_supp_bound) hs;
190+
185191
val Sb_comp_right =
186192
let
187193
val fs' = map (the o find_f o domain_type o fastype_of) gs;
188194
val f'_prems = map (HOLogic.mk_Trueprop o mk_supp_bound) fs';
189195
val goal = Term.subst_atomic_types (As' ~~ As) (mk_Trueprop_eq (
190-
Term.list_comb (Sb, map2 (curry HOLogic.mk_comp) gs fs'),
196+
Term.list_comb (Sb, map2 (curry HOLogic.mk_comp) (hs @ gs) (h_fs @ fs')),
191197
HOLogic.mk_comp (
192-
Term.list_comb (Sb, gs),
198+
Term.list_comb (Sb, hs @ gs),
193199
Term.list_comb (mapx, map (fn T => case List.find (fn f => (domain_type T) = domain_type (fastype_of f)) fs' of
194200
SOME f => f | NONE => HOLogic.id_const (domain_type T)
195201
) (fst (split_last (binder_types (fastype_of mapx)))))
196202
)
197203
));
198-
in Goal.prove_sorry lthy (names (fs' @ gs)) (f'_prems @ g_prems) goal (fn {context=ctxt, prems} => EVERY1 [
204+
in Goal.prove_sorry lthy (names (fs' @ hs @ gs)) (f'_prems @ h_prems @ g_prems) goal (fn {context=ctxt, prems} => EVERY1 [
199205
EqSubst.eqsubst_tac ctxt [0] [#map_is_Sb axioms],
200206
REPEAT_DETERM o resolve_tac ctxt prems,
201207
rtac ctxt sym,
@@ -276,9 +282,9 @@ fun mk_mrsbnf fact_policy qualify (deads, As, As', Bs, Fs, fs) name_opt mrbnfs b
276282
} end
277283
) axioms' mrbnfs (BMV_Monad_Def.axioms_of_bmv_monad bmv) (BMV_Monad_Def.facts_of_bmv_monad bmv)
278284
(BMV_Monad_Def.Sbs_of_bmv_monad bmv) (BMV_Monad_Def.Injs_of_bmv_monad bmv)
279-
(BMV_Monad_Def.SSupps_of_bmv_monad bmv);
285+
(BMV_Monad_Def.RVrs_of_bmv_monad bmv) (BMV_Monad_Def.SSupps_of_bmv_monad bmv);
280286

281-
val facts' = @{map 8} (fn axioms => fn facts => fn mrbnf => fn bmv_axioms => fn bmv_facts => fn Sb => fn Injs => fn SSupps =>
287+
val facts' = @{map 9} (fn axioms => fn facts => fn mrbnf => fn bmv_axioms => fn bmv_facts => fn Sb => fn RVrs => fn Injs => fn SSupps =>
282288
let
283289
val mapx = MRBNF_Def.map_of_mrbnf mrbnf;
284290
val var_types = MRBNF_Def.var_types_of_mrbnf mrbnf;
@@ -288,8 +294,11 @@ fun mk_mrsbnf fact_policy qualify (deads, As, As', Bs, Fs, fs) name_opt mrbnfs b
288294
val fs = map (fn T => the (List.find (curry (op=) T o fastype_of) fs)) (fst (split_last (binder_types (fastype_of mapx))));
289295
val (live_fs, bound_fs, free_fs) = MRBNF_Def.deinterlace fs var_types;
290296

291-
val (((gs, aa), x), _) = lthy
292-
|> mk_Frees "g" (map fastype_of Injs)
297+
val RVrs_aTs = map (HOLogic.dest_setT o body_type o fastype_of) RVrs;
298+
299+
val ((((hs, gs), aa), x), _) = lthy
300+
|> mk_Frees "h" (map (fn a => a --> a) RVrs_aTs)
301+
||>> mk_Frees "g" (map fastype_of Injs)
293302
||>> mk_Frees "a" (map (domain_type o fastype_of) Injs)
294303
||>> apfst hd o mk_Frees "x" [T];
295304
val frees = inter (op=) Fs (MRBNF_Def.frees_of_mrbnf mrbnf);
@@ -299,16 +308,23 @@ fun mk_mrsbnf fact_policy qualify (deads, As, As', Bs, Fs, fs) name_opt mrbnfs b
299308
mk_ordLess (mk_card_of (SSupp $ g)) (mk_card_of (HOLogic.mk_UNIV (domain_type (fastype_of g))))
300309
)) SSupps gs;
301310

311+
fun find_f T = List.find (curry (op=) T o domain_type o fastype_of) fs;
312+
val h_prems = map (HOLogic.mk_Trueprop o mk_supp_bound) hs;
313+
val h_fs = map (the o find_f o domain_type o fastype_of) hs;
314+
315+
val infinite_UNIV = @{thm cinfinite_imp_infinite} OF [MRBNF_Def.UNIV_cinfinite_of_mrbnf (hd mrbnfs)];
316+
302317
val map_Sb_strong =
303318
let
304319
val map_t = Term.list_comb (mapx, fs);
305320
val mrbnfs = map (fn Inj =>
306321
the (List.find (fn mrbnf => body_type (fastype_of (MRBNF_Def.map_of_mrbnf mrbnf)) = body_type (fastype_of Inj)) mrbnfs)
307322
) Injs;
308-
fun find_f T = List.find (curry (op=) T o domain_type o fastype_of) fs;
309323
val goal = mk_Trueprop_eq (
310-
HOLogic.mk_comp (map_t, Term.list_comb (Sb, gs)),
311-
HOLogic.mk_comp (Term.list_comb (Term.subst_atomic_types (As ~~ As') Sb, map2 (fn g => fn mrbnf =>
324+
HOLogic.mk_comp (map_t, Term.list_comb (Sb, hs @ gs)),
325+
HOLogic.mk_comp (Term.list_comb (Term.subst_atomic_types (As ~~ As') Sb,
326+
map2 (fn h => fn f => HOLogic.mk_comp (HOLogic.mk_comp (f, h), mk_inv f)) hs fs @
327+
map2 (fn g => fn mrbnf =>
312328
let val mapx = MRBNF_Def.map_of_mrbnf mrbnf;
313329
in HOLogic.mk_comp (HOLogic.mk_comp (
314330
Term.list_comb (mapx,
@@ -324,7 +340,7 @@ fun mk_mrsbnf fact_policy qualify (deads, As, As', Bs, Fs, fs) name_opt mrbnfs b
324340
(map (fn f => map HOLogic.mk_Trueprop [mk_bij f, mk_supp_bound f]) free_fs) var_types);
325341
val id_of_f = HOLogic.id_const o domain_type o fastype_of
326342
val count = live + MRBNF_Def.bound_of_mrbnf mrbnf + MRBNF_Def.free_of_mrbnf mrbnf - length frees;
327-
in Goal.prove_sorry lthy (names (fs @ gs)) (f_prems @ g_prems) goal (fn {context=ctxt, prems} => EVERY1 [
343+
in Goal.prove_sorry lthy (names (fs @ hs @ gs)) (f_prems @ h_prems @ g_prems) goal (fn {context=ctxt, prems} => EVERY1 [
328344
if count = 0 then K all_tac else EVERY' [
329345
rtac ctxt trans,
330346
rtac ctxt @{thm arg_cong2[OF _ refl, of _ _ "(\<circ>)"]},
@@ -365,7 +381,8 @@ fun mk_mrsbnf fact_policy qualify (deads, As, As', Bs, Fs, fs) name_opt mrbnfs b
365381
rtac ctxt trans,
366382
rtac ctxt @{thm arg_cong2[OF _ refl, of _ _ "(\<circ>)"]},
367383
rtac ctxt (#Sb_comp_right facts),
368-
REPEAT_DETERM o resolve_tac ctxt (@{thms supp_inv_bound}
384+
REPEAT_DETERM o resolve_tac ctxt (@{thms supp_inv_bound supp_comp_bound}
385+
@ [infinite_UNIV]
369386
@ maps (map_filter I o #SSupp_map_bound) facts' @ prems @ #SSupp_comp_bound bmv_facts
370387
),
371388
K (Local_Defs.unfold0_tac ctxt @{thms comp_assoc}),
@@ -387,8 +404,8 @@ fun mk_mrsbnf fact_policy qualify (deads, As, As', Bs, Fs, fs) name_opt mrbnfs b
387404
map_Sb_strong = map_Sb_strong
388405
}: mrsbnf_facts end
389406
) axioms' facts' mrbnfs (BMV_Monad_Def.axioms_of_bmv_monad bmv) (BMV_Monad_Def.facts_of_bmv_monad bmv)
390-
(BMV_Monad_Def.Sbs_of_bmv_monad bmv) (BMV_Monad_Def.Injs_of_bmv_monad bmv)
391-
(BMV_Monad_Def.SSupps_of_bmv_monad bmv);
407+
(BMV_Monad_Def.Sbs_of_bmv_monad bmv) (BMV_Monad_Def.RVrs_of_bmv_monad bmv)
408+
(BMV_Monad_Def.Injs_of_bmv_monad bmv) (BMV_Monad_Def.SSupps_of_bmv_monad bmv);
392409

393410
val mrsbnf = MRSBNF {
394411
mrbnfs = mrbnfs,
@@ -447,7 +464,7 @@ fun mk_mrsbnf_axioms mrbnfs bmv lthy =
447464
) mrbnfs (BMV_Monad_Def.Sbs_of_bmv_monad bmv) (BMV_Monad_Def.Maps_of_bmv_monad bmv);
448465
end;
449466

450-
val axioms = @{map 6} (fn mrbnf => fn Sb => fn Injs => fn SSupps => fn Vrs => fn bmv_frees =>
467+
val axioms = @{map 7} (fn mrbnf => fn Sb => fn Injs => fn SSupps => fn RVrs => fn Vrs => fn bmv_frees =>
451468
let
452469
val mapx = MRBNF_Def.map_of_mrbnf mrbnf;
453470
val var_types = MRBNF_Def.var_types_of_mrbnf mrbnf;
@@ -468,7 +485,9 @@ fun mk_mrsbnf_axioms mrbnfs bmv lthy =
468485
(map HOLogic.id_const As) (map HOLogic.id_const Bs) (free_fs @ map HOLogic.id_const (drop (length frees) Fs))
469486
(MRBNF_Def.var_types_of_mrbnf mrbnf)
470487
),
471-
Term.list_comb (Sb, map (fn Inj =>
488+
Term.list_comb (Sb, map (fn RVr => the (List.find (fn f =>
489+
HOLogic.dest_setT (body_type (fastype_of RVr)) = domain_type (fastype_of f)
490+
) fs)) RVrs @ map (fn Inj =>
472491
HOLogic.mk_comp (Inj, the (List.find (fn f => (op=) (apply2 (domain_type o fastype_of) (Inj, f))) fs))
473492
) Injs)
474493
)));
@@ -512,12 +531,11 @@ fun mk_mrsbnf_axioms mrbnfs bmv lthy =
512531
mk_Trueprop_eq (set $ (Term.list_comb (Sb, gs) $ x), set $ x)
513532
))) sets' end;
514533

515-
val Vrs' = bmv_frees ~~ transpose Vrs;
516534
val set_Vrs = map (fn set =>
517535
let
518536
val aT = HOLogic.dest_setT (fastype_of (set $ x));
519-
val Vrs = the (AList.lookup (op=) Vrs' aT);
520-
val Vrs' = map_filter (Option.map (fn Vrs => Vrs $ x)) Vrs;
537+
val Vrs = filter (curry (op=) aT o HOLogic.dest_setT o body_type o fastype_of) (RVrs @ Vrs);
538+
val Vrs' = map (fn Vrs => Vrs $ x) Vrs;
521539
in Logic.all x (mk_Trueprop_eq (set $ x, case Vrs' of
522540
[] => mk_bot aT
523541
| _ => foldl1 mk_Un Vrs'
@@ -530,8 +548,8 @@ fun mk_mrsbnf_axioms mrbnfs bmv lthy =
530548
set_Sb = set_Sbs
531549
}: term mrsbnf_axioms end
532550
) mrbnfs (BMV_Monad_Def.Sbs_of_bmv_monad bmv) (BMV_Monad_Def.Injs_of_bmv_monad bmv)
533-
(BMV_Monad_Def.SSupps_of_bmv_monad bmv) (BMV_Monad_Def.Vrs_of_bmv_monad bmv)
534-
(BMV_Monad_Def.frees_of_bmv_monad bmv);
551+
(BMV_Monad_Def.SSupps_of_bmv_monad bmv) (BMV_Monad_Def.RVrs_of_bmv_monad bmv)
552+
(BMV_Monad_Def.Vrs_of_bmv_monad bmv) (BMV_Monad_Def.frees_of_bmv_monad bmv);
535553

536554
in (axioms, (deads, As, As', Bs, Fs, fs), mrbnfs, bmv) end
537555

operations/BMV_Fixpoint.thy

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ type_synonym ('tv, 'v, 'btv, 'bv, 'c, 'd) FTerm_pre' =
99
+ 'bv * 'tv FType * 'c \<comment>\<open>Lam x::'v \<open>'tv FType\<close> t::\<open>('tv, 'v) FTerm\<close> binds x in t\<close>
1010
+ 'btv * 'c \<comment>\<open>TyLam a::'tv t::\<open>('tv, 'v) FTerm\<close> binds a in t\<close>"
1111

12-
ML_file \<open>../Tools/mrsbnf_comp.ML\<close>
13-
12+
(*ML_file \<open>../Tools/mrsbnf_comp.ML\<close>*)
1413

1514

1615

0 commit comments

Comments
 (0)