graphical linear algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf ·...

179
Graphical Linear Algebra Pawel Sobocinski University of Southampton graphicallinearalgebra.net joint work with Filippo Bonchi, and Fabio Zanasi PhD Open, University of Warsaw important contributions from Dusko Pavlovic, Fabio Gadducci, Aleks Kissinger, Brendan Fong and Paolo Rapisarda

Upload: others

Post on 25-Aug-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Graphical Linear AlgebraPawel Sobocinski

University of Southampton

graphicallinearalgebra.net

joint work with Filippo Bonchi, and Fabio Zanasi

PhD Open, University of Warsaw

important contributions from Dusko Pavlovic, Fabio Gadducci, Aleks Kissinger, Brendan Fong and Paolo Rapisarda

Page 2: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

What will you get out of this?• An introduction to symmetric monoidal categories and diagrammatic reasoning, an important tool in

• quantum computing and quantum information (Abramsky, Coecke, Pavlovic, Duncan, Kissinger, …)

• asynchronous circuits (Ghica)

• signal flow graphs (Bonchi, S., Zanasi)

• linear time-invariant dynamical systems (Baez, Erbele, Fong, Rapisarda, S.)

• A different way to think about several concepts of linear algebra!

• linear algebra is everywhere (quantum, machine learning, systems and control theory, graph theory, …)

• a different language means different ways to think about applications, and it is sometimes more efficient than the classical concepts of matrices, bases, etc.

• a nice calculus for recurrence relations

• An introduction to several algebraic structures that are quite common in computational models

• e.g. monoids, comonoids, Frobenius monoids, bimonoids, Hopf algebras, …

Page 3: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

More generally: 2-dim syntax

• Ordinary, tree-like syntax, together with its operations (tuples, substitution) is good in situations where all operations have a coarity 1

• i.e. operations of the form Xn → X

• This often goes together with the implicit assumption that the resources in X are copyable and discardable

• In many situations (e.g. quantum, many kinds of circuits) we have to be more careful with resources — here tree-like syntax can be less natural

• the language of symmetric monoidal categories provides the algebra for this syntax

• the language of string diagrams provides a nice notation

Page 4: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

What I will not assume

• That you know about category theory

• we will introduce categorical notions only when needed

• we will concentrate, in particular, on the class of categories called strict symmetric monoidal categories

Page 5: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Plan• symmetric monoidal categories and string diagrams

• algebra of magic Lego

• categories

• monoidal categories

• string diagrams

• symmetric monoidal categories

• algebraic theories

• symmetric monoidal theories

• props

• theory of natural number matrices (bimonoids) and integer matrices (Hopf monoids)

• theory of linear relations (interacting Hopf monoids)

• distributive laws

• linear algebra, diagrammatically

• an application: generating functions and signal flow graphs

Page 6: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Algebra of magic Lego

� - stacking one on top of the other

=�

=�

associative but not commutative

; - plugging the first into the second

; =

; =

associative but not commutative

“stacking things and plugging them together”

Page 7: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Combining operations

�( ) ; �( ) =

� � =;( ( ))

Page 8: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

A simple type system: (2, 2) : (4, 4) : (2, 0)

X : (k, l) Y : (m,n)X�Y : (k+m, l+n)

X : (k, l) Y : (l,m)X;Y : (k,m)

number of holes number of studs

Page 9: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

The magic in magic LegoX : (k, l) Y : (m,n)X�Y : (k+m, l+n)

� =

X : (k, l) Y : (l,m)X;Y : (k,m)

; = ?

; =

Pieces stretch and shrink as needed — the only important thing is the type (number of holes, number of studs)

Page 10: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

The mathematics of magic Lego

• “stacking things on top of each other” and “plugging things together” are very common operations in science and mathematics

• the mathematical structure that’s behind these operations is called a (strict) monoidal category

• let’s start with categories…

Page 11: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Categories

• A category C, seen as a mathematical structure, consists of two sets: objects and arrows

• think of objects as types

• think of arrows as operations

• every arrow C has two associated objects k, m, called domain and codomain, written C : k → m

Page 12: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

• Every object has an identity arrow (think of this as a trivial “do-nothing” operation)

Ik : k → k

Page 13: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Operations on arrows

• There is a partial operation or arrows ; called composition

C : k → l D: l → mC ; D : k → m

— like the plugging in magic Lego

Page 14: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Associativity

• Composition is associative, i.e.

C : k → l D : l → m E : m → n (C ; D) ; E = C ; (D ; E) : k → n

Page 15: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Composing identities

• Composing with identity arrows on both sides does not change the arrow, i.e.

C : m → nIm ; C = C = C ; In

Page 16: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Examples of (small) categories

• 0 - the empty category

• 1 - the category with one object * and one arrow

• Exercise: check that everything works

• 2 - the category with objects {0,1}, one non-identity arrow 0 → 1.

• Exercise: check that everything works

• Any preorder is a category with

• objects the elements of X, and at most one arrow between any 2 objects: x→y iff x≤y.

• conversely, any category with at most one arrow from any object to another is a preorder.

Page 17: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Examples of (big) categories

• Set

• Objects: sets

• Arrows: functions

• Setf

• Objects: finite sets

• Arrows: functions

• Rel

• Objects: sets

• Arrows: relations

• Mon

• Objects: monoids

• Arrows: homomorphisms

• Top

• Objects: topological spaces

• Arrows: continuous functions

• Cat

• Objects: categories

• Arrows: functors

Page 18: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Monoidal categories• A (strict) monoidal category C, seen as a mathematical

structure, consists of two sets: objects and arrows

• think of objects as (products of) types

• think of arrows as operations

• every arrow C has two associated objects k, m, called domain and codomain, written C : k → m

• there is an associative operation on objects ⊕ called monoidal product

(k ⊕ m) ⊕ n = k ⊕ (m ⊕ n)

Page 19: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

• Every object has an identity arrow (think of this as a trivial “do-nothing” operation)

• There is an identity object I for monoidal product (think of this as a unit type). This makes the set of object a monoid.

Ik : k → k

k ⊕ I = I ⊕ k = k

Page 20: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Operations on arrows• There is a partial operation or arrows ; called

composition

• There is a total operation on arrows ⊕ (abusing notation) also called monoidal product.

C : k → l D: l → mC ; D : k → m

— like the plugging in magic Lego

C : k → l D: m → nC ⊕ D : k ⊕ m → l ⊕ n

— like the stacking in magic Lego

Page 21: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Associativity• Composition is associative, i.e.

• Monoidal product is associative also on arrows, i.e.

C : k → l D : l → m E : m → n (C ; D) ; E = C ; (D ; E) : k → n

C : m → n D : m’ → n’ E : m’’ → n’’ (C ⊕ D) ⊕ E = C ⊕ (D ⊕ E) : m⊕m’⊕m’’ → n⊕n’⊕n’’

Page 22: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Monoidal product and functoriality• The monoidal product is actually a functor, a morphism of categories

• Functors consist of two functions, one each for objects and arrows, and preserve domains and codomains (c.f. morphism of digraphs)

• as well as composition and identities

F: X → Y

C : m → nF(C) : F(m) → F(n)

F(C ; D) = F(C) ; F(D) F(Ik) = IF(k)

Page 23: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

How is monoidal product a functor?• A monoid is a set M equipped with a function

• … with a unit element, satisfying associativity

• Similarly, a strict monoidal category is a category C equipped with a functor

• … with a unit object, satisfying associativity

⋅ : M × M → M

⊕ : C × C → C

(M×M is the cartesian product of sets)

(C×C is the cartesian product of categories)

Page 24: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

• Suppose that C and D are categories. How do we define of the cartesian product C×D of C and D?

• What are the objects?

• What are the arrows?

• How does composition work?

• What are the identity arrows?

Exercise

Page 25: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Monoidal product and composition

• Suppose that A can be composed with C, and B can be composed with D. Then since ⊕, being a functor, preserves composition, we have:

⊕(A;B, C;D) = ⊕( (A,C) ; (B,D) ) = ⊕(A,C) ; ⊕(B,D)

i.e.

(A ; B) ⊕ (C ; D) = (A ⊕ C) ; (B ⊕ D)

This equation is sometimes called “middle-four interchange”

Page 26: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Exercise

• Suppose that A: p →q and B: r → s. Show that

( A ⊕ Ir ) ; (Iq ⊕ B) = A ⊕ B = (Ip ⊕ B) ; (Is ⊕ A)

Page 27: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Composing identities

• Since ⊕ must preserve identities, we also require

⊕(I(m,n)) = ⊕(Im, In) = Im⊕n i.e.

Im ⊕ In = Im⊕n

C: m → nIm ; C = C = C ; In

• Composing with identity arrows on both sides does not change the arrow, i.e.

Page 28: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Examples of monoidal categories• Setf with × (cartesian product) or with + (disjoint union) as monoidal product

• it’s not quite strict… e.g. monoidal product is not associative on the nose

• it is a (non-strict) monoidal category, where associativity is up to coherent isomorphism

• F - the strict monoidal version of Setf

• Objects: finite ordinals m := {1,2,…,m}

• Arrows: functions

• Monoidal product 1: disjoint union, on objects m + n := m + n

• what is the monoidal identity object?

• how to define monoidal product on morphisms?

• Monoidal product 2: cartesian product, on objects m × n := m × n

• what is the monoidal identity object?

• how to define monoidal product on morphisms?

Page 29: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Magic Lego

• Is a monoidal category with

• Objects: natural numbers (keeping track of numbers of holes and studs)

• Arrows: lego constructions

Page 30: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

String diagrams• A graphical notation for the arrows of monoidal

categories

• We have been writing C: m → n

• We will now draw

Cm n

Page 31: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Composition

C : k → l D: l → mC ; D : k → m

Ck l

Dm

Page 32: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Monoidal productC : k → l D: m → nC ⊕ D : k ⊕ m → l ⊕ n

Ck l

mD

n

Page 33: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Perks of the notation I

C : k → l D : l → m E : m → n (C ; D) ; E = C ; (D ; E) : k → n

k l mC D E n

Page 34: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Perks of the notation IIC : m → n D : m’ → n’ E : m’’ → n’’

(C ⊕ D) ⊕ E = C ⊕ (D ⊕ E) : m ⊕ m’⊕ m’’ → n ⊕ n’⊕ n’’

C

D

E

m

m'

m''

n

n'

n''

Page 35: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Perks of the notation III

(A ; B) ⊕ (C ; D) = (A ⊕ C) ; (B ⊕ D)

A B

C D

Page 36: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Diagrammatic reasoning I• Identity on m is simply drawn as a wire

Stretching

m

C : m → nIm ; C = C = C ; In

= C =C Cm n m n m n

Page 37: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Diagrammatic reasoning II

( A ⊕ Ir ) ; (Iq ⊕ B) = A ⊕ B = (Ip ⊕ B) ; (Is ⊕ A)

Sliding

A

B

= =

A

B

A

B

p q

r s

p q

r s

p q

r s

Page 38: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

General story• A strict monoidal category is the same thing as a 2-category with one

object, a particularly simple kind of higher category

• string diagrams are a kind of graph theoretical dual, i.e.

• zero dimensional things (objects) become two dimensional things

• one dimensional things (arrows in a 2-cat = objects in a strict monoidal cat) stay as one dimensional things — wires

• two dimensional things (2-cells in a 2-cat = arrows in a strict monoidal cat) become zero dimensional things (points, or boxes as we have been drawing)

• See Globular (Vicary, Kissinger, Bar): http://globular.science

Page 39: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Symmetric monoidal categories• When wiring things up using the algebra of

connecting and stacking, we often want to permute the wires

• Mathematically, this means moving from monoidal categories to symmetric monoidal categories

• In a symmetric monoidal category, for any two objects m, n, there is a symmetry, or twist

twm,n: m⊕n → n⊕m

Page 40: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Example - Crema di MascarponeCrack Egg

eggyolk

white

Whisk

white

white

whisked whites

yolk

yolk

sugar

Beatyolky paste

yolky paste

mascarpone

Stirthick paste

whisked whites

thick paste

Foldcrema di mascarpone

Crack Eggegg

white

yolk

Crack Eggegg

white

yolkBeat

Whiskwhisked whites

thickpaste

mascarpone

Stir

crema di mascarpone

sugar

Fold

yolkypaste

Page 41: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Example - Crema di MascarponeCrack Egg

eggyolk

white

Whisk

white

white

whisked whites

yolk

yolk

sugar

Beatyolky paste

yolky paste

mascarpone

Stirthick paste

whisked whites

thick paste

Foldcrema di mascarpone

Crack Eggegg

white

yolk

Crack Eggegg

white

yolkBeat

Whiskwhisked whites

thickpaste

mascarpone

Stir

crema di mascarpone

sugar

Fold

yolkypaste

(C � C � id2) ; (id� tw � id3) ; (W �B � id) ; (id� S) ; F

Page 42: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Natural transformations• We have seen categories, and functors: morphisms between categories

• A natural transformation is a morphism between functors

• A natural transformation α : F ⇒ G is a collection of arrows of Y, one for each object in m ∈ X

• These must satisfy a condition with respect to the arrows of X, namely for each arrow C: m→n

F ⇒ G: X → Y

αm : Fm → Gm

Fm Gm

Fn GnFC GC

αm

αn

commutes. These are sometimes called naturality squares

Page 43: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Aside — string diagrams for Cat • Cat is a 2-category

• Objects (0-morphisms): categories

• Arrows (1-morphisms): functors

• 2-cells (2-morphisms): natural transformations

• Suppose that F: C→D has right adjoint G: D→C, then the triangle equations can be drawn as follows, using string diagrams:

η

ε

F

G

F=

F

η

ε

G

F

G

= G

F FGFFη

FεF

G GFGηG

GεG

Page 44: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Symmetry as natural transformation

• For a monical category C, there are actually two functors C×C → C given by ⊕

• tw is a natural transformation from the first to the second, with components twm,n : m⊕n→ n⊕m

⊕ = –1⊕–2: C×C → C ⊕’ = –2⊕–1: C×C → C

– stack the first on the second

– stack the second on the first

Page 45: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Drawing twists

twm,n: m⊕n → n⊕m

m

mn

n

Page 46: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Diagrammatic reasoning III

p⊕n n⊕p

q⊕n n⊕qC⊕n n⊕C

twp,n

twq,n

C

n

np

q Cn

np

q=

naturality = sliding across twists

m⊕p p⊕m

m⊕q q⊕mm⊕C C⊕m

twm,p

twm,q

Cp

qm

m

C

p

qm

m

=

Page 47: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Diagrammatic reasoning IV

• In any symmetric monoidal category, the twist is invertible, and has itself as inverse, in the following sense

tightening (without wires tangling)

twm,n ; twn,m= Im⊕n : m⊕n → m⊕n

=

m

m

m

n

n

n

m

n

In a braided monoidal category, the twist is invertible, but it is not, in general, it’s own inverse

Page 48: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Symmetric monoidal categories

• A strict symmetric monoidal category C, is a strict monoidal category with a natural family of arrows twm,n : m⊕n → n⊕m, indexed by pairs of objects of C, such that

twm,n ; twn,m= Im⊕n : m⊕n → m⊕n

twm⊕n, p = (Im ⊕ twn,p) ; (twp,m ⊕ In): m⊕n⊕p→ p⊕m⊕n twp, m⊕n = (twp,m ⊕ In); (Im ⊕ twp,n): p⊕m⊕n→ m⊕n⊕p

twI,m = Im = twm,I

Page 49: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

• Exercise: The famous Yang-Baxter equation is an instance of naturality of the twist

• tegether with

Yang-Baxter

=

=

we get that “pure” wiring diagrams t⊕m → t⊕m are in 1-1 correspondence with permutations of the m-element set

Page 50: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

The category of permutations

• Objects: finite ordinals m = {1,…,m}

• Arrows: no arrows from m to n if m≠n, otherwise the permutations

• Strict symmetric monoidal, with m⊕n := m+n

Page 51: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Algebraic theories• An algebraic theory is a pair (Σ, E) where

• Σ is a set of generators (or operations), each with an arity, a natural number

• E is a set of equations (or relations), between Σ-terms built up from generators and variables

Example 1 - monoids Example 2 - abelian groups

ΣM = { ⋅:2, e:0 } EM = { ⋅( ⋅(x, y), z ) = ⋅( x, ⋅(y, z) ),

⋅(x, e) = x, ⋅(e, x) = x }

ΣG = ΣM ∪ { i:1 } EG = EM ∪ { ⋅(x, y) = ⋅(y, x),

⋅(x, i(x)) = e }

Universal Algebra

Page 52: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Σ - terms (cartesian)

x ∈ Varx

t1 t2 … tm σ ∈ Σ ar(σ) = mσ(t1, t2, …, tm)

i.e. terms a trees with internal nodes labelled by the generators and the leaves labelled by variables

Page 53: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Models - classically• To give a model of an algebraic theory, choose a set X

• for each operation σ : k in Σ, choose a function [[σ]] : Xk → X

• now for each term t, given an assignment of variables α, we can recursively compute the element of [[t]]α ∈ X which is the “meaning” of t

• We need to ensure that for every assignment of variables α, and every equation t1 = t2 in E, we have [[t1]]α = [[t2]]α as elements of X

• To give a model of the algebraic theory of monoids is to give a monoid

• To give a model of the theory of abelian groups is to give an abelian group

• etc..

Page 54: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Algebraic theories, categorically

• There is a nice way to think of algebraic theories categorically, due to Lawvere in the 1960s

• get rid of “countably infinite set of variables”, “variable assignments” etc.

• relies on the notion of categorical product

Page 55: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Categorical product• Suppose that X, Y are objects in a category C. Then X and Y have a

product if ∃ object X×Y and arrows π1: X×Y → X, π2: X×Y → Y so that the following universal property holds

• Example: in the category Set of sets and functions, the cartesian product satisfies the universal property

• Any category with (binary) categorical products is monoidal, with the categorical product as monoidal product

X×Y

Z

X Yπ1 π2

f gh

for any object Z and arrows f: Z → X, g: Z → Y,

∃ unique h: Z → X×Y s.t. h ; π1 = f and h ; π2 = g

Page 56: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

• If X is a preorder, considered as a category, what does it mean if X has (binary) categorical products?

• In Set, the categorical product is the cartesian product

• What is the product in the category of categories and functors?

• What is the product in the category of monoids and homomorphisms?

Exercise

Page 57: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Lawvere categories• Suppose that (Σ, E) is an algebraic theory

• Define a category L(Σ,E) with

• Objects: natural numbers

• Arrows from m to n: n tuples of Σ-terms, each using possibly m variables x1, x2, …, xm, modulo the equations of E

• Composition is substitution

Examples in the theory of monoids

2 1

It is also possible (and elegant) to view L(Σ,E) as the free category with products on the data

specified in (Σ,E)

(x1⋅x2) 2 1(x2⋅x1)

1 1(x1⋅e) = 1 1(x1)

Page 58: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

• Lawvere categories have (binary) categorial products: m×n := m+n.

Q1. What are the projections?

• In any category with binary products there is a canonical arrow Δ: X→X×X called the diagonal.

Q2. How is it defined?

Q3. What is L(∅,∅)? Can you find a simple way of describing it?

Exercise

Page 59: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Models categorically (Functorial semantics)

• A functor F: C → D is product-preserving if

F(X×Y) = F(X) × F(Y)

• Theorem. To give a model of (Σ,E) is to give a product-preserving functor F: L(Σ,E) → Set

Proof idea: since m = 1+1+…+1 (m times), to give a product preserving functor F from L(Σ,E) it is enough to say what F(1) is.

• By changing Set to other categories, we obtain a nice generalisation of classical universal algebra, with examples such as topological groups, etc.

Page 60: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Limitations of algebraic theories

• Copying and discarding built in

• But in computer science (and elsewhere), we often need to be more careful with resources

• Consequently, there are also no bona fide operations with coarities other than one

1 2(x1, x1)2 1(x1) 2 1(x2)

1 2c = 1 2

(c1,c2)

Page 61: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Symmetric monoidal theories

• Most of our work will concern symmetric monoidal theories (SMTs) which give rise to special kinds of symmetric monoidal categories called props

• Symmetric monoidal theories generalise algebraic theories, a classical concept of universal algebra, but

• No built in copying and discarding

• Able to consider operations with coarities other than 1

Page 62: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Symmetric monoidal theories

• A symmetric monoidal theory is a pair (Σ, E) where

• Σ is a set of generators (or operations), each with an arity, and coarity, both natural numbers

• E is a set of equations (or relations), between compatible Σ-terms

• Since generators can have coarities, and since we need to be careful with resources, we can’t use the standard notion of term (tree).

• Instead, terms are arrows in a certain symmetric monoidal category, which we will construct a la magic Lego

Page 63: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Generators and terms

: (2, 1)

Running example: the SMT of commutative monoids

: (0, 1)

we always have the following “basic tiles” around

: (1, 1) : (2, 2)

Page 64: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Some string diagrams• String diagrams: constructions built up from the generators

and basic tiles, with the two operations of magic Lego

� =

� =

; =

Page 65: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Recall: diagrammatic reasoning• diagrams can slide along wires

• wires don’t tangle, i.e.

• sub-diagrams can be replaced with equal diagrams (compositionality)

Ak l

Cm n

Ak l

Cm n

= =

Ak l

Cm n

functoriality

Ak l

m

m

l

=

Ak l

m

m

k

naturality

i.e. pure wiring obeys the same equations as permutations

= =

Page 66: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Σ - Terms (monoidal)• Are thus the arrows of the free symmetric monoidal

category SΣ on Σ

• Objects: natural numbers

• Arrows from m to n: string diagrams constructed from generators, identity and twist, modulo diagrammatic reasoning

• Monoidal product, on objects: m⊕n := m+n

Page 67: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Equationsx

y

z

x+ y

(x+ y) + z

x

y

zy + z

x+ (y + z)= (Assoc)

x

y

x+y

x

y

y+x= (Comm)

0

x

0 + x

= (Unit)

Note that all equations are of the form t1 = t2 : (m, n), that is, t1 and t2 must agree on domain and codomain

Page 68: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

The SMT of commutative monoids

=

=

=

EquationsGenerators

Let’s call this SMT M, for monoid

Page 69: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Diagrammatic reasoning example

=

=

=

=

= =

Page 70: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Another SMT: commutative comonoids

EquationsGenerators

=

=

=

Page 71: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

From SMTs to symmetric monoidal categories

• Every symmetric monoidal theory (Σ,E) yields a free strict symmetric monoidal category S(Σ,E)

• Object: natural numbers

• Arrows: monoidal Σ-terms, taken modulo equations in E

• Such categories are an instance of props (product and permutation categories)

Page 72: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

props• A prop (product and permutation category) is

• strict symmetric monoidal

• objects = natural numbers

• monoidal product on objects = addition

• i.e. m⊕n = m+n

Page 73: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Examples1. Any symmetric monoidal theory gives us a prop

2. The strict symmetric monoidal category F

• arrows from m to n are all functions from the m element set {0, …, m-1} to the n element set {0, … , n-1}

3.The free strict symmetric monoidal category on one object, the category P of permutations

4. The category I with precisely one arrow from any m to n is a prop

Page 74: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Morphisms of props• A morphism of props F: X→Y is an identity on objects

symmetric monoidal functor

• identity-on-objects: F(m) = m

• strict: F(C ⊕ D) = F(C) ⊕ F(D)

• symmetric monoidal: F(twm,n) = twm,n

• functor F(Im)=Im, F(C ; D) = F(C) ; F(D)

• In other words, all the structure is simply preserved on the nose — easy peasy

Page 75: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Models• Recall: models of algebraic theories are finite product preserving functors,

often to Set

• We can define models of an SMT to be symmetric monoidal functors, a generalisation of the notion of finite product preserving

• Some computer science intuitions:

• SMTs, like M, are a syntax

• props like F are a semantics

• homomorphisms map syntax to semantics

• when the map is an isomorphisms, we have an equational characterisation, and a sound and fully complete proof system to reason about things in F

Page 76: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Example

• So M is an equational characterisation of F

• or the “commutative monoids is the theory of functions”

The prop F is not an SMT

The prop M is an SMT

As props, M is isomorphic to F

Page 77: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Morphisms from (props obtained from) SMTs

• Let us define a morphism [[-]] : M → F

• M is obtained from a symmetric monoidal theory (Σ, E), thus its arrows are constructed inductively

• To define [[-]] it thus suffices to

• say where the generators in Σ are mapped

• check that the equations in hold in F

• This is a general pattern when defining morphisms from a prop obtained from an SMT

Page 78: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

[[-]]: M → F7�!

7�! {} → {1}

{1,2} → {1}

= (Assoc)

= (Comm)

= (Unit)

Simple exercise: check the following hold in F

Page 79: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Soundness• Simple observation: the fact that we have a

homomorphism [[–]] : M → F means that diagrammatic reasoning in M is sound for F

Q1. What property of [[–]] do we need to ensure completeness?

Q2. If we have soundness and completeness, is this enough for [[–]] to be an isomorphism? (i.e. invertible)

Page 80: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Full and faithful• To show that a morphism of props F: X→Y is an

isomorphism it suffices to show that it is full and faithful

• full: for every arrow g of Y there exists an arrow f of X such that F(f) = g

• faithful: given arrows f, f’ in X, if F(f)=F(f’) then f = f’

So full and faithful functor from a (free PROP on an) SMT = sound and fully complete equational charaterisation

Page 81: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

[[–]] : M → F• full: every function between finite sets can be

constructed from the two basic building blocks together with permutations

• faithful: every diagram in M can be written as multiplications followed by units, which corresponds to a factorisation of a function as an surjection followed by an injection. This factorisation is unique “up-to-permutation”.

Page 82: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Free things• A free “something on X” is one that satisfies a universal

property — it’s the “smallest” thing that contains X which satisfies the properties of “something”

• e.g. free “monoid on a set Σ” is the set of finite words Σ*

X

F G

Page 83: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Free strict symmetric monoidal category on one object

• Any ideas?

• Recall: there is a category 1 with one object and one arrow

• Let X be the free symmetric monoidal category on 1

• There should be a functor from 1 to X

• For any functor to a strict symmetric monoidal category Y, there should be a strict symmetric monoidal functor X to Y such that the diagram below commutes

1

X Y

functorfunctor

strict symmetric monoidal functor

Page 84: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Plan• symmetric monoidal categories and string diagrams

• theory of natural number matrices (bimonoids) and integer matrices (Hopf monoids)

• bimonoids and matrices of natural numbers

• Hopf monoids and matrices of integers

• theory of linear relations (interacting Hopf monoids)

• distributive laws

• linear algebra, diagrammatically

• an application: signal flow graphs

Page 85: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

• Combines generators and equations of the SMTs of monoids and comonoids

• Intuition: “numbers” travel on wires from left to right

The monoid structure acts as addition/zero

The comonoid structure acts as copying/discarding

x

yx+y

0

xx

x

x

The SMT of bimonoids

Page 86: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Adding meets copying

• The way that adding and copying interact is responsible for all linear algebra

• In the next slide we will introduce the theory of bimonoids, the equations of which show some of the ways that the interactions happen

Page 87: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

The SMT of bimonoids• all the generators we have seen so far

• monoid and comonoid equations

• “adding meets copying” - equations compatible with intuition

=

= = =

=

=

=

=

=

=

Page 88: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Mat• A PROP where arrows m to n are n×m matrices of natural

numbers

• e.g.

• Composition is matrix multiplication

• Monoidal product is direct sum

• Symmetries are permutation matrices

�0 5

�: 2 ! 1

✓315

◆: 1 ! 2

✓1 23 4

◆: 2 ! 2

A1 �A2 =

✓A1 00 A2

Page 89: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

• Theorem. B is isomorphic to the Mat

• ie. bimonoids is the theory of natural number matrices

• natural numbers themselves can be seen as certain (1,1) diagrams, with the recursive definition below

• as we will see, the algebra (rig) of natural numbers follows

0 :=

k+1 :=k

B and Mat

+1 is “add one path”

Page 90: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

m

nm+n=

m n nm=

mm

m=

m

mm=

Exercise

0 :=

k+1 :=k

Given , prove

1.

2.

3.

4.

Page 91: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Proof B≅Mat

�1 1

�: 2 ! 1

() : 0 ! 1

✓11

◆: 1 ! 2

() : 1 ! 0

7!7!7!7!

Full - easy! Recursively define a syntactic sugar for matricesFaithful - harderUse the fact that equations are a presentation of a distributive law, obtain factorisation of diagrams as comonoid structure followed by monoid structure - normal form

Recall: Since B is an SMT, suffices to say where generators go (and check that equations hold in the codomain)

Page 92: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Normal form for B• Every diagram can be put in the form

• comonoid ; monoid

• Centipedes

Page 93: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Matrices• To get the ijth entry in the matrix, count the paths

from the jth port on the left to the ith port on the right

• Example:

2

3

4

✓1 23 4

Page 94: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Q1. Show that the monoidal product in B≅Mat is the categorical product

Q2. The categorical coproduct of X, Y, if it exists satisfies the following universal property

show that the monoidal product in B≅Mat is the categorical coproduct.

When a monoidal product satisfies both the universal properties of products and coproducts, we say that it is a biproduct.

In fact B≅Mat is the free category with biproducts on one object.

Q3 (challenging). Given a category C, describe the free category with biproducts on C.

Exercise

X+Y

Z

X Yi1 i2

f gh

for any object Z and arrows f: X → Z, g: Y → Z,

∃ unique h: X+Y → Z s.t. i1 ; h = f and i2 ; h = g

Page 95: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Lawvere categories with string diagrams

(i.e. how ordinary syntax looks, with string diagrams)

σ... (σ ∈ Σ)

=

=

=

and what else?

Page 96: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

In particular, notice that B is isomorphic (as a symmetric monoidal category) to the Lawvere category of commutative monoids!

σ...= ...

σ

σ...

...

σ...= ...

Exercise: show that the monoidal product now becomes a categorical product

Page 97: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Putting the n in ring: Hopf monoids• generators of bimonoids + antipode

• think of this as acting as -1

• equations of bimonoids and the following

=

= =

= =

Page 98: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

-1 ⋅ -1 = 1=

=

=

=

=

=

=

=

Page 99: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

The ring of integers• Simple induction:

• Recall: in B, the arrows 1→1 were in one-to-one correspondence with natural numbers

• In H, the arrows 1→1 are in one-to-one correspondence with the integers

n n=

0 :=

k+1 :=k

-n := n

Page 100: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

• Verify that, in H, for all integers m, n we have

Exercise

m

nm+n=

m n nm=

Page 101: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

• Arrows m to n are n×m matrices of integers

• composition is matrix multiplication

• monoidal product is direct sum

• MatZ is equivalent to the category of finite dimensional free Z-modules

• SMT H is isomorphic to the PROP MatZ

MatZ

Page 102: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Path counting in MatZ• To get the ijth entry in the matrix, count the

• positive paths from the jth port on the left to the ith port on the right (where antipode appears an even number of times)

• negative paths between these two ports (where antipode appears an odd number of times)

• subtract the negative paths from the positive paths

• Example:✓

0 �11 0

Page 103: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Proof H≅MatZ

• Fullness easy

• Faithfulness more challenging: put diagrams in the form

�1 1

�: 2 ! 1

() : 0 ! 1

✓11

◆: 1 ! 2

() : 1 ! 0

7!7!7!7!

copying ; antipode ; adding

7! (�1) : 1 ! 1

Page 104: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

• We saw that B is the isomorphic, as a symmetric monoidal category, to the Lawvere category of commutative monoids.

• Which Lawvere category is H isomorphic to?

Exercise

Page 105: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Plan• basic theory of string diagrams

• theory of natural number matrices (bimonoids) and integer matrices (Hopf monoids)

• theory of linear relations (interacting Hopf monoids)

• intuition upgrade

• Frobenius monoids

• the equations of IH

• linear relations

• rational numbers, diagrammatically

• distributive laws

• linear algebra, diagrammatically

• an application: signal flow graphs

Page 106: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Intuition upgrade• We have been saying that numbers go from left to right in diagrams

• this is a functional, input/output interpretation

• J.C. Willems - Behavioural approach in control theory

• Engineers create functional behaviour from non-functional components

• The physical world is NOT functional

• Functional thinking is fundamentally non-compositional

• From now on, we will take a relational point of view, a diagram is a contract that allows certain numbers to appear on the left and on the right

Page 107: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Intuition upgrade• We have been saying that numbers go from left to right in diagrams

• this is a functional, input/output interpretation

• J.C. Willems - Behavioural approach in control theory

• Engineers create functional behaviour from non-functional components

• The physical world is NOT functional

• Functional thinking is fundamentally non-compositional

• From now on, we will take a relational point of view, a diagram is a contract that allows certain numbers to appear on the left and on the right

The input/output framework is totally inappropriate for dealing with all but the most special system interconnections. [The input/output representation] often needlessly complicates matters, mathematically and conceptually. A good theory of systems takes the behavior as the basic notion.

J.C. Willems, Linear systems in discrete time, 2009

Page 108: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Intuition upgrade

• Intuition so far is this as a function +: D×D→D

• From now it will be as a relation of type DxD → D

• Composition is relational composition

Page 109: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Mirror images

xy , x+y () , 0 x , x

x x , ()

Page 110: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Mirror images

xy , x+y () , 0 x , x

x x , ()

xyx+y , 0 , () x

x , x () , x

Page 111: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Adding meets adding

p

q

r

p+q

r

p

q+r

x

y

z

x+y

z

x

y+z

x = p+qz = q+r

p=x+yr=y+z

Provided addition yields abelian group (i.e. there are additive inverses), the two

are the same relation

y=-q

Page 112: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

More adding meets adding

x+yx

yx+y

since x and y are free, this is the identity relation

x

empty relation

Page 113: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Copying meets copyingx

x

x

x

x

x

x

x

x

x

clearly both give the same relation

xx

xx

identity relation

x

empty relation

Page 114: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Two Frobenius structures

= =

= =

+ special / strongly separable equations

+ “bone” equations= =

Page 115: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Frobenius monoids

=

=

=

=

=

=

=

Frobenius monoid

Page 116: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Snakes

= =

Snake lemma

=(Frob)

=(Unit)

=(Counit)

Proof:

“cup” “cap”

Page 117: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Normal forms• In B, we saw that every

diagram can be factorised into comonoid structure ; monoid structure, this gave us centipedes

• In Frob, every diagram can be factored into monoid structure ; comonoid structure, these are often referred to as spiders

=

=

=

=

=

=

=

Special Frobenius monoid

=

Page 118: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Spiders in special Frobenius monoids 1

• In a special Frobenius monoid every connected diagram is equal to one of the form

• which suggests the “spider notation”

......

12

m

1

2

n

......

12

m

1

2

n

Page 119: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Spiders in special Frobenius monoids 2

• In general, diagrams are collections of spiders

• when two spiders connect, they fuse into one

• i.e. any connected diagram of type m→n is equal

Page 120: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Black and white cups and caps

=

{(✓

x

y

◆, ()) | x+ y = 0 }

{(✓

x

x

◆, ())}

=

Page 121: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Scalars meet scalars

if multiplication on the left by p is injective (e.g. if p ≠ 0 in a field)

px pxppx =

if multiplication on the left by p is surjective (e.g. if p ≠ 0 in a field)

p px px=py y =

Page 122: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Interacting Hopf Monoids(Bonchi, S., Zanasi, ’13, ’14)

=

=

=

Copying

=

=

=

Copyingop

=

=

=

Adding

=

= =

=

Adding meets Copying

=

=

=

Addingop

=

= =

=

Addingop meets Copyingop

Antipode

=

=

=

=

=

Antipodeop

=

=

=

=

=

H Hop

Page 123: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

White monoid (adding)

Black comonoid (copying)

White comonoid (adding-op)

Black monoid (copying-op)

Hopf Hopf

Frobenius

Frobenius

=

=

=

=

=

=

=

=

=

=

=

=

Page 124: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

The antipode cheat

=

=

The antipodes in H and Hop are formally different but we were slightly naughty with notation.

Page 125: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Interacting Hopf MonoidsAdding meets Addingop

=

=

=

Copying meets Copyingop

=

=

=

=

=

Cups and Caps

p p p p (p ≠ 0) = =

Scalars

cf. ZX-calculus (Coecke, Duncan)

Page 126: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

=

=

=

Copying

=

=

=

Copyingop

=

=

=

Adding

=

= =

=

Adding meets Copying

=

=

=

Addingop

=

= =

=

Addingop meets Copyingop

Antipode

=

=

=

=

=

Antipodeop

=

=

=

=

=

Adding meets Addingop

=

=

=

Copying meets Copyingop

=

=

=

=

=

Cups and Caps

p p p p (p ≠ 0) = =

Scalars

Symmetry 1 - colour inversion

Symmetry 2 - mirror image

IH

Page 127: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Redundancy• Generators are expressible in terms of other

generators, e.g.

Lemma=

=

=

=

so

=

=

Page 128: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Linear subspaces• Suppose that V is a vector space over field k

• A linear subspace U⊆V is a subset that

• contains the zero vector, 0∈V

• closed under addition, if u,u’ ∈ U then u+u’ ∈ U

• closed under scalar multiplication, if u ∈ U and p ∈ k then p⋅u ∈ U

• e.g. R2 is an R-vector space. What are the linear subspaces?

Page 129: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

• Suppose that U, V, W are k vector spaces,

• R ⊆ U×V is a subspace and

• S ⊆ V×W is a subspace

• Show that the relational composition R;S⊆U×W is a subspace

Exercise

Page 130: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

• PROP of linear relations over the rationals

• arrows m to n are subspaces of Qm × Qn

• composed as relations

• monoidal product is direct sum

• IH is isomorphic to LinRel

LinRel

Page 131: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Where did the rationals come from?

• Recall

• in B, the (1,1) diagrams were the natural numbers

• in H, the (1,1) diagrams were the integers

• In IH, the (1,1) diagrams include the rationals p/q

p q

Page 132: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Some Lemmas

if q ≠ 0:

p q p q= q q

= q qq p

= q p

q

q=

q

qq q

=q

q

q

qq

= q

suppose q,s ≠ 0:

p q r s=

⇔sp = qr

p s = p q q s

r s q s

r q ss

=

=

r q=

⟸ p q = p qs s

= r q qs

= r qs q

r s=

Page 133: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Rational arithmetic(q,s ≠ 0)

p q

r s=

p q

r s

s s

q q

sp sq

qr qs

sp

qrsq

=

=

= sp+qr sq

p q r s = p r sq

= rp sq

Page 134: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Keep calm and divide by zero• it’s ok, nothing blows up

• of course, arithmetic with 1/0 is not quite as nice as with proper rationals.

• two ways of interpreting 0/0 (0 · /0 or /0 · 0)

0 =

0 =

0 0 =

0 0 =

Page 135: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Projective arithmetic++• Projective arithmetic identifies numbers with one-

dimensional spaces (lines) of Q2

• one for each rational p : { (x,px) | x ∈ Q }

• and “infinity” : { (0, x) | x ∈ Q }

• The extended system includes all the subspaces of Q2, in particular:

• the unique zero dimensional space { (0, 0) }

• the unique two dimensional space { (x,y) | x,y ∈ Q }

0(x, 1/2 x)

(x, 2x)

Page 136: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Dividing by zeroEdalat and Potts suggested that two extra ‘numbers’, ∞ = 1/0 and ⊥ = 0/0, be adjoined to the set of real numbers (thus obtaining what in domain theory is called the ‘lifting’ of the real projective line) in order to make division always possible. In a seminar, Martin-Löf proposed that one should try to include these ‘numbers’ already in the construction of the rationals from the integers, by allowing not only non-zero denominators, but arbitrary denominators, thus ending up not with a field, but with a field with two extra elements.

Here we have three extra “numbers”!

Jesper Carlström, Wheels, On Division by Zero, 2001

⊤ :=

⊥ :=

∞ :=

Page 137: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Plan• basic theory of string diagrams

• theory of natural number matrices (bimonoids) and integer matrices (Hopf monoids)

• theory of linear relations (interacting Hopf monoids)

• distributive laws

• linear algebra, diagrammatically

• an application: signal flow graphs

Page 138: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Distributive laws of PROPs• Proof IH ≅ LinRel relies on the notion of distributive law of PROPs

(Lack, Composing PROPs, 2004)

• a variant of distributive laws of monads

• monads can be considered in any 2-category (R. Street, Formal Theory of Monads, 1972)

• categories = monads in Span(Set)

• strict monoidal categories = monads in Span(Mon)

• small technical complications for PROPs because of symmetries

Page 139: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Categories = Monads??• What is a monad in Span(Set)?

• endo 1-cell

• multiplication

• unit

• satisfying associativity & unit laws

O�0 � A

�1�! O

A⇥O A

✏✏

// A

�1

✏✏A

�0

// O

A⇥O Aµ�! A

O⌘�! A

let’s call it “composition”

let’s call it “identity”

Page 140: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Distributive laws of PROPsP Green PROP P Q Purple PROP Q

When can we understand P;Q as a PROP?

Q P P Qλ

P Q P QPλQ

P P Q Q

Page 141: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Distributive law of Monads• Given monads T, U, a

distributive law is a 2-cell

• that is compatible with multiplication and units in T and U in the obvious way (see diags)

• gives a monad structure on TU

� : UT ) TU

UUTµUT //

U�

✏✏

UT

✏✏UTU

�U// TUU

TµU

// TU

UTTUµT //

�T

✏✏

UT

✏✏TUT

T�// TTU

µTU// TU

T⌘UT

}}||||

|||| T⌘U

!!BBB

BBBB

B

UT�

// TU

UU⌘T

}}{{{{

{{{{ ⌘TU

!!CCCC

CCCC

UT�

// TU

Page 142: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

SMT of Spans• The bicategory Span(Set) has spans of functions as 1-cells and span morphisms as 2-cells

• composition is by pullback

• we obtain the category of spans by identifying isomorphic spans

• We already have the SMT of functions (commutative monoids) and “backwards functions” (commutative comonoids)

• Pullback defines a distributive law of PROPs - implied by the universal property

=

=

=

=

=

=

=

=

=

=

=

=

Pullback!

Page 143: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

• the theory of bimonoids is a presentation of this distributive law

• so B ≅ Mat ≅ Span(F)

• for details see Steve Lack’s paper

2⇥ 2⇡1

}}zzzzzzzz

!!DDDDDDDD⇡2

!!DDDDDDDD

2

""DDDD

DDDD

D 2

||zzzz

zzzz

z

1

Page 144: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

• the theory of bimonoids is a presentation of this distributive law

• so B ≅ Mat ≅ Span(F)

• for details see Steve Lack’s paper

2⇥ 2⇡1

}}zzzzzzzz

!!DDDDDDDD⇡2

!!DDDDDDDD

2

""DDDD

DDDD

D 2

||zzzz

zzzz

z

1

(0,0)

(0,1) (1,0) (1,1)

0

1

0

1

Page 145: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

• the theory of bimonoids is a presentation of this distributive law

• so B ≅ Mat ≅ Span(F)

• for details see Steve Lack’s paper

2⇥ 2⇡1

}}zzzzzzzz

!!DDDDDDDD⇡2

!!DDDDDDDD

2

""DDDD

DDDD

D 2

||zzzz

zzzz

z

1

(0,0)

(0,1) (1,0) (1,1)

0

1

0

1

Page 146: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

• the theory of bimonoids is a presentation of this distributive law

• so B ≅ Mat ≅ Span(F)

• for details see Steve Lack’s paper

2⇥ 2⇡1

}}zzzzzzzz

!!DDDDDDDD⇡2

!!DDDDDDDD

2

""DDDD

DDDD

D 2

||zzzz

zzzz

z

1

(0,0)

(0,1) (1,0) (1,1)

0

1

0

1

=

Page 147: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

SMT of Cospans• The bicategory Cospan(Set) has cospans of functions as 1-cells

and cospan morphisms as 2-cells

• composition is by pushout

• pushout defines a distributive law

• obtain theory strongly separable Frobenius monoids — the theory of cospans!

=

=

Page 148: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Proof of IH≅LinRel (outline)• Two distributive laws

• slight generalisation of Lack’s notion

• MatZ has both pullbacks and pushouts

• it is equivalent to the category of free f.d. Z-modules

• since Z is a PID, this category has pullbacks

• because of transpose, MatZ also has pushouts

• We thus obtain two distributive laws:

• one from pullbacks, giving spans of matrices

• one from pushouts, giving cospans of matrices

Page 149: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Spans of matricesp p =

IRSp ≅ Span(MatZ)

= =

= =

= =

(p ≠ 0)

IRSp

rr =

r

rr=

r

Page 150: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Cospans of matrices

IRCsp ≅ Cospan(MatZ)

IRCsp

(p ≠ 0) p p =

= =

= =

= =

rr =

r

rr=

r

Page 151: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

The cube - back faces

MatZ + MatZop

H + Hop

Span(MatZ)

IHSpan

IHCospan

Cospan(MatZ)

Page 152: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

The cube

MatZ + MatZop

H + Hop

Span(MatZ)

IHSpan

IHCospan

Cospan(MatZ) LinRel

IH

Page 153: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Corollary• The proof gives us some useful facts

• every diagram in IH can be factorised in two ways

• as a span

• as a cospan

• every mono in MatZ satisfies

• every epi in MatZ satisfies

A Bm nk

C Dm nl

A Am mn = m

A An nm = n

Page 154: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Plan• basic theory of string diagrams

• theory of natural number matrices (bimonoids) and integer matrices (Hopf monoids)

• theory of linear relations (interacting Hopf monoids)

• distributive laws

• linear algebra, diagrammatically

• an application: signal flow graphs

Page 155: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Factorisations• Every diagram can be factorised as a span or a cospan of matrices

• This gives us the two different ways one can think of spaces

solutions of a list of homogeneous equations

linear combinations of basis vectors

x+y=0

x

y

z

2y-z=0

2

x

y

z

x+y=02y-z=0

2

x

y

z

a[1, -1, 0]

a

b[0, 1, 2]

2 b

a[1, -1, 0]+b[0,1,2]

2

a

b

Page 156: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Factorisations• Every diagram can be factorised as a span or a cospan of matrices

• This gives us the two different ways one can think of spaces

solutions of a list of homogeneous equations

linear combinations of basis vectors

x+y=0

x

y

z

2y-z=0

2

x

y

z

x+y=02y-z=0

2

x

y

z

Cospans

a[1, -1, 0]

a

b[0, 1, 2]

2 b

a[1, -1, 0]+b[0,1,2]

2

a

b

Page 157: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Factorisations• Every diagram can be factorised as a span or a cospan of matrices

• This gives us the two different ways one can think of spaces

solutions of a list of homogeneous equations

linear combinations of basis vectors

x+y=0

x

y

z

2y-z=0

2

x

y

z

x+y=02y-z=0

2

x

y

z

Cospans

a[1, -1, 0]

a

b[0, 1, 2]

2 b

a[1, -1, 0]+b[0,1,2]

2

a

b

Spans

Page 158: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Image and kernel• Definition

• The kernel of A is

• The cokernel of A is

• The image of A is

• The coimage of A is

A

A

AT

AT

Page 159: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

InjectivityInjective matrices are the monos in MatZ

Theorem. A is injective iff A A =

⇒ ⇐AF AG=

⇒ AF AG= AA

⇒ F = G

������

���?

????

A ��???

??

A������

is pullback in MatZ

AF AG= ⇒ F = G

Page 160: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Surjectivity• Surjective matrices are the epis in MatZ, i.e.

• Theorem. A is surjective iffA A =

A AF G= ⇒ F = G

Proof: Bizarro of last slide

Page 161: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Injectivity and kernel

• Theorem. A is injective iff ker A = 0

⇒ ⇐ A A =A

A

=A

A

= A

=

=

A = A A

=

Page 162: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Surjectivity and image

• Theorem. A is surjective iff im(A)=codomain

A A =

⇔A =

Proof: bizarro of last slide

Page 163: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Invertible matrices• Theorem: A is invertible with inverse B iff

A B=

⇒ ⇐

so A is injective

A B A A= =

bizarro argument yields other half

A A B

B=

=AA B= =

Page 164: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Summary• We have done a bit of linear algebra without mentioning

• vectors, vector spaces and bases

• linear dependence/independence, spans of a vector list

• dimensions

• Similar stories can be told for other parts of linear algebra: decompositions, eigenvalues/eigenspaces, determinants

• much of this is work in progress: check out the blog! :)

Page 165: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Plan• basic theory of string diagrams

• theory of natural number matrices (bimonoids) and integer matrices (Hopf monoids)

• theory of linear relations (interacting Hopf monoids)

• distributive laws

• linear algebra, diagrammatically

• an application: signal flow graphs

Page 166: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Generalising (slightly)• It is straightforward to generalise from Z to arbitrary

PID R

• We can build the theory HR by adding enough scalars to the graphical syntax together with equations

• The equations of IHR are the same as before

r1

r2r1+r2=

r1 r2 = r2r1

1 =

0 =

Page 167: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Application: infinite series• Diagrammatic calculus for spaces over the field of fractions of Q[x]

(polynomials with one variable, a PID) is especially interesting

• polynomial fractions = nice syntax for many infinite series (generatingfunctionology!)

• formally: there is an embedding of fields from polynomial fractions (syntax) to Laurent series (semantics)

• Moreover: diagrams are very closely related to signal flow graphs

• invented by Shannon in the 40s, reinvented by Mason in the 50s, foundational structure in control and signal processing

• useful circuit-like syntax for linear time-invariant dynamical systems

Page 168: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

The cube (with extra level!)

MatQ[x] + MatQ[x]op

HQ[x] + HQ[x]op

Span(MatQ[x])

IHQ[x]Span

IHQ[x]Cospan

Cospan(MatQ[x]) LinRelQ(x)

IHQ(x)

MatQ[[x]] + MatQ[[x]]op

Cospan(MatQ[[x]])

Span(MatQ[[x]])

LinRelQ((x))

isomorphisms

faithful homomorphisms

In particular, IHQ[x] is sound and complete

as a theory for LinRelQ((x))

Page 169: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Example1-x-x2x

As linear relation over Q(x) is the space generated by

As linear relation over Q((x)) is the space generated by

(1 , x/(1-x-x2))

(1,0,0,… , 0,1,1,2,3,5,8,…)

Page 170: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Operational semantics: (1, 2) : (1, 0) k : (1, 1) x : (1, 1) : (2, 1) : (0, 1)

: (2, 1) : (0, 1) k : (1, 1)

x

: (1, 1) : (1, 2) : (1, 0)

: (0, 0) : (1, 1) : (2, 2)

c : (n, z) d : (z,m)

c ; d : (n,m)

c : (n,m) d : (r, z)

c�d : (n+r,m+z)

Figure 1. Sort inference rules.

k

��!

k k

k

�! kl

��!

kl

k x l

k

�!

l

x k

k l

��!

k+l

�!

0

k k

��!

k

�!

k

kkl

��!

l

k

x l

l

�!

k

x k

k+l

���!

k l

0�!

k

�!

k

k l

��!

l k

su

�!

v

s0 tv

�!

w

t0

s ; t u

�!

w

s0 ; t0

su1��!

v1s0 t

u2��!

v2t0

s� tu1 u2����!

v1 v2s0 � t0

Figure 2. Structural rules for operational semantics, with k, l ranging over k and u, v, w vectors of elements of k of the appropriate size.

boundary to the right: thus is a copier, duplicating the signal

arriving on the left; accepts any signal on the left and discards

it, producing nothing on the right; is an adder that takes

two signals on the left and emits their sum on the right, and

constantly emits the signal 0 on the right; k is an amplifier,

multiplying the signal on the left by the scalar k 2 k. Finally, xis a delay, a synchronous one place buffer initialised with 0.

The terms of row (5) are those of row (4) “reflected about they-axis”. Their behaviour is symmetric—indeed, here it is helpful tothink of signals flowing from right to left.

In row (6), is a twist, swapping two signals, is theempty circuit and is the identity wire: the signals on the leftand on the right ports are equal. Terms can be combined by twobinary operators: sequential ; and parallel � composition.

In the syntax specification we purposefully used a graphicalrendering of the components. Indeed, we will seldom write termsin the traditional way and instead represent them as 2-dimensionaldiagrams. We adopt the following common convention:

c ; c0 is drawn c c�......

... c� c0 is drawnc

c� ...

......

...

.

A computation of a circuit c, is a (possibly infinite) paths0

v0��!

w0s1

v1��!

w1. . . in the transition system of c, starting from

its initial state s0. When c has sort (n, m), each vi

and wi

consistof strings over k, say k

i1 . . . kin and li1 . . . lim, respectively. The

trace of a computation s0v0��!

w0s1

v1��!

w1. . . is then a pair of vec-

tors

↵1

.

.

.↵

n

!

,

�1

.

.

.�

m

!

where ↵j

= k0jk1j . . . and �j

= l0j l1j . . . .

Occasionally we will use the notation (�!↵ ,�!

� ) for such a pair and,to make the notation lighter, we will write ↵

j

= k0k1 . . . and�j

= l0l1 . . . . Moreover, with ↵j

(i) and �j

(i) we will denote thei-th elements of ↵

j

and �j

.Note that in a computation of length z, all ↵

j

,�j

have lengthz, while for an infinite computation all ↵

j

,�j

are infinite. In theformer case, we say that a trace is finite, in the latter that it is

infinite. We use ft(c) to denote the set of all finite traces of c andit(c) for the set of all infinite ones.

Example 1. Consider the two circuits below.

-1 xx

The first is a graphical representation of the term

c1 = ( ; (( -1 ; x)� )) ;

the second of the term

c2 = (( ; )� ) ; ( � ( ; ))

; ((( � x )� ) ; (( ; )� ))

Note that, according to our intuition, in the leftmost circuit thesignal flows from right to left, while the rightmost, the signal flowsfrom left to right – indeed, the terms ; and ;serve as “bent identity wires” which allow us to form a feedbackloop. Let c1[k] and c2[k] represent the states of c1 and c2, withk denoting the value at the register. The rules of Fig. 2 yield thecomputation

ci

[0] 1�!

1ci

[1] 0�!

1ci

[1] 0�!

1ci

[1] · · ·

for i 2 0, 1, which yields the trace (1000 . . . ), (1111 . . . ). Infact, as we shall show via a sound and complete axiomatisation,despite of the signal intuitively flowing in different directions, thetwo circuits have the same observable behaviour.

A slightly more involved example is given below.

x2

x -1

We leave the reader to write down a term that is represented bythe diagram above: call it c3 and let c3[k1, k2] represent the statewhere the two registers, reading from from left to right, have valuesk1 and k2. Then, the operational semantics allows us to derive the

Bonchi, S., Zanasi, Full abstraction for signal flow graphs, POPL ‘15

Important point: all executions start with all registers initialised with 0!

Page 171: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Example:= :=

x x0 0

1 1

1 1x x

1

0 2

1 1 2

x x2

0 3

1 1 3

Page 172: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Operational Semantics vs Denotational Semantics

Operational semantics closely related to denotational semantics [linear relations over Q((x))] with some “implementation issues” in diagrams where signal flow is inconsistent e.g.

x x00 00

x xk k

x x0 0 1

2x x1 2

Page 173: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Realisability and Full Abstraction

• Realisability Every diagram can be put in a form where the direction of signal flow is consistent

• Full abstraction Operational equality (in terms of behaviour, given by operational semantics) coincides with denotational equality (the denoted linear relation) on diagrams with consistent signal flow

Page 174: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Turning generating functions into signal flow graphs

1,2,3,4,…

Generating function Diagram Signal flow graph

1

(1� x)2 x x(1-x)2

0,-4,0,-8,.. �4x

(1� x

2)2

1,-2,3,-4,… 1

(1 + x)2

x xx x

-4 x(1-x2)2-4x

(1+x)2

x x

Page 175: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Fibonacci (C 1170 - C 1250)1

23581321345589144233377

A certain man had one pair of rabbits together in a certain enclosed place, and one wishes to know how many are created from the pair in one year when it is the nature of them in a single month to bear another pair, and in the second month those born to bear also.

You can indeed see in the margin how we operated, namely that we added the first number to the second, namely the 1 to the 2, and the second to the third, and the third to the fourth, and the fourth to the fifth, and thus one after another until we added the tenth to the eleventh, namely the 144 to the 233, and we had the above written sum of rabbits, namely 377, and thus you can in order find it for an unending number of months.

(extract from Liber Abaci, chapter 12, translated from Latin by Lawrence Sigler)

Page 176: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

The Fibonacci sequenceand recurrence relations

1, 2, 3, 5, 8, 13, …

in modern presentations often given as1, 1, 2, 3, 5, 8, … or 0, 1, 1, 2, 3, 5, …

is an example of a recurrence relationhere

Fn+2 = Fn+1 + Fn

more generally, the nth term can be obtain as an expression featuring previous terms

Page 177: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Code for Fibonacci

val ffib : int list -> int list = <fun>

# ffib [1;0;0;0;0;0;0;0];; - : int list = [1; 2; 3; 5; 8; 13; 21; 34]

# ffib [1;1;1;1;1;1;1;1];; - : int list = [1; 3; 6; 11; 19; 32; 53; 87]

# ffib [1;1;-3;1;-2;-4;1];; - : int list = [1; 3; 2; 3; 4; 1; 2]

Generalise the Fibonacci rabbit breeding rule from a sequence to a function of type

Page 178: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Sustainable rabbit breeding• Suppose that we want a sustainable rabbit farm, keeping 4

pairs in the rabbit pen at all times.

• Is it possible?

• If so, how many rabbits must we add and remove, in which months?

If the Fibonacci rule gives us a function of type

to solve the sustainable rabbit breeding problem we could try to write the inverse

ffib: int list -> int list

bfib: int list -> int list

Page 179: Graphical Linear Algebra - phdopen.mimuw.edu.plphdopen.mimuw.edu.pl/zima16/sobocinski-slides.pdf · Examples of monoidal categories • Set f with × (cartesian product) or with +

Bibliography• Bonchi, S., Zanasi - Interacting Bialgebras are Frobenius, FoSSaCS ’14

• Bonchi, S., Zanasi - Interacting Hopf Algebras, J Pure Applied Algebra 221:144–184, 2017

• Bonchi, S., Zanasi - The Calculus of Signal Flow Diagrams I: Linear Relations on Streams, Inf Comput 252:2–29, 2017

• Bonchi, S., Zanasi - A categorical semantics of signal flow graphs, CONCUR 2013

• Bonchi, S., Zanasi - Full abstraction for signal flow graphs, PoPL 2016

• Zanasi - Interacting Hopf Algebras: The theory of linear systems, PhD Thesis, ENS Lyon, 2015

• Bonchi, S., Zanasi - Lawvere Theories as composed PROPs, CMCS 2016

• Fong, Rapisarda, S. - A categorical approach to open and interconnected dynamical systems, LiCS 2016

• Bonchi, Gadducci, Kissinger, S. - Rewriting modulo symmetric monoidal structure, LiCS 2016

• Bonchi, Gadducci, Kissinger, S. - Confluence of Graph Rewriting with Interfaces, ESOP 2017

graphicallinearalgebra.net