Pure Type Systems without Explicit Contexts Robbert Krebbers Joint - - PowerPoint PPT Presentation

pure type systems without explicit contexts
SMART_READER_LITE
LIVE PREVIEW

Pure Type Systems without Explicit Contexts Robbert Krebbers Joint - - PowerPoint PPT Presentation

Pure Type Systems without Explicit Contexts Robbert Krebbers Joint work with Herman Geuvers, James McKinna and Freek Wiedijk Institute for Computing and Information Science Faculty of Science, Radboud University Nijmegen and Faculty of


slide-1
SLIDE 1

Pure Type Systems without Explicit Contexts

Robbert Krebbers Joint work with Herman Geuvers, James McKinna and Freek Wiedijk

Institute for Computing and Information Science Faculty of Science, Radboud University Nijmegen and Faculty of Mathematics and Computer Science Eindhoven University of Technology The Netherlands

July 14, 2010

slide-2
SLIDE 2

The main traditions of type theory

◮ Descendants of simple type theory

◮ Church’s original system ◮ Polymorphic λ-calculus, System F ◮ HOL’s type theory ◮ . . .

Traditionally presented without contexts

◮ Dependent type theories (de Bruijn, Martin-L¨

  • f)

◮ Automath ◮ Berardi/Terlouw framework of Pure Type Systems ◮ Coq’s type theory ◮ . . .

Traditionally presented with contexts

slide-3
SLIDE 3

Problem

Traditional presentation of dependent type theory

◮ Terms considered with respect to an explicit context Γ

Γ ⊢ M : A

◮ A bound variable is bound locally by a λ or Π ◮ A free variable is bound globally by Γ

slide-4
SLIDE 4

Problem

Traditional presentation of dependent type theory

◮ Terms considered with respect to an explicit context Γ

Γ ⊢ M : A

◮ A bound variable is bound locally by a λ or Π ◮ A free variable is bound globally by Γ

Can we present dependent type theory without contexts?

slide-5
SLIDE 5

Motivation

First-order logic and contexts

Predicate logic Type theory A ⊢ P(x) A ⊢ ∀x.P(x) ⊢ A → ∀x.P(x) H : A, x : D ⊢ M3 : P(x) H : A ⊢ M2 : Πx : D.P(x) ⊢ M1 : A → Πx : D.P(x) ‘sea’ of free variables context of ‘free’ variables What about? (∀x. P(x)) → (∃x. P(x))

slide-6
SLIDE 6

Approach

◮ We simulate the sea of free variables ◮ Infinitely many variables xA for each type A

slide-7
SLIDE 7

Approach

◮ We simulate the sea of free variables ◮ Infinitely many variables xA for each type A ◮ This gives an “infinite context” called Γ∞ ◮ For example

sN∗→N∗

slide-8
SLIDE 8

Approach

◮ We simulate the sea of free variables ◮ Infinitely many variables xA for each type A ◮ This gives an “infinite context” called Γ∞ ◮ For example

sN∗→N∗

◮ Variable carries history of how it comes to be well-typed

slide-9
SLIDE 9

Approach

◮ We simulate the sea of free variables ◮ Infinitely many variables xA for each type A ◮ This gives an “infinite context” called Γ∞ ◮ For example

sN∗→N∗

◮ Variable carries history of how it comes to be well-typed ◮ Judgments of the shape A : B ◮ Should be imagined as Γ∞ ⊢ A : B

slide-10
SLIDE 10

Approach

Two kinds of variables: free and bound variables Curry λx.f x Church λxA.f A→AxA

slide-11
SLIDE 11

Approach

Two kinds of variables: free and bound variables Curry λx.f x Church λxA.f A→AxA Barendregt et al. λx : A.f x

slide-12
SLIDE 12

Approach

Two kinds of variables: free and bound variables Curry λx.f x Church λxA.f A→AxA Barendregt et al. λx : A.f x Γ∞-style λ˙ x : A∗.f A∗→A∗ ˙ x

slide-13
SLIDE 13

Approach

Two kinds of variables: free and bound variables Curry λx.f x Church λxA.f A→AxA Barendregt et al. λx : A.f x Γ∞-style λ˙ x : A∗.f A∗→A∗ ˙ x That is

◮ Γ∞ extends Church’s approach to dependent types ◮ But Γ∞ avoids the need to consider substitution in labels of

bound variables

slide-14
SLIDE 14

Approach

Two kinds of variables: free and bound variables Curry λx.f x Church λxA.f A→AxA Barendregt et al. λx : A.f x Γ∞-style λ˙ x : A∗.f A∗→A∗ ˙ x That is

◮ Γ∞ extends Church’s approach to dependent types ◮ But Γ∞ avoids the need to consider substitution in labels of

bound variables (λxAλPA→∗λyPA→∗xA . . .)aA →β λPA→∗λyPA→∗aA . . .

slide-15
SLIDE 15

PTS terms

◮ The set T of pseudo-terms is defined as

T ::= s | V | ΠV : T .T | λV : T .T | T T

◮ For ordinary PTSs the choice of V does not matter

slide-16
SLIDE 16

PTS terms

◮ The set T of pseudo-terms is defined as

T ::= s | V | ΠV : T .T | λV : T .T | T T

◮ For ordinary PTSs the choice of V does not matter ◮ For Γ∞ we have two kinds of variables

V ::= ˙ X | X T X ::= x | y | z | . . . | x0 | x1 | x2 | . . .

◮ Variables xA are intended to be free ◮ Variables ˙

x are intended to be bound

slide-17
SLIDE 17

Labelling terms

◮ Type labels should be considered as strings ◮ Labels are insensitive to α and β-conversion

slide-18
SLIDE 18

Labelling terms

◮ Type labels should be considered as strings ◮ Labels are insensitive to α and β-conversion ◮ That is to say

xA[A := B] ≡ xB and (λ ˙ A : ∗. ˙ A) B∗ =β B∗ x(λ ˙

A:∗. ˙ A)B∗

=β xB∗

slide-19
SLIDE 19

Labelling terms

◮ Type labels should be considered as strings ◮ Labels are insensitive to α and β-conversion ◮ That is to say

xA[A := B] ≡ xB and (λ ˙ A : ∗. ˙ A) B∗ =β B∗ x(λ ˙

A:∗. ˙ A)B∗

=β xB∗

◮ But we do have (by type conversion)

x(λ ˙

A:∗. ˙ A)B∗ : B∗

slide-20
SLIDE 20

Typing rules

Two of the six rules

PTS rules Γ∞ rules Γ ⊢ A : s x / ∈ Γ Γ, x : A ⊢ x : A A : s xA : A Γ ⊢ A : s1 Γ, x : A ⊢ B : s2 Γ ⊢ Πx : A.B : s3 A : s1 B : s2 Π˙ x : A.B[yA := ˙ x] : s3 Remark:

◮ Binding a variable in Γ∞

replace a free variable by a bound variable

◮ No weakening rule

slide-21
SLIDE 21

But this does not correspond to PTSs!

Now we would have xA∗ : A∗ λ ˙ A : ∗.xA∗ : Π ˙ A : ∗. ˙ A but, in ordinary PTS-style A : ∗, x : A ⊢ x : A x : A ⊢ λA : ∗.x : ΠA : ∗.A which is nonsense because A∗ occurs free in the label of x.

slide-22
SLIDE 22

Taking the type annotations seriously

It is not enough to consider the free variables in a type label, but the hereditarily free variables of a type label. A : s1 B : s2 Incorrect Π˙ x : A.B[yA := ˙ x] : s3

slide-23
SLIDE 23

Taking the type annotations seriously

It is not enough to consider the free variables in a type label, but the hereditarily free variables of a type label. A : s1 B : s2 yA / ∈ hfvT(B) Π˙ x : A.B[yA := ˙ x] : s3

slide-24
SLIDE 24

Taking the type annotations seriously

It is not enough to consider the free variables in a type label, but the hereditarily free variables of a type label. A : s1 B : s2 yA / ∈ hfvT(B) Π˙ x : A.B[yA := ˙ x] : s3 M : B Π˙ x : A.B[yA := ˙ x] : s yA / ∈ hfvT(M) ∪ hfvT(B) λ˙ x : A.M[yA := ˙ x] : Π˙ x : A.B[yA := ˙ x]

slide-25
SLIDE 25

Taking the type annotations seriously

Hereditarily free type-variables are defined as hfvT(s) = hfvT(˙ x) = ∅ hfvT(F N) = hfvT(F) ∪ hfvT(N) hfvT(λ˙ x : A.N) = hfvT(Π˙ x : A.N) = hfvT(A) ∪ hfvT(N)

slide-26
SLIDE 26

Taking the type annotations seriously

Hereditarily free type-variables are defined as hfvT(s) = hfvT(˙ x) = ∅ hfvT(F N) = hfvT(F) ∪ hfvT(N) hfvT(λ˙ x : A.N) = hfvT(Π˙ x : A.N) = hfvT(A) ∪ hfvT(N) hfvT(xA) = hfv(A)

slide-27
SLIDE 27

Taking the type annotations seriously

Hereditarily free type-variables are defined as hfvT(s) = hfvT(˙ x) = ∅ hfvT(F N) = hfvT(F) ∪ hfvT(N) hfvT(λ˙ x : A.N) = hfvT(Π˙ x : A.N) = hfvT(A) ∪ hfvT(N) hfvT(xA) = hfv(A) Where the hereditarily free variables are defined as hfv(s) = hfv(˙ x) = ∅ hfv(F N) = hfv(F) ∪ hfv(N) hfv(λ˙ x : A.N) = hfv(Π˙ x : A.N) = hfv(A) ∪ hfv(N)

slide-28
SLIDE 28

Taking the type annotations seriously

Hereditarily free type-variables are defined as hfvT(s) = hfvT(˙ x) = ∅ hfvT(F N) = hfvT(F) ∪ hfvT(N) hfvT(λ˙ x : A.N) = hfvT(Π˙ x : A.N) = hfvT(A) ∪ hfvT(N) hfvT(xA) = hfv(A) Where the hereditarily free variables are defined as hfv(s) = hfv(˙ x) = ∅ hfv(F N) = hfv(F) ∪ hfv(N) hfv(λ˙ x : A.N) = hfv(Π˙ x : A.N) = hfv(A) ∪ hfv(N) hfv(xA) = {xA} ∪ hfv(A)

slide-29
SLIDE 29

The correspondence theorems

derivable PTS judgment ← → derivable Γ∞ judgment

slide-30
SLIDE 30

The correspondence theorems

derivable PTS judgment ← → derivable Γ∞ judgment (α-)rename Γ ⊢ M : A to Γ′ ⊢ M′ : A′ such that Γ′ ⊂ Γ∞ and Γ ⊢ M : A = ⇒ M′ : A′

slide-31
SLIDE 31

The correspondence theorems

derivable PTS judgment ← → derivable Γ∞ judgment (α-)rename Γ ⊢ M : A to Γ′ ⊢ M′ : A′ such that Γ′ ⊂ Γ∞ and Γ ⊢ M : A = ⇒ M′ : A′ for M : A generate a context Γ(M, A) such that Γ(M, A) ⊢ M : A ⇐ = M : A

slide-32
SLIDE 32

Type annotated judgments

A type annotated judgment is a judgment of the shape x1B1 : B1, . . . , xnBn : Bn ⊢ M : A where

  • 1. all free variables in M and A are of the form xi Bi
  • 2. all bound variables in Bi, M and A are of the form ˙

x

slide-33
SLIDE 33

Type annotated judgments

Lemma

Every judgment Γ ⊢ M : A in a PTS can be (α-)renamed to a type annotated judgment Γ′ ⊢ M′ : A′.

slide-34
SLIDE 34

Type annotated judgments

Lemma

Every judgment Γ ⊢ M : A in a PTS can be (α-)renamed to a type annotated judgment Γ′ ⊢ M′ : A′. For example consider A : ∗, a : A ⊢ (λx : A. x) a : A This judgment can be (α-)renamed to A∗ : ∗, aA∗ : A∗ ⊢ (λ˙ x : A∗. ˙ x) aA∗

slide-35
SLIDE 35

Type annotated judgments

Lemma

Every judgment Γ ⊢ M : A in a PTS can be (α-)renamed to a type annotated judgment Γ′ ⊢ M′ : A′. For example consider A : ∗, a : A ⊢ (λx : A. x) a : A This judgment can be (α-)renamed to A∗ : ∗, aA∗ : A∗ ⊢ (λ˙ x : A∗. ˙ x) aA∗

Theorem

Let Γ′ ⊢ M′ : A′ be a derivable type annotated judgment. Then M′ : A′ is derivable in the corresponding Γ∞-theory.

slide-36
SLIDE 36

The reverse implication

Theorem

Let M : A be derivable in Γ∞. Then Γ(M, A) ⊢ M : A is derivable in the corresponding PTS.

◮ Generate a context Γ(M, A) by induction over M : A

slide-37
SLIDE 37

The reverse implication

Theorem

Let M : A be derivable in Γ∞. Then Γ(M, A) ⊢ M : A is derivable in the corresponding PTS.

◮ Generate a context Γ(M, A) by induction over M : A ◮ For Π, λ, app and conv we have to merge contexts ◮ The merge of Γ and ∆ is defined as Γ, (∆ \ Γ) if

∀x ∈ dom(Γ) ∩ dom(∆)(typeΓ(x) ≡ type∆(x))

slide-38
SLIDE 38

The reverse implication

Theorem

Let M : A be derivable in Γ∞. Then Γ(M, A) ⊢ M : A is derivable in the corresponding PTS.

◮ Generate a context Γ(M, A) by induction over M : A ◮ For Π, λ, app and conv we have to merge contexts ◮ The merge of Γ and ∆ is defined as Γ, (∆ \ Γ) if

∀x ∈ dom(Γ) ∩ dom(∆)(typeΓ(x) ≡ type∆(x))

◮ So merge is a partial function ◮ Key lemma: for type annotated judgments merge is total

slide-39
SLIDE 39

Possible advantages

◮ Easier typing rules ◮ Strengthening is implicit ◮ Some meta theory is easier to prove ◮ Closer to implementation?

slide-40
SLIDE 40

Possible advantages

◮ Easier typing rules ◮ Strengthening is implicit ◮ Some meta theory is easier to prove ◮ Closer to implementation?

But is the cost of labelling variables too high?

slide-41
SLIDE 41

Future work

◮ Γ∞ presentation for other type theories

◮ Theories with definitions?

◮ Implementation based on Γ∞

◮ Efficiency? ◮ Extra kind of variables xA that remain free?

◮ Formalization

◮ Already one direction finished ◮ Locally nameless approach ◮ Suits distinction between variables well