Rewrite Semantics for Guarded Recursion in Type Theory Patrick Bahr - - PowerPoint PPT Presentation

rewrite semantics for guarded recursion in type theory
SMART_READER_LITE
LIVE PREVIEW

Rewrite Semantics for Guarded Recursion in Type Theory Patrick Bahr - - PowerPoint PPT Presentation

Rewrite Semantics for Guarded Recursion in Type Theory Patrick Bahr IT University of Copenhagen joint work with Rasmus Mgelberg and Hans Bugge Grathwohl Overview Guarded Recursive Types Dependent Types Reduction Semantics 2 / 21 Guarded


slide-1
SLIDE 1

Rewrite Semantics for Guarded Recursion in Type Theory

Patrick Bahr

IT University of Copenhagen

joint work with Rasmus Møgelberg and Hans Bugge Grathwohl

slide-2
SLIDE 2

Overview

Guarded Recursive Types Dependent Types Reduction Semantics

2 / 21

slide-3
SLIDE 3

Guarded Recursive Types

  • H. Nakano. A modality for recursion. In: LICS, 2000

3 / 21

slide-4
SLIDE 4

Guarded Recursion

◮ type modality ⊲ (pronounced “later”) ◮ ⊲ is an applicative functor

next : A → ⊲A ⊛ : ⊲(A → B) → ⊲A → ⊲B

◮ fixed-point operator fix: (⊲A → A) → A ◮ guarded recursive types: µX.A

4 / 21

slide-5
SLIDE 5

Example Str = µX.Nat × ⊲X cons: Nat → ⊲Str → Str cons = λx.λy.x, y nats: Nat → Str nats = fix(λf n.cons n (f ⊛ (next(n + 1)))) inter: Str → ⊲Str → Str inter = fix(λf s t.cons (π1s) (f ⊛ t ⊛ (next(π2s)))) foo: Str foo = fix(λx.inter (nats 0), x)

5 / 21

slide-6
SLIDE 6

Motivation

◮ functional reactive programming ◮ productive coprogramming

(clocks & clock quantification)

◮ solving recursive domain equations

(→ synthetic domain theory)

6 / 21

slide-7
SLIDE 7

Dependent Types

  • A. Bizjak, H. B. Grathwohl, R. Clouston, R. E. Møgelberg, and L. Birkedal.

Guarded dependent type theory with coinductive types. In FoSSaCS, 2016.

7 / 21

slide-8
SLIDE 8

Combining Π and ⊲ Γ ⊢ s : Πx : A.B Γ ⊢ t : A Γ ⊢ s t : B [t/x]

8 / 21

slide-9
SLIDE 9

Combining Π and ⊲ Γ ⊢ s : Πx : A.B Γ ⊢ t : A Γ ⊢ s t : B [t/x] Γ ⊢ s : ⊲ (Πx : A.B) Γ ⊢ t : ⊲ A Γ ⊢ s ⊛ t : ???

8 / 21

slide-10
SLIDE 10

Combining Π and ⊲ Γ ⊢ s : Πx : A.B Γ ⊢ t : A Γ ⊢ s t : B [t/x] Γ ⊢ s : ⊲ (Πx : A.B) Γ ⊢ t : ⊲ A Γ ⊢ s ⊛ t : ⊲ B [t/x]

8 / 21

slide-11
SLIDE 11

Combining Π and ⊲ Γ ⊢ s : Πx : A.B Γ ⊢ t : A Γ ⊢ s t : B [t/x] Γ ⊢ s : ⊲ (Πx : A.B) Γ ⊢ t : ⊲ A Γ ⊢ s ⊛ t : ⊲ B [t/x]

◮ Problem: t : ⊲ A,

but x : A

8 / 21

slide-12
SLIDE 12

Combining Π and ⊲ Γ ⊢ s : Πx : A.B Γ ⊢ t : A Γ ⊢ s t : B [t/x] Γ ⊢ s : ⊲ (Πx : A.B) Γ ⊢ t : ⊲ A Γ ⊢ s ⊛ t : ⊲ B [t/x]

◮ Problem: t : ⊲ A,

but x : A

◮ needed: getting rid of ⊲ in a controlled way

8 / 21

slide-13
SLIDE 13

Delayed Substitutions

Instead of Γ ⊢ s : ⊲ (Πx : A.B) Γ ⊢ t : ⊲ A Γ ⊢ s ⊛ t : ⊲ B [t/x] we have Γ ⊢ s : ⊲ (Πx : A.B) Γ ⊢ t : ⊲ A Γ ⊢ s ⊛ t : ⊲ [x ← t] .B

9 / 21

slide-14
SLIDE 14

Delayed Substitutions

Instead of Γ ⊢ s : ⊲ (Πx : A.B) Γ ⊢ t : ⊲ A Γ ⊢ s ⊛ t : ⊲ B [t/x] we have Γ ⊢ s : ⊲ (Πx : A.B) Γ ⊢ t : ⊲ A Γ ⊢ s ⊛ t : ⊲ [x ← t] .B

In general

⊲ [x1 ← t1, . . . xn ← tn] .A

9 / 21

slide-15
SLIDE 15

Delayed Substitutions

Instead of Γ ⊢ s : ⊲ (Πx : A.B) Γ ⊢ t : ⊲ A Γ ⊢ s ⊛ t : ⊲ B [t/x] we have Γ ⊢ s : ⊲ (Πx : A.B) Γ ⊢ t : ⊲ A Γ ⊢ s ⊛ t : ⊲ [x ← t] .B

In general

⊲ [x1 ← t1, . . . xn ← tn] .A next [x1 ← t1, . . . xn ← tn] .t

9 / 21

slide-16
SLIDE 16

Equalities

⊲ [x ← next u] .A = ⊲ A [u/x]

10 / 21

slide-17
SLIDE 17

Equalities

⊲ξ [x ← nextξ.u] .A = ⊲ξ.A [u/x]

10 / 21

slide-18
SLIDE 18

Equalities

⊲ξ [x ← nextξ.u] .A = ⊲ξ.A [u/x] ⊲ ξ [x ← u] .A = ⊲ξ.A if x ∈ fv(A) ⊲ ξ [x ← u, y ← v] ξ′.A = ⊲ξ [y ← v, x ← u] ξ′.A if . . .

10 / 21

slide-19
SLIDE 19

Equalities

⊲ξ [x ← nextξ.u] .A = ⊲ξ.A [u/x] ⊲ ξ [x ← u] .A = ⊲ξ.A if x ∈ fv(A) ⊲ ξ [x ← u, y ← v] ξ′.A = ⊲ξ [y ← v, x ← u] ξ′.A if . . . nextξ [x ← nextξ.u] .t = nextξ.t [u/x] nextξ [x ← u] .t = nextξ.t if x ∈ fv(t) nextξ [x ← u, y ← v] ξ′.t = nextξ [y ← v, x ← u] ξ′.t if . . .

10 / 21

slide-20
SLIDE 20

Typing rule

Simple Case

Γ, x : A ⊢ t : B Γ ⊢ u : ⊲A Γ ⊢ next [x ← u] .t : ⊲ [x ← u] .B

11 / 21

slide-21
SLIDE 21

Typing rule

Simple Case

Γ, x : A ⊢ t : B Γ ⊢ u : ⊲A Γ ⊢ next [x ← u] .t : ⊲ [x ← u] .B

In General

Γ, x1 : A1, . . . , xn : An ⊢ t : B Γ ⊢ ti : ⊲ [x1 ← t1, . . . , xi−1 ← ti−1] .Ai for all 1 ≤ i ≤ n Γ ⊢ next [x1 ← t1, . . . , xn ← tn] .t : ⊲ [x1 ← t1, . . . , xn ← tn] .B

11 / 21

slide-22
SLIDE 22

Applicative Structure

Applicative structure can be defined in terms of delayed substitutions: s ⊛ t = next [x ← s, y ← t] .x y

12 / 21

slide-23
SLIDE 23

Applicative Structure

Applicative structure can be defined in terms of delayed substitutions: s ⊛ t = next [x ← s, y ← t] .x y next u ⊛ next v = next [x ← next u, y ← next v] .x y = next [x ← next u] .x v = next(u v)

12 / 21

slide-24
SLIDE 24

Applicative Functor Laws

We need to add the following equality nextξ [x ← t] .x = t

13 / 21

slide-25
SLIDE 25

Applicative Functor Laws

We need to add the following equality nextξ [x ← t] .x = t We can then derive the applicative functor laws: next(λx.x) ⊛ t = t next(λf .λg.λx.f (g x)) ⊛ s ⊛ t ⊛ u = s ⊛ (t ⊛ u) next s ⊛ next t = next (s t) s ⊛ next t = next(λf .f t) ⊛ s

13 / 21

slide-26
SLIDE 26

Reduction Semantics

14 / 21

slide-27
SLIDE 27

Motivation

◮ we want to implement a type checker for

dependent type theory with guarded recursion

◮ we need to decide the equality theory ◮ possible approach: reduction relation that is

◮ strongly normalising ◮ confluent 15 / 21

slide-28
SLIDE 28

Problems with Normalisation

◮ Fixed-point combinator!

fixt = t(next(fixt))

◮ We cannot turn this equation into a normalising rewrite rule:

nextξ [x ← u, y ← v] ξ′.A = nextξ [y ← v, x ← u] ξ′.A

16 / 21

slide-29
SLIDE 29

Problems with Confluence

nextξ [x ← nextξ.s] .t = nextξ.t [s/x]

17 / 21

slide-30
SLIDE 30

Problems with Confluence

nextξ [x ← nextξ.s] .t → nextξ.t [s/x]

17 / 21

slide-31
SLIDE 31

Problems with Confluence

nextξ [x ← nextξ.s] .t → nextξ.t [s/x]

17 / 21

slide-32
SLIDE 32

Problems with Confluence

nextξ [x ← nextξ.s] .t → nextξ.t [s/x] t = [x1 ← y, x2 ← [x1 ← y] .0] .x1x2 t → next [x1 ← y] .x10 t → next [x1 ← y, x2 ← next.0] .x1x2

17 / 21

slide-33
SLIDE 33

Alternative Calculus without Delayed Substitutions

Idea

◮ controlled conversion prev : ⊲ A → A.

18 / 21

slide-34
SLIDE 34

Alternative Calculus without Delayed Substitutions

Idea

◮ controlled conversion prev : ⊲ A → A. ◮ next [x ← t] .u

  • next u [prev t/x]

◮ ⊲ [x ← t] .A

  • ⊲ A [prev t/x]

18 / 21

slide-35
SLIDE 35

Alternative Calculus without Delayed Substitutions

Idea

◮ controlled conversion prev : ⊲ A → A. ◮ next [x ← t] .u

  • nextl.u [prevlt/x]

◮ ⊲ [x ← t] .A

  • ⊲l.A [prevlt/x]

18 / 21

slide-36
SLIDE 36

Alternative Calculus without Delayed Substitutions

Idea

◮ controlled conversion prev : ⊲ A → A. ◮ next [x ← t] .u

  • nextl.u [prevlt/x]

◮ ⊲ [x ← t] .A

  • ⊲l.A [prevlt/x]

Γ ⊢L t :I ⊲l.A l ∈ L Γ ⊢L prevlt :I,l A Γ ⊢L,l t :I,l A Γ ⊢L Γ ⊢L nextl.t :I ⊲l.A

18 / 21

slide-37
SLIDE 37

Alternative Calculus without Delayed Substitutions

Idea

◮ controlled conversion prev : ⊲ A → A. ◮ next [x ← t] .u

  • nextl.u [prevlt/x]

◮ ⊲ [x ← t] .A

  • ⊲l.A [prevlt/x]

Γ ⊢L t :I ⊲l.A l ∈ L Γ ⊢L prevlt :I,l A Γ ⊢L,l t :I,l A Γ ⊢L Γ ⊢L nextl.t :I ⊲l.A J ⊆ I Γ, x :J A, Γ′ ⊢L x :I A Γ, x :I A ⊢L t :I B Γ ⊢L λx.t :I A → B

18 / 21

slide-38
SLIDE 38

Reduction rules prevl′(nextl.t) → t [l′/l] nextl.(prevlt) → t l ∈ fl(t)

19 / 21

slide-39
SLIDE 39

Reduction rules prevl′(nextl.t) → t [l′/l] nextξ [x ← nextξ.u] .A = nextξ.A [u/x] nextl.(prevlt) → t l ∈ fl(t) nextξ [x ← t] .x = t

19 / 21

slide-40
SLIDE 40

η-rule for ⊲ next [x ← t] ξ.u [next x/y] = next [x ← t] ξ.u [t/y]

20 / 21

slide-41
SLIDE 41

η-rule for ⊲ next [x ← t] ξ.u [next x/y] = next [x ← t] ξ.u [t/y] nextl.(prevl t) → t

20 / 21

slide-42
SLIDE 42

η-rule for ⊲ next [x ← t] ξ.u [next x/y] = next [x ← t] ξ.u [t/y] nextl.(prevl′t) → t l ∈ fl(t)

20 / 21

slide-43
SLIDE 43

η-rule for ⊲ next [x ← t] ξ.u [next x/y] = next [x ← t] ξ.u [t/y] nextl.(prevl′t) → t l ∈ fl(t) This rule breaks confluence!

20 / 21

slide-44
SLIDE 44

Future Work

What we have

◮ confluence proof ◮ strong normalisation without dependent types ◮ completeness w.r.t. delayed substitution calculus

21 / 21

slide-45
SLIDE 45

Future Work

What we have

◮ confluence proof ◮ strong normalisation without dependent types ◮ completeness w.r.t. delayed substitution calculus

What is missing

◮ strong normalisation of dependently typed calculus ◮ soundness w.r.t. delayed substitution calculus

21 / 21