λ-calculus as a proof language. Verified programming by encoding specifications into types (as logical propositions), and writing programs that only type-check if they satisfy the specifications. MLTT allows any proposition (of intuitionistic logic) to be represented by a type. Hence, MLTT is a single language suitable for both programming and theorem proving. Larry Diehl Martin-L¨ of’s Type Theory (MLTT)
⊥ Implication P ⇒ Q P → Q Πx:P.Q Conjuction P ∧ Q P × Q Σx:P.Q Disjunction P ∨ Q P Q Σx:B.elimB P Q x F.O. Prop. Quantif. ∀P :Prop.Q ΠP:U.Q H.O. Prop. Quantif. ∀P :Prop2.Q ΠP:A.Q Term Quantif. ∀t:A.Q Πt:A.Q Larry Diehl Martin-L¨ of’s Type Theory (MLTT)
languages, or proof assistants, implement variations of MLTT (e.g. Agda, Coq, Idris, Lean, etc.). Example: Bound-Safe Lookup lookup : ΠA:U. Πn:N. Πl:List A. n < |l| → A Example: Provably Correct Sorting sort : ΠA:U. List A → List A sorted : ΠA:U. Πl:List A. Ord A (sort A l) × Perm A l (sort A l) Larry Diehl Martin-L¨ of’s Type Theory (MLTT)
A , then A type. If a : A and a = a : A, then a : A. Consistency There is no closed term e s.t. e : ⊥. Normalization If a : A, then there exists a normal a s.t. a = a : A. If A type, then there exists a normal A s.t. A = A . Decidable Type Checking For all A, A type or its negation. For all a and A, a : A or its negation. a aAssuming intentional equality and suitable type annotations on terms. Larry Diehl Martin-L¨ of’s Type Theory (MLTT)
a : A a = a : A A = A A = A a = a : A a = a : A A1 = A2 A2 = A3 A1 = A3 a1 = a2 : A a2 = a3 : A a1 = a3 : A Larry Diehl Martin-L¨ of’s Type Theory (MLTT)
functions Type formation e.g. Πx:A.B, and congruences. Universe introduction (` a la Russell) e.g. Πx:A.B, and congruences. Term introduction e.g. λx.b, and congruences. Term elimination e.g. f a, and congruences. Equality e.g. (λx.b) a =β b[a/x], and f =η λx.f x. Larry Diehl Martin-L¨ of’s Type Theory (MLTT)
a safe version of a “type of types”, where each type is represented as a code (which is a term) of type U. Each code for a type can be lifted to a proper type, meaning it satisfies the type formation judgement (A type). U is a predicative reflection of well-formed types as terms (typeable by U). Quantifying over universe codes (U) corresponds to predicatively quantifying over types. Hence, each type formation rule is mirrored by a universe introduction rule.1 1Except for the U-formation rule. Larry Diehl Martin-L¨ of’s Type Theory (MLTT)
A] Πx:A.B type A : U B : U [x : A] Πx:A.B : U b : B [x : A] λx.b : Πx:A.B λx.b : Πx:A.B a : A f a : B[a/x] a : A b : B [x : A] (λx.b) a = b[a/x] : B[a/x] f : Πx:A.B f = λx.f x : Πx:A.B Larry Diehl Martin-L¨ of’s Type Theory (MLTT)
A B = B [x : A] Πx:A.B = Πx:A .B A = A : U B = B : U [x : A] Πx:A.B = Πx:A .B : U b = b : B [x : A] λx.b = λx.b : Πx:A.B f = f : Πx:A.B a = a : A f a = f a : B[a/x] Larry Diehl Martin-L¨ of’s Type Theory (MLTT)
the “core” types of MLTT. Open to Extension Per Martin-L¨ of prefers his theory to be “open to extension”, in the sense that adding new types (like lists, vectors, an internalized equality type, etc.) should remain possible.a Even axioms (that keep the theory consistent) may be added, like excluded middle, but at the cost of “stuck” computations. aThis is why there is no elimination rule for U. Minimal Theory for Inductive Types Next, we will extend MLTT with a minimal collection of types that allows inductive types (e.g. N) to be derived: ⊥, , Σ, B, and W. Larry Diehl Martin-L¨ of’s Type Theory (MLTT)
= tt : @@@@@@@@@@@@@@@@@@@@@ @ P type [x : Unit] p : P[tt/x] u : elim p u : P[u/x] @@@@@@@@@@@@@@@@ @ P type [x : Unit] p : P[tt/x] elim p tt = p : P[tt/x] Larry Diehl Martin-L¨ of’s Type Theory (MLTT)
A] Σx:A.B type A : U B : U [x : A] Σx:A.B : U B type [x : A] a : A b : B[a/x] (a, b) : Σx:A.B s : Σx:A.B π1 s : A s : Σx:A.B π2 s : B[π1 s/x] s : Σx:A.B s = (π1 s, π2 s) : Σx:A.B B type [x : A] a : A b : B[a/x] π1 (a, b) = a : A B type [x : A] a : A b : B[a/x] π2 (a, b) = b : B[a/x] Larry Diehl Martin-L¨ of’s Type Theory (MLTT)
from a term. Predicates Can be represented as a function (i.e. a large elimination) from booleans (B) to types. If the predicate is satisfied, the function returns (which is inhabited), otherwise it returns ⊥(which is uninhabited). Predicates can similarly be defined over other types (e.g. an IsSorted predicate from lists to types). Families of Types Also called indexed types. These are the same as predicates, but contain additional data of computational value, beyond mere inhabitance (e.g. a vector of elements indexed by the natural numbers). Larry Diehl Martin-L¨ of’s Type Theory (MLTT)
n : N suc n : N P type [x : N] pz : P[zero/x] ps : P[suc n/x] [n : N, p : P[n/x]] n : N elim N pz ps n : P[n/x] P type [x : N] pz : P[zero/x] ps : P[suc n/x] [n : N, p : P[n/x]] elim N pz ps zero = pz : P[zero/x] P type [x : N] pz : P[zero/x] ps : P[suc n/x] [x : N, p : P[x /x]] n : N elim N pz ps (suc n) = ps[n/x , (elim N pz ps n)/p] : P[suc n/x] Larry Diehl Martin-L¨ of’s Type Theory (MLTT)
of well-orderings, or well-founded trees. The A parameter represents the constructors and their non-inductive arguments. The dependent B parameter represents the inductive arguments for each constructor specified by A. Inductive Types Inductive types (e.g. N) can be encoded by W, and their constructors and eliminator (or, induction principle) can be derived from that of W and the types used for A and B. Infinitary Types W is the canonical example of an infinitary type, or a tree with possibly infinite branches. Instantiating A with N results in an infinitely branching tree. Larry Diehl Martin-L¨ of’s Type Theory (MLTT)
Wx:A.B type A : U B : U [x : A] Wx:A.B : U B type [x : A] a : A fb : B[a/x] → Wx:A.B sup a fb : Wx:A.B P type [x : Wx:A.B] p : Πa:A.Πfb:(B[a/x] → Wx:A.B).(Πb:B[a/x].P[b/x]) → P[sup a fb/x] w : Wx:A.B elimW p w : P[w/x] P type [x : Wx:A.B] p : Πa:A.Πfb:(B[a/x] → Wx:A.B).(Πb:B[a/x].P[b/x]) → P[sup a fb/x] a : A fb : B[a/x] → Wx:A.B elimW p (sup a fb) = p a fb (λb.elimW p (fb b)) : P[w/x] Larry Diehl Martin-L¨ of’s Type Theory (MLTT)
function requires function extensionality. This is needed to identify all possible representations of zero, and more specifically all possible terms of type ⊥ → N. Extensional Equality of Functions f x = f x : B [x : A] f = f : Πx:A.B Larry Diehl Martin-L¨ of’s Type Theory (MLTT)
term can be used to derive the type of lists? List ? List : U → U Vectors What term can be used to derive the type of vectors (i.e. lists of length n)? Vec ? Vec : U → N → U Larry Diehl Martin-L¨ of’s Type Theory (MLTT)
and Giovanni Sambin. Repository of works by Per Martin-L¨ of https://github.com/michaelt/martin-lof Includes a searchable and re-typeset version of the book. Larry Diehl Martin-L¨ of’s Type Theory (MLTT)