---
# System prepended metadata

title: Unconventional Comp Lecture (1/26/23)

---

# Unconventional Comp Lecture (1/26/23)

Keywords
- ODEs
- GPAC Function Computation
- Chemical Reaction Networks
- Mass Action Kinetics
- Dual-rail representation

### Computing $f(X_1)$ as time goes to $\infty$

Let's take a look at computing $X_2 = \log(X_1)$. So,

> $X_1' = 0$
> $X_2' = \log(X_1) - X_2 = X_3 - X_2$
> $X_3' = \frac{1}{X_1}*X_1' = 0$

At first, it looks like this would be reasonable, but let's look at the initial values we'd have to set.

> $X_1(0) = x$
> $X_2(0) = 1$ ; can be any value
> $X_3(0) = \log(x)$

With this sytem, we would have to precompute the answer we're looking for. We only want easy things to compute for initial values.

---

We can correct this with the following system:

> $X_1' = 0$
> $X_2' = X_1 - X_2$
> $X_3' = \log(X_2) - X_3 = X_4 - X_3$
> $X_4' = \frac{1}{X_2}X_2' = X_5(X_1-X_2)$
> $X_5' = -X_5^2(X_1-X_2)$

Now, let's look at initial values for this system:

> $X_1(0) = x$
> $X_2(0) = 1$; This can be any easy-to-compute value
> $X_3(0) = 0$; This can be any value 
> $X_4(0) = \log(X_2(0)) = \log(1) = 0$
> $X_5(0) = \frac{1}{X_2(0)} = 1$

---

### Chemical Computers

A Chemical Reaction Network (CRN) is a set of chemical reaction equations:

> $X + X \mathop{\rightarrow}\limits^{k_1} R + Y$
> $R + R \mathop{\rightarrow}\limits^{k_2} X$

where $k_1, k_2$ are positive real numbers (rate constants of the reactions).
The Law of Mass action dictates that the rate at which every reaction occurs is the product of its rate constant and the concentration of its reactants.

So, for the reactions above, the rates are $\rho_1 = k_1X^2$, $\rho_2 = k_2R^2$. The rates can be expressed as the amount of change in each species:

> $X' = -k_1X^2 + k_2R^2$
> $R' = -k_2R^2 + k_1X^2$
> $Y' = k_1X^2$

**This may be a bad example, because the rate constants don't matter in the end (the computation is rate-independent). This system computes $Y = \frac{2}{3}X$ in the limit as $t \rightarrow \infty$.**

---

An example where the rates DO matter:

> $X + X \mathop{\rightarrow}\limits^{k_1} C$
> $C + X \mathop{\rightarrow}\limits^{k_2} C + Y$
> $C \mathop{\rightarrow}\limits^{k_3} Y$

with ODEs:

> $X' = -2k_1X^2 - k_2CX$
> $C' = k_1X^2 - k_3C$
> $Y' = k_2CX + k_3C$

Depending on the rate constants $k_1,k_2,k_3$ (assuming Y(0) = C(0) = 0), the final amount $y$ of $Y$ will be $\frac{1}{2}X(0) \leq y \leq X(0)$.

*Note: Every CRN corresponds to polynomial ODEs, but not all polynomial ODEs correspond to a CRN. The polynomial ODEs above have the property that all negative monomials contain the variable for that ODE ("X-factorizable" or "Hungarian form").*

>$X' = -Y$

But, this property of non-negativity can be overcome by a change in representation. 

**Dual-rail**

Each species $S$ is represented by two species $S^+$ and $S^-$ where the difference in the concentrations of each species represents one real value ($s = s^+ - s^-$). Notice that this dual-rail form allows representation of negative values by nonegative concentrations.

So, for $X' = -Y$ what we're looking at is:

>$x'^+ - x'^- = -(y'^+ - y'^-)$

We can achieve this with the following CRN:

>$Y^+ \mathop{\rightarrow}\limits^{1} Y^+ + X^-$
>$Y^- \mathop{\rightarrow}\limits^{1} Y^- + X^+$


***Exercise:*** Now that you have all of the tools, try to create a CRN for our $\log(X_1)$ example. Recall the system of ODEs:

> $X_1' = 0$
> $X_2' = X_1 - X_2$
> $X_3' = \log(X_2) - X_3 = X_4 - X_3$
> $X_4' = \frac{1}{X_2}X_2' = X_5(X_1-X_2)$
> $X_5' = -X_5^2(X_1-X_2)$

