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
Goal • Category-theoretic semantics of co inductive 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
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
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
Heterogeneous data types Motivation: binding syntax in MLTT Lc : Type → Type s , t : Lc X t : Lc ( X + 1 ) x : X var ( x ) : Lc ( X ) app ( s , t ) : Lc X abs ( t ) : Lc X Heterogeneity of abs : recursive argument with bigger parameter X + 1 Substitution: � � subst X , Y : X → Lc Y → Lc X → Lc Y Avoiding capture: � � shift X , Y : X → Lc Y → X + 1 → Lc ( Y + 1 ) B. Ahrens and R. Spadotti Comodules over relative comonads 5/27
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
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
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 : App ◦ ( bind f ) 2 bind f ◦ App = bind f ◦ Abs = Abs ◦ bind ( shift f ) B. Ahrens and R. Spadotti Comodules over relative comonads 7/27
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 : App ◦ ( bind f ) 2 bind f ◦ App = 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
Goal: characterize co data types with co substitution Goal dualize techniques of H & M to characterize • co data types in intensional ML type theory with • co substitution as terminal object In this talk • streams • infinite triangular matrices B. Ahrens and R. Spadotti Comodules over relative comonads 8/27
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
Streams over a base type • Streams = infinite lists over some base type A . . . a 0 a 1 a 2 head tail • Specified by destructors s : Stream A s : Stream A head A ( s ) : A tail A ( s ) : Stream A • “Sameness” = bisimilarity in IMLTT s ∼ s ′ s ∼ s ′ head ( s ) = head ( s ′ ) tail ( s ) ∼ tail ( s ′ ) B. Ahrens and R. Spadotti Comodules over relative comonads 10/27
Structure on streams • ( Stream A , ∼ ) is a setoid , Stream : Type → Setoid • Canonical cosubstitution cosubst A , B : ( Stream A → B ) → Stream A → Stream B is compatible with bisimilarity: cosubst A , B : Setoid ( Stream A , eq B ) → Setoid ( Stream A , Stream B ) with eq : Type → Setoid eq ⊣ forget B. Ahrens and R. Spadotti Comodules over relative comonads 11/27
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
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 co modules over relative co monads characterize commutativity of co substitution with destructors tail : Stream → Stream tail ◦ cosubst f = cosubst f ◦ tail B. Ahrens and R. Spadotti Comodules over relative comonads 13/27
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
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
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) A E E E . . . A E E A E A B. Ahrens and R. Spadotti Comodules over relative comonads 16/27
Matrices through trapezia: the destructors of Tri A E E E t : Tri A . . . A E E top A ( t ) : A A E A E E E E t : Tri A A E E E rest A ( t ) : Tri ( E × A ) . . . A E E A E A B. Ahrens and R. Spadotti Comodules over relative comonads 17/27
Matrices through trapezia: the destructors of Tri A E E E t : Tri A . . . A E E top A ( t ) : A A E A E × A E E E t : Tri A E × A E E rest A ( t ) : Tri ( E × A ) . . . E × A E E × A B. Ahrens and R. Spadotti Comodules over relative comonads 17/27
Redecoration redec A , B : ( Tri A → B ) → ( Tri A → Tri B ) f : Tri A → B A E E E B E E E . . . . . . A E E B E E A E B E A 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
Tri is a weak constructive comonad Sameness = bisimilarity Bisimilarity ∼ coinductively defined via destructors t ∼ t ′ t ∼ t ′ top ( t ) = top ( 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
Tri is a relative comonad Alternatively, Tri A is a setoid rather than a (plain) type top A : Setoid ( Tri A , eq A ) redec A , B : Setoid ( Tri A , eq B ) → Setoid ( Tri A , Tri B ) with eq : Type → Setoid B. Ahrens and R. Spadotti Comodules over relative comonads 20/27
Tri is a relative comonad Alternatively, Tri A is a setoid rather than a (plain) type top A : Setoid ( Tri A , eq A ) redec A , B : Setoid ( Tri A , eq B ) → Setoid ( Tri A , Tri B ) 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
(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 co modules over relative co monads characterize commutativity of co substitution with destructors rest : Tri → Tri ( E × _ ) rest ◦ redec f = redec ( lift f ) ◦ rest B. Ahrens and R. Spadotti Comodules over relative comonads 21/27
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
Technical difficulty: definition of lift Definition of lift A : ( Tri A → B ) → Tri ( E × A ) → E × B requires auxiliary function cut A : Tri ( E × A ) → Tri A id E E E . . . A E E E × B cut A E A f B. Ahrens and R. Spadotti Comodules over relative comonads 23/27
Recommend
More recommend