Skip to content

Commit 3848bd6

Browse files
create and use Coh.apply in the kernel
1 parent 1611cbe commit 3848bd6

8 files changed

Lines changed: 77 additions & 39 deletions

File tree

lib/functorialisation.ml

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,6 @@ let rec next_round l =
5252
(v :: vars, (Var.Bridge v, n - 1) :: left)
5353
| _ -> Error.fatal "cannot functorialise a negative number of times."
5454

55-
let pp_data_rename pp names =
56-
let name, susp, func = pp in
57-
let rec rename f =
58-
match f with
59-
| [] -> []
60-
| (x, i) :: f -> (Display_maps.var_apply_sub x names, i) :: rename f
61-
in
62-
(name, susp, List.map rename func)
63-
6455
(* Functorialised coherences with respect to locally maximal variables are
6556
coherences. This function updates the list of variables in the resulting
6657
coherence that come from a functorialisation *)
@@ -204,15 +195,12 @@ and ctx c l =
204195
(* Functorialisation of a coherence once with respect to a list of
205196
variables *)
206197
and coh_depth0 coh l =
207-
let ps, t, pp = Coh.forget coh in
208-
let ctxf = ctx (Unchecked.ps_to_ctx ps) l in
209-
let names = Unchecked.db_level_sub_inv ctxf in
210-
let psf = PS.forget (PS.mk (Ctx.check ctxf)) in
211-
let ty = ty t l (Coh (coh, Unchecked.identity_ps ps)) in
212-
let ty = Unchecked.ty_apply_sub ty names in
213-
let pp = pp_data l pp in
214-
let pp = pp_data_rename pp names in
215-
(check_coh psf ty pp, names)
198+
let ps, _, _ = Coh.forget coh in
199+
Coh.apply
200+
(fun c -> ctx c l)
201+
(fun t -> ty t l (Coh (coh, Unchecked.identity_ps ps)))
202+
(fun pp -> pp_data l pp)
203+
coh
216204

217205
and coh coh l =
218206
let ps, ty, _ = Coh.forget coh in

lib/inverse.ml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ let ty t =
1111

1212
let coh c =
1313
if not (Coh.is_inv c) then raise CohNonInv;
14-
let ps, t, (name, susp, func) = Coh.forget c in
15-
let ty_inv = ty t in
16-
check_coh ps ty_inv (name ^ "^-1", susp, func)
14+
Coh.apply_ps
15+
(fun ps -> ps)
16+
(fun t -> ty t)
17+
(fun (name, susp, func) -> (name ^ "^-1", susp, func))
18+
c
1719

1820
let rec compute_inverse t =
1921
match t with

lib/kernel.ml

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -564,13 +564,7 @@ end = struct
564564
let db_sub = Unchecked.db_level_sub_inv c in
565565
let c, _, _ = Unchecked.db_levels c in
566566
let c = Ctx.check c in
567-
let name, susp, func = fun_pp_data pp_data in
568-
let rec rename f =
569-
match f with
570-
| [] -> []
571-
| (x, i) :: f -> (Display_maps.var_apply_sub x db_sub, i) :: rename f
572-
in
573-
let pp_data = (name, susp, List.map rename func) in
567+
let pp_data = Display_maps.pp_data_rename (fun_pp_data pp_data) db_sub in
574568
let tm = Unchecked.tm_apply_sub (fun_tm (UnnamedTm.forget tm)) db_sub in
575569
(check c pp_data tm, db_sub)
576570
end
@@ -612,6 +606,20 @@ and Coh : sig
612606
val func_data : t -> (Var.t * int) list list
613607
val check_equal : t -> t -> unit
614608
val dim : t -> int
609+
610+
val apply_ps :
611+
(ps -> ps) ->
612+
(Unchecked_types(Coh)(Tm).ty -> Unchecked_types(Coh)(Tm).ty) ->
613+
(pp_data -> pp_data) ->
614+
t ->
615+
t
616+
617+
val apply :
618+
(Unchecked_types(Coh)(Tm).ctx -> Unchecked_types(Coh)(Tm).ctx) ->
619+
(Unchecked_types(Coh)(Tm).ty -> Unchecked_types(Coh)(Tm).ty) ->
620+
(pp_data -> pp_data) ->
621+
t ->
622+
t * Unchecked_types(Coh)(Tm).sub
615623
end = struct
616624
type cohInv = { ps : PS.t; ty : Ty.t }
617625

@@ -638,6 +646,7 @@ end = struct
638646

639647
open Unchecked (Coh) (Tm)
640648
module Unchecked = Make (Coh) (Tm)
649+
module Display_maps = Unchecked.Display_maps
641650

642651
let ps = function Inv (data, _) -> data.ps | NonInv (data, _) -> data.ps
643652

@@ -774,6 +783,22 @@ end = struct
774783
Ty.check_equal d1.total_ty d2.total_ty
775784
| Inv _, NonInv _ | NonInv _, Inv _ ->
776785
raise (NotEqual (to_string coh1, to_string coh2))
786+
787+
let apply_ps fun_ps fun_ty fun_pp_data coh =
788+
let ps, ty, pp = forget coh in
789+
let ps = fun_ps ps in
790+
let pp_data = fun_pp_data pp in
791+
let ty = fun_ty ty in
792+
check ps ty pp_data
793+
794+
let apply fun_ctx fun_ty fun_pp_data coh =
795+
let ps, ty, pp = forget coh in
796+
let ctx = fun_ctx (Unchecked.ps_to_ctx ps) in
797+
let ps = PS.forget (PS.mk (Ctx.check ctx)) in
798+
let db_sub = Unchecked.db_level_sub_inv ctx in
799+
let pp_data = Display_maps.pp_data_rename (fun_pp_data pp) db_sub in
800+
let ty = Unchecked.ty_apply_sub (fun_ty ty) db_sub in
801+
(check ps ty pp_data, db_sub)
777802
end
778803

779804
module U = Unchecked (Coh) (Tm)

lib/kernel.mli

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,20 @@ module rec Coh : sig
3333
* Unchecked_types(Coh)(Tm).ty
3434

3535
val func_data : t -> (Var.t * int) list list
36+
37+
val apply_ps :
38+
(ps -> ps) ->
39+
(Unchecked_types(Coh)(Tm).ty -> Unchecked_types(Coh)(Tm).ty) ->
40+
(pp_data -> pp_data) ->
41+
t ->
42+
t
43+
44+
val apply :
45+
(Unchecked_types(Coh)(Tm).ctx -> Unchecked_types(Coh)(Tm).ctx) ->
46+
(Unchecked_types(Coh)(Tm).ty -> Unchecked_types(Coh)(Tm).ty) ->
47+
(pp_data -> pp_data) ->
48+
t ->
49+
t * Unchecked_types(Coh)(Tm).sub
3650
end
3751

3852
and Ty : sig

lib/opposite.ml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,12 @@ and sub s op_data =
7777
| (x, (t, e)) :: s -> (x, (tm t op_data, e)) :: sub s op_data
7878

7979
and coh c op_data equiv =
80-
let p, t, pp_data = Coh.forget c in
81-
let op_p = ps p op_data in
82-
let op_t = ty t op_data in
83-
let t' = Unchecked.ty_sub_preimage op_t (Unchecked.sub_ps_to_sub equiv) in
84-
check_coh op_p t' (op_pp_data pp_data op_data)
80+
Coh.apply_ps
81+
(fun p -> ps p op_data)
82+
(fun t ->
83+
Unchecked.ty_sub_preimage (ty t op_data) (Unchecked.sub_ps_to_sub equiv))
84+
(fun pp -> op_pp_data pp op_data)
85+
c
8586

8687
and ctx c op_data =
8788
match c with

lib/suspension.ml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ let sub = iter_option Unchecked.suspend_sub
1717
let coh i coh =
1818
match i with
1919
| None | Some 0 -> coh
20-
| Some _ ->
21-
let p, t, ppd = Coh.forget coh in
22-
check_coh (ps i p) (ty i t) (pp_data i ppd)
20+
| Some _ -> Coh.apply_ps (ps i) (ty i) (pp_data i) coh
2321

2422
let checked_tm i t =
2523
match i with

lib/unchecked.ml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -718,8 +718,8 @@ struct
718718
"image of a variable by a display map must be a variable"
719719

720720
(* Pullback of a substitution along a display map. Returns the resulting
721-
* context with the right canonical inclusion. The left canonical inclusion is
722-
* the identity. *)
721+
* context with the right canonical inclusion. The left canonical inclusion is
722+
* the identity. *)
723723
let rec pullback c1 sub c2 dm =
724724
match (c2, dm) with
725725
| [], [] -> (c1, [])
@@ -737,7 +737,7 @@ struct
737737
context"
738738

739739
(* Universal property of the pullback, gluing substitutions s1 and s2. Requires
740-
* the inr canonical inclusion, the second context and the display map *)
740+
* the inr canonical inclusion, the second context and the display map *)
741741
let rec glue s1 s2 inr c2 dm =
742742
match (s2, c2, dm) with
743743
| [], [], [] -> s1
@@ -761,6 +761,15 @@ struct
761761
Error.fatal
762762
"wrong data pullback gluing: substitution must be point to the \
763763
context"
764+
765+
let pp_data_rename pp names =
766+
let name, susp, func = pp in
767+
let rec rename f =
768+
match f with
769+
| [] -> []
770+
| (x, i) :: f -> (var_apply_sub x names, i) :: rename f
771+
in
772+
(name, susp, List.map rename func)
764773
end
765774
end
766775
end

lib/unchecked.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ end) : sig
9797
val var_apply_sub : Var.t -> sub -> Var.t
9898
val pullback : ctx -> sub -> ctx -> sub -> ctx * sub
9999
val glue : sub -> sub -> sub -> ctx -> sub -> sub
100+
val pp_data_rename : pp_data -> sub -> pp_data
100101
end
101102
end
102103
end

0 commit comments

Comments
 (0)