Applied category theory @KenScambler The emerging science of - - PowerPoint PPT Presentation

applied category theory
SMART_READER_LITE
LIVE PREVIEW

Applied category theory @KenScambler The emerging science of - - PowerPoint PPT Presentation

Applied category theory @KenScambler The emerging science of compositionality Category theory Applied category theory prepare lemon meringue pie prepared crust fill crust lemon unbaked lemon make butter lemon pie filling lemon


slide-1
SLIDE 1

Applied category theory


The emerging science of compositionality

@KenScambler

slide-2
SLIDE 2

Category theory

slide-3
SLIDE 3

From “Seven Sketches of Compositionality” Fong & Spivak (2018)

Applied category theory

prepare lemon meringue pie

make lemon filling

fill crust make meringue

separate egg

prepared crust lemon butter sugar yolk egg white sugar meringue lemon filling unbaked lemon pie unbaked pie

add meringue

slide-4
SLIDE 4

Applied category theory

  • Emerging field!
  • Explosion of papers, research, development in last 5

years

  • Builds a common vocabulary of composition across

disciplines

  • Enables intuitive, precise visual representations
slide-5
SLIDE 5

Brand new ACT Journal (2019?)

slide-6
SLIDE 6

Brand new ACT Book (2018)

slide-7
SLIDE 7

ACT Topics & papers

slide-8
SLIDE 8

Q: Is functional programming applied category theory?

slide-9
SLIDE 9

Q: Is functional programming applied category theory? A: Yes! (…arguably)

slide-10
SLIDE 10
slide-11
SLIDE 11

Plan

  • I want to put applied category theory on your roadmap
  • The big idea: compositionality
  • Case study: Complex adaptive system design: military search & rescue
  • Four concepts of composition:
  • Monoids
  • Categories
  • Operads
  • Monoidal categories
  • Two graphical languages:
  • String diagrams
  • Wiring diagrams
slide-12
SLIDE 12

Compositionalit y

slide-13
SLIDE 13

The meaning of a complex expression is determined by:


  • 1. The meaning of the constituent parts
  • 2. The rules for how those parts are combined

Frege’s Principle of Compositionality

slide-14
SLIDE 14

Making big things

Compositionality lets us

slide-15
SLIDE 15

Making big things
 


  • ut of little things

Compositionality lets us

slide-16
SLIDE 16

Compositionality lets us

Making big things
 


  • ut of little things


preserving guarantees

slide-17
SLIDE 17

Compositionality applied

  • Little programs that work 


BIG programs that work?


  • Little electric circuits that work


BIG electric circuits that work?


  • Little Feynman diagrams that describe real physics 


BIG Feynman diagrams that describe real physics?


  • Little resource plans that are feasible 


BIG resource plans that are feasible?


  • Little networks of agents that can solve problems 


BIG networks of agents that can solve problems?

slide-18
SLIDE 18

Compositionality distilled - monoids

c d e f h j a b i g

slide-19
SLIDE 19

a b

slide-20
SLIDE 20

a b Compose any two

slide-21
SLIDE 21

ab

slide-22
SLIDE 22

Associativity – no need for brackets

a b c

slide-23
SLIDE 23

Associativity – no need for brackets

a b c

slide-24
SLIDE 24

Associativity – no need for brackets

a b c

slide-25
SLIDE 25

Associativity – no need for brackets

a b c

slide-26
SLIDE 26

Associativity – no need for brackets

abc

slide-27
SLIDE 27

With associativity

abc

=

a b c Just the sum of its parts with

slide-28
SLIDE 28

Without associativity

+

  • r

abc

=

a b c Uh-oh! We need external data

slide-29
SLIDE 29

Identity – doesn’t do anything when you compose

a

slide-30
SLIDE 30

Identity – doesn’t do anything when you compose

a

slide-31
SLIDE 31

Identity – doesn’t do anything when you compose

a

slide-32
SLIDE 32

Compositionality distilled - categories

c d e f h j a b i g

slide-33
SLIDE 33

a b The building blocks are called morphisms The colours are called objects

slide-34
SLIDE 34

a b Can only compose when the colours match

slide-35
SLIDE 35

ab The middle bit disappears

slide-36
SLIDE 36

a b

Associativity – no need for brackets

c

slide-37
SLIDE 37

a b

Associativity – no need for brackets

c

slide-38
SLIDE 38

a b

Associativity – no need for brackets

c

slide-39
SLIDE 39

a b

Associativity – no need for brackets

c

slide-40
SLIDE 40

abc

Associativity – no need for brackets

slide-41
SLIDE 41

a

Identities – don’t do anything when you compose

slide-42
SLIDE 42

a

Identities – don’t do anything when you compose

slide-43
SLIDE 43

a

Identities – don’t do anything when you compose

slide-44
SLIDE 44

Case study: Complex Adaptive System Design

from 
 “Complex Adaptive System Design” blog posts by John C. Baez (2016-2019) “Network Models” by Baez, Foley, Moeller, Pollard (2017)

slide-45
SLIDE 45

Military research: search & rescue

  • Systems of systems
  • Many different kinds of networks
  • Complex realtime behaviour
  • How to connect them all?
slide-46
SLIDE 46

Helo 1

Target 1

Port 1

Helicopter knows the target and home base

In comms range In comms range My port Intent to rescue

slide-47
SLIDE 47

Helo 1 UAV 1

Target 1

UAV knows the target, and the helicopter as a home base

In comms range Intent to rescue My port

slide-48
SLIDE 48

Overlay the networks We now have a bigger network working together

Helo 1

Target 1

Port 1 My port Intent to rescue UAV 1 My port In comms range In comms range In comms range Intent to rescue

slide-49
SLIDE 49

Helo network UAV network Overlaying is monoidal; you can always overlay

slide-50
SLIDE 50

Helo network UAV network Overlaying is monoidal; you can always overlay

  • verl

ay

slide-51
SLIDE 51

Combined network Overlaying is monoidal; you can always overlay

slide-52
SLIDE 52

How to sew together unrelated networks?

Helo 1 UAV 1 Target 1 UAV 2 UAV 3 UAV 5

Rescue-Scene

UAV 4 In comms range In comms range

UAV-Search-Net

Helo 2

Homebase

Intent to rescue My port Havana

slide-53
SLIDE 53

1 2 3 4 5 6 7 8 9

How to sew together unrelated networks?

“Take 3 networks of 3, 4 and 2 vertices; return a network of 9 vertices”

Intent to rescue

slide-54
SLIDE 54

Helo 1 UAV 1 Target 1 UAV 2 UAV 3 UAV 5 UAV 4 In comms range In comms range Helo 2 In comms range Intent to rescue My port Intent to rescue Havana

slide-55
SLIDE 55

Is that a category?

Network-1 Network-2 Network-3

slide-56
SLIDE 56

Nope! You can’t compose the networks themselves. Network-1 Network-2 Network-3

slide-57
SLIDE 57

Morphisms with lots of inputs?

The ”type” is the number of vertices expected in subnetworks “Take 3 networks of 3, 4 and 2 vertices; return a network of 9 vertices”

3 4 2 9

slide-58
SLIDE 58

Compositionality distilled – operads

a c b d

slide-59
SLIDE 59

a c b

slide-60
SLIDE 60

a c b

slide-61
SLIDE 61

a c b

slide-62
SLIDE 62

a c b

slide-63
SLIDE 63

abc

slide-64
SLIDE 64

a

slide-65
SLIDE 65

a

slide-66
SLIDE 66

a

slide-67
SLIDE 67

a

slide-68
SLIDE 68

Obvious example: types & functions

receiveInvoice

User Invoice Signature Receipt

storeReceipt

Receipt Shoebox Shoebox

login

Username Password User

slide-69
SLIDE 69

receiveInvoice

Invoice Signature

storeReceipt

Shoebox Shoebox

login

Username Password

slide-70
SLIDE 70

Invoice Signature

fullInvoiceFlow

Shoebox Shoebox Username Password


 def fullInvoiceFlow(username,
 password, invoice, signature, shoebox) {
 user = login(username, password) receipt = receiveInvoice(user, invoice, signature) return storeReceipt(receipt, shoebox) }


slide-71
SLIDE 71

Mapping it to reality

Helicopter Port UAV Target my port Intent to rescue Comms channel

Havana

Rescue- Scene UAV-Search-Net Homebase

slide-72
SLIDE 72

Mapping it to reality

Helicopter Port UAV Target my port Intent to rescue Comms channel

Havana

Rescue-Scene := ...
 UAV-Search-Net := ...
 Homebase := ... 
 joinNetworks(Rescue-Scene, 
 UAV-Search-Net, 
 Homebase) To actually use an operad, translate it to the operad of sets & functions, preserving composition & identity

slide-73
SLIDE 73

From “Seven Sketches of Compositionality” Fong & Spivak (2018)

String diagrams

prepare lemon meringue pie

make lemon filling

fill crust make meringue

separate egg

prepared crust lemon butter sugar yolk egg white sugar meringue lemon filling unbaked lemon pie unbaked pie

add meringue

slide-74
SLIDE 74

prepare lemon meringue pie

make lemon filling

fill crust make meringue

separate egg

prepared crust lemon butter sugar yolk egg white sugar meringue lemon filling unbaked lemon pie unbaked pie

add meringue

morphisms

slide-75
SLIDE 75

prepare lemon meringue pie

make lemon filling

fill crust make meringue

separate egg

prepared crust lemon butter sugar yolk egg white sugar meringue lemon filling unbaked lemon pie unbaked pie

add meringue

  • bjects
slide-76
SLIDE 76

prepare lemon meringue pie

make lemon filling

fill crust make meringue

separate egg

prepared crust lemon butter sugar egg sugar unbaked pie

add meringue

composition

slide-77
SLIDE 77

prepare lemon meringue pie

make lemon filling

fill crust make meringue

separate egg

prepared crust lemon butter sugar yolk egg white sugar meringue lemon filling unbaked lemon pie unbaked pie

add meringue

tensoring

slide-78
SLIDE 78

Tensoring forms a monoid (up to isomorphism)

lemon butter sugar make 
 lemon filling

… on the objects of the category

lemon ⨂ butter ⨂ sugar lemon filling

slide-79
SLIDE 79

Monoidal categories

Category C
 Tensor operation 
 ⨂ : (object, object) -> object such that (a ⨂ b) ⨂ c ≃ a ⨂ (b ⨂ c) Unit object I : object such that a ⨂ I ≃ I ⨂ a ≃ a

slide-80
SLIDE 80

Monoidal categories

f g

x y y z

f g

x y z

f g

x y y z x y y z

f ⨂ g

= Horizontal composition Vertical composition

x ⨂ y

f ⨂ g

=

y ⨂ z

slide-81
SLIDE 81

Diagrams inside diagrams

prepare lemon meringue pie

make lemon filling

fill crust make meringue

separate egg

prepared crust lemon butter sugar yolk egg white sugar meringue lemon filling unbaked lemon pie unbaked pie

add meringue Make lemon filling

lemon butter sugar

Blend

yolk

Beat Combine

lemon filling

slide-82
SLIDE 82

Diagrams inside diagrams

prepare lemon meringue pie fill crust make meringue

separate egg

prepared crust lemon butter sugar yolk egg white sugar meringue lemon filling unbaked lemon pie unbaked pie

add meringue

Blend Beat Combine

slide-83
SLIDE 83
  • ven

unbaked pie

baked pie

  • ven

prepare lemon meringue pie bake pie

prepare lemon meringue pie

slide-84
SLIDE 84
  • ven

unbaked pie

baked pie

  • ven

bake pie

Surprise! It’s another operad

slide-85
SLIDE 85

Lemon Meringue Pie operad

prepare lemon meringue pie

sugar ⨂ white meringue prepared crust ⨂ lemon ⨂ butter ⨂ sugar ⨂ egg ⨂ sugar unbaked pie egg yolk ⨂ white lemon ⨂ butter ⨂ sugar ⨂ yolk lemon filling prepared crust ⨂ lemon filling unbaked lemon pie unbaked lemon pie ⨂ meringue unbaked pie

slide-86
SLIDE 86

String diagrams in software architecture

  • Fantastic for software design
  • I’ve used them for years to train junior & senior developers
  • Modularity, boundaries
slide-87
SLIDE 87

Simon Brown

slide-88
SLIDE 88

Level 1

slide-89
SLIDE 89

Level 1

Level 2

slide-90
SLIDE 90

Level 1

Level 2

Level 3

slide-91
SLIDE 91

Level 1

Level 2

Level 3

Level 4 Operad! (maybe)

slide-92
SLIDE 92

Operad of wiring diagrams

from 
 “The operad of wiring diagrams: formalizing a graphical language for databases, recursion and plug-and-play circuits” by David I. Spivak (2013)

slide-93
SLIDE 93

Inputs x1, x2, x3

slide-94
SLIDE 94

Input types {s,r,t} {w, x, y, z} {u, v} Output type {a,b,c,d,e}

slide-95
SLIDE 95
slide-96
SLIDE 96

Compositional SQL queries

SELECT L.student, L.address FROM attends a1, gender g1, attends a2, gender g2, lives L WHERE a1.student=g1.student AND a2.student=g2.student AND L.student=g1.student AND a1.course=a2.course AND g1.gender=‘male’ AND g2.gender=‘female’

slide-97
SLIDE 97

SELECT L.student, L.address FROM attends a1, gender g1, attends a2, gender g2, lives L WHERE a1.student=g1.student AND a2.student=g2.student AND L.student=g1.student AND a1.course=a2.course AND g1.gender=‘male’ AND g2.gender=‘female’

slide-98
SLIDE 98

SELECT L.student, L.address FROM attends a1, gender g1, attends a2, gender g2, lives L WHERE a1.student=g1.student AND a2.student=g2.student AND L.student=g1.student AND a1.course=a2.course AND g1.gender=‘male’ AND g2.gender=‘female’

Tables Constants

slide-99
SLIDE 99

SELECT L.student, L.address FROM attends a1, gender g1, attends a2, gender g2, lives L WHERE a1.student=g1.student AND a2.student=g2.student AND L.student=g1.student AND a1.course=a2.course AND g1.gender=‘male’ AND g2.gender=‘female’

SELECT

slide-100
SLIDE 100

SELECT L.student, L.address FROM attends a1, gender g1, attends a2, gender g2, lives L WHERE a1.student=g1.student AND a2.student=g2.student AND L.student=g1.student AND a1.course=a2.course AND g1.gender=‘male’ AND g2.gender=‘female’

WHERE 
 (wiring)

slide-101
SLIDE 101

In conclusion

  • Applied category theory is an exciting new field that seeks to

mine the benefits of compositionality wherever they may be found

  • Supports marvelous graphical languages
  • Early days!
  • Watch this space
slide-102
SLIDE 102

The future

  • Anything where “making big things out of little things” is an

important part

  • So far: category theorists discovering applications and

promoting

  • Industry might eventually begin to lead the charge
  • Computer science & programming will be at the forefront:

software has eaten the world

  • Functional programming will be at the forefront: we are early

adopters

slide-103
SLIDE 103

People to follow on Twitter

John C. Baez
 @johncarlosbae z Jules Hedges
 @_julesh_

  • Dr. Eugenia Cheng


@DrEugeniaCheng Jade Master
 @JadeMasterMath Tai-Danae Bradley
 @math3ma Joe Moeller
 @CreeepyJoe Statebox
 @statebox Jelle Herold
 @wires_wires Fabrizio Remano Genovese
 @fabgenoves e

slide-104
SLIDE 104

Further reading

  • “Seven Sketches of Compositionality” by Brendan Fong, David I. Spivak

(2018)

  • “Applied category theory course” by John C. Baez (2018)
  • “What is applied category theory?” by Tai-Danae Bradley (2018)
  • “Network models” by Baez, Foley, Moeller, Pollard (2017)
  • “The operad of wiring diagrams: formalizing a graphical language for

databases, recursion and plug-and-play circuits” by David I. Spivak (2013)