Calculus of substitutions

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:

  1. Γ asserts that Γ is a context.
  2. Γ 𝐴 asserts that 𝐴 is a type (in context Γ).[^1]
  3. Γ 𝑎 :𝐴, presupposing Γ and 𝐴, asserts that 𝑎 is a term of type 𝐴 in context Γ.
  4. Γ 𝛾 :Δ, 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:

  1. Δ 𝛾 =𝛾 :Γ, presupposing Δ 𝛾 :Γ and Δ 𝛾 :Γ, asserts that 𝛾 and 𝛾 are equal substitutions from Δ to Γ.
  2. Γ 𝐴 =𝐴, presupposing Γ 𝐴 and Γ 𝐴, asserts that 𝐴 and 𝐴 are equal types in context Γ.
  3. Γ 𝑎 =𝑎 :𝐴, presupposing Γ 𝑎 :𝐴 and Γ 𝑎 :𝐴, asserts that 𝑎 and 𝑎 are equal terms of type 𝐴 in context Γ.

We will also sometimes consider

  1. Δ =Γ , 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:

  1. The meta-set Cx ={Γ ::Γ } of contexts;
  2. For Γ Cx, the meta-set Ty(Γ) ={𝑇 ::Γ 𝑇} of types over Γ;
  3. For Γ Cx and 𝑇 Ty(Γ), the meta-set Tm(Γ,𝑇) ={𝑡 ::Γ 𝑡 :𝑇} of terms of type 𝑇 over Γ;
  4. For Γ,Δ Cx, the meta-set Sb(Δ,Γ) ={𝛾 ::Δ 𝛾 :Γ} of substitutions from Δ 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 Γ =.𝐴1𝐴𝑛, each of which may depend on the previous one. Thus we ready Γ J as

Assuming hypotheses 𝐴1,,𝐴𝑛, the judgement thesis J holds.

or what is the same

Given a variables of each type 𝐴1,,𝐴𝑛, the judgement thesis J.

Substitutions form a category

The “algebra” of substitutions is governed by the following inference rules:

ΓΓ𝐢𝐝Γ:ΓΓ2𝛾1:Γ1Γ1𝛾0:Γ0Γ2𝛾0Γ0,Γ1,Γ2𝛾1:Γ0 Δ𝛾:ΓΔ𝐢𝐝Γ𝛾=𝛾:ΓΔ𝛾:ΓΔ𝛾𝐢𝐝Δ=𝛾:Γ Γ1𝛾0:Γ0Γ2𝛾1:Γ1Γ3𝛾2:Γ2Γ3𝛾0(𝛾1𝛾2)=(𝛾0𝛾1)𝛾2:Γ0

In concert these ensure that the meta-set of contexts Cx and the meta-sets of substitutions Sb(Δ,Γ) form a category, which we also denote Cx.

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:

Γ𝐴Γ𝐴[𝐢𝐝Γ]=𝐴Γ𝑎:𝐴Γ𝑎[𝐢𝐝Γ]=𝑎:𝐴 Γ2𝛾1:Γ1Γ1𝛾0:Γ0Γ0𝐴Γ2𝐴[𝛾0𝛾1]=𝐴[𝛾0][𝛾1] Γ2𝛾1:Γ1Γ1𝛾0:Γ0Γ0𝑎:𝐴Γ2𝑎[𝛾0𝛾1]=𝑎[𝛾0][𝛾1]:𝐴[𝛾0𝛾1]

Cartesian contexts

First we establish is the terminal object in Cx:

ΓΓ!Γ:Γ𝛿:Γ!Γ=𝛿:

We now establish that Γ.𝐴 is something like a categorical product. For the “universal morphism” we have the subsitution extension 𝛾.𝑎, which given a substitution Δ :𝛾 Γ allows us to use the hypotheses of Δ to fill an additional hypothesis Γ 𝐴:

Γ𝛾:ΓΓ𝐴Δ𝑎:𝐴[𝛾]Δ𝛾.Δ,Γ,𝐴𝑎:Γ.𝐴(E)

The left projection 𝐩 is called weakening, since it allows us to add arbitrary hypotheses onto the end of a domain context:

Γ𝐴Γ.𝐴𝐩Γ,𝐴:Γ(W)

The right projection 𝐪 is called the variable substitution since it allows us to recover the last variable declared in a context:

Γ𝐴Γ.𝐴𝐪Γ,𝐴:𝐴[𝐩Γ,𝐴](V)

Finally, we have ”𝛽” and “𝜂” rules giving the universal property:

Δ𝛾:ΓΔ𝑎:𝐴[𝛾]Δ𝐩Γ,𝐴(𝛾.𝑎)=𝛾:Γ(𝛽𝐩)Δ𝛾:ΓΔ𝑎:𝐴[𝛾]Δ𝐪Γ,𝐴[𝛾.𝑎]=𝑎:𝐴[𝛾](𝛽𝐪) Δ𝛾:Γ.𝐴Δ𝛾=(𝐩Γ,𝐴𝛾).(𝐪Γ,𝐴[𝛾]):Γ.𝐴(𝜂𝐩𝐪)

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,

.𝐴0𝐴𝑛𝐪[𝐩𝑖]:𝐴𝑛𝑖

so we can see 𝐪[𝐩𝑖] as picking out the 𝑖th last variable declared (0-indexed). We will informally use the alternate surface syntax of named variables

𝑥𝑛:𝐴0,,𝑥0:𝐴𝑛𝑥𝑖:𝐴𝑛𝑖

for the same judgement. These should be viewed as syntax sugar reducing to judgements of the form given above, so for example

𝑦𝑛:𝐴0,,𝑦0:𝐴𝑛𝑦𝑖:𝐴𝑛𝑖

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

Γ,𝑥:𝐴JΓ𝑎:𝐴ΓJ[𝑎/𝑥]

which in the formal syntax is

Γ.𝐴JΓ𝑎:𝐴ΓJ[𝐢𝐝.𝑎]


tidy | en | SemBr