Semantics of type theory

From HandWiki

The semantics of type theory involves several closely related types of models, which are constructed and studied in order to justify axioms and new type theories, and to use type theory as an internal language for categories, higher categories and other mathematical structures.

Categories with families

Categories with families, introduced by Dybjer,[1] are a commonly used notion of model which stays relatively close to the syntax of type theory. They form a base substrate consisting of a substitution calculus, onto which extra structure is added for each type former supported by the type theory considered.

Let Fam denote the category of families of sets: an object is a family (Ai)iI where each Ai is a set, and a morphism f:(Ai)iI(Bj)jJ is a function r:IJ together with, for each iI, a function ti:AiBr(i). (This category is equivalent to the arrow category Set of Set through the functor that sends a function f:AI to the family (f1(i))iI, with the natural action on morphisms.)

A category with families (CwF) consists of the following data:[2][3][4][1]

  • A category, whose class of objects is denoted Con and whose class of morphisms from Γ to Δ is denoted Sub(Γ,Δ). The objects are called contexts and the morphisms are called substitutions.
  • A contravariant functor from the category of contexts to Fam. The image of a context Γ is denoted (TmΓ(A))ATy(Γ) (we usually drop the subscript in TmΓ(A)). The elements of Ty(Γ) are called types in context Γ, and the elements of Tm(A) are called terms of type A (in context Γ). The image of a substitution σSub(Δ,Γ) is a morphism (Tm(A))ATy(Γ)(Tm(B))BTy(Δ) in Fam. Its component Ty(Γ)Ty(Δ) is denoted by AA[σ], and for each ATy(Γ), its component Tm(A)Tm(A[σ]) is also denoted tt[σ]. These operations are respectively called substitution in types and substitution in terms. The functoriality means that the following laws hold: A[σδ]=A[σ][δ], A[id]=A, t[σδ]=t[σ][δ], t[id]=t.
  • A terminal object in the category of contexts, called the empty context and denoted . (Some authors omit this requirement.[5])
  • For each context Γ and for each type ATy(Γ), a representing object for a certain presheaf on contexts, together with a natural isomorphism witnessing that this object represents it. This presheaf sends a context Δ to the set of pairs of a substitution σSub(Δ,Γ) and a term tTm(A[σ]), and its action on a substitution δSub(Σ,Δ) is given by (σ,t)(σδ,t[δ]). The representing context is denoted (Γ,A) and called the context extension of Γ by A. In one direction, the natural isomorphism sends a substitution σSub(Δ,Γ) and a term tTm(A[σ]) to a new substitution (σ,t)Sub(Δ,(Γ,A)) called the substitution extension of σ by t. In the other direction, it sends a substitution σSub(Δ,(Γ,A)) to a pair of its tail tl(σ)Sub(Δ,Γ) and its head term hd(σ)Tm(A[tl(σ)]). The fact that this is a natural isomorphism means that the following laws hold for σSub(Δ,Γ), tTm(A[σ]), σSub(Δ,(Γ,A)), δSub(Σ,Δ):tl((σ,t))=σhd((σ,t))=tσ=(tl(σ),hd(σ))(σ,t)δ=(σδ,t[δ])tl(σ)δ=tl(σδ)hd(σ)[δ]=hd(σδ)

Given a context ΓCon and a type ATy(Γ), we define the weakening substitution wkΓ,ASub((Γ,A),Γ) by wkΓ,A:=tl(id(Γ,A)), and the last variable vzΓ,ATm(Γ,A)(A[wkΓ,A]) by vzΓ,A:=hd(id(Γ,A)). Observe that for every substitution σSub(Δ,(Γ,A)), we have tl(σ)=tl(id(Γ,A)σ)=tl(id(Γ,A))σ=wkΓ,Aσ

Furthermore, given contexts Γ,ΔCon, a substitution σSub(Δ,Γ), and a type ATy(Γ), we define a lifted substitution σ+Sub((Δ,A[σ]),(Γ,A)) by σ+:=(σwkΓ,A[σ],vzΔ,A[σ]).

To interpret type formers, the following structures are added on top of a CwF.

For the unit type:

  • For each context ΓCon, a type ΓTy(Γ), with the requirement that Γ[σ]=Δ for every substitution σSub(Δ,Γ). (This can be replaced with a type in the empty context Ty(), although the previous definition does not require the CwF to have a terminal object for the empty context.) This interprets the inference rule for type formation of the unit type in Martin-Löf type theory:Γ contextΓ type
  • For each context ΓCon, a term ΓTm(Γ), with the requirement that Γ[σ]=Δ for every substitution σSub(Δ,Γ). This interprets the introduction ruleΓ contextΓ:
  • For each context ΓCon, for each type CTy((Γ,Γ)), for each term wTm(C[(idΓ,Γ)]), and for each term tTm(Γ), a term elim(Γ,C,w,t)Tm(C[(idΓ,t)]), with the requirement that elim(Γ,C,w,t)[σ]=elim(Δ,C[σ+],w[σ],t[σ]) for every substitution σSub(Δ,Γ). This interprets the elimination ruleΓ contextΓ,x:C(x) typeΓw:C()Γt:Γelim(C,w,t):C(t)
  • A requirement that elim(Γ,C,w,Γ)=w for all context ΓCon, type CTy((Γ,Γ)) and term wTm(C[(idΓ,Γ)]). This interprets the computation ruleΓ contextΓ,x:C(x) typeΓw:C()Γelim(C,w,)w
  • Optionally, a requirement that t=Γ for all context Γ and term tTm(Γ), if the type theory contains the uniqueness rule (η-rule)Γ contextΓt:Γt

For the empty type:

  • For each context ΓCon, a type ΓTy(Γ), with the requirement that Γ[σ]=Δ for every substitution σSub(Δ,Γ). This interprets the type formation ruleΓ contextΓ type
  • For each context ΓCon, for each type CTy((Γ,Γ)), for each term fTm(Γ), a term elim(Γ,C,t)Tm(C[(idΓ,f)]), with the requirement that elim(Γ,C,f)[σ]=elim(Δ,C[σ+],f[σ]) for every substitution σSub(Δ,Γ). This interprets the elimination ruleΓ contextΓ,x:C(x) typeΓt:Γelim(C,t):C(t)

For the type of booleans:

  • For each context ΓCon, a type 𝔹ΓTy(Γ), with the requirement that 𝔹Γ[σ]=𝔹Δ for every substitution σSub(Δ,Γ). This interprets the type formation ruleΓ contextΓ𝔹 type
  • For each context ΓCon, terms trueΓ,falseΓTm(Γ), with the requirement that trueΓ[σ]=trueΔ and falseΓ[σ]=falseΔ for every substitution σSub(Δ,Γ). This interprets the introduction rulesΓ contextΓtrue:𝔹Γ contextΓfalse:𝔹
  • For each context ΓCon, for each type CTy((Γ,𝔹Γ)), for each term tTm(C[(idΓ,trueΓ)]) and term fTm(C[(idΓ,falseΓ)]), and for each term bTm(𝔹Γ), a term elim𝔹(Γ,C,t,f,b)Tm(C[(idΓ,b)]), with the requirement that elim𝔹(Γ,C,t,f,b)[σ]=elim𝔹(Δ,C[σ+],t[σ],f[σ],b[σ]) for all substitution σSub(Δ,Γ). This interprets the elimination ruleΓ contextΓ,x:𝔹C(x) typeΓtC(true)Γf:C(false)Γb:𝔹Γelim𝔹(C,t,f,b):C(b)
  • A requirement that elim𝔹(Γ,C,t,f,trueΓ)=t and elim𝔹(Γ,C,t,f,falseΓ)=f for all context ΓCon, type CTy((Γ,𝔹Γ)) and terms tTm(C[(idΓ,trueΓ)]) and fTm(C[(idΓ,falseΓ)]). This interprets the computation rulesΓ contextΓ,x:𝔹C(x) typeΓt:C(true)Γf:C(false)Γelim𝔹(C,t,f,true)tΓ contextΓ,x:𝔹C(x) typeΓt:C(true)Γf:C(false)Γelim𝔹(C,t,f,false)f

For the type of natural numbers:

  • For each context ΓCon, a type ΓTy(Γ), with the requirement that Γ[σ]=Δ for every substitution σSub(Δ,Γ). This interprets the type formation ruleΓ contextΓ type
  • For each context ΓCon, a term 0ΓTmΓ, with the requirement that 0Γ[σ]=0Δ for every substitution σSub(Γ,Δ); additionally, for each context ΓCon and term nTm(Γ), a term SΓ(n)Tm(Γ), with the requirement that SΓ(n)[σ]=SΔ(n[σ]) for all substitution σSub(Δ,Γ). This interprets the introduction rulesΓ contextΓ0:Γ contextΓn:ΓS(n):
  • For each context ΓCon, for each type CTy((Γ,Γ)), for each term zTmΓ(C[(idΓ,0Γ)]) and term sTm((Γ,Γ),C)(C[(wk(Γ,Γ),AwkΓ,,S((Γ,Γ),A)(vzΓ,Γ[wk(Γ,Γ),C]))]), and for each term nTmΓ(Γ), a term elim(Γ,C,z,s,n)TmΓ(C[(idΓ,n)]), with the requirement that elim(Γ,C,z,s,n)[σ]=elim(Δ,C[σ+],z[σ],s[σ+]) for every substitution σSub(Δ,Γ). This interprets the elimination ruleΓ contextΓ,x:C(x) typeΓz:C(0)Γ,m:,w:C(m)s(m,w):C(S(m))Γn:Γelim(C,z,s,n):C(n)
  • A requirement that elim(Γ,C,z,s,0Γ)=z for all Γ, C, z, s as above, and moreover that elim(Γ,C,z,s,SΓ(n))=s[(idΓ,Γ,elim(Γ,C,z,s,n)[wk(Γ,Γ),C])(idΓ,n)) when additionally nTm(Γ). This interprets the computation rulesΓ contextΓ,x:C(x) typeΓz:C(0)Γ,m:,w:C(m)s(m,w):C(S(m))Γelim(C,z,s,0)zΓ contextΓ,x:C(x) typeΓz:C(0)Γ,m:,w:C(m)s(m,w):C(S(m))n:Γelim(C,z,s,S(n))S(n,elim(C,z,s,n))

For binary product types:

  • For each context ΓCon, for each types A,BTy(Γ), a type A×ΓBTy(Γ), with the requirement that (A×ΓB)[σ]=A[σ]×ΔB[σ] for every substitution σSub(Δ,Γ). This interprets the type formation ruleΓ contextΓA typeΓB typeΓA×B type
  • For each context ΓCon, for each types A,BTy(Γ), for each term aTm(A) and term bTm(B), a term a,bΓ,A,B, with the requirement that a,bΓ,A,B[σ]=a[σ],b[σ]Δ,A[σ],B[σ] for every substitution σSub(Δ,Γ). This interprets the introduction ruleΓ contextΓA typeΓB typeΓa:AΓb:BΓa,b:A×B
  • For each context ΓCon, for each types A,BTy(Γ), for each type CTy((Γ,A×ΓB)), for each term wTm((Γ,A),B)(C[(wk(Γ,A),BwkΓ,A,q)]) where B:=B[wkΓ,A], A:=A[wk(Γ,A),BwkΓ,A], B:=B[wk(Γ,A),B], q:=vzΓ,A[wk(Γ,A),B],vz(Γ,A),B((Γ,A),B),A,B, for each term pTm(A×ΓB), a term elim×(Γ,A,B,C,w,p)C[(idΓ,p)], with the requirement that elim×(Γ,A,B,C,w,p)[σ]=elim×(Δ,A[σ],B[σ],C[σ+],w[(σ+)+],p[σ]) for every substitution σSub(Δ,Γ). This interprets the elimination ruleΓ contextΓA typeΓB typeΓ,x:A×BC(x) typeΓ,y:A,z:Bw(y,z):C(y,z)Γp:A×BΓelim×(A,B,C,w,p):C(p)
  • A requirement that elim×(Γ,A,B,C,w,a,bΓ,A,B)=w[(idΓ,A,b[wkΓ,A])(idΓ,a)] for all Γ, A, B, w as above and aTm(A), bTm(B). This interprets the computation ruleΓ contextΓA typeΓB typeΓ,x:A×BC(x) typeΓ,y:A,z:Bw(y,z):C(y,z)Γa:AΓb:BΓelim×(A,B,C,w,a,bw(a,b)


Other kinds of models

Notions of models other than categories with families include comprehension categories, categories with attributes and contextual categories.[5]

Main models

Models of type theory include the standard model (or set model),[2][4], the term model (or syntactic model, or initial model),[2][4], the setoid model,[citation needed] the groupoid model,[6] the simplicial set model,[7] and several models in cubical sets starting with the BCH (Bezem–Coquand–Huber) model.[8]

References

  1. 1.0 1.1 Dybjer, Peter (1996). "Internal type theory". TYPES 1995. Springer Berlin Heidelberg. pp. 120–134. doi:10.1007/3-540-61780-9_66. ISBN 9783540707226. https://www.cse.chalmers.se/~peterd/papers/InternalTT.pdf. 
  2. 2.0 2.1 2.2 Hofmann, Martin (1997). "Syntax and semantics of dependent types". Extensional constructs in intensional type theory. London: Springer. doi:10.1007/978-1-4471-0963-1_2. ISBN 978-1-4471-0963-1. 
  3. Gratzer, Daniel; Angiuli, Carlo. Principles of dependent type theory. https://www.danielgratzer.com/papers/type-theory-book.pdf. Retrieved 2025-11-21. 
  4. 4.0 4.1 4.2 Gratzer, Daniel. "Denotational semantics of type theory". https://www.danielgratzer.com/papers/2023-semantics-primer-lecture-notes.pdf. 
  5. 5.0 5.1 Categorical semantics of dependent type theory in nLab
  6. Hofmann, Martin; Streicher, Thomas (1994). "The groupoid model refutes uniqueness of identity proofs". LICS 1994. IEEE Computer Society Press. 
  7. Kapulkin, Chris; LeFanu Lumsdaine, Peter (2012). "The simplicial model of univalent foundations (after Voevodsky)". Journal of the European Mathematical Society. doi:10.4171/JEMS/1050. 
  8. Bezem, Marc; Coquand, Thierry; Huber, Simon (2014). "A model of type theory in cubical sets". TYPES 2013. 26. Schloss Daghstuhl — Leibniz Zentrum für Informatik. ISBN 978-3-939897-72-9. https://drops.dagstuhl.de/entities/document/10.4230/LIPIcs.TYPES.2013.107.