Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gmcninch-tufts
GitHub Repository: gmcninch-tufts/2024-Sp-Math190
Path: blob/main/course-contents/notes-formal-02.md
908 views
---
title: | Overview on Formalization - Type Theory part 2 date: 2024-04-08
---

\newcommand{\type}{\ \text{type}} \newcommand{\id}{\operatorname{id}} \newcommand{\prd}[1]{\Pi_{(#1)}} \newcommand{\comp}{\operatorname{comp}}

A derivation about renaming variables

We are going to derive the inference rule

Γ,x:A,ΔJΓ,x:A,Δ[x/x]J[x/x]x/x\dfrac{\Gamma, x:A,\Delta \vdash \mathscr{J}} {\Gamma,x':A,\Delta[x'/x] \vdash \mathscr{J}[x'/x]}x'/x

which essentially says "we an replace variable x:Ax:A by variable x:Ax':A".

The derivation uses substitution, weakening and the generic element:

ParseError: KaTeX parse error: Undefined control sequence: \type at position 34: …Gamma \vdash A \̲t̲y̲p̲e̲}{\Gamma,x':A \…

Dependent function types

Let bb be a section of a family BB over AA in context Γ\Gamma. Thus Γ,x:Ab(x):B(x).\Gamma,x:A \vdash b(x): B(x).

Two points of view here:

  • can think of bb as a "program" xb(x)x \mapsto b(x) that takes as input x:Ax:A and produces a term b(x):B(x)b(x):B(x).

  • or, can view b(x)b(x) as just a "choice of element" in each B(x)B(x) for x:Ax:A. i.e. xb(x)x \mapsto b(x) is a dependent function

The type of all such dependent functions is called the dependent function type, written: Π(x:A)B(x)\Pi_{(x:A)} B(x)

Part of what we must formulate in our type theory are inference rules guaranteeing that these types are well-formed. For this we need various sorts of rules:

  • formation rule specifying how we may form dependent function types

  • introduction rule specifying how to introduce new terms of dependent function types

  • elimination rule specifying how to use arbitrary terms of dependent function types

  • computation rules specifying how introduction rules and elimination rules interact

For the first three of these rules, we also need rules asserting that the constructions play nice with judgmental equality.

Π\Pi-formation rule

ParseError: KaTeX parse error: No such environment: prooftree at position 7: \begin{̲p̲r̲o̲o̲f̲t̲r̲e̲e̲}̲ \AxiomC{$\Ga…

Also need the congruence rule:

ParseError: KaTeX parse error: No such environment: prooftree at position 7: \begin{̲p̲r̲o̲o̲f̲t̲r̲e̲e̲}̲ \AxiomC{$\Ga…

Π\Pi-introduction rule

This rule specifies that we may "construct" dependent functions provided that we have constructed a section:

ParseError: KaTeX parse error: No such environment: prooftree at position 7: \begin{̲p̲r̲o̲o̲f̲t̲r̲e̲e̲}̲ \AxiomC{$\Ga…

We use the notation λx.b(x)\lambda x.b(x) for the "dependent function". This introduction rule is also called the λ\lambda-abstraction rule.

Again, we need to know that λ\lambda-abstraction respects judgmental equality:

ParseError: KaTeX parse error: No such environment: prooftree at position 7: \begin{̲p̲r̲o̲o̲f̲t̲r̲e̲e̲}̲ \AxiomC{$\Ga…

Π\Pi-elimination rule

The way to use a dependent function is to evaluate it at any an element of the domain type. The Π\Pi-elimination rule is thus sometimes called the evaluation rule.

ParseError: KaTeX parse error: No such environment: prooftree at position 7: \begin{̲p̲r̲o̲o̲f̲t̲r̲e̲e̲}̲ \AxiomC{$\Ga…

(Note that in practice -- e.g. in type-theory based programming languages Lean, Haskell, ML, ... -- we write "f xf\ x" for "f(x)f(x)").

ParseError: KaTeX parse error: No such environment: prooftree at position 7: \begin{̲p̲r̲o̲o̲f̲t̲r̲e̲e̲}̲ \AxiomC{$\Ga…

Π\Pi-computation rule

We need to postulate rules controlling our functions.

The β\beta-rule stipulates that λx.b(x)\lambda x. b(x) behaves in the way that we understand the function xb(x)x \mapsto b(x).

ParseError: KaTeX parse error: No such environment: prooftree at position 7: \begin{̲p̲r̲o̲o̲f̲t̲r̲e̲e̲}̲ \AxiomC{$\Ga…

The second rule -- known as the η\eta-rule -- postulates that the only elements of Π(x:A)B(x)\Pi_{(x:A)}B(x) are dependent functions.

ParseError: KaTeX parse error: No such environment: prooftree at position 7: \begin{̲p̲r̲o̲o̲f̲t̲r̲e̲e̲}̲ \AxiomC{$\Ga…

Ordinary function types

We obtain ordinary functions as a special case of dependent functions. Let's describe the setting.

Suppose that AA and BB are types in context Γ\Gamma. We can view BB as the "constant family" B(x)=BB(x) = B over a:Aa:A. From this point of view, we obtain the type of functions as AB:=Π(x:A)B(x)A \to B := \Pi_{(x:A)} B(x) i.e. AB:=Π(x:A)BA \to B := \Pi_{(x:A)}B

Here is the formal derivation:

ParseError: KaTeX parse error: No such environment: prooftree at position 7: \begin{̲p̲r̲o̲o̲f̲t̲r̲e̲e̲}̲ \AxiomC{$\Ga…

And here is the formal declaration of the "new notation":

ParseError: KaTeX parse error: No such environment: prooftree at position 7: \begin{̲p̲r̲o̲o̲f̲t̲r̲e̲e̲}̲ \AxiomC{$\Ga…

Construction of the identity function

Given a type AA in context Γ\Gamma, let's construct the identity function ParseError: KaTeX parse error: Undefined control sequence: \id at position 1: \̲i̲d̲ ̲= \id_A:A \to A using the generic term:

ParseError: KaTeX parse error: No such environment: prooftree at position 7: \begin{̲p̲r̲o̲o̲f̲t̲r̲e̲e̲}̲ \AxiomC{$\Gamm…

Construction of the composition of two functions

Given types AA, BB, CC and terms f:ABf:A \to B, g:BCg:B \to C, we can form gf:ACg \circ f:A \to C.

In fact, write ParseError: KaTeX parse error: Undefined control sequence: \comp at position 1: \̲c̲o̲m̲p̲(g,f) for gfg \circ f. Then ParseError: KaTeX parse error: Undefined control sequence: \comp at position 1: \̲c̲o̲m̲p̲ is in some sense a function of two arguments gg and ff. Let's pause to discuss functions of multiple arguments.

Consider a function f:A(BC)f : A \to (B \to C) For an argument a:Aa:A, f(a):BCf(a):B \to C so f(a)f(a) is again a function. For b:Bb :B, we can write f(a)(b)orf(a,b)orf a bf(a)(b) \quad \text{or} \quad f(a,b) \quad \text{or} \quad f\ a \ b for the value of f(a)f(a) at b:Bb:B.

Now we see that the type of the function ParseError: KaTeX parse error: Undefined control sequence: \comp at position 1: \̲c̲o̲m̲p̲ is (BC)((AB)(AC))(B \to C) \to ((A \to B) \to (A \to C)) Thus for g:BCg:B \to C, we have ParseError: KaTeX parse error: Undefined control sequence: \comp at position 1: \̲c̲o̲m̲p̲(g):(A \to B) \…

We are going to define ParseError: KaTeX parse error: Undefined control sequence: \comp at position 1: \̲c̲o̲m̲p̲ by the rule ParseError: KaTeX parse error: Undefined control sequence: \comp at position 1: \̲c̲o̲m̲p̲ ̲= \lambda g.\la….

Before we give the derivation, we need a preliminary result using the generic element; we'll refer to this as ()(\clubsuit) below:

ParseError: KaTeX parse error: No such environment: prooftree at position 7: \begin{̲p̲r̲o̲o̲f̲t̲r̲e̲e̲}̲ \AxiomC{$\Ga…

Now here is the full derivation:

ParseError: KaTeX parse error: No such environment: prooftree at position 7: \begin{̲p̲r̲o̲o̲f̲t̲r̲e̲e̲}̲ \AxiomC{$\Ga…

One can now derive a number of properties of function composition:

  • associativity, i.e. ParseError: KaTeX parse error: No such environment: prooftree at position 7: \begin{̲p̲r̲o̲o̲f̲t̲r̲e̲e̲}̲ \AxiomC{$\Ga…

  • left and right unit laws ParseError: KaTeX parse error: No such environment: prooftree at position 7: \begin{̲p̲r̲o̲o̲f̲t̲r̲e̲e̲}̲ \AxiomC{$\Ga…

    ParseError: KaTeX parse error: No such environment: prooftree at position 7: \begin{̲p̲r̲o̲o̲f̲t̲r̲e̲e̲}̲ \AxiomC{$\…

Bibliography

::: {.refs} :::