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 Ξ“).
  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

βˆ…βŠ’Ξ“βŠ’Ξ“βŠ’π΄Ξ“.𝐴⊒

giving the empty context and context extension respectively. Since these are the only way contexts are formed, they establish that every context is a list of types Ξ“ =βˆ….𝐴1…𝐴𝑛, each of which may depend on the previous one. We therefore treat Ξ“ ⊒ and Ξ“ ⊒𝐴 as presuppositions for the judgement Ξ“.𝐴 ⊒.

For a judgement thesis J we read Ξ“ ⊒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 holds.

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:

Ξ“βŠ’Ξ“βŠ’π’πΞ“:ΓΓ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. Due to the final rule, we unambiguously omit brackets in compositions.

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]

Given a substitution Ξ” βŠ’π›Ύ :Ξ“, these inference rules give rise to the following β€œpullback” meta-functions, all denoted by π›Ύβˆ—:

  1. π›Ύβˆ— :πœ‰ β†¦πœ‰ βˆ˜π›Ύ :Sb⁑(Ξ“,Ξ) β†’Sb⁑(Ξ”,Ξ);
  2. π›Ύβˆ— :𝐴 ↦𝐴[𝛾] :Ty⁑(Ξ“) β†’Ty⁑(Ξ”);
  3. π›Ύβˆ— :π‘Ž β†¦π‘Ž[𝛾] :Tm⁑(Ξ“,𝐴) β†’Tm⁑(Ξ”,π›Ύβˆ—π΄).

^PB1 and ^PB3 can be combined to give

  1. βˆπ›Ώβˆ—π›Ώβˆ— :(𝛾,π‘Ž) ↦(π›Ώβˆ—π›Ύ,π›Ώβˆ—π‘Ž) :βˆπ›ΎβˆˆSb⁑(Ξ”1,Ξ“)Tm⁑(Ξ”1,𝐴[𝛾]) β†’βˆπ›ΎβˆˆSb⁑(Ξ”0,Ξ“)Tm⁑(Ξ”0,𝐴[𝛾])

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 substitution extension 𝛾.π‘Ž, which given a substitution Ξ” :𝛾 βŠ’Ξ“ allows us to use the hypotheses of Ξ” to fill an additional hypothesis Ξ“ ⊒𝐴:

Ξ”βŠ’π›Ύ:Ξ“Ξ“βŠ’π΄Ξ”βŠ’π‘Ž:𝐴[𝛾]Ξ”βŠ’π›Ύ.Ξ”,Ξ“,π΄π‘Ž:Ξ“.𝐴(X)
Notation

To reduce proliferation of parentheses, (.) binds more tightly then ( ∘).

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:

Ξ”βŠ’π›Ύ:Ξ“Ξ”βŠ’π‘Ž:𝐴[𝛾]Ξ”βŠ’π©Ξ“,𝐴∘(𝛾.π‘Ž)=𝛾:Ξ“(𝛽𝐩)Ξ”βŠ’π›Ύ:Ξ“Ξ”βŠ’π‘Ž:𝐴[𝛾]Ξ”βŠ’πͺΞ“,𝐴[𝛾.π‘Ž]=π‘Ž:𝐴[𝛾](𝛽πͺ) Ξ”βŠ’π›Ύ:Ξ“.π΄Ξ”βŠ’π›Ύ=(𝐩Γ,π΄βˆ˜π›Ύ).(πͺΞ“,𝐴[𝛾]):Ξ“.𝐴(πœ‚π©πͺ)

We can use these to define the auxiliary operation of Substitution extension by a type.

Syntax sugar for named variables

While the above presentation has nice formal properties, its use of De Brujin indices has a negative effect on human readability. 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[𝐒𝐝.π‘Ž]

Elementary properties

  1. Terms Ξ“ βŠ’π‘Ž :𝐴 are in bijection with substitutions Ξ“ βŠ’π›Ύ :Ξ“.𝐴 satisfying 𝐩 βˆ˜π›Ύ =𝐒𝐝.
  2. For Ξ” βŠ’π›Ύ :Ξ“, Ξ βŠ’π›Ώ :Ξ”, and Ξ” βŠ’π‘Ž :𝐴[𝛾] we have Ξ βŠ’π›Ύ.π‘Ž βˆ˜π›Ώ =(𝛾 βˆ˜π›Ώ).π‘Ž[𝛿] :Ξ“.𝐴.
  3. For Ξ“,Ξ” ∈Cx and 𝐴 ∈Ty⁑(Ξ“) we have a bijection πœ„Ξ”,Ξ“,𝐴:Sb⁑(Ξ”,Ξ“.𝐴)β‰…βˆπ›ΎβˆˆSb⁑(Ξ”,Ξ“)Tm⁑(Ξ”,𝐴[𝛾]) natural in Ξ” so that for any Ξ”0 βŠ’π›Ώ :Ξ”1 https://q.uiver.app/#q=WzAsNCxbMCwwLCJcXG9wbntTYn0oXFxEZWx0YV8xLCBcXEdhbW1hLkEpIl0sWzAsMiwiXFxvcG57U2J9KFxcRGVsdGFfMCwgXFxHYW1tYS5BKSJdLFsyLDAsIlxcY29wcm9kX3tcXGdhbW1hIFxcaW4gXFxvcG57U2J9KFxcRGVsdGFfMSwgXFxHYW1tYSl9IFxcb3Bue1RtfShcXERlbHRhXzEsIEFbXFxnYW1tYV0pIl0sWzIsMiwiXFxjb3Byb2Rfe1xcZ2FtbWEgXFxpbiBcXG9wbntTYn0oXFxEZWx0YV8wLCBcXEdhbW1hKX0gXFxvcG57VG19KFxcRGVsdGFfMCwgQVtcXGdhbW1hXSkiXSxbMCwyLCJcXGlvdGFfe1xcRGVsdGFfMSwgXFxHYW1tYSwgQX0iXSxbMSwzLCJcXGlvdGFfe1xcRGVsdGFfMCwgXFxHYW1tYSwgQX0iLDJdLFswLDEsIlxcZGVsdGFeKiIsMl0sWzIsMywiXFxjb3Byb2Rfe1xcZGVsdGFeKn0gXFxkZWx0YV4qIl1d&macro_url=https%3A%2F%2Fraw.githubusercontent.com%2Fjajaperson%2FPKM%2Frefs%2Fheads%2Fmain%2Fcontent%2Fpreamble.sty commutes.
Proof of 1–3

For ^P1, first suppose we have Ξ“ βŠ’π‘Ž :𝐴. Then letting Ξ“ βŠ’π›Ύ :=𝐒𝐝.π‘Ž :Ξ“.𝐴 we have 𝐩 βˆ˜π›Ύ =𝐒𝐝 by 𝛽𝐩. This gives the forward direction of our bijection. On the other hand, suppose we have Ξ“ βŠ’π›Ύ :Ξ“.𝐴 where 𝐩 βˆ˜π›Ύ =𝐒𝐝. Then by V, we have Ξ“ ⊒πͺ[𝛾] :𝐴. This gives us the reverse direction of our bijection. To see that these are indeed inverses, note

Ξ“βŠ’π’π.πͺ[𝛾]=(π©βˆ˜π›Ύ).πͺ[𝛾]πœ‚π©πͺ=𝛾:Ξ“.𝐴

and

Ξ“βŠ’πͺ[𝐒𝐝.π‘Ž]𝛽πͺ=π‘Ž:𝐴[𝐒𝐝]=𝐴

which completes the proof of ^P1.

For ^P2, first note

𝛾.π‘Žβˆ˜π›Ώ=(π©βˆ˜π›Ύ.π‘Žβˆ˜π›Ώ).πͺ[𝛾.π‘Žβˆ˜π›Ώ](πœ‚π©πͺ)=(π›Ύβˆ˜π›Ώ).πͺ[𝛾.π‘Ž][𝛿](𝛽𝐩)=(π›Ύβˆ˜π›Ώ).π‘Ž[𝛿](𝛽πͺ)

proving ^P2.

For ^P3, first suppose we have Ξ” βŠ’π›Ύ :Ξ“.𝐴. Then we have

Ξ”βŠ’π›Ύ:Ξ“.π΄Ξ“βŠ’π΄Ξ“.𝐴⊒𝐩:Ξ“(W)Ξ”βŠ’π©βˆ˜π›Ύ:Ξ“

and

Ξ”βŠ’π›Ύ:Ξ“.π΄Ξ“βŠ’π΄Ξ“.𝐴⊒πͺ:𝐴[𝐩](V)Ξ”βŠ’πͺ[𝛾]:𝐴[π©βˆ˜π›Ύ]

so 𝛾0 :=𝐩 βˆ˜π›Ύ and π‘Ž :=πͺ[𝛾] gives us the forward direction of our bijection. On the other hand, suppose Ξ” βŠ’π›Ύ0 :Ξ“ and Ξ” βŠ’π‘Ž :𝐴[𝛾0]. Then

Ξ”βŠ’π›Ύ0:Ξ“Ξ“βŠ’π΄Ξ”βŠ’π‘Ž:𝐴[𝛾]Ξ”βŠ’π›Ύ0.π‘Ž:Ξ“.𝐴(E)

so 𝛾 :=𝛾0.π‘Ž gives us the reverse direction. To see that these are indeed inverses, note that Ξ” ⊒𝐩 βˆ˜π›Ύ0.π‘Ž =𝛾0 :Ξ“ by 𝛽𝐩, Ξ” ⊒πͺ[𝛾0.π‘Ž] =π‘Ž :𝐴[𝛾0] by 𝛽πͺ, and Ξ” ⊒(𝐩 βˆ˜π›Ύ).πͺ[𝛾] =𝛾 :Ξ“.𝐴 by πœ‚π©πͺ. For naturality, suppose Ξ”0 βŠ’π›Ώ :Ξ”1 and Ξ”1 βŠ’π›Ύ :Ξ“.𝐴. Since

π›Ώβˆ—(π©βˆ˜π›Ύ)=π©βˆ˜π›Ύβˆ˜π›Ώ=π©βˆ˜π›Ώβˆ—π›Ύ

and

π›Ώβˆ—(πͺ[𝛾])=πͺ[π›Ύβˆ˜π›Ώ]=πͺ[π›Ώβˆ—π›Ύ]

it follows

βˆπ›Ώβˆ—π›Ώβˆ—βˆ˜πœ„Ξ”1,Ξ“,𝐴(𝛾)=πœ„Ξ”0,Ξ“,π΄βˆ˜π›Ώβˆ—(𝛾).

This completes the proof of ^P3.


#state/tidy | #lang/en | #SemBr