Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Martin-Löf's Type Theory (MLTT)

Martin-Löf's Type Theory (MLTT)

Guest lecture at the University of Iowa.

larrytheliquid

April 26, 2018
Tweet

More Decks by larrytheliquid

Other Decks in Programming

Transcript

  1. Martin-L¨ of’s Type Theory (MLTT) Larry Diehl University of Iowa

    - Guest Lecture CS:5860 Lambda Calculus and Applications Larry Diehl Martin-L¨ of’s Type Theory (MLTT)
  2. Curry-Howard Isomorphism Propositions as types and proofs as terms. Use

    λ-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)
  3. Curry-Howard Isomorphism System F Falsity ⊥ ∀X.X Truth ∀X.X →

    X Implication P ⇒ Q P → Q F.O. Prop. Quantif. ∀P :Prop.Q ∀P.Q Larry Diehl Martin-L¨ of’s Type Theory (MLTT)
  4. Curry-Howard Isomorphism System Fω Falsity ⊥ ∀X : .X Truth

    ∀X : .X → X Negation ¬P P → ⊥ Implication P ⇒ Q P → Q Conjuction P ∧ Q ∀X : .(P → Q → X) → X Disjunction P ∨ Q ∀X : .(P → X) → (Q → X) → X F.O. Prop. Quantif. ∀P :Prop.Q ∀P : .Q H.O. Prop. Quantif. ∀P :Prop2.Q ∀P :κ.Q Larry Diehl Martin-L¨ of’s Type Theory (MLTT)
  5. Curry-Howard Isomorphism MLTT Falsity ⊥ Truth Negation ¬P P →

    ⊥ 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)
  6. Verified Programming Dependently Typed Programming Languages Modern dependently typed programming

    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)
  7. MLTT Syntax Unified syntax for types and terms, so typehood

    and termhood are determined judgementally. Grammar A, B, a, b, f ::= ... | Πx:A.B | λx.b | f a | ... Larry Diehl Martin-L¨ of’s Type Theory (MLTT)
  8. MLTT Judgements Static and dynamic semantics are mutually defined judgements.

    Type is well-formed A type Term has type a : A Type equality A = B Term equality a = a : A Larry Diehl Martin-L¨ of’s Type Theory (MLTT)
  9. Hypothetical Judgements or, “higher-order” judgements Explicit context Γ A type

    Implicit (meta-level) context A type Larry Diehl Martin-L¨ of’s Type Theory (MLTT)
  10. Hypothetical Judgements or, “higher-order” judgements Explicit context Γ, x:A B

    type Implicit (meta-level) context B type [x : A] Variable rule x : A [x : A] Larry Diehl Martin-L¨ of’s Type Theory (MLTT)
  11. Metatheoretic Properties Type Preservation If A type and A =

    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)
  12. Equality is an Equivalence Relation A type A = A

    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)
  13. Package of Rules per Type e.g. the type of dependent

    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)
  14. A Universe (U) of Types The universe type U is

    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)
  15. Universe (U type) Formation Rules U type A : U

    A type A = A : U A = A U : U Larry Diehl Martin-L¨ of’s Type Theory (MLTT)
  16. Predicative Universe e.g. the type of the identity function ΠA:U.A

    → A type @@@@@@@@ @ ΠA:U.A → A : U Larry Diehl Martin-L¨ of’s Type Theory (MLTT)
  17. Dependent Functions (Π types) A type B type [x :

    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)
  18. Dependent Functions (Π types) Congruence Rules (suppressed henceforth) A =

    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)
  19. Computation in Types Id λA.A id λA.λa.a Id : U

    → U id : ΠA:U.A → Id A Larry Diehl Martin-L¨ of’s Type Theory (MLTT)
  20. Conversion Rules Equality of Types a : A A =

    A a : A a = a : A A = A a = a : A Larry Diehl Martin-L¨ of’s Type Theory (MLTT)
  21. Exercise: Derive the Following Typing Judgements Computation in Types λA.A

    : U → U λA.λa.a : ΠA:U.A → (λX.X) A Larry Diehl Martin-L¨ of’s Type Theory (MLTT)
  22. MLTT Open to Extension Core Can consider Π and U

    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)
  23. Bottom (⊥ type) ⊥ type ⊥ : U A type

    e : ⊥ elim⊥ e : A Larry Diehl Martin-L¨ of’s Type Theory (MLTT)
  24. Unit ( type) : U tt : u : u

    = 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)
  25. Exercise: Solve the Following Terms Elimination rule for is derivable

    P type [x : Unit] p : P[tt/x] u : elim p u : P[u/x] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Elim ? Elim : ? elim ? elim : ? Larry Diehl Martin-L¨ of’s Type Theory (MLTT)
  26. Dependent Pairs (Σ types) A type B type [x :

    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)
  27. Booleans (B type) B : U tt : B ff

    : B P type [x : B] pt : P[tt/x] pf : P[ff/x] b : B elimB pt pf b : P[b/x] P type [x : B] pt : P[tt/x] pf : P[ff/x] elimB pt pf tt = pt : P[tt/x] P type [x : B] pt : P[tt/x] pf : P[ff/x] elimB pt pf ff = pf : P[ff/x] Larry Diehl Martin-L¨ of’s Type Theory (MLTT)
  28. Large Eliminations Large Elimination A function that computes a type

    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)
  29. Exercise: Solve the Following Terms Elimination rule for is derivable

         U : U P type [x : Unit] p : P[tt/x] u : elim p u : P[u/x] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Elim : ? Elim ? elim : ? elim ? Larry Diehl Martin-L¨ of’s Type Theory (MLTT)
  30. Truth Predicate (True) b : B True b : U

    True tt = True ff = ⊥ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . True λb.elimB ⊥ b True : B → U Larry Diehl Martin-L¨ of’s Type Theory (MLTT)
  31. Church-Encoded Datatypes System F N ∀X.X → (X → X)

    → X zero ΛX.λcz.λcs.cz suc λn.ΛX.λcz.λcs.cs n N : zero : N suc : N → N Larry Diehl Martin-L¨ of’s Type Theory (MLTT)
  32. Natural Numbers (N type) N : U zero : N

    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)
  33. W-Encoded Datatypes MLTT W Types (Wx:A.B) W is the type

    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)
  34. Well-Orderings (W types) A type B type [x : A]

    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)
  35. Natural Numbers (N type) N Wb:B.True b zero sup ff

    (λe.elim⊥ e) suc λn.sup tt (λu.n) N : zero : N suc : N → N Larry Diehl Martin-L¨ of’s Type Theory (MLTT)
  36. Natural Numbers (N type) Caveat Deriving typing of elim N

    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)
  37. Exercise: Solve the Following Terms Lists and vectors Lists What

    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)
  38. References Book Intuitionistic type theory (1984), by Per Martin-L¨ of

    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)