Induction-Recursion Capretta University of A polymorphic - - PowerPoint PPT Presentation

induction recursion
SMART_READER_LITE
LIVE PREVIEW

Induction-Recursion Capretta University of A polymorphic - - PowerPoint PPT Presentation

Induction- Recursion A polymorphic representation Venanzio Induction-Recursion Capretta University of A polymorphic representation Nottingham IR definitions Leftist Heaps Venanzio Capretta Slice Categories University of Nottingham


slide-1
SLIDE 1

Induction- Recursion A polymorphic representation Venanzio Capretta University of Nottingham IR definitions Leftist Heaps Slice Categories Wander Types Conclusion Coda

Induction-Recursion A polymorphic representation

Venanzio Capretta University of Nottingham DTP 2011, Nijmegen

Venanzio CaprettaUniversity of Nottingham Induction-Recursion A polymorphic representation

slide-2
SLIDE 2

Induction- Recursion A polymorphic representation Venanzio Capretta University of Nottingham IR definitions Leftist Heaps Slice Categories Wander Types Conclusion Coda

IR definitions

Inductive-Recursive (IR) definitions

Venanzio CaprettaUniversity of Nottingham Induction-Recursion A polymorphic representation

slide-3
SLIDE 3

Induction- Recursion A polymorphic representation Venanzio Capretta University of Nottingham IR definitions Leftist Heaps Slice Categories Wander Types Conclusion Coda

IR definitions

Inductive-Recursive (IR) definitions Simultaneously define

an inductive type T : Set a recursive function on it f : T → D

mutually dependent

Venanzio CaprettaUniversity of Nottingham Induction-Recursion A polymorphic representation

slide-4
SLIDE 4

Induction- Recursion A polymorphic representation Venanzio Capretta University of Nottingham IR definitions Leftist Heaps Slice Categories Wander Types Conclusion Coda

IR definitions

Inductive-Recursive (IR) definitions Simultaneously define

an inductive type T : Set a recursive function on it f : T → D

mutually dependent

The constructors of T can use f

Venanzio CaprettaUniversity of Nottingham Induction-Recursion A polymorphic representation

slide-5
SLIDE 5

Induction- Recursion A polymorphic representation Venanzio Capretta University of Nottingham IR definitions Leftist Heaps Slice Categories Wander Types Conclusion Coda

IR definitions

Inductive-Recursive (IR) definitions Simultaneously define

an inductive type T : Set a recursive function on it f : T → D

mutually dependent

The constructors of T can use f f recursive over T

Venanzio CaprettaUniversity of Nottingham Induction-Recursion A polymorphic representation

slide-6
SLIDE 6

Induction- Recursion A polymorphic representation Venanzio Capretta University of Nottingham IR definitions Leftist Heaps Slice Categories Wander Types Conclusion Coda

IR definitions

Inductive-Recursive (IR) definitions Simultaneously define

an inductive type T : Set a recursive function on it f : T → D

mutually dependent

The constructors of T can use f f recursive over T

Definition of Type Universes [Martin-L¨

  • f 1984, Palmgren 1998]

General Definition [Dybjier 2001, Dybjier/Setzer 1999]

Venanzio CaprettaUniversity of Nottingham Induction-Recursion A polymorphic representation

slide-7
SLIDE 7

Induction- Recursion A polymorphic representation Venanzio Capretta University of Nottingham IR definitions Leftist Heaps Slice Categories Wander Types Conclusion Coda

Type Universes

U : Type

(large) type of codes for (small) types

Venanzio CaprettaUniversity of Nottingham Induction-Recursion A polymorphic representation

slide-8
SLIDE 8

Induction- Recursion A polymorphic representation Venanzio Capretta University of Nottingham IR definitions Leftist Heaps Slice Categories Wander Types Conclusion Coda

Type Universes

U : Type

(large) type of codes for (small) types

El : U → Type

decoding function, giving type of elements of codes

Venanzio CaprettaUniversity of Nottingham Induction-Recursion A polymorphic representation

slide-9
SLIDE 9

Induction- Recursion A polymorphic representation Venanzio Capretta University of Nottingham IR definitions Leftist Heaps Slice Categories Wander Types Conclusion Coda

Type Universes

U : Type

nat : U

El : U → Type

El nat = N

Venanzio CaprettaUniversity of Nottingham Induction-Recursion A polymorphic representation

slide-10
SLIDE 10

Induction- Recursion A polymorphic representation Venanzio Capretta University of Nottingham IR definitions Leftist Heaps Slice Categories Wander Types Conclusion Coda

Type Universes

U : Type

nat : U prod : U → U → U

El : U → Type

El nat = N El (prod a b) = (El a) × (El b)

Venanzio CaprettaUniversity of Nottingham Induction-Recursion A polymorphic representation

slide-11
SLIDE 11

Induction- Recursion A polymorphic representation Venanzio Capretta University of Nottingham IR definitions Leftist Heaps Slice Categories Wander Types Conclusion Coda

Type Universes

U : Type

nat : U prod : U → U → U sum : U → U → U

El : U → Type

El nat = N El (prod a b) = (El a) × (El b) El (sum a b) = (El a) + (El b)

Venanzio CaprettaUniversity of Nottingham Induction-Recursion A polymorphic representation

slide-12
SLIDE 12

Induction- Recursion A polymorphic representation Venanzio Capretta University of Nottingham IR definitions Leftist Heaps Slice Categories Wander Types Conclusion Coda

Type Universes

U : Type

nat : U prod : U → U → U sum : U → U → U arrow : U → U → U

El : U → Type

El nat = N El (prod a b) = (El a) × (El b) El (sum a b) = (El a) + (El b) El (arrow a b) = (El a) → (El b)

Venanzio CaprettaUniversity of Nottingham Induction-Recursion A polymorphic representation

slide-13
SLIDE 13

Induction- Recursion A polymorphic representation Venanzio Capretta University of Nottingham IR definitions Leftist Heaps Slice Categories Wander Types Conclusion Coda

Type Universes

U : Type

· · · pi : (a : U; b : El a → U) → U

El : U → Type

· · · El (pi a b) = Πx : El a.El (b x)

Venanzio CaprettaUniversity of Nottingham Induction-Recursion A polymorphic representation

slide-14
SLIDE 14

Induction- Recursion A polymorphic representation Venanzio Capretta University of Nottingham IR definitions Leftist Heaps Slice Categories Wander Types Conclusion Coda

Type Universes

U : Type

· · · pi : (a : U; b : El a → U) → U sig : (a : U; b : El a → U) → U

El : U → Type

· · · El (pi a b) = Πx : El a.El (b x) El (sig a b) = Σx : El a.El (b x)

Venanzio CaprettaUniversity of Nottingham Induction-Recursion A polymorphic representation

slide-15
SLIDE 15

Induction- Recursion A polymorphic representation Venanzio Capretta University of Nottingham IR definitions Leftist Heaps Slice Categories Wander Types Conclusion Coda

Advanced Data Structures

Heap (priority queue)

  • n ordered set A,

Venanzio CaprettaUniversity of Nottingham Induction-Recursion A polymorphic representation

slide-16
SLIDE 16

Induction- Recursion A polymorphic representation Venanzio Capretta University of Nottingham IR definitions Leftist Heaps Slice Categories Wander Types Conclusion Coda

Advanced Data Structures

Heap (priority queue)

  • n ordered set A,

Heap : Set

Venanzio CaprettaUniversity of Nottingham Induction-Recursion A polymorphic representation

slide-17
SLIDE 17

Induction- Recursion A polymorphic representation Venanzio Capretta University of Nottingham IR definitions Leftist Heaps Slice Categories Wander Types Conclusion Coda

Advanced Data Structures

Heap (priority queue)

  • n ordered set A,

Heap : Set empty : Heap isEmpty : Heap → B

Venanzio CaprettaUniversity of Nottingham Induction-Recursion A polymorphic representation

slide-18
SLIDE 18

Induction- Recursion A polymorphic representation Venanzio Capretta University of Nottingham IR definitions Leftist Heaps Slice Categories Wander Types Conclusion Coda

Advanced Data Structures

Heap (priority queue)

  • n ordered set A,

Heap : Set empty : Heap isEmpty : Heap → B insert : A → Heap → Heap

Venanzio CaprettaUniversity of Nottingham Induction-Recursion A polymorphic representation

slide-19
SLIDE 19

Induction- Recursion A polymorphic representation Venanzio Capretta University of Nottingham IR definitions Leftist Heaps Slice Categories Wander Types Conclusion Coda

Advanced Data Structures

Heap (priority queue)

  • n ordered set A,

Heap : Set empty : Heap isEmpty : Heap → B insert : A → Heap → Heap findMin : Heap → A

Venanzio CaprettaUniversity of Nottingham Induction-Recursion A polymorphic representation

slide-20
SLIDE 20

Induction- Recursion A polymorphic representation Venanzio Capretta University of Nottingham IR definitions Leftist Heaps Slice Categories Wander Types Conclusion Coda

Advanced Data Structures

Heap (priority queue)

  • n ordered set A,

Heap : Set empty : Heap isEmpty : Heap → B insert : A → Heap → Heap findMin : Heap → A deleteMin : Heap → Heap

Venanzio CaprettaUniversity of Nottingham Induction-Recursion A polymorphic representation

slide-21
SLIDE 21

Induction- Recursion A polymorphic representation Venanzio Capretta University of Nottingham IR definitions Leftist Heaps Slice Categories Wander Types Conclusion Coda

Advanced Data Structures

Heap (priority queue)

  • n ordered set A,

Heap : Set empty : Heap isEmpty : Heap → B insert : A → Heap → Heap findMin : Heap → A deleteMin : Heap → Heap merge : Heap → Heap → Heap

Venanzio CaprettaUniversity of Nottingham Induction-Recursion A polymorphic representation

slide-22
SLIDE 22

Induction- Recursion A polymorphic representation Venanzio Capretta University of Nottingham IR definitions Leftist Heaps Slice Categories Wander Types Conclusion Coda

Advanced Data Structures

Heap (priority queue)

  • n ordered set A,

Heap : Set empty : Heap isEmpty : Heap → B insert : A → Heap → Heap findMin : Heap → A deleteMin : Heap → Heap merge : Heap → Heap → Heap With lists: linear complexity With leftist heaps: logarithmic complexity

Venanzio CaprettaUniversity of Nottingham Induction-Recursion A polymorphic representation

slide-23
SLIDE 23

Induction- Recursion A polymorphic representation Venanzio Capretta University of Nottingham IR definitions Leftist Heaps Slice Categories Wander Types Conclusion Coda

Leftist Heaps

Definition of Leftist Heaps [Crane 1972, Knuth 1973]

Venanzio CaprettaUniversity of Nottingham Induction-Recursion A polymorphic representation

slide-24
SLIDE 24

Induction- Recursion A polymorphic representation Venanzio Capretta University of Nottingham IR definitions Leftist Heaps Slice Categories Wander Types Conclusion Coda

Leftist Heaps

Definition of Leftist Heaps [Crane 1972, Knuth 1973] Heaps are often implemented as heap-ordered trees, in which the element at each node is no larger than the elements at its children. Under this ordering, the minimum element in a tree is always at the root. Leftist heaps are heap-ordered binary trees that satisfy the leftist property: the rank of any left child is at least as large as the rank of its right sibling. The rank of a node is defined to be the length of its right spine (i.e., the rightmost path from the node in question to an empty node).

[Okasaki 1998] Venanzio CaprettaUniversity of Nottingham Induction-Recursion A polymorphic representation

slide-25
SLIDE 25

Induction- Recursion A polymorphic representation Venanzio Capretta University of Nottingham IR definitions Leftist Heaps Slice Categories Wander Types Conclusion Coda

Inductive-Recursive Leftist Heaps

lHeap : Set

Venanzio CaprettaUniversity of Nottingham Induction-Recursion A polymorphic representation

slide-26
SLIDE 26

Induction- Recursion A polymorphic representation Venanzio Capretta University of Nottingham IR definitions Leftist Heaps Slice Categories Wander Types Conclusion Coda

Inductive-Recursive Leftist Heaps

lHeap : Set rootor : lHeap → A → A

Venanzio CaprettaUniversity of Nottingham Induction-Recursion A polymorphic representation

slide-27
SLIDE 27

Induction- Recursion A polymorphic representation Venanzio Capretta University of Nottingham IR definitions Leftist Heaps Slice Categories Wander Types Conclusion Coda

Inductive-Recursive Leftist Heaps

lHeap : Set rootor : lHeap → A → A rank : lHeap → N

Venanzio CaprettaUniversity of Nottingham Induction-Recursion A polymorphic representation

slide-28
SLIDE 28

Induction- Recursion A polymorphic representation Venanzio Capretta University of Nottingham IR definitions Leftist Heaps Slice Categories Wander Types Conclusion Coda

Inductive-Recursive Leftist Heaps

lHeap : Set

leaf : lHeap

rootor : lHeap → A → A

rootor leaf = id

rank : lHeap → N

rank leaf = 0

Venanzio CaprettaUniversity of Nottingham Induction-Recursion A polymorphic representation

slide-29
SLIDE 29

Induction- Recursion A polymorphic representation Venanzio Capretta University of Nottingham IR definitions Leftist Heaps Slice Categories Wander Types Conclusion Coda

Inductive-Recursive Leftist Heaps

lHeap : Set

leaf : lHeap node : (a : A; t1, t2 : lHeap) → a (rootor t1 a) → a (rootor t2 a) → (rank t2) ≤ (rank t1) → lHeap

rootor : lHeap → A → A

rootor leaf = id

rank : lHeap → N

rank leaf = 0

Venanzio CaprettaUniversity of Nottingham Induction-Recursion A polymorphic representation

slide-30
SLIDE 30

Induction- Recursion A polymorphic representation Venanzio Capretta University of Nottingham IR definitions Leftist Heaps Slice Categories Wander Types Conclusion Coda

Inductive-Recursive Leftist Heaps

lHeap : Set

leaf : lHeap node : (a : A; t1, t2 : lHeap) → a (rootor t1 a) → a (rootor t2 a) → (rank t2) ≤ (rank t1) → lHeap

rootor : lHeap → A → A

rootor leaf = id rootor (node a t1 t2 . . .) = λx.a

rank : lHeap → N

rank leaf = 0

Venanzio CaprettaUniversity of Nottingham Induction-Recursion A polymorphic representation

slide-31
SLIDE 31

Induction- Recursion A polymorphic representation Venanzio Capretta University of Nottingham IR definitions Leftist Heaps Slice Categories Wander Types Conclusion Coda

Inductive-Recursive Leftist Heaps

lHeap : Set

leaf : lHeap node : (a : A; t1, t2 : lHeap) → a (rootor t1 a) → a (rootor t2 a) → (rank t2) ≤ (rank t1) → lHeap

rootor : lHeap → A → A

rootor leaf = id rootor (node a t1 t2 . . .) = λx.a

rank : lHeap → N

rank leaf = 0 rank (node a t1 t2 . . .) = 1 + rank t2

Venanzio CaprettaUniversity of Nottingham Induction-Recursion A polymorphic representation

slide-32
SLIDE 32

Induction- Recursion A polymorphic representation Venanzio Capretta University of Nottingham IR definitions Leftist Heaps Slice Categories Wander Types Conclusion Coda

Slice Category

Inductive Types: initial algebras in the base category.

Venanzio CaprettaUniversity of Nottingham Induction-Recursion A polymorphic representation

slide-33
SLIDE 33

Induction- Recursion A polymorphic representation Venanzio Capretta University of Nottingham IR definitions Leftist Heaps Slice Categories Wander Types Conclusion Coda

Slice Category

Inductive Types: initial algebras in the base category. IR Types: initial algebras in a slice category.

[Dybjer/Setzer 1999, Hancock/Ghani 2011] Venanzio CaprettaUniversity of Nottingham Induction-Recursion A polymorphic representation

slide-34
SLIDE 34

Induction- Recursion A polymorphic representation Venanzio Capretta University of Nottingham IR definitions Leftist Heaps Slice Categories Wander Types Conclusion Coda

Slice Category

Inductive Types: initial algebras in the base category. IR Types: initial algebras in a slice category.

[Dybjer/Setzer 1999, Hancock/Ghani 2011]

For every type D the slice category Set ↓ D has:

Venanzio CaprettaUniversity of Nottingham Induction-Recursion A polymorphic representation

slide-35
SLIDE 35

Induction- Recursion A polymorphic representation Venanzio Capretta University of Nottingham IR definitions Leftist Heaps Slice Categories Wander Types Conclusion Coda

Slice Category

Inductive Types: initial algebras in the base category. IR Types: initial algebras in a slice category.

[Dybjer/Setzer 1999, Hancock/Ghani 2011]

For every type D the slice category Set ↓ D has: Objects: pairs X, f where X : Set f : X → D

Venanzio CaprettaUniversity of Nottingham Induction-Recursion A polymorphic representation

slide-36
SLIDE 36

Induction- Recursion A polymorphic representation Venanzio Capretta University of Nottingham IR definitions Leftist Heaps Slice Categories Wander Types Conclusion Coda

Slice Category

Inductive Types: initial algebras in the base category. IR Types: initial algebras in a slice category.

[Dybjer/Setzer 1999, Hancock/Ghani 2011]

For every type D the slice category Set ↓ D has: Objects: pairs X, f where X : Set f : X → D Morphisms: functions g : X1, f1 → X2, f2 where g : X1 → X2 f2 ◦ g = f1

Venanzio CaprettaUniversity of Nottingham Induction-Recursion A polymorphic representation

slide-37
SLIDE 37

Induction- Recursion A polymorphic representation Venanzio Capretta University of Nottingham IR definitions Leftist Heaps Slice Categories Wander Types Conclusion Coda

Slice Category

Inductive Types: initial algebras in the base category. IR Types: initial algebras in a slice category.

[Dybjer/Setzer 1999, Hancock/Ghani 2011]

For every type D the slice category Set ↓ D has: Objects: pairs X, f where X : Set f : X → D Morphisms: functions g : X1, f1 → X2, f2 where g : X1 → X2 f2 ◦ g = f1 In the case of leftist heaps: D = (A → A) × N lHeap, rootor, rank object of Set ↓ D

Venanzio CaprettaUniversity of Nottingham Induction-Recursion A polymorphic representation

slide-38
SLIDE 38

Induction- Recursion A polymorphic representation Venanzio Capretta University of Nottingham IR definitions Leftist Heaps Slice Categories Wander Types Conclusion Coda

Slice Functors

A functor Θ : Set ↓ D → Set ↓ D has three components:

Venanzio CaprettaUniversity of Nottingham Induction-Recursion A polymorphic representation

slide-39
SLIDE 39

Induction- Recursion A polymorphic representation Venanzio Capretta University of Nottingham IR definitions Leftist Heaps Slice Categories Wander Types Conclusion Coda

Slice Functors

A functor Θ : Set ↓ D → Set ↓ D has three components:

Set part, for every X, f : F X f : Set

Venanzio CaprettaUniversity of Nottingham Induction-Recursion A polymorphic representation

slide-40
SLIDE 40

Induction- Recursion A polymorphic representation Venanzio Capretta University of Nottingham IR definitions Leftist Heaps Slice Categories Wander Types Conclusion Coda

Slice Functors

A functor Θ : Set ↓ D → Set ↓ D has three components:

Set part, for every X, f : F X f : Set Arrow part: e X f : F X f → D

Venanzio CaprettaUniversity of Nottingham Induction-Recursion A polymorphic representation

slide-41
SLIDE 41

Induction- Recursion A polymorphic representation Venanzio Capretta University of Nottingham IR definitions Leftist Heaps Slice Categories Wander Types Conclusion Coda

Slice Functors

A functor Θ : Set ↓ D → Set ↓ D has three components:

Set part, for every X, f : F X f : Set Arrow part: e X f : F X f → D Mapping: for every g : X1, f1 → X2, f2:

Θ g : F X1 f1 → F X2 f2 satisfying some equalities

Venanzio CaprettaUniversity of Nottingham Induction-Recursion A polymorphic representation

slide-42
SLIDE 42

Induction- Recursion A polymorphic representation Venanzio Capretta University of Nottingham IR definitions Leftist Heaps Slice Categories Wander Types Conclusion Coda

Slice Functors

A functor Θ : Set ↓ D → Set ↓ D has three components:

Set part, for every X, f : F X f : Set Arrow part: e X f : F X f → D Mapping: for every g : X1, f1 → X2, f2:

Θ g : F X1 f1 → F X2 f2 satisfying some equalities Note: No underlying functor on Set: F essentially depends on f

Venanzio CaprettaUniversity of Nottingham Induction-Recursion A polymorphic representation

slide-43
SLIDE 43

Induction- Recursion A polymorphic representation Venanzio Capretta University of Nottingham IR definitions Leftist Heaps Slice Categories Wander Types Conclusion Coda

Initial Slice Algebras

A Θ-algebra is a triple X, f , g X : Set f : X → D g : F X f , e X f → X, f The inductive-recursive pair is the initial Θ-algebra

Venanzio CaprettaUniversity of Nottingham Induction-Recursion A polymorphic representation

slide-44
SLIDE 44

Induction- Recursion A polymorphic representation Venanzio Capretta University of Nottingham IR definitions Leftist Heaps Slice Categories Wander Types Conclusion Coda

Initial Slice Algebras

A Θ-algebra is a triple X, f , g X : Set f : X → D g : F X f , e X f → X, f The inductive-recursive pair is the initial Θ-algebra How to represent ind-rec in a system (COQ) not supporting it?

Venanzio CaprettaUniversity of Nottingham Induction-Recursion A polymorphic representation

slide-45
SLIDE 45

Induction- Recursion A polymorphic representation Venanzio Capretta University of Nottingham IR definitions Leftist Heaps Slice Categories Wander Types Conclusion Coda

Second Order Encoding

Future Work: Second-order representation of induction recursion [VC 2004] Similar to polymorphic definition of (weak) inductive types:

[B¨

  • hm/Berarducci 1985, Girard 1989]

µΘ = ΠX, f : Set ↓ D.(ΘX, f → X, f ) The inductive-recursive type is the product of all Θ-algebras

[Also coinductive version, Wraith 1989, Geuvers 1992] Venanzio CaprettaUniversity of Nottingham Induction-Recursion A polymorphic representation

slide-46
SLIDE 46

Induction- Recursion A polymorphic representation Venanzio Capretta University of Nottingham IR definitions Leftist Heaps Slice Categories Wander Types Conclusion Coda

Second Order Encoding

Future Work: Second-order representation of induction recursion [VC 2004] Similar to polymorphic definition of (weak) inductive types:

[B¨

  • hm/Berarducci 1985, Girard 1989]

µΘ = ΠX, f : Set ↓ D.(ΘX, f → X, f ) The inductive-recursive type is the product of all Θ-algebras

[Also coinductive version, Wraith 1989, Geuvers 1992]

Better Way [Conor McBride] Inductive family indexed on the result of the function.

Venanzio CaprettaUniversity of Nottingham Induction-Recursion A polymorphic representation

slide-47
SLIDE 47

Induction- Recursion A polymorphic representation Venanzio Capretta University of Nottingham IR definitions Leftist Heaps Slice Categories Wander Types Conclusion Coda

Wander Types: Final Θ-algebra

Coinductive version of leftist heaps?

Venanzio CaprettaUniversity of Nottingham Induction-Recursion A polymorphic representation

slide-48
SLIDE 48

Induction- Recursion A polymorphic representation Venanzio Capretta University of Nottingham IR definitions Leftist Heaps Slice Categories Wander Types Conclusion Coda

Wander Types: Final Θ-algebra

Coinductive version of leftist heaps? Potentially infinite binary trees. But the rank function must still be defined. Right spine must be finite.

Venanzio CaprettaUniversity of Nottingham Induction-Recursion A polymorphic representation

slide-49
SLIDE 49

Induction- Recursion A polymorphic representation Venanzio Capretta University of Nottingham IR definitions Leftist Heaps Slice Categories Wander Types Conclusion Coda

Wander Types: Final Θ-algebra

Coinductive version of leftist heaps? Potentially infinite binary trees. But the rank function must still be defined. Right spine must be finite. Wander Types: Define a coinductive type and a recursive function simultaneously. Final coalgebras in slice categories

Venanzio CaprettaUniversity of Nottingham Induction-Recursion A polymorphic representation

slide-50
SLIDE 50

Induction- Recursion A polymorphic representation Venanzio Capretta University of Nottingham IR definitions Leftist Heaps Slice Categories Wander Types Conclusion Coda

Wander Types: Final Θ-algebra

Coinductive version of leftist heaps? Potentially infinite binary trees. But the rank function must still be defined. Right spine must be finite. Wander Types: Define a coinductive type and a recursive function simultaneously. Final coalgebras in slice categories Mixed Inductive-Coinductive Definitions [Anders/Altenkirch 2009]

Venanzio CaprettaUniversity of Nottingham Induction-Recursion A polymorphic representation

slide-51
SLIDE 51

Induction- Recursion A polymorphic representation Venanzio Capretta University of Nottingham IR definitions Leftist Heaps Slice Categories Wander Types Conclusion Coda

Mixed Induction-Coinduction

Streams 0s and 1s, with no infinite consecutive 1s.

Venanzio CaprettaUniversity of Nottingham Induction-Recursion A polymorphic representation

slide-52
SLIDE 52

Induction- Recursion A polymorphic representation Venanzio Capretta University of Nottingham IR definitions Leftist Heaps Slice Categories Wander Types Conclusion Coda

Mixed Induction-Coinduction

Streams 0s and 1s, with no infinite consecutive 1s.

CoInductive ZeroOne : Set

zero : ZeroOne → ZeroOne

  • ne : ZeroOne → ZeroOne

Venanzio CaprettaUniversity of Nottingham Induction-Recursion A polymorphic representation

slide-53
SLIDE 53

Induction- Recursion A polymorphic representation Venanzio Capretta University of Nottingham IR definitions Leftist Heaps Slice Categories Wander Types Conclusion Coda

Mixed Induction-Coinduction

Streams 0s and 1s, with no infinite consecutive 1s.

CoInductive ZeroOne : Set

zero : ZeroOne → ZeroOne

  • ne : ZeroOne → ZeroOne

Simultaneously count1 : ZeroOne → N

count1 (zero s) = 0 count1 (one s) = 1 + count1 s

Venanzio CaprettaUniversity of Nottingham Induction-Recursion A polymorphic representation

slide-54
SLIDE 54

Induction- Recursion A polymorphic representation Venanzio Capretta University of Nottingham IR definitions Leftist Heaps Slice Categories Wander Types Conclusion Coda

Mixed Induction-Coinduction

Streams 0s and 1s, with no infinite consecutive 1s.

CoInductive ZeroOne : Set

zero : ZeroOne → ZeroOne

  • ne : ZeroOne → ZeroOne

Simultaneously count1 : ZeroOne → N

count1 (zero s) = 0 count1 (one s) = 1 + count1 s

We can even make the zeros finite (still infinite sequences)

count0 : ZeroOne → N count0 (zero s) = 1 + count0 s count0 (one s) = 0

Venanzio CaprettaUniversity of Nottingham Induction-Recursion A polymorphic representation

slide-55
SLIDE 55

Induction- Recursion A polymorphic representation Venanzio Capretta University of Nottingham IR definitions Leftist Heaps Slice Categories Wander Types Conclusion Coda

No-zigzag type

Define a type of potentially infinite binary trees, but with the restriction that there can’t be infinite zigzags.

Venanzio CaprettaUniversity of Nottingham Induction-Recursion A polymorphic representation

slide-56
SLIDE 56

Induction- Recursion A polymorphic representation Venanzio Capretta University of Nottingham IR definitions Leftist Heaps Slice Categories Wander Types Conclusion Coda

No-zigzag type

Define a type of potentially infinite binary trees, but with the restriction that there can’t be infinite zigzags. CoInductive ZigZag : Set

Venanzio CaprettaUniversity of Nottingham Induction-Recursion A polymorphic representation

slide-57
SLIDE 57

Induction- Recursion A polymorphic representation Venanzio Capretta University of Nottingham IR definitions Leftist Heaps Slice Categories Wander Types Conclusion Coda

No-zigzag type

Define a type of potentially infinite binary trees, but with the restriction that there can’t be infinite zigzags. CoInductive ZigZag : Set Simultaneously zigs : ZigZag → N zags : ZigZag → N

Venanzio CaprettaUniversity of Nottingham Induction-Recursion A polymorphic representation

slide-58
SLIDE 58

Induction- Recursion A polymorphic representation Venanzio Capretta University of Nottingham IR definitions Leftist Heaps Slice Categories Wander Types Conclusion Coda

No-zigzag type

Define a type of potentially infinite binary trees, but with the restriction that there can’t be infinite zigzags. CoInductive ZigZag : Set Simultaneously zigs : ZigZag → N zags : ZigZag → N Constructors zzlf : ZigZag zznd : ZigZag → ZigZag → ZigZag

Venanzio CaprettaUniversity of Nottingham Induction-Recursion A polymorphic representation

slide-59
SLIDE 59

Induction- Recursion A polymorphic representation Venanzio Capretta University of Nottingham IR definitions Leftist Heaps Slice Categories Wander Types Conclusion Coda

No-zigzag type

Define a type of potentially infinite binary trees, but with the restriction that there can’t be infinite zigzags. CoInductive ZigZag : Set Simultaneously zigs : ZigZag → N zags : ZigZag → N Constructors zzlf : ZigZag zznd : ZigZag → ZigZag → ZigZag Equations zigs zzlf = 0 zigs (zznd t1 t2) = 1 + zags t1 zags zzlf = 0 zags (zznd t1 t2) = 1 + zigs t2

Venanzio CaprettaUniversity of Nottingham Induction-Recursion A polymorphic representation

slide-60
SLIDE 60

Induction- Recursion A polymorphic representation Venanzio Capretta University of Nottingham IR definitions Leftist Heaps Slice Categories Wander Types Conclusion Coda

Perspective

Induction-recursion: direct implementation of advanced

data types

Venanzio CaprettaUniversity of Nottingham Induction-Recursion A polymorphic representation

slide-61
SLIDE 61

Induction- Recursion A polymorphic representation Venanzio Capretta University of Nottingham IR definitions Leftist Heaps Slice Categories Wander Types Conclusion Coda

Perspective

Induction-recursion: direct implementation of advanced

data types

Realization by polymorphic quantification in slice category

Venanzio CaprettaUniversity of Nottingham Induction-Recursion A polymorphic representation

slide-62
SLIDE 62

Induction- Recursion A polymorphic representation Venanzio Capretta University of Nottingham IR definitions Leftist Heaps Slice Categories Wander Types Conclusion Coda

Perspective

Induction-recursion: direct implementation of advanced

data types

Realization by polymorphic quantification in slice category Coinductive version (Wander types) leads to a realization

  • f mixed induction-coinduction

Venanzio CaprettaUniversity of Nottingham Induction-Recursion A polymorphic representation

slide-63
SLIDE 63

Induction- Recursion A polymorphic representation Venanzio Capretta University of Nottingham IR definitions Leftist Heaps Slice Categories Wander Types Conclusion Coda

Perspective

Induction-recursion: direct implementation of advanced

data types

Realization by polymorphic quantification in slice category Coinductive version (Wander types) leads to a realization

  • f mixed induction-coinduction

Data with fine control on structural properties

Venanzio CaprettaUniversity of Nottingham Induction-Recursion A polymorphic representation

slide-64
SLIDE 64

Induction- Recursion A polymorphic representation Venanzio Capretta University of Nottingham IR definitions Leftist Heaps Slice Categories Wander Types Conclusion Coda

Stream Processors

Other example [Ghani/Hancock/Pattinson 2009] Continuous Stream Processors (Stream A) → (Stream B) represented by nested fixed points.

Venanzio CaprettaUniversity of Nottingham Induction-Recursion A polymorphic representation

slide-65
SLIDE 65

Induction- Recursion A polymorphic representation Venanzio Capretta University of Nottingham IR definitions Leftist Heaps Slice Categories Wander Types Conclusion Coda

Stream Processors

Other example [Ghani/Hancock/Pattinson 2009] Continuous Stream Processors (Stream A) → (Stream B) represented by nested fixed points. StrProc (A, B) : Set write : B → StrProc (A, B) → StrProc (A, B) read : (A → StrProc (A, B)) → StrProc (A, B) write coinductive, read inductive.

Venanzio CaprettaUniversity of Nottingham Induction-Recursion A polymorphic representation

slide-66
SLIDE 66

Induction- Recursion A polymorphic representation Venanzio Capretta University of Nottingham IR definitions Leftist Heaps Slice Categories Wander Types Conclusion Coda

Stream Processors

Other example [Ghani/Hancock/Pattinson 2009] Continuous Stream Processors (Stream A) → (Stream B) represented by nested fixed points. StrProc (A, B) : Set write : B → StrProc (A, B) → StrProc (A, B) read : (A → StrProc (A, B)) → StrProc (A, B) write coinductive, read inductive. eval : StrProc (A, B) → Stream A → Stream B eval (write b p) s = b : : eval p s eval (read f ) (a : : s) = eval (f a) s

Venanzio CaprettaUniversity of Nottingham Induction-Recursion A polymorphic representation

slide-67
SLIDE 67

Induction- Recursion A polymorphic representation Venanzio Capretta University of Nottingham IR definitions Leftist Heaps Slice Categories Wander Types Conclusion Coda

Simultaneous Coinductive-Recursive Definition

Coinductive StrProc (A, B) : Type

write : B → StrProc (A, B) → StrProc (A, B) read : (A → StrProc (A, B)) → StrProc (A, B)

Venanzio CaprettaUniversity of Nottingham Induction-Recursion A polymorphic representation

slide-68
SLIDE 68

Induction- Recursion A polymorphic representation Venanzio Capretta University of Nottingham IR definitions Leftist Heaps Slice Categories Wander Types Conclusion Coda

Simultaneous Coinductive-Recursive Definition

Coinductive StrProc (A, B) : Type

write : B → StrProc (A, B) → StrProc (A, B) read : (A → StrProc (A, B)) → StrProc (A, B)

Simultaneous readWf : StrProc (A, B) → Prop

readWf (write b s) = readWf (read f ) = ∀x : A.readWf (f x) That’s a large type. But alternatively ...

Venanzio CaprettaUniversity of Nottingham Induction-Recursion A polymorphic representation

slide-69
SLIDE 69

Induction- Recursion A polymorphic representation Venanzio Capretta University of Nottingham IR definitions Leftist Heaps Slice Categories Wander Types Conclusion Coda

Simultaneous Coinductive-Recursive Definition

Coinductive StrProc (A, B) : Set

write : B → StrProc (A, B) → StrProc (A, B) read : (A → StrProc (A, B)) → StrProc (A, B)

Simultaneous readTree : StrProc (A, B) → Tree A

readTree (write b s) = leaf readTree (read f ) = node (λx.readTree (f x)) (Tree A: well-founded A-branching trees.)

Venanzio CaprettaUniversity of Nottingham Induction-Recursion A polymorphic representation