dependent type theory with pattern matching and size
play

Dependent Type Theory with Pattern-Matching and Size-Change - PowerPoint PPT Presentation

Dependent Type Theory with Pattern-Matching and Size-Change Termination TYPES 2006 Nottingham David Wahlstedt Chalmers University of Technology, G oteborg, Sweden davidw@cs.chalmers.se 1 Contribution A proof of normalisation for


  1. Dependent Type Theory with Pattern-Matching and Size-Change Termination TYPES 2006 Nottingham David Wahlstedt Chalmers University of Technology, G¨ oteborg, Sweden davidw@cs.chalmers.se 1

  2. Contribution A proof of normalisation for Martin-L¨ of’s Logical Framework (Martin-L¨ of ’86, in Nordstr¨ om, Petersson, Smith ’90) extended with first-order parametric data types and recursively defined constants with pattern-matching. Recursion is proved well-founded if the definitions obey the Size-Change Principle for Program Termination . (Lee, Jones, Ben-Amram ’01) 2

  3. Pattern-matching definitions Call Graph f1 c1 f 1 p 11 . . . p 1 n = t 1 c4 . . . . . . ⇒ . . . c3 c5 f3 f4 f n p m 1 . . . p mn = t m f2 c2 For each call , c k , to f j in t i there is an arc from f i to f j . 3

  4. For each recursive call c , relate formal parameters and actual parameters: Recursive call c ⇒ Size-change graph f g f p 1 . . . p n = p 1 b whenever 1 p b . . . 2 2 p = b b j j i g u 1 . . . u m p i p > b r b r . . . p k k b m p n 4

  5. The Size-Change Principle All the infinite call sequences contain an infinitely decreasing thread. Path f f f f f f f ... i i i i i i i 1 2 3 4 5 6 7 Thread 5

  6. Example: “zipping” lists alternate : (A : Set) -> List A -> List A -> List A alternate A nil ys = ys alternate A (cons x xs) ys = cons x (alternate A ys xs) 6

  7. Martin-L¨ of’s logical framework Terms t, u, v ::= x | t u | λx.t Types T, U, V ::= Set | El t | Fun T ( λx.U ) The notation ( x : T ) → U is shorthand for Fun T ( λx.U ) . ( x 1 : T 1 , . . . , x n : T n ) → T is shorthand for ( x 1 : T 1 ) → . . . → ( x n : T n ) → T . 7

  8. Extended language Defined constants f : ( x 1 : T 1 , . . . , x n : T n ) → T with pattern-matching rules f p 1 . . . p n = t Patterns are of the form p ::= x | c p . . . p d : Set n → Set First-order parametric data types with polymorphic constructors c : El e 1 → . . . → El e n → El ( d x 1 . . . x k ) with e ::= x | d e . . . e and FV ( e i ) ⊆ { x 1 , . . . , x k } Extensions f, d, c are contained in the signature Σ . 8

  9. Reduction rules t � t ′ reduction in one step t � ∗ t ′ reduction in zero or more steps ( λx.t ) u � β t [ x = u ] f ( p 1 γ ) . . . ( p n γ ) � ι t γ f p 1 . . . p n = t Equality t = βι u ⇔ t � ∗ v ∧ u � ∗ v. Reduction is confluent—equality is transitive. 9

  10. Example: Set-valued functions data T = Big | Small | T ==> T subtype : T -> T -> Set subtype Small Big = Unit subtype Big Small = Empty ... subtype (t1 ==> t2) (u1 ==> u2) = And (subtype u1 t1) (subtype t2 u2) 10

  11. Context formation Γ well-formed Γ ⊢ T () well-formed (Γ , x : T ) well-formed Type formation Γ ⊢ U (Γ , x : U ) ⊢ V Γ well-formed Γ ⊢ t : Set Γ ⊢ Set Γ ⊢ El t Γ ⊢ ( x : U ) → V 11

  12. Type inhabitation Γ well-formed Γ ⊢ T Γ ⊢ t : U U = βι T Γ ⊢ x : Γ( x ) Γ ⊢ t : T Γ ⊢ t : ( x : U ) → V Γ ⊢ u : U Γ ⊢ U (Γ , x : U ) ⊢ v : V Γ ⊢ t u : V [ u/x ] Γ ⊢ λx.v : ( x : U ) → V Γ ⊢ u 1 : Set . . . Γ ⊢ u k : Set Γ well-formed Γ well-formed Γ ⊢ f : Σ( f ) Γ ⊢ d : Σ( d ) Γ ⊢ c : Σ( c )[ u 1 , . . . , u k ] 12

  13. The cartesian product of a family of sets Γ ⊢ Π : ( x : Set , El x → Set) → Set Γ ⊢ u : Set Γ ⊢ t : El u → Set Γ ⊢ fun : (( x : El u ) → El ( t x )) → El (Π t u ) We can define sets by recursion F : ( n : El Nat) → Set F zero = Nat F ( succ n ) = Π ( F n ) ( λx. Nat) 13

  14. We can only type-check β -normal terms s ::= h s 1 . . . s n | λx.s h ::= x | f | c | d | Π | fun Checking type inhabitation  Γ( x ) = ( x 1 : T 1 , . . . , x n : T n ) → T Γ ⊢ s i ↑ T i [ s 1 , . . . , s i − 1 ]  Γ ⊢ x s 1 . . . s n ↑ U U = βι T [ s 1 , . . . , s n ]  Γ , x : U ⊢ s ↑ V Γ ⊢ λx.s ↑ ( x : U ) → V x �∈ Γ 14

  15.  Σ( f ) = ( x 1 : T 1 , . . . , x n : T n ) → T Γ ⊢ s i ↑ T i [ s 1 , . . . , s i − 1 ]  Γ ⊢ f s 1 . . . s n ↑ U U = βι T [ s 1 , . . . , s n ]   Σ( c ) = (El e 1 , . . . , El e n )  Γ ⊢ s i ↑ El e i [ u 1 , . . . , u k ]   → El ( d x 1 . . . x k ) Γ ⊢ c s 1 . . . s n ↑ El u  El u � ∗ El ( d u 1 . . . u k )   Γ ⊢ s i ↑ Set Γ ⊢ d s 1 . . . s n ↑ Set m → Set Σ( d ) = Set n + m → Set 15

  16. Γ ⊢ s 1 ↑ Set Γ ⊢ s 2 ↑ El s 1 → Set Γ ⊢ Π s 1 s 2 ↑ Set Γ ⊢ s ↑ ( x : El u ) → El ( v x ) U � ∗ El (Π u v ) Γ ⊢ fun s ↑ U 16

  17. Theorem ∼ If ≺ well-founded, Σ valid and Γ ⊢ t : T , then t normalisable. Reducibility method (G¨ odel ’41, ’58, Tait ’67, Girard ’71, Martin-L¨ of ’72, C. Coquand ’96) RED T ( t ) (simplified version) • T atomic: t normalizable. • T is a function type U → V : t maps reducible terms in U to reducible terms in V . 17

  18. Given a new constant f : ( x 1 : T 1 , . . . , x n : T n ) → T, assuming RED T 1 ( t 1 ) , RED T 2 [ t 1 ] ( t 2 ) , . . . , RED T n [ t 1 , ... , t n − 1 ] ( t n ) , we have to prove RED T [ t 1 , ... , t n ] ( f t 1 . . . t n ) 18

  19. Call relation • Formal call g u 1 . . . u m ≺ f p 1 . . . p n whenever there is a rule f p 1 . . . p n = t with g u 1 . . . u m subterm of t . • Call instance ∼ ( g u 1 . . . u m ) γ δ ≺ ( f p 1 . . . p n ) γ whenever g u 1 . . . u m ≺ f p 1 . . . p n with γ and δ normal. 19

  20. In the case when t i ≡ p i γ and ( f p 1 . . . p n ) γ � ι s γ , knowing γ reducible and ∆ ⊢ s : T [ p 1 . . . p n ] , prove RED T [ p 1 ... p n ] γ ( s γ ) . By completeness we get ∆ ⊢ s ↑ T [ p 1 . . . p n ] , and we prove the goal by induction on the type-checking and ∼ the well-foundedness of ≺ . 20

Recommend


More recommend