Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019....

94
Programming Languages in String Diagrams [ four ] Local stores Paul-André Melliès Oregon Summer School in Programming Languages June 2011

Transcript of Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019....

Page 1: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Programming Languages in String Diagrams

[ four ]

Local stores

Paul-André Melliès

Oregon Summer School in Programming Languages

June 2011

Page 2: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Finitary monads

A monadic account of algebraic theories

Page 3: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Algebraic presentations of effects

We want to reason about programs with effects like states, excep-tions...

Computational monads:

Apimpurep

// B = Appurep

// T (B)

Algebraic theories:

operations : A n−→ A and equations

Page 4: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

A useful correspondence

Recall that a monad

T : Set −→ Set

is finitary when it preserves the filtered colimit.

Important fact. There is an equivalence of categories

the categoryof

algebraic theories�

the categoryof

finitary monads

4

Page 5: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Finitary monads

Alternative definition. A monad

T : Set −→ Set

is finitary when the diagram

Set

id08

FinSet i//

T◦ i

BB���������������������

Set

T

ZZ55555555555555555555

exhibits the functor T as a left Kan extension of T ◦ i along i.

5

Page 6: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Finitary monad

A monad T on the category Set is finitary when every map

[1] −→ TA

factors as

[1] e−→ T [p]

T f−→ TA

for a pair of maps

[1] −→ T [p] [p] −→ A.

6

Page 7: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Finitary monad

Moreover, the factorization should be unique up to zig-zag:

T [p]

Tu

��

T f1

!!CCCCCCCCCCCCCCCCCCCCCCC

[1]

e1

=={{{{{{{{{{{{{{{{{{{{{{

e2

!!CCCCCCCCCCCCCCCCCCCCCC TA

T [q]

T f2

=={{{{{{{{{{{{{{{{{{{{{{{

7

Page 8: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

The Kleisli category of a monad

The Kleisli category Set T associated to a monad

T : Set −→ Set

has sets as objects, and functions

f : A −→ T(B)

as morphisms from A to B.

An alternative formulation of the category of free algebras.

8

Page 9: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

The Lawvere theory of a monad

The Lawvere theory Θ T associated to a monad

T : Set −→ Set

is the full subcategory of Set T with finite ordinals

[p] = { 0 , 1 , . . . , p − 1 }

as objects.

Remark. The category Θ T has finite sums.

9

Page 10: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Algebras of a monad

A set A equipped with a function

alg : TA −→ A

making the two diagrams below commute:

TTAT ( alg )

//

µ

��

TA

alg

��

TAalg

//A

TA

alg

��::::::::::::::::::::::::

A

ηA

BB������������������������ id //A

10

Page 11: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Key theorem [ originating from Lawvere ]

The category of T-algebras

is equivalent to

the category of finite product preserving functors

ΘopT −→ Set

This property holds for every finitary monad T.

11

Page 12: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Finitary monads as saturated theories

The finitary monad describes the equational classes of the theory :

Tn =

terms with n variables modulo equations

where

n =

x0 , x1 , · · · , xn−1

The monad often reveals a canonical form for the equational

theory.

Page 13: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Mnemoids

An algebraic presentation of the state monad

Page 14: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

The state monad

A program accessing one register with a finite set V of values

Aimpure

// B

is interpreted as a function

V × Apure

// V × B

thus as a function

Apure

// V ⇒ (V × B)

Hence, the state monad

T : A 7→ V ⇒ (V × A)

14

Page 15: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

What is an algebra of the state monad ?

An elegant answer by Plotkin and Power [2002]

Page 16: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Mnemoids

A mnemoid is a set A equipped with a V-ary operation

lookup : A V−→ A

and a unary operation

update〈val〉 : A −→ A

for each value val ∈ V .

16

Page 17: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Mnemoids

Typically, the lookup operation on the boolean space

V = { false , true }

is binary :

lookup : A × A −→ A

The intuition is that

lookup (u, v) =

{u when the register is falsev when the register is true

17

Page 18: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Annihilation lookup – update

A V

lookup

AAAAAAAAAAAAAAAAAAAAA

A

update〈V〉

>>}}}}}}}}}}}}}}}}}}}}} id //A

term = lookup

val 7→ update〈val〉 term

18

Page 19: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Annihilation lookup – update

Here, the map

update〈V〉 : A −→ A V

is the V-ary vector update〈0〉 , · · · , update〈V−1〉

also noted val 7→ update〈val〉

19

Page 20: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Annihilation lookup – update

x =x

x

true

false

20

Page 21: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Interaction update – update

A

update〈val1〉

��?????????????????????????

A

update〈val2〉

??������������������������� update〈val2〉 //A

update〈val1〉 ◦ update〈val2〉 = update〈val2〉

21

Page 22: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Interaction update – update

val2 val1 = val2

22

Page 23: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Interaction update – lookup

AV lookup//

Aval

��

A

update〈val〉

��

Aupdate〈val〉 //A

update〈val〉 ◦ lookup

x 7→ term(x)

= update〈val〉 ◦ term(val)

23

Page 24: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Interaction update – lookup

x

y

true = truex

24

Page 25: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Key theorem [ Plotkin & Power ]

the category of mnemoids

is equivalent to

the category of algebras of the state monad

Provides an algebraic presentation of the state monad

25

Page 26: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

A proof in three steps

1. establish that the state monad T is finitary [easy]

2. construct a functor [easy]

ι : Θ M −→ Θ T

starting from the Lawvere theory Θ M of mnemoidsby interpreting the update and lookup operations andby checking that the equations are valid in Θ T

3. show that the functor ι is full and faithful [rewriting]

26

Page 27: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Store with several locations

Algebraic presentation of the state monad

Page 28: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

The global state monad

The state monad is generally defined as

T : A 7→ S⇒ (S × A)

for a set of states

S = V L

induced by a set L of locations and a finite set V of values.

28

Page 29: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Global store [Plotkin & Power ]

A global store is a family of compatible mnemoidal structures

lookup〈loc〉 : AV−→ A

update〈loc,val〉 : A −→ A

one for each location loc ∈ L.

A tensor product of algebraic theories

29

Page 30: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Annihilation lookup – update

AV

lookup〈loc〉

@@@@@@@@@@@@@@@@@@@@@@@

A

update〈loc,V〉

>>~~~~~~~~~~~~~~~~~~~~~~~ id //A

lookup〈loc〉

val 7→ update〈loc,val〉 term

= term

30

Page 31: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Annihilation lookup – update

x =

true

falsex

x

31

Page 32: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Interaction update – update

A

update〈loc,val〉

��?????????????????????????

A

update〈loc,val′〉

??�������������������������

update〈loc,val′〉//A

update〈loc,val1〉 ◦ update〈loc,val2〉 = update〈loc,val2〉

32

Page 33: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Interaction update – update

val1val2 = val2

33

Page 34: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Interaction update – lookup

AVlookup〈loc〉 //

Aval

��

A

update〈loc,val〉

��

A update〈loc,val〉//A

update〈loc,val〉 ◦ lookup〈loc〉

x 7→ term(x)

= update〈loc,val〉 ◦ term(val)

34

Page 35: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Interaction update – lookup

true

y

x

= truex

35

Page 36: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Interaction update – lookup

false

y

x

= falsey

36

Page 37: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Commutation update – update

Aupdate〈loc,val〉 //

update〈loc′,val′〉

��

A

update〈loc′,val′〉

��

A update〈loc,val〉//A

update〈loc,v〉 update〈loc′,v′〉 x=

update〈loc′,v′〉 update〈loc,v〉 x

when loc , loc′

37

Page 38: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Commutation update – update

val′

val = val

val′

38

Page 39: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Corollary [ Plotkin & Power ]

the category of objects with a global store

is equivalent to

the category of algebras of the state monad

39

Page 40: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Graded monads

A stratified version of finitary monads

Page 41: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Presheaf models

Key idea: interpret a type A as a family of sets

A[0] A[1] · · · A[n] · · ·

indexed by natural numbers, where each set

A[n]

contains the programs of type A which have access to n variables.

41

Page 42: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Presheaf models

This defines a covariant presheaf

A[n] : Inj −→ Set

on the category Inj of natural numbers and injections.

The action of the injections on A are induced by the operations

collect〈loc〉 : A[n] −→ A[n+1]

defined for 0 ≤ loc ≤ n.

42

Page 43: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Local stores [Plotkin – Power]

The slightly intimidating monad

TA : n 7→ S[n]⇒

∫ p∈Inj S[p]× A[p] × Inj(n, p)

on the presheaf category [Inj,Set] where the contravariant presheaf

S[p] = V p

describes the states available at degree p.

43

Page 44: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Graded arities

A graded arity is defined as a finite sum of representables

[ p0 , · · · , pn ] = 〈0〉 + · · · + 〈0〉︸ ︷︷ ︸p0 times

+ · · · + 〈n〉 + · · · + 〈n〉︸ ︷︷ ︸pn times

where each representable presheaf

〈n〉 : Inj −→ Set

is defined as

〈n〉 = p 7→ Inj(n, p)

44

Page 45: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Graded arities

This defines a full and faithful functor

Σ Inj op−→ Inj op

which generalizes the full and faithful functor

FinSet −→ Set

encountered in the case of finitary monads.

45

Page 46: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Graded monads

Definition. A monad

T : [Inj,Set] −→ [Inj,Set]

is graded when the diagram

[Inj,Set]

id19

Σ Inj opi

//

T◦ i

AA������������������������

[Inj,Set]

T

^^=========================

exhibits the functor T as a left Kan extension of T ◦ i along i.

46

Page 47: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Graded monad

A monad T on the category [Inj,Set] is graded when every map

〈n〉 −→ TA

factors as

〈n〉 e−→ T [p0, . . . , pk]

T f−→ TA

for a pair of maps

〈n〉 −→ T [p0, . . . , pk] [p0, . . . , pk] −→ A.

47

Page 48: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Graded monad

Moreover, the factorization should be unique up to zig-zag:

T [p0, · · · , pi]

Tu

��

T f1

%%KKKKKKKKKKKKKKKKKKKKKKKK

〈n〉

e1

99ssssssssssssssssssssssss

e2%%JJJJJJJJJJJJJJJJJJJJJJJ TA

T [q0, · · · , q j]

T f2

99tttttttttttttttttttttttt

48

Page 49: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Motivating example

Theorem. The local state monad

TA : n 7→ S[n]⇒

∫ p∈Inj S[p]× A[p] × Inj(n, p)

is a graded monad on the presheaf category [Inj,Set].

49

Page 50: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Graded theories

A stratified version of algebraic theories

Page 51: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

The Lawvere theory of a graded monad

The Lawvere theory Θ T associated to a graded monad

T : [Inj,Set] −→ [Inj,Set]

is the full subcategory of [Inj,Set] T with the graded arities

[ p0 , · · · , pn ]

as objects.

Remark. The category Θ T has finite sums.

51

Page 52: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Modules over the category Inj

An Inj-module is a category A equipped with an action

� : Inj ×A −→ A

(m,A) m � A

satisfying the expected properties:

(p + q) � A = p � (q � A) 0 � A = A

52

Page 53: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Modules over the category Inj

A category A equipped with an endofunctor

D : A −→ A

and two natural transformations

permute : D ◦D −→ D ◦D collect : Id −→ D

depicted as follows in the language of string diagrams:

D

D

D

D

D

53

Page 54: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Yang-Baxter equation

D

D

D

D

D

D

=D

D

D

D

D

D

54

Page 55: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Symmetry

D

D

D

D

=D

D

D

D

55

Page 56: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Interaction dispose – permute

D

D D

=D

D D

DD

D

=DD

D

56

Page 57: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Graded theories

A graded theory is a category with finite products with objects

[ p0 , · · · , pn ] = 〈0〉 × · · · × 〈0〉︸ ︷︷ ︸p0 times

× · · · × 〈n〉 × · · · × 〈n〉︸ ︷︷ ︸pn times

equipped with an action of the category Inj satisfying

D(A × B) � DA × DB D(1) � 1

In particular

D [ p0 , · · · , pn ] = [ 0 , p0 , · · · , pn ]

57

Page 58: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

The trivial graded theory

Σ Inj op is the free Inj-module with finite sums such that

D(A + B) � DA + DB D(0) � 0

Π Inj is the free Inj-module with finite products such that

D(A × B) � DA × DB D(1) � 1

58

Page 59: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

The graded theory of local stores

Let |מ be the graded theory associated to the monad of localstores.

Fact.

|מ is the free Inj-module with finite sums such that

D(A + B) � DA + DB D(0) � 0

such that D is a dynamic mnemoid.

59

Page 60: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Dynamic mnemoids

A dynamic mnemoid is a pair of sets

A[0] A[1]

equipped with the following operations

lookup : AV[1] −→ A[1]

update〈val〉 : A[1] −→ A[1]

fresh〈val〉 : A[1] −→ A[0]

collect : A[0] −→ A[1]

satisfying a series of basic equations.

60

Page 61: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Garbage collect : fresh – dispose

val = id

61

Page 62: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Interaction fresh – update

val2 val1 = val2

62

Page 63: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Interaction fresh – lookup

x

y

true = truex

x

y

false = falsey

63

Page 64: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Model of a graded theory

A model of a graded theory |מ is a functor

M : |מ −→ [Inj,Set]

which preserves the finite products and the action of D.

A stratified version of the usual algebraic theories

64

Page 65: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

The graded theory of local mnemoids

Main theorem [after Plotkin and Power]

The category of models of the theory |מ of local mnemoids

is equivalent to

the category of algebras of the local state monad

65

Page 66: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Local stores in string diagrams

A graphical account of memory calls

Page 67: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Annihilation lookup – update

x =

true

falsex

x

The equation D(A × B) � DA ×DB means

that space commutes with time ramification !!!

Page 68: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Interaction update – update

val1val2 = val2

68

Page 69: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Interaction update – lookup

true

y

x

= truex

69

Page 70: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Interaction update – lookup

false

y

x

= falsey

70

Page 71: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Interaction fresh – dispose

val

D

D

D

D

D

D

=D

D

D

D

D

D

71

Page 72: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Interaction fresh – update

D

D

D

D

D

D

D

val1val2 = D

D

D

D

D

D

D

val2

72

Page 73: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Interaction fresh – lookup

true

D

D

D

y

x

= true

D

D

D

y

73

Page 74: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Interaction fresh – lookup

false

D

D

D

y

x

= false

D

D

D

y

74

Page 75: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Interaction fresh – permutation

val

D

D

D

D

D

D

D

= valD

D

D

D

D

D

D

75

Page 76: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

The Segal condition

A basic tool in higher dimensional algebra

76

Page 77: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

In higher dimensional algebra

Exactly the same categorical combinatorics !!!

77

Page 78: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

In higher dimensional algebra

A globular set is defined as a contravariant presheaf over the cate-gory

0s //

t// 1

s //

t// 2

s //

t// · · ·

defined by the equations

s ◦ s = s ◦ t t ◦ s = t ◦ t

Anω-category is then defined as an algebra of a particular monad T.

Is the notion of ω-category equational ?

78

Page 79: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Level 1 : the free category monad

A category C is a graph where every path

A0f1 // A1

f2 // A2f3 // · · ·

fn // An

defines an edge

A0◦n ( f1, ··· , fn)

// An

where the operations ◦n are required to be associative.

the arities of the theory are finite paths rather than finite sets

Page 80: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Category with arities

A fully faithful and dense functor

i0 : Θ0 −→ A

where Θ0 is a small category.

Typical example: the full subcategory Θ0 of linear graphs

[n] = 0 // 1 // · · · // n

in the category Graph.

80

Page 81: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

The nerve functor

This induces a fully faithful functor

nerve : A −→ Θ̂0

which transports every object A of the category A into the presheaf

nerve : Θ0 −→ Set

p 7→ A( i0p , A )

81

Page 82: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

The nerve functor

Page 83: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Definition of a monad T with arity

◦ the functor T is the left kan extension of T ◦ i0 along the functor i0

A

id08

Θ0 i0//

T◦i0

EE������������������������

A

T

XX111111111111111111111111

This enables to reconstruct T from its restriction to the arities

83

Page 84: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Monads with arities

◦ this left kan extension is preserved by the nerve functor:

Θ̂0

A

nerve

OO

id08

Θ0 i0//

T◦i0

EE�������������������������

A

T

YY2222222222222222222222222

84

Page 85: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

A purely combinatorial formulation

For every object A, the canonical morphism

∫ p∈Θ0A(i0n,Ti0p) ×A(i0p,A) −→ A(i0n,TA)

is an isomorphism.

85

Page 86: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Unique factorization up to zig-zag

Every map

n −→ TA

in the category A decomposes as

n e−→ Tp

T f−→ TA

A finite number of words encounters a finite number of letters

A finite path in the free category TA encounters a finite path in A

86

Page 87: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Unique factorization up to zig-zag

The factorization should be unique up to zig-zag of

Ti0p

Ti0u

��

T f1

!!DDDDDDDDDDDDDDDDD

i0n

e1

=={{{{{{{{{{{{{{{{

e2!!CCCCCCCCCCCCCCCC

TA

Ti0qT f2

==zzzzzzzzzzzzzzzzz

87

Page 88: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Model of an algebraic theory

A model A of a Lawvere theory L is a presheaf

A : ΘopL

−→ Set

such that the induced presheaf

Θop0

i0 //ΘopL

A //Set

is representable along i0.

88

Page 89: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Key theorem

The category of T-modules

is equivalent to

the category of models of the theory ΘT

This property holds for every monad T with arities Θ0.

89

Page 90: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Algebraic theories with arities

A 2-dimensional approach to Lawvere theories

90

Page 91: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Algebraic theory with arities

An algebraic theory L with arities

i0 : Θ0 −→ A

is an identity-on-object functor

L : Θ0 −→ ΘL

such that...

91

Page 92: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Algebraic theories with arities

... there exists a functor

F : A −→ A

making the diagram

Θ̂0∃L // Θ̂L

L∗ // Θ̂0

nerve

OO

nerve

OO

AF // A

commute up natural isomorphism.

92

Page 93: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Algebraic theories with arities

Set

/7

Θop0 L

//

nerve(A)

EE

ΘopL

left Kan extension

YY4444444444444444444444444

This simply means that the free construction works...

93

Page 94: Programming Languages in String Diagrams [ four ]mellies/slides/oregon-slides-2011-D.pdf · 2019. 12. 6. · 4. Finitary monads Alternative definition. A monad T : Set ! Set is finitary

Theorem

the category of algebraic theories with arity (A, i0)

is equivalent to

the category of monads with arity (A, i0)

This generalizes the traditional correspondence

algebraic theories ∼ finitary monads

Also extends the result by Power on enriched Lawvere theories

94