1313(* * {6 Explicit substitutions } *)
1414(* * Explicit substitutions for some type of terms ['a].
1515
16- Assuming terms enjoy a notion of typability Γ ⊢ t : A, where Γ is a
17- telescope and A a type, substitutions can be typed as Γ ⊢ σ : Δ, where
18- as a first approximation σ is a list of terms u₁; ...; uₙ s.t.
19- Δ := (x₁ : A₁), ..., (xₙ : Aₙ) and Γ ⊢ uᵢ : Aᵢ{u₁...uᵢ₋₁} for all 1 ≤ i ≤ n.
16+ Assuming terms enjoy a notion of typability [Γ ⊢ t : A], where [Γ] is a
17+ telescope and [A] a type, substitutions can be typed as [Γ ⊢ σ : Δ], where
18+ as a first approximation [σ] is a list of terms [[u₁; ...; uₙ]] s.t.
19+ [Δ := (x₁ : A₁), ..., (xₙ : Aₙ)] and [Γ ⊢ uᵢ : Aᵢ{u₁...uᵢ₋₁}]
20+ for all [1 ≤ i ≤ n].
2021
2122 Substitutions can be applied to terms as follows, and furthermore
22- if Γ ⊢ σ : Δ and Δ ⊢ t : A, then Γ ⊢ t{σ} : A{σ}.
23+ if [ Γ ⊢ σ : Δ] and [ Δ ⊢ t : A] , then [ Γ ⊢ t{σ} : A{σ}] .
2324
2425 We make the typing rules explicit below, but we omit the explicit De Bruijn
2526 fidgetting and leave relocations implicit in terms and types.
@@ -29,79 +30,82 @@ type 'a subs
2930
3031(* * Derived constructors granting basic invariants *)
3132
32- (* * Assuming |Γ| = n, Γ ⊢ subs_id n : Γ *)
33+ (* * Assuming [ |Γ| = n], [ Γ ⊢ subs_id n : Γ] *)
3334val subs_id : int -> 'a subs
3435
35- (* * Assuming Γ ⊢ σ : Δ and Γ ⊢ t : A{σ}, then Γ ⊢ subs_cons t σ : Δ, A *)
36+ (* * Assuming [ Γ ⊢ σ : Δ] and [ Γ ⊢ t : A{σ}] , then [ Γ ⊢ subs_cons t σ : Δ, A] *)
3637val subs_cons : 'a -> 'a subs -> 'a subs
3738
38- (* * Assuming Γ ⊢ σ : Δ and |Ξ| = n, then Γ, Ξ ⊢ subs_shft (n, σ) : Δ *)
39+ (* * Assuming [ Γ ⊢ σ : Δ] and [ |Ξ| = n] , then [ Γ, Ξ ⊢ subs_shft (n, σ) : Δ] *)
3940val subs_shft : int * 'a subs -> 'a subs
4041
41- (* * Assuming Γ ⊢ σ : Δ and |Ξ| = n, then Γ, Ξ ⊢ subs_liftn n σ : Δ, Ξ *)
42+ (* * Assuming [ Γ ⊢ σ : Δ] and [ |Ξ| = n] , then [ Γ, Ξ ⊢ subs_liftn n σ : Δ, Ξ] *)
4243val subs_liftn : int -> 'a subs -> 'a subs
4344
4445(* * Unary variant of {!subst_liftn}. *)
4546val subs_lift : 'a subs -> 'a subs
4647
4748(* * [expand_rel k subs] expands de Bruijn [k] in the explicit substitution
48- [subs]. The result is either (Inl(lams,v)) when the variable is
49- substituted by value [v] under [lams] binders (i.e. v *has* to be
50- shifted by [lams]), or (Inr (k',p)) when the variable k is just relocated
51- as k'; p is None if the variable points inside subs and Some(k) if the
52- variable points k bindings beyond subs (cf argument of ESID).
49+ [subs]. The result is either [Inl (lams, v)] when the variable is
50+ substituted by value [v] under [lams] binders (i.e. [v] *has* to be
51+ shifted by [lams]), or [Inr (k', p)] when the variable [k] is just
52+ relocated as [k']; [p] is [None] if the variable points inside [subs]
53+ and [Some k] if the variable points [k] bindings beyond [subs]
54+ (cf argument of [ESID]).
5355*)
5456val expand_rel : int -> 'a subs -> (int * 'a , int * int option ) Util .union
5557
5658(* * Tests whether a substitution behaves like the identity *)
5759val is_subs_id : 'a subs -> bool
5860
59- (* * {6 Compact representation } *)
61+ (* * {6 Compact representation} *)
6062(* * Compact representation of explicit relocations
61- - [ELSHFT(l,n)] == lift of [n], then apply [lift l].
62- - [ELLFT(n,l)] == apply [l] to de Bruijn > [n] i.e under n binders.
63+ - [ELID]: identity relocation [id]
64+ - [ELSHFT (σ, n)]: shift of [n], then [σ]; [↑^n ∘ σ] in sigma calculi
65+ - [ELLFT (n, σ)]: apply [σ] to de Bruijn > [n], i.e under [n] binders;
66+ [⇑^n(σ)] in sigma calculi
6367
64- Invariant ensured by the private flag: no lift contains two consecutive
65- [ELSHFT] nor two consecutive [ELLFT ].
68+ Invariant ensured by the private flag: no lift contains an [ELLFT] of [ELID],
69+ two consecutive [ELLFT] or two consecutive [ELSHFT ].
6670
6771 Relocations are a particular kind of substitutions that only contain
68- variables. In particular, [el_*] enjoys the same typing rules as the
72+ variables. In particular, [el_*] enjoys similar typing rules as the
6973 equivalent substitution function [subs_*].
7074*)
7175type lift = private
7276 | ELID
7377 | ELSHFT of lift * int
7478 | ELLFT of int * lift
7579
76- (* * For arbitrary Γ: Γ ⊢ el_id : Γ *)
80+ (* * For arbitrary Γ, [ Γ ⊢ el_id : Γ] *)
7781val el_id : lift
7882
79- (* * Assuming Γ ⊢ σ : Δ₁, Δ₂ and |Δ₂ | = n, then Γ ⊢ el_shft n σ : Δ₁ *)
83+ (* * Assuming [ Γ ⊢ σ : Δ, Ξ] and [|Ξ | = n] , then [ Γ ⊢ el_shft n σ : Δ] *)
8084val el_shft : int -> lift -> lift
8185
82- (* * Assuming Γ ⊢ σ : Δ and |Ξ| = n, then Γ, Ξ ⊢ el_liftn n σ : Δ, Ξ *)
86+ (* * Assuming [ Γ ⊢ σ : Δ] and [ |Ξ| = n] , then [ Γ, Ξ ⊢ el_liftn n σ : Δ, Ξ] *)
8387val el_liftn : int -> lift -> lift
8488
8589(* * Unary variant of {!el_liftn}. *)
8690val el_lift : lift -> lift
8791
88- (* * Assuming Γ₁, A, Γ₂ ⊢ σ : Δ₁, A, Δ₂ and Δ₁, A, Δ₂ ⊢ n : A,
89- then Γ₁, A, Γ₂ ⊢ reloc_rel n σ : A *)
92+ (* * Assuming [ Γ₁, A, Γ₂ ⊢ σ : Δ₁, A, Δ₂] and [ Δ₁, A, Δ₂ ⊢ n : A] ,
93+ then [ Γ₁, A, Γ₂ ⊢ reloc_rel n σ : A] *)
9094val reloc_rel : int -> lift -> int
9195
9296val is_lift_id : lift -> bool
9397
9498(* * Lift applied to substitution: [lift_subst mk_clos el s] computes a
95- substitution equivalent to applying el then s . Argument
96- mk_clos is used when a closure has to be created, i.e. when
97- el is applied on an element of s .
99+ substitution equivalent to applying [el] then [s] . Argument
100+ [ mk_clos] is used when a closure has to be created, i.e. when
101+ [el] is applied on an element of [s] .
98102
99- That is, if Γ ⊢ e : Δ and Δ ⊢ σ : Ξ, then Γ ⊢ lift_subst mk e σ : Ξ.
103+ That is, if [ Γ ⊢ e : Δ] and [ Δ ⊢ σ : Ξ] , then [ Γ ⊢ lift_subst mk e σ : Ξ] .
100104*)
101105val lift_subst : (lift -> 'a -> 'b ) -> lift -> 'a subs -> 'b subs
102106
107+ (* * Structural equality for lifts *)
103108val eq_lift : lift -> lift -> bool
104- (* * Equality for lifts *)
105109
106110(* * Debugging utilities *)
107111module Internal :
0 commit comments