Kris Brown
(press s
for speaker notes, available online here)
11/1/23
$$
$$
Natural science
Computer science
Math + CS + Natural science
In the course so far, you’ve learned to:
Physical system: chemical reaction network
\[ 2 H_2O \rightarrow 2 H_2 + O_2 \] \[ H_2 \leftrightarrow 2 H \]
Mathematical model: ODEs
\[\frac{d[H_2O]}{dt} = -k_1 \cdot [H_2O]^2 + ...\]
\[\frac{d[H_2]}{dt} = 2 k_1 \cdot [H_2O]^2 - k_{2f} [H_2] + ...\]
Computational implementation: Python
def four_reactor(time):
V1, V2, V3, V4 = 20.0, 30.0, 20.0, 30.0 # L
in_concs = [996, 0.4, 0.05, 0.05] # g/L
def yprime(t, concs):
# 4 species in four tanks: 1_1, 1_2, 2_1, 2_2
H2O2_1_1, H2O_1_1, H_1_1, H2O2_1_1, ...
H2O2_2_2, H2O_2_2, H_2_2, H2O2_2_2 = concs
# NEW MATH TO BE WORKED OUT
# FROM SCRATCH
solve_ivp(yprime, [0, time], [.1,.4,.3,.5])
\[ 2 A + B \rightarrow B + C \] \[ A + D \rightarrow B \]
\[ B \rightarrow C \] \[ 2 C \rightarrow A \]
Two students complete the same lab assignment but get different results.
from scipy.integrate import solve_ivp
def my_python_code_to_solve_ode(t):
def y_prime(_, specs):
c1, c2, c3, c4 = specs # corresponds to D, C, B, A
f1 = c3 # corresponds to bc
f3 = c1*c4 # corresponds to ac
f2 = c2*c2 # corresponds to cd
f4 = c3+c4**2 # corresponds to ab
return [-f3, ...]
solve_ivp(y_prime, [0, t], [.1, .1, .1, .1])
This is hard to verify, especially if the code is big.
Goal: define a mathematical object which can represent a chemical reaction network.
A set is a collection of things.
Membership notation
\(red \in \{red,blue,green\}\)
\(pink \notin \{red,blue,green\}\)
\(false \in \mathbb{B}\)
\(35 \in \mathbb{N}\)
\(6.02 \times 10^{23} \in \mathbb{R}\)
\(2+3i \notin \mathbb{R}\)
A function is a map between sets.
\(\{red \mapsto \top, green \mapsto \top, blue \mapsto \bot\}\)
\(\{\bullet \mapsto \pi\}\)
A function (or a map between sets, written \(f: A \rightarrow B\)) assigns to each element of set \(A\) an element of set \(B\).
We denote the element that \(f\) sends \(a\) to as \(f(a)\). \(A\) the domain and \(B\) the codomain of \(f\).
We can explicitly write a function as a set of pairs \(\{a_1 \mapsto b_n, a_2 \mapsto b_m, ...\}\).
Some examples of functions:
\(\{red \mapsto \top, green \mapsto \top, blue \mapsto \bot\}\)
\(\{\bullet \mapsto \pi\}\)
Other functions:
Which of the following is a function?
A function (\(f: A \rightarrow B\)) assigns to each element of set \(A\) an element of set \(B\).
The identity function for a set \(X\) sends each \(x \in X\) to itself.
The composition of functions \(f: A\rightarrow B\) and \(g: B \rightarrow C\) is a function \(f ; g: A \rightarrow C\) which sends each \(a \in A\) to \(g(f(a))\).
An isomorphism between sets \(A\) and \(B\) is a function \(f: A \rightarrow B\) such that there exists an inverse function \(f^{-1}: B \rightarrow A\) such that \(f;f^{-1}\) and \(f^{-1};f\) are identity functions.
Quick way to check if function is an iso
If both answers are “no”, then it’s an isomorphism!
[see whiteboard]
A graph is something which has the following components:
To connect to earlier drawings of sets, we could draw a graph like this:
The graph itself looks like this:
A graph is something which has the following components:
To connect to earlier drawings of sets, we could draw a graph like this:
The graph itself looks like this:
[see whiteboard]
Suppose we have the chemical reaction network:
\[ ab: A \rightarrow B \] \[ ac: A \rightarrow C \] \[ bc: B \rightarrow C \]
How might we represent this with a graph?
What would you have to do in order to solve that problem?
A graph mapping \(f: G_1 \rightarrow G_2\) is a pair of compatible functions:
Compatible means \(f_E;src_2 = src_1;f_V\) and \(f_E;tgt_2 = tgt_1;f_V\).
[see whiteboard]
A graph isomorphism is a graph mapping where \(f_V\) and \(f_E\) are isomorphisms.
Two students complete the same lab assignment but get different results.
from scipy.integrate import solve_ivp
def my_python_code_to_solve_ode(t):
def y_prime(tim, specs):
c1, c2, c3, c4 = specs # corresponds to D, C, B, A
f1 = c3 # corresponds to bc
f3 = c4 # corresponds to ac
f2 = c2 # corresponds to cd
f4 = c4 # corresponds to ab
return [f2, f3 + f1 - f2, f4 - f1, -f4 - f2]
solve_ivp(y_prime, [0, t], [.1, .1, .1, .1])
This is hard to verify, especially if the code is big.
Solution
If the two students had first defined their models as graphs, then they could answer their question by computing whether or not their graphs are isomorphic.
Problem with graphs
Chemical reactions contain multiple inputs and outputs.
\[\square: A\rightarrow 2B\]
\[\blacksquare: C+D\rightarrow A\]
Problem with graphs
Chemical reactions contain multiple inputs and outputs.
A Petri net consists of:
A Petri net consists of:
E.g. the reaction network: \(\square: A\rightarrow 2B\) and \(\blacksquare: C+D\rightarrow A\).
The Petri net is drawn like this:
[see whiteboard]
Suppose we have the chemical reaction network:
\[ A + B \rightarrow B + C\] \[ A \rightarrow C \]
How might we represent this with a Petri net?
Reminder from last slide:
\(\square: A\rightarrow 2B\)
\(\blacksquare: C+D\rightarrow A\).
A map of Petri nets \(f: P_1 \rightarrow P_2\) consists of four compatible functions, \(f_S: S_1 \rightarrow S_2,\ f_T: T_1 \rightarrow T_2,\ f_I: I_1 \rightarrow I_2,\ f_O: O_1 \rightarrow O_2\).
A Petri net isomorphism is a Petri net map where all four functions are iso.
\[ 2 A + B \rightarrow B + C \] \[ A + D \rightarrow B \]
\[ B \rightarrow C \] \[ 2 C \rightarrow A \]
Two students complete the same lab assignment but get different results.
from scipy.integrate import solve_ivp
def my_python_code_to_solve_ode(t):
def y_prime(_, specs):
c1, c2, c3, c4 = specs # corresponds to D, C, B, A
f1 = c3 # corresponds to bc
f3 = c1*c4 # corresponds to ac
f2 = c2*c2 # corresponds to cd
f4 = c3+c4**2 # corresponds to ab
return [-f3, ...]
solve_ivp(y_prime, [0, t], [.1, .1, .1, .1])
This is hard to verify, especially if the code is big.
Rxn Net Representation | Advantage |
---|---|
Traditional text-based format | Communication |
Code representation | Computation of concentrations over time |
Petri nets (drawing) | Visualization |
Petri nets (four sets, four functions) | Computation on the network itself |
Next lecture:
Applied category theory textbooks
Category theory textbooks
Blogs
A function \(f: A \rightarrow B\) assigns to each element of set \(A\) an element of set \(B\).
An isomorphism between sets \(A\) and \(B\) is a function \(f: A \rightarrow B\) such that there exists an inverse function \(f^{-1}: B \rightarrow A\) such that \(f;f^{-1}\) and \(f^{-1};f\) are identity functions.
A graph has a set of edges, \(E\), a set of vertices \(V\), and two functions \(E\rightarrow V\) called src and tgt.
The graph on the left is visualized like this:
A graph mapping \(f: G_1 \rightarrow G_2\) is a pair of compatible functions \(f_V: V_1 \rightarrow V_2\) and \(f_E: E_1 \rightarrow E_2\). (Compatible means \(f_E;src_2 = src_1;f_V\) and \(f_E;tgt_2 = tgt_1;f_V\))
A Petri net consists of:
A map of Petri nets \(f: P_1 \rightarrow P_2\) consists of four compatible functions for \(S\), \(T\), \(I\), and \(O\).
def combined_rxn_network(t): # tedious to construct
def yprime(t, species):
cH2O, cOH, cH, cH2O2, cH2 = species
k1, k2, k3 = [0.02, 0.01, 0.3]
f1 = k1 * cH20
f2 = k2 * cH * cOH
f3 = k3 * cH2O2 * cH2
return [f3-f1, f1-f2, f1-f2, -f3, -f3]
solve_ivp(yprime, [0, t], [.1,.4,.3])
# Preferred alternative
overlap = Overlap(rxn_network1, rxn_network2, ...)
combined_rxn_network = glue(overlap)
Gluing together graphs
Gluing together Petri nets
Gluing together dynamical systems
Reinvent the wheel each time? Or general solution possible?
Beyond being precise, we want to be generalizable.
Ideally there is just one definition that works for:
We will do this with the technique of universal properties.
Part 1. The notion of being empty
Part 2. Placing things side-by-side
For any set \(X\), there exists exactly one function \(\{\} \rightarrow X\).
This is a function because it assigns a value of \(X\) for every element of \(\{\}\).
This function is unique for each \(X\) because there are no other ways to make this function.
\(\{\}\) is an initial object because this is true for any set \(X\).
A set with even a single element doesn’t have this property:
What is special about defining ‘emptiness’ via the diagram \(0 \rightarrow X\) is that it can be interpreted in many contexts, not just sets and functions.
Is there a graph which plays the role of “initial object” in the context of graphs and graph mappings?
When \(E\) and \(V\) are empty, the resulting graph is an initial object.
When \(S\), \(T\), \(I\), and \(O\) are empty, the resulting Petri net is an initial object.
Universal property of being an initial object:
We can think of other contexts than the ones discussed so far:
Not every context has an initial object
Consider the integers, \(\mathbb{Z}\), (…-2, -1, 0, 1, 2, …) and an arrow \(n \rightarrow m\) whenever \(n \leq m\).
[See whiteboard]
What does it mean to place two sets side-by-side?
The disjoint union of two sets \(A\) and \(B\), written \(A + B\) is a set which contains the elements of both \(A\) and \(B\) along with a label to distinguish whether the element came from \(A\) or from \(B\).
Sets are not allowed to have duplicates, so the label prevents collisions between the overlapping items of \(A\) and \(B\).
Fun fact
We can encode any pair of functions \(A \rightarrow X\) and \(B \rightarrow X\), as a function \(A+B\rightarrow X\).
[See whiteboard]
Disjoint union only makes sense for sets. We want to describe it purely in terms of abstract points and arrows in order to generalize to other contexts.
This is sufficient to define putting graphs side-by-side.
[See whiteboard]
Universal property of a pushout:
Two simple definitions yield all of the specifics of these lectures as special cases:
It’s easy to write code which manipulates sets/graphs/Petri nets.
It’s hard to write code which manipulates other pieces of code.
Universal properties allow us to make very general definitions (and write flexible code) which work in many contexts.
The field of category theory strives to do this with all concepts we care about, including gluing, multiplication, optimization, substitution, and recursion.
Applied category theory textbooks
Category theory textbooks
Blogs
The coproduct of graphs \(G_1 + G_2\) can also be described as the following graph:
How to say more precisely what functions \(src\) and \(tgt\) are?
The coproduct of graphs \(G_1 + G_2\) can also be described as the following graph:
How to say more precisely what functions \(src\) and \(tgt\) are?