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 R egis Spadotti joint work with Benedikt Ahrens Institut de Recherche en Informatique de Toulouse Universit e Paul Sabatier types 2014 B. Ahrens and R. Spadotti


slide-1
SLIDE 1

Comodules over relative comonads for streams and infinite matrices

R´ egis Spadotti joint work with Benedikt Ahrens

Institut de Recherche en Informatique de Toulouse Universit´ e Paul Sabatier

types 2014

  • B. Ahrens and R. Spadotti

Comodules over relative comonads 1/28

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/28

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/28

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/28

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/28

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/28

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/28

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/28

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/28

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 final object In this talk

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

Comodules over relative comonads 8/28

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/28

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

  • Propositional equality is not adequate for infinite object

bisimulation

  • B. Ahrens and R. Spadotti

Comodules over relative comonads 10/28

slide-13
SLIDE 13

Axioms for streams

  • Formation rules

Stream : Type → Type ∼ : StreamA → StreamA → Prop

  • Destructors

head, tail : StreamA → A × StreamA ∼head : s1 ∼ s2 → head s1 = head s2 ∼tail : s1 ∼ s2 → tail s1 ∼ tail s2

  • Coiterator

coiterT : (T → A × T) → T → StreamA bisimR : R ⊆ R on head, tail → R ⊆ ∼

  • Computation

head(coiterTf t) = π1(f t) tail(coiterTf t) ∼ coiterTf (π2(f t))

  • B. Ahrens and R. Spadotti

Comodules over relative comonads 11/28

slide-14
SLIDE 14

Axioms for streams

  • Formation rules

Stream : Type → Type ∼ : StreamA → StreamA → Prop

  • Destructors

head, tail : StreamA → A × StreamA ∼head : s1 ∼ s2 → head s1 = head s2 ∼tail : s1 ∼ s2 → tail s1 ∼ tail s2

  • Coiterator

coiterT : (T → A × T) → T → StreamA bisimR : R ⊆ R on head, tail → R ⊆ ∼

  • Computation

head(coiterTf t) = π1(f t) tail(coiterTf t) ∼ coiterTf (π2(f t)) Provable with Coq coinductive type definitions

  • B. Ahrens and R. Spadotti

Comodules over relative comonads 11/28

slide-15
SLIDE 15

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 12/28

slide-16
SLIDE 16

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 13/28

slide-17
SLIDE 17

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 14/28

slide-18
SLIDE 18

Final 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 final object in the above category.

  • B. Ahrens and R. Spadotti

Comodules over relative comonads 15/28

slide-19
SLIDE 19

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 16/28

slide-20
SLIDE 20

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 17/28

slide-21
SLIDE 21

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 18/28

slide-22
SLIDE 22

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 18/28

slide-23
SLIDE 23

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 19/28

slide-24
SLIDE 24

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 20/28

slide-25
SLIDE 25

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 21/28

slide-26
SLIDE 26

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 21/28

slide-27
SLIDE 27

(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 22/28

slide-28
SLIDE 28

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 final object in the above category. That’s almost how it works . . .

  • B. Ahrens and R. Spadotti

Comodules over relative comonads 23/28

slide-29
SLIDE 29

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 24/28

slide-30
SLIDE 30

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 final in the category of coalgebras (T, c, r).

  • B. Ahrens and R. Spadotti

Comodules over relative comonads 25/28

slide-31
SLIDE 31

Summary

  • Coinductive type + bisimilarity as setoid in IMLTT
  • Stream and Tri are relative comonads
  • Develop comodules over relative comonads
  • Final 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

Coinductive type ⇒ Axioms ⇒ Final object

  • B. Ahrens and R. Spadotti

Comodules over relative comonads 26/28

slide-32
SLIDE 32

Conclusion

Another line of work

  • Axioms ⇐

⇒ Final object ? Needs more general coalgebra Theorem Axioms for MA,B ⇐ ⇒ Final coalgebra for PA,B Future work M-types in Univalent Foundations

  • B. Ahrens and R. Spadotti

Comodules over relative comonads 27/28

slide-33
SLIDE 33

Conclusion

Another line of work

  • Axioms ⇐

⇒ Final object ? Needs more general coalgebra Theorem Axioms for MA,B ⇐ ⇒ Final coalgebra for PA,B Future work M-types in Univalent Foundations Thanks for your attention

  • B. Ahrens and R. Spadotti

Comodules over relative comonads 27/28

slide-34
SLIDE 34

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 28/28