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-01.md
908 views
---
title: | Overview on Formalization - Type Theory part 1 date: 2024-04-08
---

\newcommand{\type}{\ \text{type}}

Parallel to the course discussions of Lean usage, I want to give at least a bit of a description of the underlying dependent type theory.

I'm going to follow the first chapter of Egbert Rijke's new text Homotopy Type Theory [arXiv: Homotopy Type Theory] -- (though for now I ignore the potential homotopy in the type theory.)

The second section of Theorem Proving in Lean vi[@avigadTheoremProvingLean] is also good - and Lean specific! - but still comes across (to me) as more of a guide to using Lean than an introduction to type theory (this is not a criticism, of course!)

All of this really does bump up against an important pedagogical question: how much type theory does one really need to know in order to use Lean to formalize mathematics?

I'm sure I don't know the answer! In the limited time in this third-of-a-course, I'm hoping to say a little about "using Lean" as well as a little about the type theory than enables it.

Martin-Löf's Type Theory

I'm mostly viewing these notes as a quick exposition of the first chapter of Rijke's text [@rijkeIntroductionHomotopyType]; probably you should just read the text! But maybe these notes will encourage you to do so... At any rate, quotes below are taken from [@rijkeIntroductionHomotopyType].

To the newcomer, one of the main questions one probably faces in this subject is: "what are the differences between type theory and the usual description of math via set theory?" The introduction to Rijke's chapter tells us that in type theory:

  • every element comes equipped with its type

  • set theory is axiomatized in the formal system of first-order logic, while type theory is its own formal system.

"the expression a:Aa:A is not considered a proposition - i.e. something which one can assert about an arbitrary element and an arbitrary type -- but is considered to be a judgment ... that is part of the construction of the element a:Aa:A."

  • there is a greater emphasis in type theory on equality of elements than in set theory.

    Unlike in set theory, where equality is a decidable proposition of first-order logic, the type x=yx=y of identifications of two elements x,y:Ax, y:A is itself a type.

By way of a general description, we have:

Dependent type theory is a system of inference rules that can be combined to make derivations ... the goal is often to construct an element of a certain type.

Judgments and contexts in type theory

In type theory, an inference rule is represented symbolically as follows: H1 H2  HnC.\dfrac{\mathscr{H}_1 \ \mathscr{H}_2 \ \cdots \ \mathscr{H}_n}{C}. Above the horizontal line is a finite list of judgments Hi\mathscr{H}_i for the premises, and below the horizontal line is a single judgment CC for the conclusion.

When we later introduce function types, we'll see the following inference rule appear:

Γa:AΓf:ABΓf(a):B.\dfrac{\Gamma \vdash a:A \quad \Gamma \vdash f:A \to B} {\Gamma \vdash f(a):B}.

This means: "in a context Γ\Gamma (more on the notion of context below!) given an element [^1] aa of type AA and a function f:ABf:A \to B, we obtain an element f(a)f(a) of type BB."

[^1]: Rijke reads "a:Aa:A" as "aa is an element of type AA". Some other authors read this as "aa is a term of type AA."

Here the judgments include Γa:A\Gamma \vdash a:A and Γf:AB\Gamma \vdash f:A \to B.

In fact, there are just four sorts of judgments in Martin-Löf's dependent type theory:

  • judgment that AA is a well-formed type in context ΓΓ: ΓA typeΓ ⊢ A \ \text{type}

  • judgment that AA and BB are judgmentally equal (or definitionally equal) in context Γ\Gamma: ΓAB  typeΓ ⊢ A \doteq B  \ \text{type}

  • judgment that aa is an element of type AA in context Γ\Gamma: Γa:A\Gamma \vdash a:A

  • judgment that aa and bb are judgmentally equal elements of type AA Γab:A.\Gamma \vdash a \doteq b : A.

Notice that any judgment has the form ΓJ\Gamma \vdash \mathscr{J} where Γ\Gamma is the context and J\mathscr{J} is the judgment thesis. It remains to explain the context Γ\Gamma.

The role of the context is to declare what hypothetical elements (variables) are assumed.

Definition : A context is a finite list of variable declarations x1:A1,x:2:A2(x1),,xn:An(x1,,xn1)x_1:A_1, x:2:A_2(x_1), \cdots , x_n:A_n(x_1,\cdots,x_{n-1}) such that for 1kn1 \le k \le n we can derive the judgment ()x1:A1,x2:A2(x1),,xk1:Ak1(x1,,xk2)Ak(x1,,xk1) type(\clubsuit) \quad x_1:A_1, x_2:A_2(x_1), \cdots, x_{k-1}:A_{k-1}(x_1,\cdots,x_{k-2}) \vdash A_k(x_1,\cdots,x_{k-1}) \ \text{type} using inference rules of type theory.

Of course, in a context we may use other variable names than xix_i, so long as no variable is declared more than once.

Examples : - the empty context has length 0 and declares no variables. Examples of well-formed types in an empty context include the natural numbers ℕ.

- a context of length 1 has the form $x_1:A_1$ where $A_1$ is a well-formed type in the empty context. The type `Vec ℤ n` of *vectors of integers of length `n:ℕ`* is a type in context $n:$. e.g. we have `[8,22,-17] : Vec ℤ 3` - For any type $A$ in the empty context, and any term $a:A$, the equality type $x = a$ is a type in context $x:A$. (for a term $x_0:A$, the type $x_0 = a$ has the term `refl:`$x_0 = a$ if $x_0$ and $a$ are judgmentally equal; i.e. we have the judgment $$ x_0 a:A$$ ) - a context of length 2 has the form $x_1:A_1, x_2:A_2(x_1)$ and we will explain what is meant by the notation $A_2(x_1)$ in the next section on *type families*.

Type families

Definition : Consider a type AA in context ΓΓ. A family of types over AA in context ΓΓ is a type B(x)B(x) in context Γ,x:AΓ,x:A.

In other words, we have the judgment $$Γ,x:A B(x)\ \text{type}.$$ **Terminology**: we say that $B$ is a family of types over $A$ in context $, or that $B(x)$ is a type *indexed* by $x:A$.

Examples:

  • Vec ℤ n is a type indexed by n:Nn:ℕ.

  • For a:Aa:A, x = a is a typed indexed by x:Ax:A. More precisely, we have the inference rule Γa:AΓ,x:Aa=x type.\dfrac{\Gamma \vdash a:A}{\Gamma, x:A \vdash a = x \ \text{type}}.

Definition : Consider a family of type BB over AA in context Γ\Gamma. A section of BB over AA in context Γ\Gamma is an element of type B(x)B(x) in context Γ,x:A\Gamma,x:A; i.e. the judgment Γ,x:Ab(x):B(x).\Gamma,x:A \vdash b(x):B(x).

For example, consider the type Vec ℤ n indexed by n:Nn:ℕ. An example of a section is the term b(n)b(n) where b(0)=[]b(0) = [] and for n>0n>0, b(n)=[0,0,,0]=0::b(n1)b(n) = [0,0,\cdots,0] = 0 :: b(n-1)

Inference Rules

Here are the inference rules "underlying" dependent type theory.

  • Rules for formation of contexts, types and elements

    The following rules amount to "presuppositions"; for example, If we have the judgment that B(x)B(x) is a well-formed type in context Γ,x:A\Gamma,x:A, then AA is already a well-formed type in context Γ\Gamma.

    ParseError: KaTeX parse error: Undefined control sequence: \type at position 30: …x:A \vdash B(x)\̲t̲y̲p̲e̲}{\Gamma \vdash…ParseError: KaTeX parse error: Undefined control sequence: \type at position 25: …amma \vdash a:A\̲t̲y̲p̲e̲}{\Gamma \vdash…
  • Judgmental equality is an equivalence relation

    We have to require this for types: ParseError: KaTeX parse error: Undefined control sequence: \type at position 24: …Gamma \vdash A \̲t̲y̲p̲e̲}{\Gamma\vdash …

    and for terms: Γa:AΓaa:AΓab:AΓba:AΓab:AΓbc:AΓac:A\dfrac{\Gamma \vdash a:A}{\Gamma\vdash a \doteq a:A} \quad \dfrac{\Gamma \vdash a \doteq b:A}{\Gamma\vdash b \doteq a:A} \quad \dfrac{\Gamma \vdash a ≐ b:A \quad \Gamma \vdash b ≐ c:A}{\Gamma\vdash a \doteq c:A}

  • variable conversion rules

    One example of such a rule is:

    ParseError: KaTeX parse error: Undefined control sequence: \type at position 54: …ash A \doteq A'\̲t̲y̲p̲e̲ ̲\quad …

    thus if xx is a variable of type AA and if AAA \doteq A' (in the given context), then we can replace x:Ax:A by x:Ax:A' when describing families of types.

    Note that writing B(x)B(x) just emphasizes the dependence on x:Ax:A; of course, BB depends on the whole context Γ,x:A,Δ\Gamma,x:A,\Delta.

    We must give rules like ()(\diamondsuit) not only for judgments of well-formed types, but of judgments for type-equality, for elements, and for element-equality. We write J\mathscr{J} for a generic judgment thesis; the general form of the variable conversion rule is then

    ()ΓAAΓ,x:A,ΔJΓ,x:A,ΔJ(\diamondsuit') \quad \dfrac{\Gamma \vdash A \doteq A' \quad \Gamma,x:A,\Delta \vdash \mathscr{J}} {\Gamma,x:A',\Delta \vdash \mathscr{J}}
  • substitution

    Consider a section f(x):B(x)f(x): B(x) indexed by x:Ax:A in context Γ\Gamma and suppose give a:Aa:A.

    We can simultaneously substitute aa for all occurrences of xx in f(x)f(x) and B(x)B(x) to obtain a new element f[a/x]:B[a/x]f[a/x]:B[a/x].

    Somewhat more precisely, consider the following. Given the judgment

    ParseError: KaTeX parse error: Undefined control sequence: \type at position 54: …n:B_n \vdash C \̲t̲y̲p̲e̲

    and a term a:Aa:A, we can substitute to obtain the judgment ParseError: KaTeX parse error: Undefined control sequence: \type at position 55: … \vdash C[a/x] \̲t̲y̲p̲e̲

    Note that in this latter judgment, the variables y1,,yny_1,\cdots,y_n are assigned new types after substitution.

    Similarly, given CC as in ()(*), from a term c:Cc:C, we obtain a new term c[a/x]:C[a/x]c[a/x]:C[a/x].

    For a generic judgment J\mathscr{J}, we have the substitution rule Γa:AΓ,x:A,ΔJΓ,Δ[a/x]J[a/x]S\dfrac{\Gamma \vdash a:A \quad \Gamma,x:A,\Delta \vdash \mathscr{J}} {\Gamma,\Delta[a/x] \vdash \mathscr{J}[a/x]}S

    Definition : When BB is a family of types over AA in context Γ\Gamma and when a:Aa:A, we refer to the type B[a/x]B[a/x] as the fiber of BB at aa. It is often written B(a)B(a).

    Similarly, given a section $b$ of $B$, we write $b(a)$ for $b[a/x]$.
  • weakening

    Given a type AA in context Γ\Gamma, any judgment made in a longer context Γ,Δ\Gamma,\Delta can be made in the context Γ,x:A,Δ\Gamma,x:A,\Delta for a new variable xx. The weakening rule says that well-formed-ness and judgmental equality of types and elements are preserved by this operation: for a generic judgement J\mathscr{J} we have

    ParseError: KaTeX parse error: Undefined control sequence: \type at position 24: …Gamma \vdash A \̲t̲y̲p̲e̲ ̲\quad \Gamma,\D…

    The process of expanding the context by x:Ax:A is called weakening (by AA).

    Example : If we have two types A,BA,B in context Γ\Gamma, then we can weaken BB by AA to obtain ParseError: KaTeX parse error: Undefined control sequence: \type at position 24: …Gamma \vdash A \̲t̲y̲p̲e̲ ̲\quad \Gamm… The type BB in context Γ,x:A\Gamma,x:A is called the constant (or trivial) family BB.

  • the generic element

    The last general inference rule concerns the so-called generic element of a type family. Given a type AA in context Γ\Gamma, we can weaken AA by itself to obtain that AA is a type in context Γ,x:A\Gamma,x:A. The rule then stipulates that the variable xx may be viewed as an element of x:Ax:A in this context; i.e. ParseError: KaTeX parse error: Undefined control sequence: \type at position 17: …dfrac{\Gamma:A \̲t̲y̲p̲e̲}{\Gamma,x:A \v…

Bibliography

::: {.refs} :::