The Clocks Are Ticking: No More Delays! Reduction Semantics for - - PowerPoint PPT Presentation

the clocks are ticking no more delays
SMART_READER_LITE
LIVE PREVIEW

The Clocks Are Ticking: No More Delays! Reduction Semantics for - - PowerPoint PPT Presentation

The Clocks Are Ticking: No More Delays! Reduction Semantics for Type Theory with Guarded Recursion Patrick Bahr 1 Hans Bugge Grathwohl 2 Rasmus Mgelberg 1 1 IT University of Copenhagen 2 Aarhus University What is guarded recursion?


slide-1
SLIDE 1

The Clocks Are Ticking: No More Delays!

Reduction Semantics for Type Theory with Guarded Recursion Patrick Bahr1 Hans Bugge Grathwohl2 Rasmus Møgelberg1

1IT University of Copenhagen 2Aarhus University

slide-2
SLIDE 2

What is guarded recursion?

◮ abstract form of step-indexing ◮ allows to add general recursive types without

breaking consistency

What is it good for?

◮ For reasoning: construct models of

programming languages and type systems.

◮ For programming: ensures productivity of

coinductive definitions – in a modular way.

1 / 14

slide-3
SLIDE 3

Goals

Reduction semantics

for dependent type theory with

◮ a universe ◮ guarded recursion ◮ multiple clocks & clock quantification

Motivation

◮ decide equality (confluence + normalisation)

type checking

◮ establish productivity operationally (canonicity)

2 / 14

slide-4
SLIDE 4

Overview

  • 1. Guarded Recursion
  • 2. Guarded Dependent Type Theory
  • 3. Clocked Type Theory (CloTT)

+ Reduction Semantics

slide-5
SLIDE 5

Guarded Recursive Types

  • Nakano. A modality for recursion. LICS 2000
slide-6
SLIDE 6

Guarded Recursion

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

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

◮ guarded fixed-point operator

fix: (⊲A → A) → A fix f = f (next(fix f ))

1Atkey & McBride. Productive Coprogramming with Guarded

Recursion, ICFP 2013

3 / 14

slide-7
SLIDE 7

Guarded Recursive Types

Guarded streams: StrG ∼ = Nat × ⊲StrG functions of types StrG → StrG are causal.

4 / 14

slide-8
SLIDE 8

Guarded Recursive Types

Guarded streams: StrG ∼ = Nat × ⊲StrG functions of types StrG → StrG are causal.

Example

We can write a function that increments each element:

incr : StrG → StrG incr := fix λg.λx : StrG. suc (π1x), g ⊛ (π2 x) but not a function that skips every other element skipEven : StrG → StrG

4 / 14

slide-9
SLIDE 9

Coinductive types via clock quantification

◮ ⊲ annotated with clock variables κ ◮ quantification over clocks: ∀κ.A ◮ force : (∀κ.⊲κA) → ∀κ.A

Example

StrG ∼ = Nat × ⊲ StrG

Atkey & McBride. Productive Coprogramming with Guarded Recursion, ICFP 2013

5 / 14

slide-10
SLIDE 10

Coinductive types via clock quantification

◮ ⊲ annotated with clock variables κ ◮ quantification over clocks: ∀κ.A ◮ force : (∀κ.⊲κA) → ∀κ.A

Example

StrG ∼ = Nat × ⊲κStrG

Atkey & McBride. Productive Coprogramming with Guarded Recursion, ICFP 2013

5 / 14

slide-11
SLIDE 11

Coinductive types via clock quantification

◮ ⊲ annotated with clock variables κ ◮ quantification over clocks: ∀κ.A ◮ force : (∀κ.⊲κA) → ∀κ.A

Example

Strκ

G ∼

= Nat × ⊲κStrκ

G Atkey & McBride. Productive Coprogramming with Guarded Recursion, ICFP 2013

5 / 14

slide-12
SLIDE 12

Coinductive types via clock quantification

◮ ⊲ annotated with clock variables κ ◮ quantification over clocks: ∀κ.A ◮ force : (∀κ.⊲κA) → ∀κ.A

Example

Strκ

G ∼

= Nat × ⊲κStrκ

G

Str = ∀κ.Strκ

G Atkey & McBride. Productive Coprogramming with Guarded Recursion, ICFP 2013

5 / 14

slide-13
SLIDE 13

Coinductive types via clock quantification

◮ ⊲ annotated with clock variables κ ◮ quantification over clocks: ∀κ.A ◮ force : (∀κ.⊲κA) → ∀κ.A

Example

Strκ

G ∼

= Nat × ⊲κStrκ

G

Str = ∀κ.Strκ

G

Functions of type Str → Str are productive. e.g. skipEven : StrG → StrG

Atkey & McBride. Productive Coprogramming with Guarded Recursion, ICFP 2013

5 / 14

slide-14
SLIDE 14

Guarded Recursion + Dependent Type Theory

  • A. Bizjak, H. B. Grathwohl, R. Clouston, R. E. Møgelberg, and L.
  • Birkedal. Guarded dependent type theory with coinductive types.

FoSSaCS 2016.

slide-15
SLIDE 15

Guarded Recursion + Dependent Type Theory Guarded Dependent Type Theory (GDTT)

  • A. Bizjak, H. B. Grathwohl, R. Clouston, R. E. Møgelberg, and L.
  • Birkedal. Guarded dependent type theory with coinductive types.

FoSSaCS 2016.

slide-16
SLIDE 16

Combining Π and ⊲κ

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

6 / 14

slide-17
SLIDE 17

Combining Π and ⊲κ

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

6 / 14

slide-18
SLIDE 18

Combining Π and ⊲κ

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

6 / 14

slide-19
SLIDE 19

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

6 / 14

slide-20
SLIDE 20

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

6 / 14

slide-21
SLIDE 21

Delayed Substitutions

[Bizjak et al. FoSSaCS 2016]

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

7 / 14

slide-22
SLIDE 22

Delayed Substitutions

[Bizjak et al. FoSSaCS 2016]

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

  • ”let nextκx = t in B”

7 / 14

slide-23
SLIDE 23

Delayed Substitutions

[Bizjak et al. FoSSaCS 2016]

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

  • ”let nextκx = t in B”

In general

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

7 / 14

slide-24
SLIDE 24

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 . . . nextξ [x ← t] .x = t

8 / 14

slide-25
SLIDE 25

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 . . . nextξ [x ← t] .x = t Not clear how to devise a confluent & normalising reduction semantics that verify these equalities.

8 / 14

slide-26
SLIDE 26

Clocked Type Theory (CloTT)

“The clocks are ticking: No more delays!”

slide-27
SLIDE 27

The clocks are ticking

◮ Treat ⊲κA as function type “κ → A” ◮ generalise to dependent function type: ⊲ (α : κ).A

9 / 14

slide-28
SLIDE 28

The clocks are ticking

◮ Treat ⊲κA as function type “κ → A” ◮ generalise to dependent function type: ⊲ (α : κ).A

Γ, α : κ ⊢∆ t : A Γ ⊢∆ λ(α : κ).t : ⊲ (α : κ).A

9 / 14

slide-29
SLIDE 29

The clocks are ticking

◮ Treat ⊲κA as function type “κ → A” ◮ generalise to dependent function type: ⊲ (α : κ).A

Γ, α : κ ⊢∆ t : A Γ ⊢∆ λ(α : κ).t : ⊲ (α : κ).A Γ ⊢∆ t : ⊲ (α : κ).A Γ, α′ : κ, Γ′ ⊢∆ Γ , α′ : κ, Γ′ ⊢∆ t [α′] : A [α′/α]

9 / 14

slide-30
SLIDE 30

The clocks are ticking

◮ Treat ⊲κA as function type “κ → A” ◮ generalise to dependent function type: ⊲ (α : κ).A

Γ, α : κ ⊢∆ t : A Γ ⊢∆ λ(α : κ).t : ⊲ (α : κ).A Γ ⊢∆ t : ⊲ (α : κ).A Γ, α′ : κ, Γ′ ⊢∆ Γ , α′ : κ, Γ′ ⊢∆ t [α′] : A [α′/α] available before tick α′ on clock κ occurred

9 / 14

slide-31
SLIDE 31

The clocks are ticking

◮ Treat ⊲κA as function type “κ → A” ◮ generalise to dependent function type: ⊲ (α : κ).A

Γ, α : κ ⊢∆ t : A Γ ⊢∆ λ(α : κ).t : ⊲ (α : κ).A Γ ⊢∆ t : ⊲ (α : κ).A Γ, α′ : κ, Γ′ ⊢∆ Γ , α′ : κ, Γ′ ⊢∆ t [α′] : A [α′/α] available before tick α′ on clock κ occurred available after tick α′ on clock κ occurred

9 / 14

slide-32
SLIDE 32

The clocks are ticking

◮ Treat ⊲κA as function type “κ → A” ◮ generalise to dependent function type: ⊲ (α : κ).A

Γ, α : κ ⊢∆ t : A Γ ⊢∆ λ(α : κ).t : ⊲ (α : κ).A Γ ⊢∆ t : ⊲ (α : κ).A Γ, α′ : κ, Γ′ ⊢∆ Γ , α′ : κ, Γ′ ⊢∆ t [α′] : A [α′/α]

9 / 14

slide-33
SLIDE 33

The clocks are ticking

◮ Treat ⊲κA as function type “κ → A” ◮ generalise to dependent function type: ⊲ (α : κ).A

Γ, α : κ ⊢∆ t : A Γ ⊢∆ λ(α : κ).t : ⊲ (α : κ).A Γ ⊢∆ t : ⊲ (α : κ).A Γ, α′ : κ, Γ′ ⊢∆ Γ , α′ : κ, Γ′ ⊢∆ t [α′] : A [α′/α]

No more delays!

nextκ [x ← t] .s

  • λ(α : κ).s [t [α]/x]

⊲κ [x ← t] .s

  • ⊲ (α : κ).s [t [α]/x]

9 / 14

slide-34
SLIDE 34

Reduction Semantics of Ticks

(λ(α′ : κ).t) [α] t [α/α′] λ(α : κ).(t [α]) t if α ∈ fv(t)

10 / 14

slide-35
SLIDE 35

Guarded fixed points

Fixed point combinator

fixκ: (⊲κA → A) → A fixκf = f (nextκ(fixκf )) We need to restrict fixed point unfolding to obtain strong normalisation (while retaining canonicity).

11 / 14

slide-36
SLIDE 36

Guarded fixed points

Fixed point combinator

fixκ: (⊲κA → A) → A fixκf = f (nextκ(fixκf )) We need to restrict fixed point unfolding to obtain strong normalisation (while retaining canonicity).

Delayed fixed point

◮ dfixκ: (⊲κA → A) → ⊲κA ◮ only unfolds if applied to tick constant ⋄

(dfixκf ) [α]

  • f (dfixκf )

if α is tick variable (dfixκf ) [⋄] f (dfixκf )

11 / 14

slide-37
SLIDE 37

Tick constant

⋄ can only be used in a context without free

  • ccurrences of κ.

Γ ⊢∆,κ t : ⊲ (α : κ).A Γ ⊢∆ Γ ⊢∆,κ t [⋄] : A [⋄/α]

⋄ is used to implement force

force : ∀κ.⊲κA → ∀κ.A force x = Λκ.(x [κ]) [⋄]

12 / 14

slide-38
SLIDE 38

Tick constant

⋄ can only be used in a context without free

  • ccurrences of κ.

Γ ⊢∆,κ t : ⊲ (α : κ).A κ′ ∈ ∆ Γ ⊢∆ Γ ⊢∆ t [⋄] [κ′/κ] : A [⋄/α] [κ′/κ]

⋄ is used to implement force

force : ∀κ.⊲κA → ∀κ.A force x = Λκ.(x [κ]) [⋄]

12 / 14

slide-39
SLIDE 39

Results

Theorem (Decidable equality)

◮ Reduction relation

is confluent.

◮ Well-typed terms are strongly normalising.

13 / 14

slide-40
SLIDE 40

Results

Theorem (Decidable equality)

◮ Reduction relation

is confluent.

◮ Well-typed terms are strongly normalising.

Theorem (Canonicity)

If ⊢∆ t : Nat, then t

∗ suc n 0 for some n ∈ N.

13 / 14

slide-41
SLIDE 41

Results

Theorem (Decidable equality)

◮ Reduction relation

is confluent.

◮ Well-typed terms are strongly normalising.

Theorem (Canonicity)

If ⊢∆ t : Nat, then t

∗ suc n 0 for some n ∈ N.

Corollary (Productivity)

Given ⊢∆ t : Str, any element of the stream t can be computed with a finite number of reduction steps.

13 / 14

slide-42
SLIDE 42

Summary

Reduction semantics for dependent type theory with

◮ a universe ◮ guarded recursion ◮ multiple clocks & clock quantification

2Birkedal et al. Guarded cubical type theory: Path equality for

guarded recursion. CSL 2016

14 / 14

slide-43
SLIDE 43

Summary

Reduction semantics for dependent type theory with

◮ a universe ◮ guarded recursion ◮ multiple clocks & clock quantification

Future work

◮ identity types cubical type theory2 ◮ add propositional equalities (fixed point

unfolding, clock/tick irrelevance)

2Birkedal et al. Guarded cubical type theory: Path equality for

guarded recursion. CSL 2016

14 / 14

slide-44
SLIDE 44

The Clocks Are Ticking: No More Delays!

Reduction Semantics for Type Theory with Guarded Recursion Patrick Bahr1 Hans Bugge Grathwohl2 Rasmus Møgelberg1

1IT University of Copenhagen 2Aarhus University

slide-45
SLIDE 45

Bonus Slides

slide-46
SLIDE 46

Typing Rules

Γ ⊢∆,κ t : A Γ ⊢∆ Γ ⊢∆ Λκ.t : ∀κ.A Γ ⊢∆ t : ∀κ.A κ′ ∈ ∆ Γ ⊢∆ t[κ′] : A [κ′/κ] Γ, α : κ ⊢∆ t : A κ ∈ ∆ Γ ⊢∆ λ(α : κ).t : ⊲ (α : κ).A Γ ⊢∆ t : ⊲ (α : κ).A Γ, α′ : κ, Γ′ ⊢∆ Γ, α′ : κ, Γ′ ⊢∆ t [α′] : A [α′/α] Γ ⊢∆,κ t : ⊲ (α : κ).A Γ ⊢∆ κ′ ∈ ∆ Γ ⊢∆ (t [κ′/κ]) [⋄] : A [κ′/κ] [⋄/α] Γ ⊢∆ t : ⊲κA → A Γ ⊢∆ dfixκ t : ⊲κA

15 / 14

slide-47
SLIDE 47

Typing Rules (cont.)

Γ, x : A ⊢∆ t : B Γ ⊢∆ λ(x : A).t : Π(x : A). B Γ ⊢∆ t : Π(x : A). B Γ ⊢∆ u : A Γ ⊢∆ t u : B [u/x] Γ ⊢∆ F (dfixκ F) u : U Γ ⊢∆ t : El ((dfixκ F) [α] u) Γ ⊢∆ unfoldα t : El (F (dfixκ F) u) Γ ⊢∆ ((dfixκ F) [α]) u : U Γ ⊢∆ t : El (F (dfixκ F) u) Γ ⊢∆ foldα t : El ((dfixκ F) [α] u)

16 / 14

slide-48
SLIDE 48

Reduction Semantics

(λx : A.t)s t [s/x] (Λκ.t)[κ′] t [κ′/κ] (λ(α′ : κ).t) [α] t [α/α′] λ(α : κ).(t [α]) t (Λκ.t[κ]) t πi t1, t2 ti fold⋄t t unfold⋄t t if true t1 t2 t1 if false t1 t2 t2 rec (suc t1) t2 t3 t3 t1 (rec t1 t2 t3) rec 0 t s t (dfixκ t) [⋄] t (dfixκ t) t u C[t] C[u]

17 / 14