Applied category theory
The emerging science of compositionality
@KenScambler
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
The emerging science of compositionality
@KenScambler
From “Seven Sketches of Compositionality” Fong & Spivak (2018)
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
years
disciplines
The meaning of a complex expression is determined by:
BIG programs that work?
BIG electric circuits that work?
BIG Feynman diagrams that describe real physics?
BIG resource plans that are feasible?
BIG networks of agents that can solve problems?
c d e f h j a b i g
a b
a b Compose any two
ab
a b c
a b c
a b c
a b c
abc
abc
a b c Just the sum of its parts with
abc
a b c Uh-oh! We need external data
a
a
a
c d e f h j a b i g
a b The building blocks are called morphisms The colours are called objects
a b Can only compose when the colours match
ab The middle bit disappears
a b
c
a b
c
a b
c
a b
c
abc
a
a
a
from “Complex Adaptive System Design” blog posts by John C. Baez (2016-2019) “Network Models” by Baez, Foley, Moeller, Pollard (2017)
Helo 1
Target 1
Port 1
Helicopter knows the target and home base
In comms range In comms range My port Intent to rescue
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
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
Helo network UAV network Overlaying is monoidal; you can always overlay
Helo network UAV network Overlaying is monoidal; you can always overlay
ay
Combined network Overlaying is monoidal; you can always overlay
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
1 2 3 4 5 6 7 8 9
“Take 3 networks of 3, 4 and 2 vertices; return a network of 9 vertices”
Intent to rescue
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
Network-1 Network-2 Network-3
Nope! You can’t compose the networks themselves. Network-1 Network-2 Network-3
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
a c b d
a c b
a c b
a c b
a c b
abc
a
a
a
a
receiveInvoice
User Invoice Signature Receipt
storeReceipt
Receipt Shoebox Shoebox
login
Username Password User
receiveInvoice
Invoice Signature
storeReceipt
Shoebox Shoebox
login
Username Password
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) }
Helicopter Port UAV Target my port Intent to rescue Comms channel
Havana
Rescue- Scene UAV-Search-Net Homebase
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
From “Seven Sketches of Compositionality” Fong & Spivak (2018)
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
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
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
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
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
Tensoring forms a monoid (up to isomorphism)
lemon butter sugar make lemon filling
… on the objects of the category
lemon ⨂ butter ⨂ sugar lemon filling
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
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
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
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
unbaked pie
baked pie
prepare lemon meringue pie bake pie
prepare lemon meringue pie
unbaked pie
baked pie
bake pie
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
Simon Brown
Level 1
Level 1
Level 2
Level 1
Level 2
Level 3
from “The operad of wiring diagrams: formalizing a graphical language for databases, recursion and plug-and-play circuits” by David I. Spivak (2013)
Inputs x1, x2, x3
Input types {s,r,t} {w, x, y, z} {u, v} Output type {a,b,c,d,e}
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 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 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
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
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)
mine the benefits of compositionality wherever they may be found
important part
promoting
software has eaten the world
adopters
John C. Baez @johncarlosbae z Jules Hedges @_julesh_
@DrEugeniaCheng Jade Master @JadeMasterMath Tai-Danae Bradley @math3ma Joe Moeller @CreeepyJoe Statebox @statebox Jelle Herold @wires_wires Fabrizio Remano Genovese @fabgenoves e
(2018)
databases, recursion and plug-and-play circuits” by David I. Spivak (2013)