Normalization by Evaluation for Martin-L of Type Theory Andreas - - PowerPoint PPT Presentation

normalization by evaluation for martin l of type theory
SMART_READER_LITE
LIVE PREVIEW

Normalization by Evaluation for Martin-L of Type Theory Andreas - - PowerPoint PPT Presentation

Normalization by Evaluation for Martin-L of Type Theory Andreas Abel 1 Thierry Coquand 2 Peter Dybjer 2 1 Ludwig-Maximilians-University Munich 2 Chalmers University of Technology Buchholz-Fest Munich 5 April 2008 Abel Coquand Dybjer (LMU,


slide-1
SLIDE 1

Normalization by Evaluation for Martin-L¨

  • f Type Theory

Andreas Abel1 Thierry Coquand2 Peter Dybjer2

1Ludwig-Maximilians-University Munich 2Chalmers University of Technology

Buchholz-Fest Munich 5 April 2008

Abel Coquand Dybjer (LMU, CTH) NbE for Type Theory Buchholz’08 1 / 1

slide-2
SLIDE 2

Introduction

My Talk

Dependent type theory basis for theorem provers (functional programming languages) Agda, Coq, Epigram, . . . Intensional theory with predicative universes. Judgemental βη-equality. Deciding type equality with Normalization-By-Evaluation. Semantic proof of decidability of typing.

Abel Coquand Dybjer (LMU, CTH) NbE for Type Theory Buchholz’08 2 / 1

slide-3
SLIDE 3

Introduction

Dependent Types

Dependent function space: r : Πx :A. B[x] s : A r s : B[s] Types contain terms, type equality non-trivial. Shape of types can depend on terms: Vec A n = A × · · · × A

  • n factors

Type conversion rule: t : A t : B A ∼ = B Deciding type checking requires injectivity of Π Πx :A.B ∼ = Πx :A′.B′ implies A ∼ = A′ and B ∼ = B′

Abel Coquand Dybjer (LMU, CTH) NbE for Type Theory Buchholz’08 3 / 1

slide-4
SLIDE 4

Introduction

Untyped β-Equality

One solution: A ∼ = B iff A, B have common β-reduct. Confluence of β makes ∼ = transitive. Injectivity of Π trivial. But we want also η! E.g.

Theorem prover should not distinguish between P (λx. f x) and P f ,

  • r between two inhabitants of a one-element type.

The stronger the type equality, the more (sound) programs are accepted by the type checker.

Abel Coquand Dybjer (LMU, CTH) NbE for Type Theory Buchholz’08 4 / 1

slide-5
SLIDE 5

Introduction

Untyped βη-Equality

Try: A ∼ = B iff A, B have common βη-reduct. βη-reduction (with surjective pairing) only confluent on strongly normalizing terms Proof of s.n. requires model construction . . . which requires invariance of interpretation under reduction . . . which requires subject reduction . . . which requires strengthening . . . hard to prove for pure type systems (van Benthem 1993) Even for untyped β, model construction difficult: Miquel Werner 2002: The not so simple proof-irrelevant model of CC

Abel Coquand Dybjer (LMU, CTH) NbE for Type Theory Buchholz’08 5 / 1

slide-6
SLIDE 6

Introduction

Typed βη-Equality

Introduce equality judgement ⊢ A = B. Relies on term equality ⊢ t = t′ : C. Natural for η-laws, like ⊢ t = t′ : 1. Now injectivity of Π is hard. Goguen 1994: Typed Operational Semantics for UTT.

“Syntactical” model. Shows confluence, subject reduction, normalization in one go. Impressive, technically demanding work.

This work: simpler argument, in the same spirit. Slogan: semantics proves properties of syntax. (Altenkirch 1994).

Abel Coquand Dybjer (LMU, CTH) NbE for Type Theory Buchholz’08 6 / 1

slide-7
SLIDE 7

Introduction

Deciding judgemental equality

Normalization function nfA(t). Completeness: ⊢ t = t′ : A implies nfA(t) = nfA(t′) (syntactically equal). Soundness: ⊢ t : A implies ⊢ t = nfA(t) : A.

Abel Coquand Dybjer (LMU, CTH) NbE for Type Theory Buchholz’08 7 / 1

slide-8
SLIDE 8

Syntax

Syntax of Terms and Types

Lambda-calculus with constants r, s, t ::= c | x | λx.t | r s c ::= N type of natural numbers z zero s successor rec primitive recursion Fun function space constructor U universe of small types Πx :A.B is written Fun A (λx.B).

Abel Coquand Dybjer (LMU, CTH) NbE for Type Theory Buchholz’08 8 / 1

slide-9
SLIDE 9

Syntax

Judgements

Essential judgements Γ ⊢ A A is a well-formed type in Γ Γ ⊢ t : A t has type A in Γ Γ ⊢ A = A′ A and A′ are equal types in Γ Γ ⊢ t = t′ : A t and t′ are equal terms of type A in Γ Typing of functions: Γ, x :A ⊢ t : B Γ ⊢ λx.t : Fun A (λx.B) Γ ⊢ r : Fun A (λx.B) Γ ⊢ s : A Γ ⊢ r s : B[s/x]

Abel Coquand Dybjer (LMU, CTH) NbE for Type Theory Buchholz’08 9 / 1

slide-10
SLIDE 10

Syntax

Rules for Judgmental Equality

Equality axioms: (β) Γ, x :A ⊢ t : B Γ ⊢ s : A Γ ⊢ (λx.t) s = t[s/x] : B[s/x] (η) Γ ⊢ t : Fun A (λx.B) Γ ⊢ (λx. t x) = t : Fun A (λx.B) x ∈ FV(t) Computation axioms for primitive recursion. Congruence rules.

Abel Coquand Dybjer (LMU, CTH) NbE for Type Theory Buchholz’08 10 / 1

slide-11
SLIDE 11

Syntax

Small and Large Types

Small types (sets): Γ ⊢ N : U Γ ⊢ A : U Γ, x :A ⊢ B : U Γ ⊢ Fun A (λx.B) : U U includes types defined by recursion like Vec A n. (Large) types: Γ ⊢ A : U Γ ⊢ A Γ ⊢ U Γ ⊢ A Γ, x :A ⊢ B Γ ⊢ Fun A (λx.B)

Abel Coquand Dybjer (LMU, CTH) NbE for Type Theory Buchholz’08 11 / 1

slide-12
SLIDE 12

Semantics

λ-Model

Consider a (total) combinatorial algebra D with constructors N, z, s, Fun, U. Evaluation [[t]]ρ: Standard. [[c]]ρ = c (c constant) [[x]]ρ = ρ(x) [[r s]]ρ = [[r]]ρ [[s]]ρ [[λx.t]]ρ d = [[t]]ρ[x→d] Example: [[Fun A (λx.B)]] = Fun X F where X = [[A]] and F d = [[B]][x→d]. We enrich D with term variables: Up u ∈ D for each neutral term u ::= x v (generalized variable).

Abel Coquand Dybjer (LMU, CTH) NbE for Type Theory Buchholz’08 12 / 1

slide-13
SLIDE 13

Semantics

Reification (Printing)

Reification ↓Xd produces a η-long β-normal term. ↓Nz = z ↓N(s d) = s (↓Nd) ↓N(Up u) = u ↓Up u′(Up u) = u ↓Fun X Ff = λx. ↓F (↑X x)(f (↑Xx)), x fresh Reflection ↑Xu embeds a neutral term u into D, η-expanded. (↑Fun X F u) d = ↑F d(u ↓Xd) ↑X u = Up u Normalization of closed terms ⊢ t : A nfA(t) = ↓[

[A] ][[t]].

Abel Coquand Dybjer (LMU, CTH) NbE for Type Theory Buchholz’08 13 / 1

slide-14
SLIDE 14

Semantics

PER Model

A PER is a symmetric and transitive relation on D. Small types: define a PER U and a PER [X] for X ∈ U. N = N ∈ U z = z ∈ [N] d = d′ ∈ [N] s d = s d′ ∈ [N] u neutral Up u = Up u ∈ [N] u neutral Up u = Up u ∈ U u, u′ neutral Up u′ = Up u′ ∈ [Up u] X = X ′ ∈ U F d = F ′ d′ ∈ U for all d = d′ ∈ [X] Fun X F = Fun X ′ F ′ ∈ U f d = f ′ d′ ∈ [F d] for all d = d′ ∈ [X] f = f ′ ∈ [Fun X F]

Abel Coquand Dybjer (LMU, CTH) NbE for Type Theory Buchholz’08 14 / 1

slide-15
SLIDE 15

Semantics

Modelling Large Types

Large types: Define PER Type and extend [ ] to Type. U ⊆ Type X = X ′ ∈ Type F d = F ′ d′ ∈ Type for all d = d′ ∈ [X] Fun X F = Fun X ′ F ′ ∈ Type U = U ∈ Type [U] = U PERs contain only total elements of D. These can be printed (converted to terms).

Abel Coquand Dybjer (LMU, CTH) NbE for Type Theory Buchholz’08 15 / 1

slide-16
SLIDE 16

Semantics

Checking Semantic Equality

Lemma Let X = X ′ ∈ Type.

1 ↑Xu = ↑X ′u ∈ [X]. 2 If d = d′ ∈ [X] then ↓Xd =α ↓X ′d′.

Proof. Simultaneously by induction on X = X ′ ∈ Type.

Abel Coquand Dybjer (LMU, CTH) NbE for Type Theory Buchholz’08 16 / 1

slide-17
SLIDE 17

Semantics

Completeness of NbE

Theorem (Validity of judgements in PER model) Let ρ(x) = ρ′(x) ∈ [[Γ(x)]]ρ for all x. If Γ ⊢ t : A then [[t]]ρ = [[t]]ρ′ ∈ [[[A]]ρ]. If Γ ⊢ t = t′ : A then [[t]]ρ = [[t′]]ρ′ ∈ [[[A]]ρ]. Corollary (Completeness of nf) If ⊢ t = t′ : A then nfA(t) =α nfA(t′). Soundness remains: If ⊢ t : A then ⊢ t = nfA(t) : A.

Abel Coquand Dybjer (LMU, CTH) NbE for Type Theory Buchholz’08 17 / 1

slide-18
SLIDE 18

Logical Relations

Kripke Logical Relation

Relate well-typed terms modulo equality to inhabitants of PERs. Lemma (Into and out of the logical relation) Let Γ ⊢ C

R

X.

1 If Γ ⊢ r = u : C then Γ ⊢ r : C

R

↑Xu ∈ [X].

2 If Γ ⊢ r : C

R

d ∈ [X] then Γ ⊢ r = ↓Xd : C. Definition Γ ⊢ r : C

R

d ∈ [X] :⇐ ⇒ Γ ⊢ r = ↓Xd : C for X base type, Γ ⊢ r : C

R

f ∈ [Fun X F] :⇐ ⇒ Γ ⊢ C = Fun A (λx.B) for some A, B and for all Γ′ ≤ Γ and Γ′ ⊢ s : A R d ∈ [X], Γ′ ⊢ r s : B[s/x] R f d ∈ [F d].

Abel Coquand Dybjer (LMU, CTH) NbE for Type Theory Buchholz’08 18 / 1

slide-19
SLIDE 19

Logical Relations

Soundness of NbE

Prove the fundamental theorem. Corollary: ⊢ t : A implies ⊢ t : A R [[t]] ∈ [[[A]]]. Escaping the log.rel.: ⊢ t = ↓[

[A] ][[t]] : A.

Hence, nf is also sound. Decidability of judgemental equality entails injectivity of Π.

Abel Coquand Dybjer (LMU, CTH) NbE for Type Theory Buchholz’08 19 / 1

slide-20
SLIDE 20

Logical Relations

Conclusion

Semantic metatheory of Martin-L¨

  • f Type Theory.

Inference rules directly justified by PER model. No need to prove strengthening, subject reduction, confluence, normalization. Future work:

Extend to Σ-types, singleton-types, proof-irrelevance. Adopt to syntax of categories-with-families (de Bruijn indices and explicit substitutions).

Abel Coquand Dybjer (LMU, CTH) NbE for Type Theory Buchholz’08 20 / 1

slide-21
SLIDE 21

Logical Relations

Related Work

Martin-L¨

  • f 1975: NbE for Type Theory (weak conversion)

Martin-L¨

  • f 2004: Talk on NbE (philosophical justification)

Danvy et al: Type-directed partial evaluation Altenkirch Hofmann Streicher 1996: NbE for λ-free System F Berger Eberl Schwichtenberg 2003: Term rewriting for NbE Aehlig Joachimski 2004: Untyped NbE, operationally Filinski Rohde 2004: Untyped NbE, denotationally Danielsson 2006: strongly typed NbE for LF Altenkirch Chapman 2007: Tait in one big step

Abel Coquand Dybjer (LMU, CTH) NbE for Type Theory Buchholz’08 21 / 1