Skip to content

Commit 8904c53

Browse files
committed
Prove supported functor structure
1 parent b26ae73 commit 8904c53

File tree

2 files changed

+211
-27
lines changed

2 files changed

+211
-27
lines changed

Tools/bmv_monad_def.ML

Lines changed: 162 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
signature BMV_MONAD_DEF = sig
22
type bmv_monad
3-
type supported_functor (* TODO *)
3+
4+
type 'a supported_functor_axioms = {
5+
Map_id: 'a,
6+
Map_comp: 'a,
7+
Supp_Map: 'a list,
8+
Map_cong: 'a
9+
};
410

511
type 'a bmv_monad_axioms = {
612
Sb_Inj: 'a,
@@ -10,7 +16,12 @@ signature BMV_MONAD_DEF = sig
1016
Vrs_bds: 'a option list list,
1117
Vrs_Injs: 'a option list list,
1218
Vrs_Sbs: 'a option list list
13-
(* Add optional Map_Sb axiom (dependent on iff Map exists) *)
19+
};
20+
21+
type supported_functor_model = {
22+
Map: term,
23+
Supps: term list,
24+
tacs: (Proof.context -> tactic) supported_functor_axioms
1425
};
1526

1627
type bmv_monad_model = {
@@ -19,11 +30,15 @@ signature BMV_MONAD_DEF = sig
1930
var_class: class,
2031
bmv_ops: bmv_monad list,
2132
frees: typ list,
22-
lives: typ list,
2333
leader: int,
34+
lives: typ list,
35+
lives': typ list,
36+
params: {
37+
model: supported_functor_model,
38+
Map_Sb: Proof.context -> tactic
39+
} option list,
2440
Injs: term list list,
2541
Sbs: term list,
26-
Maps: term option list,
2742
Vrs: term option list list list,
2843
tacs: (Proof.context -> tactic) bmv_monad_axioms list
2944
}
@@ -34,9 +49,11 @@ signature BMV_MONAD_DEF = sig
3449
val leader_of_bmv_monad: bmv_monad -> int;
3550
val frees_of_bmv_monad: bmv_monad -> typ list;
3651
val lives_of_bmv_monad: bmv_monad -> typ list;
52+
val lives'_of_bmv_monad: bmv_monad -> typ list;
3753
val Injs_of_bmv_monad: bmv_monad -> term list list;
3854
val Sbs_of_bmv_monad: bmv_monad -> term list;
3955
val Maps_of_bmv_monad: bmv_monad -> term option list;
56+
val Supps_of_bmv_monad: bmv_monad -> term list option list;
4057
val Vrs_of_bmv_monad: bmv_monad -> term option list list list;
4158

4259
val morph_bmv_monad: morphism -> bmv_monad -> bmv_monad;
@@ -73,38 +90,70 @@ fun morph_bmv_axioms phi {
7390
Vrs_Sbs = map (map (Option.map (Morphism.thm phi))) Vrs_Sbs
7491
} : thm bmv_monad_axioms
7592

93+
type 'a supported_functor_axioms = {
94+
Map_id: 'a,
95+
Map_comp: 'a,
96+
Supp_Map: 'a list,
97+
Map_cong: 'a
98+
};
99+
100+
fun morph_supported_functor_axioms phi { Map_id, Map_comp, Supp_Map, Map_cong } = {
101+
Map_id = Morphism.thm phi Map_id,
102+
Map_comp = Morphism.thm phi Map_comp,
103+
Supp_Map = map (Morphism.thm phi) Supp_Map,
104+
Map_cong = Morphism.thm phi Map_cong
105+
} : thm supported_functor_axioms;
106+
107+
type supported_functor_model = {
108+
Map: term,
109+
Supps: term list,
110+
tacs: (Proof.context -> tactic) supported_functor_axioms
111+
};
112+
76113
datatype bmv_monad = BMV of {
77114
ops: typ list,
78115
bd: term,
79116
var_class: class,
80117
leader: int,
81118
frees: typ list,
82119
lives: typ list,
120+
lives': typ list,
121+
params: {
122+
Map: term,
123+
Supps: term list,
124+
axioms: thm supported_functor_axioms,
125+
Map_Sb: thm
126+
} option list,
83127
Injs: term list list,
84128
Sbs: term list,
85-
Maps: term option list,
86129
Vrs: term option list list list,
87130
axioms: thm bmv_monad_axioms list
88131
}
89132

133+
fun morph_bmv_param phi { Map, Supps, axioms, Map_Sb } = {
134+
Map = Morphism.term phi Map,
135+
Supps = map (Morphism.term phi) Supps,
136+
axioms = morph_supported_functor_axioms phi axioms,
137+
Map_Sb = Morphism.thm phi Map_Sb
138+
};
139+
90140
fun morph_bmv_monad phi (BMV {
91-
ops, bd, var_class, leader, frees, lives, Injs, Sbs, Maps, Vrs, axioms
141+
ops, bd, var_class, leader, frees, lives, lives', params, Injs, Sbs, Vrs, axioms
92142
}) = BMV {
93143
ops = map (Morphism.typ phi) ops,
94144
bd = Morphism.term phi bd,
95145
leader = leader,
96146
var_class = var_class,
97147
frees = map (Morphism.typ phi) frees,
98148
lives = map (Morphism.typ phi) lives,
149+
lives' = map (Morphism.typ phi) lives',
150+
params = map (Option.map (morph_bmv_param phi)) params,
99151
Injs = map (map (Morphism.term phi)) Injs,
100152
Sbs = map (Morphism.term phi) Sbs,
101-
Maps = map (Option.map (Morphism.term phi)) Maps,
102153
Vrs = map (map (map (Option.map (Morphism.term phi)))) Vrs,
103154
axioms = map (morph_bmv_axioms phi) axioms
104155
}
105156

106-
datatype supported_functor = Supported_Functor (* TODO *)
107-
108157
fun Rep_bmv (BMV x) = x
109158

110159
val ops_of_bmv_monad = #ops o Rep_bmv
@@ -113,41 +162,70 @@ val var_class_of_bmv_monad = #var_class o Rep_bmv;
113162
val leader_of_bmv_monad = #leader o Rep_bmv
114163
val frees_of_bmv_monad = #frees o Rep_bmv
115164
val lives_of_bmv_monad = #lives o Rep_bmv
165+
val lives'_of_bmv_monad = #lives' o Rep_bmv
116166
val Injs_of_bmv_monad = #Injs o Rep_bmv
117167
val Sbs_of_bmv_monad = #Sbs o Rep_bmv
118-
val Maps_of_bmv_monad = #Maps o Rep_bmv
168+
val Maps_of_bmv_monad = map (Option.map #Map) o #params o Rep_bmv
169+
val Supps_of_bmv_monad = map (Option.map #Supps) o #params o Rep_bmv
119170
val Vrs_of_bmv_monad = #Vrs o Rep_bmv
120171

172+
type supported_functor_model = {
173+
Map: term,
174+
Supps: term list,
175+
tacs: (Proof.context -> tactic) supported_functor_axioms
176+
};
177+
178+
fun morph_supported_functor_model phi { Map, Supps, tacs } = {
179+
Map = Morphism.term phi Map,
180+
Supps = map (Morphism.term phi) Supps,
181+
tacs = tacs
182+
} : supported_functor_model;
183+
121184
type bmv_monad_model = {
122185
ops: typ list,
123186
bd: term,
124187
var_class: class,
125188
frees: typ list,
126189
lives: typ list,
190+
lives': typ list,
191+
params: {
192+
model: supported_functor_model,
193+
Map_Sb: Proof.context -> tactic
194+
} option list,
127195
bmv_ops: bmv_monad list,
128196
leader: int,
129197
Injs: term list list,
130198
Sbs: term list,
131-
Maps: term option list,
132199
Vrs: term option list list list,
133200
tacs: (Proof.context -> tactic) bmv_monad_axioms list
134201
}
135202

136-
fun morph_bmv_monad_model phi ({ ops, bd, var_class, frees, lives, bmv_ops, leader, Injs, Sbs, Maps, Vrs, tacs }: bmv_monad_model) = {
203+
fun morph_bmv_monad_model phi ({ ops, bd, var_class, frees, lives, lives', params, bmv_ops, leader, Injs, Sbs, Vrs, tacs }: bmv_monad_model) = {
137204
ops = map (Morphism.typ phi) ops,
138205
bd = Morphism.term phi bd,
139206
var_class = var_class,
140207
frees = map (Morphism.typ phi) frees,
141208
lives = map (Morphism.typ phi) lives,
209+
lives' = map (Morphism.typ phi) lives',
210+
params = map (Option.map (fn { model, Map_Sb } => {
211+
model = morph_supported_functor_model phi model,
212+
Map_Sb = Map_Sb
213+
})) params,
142214
bmv_ops = map (morph_bmv_monad phi) bmv_ops,
143215
leader = leader,
144216
Injs = map (map (Morphism.term phi)) Injs,
145217
Sbs = map (Morphism.term phi) Sbs,
146-
Maps = map (Option.map (Morphism.term phi)) Maps,
147218
Vrs = map (map (map (Option.map (Morphism.term phi)))) Vrs,
148219
tacs = tacs
149220
} : bmv_monad_model;
150221

222+
val mk_small_prems = map2 (fn rho => fn Inj => HOLogic.mk_Trueprop (mk_ordLess
223+
(mk_card_of (HOLogic.mk_Collect ("a", fst (dest_funT (fastype_of Inj)),
224+
HOLogic.mk_not (HOLogic.mk_eq (rho $ Bound 0, Inj $ Bound 0))
225+
)))
226+
(mk_card_of (HOLogic.mk_UNIV (fst (dest_funT (fastype_of Inj)))))
227+
));
228+
151229
fun prove_axioms (model: bmv_monad_model) lthy =
152230
let
153231
val Ts = #ops model @ maps ops_of_bmv_monad (#bmv_ops model);
@@ -173,14 +251,8 @@ fun prove_axioms (model: bmv_monad_model) lthy =
173251
mk_Trueprop_eq (Term.list_comb (Sb, Injs), HOLogic.id_const T)
174252
) (fn {context=ctxt, ...} => #Sb_Inj tacs ctxt);
175253

176-
fun mk_small_prems rhos = map2 (fn rho => fn Inj => HOLogic.mk_Trueprop (mk_ordLess
177-
(mk_card_of (HOLogic.mk_Collect ("a", fst (dest_funT (fastype_of Inj)),
178-
HOLogic.mk_not (HOLogic.mk_eq (rho $ Bound 0, Inj $ Bound 0))
179-
)))
180-
(mk_card_of (HOLogic.mk_UNIV (fst (dest_funT (fastype_of Inj)))))
181-
)) rhos Injs;
182-
val small_prems = mk_small_prems rhos;
183-
val small_prems' = mk_small_prems rhos';
254+
val small_prems = mk_small_prems rhos Injs;
255+
val small_prems' = mk_small_prems rhos' Injs;
184256

185257
val Sb_comp_Injs = @{map 3} (fn Inj => fn rho => fn tac => Goal.prove_sorry lthy [] [] (
186258
fold_rev Logic.all rhos (fold_rev (curry Logic.mk_implies) small_prems (mk_Trueprop_eq (
@@ -261,6 +333,72 @@ fun prove_axioms (model: bmv_monad_model) lthy =
261333
) (#ops model) (#Injs model) (#Sbs model) (#Vrs model) (#tacs model);
262334
in axioms end;
263335

336+
fun prove_params (model: bmv_monad_model) lthy = @{map 4} (fn T => fn Sb => fn Injs => Option.map (fn param =>
337+
let
338+
val (Cs, _) = lthy
339+
|> mk_TFrees (length (#lives model));
340+
val ((((fs, gs), rhos), x), _) = lthy
341+
|> mk_Frees "f" (map2 (curry (op-->)) (#lives model) (#lives' model))
342+
||>> mk_Frees "g" (map2 (curry (op-->)) (#lives' model) Cs)
343+
||>> mk_Frees "\<rho>" (map fastype_of Injs)
344+
||>> apfst hd o mk_Frees "x" [T];
345+
val pmodel = #model param;
346+
347+
val Map_id = Goal.prove_sorry lthy [] [] (Term.subst_atomic_types (#lives' model ~~ #lives model) (
348+
mk_Trueprop_eq (
349+
Term.list_comb (#Map pmodel, map HOLogic.id_const (#lives model)), HOLogic.id_const T
350+
)
351+
)) (fn {context=ctxt, ...} => #Map_id (#tacs pmodel) ctxt);
352+
353+
val Map_comp = Goal.prove_sorry lthy [] [] (fold_rev Logic.all (fs @ gs) (mk_Trueprop_eq (
354+
HOLogic.mk_comp (Term.list_comb (
355+
Term.subst_atomic_types ((#lives model @ #lives' model) ~~ (#lives' model @ Cs)) (#Map pmodel), gs
356+
), Term.list_comb (#Map pmodel, fs)),
357+
Term.list_comb (Term.subst_atomic_types (#lives' model ~~ Cs) (#Map pmodel), map2 (curry HOLogic.mk_comp) gs fs)
358+
))) (fn {context=ctxt, ...} => #Map_comp (#tacs pmodel) ctxt);
359+
360+
val Supp_Maps = @{map 3} (fn Supp => fn f => fn tac =>
361+
Goal.prove_sorry lthy [] [] (fold_rev Logic.all (fs @ [x]) (mk_Trueprop_eq (
362+
Term.subst_atomic_types (#lives model ~~ #lives' model) Supp $ (Term.list_comb (#Map pmodel, fs) $ x),
363+
mk_image f $ (Supp $ x)
364+
))) (fn {context=ctxt, ...} => tac ctxt)
365+
) (#Supps pmodel) fs (#Supp_Map (#tacs pmodel));
366+
367+
val (gs', _) = lthy
368+
|> mk_Frees "g" (map fastype_of fs);
369+
val Map_cong = Goal.prove_sorry lthy [] [] (fold_rev Logic.all (fs @ gs' @ [x]) (
370+
fold_rev (curry Logic.mk_implies) (@{map 3} (fn Supp => fn f => fn g =>
371+
let val a = Free ("a", hd (binder_types (fastype_of f)));
372+
in Logic.all a (Logic.mk_implies (
373+
HOLogic.mk_Trueprop (HOLogic.mk_mem (a, Supp $ x)),
374+
mk_Trueprop_eq (f $ a, g $ a)
375+
)) end
376+
) (#Supps pmodel) fs gs') (mk_Trueprop_eq (
377+
Term.list_comb (#Map pmodel, fs) $ x,
378+
Term.list_comb (#Map pmodel, gs') $ x
379+
)))) (fn {context=ctxt, ...} => #Map_cong (#tacs pmodel) ctxt);
380+
381+
val Map_Sb = Goal.prove_sorry lthy [] [] (fold_rev Logic.all (fs @ rhos) (
382+
fold_rev (curry Logic.mk_implies) (mk_small_prems rhos Injs) (mk_Trueprop_eq (
383+
HOLogic.mk_comp (Term.list_comb (#Map pmodel, fs), Term.list_comb (Sb, rhos)),
384+
HOLogic.mk_comp (Term.list_comb (
385+
Term.subst_atomic_types (#lives model ~~ #lives' model) Sb, rhos
386+
), Term.list_comb (#Map pmodel, fs))
387+
))
388+
)) (fn {context=ctxt, ...} => #Map_Sb param ctxt);
389+
in {
390+
Map = #Map pmodel,
391+
Supps = #Supps pmodel,
392+
axioms = {
393+
Map_id = Map_id,
394+
Map_comp = Map_comp,
395+
Supp_Map = Supp_Maps,
396+
Map_cong = Map_cong
397+
},
398+
Map_Sb = Map_Sb
399+
} end
400+
)) (#ops model) (#Sbs model) (#Injs model) (#params model);
401+
264402
fun bmv_monad_def inline_policy fact_policy qualify (model: bmv_monad_model) lthy =
265403
let
266404
val _ = let
@@ -276,6 +414,7 @@ fun bmv_monad_def inline_policy fact_policy qualify (model: bmv_monad_model) lth
276414
val model = morph_bmv_monad_model (MRBNF_Util.subst_typ_morphism (#frees model ~~ frees)) model;
277415

278416
val axioms = prove_axioms model lthy;
417+
val params = prove_params model lthy;
279418

280419
val bmv = BMV {
281420
ops = #ops model @ maps (#ops o Rep_bmv) (#bmv_ops model),
@@ -284,10 +423,11 @@ fun bmv_monad_def inline_policy fact_policy qualify (model: bmv_monad_model) lth
284423
leader = #leader model,
285424
frees = #frees model,
286425
lives = #lives model,
426+
lives' = #lives' model,
427+
params = params,
287428
Injs = #Injs model @ maps (#Injs o Rep_bmv) (#bmv_ops model),
288429
Sbs = #Sbs model @ maps (#Sbs o Rep_bmv) (#bmv_ops model),
289430
Vrs = #Vrs model @ maps (#Vrs o Rep_bmv) (#bmv_ops model),
290-
Maps = #Maps model @ maps (#Maps o Rep_bmv) (#bmv_ops model),
291431
axioms = axioms @ maps (#axioms o Rep_bmv) (#bmv_ops model)
292432
} : bmv_monad;
293433
in (bmv, lthy) end

0 commit comments

Comments
 (0)