Cartesian calculus of substitutions
The (cartesian) calculus of substitutions is one way of presenting a (dependent, cartesian) type theory as a formal system which is naturally viewed as having semantics in a cartesian category. It can be viewed as an extension of the linear calculus of substitutions, but here we give a full presentation following Principles of dependent type theory.
Notes on this presentation
We use De Brujin indices, and describe Syntax sugar for named variables. Following Principles, “implicit” arguments are made explicit in grey, for example we have
. We also have “meta-implicit arguments” for judgements, which are called presuppositions (notation 2.2.1). The surface syntax for our judgements differs slightly. Γ ⊢ 𝐢 𝐝 Γ : Γ
Judgements
We have the following basic judgements:
asserts thatΓ ⊢ is a context.Γ asserts thatΓ ⊢ 𝐴 is a type (in context𝐴 ).[^1]Γ , presupposingΓ ⊢ 𝑎 : 𝐴 andΓ ⊢ , asserts that⊢ 𝐴 is a term of type𝑎 in context𝐴 .Γ , presupposingΓ ⊢ 𝛾 : Δ andΓ ⊢ , asserts thatΔ ⊢ is a substitution from𝛾 toΓ , that is,Δ fills all the hypotheses of𝛾 with terms inΔ .Γ
We also have the following manifestations of judgemental equality:
, presupposingΔ ⊢ 𝛾 = 𝛾 ′ : Γ andΔ ⊢ 𝛾 : Γ , asserts thatΔ ⊢ 𝛾 ′ : Γ and𝛾 are equal substitutions from𝛾 ′ toΔ .Γ , presupposingΓ ⊢ 𝐴 = 𝐴 ′ andΓ ⊢ 𝐴 , asserts thatΓ ⊢ 𝐴 ′ and𝐴 are equal types in context𝐴 ′ .Γ , presupposingΓ ⊢ 𝑎 = 𝑎 ′ : 𝐴 andΓ ⊢ 𝑎 : 𝐴 , asserts thatΓ ⊢ 𝑎 ′ : 𝐴 and𝑎 are equal terms of type𝑎 ′ in context𝐴 .Γ
We will also sometimes consider
, presupposingΔ = Γ ⊢ andΔ ⊢ , asserts thatΓ ⊢ andΔ are equal contexts,Γ
although this is redundant as it reduces to equality of types. Judgemental structure suggests the following meta-sets:
- The meta-set
of contexts;C x = { Γ : ∣ : Γ ⊢ } - For
, the meta-setΓ ∈ C x of types overT y ( Γ ) = { 𝑇 : ∣ : Γ ⊢ 𝑇 } ;Γ - For
andΓ ∈ C x , the meta-set𝑇 ∈ T y ( Γ ) of terms of typeT m ( Γ , 𝑇 ) = { 𝑡 : ∣ : Γ ⊢ 𝑡 : 𝑇 } over𝑇 ;Γ - For
, the meta-setΓ , Δ ∈ C x of substitutions fromS b ( Δ , Γ ) = { 𝛾 : ∣ : Δ ⊢ 𝛾 : Γ } toΔ .Γ
In practice these may be thought of as equivalence classes of derivation trees with the appropriate judgement at the root.
Inference rules
Context formation
The creation of contexts is governed by
A context is thus a list of types
Assuming hypotheses
, the judgement thesis 𝐴 1 , … , 𝐴 𝑛 holds. J
or what is the same
Given a variables of each type
, the judgement thesis 𝐴 1 , … , 𝐴 𝑛 . J
Judgemental equality of contexts
We can define equality of contexts recursively by
∅ = ∅ ⊢ Γ = Δ ⊢ Γ ⊢ 𝐴 = 𝐵 Γ , 𝐴 = Δ , 𝐵 ⊢ which is why this judgement is considered redundant.
Substitutions form a category
The “algebra” of substitutions is governed by the following inference rules:
In concert these ensure that the meta-set of contexts
Substitutions act on types and terms from the right
Substitutions act on both types and terms on the right, so:
Moreover, this action respects the categorical structure of substitutions:
Cartesian contexts
First we establish
We now establish that
The left projection
The right projection
Finally, we have ”
Syntax sugar for named variables
While the above presentation has nice formal properties, its use of De Brujin indices makes it hard to parse. Note that by the variable and weakening rules,
so we can see
for the same judgement. These should be viewed as syntax sugar reducing to judgements of the form given above, so for example
is the same judgement. When applying substitutions into named contexts, we are explicit about which named variable is being substituted into, for example we have
which in the formal syntax is