Streams and Coalgebra Lecture 1 Helle Hvid Hansen and Jan Rutten Radboud University Nijmegen & CWI Amsterdam Representing Streams II, Lorentz Center, Leiden, January 2014
Tutorial Overview Lecture 1 (Hansen): Coalgebra as a Unifying Theory of Systems Introduction and motivation Examples of systems. Universal coalgebra: basic concepts Lecture 2 (Hansen): The Coinduction Principle Coinductive proofs: Bisimulations Coinductive definitions: Behavioural differential equations Definition format: Syntactic method. Exercises (Hansen/Rutten). Lecture 3 (Rutten): Newton Series and Shuffle Product.
Coalgebra: Historical background Non-wellfounded set theory (Aczel 88, Barwise-Moss 96). Solving systems of equations, self-referentiality. E.g. x = {a, y} y = {x} Program semantics: solving recursive domain equations X = F (X ) (ordered spaces, metric spaces) Transition systems as coalgebras (Rutten 95), precursor of J. Rutten. Universal Coalgebra, a theory of systems, 2000. Growing community. Established subdiscipline of theoretical computer science: automata theory, program semantics, modal logic,... Coalgebraic Methods in Computer Science (CMCS). Conf. on Algebra and Coalgebra in Comp. Science (CALCO) also: LICS, FoSSaCS, ICALP, MFPS, POPL,...
Coalgebra General theory of state-based systems (black-box view). Abstract notion of observable behaviour. Developed parametric in system type. General definitions of morphism, behavioural equivalence, bisimulation,... (parametric in system type). Includes many familiar systems (streams, trees, automata, relations,...)
Algebra vs Coalgebra Coalgebra is dual to algebra, see e.g. B. Jacobs and J.J.M.M. Rutten. An introduction to (co)algebras and (co)induction, 2011 (1997).
Algebra vs Coalgebra Coalgebra is dual to algebra, see e.g. B. Jacobs and J.J.M.M. Rutten. An introduction to (co)algebras and (co)induction, 2011 (1997). algebra coalgebra well-founded structures non-well-founded structures construction observation syntax behaviour
Algebra vs Coalgebra Coalgebra is dual to algebra, see e.g. B. Jacobs and J.J.M.M. Rutten. An introduction to (co)algebras and (co)induction, 2011 (1997). algebra coalgebra well-founded structures non-well-founded structures construction observation syntax behaviour congruence bisimulation initiality finality induction coinduction
Algebra vs Coalgebra Coalgebra is dual to algebra, see e.g. B. Jacobs and J.J.M.M. Rutten. An introduction to (co)algebras and (co)induction, 2011 (1997). algebra coalgebra well-founded structures non-well-founded structures construction observation syntax behaviour congruence bisimulation initiality finality induction coinduction Algebra and coalgebra both fundamental to theoretical computer science, especially their interaction.
Motivation What can coalgebra do for you? Unifying theory: reveal common mathematical structure. New perspective on existing results. New results/generalisations via transfer using general perspective. Theorems and proofs for many system types in one go. Mathematical tool box: morphism, bisimulation, equivalence, modal logics,...
Some Examples Deterministic Systems with Output (DSO) Deterministic Automata with Output (DAO) (On the board) Remarks: State space can be infinite No initial state
Systems as Coalgebras DSO with output in B: DAO with output in B on alphabet A: Deterministic automaton on alphabet A: X B X X B X A X 2 X A
Systems as Coalgebras DSO with output in B: X B X DAO with output in B on alphabet A: X B X A Deterministic automaton on alphabet A: X 2 X A Kripke frame (relation): X P(X )
Systems as Coalgebras DSO with output in B: X B X DAO with output in B on alphabet A: X B X A Deterministic automaton on alphabet A: X 2 X A Kripke frame (relation): X P(X ) A-labelled transition system: X P(X ) A Nondeterministic automaton on alphabet A: X 2 P(X ) A
Systems as Coalgebras DSO with output in B: X B X DAO with output in B on alphabet A: X B X A Deterministic automaton on alphabet A: X 2 X A Kripke frame (relation): X P(X ) A-labelled transition system: X P(X ) A Nondeterministic automaton on alphabet A: X 2 P(X ) A Markov chains: X D(X )...
Systems as Coalgebras DSO with output in B: X B X DAO with output in B on alphabet A: X B X A Deterministic automaton on alphabet A: X 2 X A Kripke frame (relation): X P(X ) A-labelled transition system: X P(X ) A Nondeterministic automaton on alphabet A: X 2 P(X ) A Markov chains: X D(X )... F -coalgebra: X F (X ) F defines the system type Formally, F is a functor on a category...
Categories A category C consists of: a collection Ob(C) of objects, and a collection Ar(C) of arrows between objects: write: f : X Y or X f Y for f is an arrow from X to Y where X, Y Ob(C). Hom(X, Y ) is the collection of all arrows from X to Y. a composition of arrows Hom(X, Y ) Hom(Y, Z) Hom(X, Z), written g f for f : X Y, g : Y Z, such that (assoc) for all f : X Y, g : Y Z, h : Z U: h (g f ) = (h g) f (id) for all X Ob(C) there is an identity arrow id X : X X such that for all f : X Y : f id X = id Y f.
Categories A category C consists of: a collection Ob(C) of objects, and a collection Ar(C) of arrows between objects: write: f : X Y or X f Y for f is an arrow from X to Y where X, Y Ob(C). Hom(X, Y ) is the collection of all arrows from X to Y. a composition of arrows Hom(X, Y ) Hom(Y, Z) Hom(X, Z), written g f for f : X Y, g : Y Z, such that (assoc) for all f : X Y, g : Y Z, h : Z U: h (g f ) = (h g) f (id) for all X Ob(C) there is an identity arrow id X : X X such that for all f : X Y : f id X = id Y f.
Categories Examples: Set = sets and functions
Categories Examples: Set = sets and functions Mon = monoids and monoid morphisms Ring = rings and ring homomorphisms Top = topological spaces and continuous maps.
Categories Examples: Set = sets and functions Mon = monoids and monoid morphisms Ring = rings and ring homomorphisms Top = topological spaces and continuous maps. Rel = sets and relations, i.e., f : X Y means f X Y. (P, ) partially ordered set P: objects are elements x, y,... P, arrows: x y iff x y (arrows are unique).... Exercise: Show that these are indeed categories.
Functors between Categories A functor F from a category C to a category D (F : C D) associates objects and arrows from C with objects and arrows from D: (objects) X Ob(C) F (X ) Ob(D), (arrows) f : X Y Ar(C) F (f ): F (X ) F (Y ) Ar(D) s.t.: (id) F (id X ) = id F (X ) for all X Ob(C) and (comp) F (g f ) = F (g) F (f ) for all f : X Y, g : Y Z Ar(D). An (endo)functor on C (or C-functor) is a functor F : C C.
Functors between Categories Examples: Identity functor on C: X X, f f. Constant functor on C for some A Ob(C): X A, f id A.
Functors between Categories Examples: Identity functor on C: X X, f f. Constant functor on C for some A Ob(C): X A, f id A. Powerset functor on Set: X P(X ), f f [ ] (direct image).
Functors between Categories Examples: Identity functor on C: X X, f f. Constant functor on C for some A Ob(C): X A, f id A. Powerset functor on Set: X P(X ), f f [ ] (direct image). Forgetful functor from Mon to Set: (X,, 1) X, f f (underlying function). Free functor from Set to Mon: X X, f : X Y unique morphism f : X Y extending f. Monotonic maps on a partially ordered set (P, ). Exercise: Show that these are indeed functors.
Let F : C C be a functor on C. Category of F -coalgebras
Let F : C C be a functor on C. Category of F -coalgebras An F -coalgebra is an arrow γ : X F (X ) in Ar(C), also written as (X, γ). An F -coalgebra morphism f : (X, γ) (Y, δ) is an arrow f : X Y in Ar(C) such that F (f ) γ = δ f, i.e., the following diagram commutes: X f Y γ F (X ) F (f ) F (Y ) Coalg(F ) denotes the category of F -coalgebras and F -coalgebra morphisms. Exercise: Verify that Coalg(F ) is indeed a category. δ
Basic Constructions Assume F : Set Set. (All notions generalise). (X, γ) is a subcoalgebra of (Y, δ) if X Y and inclusion map X Y is coalgebra morphism, i.e., (X, γ) (Y, δ). (Y, δ) is a quotient of (X, γ) if there is f : (X, γ) (Y, δ). the coproduct of (X, γ) and (Y, γ) is (X + Y, φ) where γ X κ 1 X + Y φ κ 2 F (X ) F κ 1 F (X + Y ) F (Y ) where φ = [F κ 1 γ, F κ 2 δ]. F κ 2 Y δ
Coalgebraic Modelling of DSOs Deterministic systems with output in B are F -coalgebras for Set-functor F (X ) = B X. o, d : X B X Coalgebra morphisms: o γ,d γ X f Y B X id B f B Y o δ,d δ x X : o δ (f (x)) = o γ (x) d δ (f (x)) = f (d γ (x))
Coalgebraic Modelling of DSOs Deterministic systems with output in B are F -coalgebras for Set-functor F (X ) = B X. o, d : X B X Coalgebra morphisms: o γ,d γ X f Y B X id B f B Y o δ,d δ x X : o δ (f (x)) = o γ (x) d δ (f (x)) = f (d γ (x)) morphisms preserve output and transitions. subsystems are transition closed subsets. quotients identify states that are equivalent. coproducts are disjoint unions. observable behaviours are streams B ω.
Coalgebraic Modelling of DAOs DAOs (with output in B, alphabet A) are F -coalgebras for Set-functor F (X ) = B X A. Morphisms: X o γ,d γ f Y o δ,d δ B X A id B f A B Y A where f A : X A Y A h f h x X a A : o δ (f (x)) = o γ (x) d δ (f (x))(a) = f (d γ (x)(a)) (G(X ) = X A is a functor)
Coalgebraic Modelling of DAOs DAOs (with output in B, alphabet A) are F -coalgebras for Set-functor F (X ) = B X A. Morphisms: X o γ,d γ f Y o δ,d δ B X A id B f A B Y A x X a A : o δ (f (x)) = o γ (x) d δ (f (x))(a) = f (d γ (x)(a)) where f A : X A Y A (G(X ) = X A is a functor) h f h morphisms preserve output and transitions. subsystems are transition closed subsets. quotients identify states that are equivalent. coproducts are disjoint unions. observable behaviours are B-valued languages B A.
Final F -Coalgebra An F -coalgebra (Z, ζ) is final if for all F -coalgebras (X, γ) there is a unique F -coalgebra morphism h : (X, γ) (Z, ζ): X!h Z γ F (X ) F (h) F (Z) The unique morphism h : (X, γ) (Z, ζ) is called the behaviour map. We often write [[ ]] = h. Z is the collection of all behaviours of F -coalgebras. ζ
Final F -Coalgebra Facts Final F -coalgebra is unique up to isomorphism (in Coalg(F )). (We speak about the final F -coalgebra.) If (Z, ζ) is final, then ζ : Z = F (Z) is an isomorphism in C (Lambek s Lemma). Final F -coalgebras do not always exist. E.g. X = P(X ) for all sets X. But P ω (X ) = {U X card(u) finite} does have final coalgebra.
The Final DSO of Streams Streams B ω = {σ : N B} are a DSO with output in B: B ω B B ω σ σ(0), σ where σ(0) is initial value, head of σ, σ = (σ(1), σ(2), σ(3),...) is stream derivative, tail of σ.
The Final DSO of Streams Streams B ω = {σ : N B} are a DSO with output in B: B ω B B ω σ σ(0), σ where σ(0) is initial value, head of σ, σ = (σ(1), σ(2), σ(3),...) is stream derivative, tail of σ. o,d X B X [[ ]] id B [[ ]] B ω B B ω ( )(0),( ) x X : [[x]](0) = o(x) [[x]] = [[d(x)]] where behaviour map is x X : [[x]](n) = o(d n (x)) n N.
The Final DAO of Languages The set L = B A = {L: A B} of all B-valued languages over A is a DAO (with output in B, alphabet A) : λ : L B L A L L(ε), a L a where L a (w) = L(aw) for all w A (left language derivative).
The Final DAO of Languages The set L = B A = {L: A B} of all B-valued languages over A is a DAO (with output in B, alphabet A) : λ : L B L A L L(ε), a L a where L a (w) = L(aw) for all w A (left language derivative). X o,d B X A [[ ]] L λ id B [[ ]] A B L A x X, a A : [[x]](ε) = o(x) [[x]] a = [[d(x)(a)]] where behaviour map is: x X : [[x]](w) = o(d(x)(w)) w A.
The DAO of Streams The set B ω of streams is a DAO (with output in B, alphabet A).
The DAO of Streams The set B ω of streams is a DAO (with output in B, alphabet A). Case A = {1, 2, 3}. For all σ B ω and j {0, 1, 2}, let: unzip j,3 (σ)(n) = σ(j + 3n). Note that unzip 3 := unzip 0,3, unzip 1,3, unzip 2,3 : B ω = (B ω ) {1,2,3} with inverse zip 3 : (B ω ) {1,2,3} B ω.
The DAO of Streams The set B ω of streams is a DAO (with output in B, alphabet A). Case A = {1, 2, 3}. For all σ B ω and j {0, 1, 2}, let: unzip j,3 (σ)(n) = σ(j + 3n). Note that unzip 3 := unzip 0,3, unzip 1,3, unzip 2,3 : B ω = (B ω ) {1,2,3} with inverse zip 3 : (B ω ) {1,2,3} B ω. Take as DAO structure on B ω, β = B ω ( )(0),( ) B B ω id B unzip 3 = B (B ω ) {1,2,3} = Concretely, β : B ω B (B ω ) {1,2,3} σ σ(0), j unzip j 1,3 (σ )
The DAO of Streams By finality of (L, λ), there is unique h : (B ω, β) (L, λ).
The DAO of Streams By finality of (L, λ), there is unique h : (B ω, β) (L, λ). Concretely, h(σ)(w) = σ(ν(w)) w {1, 2, 3} where ν : {1, 2, 3} = N is bijective 3-adic numeration (least significant digit first, reverse). defined by: ν(ε) = 0, ν(aw) = a + 3 ν(w) ν(n) n ε 0 1 1 + 3 ν(ε) = 1 2 2 + 3 ν(ε) = 2 3 3 + 3 ν(ε) = 3 11 1 + 3 ν(1) = 4 21 2 + 3 ν(1) = 5 31 3 + 3 ν(1) = 6 12 1 + 3 ν(2) = 7..
The Final DAO of Streams ν bijective h : B ω L bijective h is DAO-isomorphism (B ω, β) is also final. X [[ ]] B ω o,d B X A id B [[ ]] {1,2,3} B (B ω ) {1,2,3} ( )(0),unzip 3 (( ) )
The Final DAO of Streams ν bijective h : B ω L bijective h is DAO-isomorphism (B ω, β) is also final. X [[ ]] B ω o,d For general k, B X A id B [[ ]] {1,2,3} B (B ω ) {1,2,3} ( )(0),unzip 3 (( ) ) Subcoalgebra σ generated by σ in (B ω, β) has as its states D(σ) = {σ(j + k e n) n N e 1 i=0 ki j e i=1 ki, e 1} {σ}. D(σ) finite iff k-kernel(σ) finite. σ is k-automatic iff σ is finite iff h(σ) is a regular language. σ is a minimal DAO that generates σ.
Summary Summary of today s lecture: Coalgebra is a uniform framework of state-based systems. Final coalgebras characterise observable behaviour. Streams and languages are final coalgebras. Coalgebraic perspective on automatic sequences via final DAO of streams. Next lecture: Coinduction proof principle (when are two states equivalent?) definition principle: behavioural differential equations
Coinduction Streams and Coalgebra Lecture 2 Helle Hvid Hansen and Jan Rutten Radboud University Nijmegen & CWI Amsterdam Representing Streams II, Lorentz Center, Leiden, January 2014
Coinduction Tutorial Overview Lecture 1 (Hansen): Coalgebra as a Unifying Framework Introduction and motivation Examples: Streams and languages Universal coalgebra: basic concepts Lecture 2 (Hansen): The Coinduction Principle Coinductive definitions: Behavioural differential equations Definition format: Syntactic method. Coinductive proofs: Bisimulations Exercises (Hansen/Rutten) Lecture 3 (Rutten): Newton Series and Shuffle Product
Coinduction Specifying Streams Methods: pointwise: σ(n) =..., n N fixed point of substitution φ: A A (morphic sequence) generated by deterministic automaton with output (DAO). Today: Coinduction (behavioural differential equations). Idea: Use universal property of final (Z, ζ) to define maps into Z. A final coalgebra yields a coinduction principle. Coinduction wrt final DSO (B ω, ( )(0), ( ) ). Coinduction wrt final DAO (B ω, ( )(0), unzip k ).
Coinduction Example: Binary operation on Streams Define a binary operation on streams B ω B ω B ω : B ω B ω o,d B (B ω B ω ) B ω B B ω ( )(0),( )
Coinduction Example: Binary operation on Streams Define a binary operation on streams B ω B ω B ω : B ω B ω o,d B (B ω B ω ) B ω B B ω ( )(0),( ) by taking as coalgebra structure on B ω B ω : σ, τ B ω, o(σ, τ) = σ(0), d(σ, τ) = τ, σ
Coinduction Example: Binary operation on Streams Define a binary operation on streams B ω B ω B ω : B ω B ω o,d B (B ω B ω ) zip id B zip B ω B B ω ( )(0),( ) by taking as coalgebra structure on B ω B ω : σ, τ B ω, o(σ, τ) = σ(0), d(σ, τ) = τ, σ Operation zip is defined by coinduction.
Coinduction Example: Binary operation on Streams Define a binary operation on streams B ω B ω B ω : B ω B ω o,d B (B ω B ω ) zip id B zip B ω B B ω ( )(0),( ) by taking as coalgebra structure on B ω B ω : σ, τ B ω, o(σ, τ) = σ(0), d(σ, τ) = τ, σ Operation zip is defined by coinduction. Commutativity of the diagram means that σ, τ B ω, zip(σ, τ)(0) = σ(0), zip(σ, τ) = zip(τ, σ ) (1) zip is a solution to the stream differential equation (SDE) (1).
Coinduction Behavioural Differential Equations (BDEs) Define elements of and operations on a final F -coalgebra (Z, ζ) by specifying the behavioural equations it must satisfy. More examples on N ω : σ = σ + σ, σ(0) = 0, σ (0) = 1 defines Fibonacci σ = (0, 1, 1, 2, 3, 5, 8,...). σ = σ + (σ σ), σ(0) = 1 defines σ = (1, 2, 6, 22, 90, 394, 1806, 8558, 41586,...) of (large) Schröder numbers (sequence A006318 in OEIS), cf. [Winter-Bonsangue-Rutten 12] (n σ) = n σ (n σ)(0) = n σ(0) n N defines scalar product.
Coinduction Example: Hamming Numbers Stream H N ω of Hamming numbers H = (1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, 16,...) consists of natural numbers of the form 2 i 3 j 5 k for i, j, k 0 in increasing order (cf. Dijkstra 81, Yuen 92).
Coinduction Example: Hamming Numbers Stream H N ω of Hamming numbers H = (1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, 16,...) consists of natural numbers of the form 2 i 3 j 5 k for i, j, k 0 in increasing order (cf. Dijkstra 81, Yuen 92). We define H by the following SDEs: H(0) = 1, H = (2 H) ((3 H) (5 H)) { σ(0) if σ(0) < τ(0) and (σ τ)(0) = τ(0) if σ(0) τ(0) σ τ if σ(0) < τ(0) (σ τ) = σ τ if σ(0) = τ(0) σ τ if σ(0) > τ(0) That is, merges two streams by taking smallest initial values first, and removing duplicates. Scalar product defined as before.
Coinduction Ensuring Unique Solutions SDEs as specification language for streams We want unique solutions. Do all SDEs have unique solutions?
Coinduction Ensuring Unique Solutions SDEs as specification language for streams We want unique solutions. Do all SDEs have unique solutions? σ(0) = 1, σ = σ has many solutions. even(σ)(0) = σ(0), even(σ) = even(σ ) has unique solution, even(σ) = (σ(0), σ(2), σ(4),...) but σ(0) = 1, σ = even(σ) has no unique solution. How can we guarantee unique solutions? When is a stream definition productive?
Coinduction A Syntactic Format for SDEs Signature Σ: collection of operation symbols with arities. E.g. (B ω = R ω operation [r], r R X + ) arity 0 0 2 1 2 T Σ (V ) = Σ-terms over (set of generators) V : T Σ (V ) t ::= v V [r], r R X t + t t t t
Coinduction A Syntactic Format for SDEs Signature Σ: collection of operation symbols with arities. E.g. (B ω = R ω operation [r], r R X + ) arity 0 0 2 1 2 T Σ (V ) = Σ-terms over (set of generators) V : T Σ (V ) t ::= v V [r], r R X t + t t t t Def. A stream definition for Σ is a set of SDEs, one for each Σ-operation f Σ of arity k of the form: f (σ 1,..., σ k )(0) = o f (σ 1 (0),..., σ k (0)) f (σ 1,..., σ k ) = d f (σ 1 (0),..., σ k (0)) where o f (σ 1 (0),..., σ k (0)) B d f (σ 1 (0),..., σ k (0)) T Σ (σ 1,..., σ k, σ 1,..., σ k ).
Coinduction A Syntactic Format for SDEs (II) Example: Stream definition for stream calculus signature: [r](0) = r, [r] = [0] r R X(0) = 0, X = [1] (σ + τ)(0) = σ(0) + τ(0), (σ + τ) = σ + τ ( σ)(0) = σ(0), ( σ) = σ (σ τ)(0) = σ(0) τ(0), (σ τ) = (σ τ) + ([σ(0)] τ ) Example: Definition of Hamming numbers. The syntactic format is also known as the stream GSOS format due to analogy with GSOS format from structural operational semantics (cf. [Bartels], [Klin], [Turi-Plotkin]). Generalisations for other coalgebra types immediate from categorical framework.
Coinduction A Syntactic Format for SDEs (III) Theorem: [Kupke-Niqui-Rutten 11][Bartels][Klin] Given a signature Σ, any Σ-definition in the stream GSOS format has a unique solution, i.e., defines a unique interpretation of operation symbols as stream operations. Proof sketch: A stream GSOS definition induces a coalgebra structure δ on terms: T Σ (B ω ) δ B T Σ (B ω ) α id B α B ω = B B ω By coinduction, we obtain a unique term interpretation α which corresponds to unique interpretation of Σ-operations.
Coinduction A Syntactic Format for SDEs (IV) Examples not in the stream GSOS format: c(0) = 1, c = c, since d c = c / T Σ ( ). even(σ) = σ(0), even(σ) = even(σ ), since even(σ ) / T Σ (σ, σ ). (Note: d(0) = 1, d = even(d) is in stream GSOS format.)
Coinduction A Syntactic Format for SDEs (IV) Examples not in the stream GSOS format: c(0) = 1, c = c, since d c = c / T Σ ( ). even(σ) = σ(0), even(σ) = even(σ ), since even(σ ) / T Σ (σ, σ ). (Note: d(0) = 1, d = even(d) is in stream GSOS format.) Remark on causal operations: All operations defined in the stream GSOS format are causal: The n th element of output stream f (σ 1,..., σ k ) is determined by the first n elements of the input streams σ 1,..., σ k. Operation even is not causal. Conversely, all causal stream operations can be defined by a (possibly infinite) stream GSOS definition (cf. [KNR 11]).
Coinduction Beyond Causality Endrullis,Grabmayer,Hendriks,Isihara & Klop. Productivity of stream definitions. Theor.Comp.Sci. 411, 2012. Ghani,Hancock & Pattinson. Representations of stream processors using nested fixed points. Logical Methods in Computer Science, 5(3), 2009. Abel & Pientka. Well-founded recursion with copatterns. Int. Conf. on Functional Programming (ICFP 2013).
Coinduction Coinduction wrt final DAO of Streams Recall the final DAO (output in B, alphabet A = {1, 2, 3}) of streams: β = ( )(0), unzip 3 (( ) ) : B ω B (B ω ) {1,2,3}
Coinduction Coinduction wrt final DAO of Streams Recall the final DAO (output in B, alphabet A = {1, 2, 3}) of streams: β = ( )(0), unzip 3 (( ) ) : B ω B (B ω ) {1,2,3} Behaviour map [[ ]]: (X, o, d ) (B ω, α) is coalgebra morphism: x X : [[x]](0) = o(x) unzip 0,3 ([[x]] ) = [[d(x)(1)]] unzip 1,3 ([[x]] ) = [[d(x)(2)]] unzip 2,3 ([[x]] ) = [[d(x)(3)]] using zip 3 unzip 3 = id B ω, this is equivalent with x X : [[x]](0) = o(x) [[x]] = zip 3 ([[d(x)(1)]], [[d(x)(2)]], [[d(x)(3)]])
Coinduction Zip-SDEs Example of a (finite) system of zip 3 -SDEs over X = {x, y, z} with B = {a, b}: x(0) = a, x = zip 3 (y, x, x), y(0) = b, y = zip 3 (x, y, x), z(0) = b, z = zip 3 (y, z, y), Every system of zip k -SDEs has a unique stream solution [[ ]]: X B ω. TFAE (cf. [Endrullis-Grabmayer-Hendriks-Klop-Moss 11]): σ B ω is k-automatic σ is in the solution to a finite system of zip k -SDEs.
Coinduction Stream Calculus Recall the SDEs defining stream calculus operations on R ω : [r](0) = r, [r] = [0] r R X(0) = 0, X = [1] (σ + τ)(0) = σ(0) + τ(0), (σ + τ) = σ + τ ( σ)(0) = σ(0), ( σ) = σ (σ τ)(0) = σ(0) τ(0), (σ τ) = (σ τ) + ([σ(0)] τ ) (R ω, +,,, 0, 1) is an integral domain. Fundamental theorem: σ = σ(0) + X σ for all σ R ω. Convolution inverse: σ 1 (0) = σ(0) 1, (σ 1 ) = (σ(0) σ ) σ 1 under condition σ(0) 0 (partial operation). We write: rσ = [r] σ, 1 σ = 1/σ = σ 1 and σ τ = σ τ 1.
Coinduction Polynomial and Rational Streams Polynomial stream σ = a 0 + a 1 X + a 2 X 2 + a 3 X 3 + + a n X n Rational stream σ = ρ π where ρ, π polynomial, and π(0) 0. Stream calculus operations will come back in several talks.
Coinduction How to prove stream identities? (R ω, +,,, 0, 1) is a commutative ring. Can we prove this using only the SDE definitions?
Coinduction Equivalence When are two systems the same? When their states encode the same set of behaviours. When do two states have the same behaviour? When [[x]] = [[y]].
Coinduction Equivalence When are two systems the same? When their states encode the same set of behaviours. When do two states have the same behaviour? When [[x]] = [[y]]. More generally, two states x (X, γ) and y (Y, δ) are behaviourally equivalent if there exist morphisms (X, γ) f g (Z, ζ) (Y, δ) such that f (x) = g(y). How do we prove it? We build a bisimulation.
Coinduction Coalgebraic Bisimulation Coalgebra morphism = structure-respecting function Coalgebra bisimulation = structure-respecting relation
Coinduction Coalgebraic Bisimulation Coalgebra morphism = structure-respecting function Coalgebra bisimulation = structure-respecting relation Def. (Aczel-Mendler) A bisimulation between F -coalgebras (X, γ) and (Y, δ) is a relation R X Y such that there is a coalgebra structure ρ: R F (R) such that the projections π X : (R, ρ) (X, γ) and π Y : (R, ρ) (Y, δ) are coalgebra morphisms: X γ F (X ) π X F (π X ) R ρ π Y Y F (π Y ) F (R) F (Y ) δ
Coinduction Bisimulation for DSOs Bisimulation diagram: X π X R π Y Y o X,d X B X id B π X ρ B R id B π Y B Y o Y,d Y Concretely: x, y R : o X (x) = o Y (y) and d X (x), d Y (y) R. Stream bisimulation (bisimulation on (B ω, ( )(0), ( ) ): σ, τ R : σ(0) = τ(0) and σ, τ R.
Coinduction Basic Facts about Bisimulations A map f : X Y is a coalgebra morphism f : (X, γ) (Y, δ) iff Graph(f ) = { x, f (x) x X } is a bisimulation. Bisimulations are closed under arbitrary unions. Hence the largest bisimulation ( bisimilarity, ) between two coalgebras exists: x y iff there is a bisimulation R s.t. x, y R. Coalgebra morphisms preserve bisimilarity: x y f (x) g(y) if f, g are coalgebra morphims. Bisimilarity on a single coalgebra is an equivalence relation. For all (X, γ) there is a coalgebra map γ : X / F (X / ) s.t. the quotient map q : X X / is a coalgebra morphism. Generalises existing notions from process theory and modal logic.
Coinduction Coinductive Proof Principle Let (Z, ζ) be a final F -coalgebra. id Z : (Z, ζ) (Z, ζ) is the unique F -coalgebra morphism. q Hence: (Z, ζ) (Z/, ζ )!h (Z, ζ) = id Z hence q is injective, and = Z (identity relation).
Coinduction Coinductive Proof Principle Let (Z, ζ) be a final F -coalgebra. id Z : (Z, ζ) (Z, ζ) is the unique F -coalgebra morphism. q Hence: (Z, ζ) (Z/, ζ )!h (Z, ζ) = id Z hence q is injective, and = Z (identity relation). A final coalgebra (Z, ζ) satisfies the Coinductive Proof Principle: x, y (Z, ζ) : x y x = y. By preservation of bisimilarity under morphisms, we have: For all x (X, γ) and y (Y, δ): x y [[x]] = [[y]]. A bisimulation is a proof of behavioural equivalence.
Coinduction Stream Bisimulation Example Prove that: σ + τ = τ + σ for all σ, τ B ω.
Coinduction Stream Bisimulation Example Prove that: σ + τ = τ + σ for all σ, τ B ω. Take R is a stream bisimulation: R = { σ + τ, τ + σ σ, τ B ω }. (σ + τ)(0) = σ(0) + τ(0) = τ(0) + σ(0) = (τ + σ)(0) (σ + τ) = σ + τ R τ + σ = (τ + σ)
Coinduction Stream Bisimulation Example Consider shuffle product defined by SDE (σ τ)(0) = σ(0) τ(0), (σ τ) = (σ τ) + (σ τ ) Prove that : σ τ = τ σ.
Coinduction Stream Bisimulation Example Consider shuffle product defined by SDE (σ τ)(0) = σ(0) τ(0), (σ τ) = (σ τ) + (σ τ ) Prove that : σ τ = τ σ. Compute: (σ τ) = (σ τ) + (σ τ ) (τ σ) = (τ σ) + (τ σ ) (σ τ) = ((σ τ) + (σ τ )) + ((σ τ ) + (σ τ ) (τ σ) = ((τ σ) + (τ σ )) + ((τ σ ) + (τ σ ) Problem: derivatives keep growing.
Coinduction Bisimulation-up-to Def. Let Σ denote a collection of stream operations. A relation R B ω B ω is a stream bisimulation-up-to-σ if for all σ, τ R: σ(0) = τ(0) and σ, τ R, where R B ω B ω is the smallest relation such that 1. R R 2. { σ, σ σ B ω } R 3. R is closed under the (element-wise application of) operations in Σ. For instance, if Σ contains addition and α, β, γ, δ R then α + γ, β + δ R. Lemma: If R is a bisimulation-up-to-σ then R is a bisimulation. (Bisimulation-up-to-Σ is sound)
Coinduction Bisimulation-up-to Example Back to commutativity of shuffle product: Observe: So is a bisimulation-up-to addition. (σ τ) = (σ τ) + (σ τ ) = (σ τ ) + (σ τ) (τ σ) = (τ σ) + (τ σ ) R = { σ τ, τ σ σ, τ R ω } Note: Symbolic reasoning, algorithmic. No knowledge of binomial coefficients needed.
Coinduction Summary Coalgebra is a uniform framework of state-based systems. final coalgebras characterise observable behaviour. final coalgebras yield a coinduction principle (proof and definition). Coinductive definitions are behavioural differential equations. streams are a final DSO stream differential eqs (SDEs). streams are a final DAO zip-sdes. stream GSOS format ensures unique solutions to SDEs. Coinductive proofs are bisimulations (up-to), circular proofs. can be constructed as a greatest fixed point.
Coinduction Selected Coalgebra References Universal Coalgebra: J.J.M.M. Rutten. Universal coalgebra: a theory of systems. Theoretical Computer Science, 249(1):380, 2000. B. Jacobs and J.J.M.M. Rutten. An introduction to (co)algebras and (co)induction. In: Advanced topics in bisimulation and coinduction, Cambridge Tracts in Theor. Comp. Science Volume 52, CUP 2011. Stream Differential Equations: J.J.M.M. Rutten. Behavioural differential equations: a coinductive calculus of streams, automata, and power series. Theoretical Computer Science Volume 308(1 3), pp. 1 53, 2003. C. Kupke, M. Niqui, J. Rutten. Stream Differential Equations: concrete formats for coinductive definitions. Technical Report No. RR-11-10, Oxford University, 2011. J. Winter, M. Bonsangue and J. Rutten. Coalgebraic characterizations of context-free languages. Logical Methods in Computer Science, Vol. 9 (3:14), 2013. H.H. Hansen, C. Kupke and J. Rutten. Stream differential equations, an overview. In preparation.
Coinduction Selected Coalgebra References Automatic Sequences: C. Grabmayer, J. Endrullis, D. Hendriks, J.W. Klop, and L.S. Moss. Automatic sequences and zip-specifications. Proceedings of LICS, 2012. C. Kupke and J. Rutten. On the final coalgebra of automatic sequences. Logic and Program Semantics, volume 7230 of LNCS, Springer, 2012. Automata and Formal Languages: F. Bonchi, M. Bonsangue, H.H. Hansen, P. Panangaden, J. Rutten, A. Silva. Algebra-coalgebra duality in Brzozowski s minimization algorithm. ACM Transactions on Computational Logic, to appear. A. Silva, F. Bonchi, M. Bonsangue, and J. Rutten. Generalizing determinization from automata to coalgebras. Logical Methods in Computer Science, 9(1), 2013. J. Rot, M. Bonsangue, J. Rutten. Coinductive Proof Techniques for Language Equivalence. 7th International Conference on Language and Automata Theory and Applications (LATA 2013). LNCS 7810, Springer.