normalization by evaluation for martin l f type theory
play

Normalization by Evaluation for Martin-Lf Type Theory with One - PowerPoint PPT Presentation

Normalization Martin-Lf type theory Normalization algorithm Decidability of equality Normalization by Evaluation for Martin-Lf Type Theory with One Universe Peter Dybjer, Gteborg (with Andreas Abel, Munich, and Klaus Aehlig, Swansea)


  1. Normalization Martin-Löf type theory Normalization algorithm Decidability of equality Normalization by Evaluation for Martin-Löf Type Theory with One Universe Peter Dybjer, Göteborg (with Andreas Abel, Munich, and Klaus Aehlig, Swansea) MFPS XXIII, New Orleans 11-14 April, 2007 MFPS 2007, New Orleans

  2. Normalization Martin-Löf type theory Normalization algorithm Decidability of equality Partial evaluation of programs Let us define power m n = m n . power :: int -> int -> int power m 0 = 1 power m (Succ n) = m * (power m n) In Gödel System T power m n = rec 1 (\x y -> m * y) n Let n = 3. Simplify: power m 3 = m * (m * m) MFPS 2007, New Orleans by using the reduction rules for power , *, and +.

  3. Normalization Martin-Löf type theory Normalization algorithm Decidability of equality Partial evaluation of types In Martin-Löf type theory we can define the type-valued function Power A n = A n . Set is the type of small types - a universe: Power :: Set -> Nat -> Set Power A 0 = 1 Power A (Succ n) = A * (Power A n) Power A n = rec 1 (\x y -> A * y) n Let n = 3. Simplify: Power A 3 = A * (A * (A * 1)) by using the reduction rules for Power . Can we simplify further? MFPS 2007, New Orleans

  4. Normalization Martin-Löf type theory Normalization algorithm Decidability of equality Normalization during type-checking To check that (2007,(4,(12,()))) :: Power Nat 3 we need to normalize the type: (2007,(4,(12,()))) :: Nat * (Nat * (Nat * 1)) MFPS 2007, New Orleans

  5. Normalization Martin-Löf type theory Normalization algorithm Decidability of equality Programming normalization – by evaluation Normalization as a program ! Constructive metamathematics is meta-programming! An elegant way is to normalize by “evaluating” a term in a model, and then extracting the normal form: [[ − ]] syntax model ✲ ✛ ↓ nbe t = ↓ [[ t ]] In this talk we shall view the model as the model of normal forms in higher-order abstract syntax . MFPS 2007, New Orleans

  6. Normalization Martin-Löf type theory Normalization algorithm Decidability of equality Plan Martin-Löf type theory with one universe and untyped conversion (like Martin-Löf 1972 + η -rule). Syntax, reduction, normal forms, and inference rules. Normalization algorithms for terms and types: [ [ A ] ] ρΓ nbe A Γ t = ↓ [[ t ]] ρ Γ | Γ | Nbe Γ A = ⇓ | Γ | [[ A ]] ρ Γ Correctness of normalization algorithm for terms and types means decidability of equality: If Γ ⊢ t , t ′ : A then t = βη t ′ iff nbe A Γ t ′ ∈ Tm . Γ t ≡ nbe A If Γ ⊢ A , A ′ then A = βη A ′ iff Nbe Γ A ≡ Nbe Γ A ′ ∈ Tm . MFPS 2007, New Orleans

  7. Normalization Martin-Löf type theory Normalization algorithm Decidability of equality Martin-Löf Type Theory Types and terms with de Bruijn indices (types are terms - universe à la Russell) Tm ∋ r , s , t , z , A , B :: = v i de Bruijn index λ t | abstracting 0th variable | r s application | Zero natural number “0” | Succ t successor | Rec Az s t primitive recursion Π AB | dependent function type | Nat natural number type | Set universe We can add other set constructors too: Σ AB , A + B , 0 , 1 , and inductively defined datatypes. (E.g example with Power -types used × .) MFPS 2007, New Orleans

  8. Normalization Martin-Löf type theory Normalization algorithm Decidability of equality Reduction and conversion One-step βη -reduction t − → t ′ is given as the congruence-closure of the following contractions. ( λ t ) s ( β - λ ) − → t [ s ] λ . ( ⇑ 1 t ) v 0 ( η ) − → t ( β - Rec - Zero ) − → Rec Az s Zero z ( β - Rec - Succ ) Rec Az s ( Succ r ) − → s r ( Rec Az s r ) → ∗ is confluent, so we can define Its reflexive-transitive closure − t = βη t ′ as ∃ s . t − → ∗ s ∗ ← − t ′ . MFPS 2007, New Orleans

  9. Normalization Martin-Löf type theory Normalization algorithm Decidability of equality Judgement forms Γ ⊢ Γ is a well-formed context Γ ⊢ A A is a well-formed type in context Γ Γ ⊢ t : A t has type A in context Γ We follow Martin-Löf 1972: basis is conversion of untyped terms (does not count as judgement): t = βη t ′ Martin-Löf 1973 and onwards instead has typed equality judgements Γ ⊢ A = A ′ Γ ⊢ t = t ′ : A MFPS 2007, New Orleans

  10. Normalization Martin-Löf type theory Normalization algorithm Decidability of equality Some inference rules We only give the rules for well-formed sets Γ ⊢ A : Set Γ , A ⊢ B : Set Γ ⊢ Nat : Set Γ ⊢ Π AB : Set well-formed types Γ ⊢ A : Set Γ ⊢ Γ ⊢ A Γ , A ⊢ B Γ ⊢ A Γ ⊢ Set Γ ⊢ Π AB and the type conversion rule: Γ ⊢ t : A Γ ⊢ A ′ A = βη A ′ Γ ⊢ t : A ′ There are also introduction and elimination rules for Π and Nat , and rules for context formation and assumption. MFPS 2007, New Orleans

  11. Normalization Martin-Löf type theory Normalization algorithm Decidability of equality Semantics: normal forms in higher order abstract syntax First-order syntax of normal and neutral (well-formed) types and (well-typed) terms: Π AB | Nat | Set | λ t | Zero | Succ t | s :: = A , B , t , u :: = v i | s t | Rec At u s s "There is no model of normal forms; normality is not closed under application (and recursion)". Define a domain D of normal forms in higher-order abstract syntax with the following "constructors": D × [ D → D ] → D [ D → D ] → D Pi : Lam : : : Nat D Zero D D → D Set : D Succ : : TM ⊥ → D Ne where TM = N → Tm Z (See paper for strictness issues.) MFPS 2007, New Orleans

  12. Normalization Martin-Löf type theory Normalization algorithm Decidability of equality Haskell datatypes for terms and normal forms in hoas data Tm = Var Int | App Tm Tm | Lam Tm | Zero | Succ Tm | Rec Tm Tm Tm Tm | Nat | Pi Tm Tm | Set deriving (Show,Eq) type TM = Int -> Tm data D = PiD D (D -> D) -- dependent function type | NatD -- natural number type | SetD -- type of sets | LamD (D -> D) -- function | ZeroD -- 0 | SuccD D -- successor | NeD TM -- neutral terms MFPS 2007, New Orleans

  13. Normalization Martin-Löf type theory Normalization algorithm Decidability of equality Nbe functions in Haskell A context is a list of types type Cxt = [Tm] Normalization of a term wrt a type and a context: nbe :: Cxt -> Tm -> Tm -> Tm Normalization of a type wrt a context nbeT :: Cxt -> Tm -> Tm MFPS 2007, New Orleans

  14. Normalization Martin-Löf type theory Normalization algorithm Decidability of equality Evaluation function [[ _ ]] _ Tm → [[ N → D ] → D ] : ρ ( i ) [[ v i ]] ρ = [[ λ t ]] ρ = Lam ( d �→ [[ t ]] ρ , d ) [[ r s ]] ρ = [[ r ]] ρ · [[ s ]] ρ [[ Zero ]] ρ = Zero [[ Succ t ]] ρ = Succ [[ t ]] ρ [[ Rec Az s t ]] ρ = rec ( d �→ [[ A ]] ρ , d )[[ z ]] ρ [[ s ]] ρ [[ t ]] ρ [[ Π AB ]] ρ = Pi [[ A ]] ρ ( d �→ [[ B ]] ρ , d ) [[ Nat ]] ρ = Nat [[ Set ]] ρ = Set MFPS 2007, New Orleans

  15. Normalization Martin-Löf type theory Normalization algorithm Decidability of equality Application of normal forms in hoas We define application on D as the function app : [ D → [ D → D ]] ( Lam f ) · d = f d e · d = ⊥ if e is not Lam f where in the following “default ⊥ clauses” like the last one are always tacitly assumed. In Haskell: appD :: D -> D -> D appD (LamD f) d = f d We also need to define primitive recursion rec in the model, but first we need reification and reflection. MFPS 2007, New Orleans

  16. Normalization Martin-Löf type theory Normalization algorithm Decidability of equality Reification - translating hoas to foas ⇓ : [ D → TM ⊥ ] Π ( ⇓ k a )( ⇓ k + 1 g ( ↑ a ˆ ⇓ k ( Pi ag ) = v − ( k + 1 ) )) ⇓ k Nat = Nat ⇓ k Set = Set ⇓ k ( Ne ˆ ˆ t ) = t ( k ) ↓ : [ D → [ D → TM ⊥ ]] ↓ Set = ⇓ k a a k g ( ↑ a ˆ v − ( k + 1 ) ) ( f ( ↑ a ˆ λ ( ↓ ↓ Pi ag ( Lam f ) = v − ( k + 1 ) ))) k + 1 k ↓ Nat = Zero Zero k ↓ Nat Succ ( ↓ Nat k ( Succ d ) = d ) k MFPS 2007, New Orleans ↓ c k ( Ne ˆ ˆ t ) = t ( k ) if c � = ⊥ , c � = Pi ...

  17. Normalization Martin-Löf type theory Normalization algorithm Decidability of equality Reflection Mapping neutral terms (including variables) to D: ↑ : [ D → [ TM ⊥ → D ]] ↑ Pi ag ˆ t ↓ a d )) Lam ( d �→ ↑ g ( d ) ( ˆ = t ↑ c ˆ Ne ˆ = if c � = ⊥ , c � = Pi ... t t We perform η -expansion. Hence we need the first argument which is a normal type in hoas - an element of D. MFPS 2007, New Orleans

  18. Normalization Martin-Löf type theory Normalization algorithm Decidability of equality Primitive recursion on normal forms in hoas rec : [[ D → D ] → [ D → [ D → [ D → D ]]]] = rec ad z d s Zero d z rec ad z d s ( Succ e ) = d s · e · ( rec ad z d s e ) ↑ a ( Ne ˆ t ) ( k �→ Rec ( ⇓ k + 1 a ( Ne v − ( k + 1 ) )) rec ad z d s ( Ne ˆ t ) = ( ↓ a Zero d z ) k ( ↓ Π Nat ( d �→ ad ⇒ a ( Succ d )) d s ) k ˆ t ( k )) Here we use reification ↓ and reflection ↑ . MFPS 2007, New Orleans

  19. Normalization Martin-Löf type theory Normalization algorithm Decidability of equality The normalization function Normalization by evaluation for terms and types is now implemented by these two functions: [ [ A ] ] ρΓ nbe A : = ↓ [[ t ]] ρ Γ Γ t | Γ | : = ⇓ | Γ | [[ A ]] ρ Γ Nbe Γ A where ρ Γ is the identity valuation which is obtained by reflection of the identity substitution. MFPS 2007, New Orleans

Recommend


More recommend