Comodules over relative comonads for streams and infinite matrices - - PowerPoint PPT Presentation

comodules over relative comonads for streams and infinite
SMART_READER_LITE
LIVE PREVIEW

Comodules over relative comonads for streams and infinite matrices - - PowerPoint PPT Presentation

Comodules over relative comonads for streams and infinite matrices Benedikt Ahrens joint work with Rgis Spadotti Institut de Recherche en Informatique de Toulouse Universit Paul Sabatier CMCS 2014 B. Ahrens and R. Spadotti Comodules over


slide-1
SLIDE 1

Comodules over relative comonads for streams and infinite matrices

Benedikt Ahrens joint work with Régis Spadotti

Institut de Recherche en Informatique de Toulouse Université Paul Sabatier

CMCS 2014

  • B. Ahrens and R. Spadotti

Comodules over relative comonads 1/27

slide-2
SLIDE 2

Goal

  • Category-theoretic semantics of coinductive data types in

intensional Martin-Löf type theory (IMLTT) Develop a notion of “coalgebra” for the signature of a codata type

  • Incorporate canonical cosubstitution
  • B. Ahrens and R. Spadotti

Comodules over relative comonads 2/27

slide-3
SLIDE 3

Outline

1 Syntax: inductives and substitution 2 Homogeneous cosyntax: streams 3 Heterogeneous cosyntax: infinite triangular matrices

  • B. Ahrens and R. Spadotti

Comodules over relative comonads 3/27

slide-4
SLIDE 4

Outline

1 Syntax: inductives and substitution 2 Homogeneous cosyntax: streams 3 Heterogeneous cosyntax: infinite triangular matrices

  • B. Ahrens and R. Spadotti

Comodules over relative comonads 4/27

slide-5
SLIDE 5

Heterogeneous data types

Motivation: binding syntax in MLTT Lc : Type → Type x : X var(x) : Lc(X) s, t : LcX app(s, t) : LcX t : Lc(X + 1) abs(t) : LcX Heterogeneity of abs: recursive argument with bigger parameter X + 1 Substitution: substX,Y :

  • X → LcY
  • → LcX → LcY

Avoiding capture: shiftX,Y :

  • X → LcY
  • → X + 1 → Lc(Y + 1)
  • B. Ahrens and R. Spadotti

Comodules over relative comonads 5/27

slide-6
SLIDE 6

Initial semantics for binding syntax

Initial semantics for lambda calculus: Fiore, Plotkin & Turi ’99

  • characterizes not only data type but also substitution
  • reformulated using monads by Hirschowitz & Maggesi ’07

Basis for this reformulation: Lemma (Substitution is monadic: Altenkirch & Reus ’99) (Lc, var, subst) forms a monad (in Kleisli form)

  • B. Ahrens and R. Spadotti

Comodules over relative comonads 6/27

slide-7
SLIDE 7

Initial semantics for λ-calculus using monads

Definition (Algebra for signature of Lc, H & M ’07)

  • a monad (T, unit, bind) on Type
  • two morphisms of modules over T,

App : T × T → T Abs : T(_ + 1) → T

  • B. Ahrens and R. Spadotti

Comodules over relative comonads 7/27

slide-8
SLIDE 8

Initial semantics for λ-calculus using monads

Definition (Algebra for signature of Lc, H & M ’07)

  • a monad (T, unit, bind) on Type
  • two morphisms of modules over T,

App : T × T → T Abs : T(_ + 1) → T “Module morphism” expresses commutativity with bind: bind f ◦ App = App ◦ (bind f )2 bind f ◦ Abs = Abs ◦ bind (shift f )

  • B. Ahrens and R. Spadotti

Comodules over relative comonads 7/27

slide-9
SLIDE 9

Initial semantics for λ-calculus using monads

Definition (Algebra for signature of Lc, H & M ’07)

  • a monad (T, unit, bind) on Type
  • two morphisms of modules over T,

App : T × T → T Abs : T(_ + 1) → T “Module morphism” expresses commutativity with bind: bind f ◦ App = App ◦ (bind f )2 bind f ◦ Abs = Abs ◦ bind (shift f ) Lemma (Initial semantics for Lc, H & M ’07) (Lc, app, abs) is the initial algebra, where Lc = (Lc, var, subst)

  • B. Ahrens and R. Spadotti

Comodules over relative comonads 7/27

slide-10
SLIDE 10

Goal: characterize codata types with cosubstitution

Goal dualize techniques of H & M to characterize

  • codata types in intensional ML type theory with
  • cosubstitution

as terminal object In this talk

  • streams
  • infinite triangular matrices
  • B. Ahrens and R. Spadotti

Comodules over relative comonads 8/27

slide-11
SLIDE 11

Outline

1 Syntax: inductives and substitution 2 Homogeneous cosyntax: streams 3 Heterogeneous cosyntax: infinite triangular matrices

  • B. Ahrens and R. Spadotti

Comodules over relative comonads 9/27

slide-12
SLIDE 12

Streams over a base type

  • Streams = infinite lists over some base type A

a0 a1 a2 . . . head tail

  • Specified by destructors

s : StreamA headA(s) : A s : StreamA tailA(s) : StreamA

  • “Sameness” = bisimilarity in IMLTT

s ∼ s′ head(s) = head(s′) s ∼ s′ tail(s) ∼ tail(s′)

  • B. Ahrens and R. Spadotti

Comodules over relative comonads 10/27

slide-13
SLIDE 13

Structure on streams

  • (StreamA, ∼) is a setoid,

Stream : Type → Setoid

  • Canonical cosubstitution

cosubstA,B : (StreamA → B) → StreamA → StreamB is compatible with bisimilarity: cosubstA,B : Setoid(StreamA, eqB) → Setoid(StreamA, StreamB) with eq : Type → Setoid eq ⊣ forget

  • B. Ahrens and R. Spadotti

Comodules over relative comonads 11/27

slide-14
SLIDE 14

Structure on streams

Lemma (Stream, head, cosubst) is a comonad relative to eq : Type → Setoid. Definition (Relative (co)monad, Alten., Chapm. & Uust. ’10)

  • underlying functor is not necessarily endo
  • needs “mediating” functor (above: eq)
  • B. Ahrens and R. Spadotti

Comodules over relative comonads 12/27

slide-15
SLIDE 15

About the destructor tail

Morphisms of modules over monads characterize commutativity of substitution with constructors app : Lc × Lc → Lc subst f ◦ app = app ◦ (subst f )2 Morphisms of comodules over relative comonads characterize commutativity of cosubstitution with destructors tail : Stream → Stream tail ◦ cosubst f = cosubst f ◦ tail

  • B. Ahrens and R. Spadotti

Comodules over relative comonads 13/27

slide-16
SLIDE 16

Terminal semantics for Stream

Definition (Category of coalgebras) A coalgebra for the signature of Stream is given by a pair (S, t):

  • a comonad S relative to eq : Type → Setoid
  • a morphism of comodules over S

t : S → S Morphisms: . . . Lemma (Stream, tail) is the terminal object in the above category.

  • B. Ahrens and R. Spadotti

Comodules over relative comonads 14/27

slide-17
SLIDE 17

Outline

1 Syntax: inductives and substitution 2 Homogeneous cosyntax: streams 3 Heterogeneous cosyntax: infinite triangular matrices

  • B. Ahrens and R. Spadotti

Comodules over relative comonads 15/27

slide-18
SLIDE 18

An example of cosyntax: infinite triangular matrices

Tri: the codata type of infinite triangular matrices

  • omit redundant information below the diagonal
  • have a variable type A of diagonal elements
  • e.g. invertible elements
  • a fixed type E of elements for rest of matrix
  • usage: Pascal matrices (binomial coefficients),

mathematical physics (infinite-dim. problems) E E E E E E A A A A . . .

  • B. Ahrens and R. Spadotti

Comodules over relative comonads 16/27

slide-19
SLIDE 19

Matrices through trapezia: the destructors of Tri

t : TriA topA(t) : A t : TriA restA(t) : Tri(E × A) E E E E E E A A A A . . . E E E E E E A A A A E E E E . . .

  • B. Ahrens and R. Spadotti

Comodules over relative comonads 17/27

slide-20
SLIDE 20

Matrices through trapezia: the destructors of Tri

t : TriA topA(t) : A t : TriA restA(t) : Tri(E × A) E E E E E E A A A A . . . E E E E E E E×A E×A E×A E×A . . .

  • B. Ahrens and R. Spadotti

Comodules over relative comonads 17/27

slide-21
SLIDE 21

Redecoration

redecA,B : (TriA → B) → (TriA → TriB) E E E E E E A A A A . . . E E E E E E B B B B . . . f : TriA → B top ◦ redec f := f and rest ◦ redec f := redec (lift f ) ◦ rest with lift f : Tri(E × A) → E × B

  • B. Ahrens and R. Spadotti

Comodules over relative comonads 18/27

slide-22
SLIDE 22

Tri is a weak constructive comonad

Sameness = bisimilarity Bisimilarity ∼ coinductively defined via destructors t ∼ t′ top(t) = top(t′) t ∼ t′ rest(t) ∼ rest(t′) Lemma (Matthes and Picard ’11) (Tri : Type → Type, top, redec) forms a “weak constructive comonad”. “weak constructive” refers to compatibility conditions with bisimilarity

  • B. Ahrens and R. Spadotti

Comodules over relative comonads 19/27

slide-23
SLIDE 23

Tri is a relative comonad

Alternatively, TriA is a setoid rather than a (plain) type topA : Setoid(TriA, eqA) redecA,B : Setoid(TriA, eqB) → Setoid(TriA, TriB) with eq : Type → Setoid

  • B. Ahrens and R. Spadotti

Comodules over relative comonads 20/27

slide-24
SLIDE 24

Tri is a relative comonad

Alternatively, TriA is a setoid rather than a (plain) type topA : Setoid(TriA, eqA) redecA,B : Setoid(TriA, eqB) → Setoid(TriA, TriB) with eq : Type → Setoid Lemma (Reformulation of Matthes and Picard ’11) (Tri : Type → Setoid, top, redec) forms a comonad relative to eq : Type → Setoid.

  • B. Ahrens and R. Spadotti

Comodules over relative comonads 20/27

slide-25
SLIDE 25

(Co)modules over (relative) (co)monads

Morphisms of modules over monads characterize commutativity of substitution with constructors abs : Lc(_ + 1) → Lc subst f ◦ abs = abs ◦ subst (shift f ) Morphisms of comodules over relative comonads characterize commutativity of cosubstitution with destructors rest : Tri → Tri(E × _) rest ◦ redec f = redec (lift f ) ◦ rest

  • B. Ahrens and R. Spadotti

Comodules over relative comonads 21/27

slide-26
SLIDE 26

Coalgebras for the signature of Tri

Definition (Category of coalgebras) A coalgebra for the signature of Tri is given by a pair (T, r):

  • a comonad T relative to eq : Type → Setoid
  • a morphism of comodules over T

r : T → T(E × _) Morphisms: . . . Lemma (Tri, rest) is the terminal object in the above category. That’s almost how it works . . .

  • B. Ahrens and R. Spadotti

Comodules over relative comonads 22/27

slide-27
SLIDE 27

Technical difficulty: definition of lift

Definition of liftA : (TriA → B) → Tri(E × A) → E × B requires auxiliary function cutA : Tri(E × A) → TriA E E E E E E A A A . . . E × B id f cut

  • B. Ahrens and R. Spadotti

Comodules over relative comonads 23/27

slide-28
SLIDE 28

A specified cut for any coalgebra

  • we were not able to define cut categorically
  • fix: every coalgebra (T, r) comes with a specified

cA : T(E × A) → TA and equations characterizing c

  • cTri := cut for Tri uniquely determined by these equations

Lemma (for real this time) (Tri, cut, rest) is terminal in the category of coalgebras (T, c, r).

  • B. Ahrens and R. Spadotti

Comodules over relative comonads 24/27

slide-29
SLIDE 29

Formalization

Mechanization in the proof assistant Coq

  • helped to find a mistake we made (already made by Abel,

Matthes & Uustalu ’05)

  • reuses code by Matthes & Picard ’11
  • 3000 lines of code, among which 1500 by MP ’11
  • fully constructive and axiom-free
  • tedious: coinduction in Coq cumbersome
  • B. Ahrens and R. Spadotti

Comodules over relative comonads 25/27

slide-30
SLIDE 30

Summary

  • Coinductive type + bisimilarity as setoid in IMLTT
  • Stream and Tri are relative comonads
  • Develop comodules over relative comonads
  • Terminal coalgebra semantics for Stream and Tri
  • Bisimilarity and redecoration are part of universal object
  • Tri not as straightforward as the λ-calculus because of cut
  • Mechanization in Coq
  • B. Ahrens and R. Spadotti

Comodules over relative comonads 26/27

slide-31
SLIDE 31

Summary

  • Coinductive type + bisimilarity as setoid in IMLTT
  • Stream and Tri are relative comonads
  • Develop comodules over relative comonads
  • Terminal coalgebra semantics for Stream and Tri
  • Bisimilarity and redecoration are part of universal object
  • Tri not as straightforward as the λ-calculus because of cut
  • Mechanization in Coq

Thanks for your attention

  • B. Ahrens and R. Spadotti

Comodules over relative comonads 26/27

slide-32
SLIDE 32

Some references

Some references

  • Altenkirch, Chapman & Uustalu: Monads need not be

endofunctors

  • Hirschowitz & Maggesi: Modules over Monads and

Linearity

  • Matthes & Picard: Verification of Redecoration for Infinite

Triangular Matrices using Coinduction

  • preprint about this work on the arXiv

TikZ pictures used with permission from Matthes and Picard

  • B. Ahrens and R. Spadotti

Comodules over relative comonads 27/27