Algebraic simple type theory
A polynomial approach
Nathanael Arkor & Marcelo Fiore
Department of Computer Science and Technology University of Cambridge Category Theory 2019
Algebraic simple type theory A polynomial approach Nathanael Arkor - - PowerPoint PPT Presentation
Algebraic simple type theory A polynomial approach Nathanael Arkor & Marcelo Fiore Department of Computer Science and Technology University of Cambridge Category Theory 2019 What is a type theory? What is a type theory? system of
A polynomial approach
Nathanael Arkor & Marcelo Fiore
Department of Computer Science and Technology University of Cambridge Category Theory 2019
What is a type theory?
What is a type theory?
system of mathematical proof
What is a type theory?
system of mathematical proof specification for a programming language
What is a type theory?
system of mathematical proof internal language of a category specification for a programming language
Algebraic type theory
categorical algebra typing / sorting binding polymorphism dependency
Algebraic simple type theory
categorical algebra typing / sorting binding polymorphism dependency e.g. λ-calculus, computational λ-calculus, predicate logic
Examples
Typing judgements
contexts terms and types
contexts terms and types
Cartesian context structures
the sorts, or types
the variable contexts
the empty context
types as contexts
context extension e.g. any cartesian category
Cartesian context structures
the sorts, or types
the variable contexts
the empty context
types as contexts
context extension e.g. any cartesian category
Cartesian context structures
the sorts, or types
the variable contexts
the empty context
types as contexts
context extension e.g. any cartesian category
Cartesian context structures
the sorts, or types
the variable contexts
the empty context
types as contexts
context extension e.g. any cartesian category
Cartesian context structures
the sorts, or types
the variable contexts
the empty context
types as contexts
context extension e.g. any cartesian category
contexts terms and types
Term-typing structure
presheaf of terms (in context Γ)
We consider presheaves 𝒟op → Set on a cartesian context structure (𝒟, S), fibred over S.
presheaf of types (in context Γ) assignment of types to terms
constant presheaf of types
Term-typing structure
presheaf of terms (in context Γ)
We consider presheaves 𝒟op → Set on a cartesian context structure (𝒟, S), fibred over S.
assignment of types to terms
Terms with a specified type
σ τ
Presheaf of variables
For any context Γ ∈ 𝒟, V(Γ) is the set of variables in Γ.
σ∈S def
contexts terms and types
Models of simple type theory
contexts terms and types
Models of simple type theory
algebraic structure
Models of simple type theory
term operators
τ → σ | τ × σ | T(τ) | ...
type operators
(t1, t2) | π1 t | t1 t2 | λ(x) t | ...
Algebraic structure on types
Type structure is as in universal algebra. For instance, the following operators
τ → σ | τ × σ | T(τ) | U
induce a signature endofunctor on Set
Σty = X ↦ X2 + X2 + X + 1
the algebras for which are sets S with the appropriate structure
[⟦ →⟧, ⟦×⟧, ⟦T⟧, ⟦U⟧] : Σty S → S
(NB. These signature functors are polynomial.)
How should we define the algebraic structure on terms? Natural deduction rules present algebraic structure Polynomials present natural deduction rules
How should we define the algebraic structure on terms? Natural deduction rules present algebraic structure Polynomials present natural deduction rules
How should we define the algebraic structure on terms? Natural deduction rules present algebraic structure Polynomials present natural deduction rules
Polynomials & polynomial functors
In a locally cartesian-closed category ℰ, a polynomial is a diagram: The polynomial functor associated to the polynomial is given by:
f g h
We will consider polynomials in Psh(𝒟), inducing polynomial functors Psh(𝒟)/S → Psh(𝒟)/S, where (𝒟, S) is a cartesian context structure with algebraic structure ΣtyS → S. Let P be a polynomial in Psh(𝒟). Algebras for the corresponding polynomial functor are bundles τ : T → S together with morphisms as in the following.
T S τ T S τ
Polynomials & polynomial functors
⟦P⟧
Algebraic structure & natural deduction
Γ ⊢ a : A Γ ⊢ b : B Γ ⊢ pair(a, b) : Prod(A, B) Prod-ɪɴᴛʀᴏ
Algebraic structure & natural deduction
Γ ⊢ a : A Γ ⊢ b : B Γ ⊢ pair(a, b) : Prod(A, B) Prod-ɪɴᴛʀᴏ
Algebraic structure & natural deduction
Γ ⊢ a : A Γ ⊢ b : B Γ ⊢ pair(a, b) : Prod(A, B) Prod-ɪɴᴛʀᴏ
⟦Prod⟧
Algebraic structure & natural deduction
Γ ⊢ a : A Γ ⊢ b : B Γ ⊢ pair(a, b) : Prod(A, B) Prod-ɪɴᴛʀᴏ
⟦Prod⟧
Algebraic structure & natural deduction
Γ ⊢ a : A Γ ⊢ b : B Γ ⊢ pair(a, b) : Prod(A, B) Prod-ɪɴᴛʀᴏ
∇2 ⟦Prod⟧
Algebraic structure & natural deduction
Γ ⊢ a : A Γ ⊢ b : B Γ ⊢ pair(a, b) : Prod(A, B) Prod-ɪɴᴛʀᴏ
∇2 ⟦Prod⟧ [π1, π2]
Algebraic structure & natural deduction
Γ ⊢ a : A Γ ⊢ b : B Γ ⊢ pair(a, b) : Prod(A, B) Prod-ɪɴᴛʀᴏ
∇2 ⟦Prod⟧ [π1, π2]
Algebraic structure & natural deduction
∇2 ⟦Prod⟧ [π1, π2]
⟦pair⟧ ⟦Prod⟧ τ × τ τ
polynomial functor algebra
Γ ⊢ a : A Γ ⊢ b : B Γ ⊢ pair(a, b) : Prod(A, B) Prod-ɪɴᴛʀᴏ
introduction rule
Binding algebraic structure & natural deduction
Γ, x : A ⊢ t : B Γ ⊢ abs(x : A . t) : Fun(A, B) Fun-ɪɴᴛʀᴏ
Binding algebraic structure & natural deduction
Γ, x : A ⊢ t : B Γ ⊢ abs(x : A . t) : Fun(A, B) Fun-ɪɴᴛʀᴏ
Binding algebraic structure & natural deduction
Γ, x : A ⊢ t : B Γ ⊢ abs(x : A . t) : Fun(A, B) Fun-ɪɴᴛʀᴏ
⟦Fun⟧
Binding algebraic structure & natural deduction
Γ, x : A ⊢ t : B Γ ⊢ abs(x : A . t) : Fun(A, B) Fun-ɪɴᴛʀᴏ
⟦Fun⟧
Binding algebraic structure & natural deduction
Γ, x : A ⊢ t : B Γ ⊢ abs(x : A . t) : Fun(A, B) Fun-ɪɴᴛʀᴏ
types of variables ⟦Fun⟧ ν × id
Binding algebraic structure & natural deduction
Γ, x : A ⊢ t : B Γ ⊢ abs(x : A . t) : Fun(A, B) Fun-ɪɴᴛʀᴏ
ν × id ⟦Fun⟧ π2
Binding algebraic structure & natural deduction
⟦abs⟧Γ ⟦Fun⟧Γ τΓ
ν × id ⟦Fun⟧
A, B ∈ S
π
π2 Γ, x : A ⊢ t : B Fun-ɪɴᴛʀᴏ Γ ⊢ abs(x : A . t) : Fun(A, B)
polynomial functor algebra introduction rule
Algebraic structure & natural deduction
The natural deduction rules corresponding to introduction/elimination can be described by a second-order arity (describing the typing and binding data for each argument). Each second-order arity induces a polynomial in Psh(𝒟). The algebras for their associated polynomial functors are presheaves with the corresponding (typed & binding) term structure. We can collect the arities into a term signature Σtm, which itself induces a polynomial. (NB. We're using the same notation for a signature and the polynomial functor it induces.)
contexts terms and types
Models of simple type theory
algebraic structure
Model homomorphisms
a Σty-algebra homomorphism
a structure-preserving functor
a morphism in Psh(𝒟)/S preserving the Σtm-algebra structure (S, 𝒟, ε, ⟨–⟩, – × ⟨=⟩, T, τ, ⟦–⟧ty, ⟦–⟧tm) ⟶ (S', 𝒟', ε', ⟨–⟩', – × ⟨=⟩', T', τ', ⟦–⟧'ty, ⟦–⟧'tm)
Model homomorphisms
a Σty-algebra homomorphism
a morphism in Psh(𝒟)/S preserving the Σtm-algebra structure
h
f
where 𝖎 = h*(– H)
Syntactic models of simple type theory
For any given term and type signature, we want a model of simple type theory freely generated by the syntax. The model freely generated by the syntax is exactly the initial model. Since we have no type dependency, we can construct the initial model piecewise.
syntactic model
Initial models of simple type theory
Initial models of simple type theory
initial Σty-algebra
Initial models of simple type theory
initial Σty-algebra
free cartesian category on _S_
S
Initial models of simple type theory
initial Σty-algebra
free cartesian category on _S_
initial Σtm-algebra
S
There's one last thing...
Substitution
???
Substitution
an algebraic operation on terms
Substitution
Γ, x : A ⊢ t : B Γ ⊢ u : A Γ ⊢ subst(x : A . t, u) : B subst Γ, x : A ⊢ var(x) : A var
Substitution
Γ, x : A ⊢ t : B Γ ⊢ u : A Γ ⊢ subst(x : A . t, u) : B subst Γ, x : A ⊢ var(x) : A var
ν
ν × id + id π2 [π2, π1]
Substitution
Γ, x : A ⊢ t : B Γ ⊢ u : A Γ ⊢ subst(x : A . t, u) : B subst Γ, x : A ⊢ var(x) : A var subject to equational laws…
Initial models of simple type theories with substitution
syntactic model with substitution
Initial models of simple type theories with substitution
syntactic model with substitution
(ℂ, T ⟶ S, ⟦-⟧ty, ⟦-⟧tm + subst) A partial answer
(𝒟, T ⟶ S, ⟦-⟧ty, ⟦-⟧tm + subst)
τ
A partial answer
(𝒟, T ⟶ S, ⟦-⟧ty, ⟦-⟧tm + subst)
τ
A partial answer
We can now construct the classifying category and equational logic...
Conclusion
terms and algebraic structure.
be presented by polynomials.
theory, and can be constructed explicitly with a free algebra construction.
can derive a classifying category, demonstrating that the type theory is its internal language.