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

dependent type theory with pattern matching and size
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

Dependent Type Theory with Pattern-Matching and Size-Change Termination

TYPES 2006 Nottingham

David Wahlstedt

Chalmers University of Technology, G¨

  • teborg, Sweden

davidw@cs.chalmers.se

1

slide-2
SLIDE 2

Contribution A proof of normalisation for Martin-L¨

  • f’s Logical Framework

(Martin-L¨

  • f ’86, in Nordstr¨
  • m, 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

slide-3
SLIDE 3

Pattern-matching definitions Call Graph f1 p11 . . . p1n = t1 . . . . . . . . . fn pm1 . . . pmn = tm ⇒

f1 f2 f3 f4 c1 c2 c3 c4 c5

For each call, ck, to fj in ti there is an arc from fi to fj.

3

slide-4
SLIDE 4

For each recursive call c, relate formal parameters and actual parameters: Recursive call c ⇒ Size-change graph f p1 . . . pn = . . . g u1 . . . um . . .

p

k

p

i

p p b b

n 2 1 2

p 1 g b m = > whenever

j

b b r p

i j

b b r p

k

f

4

slide-5
SLIDE 5

The Size-Change Principle All the infinite call sequences contain an infinitely decreasing thread. Path

i i i i i i

1 2 3 4 5 6 7

f f f f f f Thread f

i

...

5

slide-6
SLIDE 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

slide-7
SLIDE 7

Martin-L¨

  • f’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). (x1 : T1, . . . , xn : Tn) → T is shorthand for (x1 : T1) → . . . → (xn : Tn) → T.

7

slide-8
SLIDE 8

Extended language Defined constants f : (x1 : T1, . . . , xn : Tn) → T with pattern-matching rules f p1 . . . pn = t Patterns are of the form p ::= x | c p . . . p First-order parametric data types d : Setn → Set with polymorphic constructors c : El e1 → . . . → El en → El (d x1 . . . xk) with e ::= x | d e . . . e and FV (ei) ⊆ {x1, . . . , xk} Extensions f, d, c are contained in the signature Σ.

8

slide-9
SLIDE 9

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

9

slide-10
SLIDE 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

slide-11
SLIDE 11

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

11

slide-12
SLIDE 12

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

12

slide-13
SLIDE 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

slide-14
SLIDE 14

We can only type-check β-normal terms s ::= h s1 . . . sn | λx.s h ::= x | f | c | d | Π | fun Checking type inhabitation Γ ⊢ si ↑ Ti[s1, . . . , si−1] Γ ⊢ x s1 . . . sn ↑ U    Γ(x) = (x1 : T1, . . . , xn : Tn) → T U =βιT[s1, . . . , sn] Γ, x : U ⊢ s ↑ V Γ ⊢ λx.s ↑ (x : U) → V x ∈ Γ

14

slide-15
SLIDE 15

Γ ⊢ si ↑ Ti[s1, . . . , si−1] Γ ⊢ f s1 . . . sn ↑ U    Σ(f) = (x1 : T1, . . . , xn : Tn) → T U =βιT[s1, . . . , sn] Γ ⊢ si ↑ El ei[u1, . . . , uk] Γ ⊢ c s1 . . . sn ↑ El u        Σ(c) = (El e1, . . . , El en) → El (d x1 . . . xk) El u ∗ El (d u1 . . . uk) Γ ⊢ si ↑ Set Γ ⊢ d s1 . . . sn ↑ Setm → Set Σ(d) = Setn+m → Set

15

slide-16
SLIDE 16

Γ ⊢ s1 ↑ Set Γ ⊢ s2 ↑ El s1 → Set Γ ⊢ Π s1 s2 ↑ Set Γ ⊢ s ↑ (x : El u) → El (v x) Γ ⊢ fun s ↑ U U ∗ El (Π u v)

16

slide-17
SLIDE 17

Theorem If

≺ well-founded, Σ valid and Γ ⊢ t : T, then t normalisable. Reducibility method (G¨

  • del ’41, ’58, Tait ’67, Girard ’71, Martin-L¨
  • f ’72,
  • C. Coquand ’96)

REDT(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

slide-18
SLIDE 18

Given a new constant f : (x1 : T1, . . . , xn : Tn) → T, assuming REDT1(t1), REDT2[t1](t2), . . . , REDTn[t1, ... , tn−1](tn), we have to prove REDT[t1, ... , tn](f t1 . . . tn)

18

slide-19
SLIDE 19

Call relation

  • Formal call

g u1 . . . um ≺ f p1 . . . pn whenever there is a rule f p1 . . . pn = t with g u1 . . . um subterm of t.

  • Call instance

(g u1 . . . um) γ δ

≺ (f p1 . . . pn) γ whenever g u1 . . . um ≺ f p1 . . . pn with γ and δ normal.

19

slide-20
SLIDE 20

In the case when ti ≡ pi γ and (f p1 . . . pn) γ ι s γ, knowing γ reducible and ∆ ⊢ s : T[p1 . . . pn], prove REDT[p1 ... pn]γ(s γ). By completeness we get ∆ ⊢ s ↑ T[p1 . . . pn], and we prove the goal by induction on the type-checking and the well-foundedness of

≺.

20