Rate-Independent Computation in Continuous Chemical Reaction Networks

Abstract: Coupled chemical interactions in a well-mixed solution are commonly formalized as chemical reaction networks (CRNs). However, despite the widespread use of CRNs in the natural sciences, the range of computational behaviors exhibited by CRNs is not well understood. Here we study the following problem: what functions $f:\mathbb{R}^k \to \mathbb{R}$ can be computed by a CRN, in which the CRN eventually produces the correct amount of the "output" molecule, no matter the rate at which reactions proceed? This captures a previously unexplored, but very natural class of computations: for example, the reaction $X_1 + X_2 \to Y$ can be thought to compute the function $y = \min(x_1, x_2)$. Such a CRN is robust in the sense that it is correct no matter the kinetic model of chemistry, so long as it respects the stoichiometric constraints.We develop a reachability relation based on "what could happen" if reaction rates can vary arbitrarily over time. We define *stable computation* analogously to probability 1 computation in distributed computing, and connect it with a seemingly stronger notion of rate-independent computation based on convergence under a wide class of generalized rate laws. We also consider the "dual-rail representation" that can represent negative values as the difference of two concentrations and allows the composition of CRN modules. We prove that a function is rate-independently computable if and only if it is piecewise linear (with rational coefficients) and continuous (dual-rail representation), or non-negative with discontinuities occurring only when some inputs switch from zero to positive (direct representation). The many contexts where continuous piecewise linear functions are powerful targets for implementation, combined with the systematic construction we develop for computing these functions, demonstrate the potential of rate-independent chemical computation.

\section{Max-min representation of continuous piecewise linear functions}
\label{app:A}

Here we state and prove a slight generalization of Ovchinnikov's theorem~\cite{ovchinnikov2002max}.
In Ovchinnikov's original paper, he only considers piecewise affine functions
(in Ovchinnikov's terminology, piecewise ``linear'' functions) that are defined on closed domains (that is, closures of open subsets of $\mathbb{R}^n$).
However, the key proof techniques of~\cite{ovchinnikov2002max} did not crucially use this fact.
In fact, we apply~\cref{thm-min-max-representation} on non-closed domains such as the sets $D_U$ in the proof of Lemma~\ref{lem-nonnegative-piecewise-linear-implies-computable}.
For completeness we prove the variant of the theorem not requiring $D$ to be closed.

\begin{thm}[\cite{ovchinnikov2002max}]\label{thm-min-max-representation-appendix}
  Let $D \subseteq \mathbb{R}^k$ be convex.
  For every continuous piecewise affine function $f:D \to \mathbb{R}$ with components $g_1,\ldots,g_p$, there exists a family $S_1,\ldots,S_q \subseteq \{1,\ldots,p\}$ such that, for all $\vec{x} \in D$,
  $
    f(\vec{x}) =
    \max\limits_{i \in \{1,\ldots,q\}}
    \min\limits_{j \in S_i}
    g_j(\vec{x}).
  $
\end{thm}

In order to prove the theorem, we  first prove three lemmas.
The first technical lemma is implicit in~\cite{ovchinnikov2002max}.
The second and third lemmas correspond to Lemmas 2.1 and 2.2 of~\cite{ovchinnikov2002max}. The proofs we give of the second and third lemmas are almost identical in content to the proofs of the corresponding lemmas in~\cite{ovchinnikov2002max}, except for the fact that we consider piecewise affine functions defined over more general subsets of $\mathbb{R}^n$. The same is true for our proof of \Cref{thm-min-max-representation-appendix}, which is again almost identical to the proof of Theorem 2.1 in~\cite{ovchinnikov2002max}.

\begin{lemma}\label[lemma]{lem:piecewise-linear-functions-are-nice}
If $f: [a,b] \to \mathbb{R}$ is a continuous piecewise affine function with components $\set{g_1, \ldots, g_n}$ then there are finitely many numbers $a = x_0 < x_1 < \ldots < x_m = b$ such that $f$ is affine on $[x_k, x_{k + 1}]$ for all $k$.
\end{lemma}

\begin{proof}
Without loss of generality we can assume that all of the component functions $g_i$ are distinct affine functions. For each $i$ between $1$ and $n$, let $D_i$ be the set of $x \in [a,b]$ such that $g_i(x) = f(x)$. For each $i$, both $g_i$ and $f$ are continuous, so $D_i$ is closed. Let $S$ be the subset of $[a,b]$ consisting of points $x \in [a,b]$ where $x$ is a member of more than one $D_i$. For each pair $i \neq j$, we know that $g_i$ and $g_j$ are distinct affine functions, so there can be at most one $x \in [a,b]$ such that $g_i(x) = g_j(x)$. This implies that $D_i$ and $D_j$ can intersect in at most one point, so $S$ must be a finite set. Let $x_0\ldots x_m$ be the elements of $S \cup \set{a,b}$.

Now for a given $k$ write $I$ for the interval $(x_k, x_{k + 1})$ and consider the restriction of $f$ to $I$. Pick a random point $c \in I$ and suppose $f(c) = g_l(c)$. Then clearly $D_l \cap I$ is nonempty. Because $D_l$ is closed in $[a,b]$, by definition $D_l \cap I$ is closed relative to $I$. Because $S \cap I = \emptyset$ we also know that
\[D_l \cap I = I \setminus \left(\bigcup_{i \neq l} D_i \right) \]
so $D_l \cap I$ is open relative to $I$. But the only subset of an interval that is both open and closed is the whole interval, so $I \subseteq D_l$. Therefore $f = g_l$ when restricted to $I$, and by continuity we see that $f$ is affine on the closure of $I$ as well.
\end{proof}

Note that we define piecewise affine functions to have only finitely many components---without this assumption the above lemma is false.

\begin{lem}\label[lemma]{lem:piecewise-linear-on-interval}
Let $f: [a,b] \to \mathbb{R}$ be a continuous piecewise affine function. Let $\set{g_1, \ldots, g_n}$ be its set of components. Then there is some $k$ such that
\[g_k(a) \le f(a)\ \text{ and }\ g_k(b) \ge f(b).\]
\end{lem}

\begin{proof}
We'll first prove the result for $f(a) = f(b) = 0$ and then show how this implies the general case. Given this assumption, if one of the $g_i$ is the zero function, then we're done. If not, since all of the component functions $g_i$ are affine, each $g_i$ can have at most one zero. Since $f$ has finitely many components, this implies that $f$ has finitely many zeros. Let $c$ be the smallest number such that $c > a$ and $f(c) = 0$.

By \Cref{lem:piecewise-linear-functions-are-nice} we know that there are some $x$ and $y$ with $a < x < y < c$ and component functions $g_k$ and $g_l$ such that $f = g_k$ on $[a, x]$ and $f = g_l$ on $[y, c]$. If the slope of either $g_k$ or $g_l$ is non-negative, then we are done:
\begin{align*}
     g_k(a) &\le g_k(c) = 0 = f(a)\\
     g_k(b) &\ge g_k(c) = 0 = f(b)
\end{align*}
and similarly for $g_l$.
But $g_k$ and $g_l$ can't both have negative slope, for then $f(x) = g_k(x) < 0$ and $f(y) = g_l(y) > 0$, so by the intermediate value theorem there would be some $z$ between $x$ and $y$ such that $f(z) = 0$. This contradicts our assumption that $c$ was the smallest number with $c > a$ and $f(c) = 0$.
This concludes the proof assuming that $f(a)=f(b)=0.$

To deduce the result for a general continuous piecewise affine function from this special case, subtract the affine function
\[\ell(x) = f(a) + f(b)\frac{x - a}{b - a}\]
from $f$ and all of its components.
\end{proof}

\begin{lem}\label[lemma]{lem:piecewise-linear-on-convex-domain}
Let $D$ be a convex subset of $\mathbb{R}^n$ and let $f: D \to \mathbb{R}$ be a continuous piecewise affine function. If the components of $f$ are $\set{g_1 \ldots g_n}$, then for every pair of vectors $\vec{a}$ and $\vec{b}$ in $D$, there is some $k$ such that
\[g_k(\vec{a}) \le f(\vec{a})\ \text{ and }\ g_k(\vec{b}) \ge f(\vec{b})\]
\end{lem}
\begin{proof}
Because $D$ is convex, the straight-line interval between $\vec{a}$ and $\vec{b}$ is contained in $D$. Apply \Cref{lem:piecewise-linear-on-interval} to the restriction of $f$ to this interval.
\end{proof}

\begin{proof}[of \Cref{thm-min-max-representation-appendix}]
For each $\vec{b} \in D$, define the set $S_{\vec{x}} \subseteq \set{1 \ldots p}$ as
\[S_\vec{b} = \set{i\ |\ g_i(\vec{b}) \ge f(\vec{b})}.\]
Let
\[F_\vec{b}(\vec{x}) = \min_{i \in S_\vec{b}} g_i(\vec{x}).\]
Because there is always some component function $g_j$ with $g_j(\vec{b}) = f(\vec{b})$, we see that $F_\vec{b}(\vec{b}) = f(\vec{b})$ for every $\vec{b} \in D$. Also, by \Cref{lem:piecewise-linear-on-convex-domain}, we know that for every $\vec{a} \in D$, there is some component function $g_k \in S_\vec{b}$ with $g_k(\vec{a}) \le f(\vec{a})$, so $F_\vec{b}(\vec{a}) \le f(\vec{a})$ for every pair $\vec{b}, \vec{a} \in D$. This implies that
\begin{align}\label{eq:max-min}
f(\vec{x}) = \max_{\vec{b} \in D}F_\vec{b}(\vec{x}) = \max_{\vec{b} \in D}\min_{i \in S_\vec{b}}g_i(\vec{x})
\end{align}
Since $\set{1 \ldots p}$ is a finite set, it has only finitely many subsets, so each $S_\vec{b}$ is equal to one of finitely many sets $S_j$. We can therefore replace the maximum over all $\vec{b} \in D$ in \Cref{eq:max-min} with a maximum over finitely many functions.
\end{proof}

\section{Finding Rational Solutions to Systems of Linear Equations}

It is well-known that a system of linear equations with rational coefficients has a rational solution if and only if it has a real solution.
The following result
shows the slightly generalized claim that
rational solutions exist arbitrarily close to all real solutions
(i.e., the rational solutions are dense in the real solutions).

\begin{lem}\label{lem-rational-sols}
Let $A\vec{x} = \vec{b}$ be a system of linear equations, where $A$ is a matrix with rational coefficients and $\vec{b}$ is a vector with rational coefficients. If the equation has a solution $\vec{x}$ with real coefficients, then for any $\varepsilon > 0$, it has a solution with $\vec{x}'$ rational coefficients such that $||\vec{x}' - \vec{x}|| < \varepsilon$.
\end{lem}

\begin{proof}
Let $n$ be the number of rows of $A$ and the length of $\vec{b}$. Let $m$ be the number of columns of $A$ and the length of $\vec{x}$. Because $A$ has rational entries, using elementary row and column operations it can be decomposed as $PNQ$ where $P$ is an $m \times m$ invertible rational matrix, $Q$ is an $n \times n$ invertible rational matrix, and
\[N_{ij} = \begin{cases}
1 & i = j \text{ and } i \le r \\
0 & \text{otherwise}
\end{cases}\]
where $r$ is the rank of $M$. Let $\vec{y} = Q\vec{x}$ and let $\vec{c} = P^{-1} \vec{b}$, so that $N\vec{y} = \vec{c}$. If $r = n$, then all of the entries of $\vec{y}$ must be rational, since $\vec{y}_i = \vec{c}_i$ for all $i$ and all of the entries of $\vec{c}_i$ are rational. Then the entries of $\vec{x}$ must also all be rational, since $\vec{x} = Q^{-1}\vec{y}$ and $Q$ has all rational entries. As a result, if $r = n$, we can just take $\vec{x}' = \vec{x}$.

On the other hand, if $r < n$, then let
\[\delta = \frac{\varepsilon}{\sqrt{n - r} ||Q^{-1}||}\]
where
\[||Q^{-1}|| = \sup_{\vec{v} \neq 0} \frac{||Q^{-1}\vec{v}||}{||\vec{v}||}\]
is the operator norm of $||Q^{-1}||$. Now let $\vec{y}'$ be a vector such that $\vec{y}'_i = \vec{y}_i$ for $i \le r$ and $\vec{y}'_i$ is a rational number such that $|\vec{y}'_i - \vec{y}_i| < \delta$ for $i > r$. All of the components of $\vec{y}'$ are rational: $\vec{y}'_i$ is rational by construction for $i > r$, and $\vec{y}'_i = \vec{y}_i = \vec{c}_i$ is rational for $i \le r$. Moreover, the fact that $\vec{y}'_i = \vec{c}_i$ for $i \le r$ shows that $N\vec{y}' = \vec{c}$.

If we take $\vec{x}' = Q^{-1}\vec{y}'$, then all of the components of $\vec{x}'$ are rational, and $M\vec{x}' = \vec{b}$, since
\begin{align*}
M\vec{x}' = PNQ\vec{x}' = PN\vec{y}' = P\vec{c} = \vec{b}.
\end{align*}
Finally, we know that $||\vec{x}' - \vec{x}|| < \varepsilon$, since
\begin{align*}
||\vec{x}' - \vec{x}|| &= ||Q^{-1}(\vec{y}' - \vec{y})|| \\
&\le ||Q^{-1}|| \cdot ||\vec{y}' - \vec{y}|| \\
&= ||Q^{-1}|| \sqrt{\sum_{i = 1}^n (\vec{y}'_i - \vec{y}_i)^2} \\
&< ||Q^{-1}|| \sqrt{(n - r)\delta^2} \\
&= \varepsilon
\end{align*}
This shows that $\vec{x}'$ is our desired solution.
\end{proof}

\section{Conclusion}
\label{sec-conclusion}

We characterized the class of functions computable in a manner that is absolutely robust to reaction rates in the continuous model of chemical kinetics.
Such rate-independent computation must rely solely on reaction stoichiometry---which reactants and how many of each produce which products and how many of each?
We considered two methods of encoding inputs and outputs: direct and dual-rail.
The dual-rail encoding permits easier composition of modules and can represent negative values;
we characterized its computational power as continuous, piecewise rational linear.
The direct encoding, however, allows computing functions that are discontinuous at the axes.
For both encodings, we developed both negative results (showing that nothing more can be computed) and positive results (offering a construction for computing functions in the class).

Since rate-independent computation does not require  difficult-to-achieve tuning of parameters or reaction conditions, it may be significantly more ``engineerable'' than rate-dependent computation.
More generally, our work also helps uncover the multifaceted sources of chemical computational power by disentangling the control of stoichiometry from reaction rates.

We close by discussing some directions for future research.

\paragraph{Non-zero initial context}
    Throughout this paper we have assumed
    that the only species allowed to be present at the start of the computation are the input species. Instead, one could consider a model where certain non-input species $Z_1 \ldots Z_n$, called the \emph{initial context}~\cite{CheDotSol12},
    have a fixed, nonzero rational concentration at the start of the computation. In this setting, we can clearly compute more functions than in the setting without initial context: for instance, we can easily compute $f(x_1 \ldots x_k) = C$ for some nonzero constant $C$, which is impossible without initial context because $f$ is affine  but not linear.

    In fact, we can dual-rail compute any continuous piecewise rational affine function $f: \mathbb{R}^k \to \mathbb{R}$,
    i.e., any function that is a rational linear function plus a rational constant: $f(\vec{x}) = \vec{a} \cdot \vec{x} + b$.
    To see this, first note that we can compute any rational affine function by using the initial context to offset the value at $f(0) = b$.
    In fact, we can simply let output species $Y^+$ and $Y^-$ be the initial context, with $[Y^+] = b$ initially if $b>0$ and $[Y^-] = -b$ otherwise.
    Similar machinery to the proof of Lemma~\ref{lem-piecewise-linear-implies-computable} can be used to extend this to continuous \emph{piecewise} rational affine functions:
    By Theorem~\ref{thm-min-max-representation}, any continuous piecewise rational affine function can be represented in max-min form, and then our construction from Section~\ref{negative-piecewise-linear-implies-computable} shows that we can compute our given function $f$. In the direct computation setting, by a construction like the one in Section~\ref{sec:positive-continuous-piecewise-rational-linear-computable} we can compute any positive-continuous piecewise rational affine function $f: \mathbb{R}^k_{\ge 0} \to \mathbb{R}_{\ge 0}$.

    It also turns out that, even with initial context, we can't compute any more functions than these. To see this, note that without loss of generality we can assume that there is only one initial context species $Z$ with initial concentration 1, since we can modify any CRC with initial context to include a reaction that converts $Z$ into the $Z_i$ with appropriate concentrations. Now let $g(x_1, \ldots, x_n, z)$ be the value that the CRC computes when the input species have initial values $x_1,\ldots, x_n$ and the initial context species has value $z$. A priori, $g$ is only well-defined when $z = 1$, but because piecewise linear paths remain valid after scaling we know that
    \[
    g(x_1, \ldots, x_n, z) =
    z \cdot g(x_1/z, \ldots, x_n/z, 1) =
    z \cdot f(x_1/z, \ldots, x_n/z)\]
    for any value of $z > 0$. This shows that $g$ is well-defined on
    $D_U$ (recall Definition~\ref{def:positive-continuous}) for every $U$ that contains $Z$, so we can apply the results of Section~\ref{sec:negative-results} to characterize $g$ on these domains. Using the fact that $f(x_1, \ldots, x_n) = g(x_1, \ldots, x_n, z)$ gives us the desired result.

    Since every continuous function on a compact domain is uniformly continuous,
    it can be uniformly approximated by continuous piecewise rational affine functions.
    This shows that we can use rate-independent CRNs to approximate continuous functions. Note that for the negative argument above to work, it was important that all of the initial concentrations of the initial context species were rational. For practical purposes, this assumption is not at all restrictive, but it might be of theoretical interest to know what other functions can be computed if the initial concentrations are allowed to be arbitrary real numbers.

\paragraph{Reaction complexity of stably computable functions}

    An interesting question regards the description complexity of functions stably computable by CRNs.
    Some piecewise linear functions have a number of pieces exponential in the number of inputs;
    for example, $f(x_1,\ldots,x_{2k}) = \min(x_1,x_2) + \min(x_3,x_4) + \ldots + \min(x_{2k-1}, x_{2k})$ has $2^k$ linear pieces.
    If we express this function in $\max \min g_i$ form of Theorem~\ref{thm-min-max-representation},
    we need $2^k$ different linear $g_i$,
    and thus the construction in the proof of Lemma~\ref{lem-piecewise-linear-implies-computable} would require exponentially many species and reactions.

    However, this particular $f$ has a more succinct CRN that stably computes it, namely the reactions
    \begin{eqnarray*}
      X_1 + X_2 &\to& Y
      \\
      X_3 + X_4 &\to& Y
      \\
      \vdots
      \\
      X_{2k-1} + X_{2k} &\to& Y.
    \end{eqnarray*}
    Given a positive-continuous, piecewise rational linear function $f$, how can we tell whether it has a more compact CRN stably computing it than our construction?
    If it does, how can we arrive at it?

\paragraph{Other rate laws}

    Our results concerning mass-action rate laws
    (\Cref{thm:mass-action-reachable} and Lemma~\ref{lem:mass-action-convergence-stable-computation})
    establish that our reachability-based definitions of computation, which talk only about what the CRNs \emph{could do},
    imply something about what the CRNs \emph{will do}, under the mass-action rate law.
    It seems as though other ``reasonable'' rate laws, such as Hill function kinetics, or Michalis-Menten kinetics,
    should obey the same results.
    It would be interesting to establish a general condition on a rate law, obeyed by all known and studied rate laws, that is sufficient to establish that analogs of those results hold.
    This could be related to the generalized rate laws studied by other authors~\cite{angeli2007petri,degrand2020graphical}.

\paragraph{Arbitrary but fixed rate constants}
    A related notion of rate-independence is one where the form of rate-law cannot vary,
    but the constant parameters can,
    e.g., mass-action rates, where an adversary picks the rate constants
    (possibly depending on the initial input).
    For example, consider the following CRN with input species $A,B,C,X$ and output species $Y$.

    \begin{eqnarray*}
      A + X &\to& A + Y
      \\
      B + Y &\to& B + X
      \\
      A + B &\to& C
      \\
      C + Y &\to& C + X
      \\
      3C &\to& \emptyset.
    \end{eqnarray*}
    Let $a, b, c, x$ denote the initial concentrations of species $A$, $B$, $C$, $X$.
    Note that this system does not stably compute any function in the model defined in this paper because on input $a=b$ we can stabilize to any value of output $y$ between $0$ and $x$.

    In contrast, consider the above system under mass-action kinetics.
    First note that the concentration of $C$ approaches $0$ as time goes to infinity in all cases.
    If $a>b$, then also the concentration $B$ approaches $0$ but the concentration of $A$ remains bounded away from $0$. Therefore, the output $y$ converges to $x$, regardless of what the rate constants are. Similarly, if $b>a$, the output $y$ approaches $0$.
    When $a=b$, the concentrations of $A, B, C$ approach $0$ at different rates. The concentrations of $A, B$ are $\Theta(\frac{1}{t})$ at time $t$ (rate of bimolecular decay),
    and the concentration of $C$ is $\Theta(\frac{1}{\sqrt{t}})$ (rate of trimolecular decay). As a result, the effective rate of conversion of $Y$ to $X$ via the channel $C + Y \to C + X$ is $\Theta(\frac{1}{\sqrt{t}})$. Since this is $\Omega(\frac{1}{t})$ the output $y$ always converges to $0$ regardless of the rate constants (in our particular case the concentration of $Y$ is $e^{-\Theta(\sqrt{t})}$). From the above, this CRN computes $f(a, b, c, x) = x$ when $a > b$ and $f(a, b, c, x) = 0$ when $a \leq b$, no matter what the rate constants are.
    This function is discontinuous at points where $a=b$,
    so it is not positive-continuous,
    thus not stably computable by any CRN under our model of rate-independence.
    It remains open to classify what functions can be computed by
    mass-action CRNs in which rate constants are chosen adversarially.

\section{Introduction}
\label{sec-intro}

Both the engineering of complex artificial molecular systems,
as well as the understanding of the constraints imposed upon biology,
require the understanding of what is, in principle, achievable in chemistry.
The natural language for describing the interactions of molecular species in a well-mixed solution is that of chemical reaction networks (CRNs), i.e., finite sets of chemical reactions such as $A + B \to A + C$.
The intuitive meaning of this expression is that a unit of chemical species $A$ reacts with a unit of chemical species $B$, producing a unit of a new chemical species $C$ and regenerating a unit of $A$ back.
Typically (in mass-action kinetics) the rate with which this occurs is proportional to the product of the amounts of the reactants $A$ and $B$.

Traditionally CRNs have been used as a descriptive language to analyze naturally occurring chemical reactions,
as well as various other systems with a large number of interacting components such as gene regulatory networks and animal populations.
However, CRNs also constitute a natural choice of programming language for engineering artificial systems.
For example, nucleic-acid networks can be rationally designed to implement arbitrary chemical reaction networks~\cite{SolSeeWin10,cardelli2011strand,chen2013programmable,srinivas2017enzyme}.
Thus, since in principle any CRN can be physically built, hypothetical CRNs with interesting behaviors are becoming of more than theoretical interest.
One day artificial CRNs may underlie embedded controllers for biochemical, nanotechnological, or medical applications, where environments are inherently incompatible with traditional electronic controllers.
However, to effectively program chemistry, we must understand the computational power at our disposal.
In turn, the computer science approach to CRNs is also beginning to generate novel insights regarding natural cellular regulatory networks~\cite{cardelli2012cell}.

Informally speaking we can identify two sources of computational power in CRNs.
First, the reaction \emph{stoichiometry} transforms some specific ratios of reactants to products.
For example, $X \rxn 2Y$ makes two units of $Y$ for every unit of $X$.
Second, in mass-action kinetics the reaction \emph{rate laws} effectively perform multiplication of the reactant concentrations.
In this work, we seek to disentangle the contributions of these two computational ingredients by focusing on the computational power of stoichiometry alone.

One reason to focus on \emph{stoichiometric computation} is that algorithms that rely on stoichiometry make easier design targets.
The rates of reactions are real-valued quantities that can fluctuate with reaction conditions and temperature, while the stoichiometries are immutable whole numbers set by the nature of the reaction.
Methods for physically implementing CRNs naturally yield systems with digital stoichiometry that can be set exactly~\cite{SolSeeWin10,cardelli2011strand}.
Further, relying on specific rate laws can be problematic:
many systems do not follow mass-action rate laws\footnote{Although it is generally taken for granted that they would if properly decomposed into truly elementary reactions.} and chemists have developed an array of alternative rate laws such as Michaelis-Menten and Hill-function kinetics.
Indeed, robustness of rate laws is a recurring motif in systems biology due to much evidence that biological regulatory networks tend to be robust to the form of the rate laws and the rate parameters~\cite{barkal1997robustness}.
Thus we are interested in what computations can be understood or engineered without regard for the reaction rate laws.

There are two well-studied models of chemical kinetics: \emph{continuous} and \emph{discrete}.
In the discrete model, the amount of a species is a nonnegative \emph{integer} representing the total count of molecules of that species in a given reaction vessel.
In the continuous model, the amount of a species is a nonnegative \emph{real number} representing its average count per unit volume or concentration.
The discrete model is \emph{stochastic} and reactions are modeled by a Markov jump process~\cite{Gillespie77},
while the continuous model is \emph{deterministic}, governed by a system of ordinary differential equations with a unique solution.
When the volume and counts are large, the discrete model converges to the continuous model~\cite{kurtz1972relationship}.
While many cellular chemical processes operate at single-molecule precision,
a significant amount of regulation is well-understood by continuous models~\cite{alon2007introduction}.
Further, because of the difficulty of working at molecular resolution most experimental implementations of rationally designed chemical computation have been in bulk solution (e.g.~\cite{SeeSolZhaWin06,qian2011scaling,chen2013programmable}).

Here we study the continuous setting,
and characterize the class of real-valued functions computable by CRNs when reaction rates are permitted to vary arbitrarily (and possibly adversarially) over time.
Any computation in this setting must rely on stoichiometry alone.
Our work is related to the study of \emph{deterministic\footnote{Deterministic computation in the discrete/stochastic model should not be confused with the determinism of the continuous model, where any stochasticity is absent.} computation} in stochastic CRNs:
making reaction rates unreliable is the natural analog to error in the stochastic setting (where error corresponds to reactions occurring in an undesired order).
(See Section~\ref{sec:prev}.)

How can rate laws ``preserve stoichiometry'' while varying ``arbitrarily over time''?
Formally, preserving stoichiometry means that if we reach state $\vec{d}$ from state $\vec{c}$, then $\vec{d} = \vec{c} + \vec{M} \vec{u}$ for stoichiometry matrix $\vec{M}$, and some non-negative vector $\vec{u}$ of reaction fluxes.
Subject to this constraint, the widest class of trajectories that still satisfies the intuitive meaning of the reaction semantics can be described informally as follows:
(1) concentrations can't become negative,
(2) all reactants must be non-zero for a reaction to occur (e.g.~if a reaction uses a catalyst\footnote{A species acts catalytically in a reaction if it is both a reactant and product: e.g.~$C$ in reaction $A + C \to B + C$. Note that executing this reaction without $C$ does not by itself violate condition (1).}, it must be present).

\newcommand{3.1in}{3.1in}
\begin{figure}
\centering
\includegraphics[width=3.1in]{examples}
\caption{Examples of (a) \emph{direct} and (b) \emph{dual-rail} rate-independent computation of $f(x_1, x_2) = \max(x_1,x_2)$.}
\label{fig:ex}
\end{figure}

The example shown in Fig~\ref{fig:ex}(a) illustrates the style of computation studied here.
Let $f: \mathbb{R}_{\geq 0}^2 \to \mathbb{R}_{\geq 0}$ be the max function $f(x_1, x_2) = \max(x_1,x_2)$ restricted to non-negative $x_1$ and $x_2$.
The CRN shown computes this function in the following sense.
Inputs $x_1$  and $x_2$ are given as initial concentrations of input species $X_1$ and $X_2$.
Then the CRN converges to the output value of species $Y$, under a very wide interpretation of rate laws.
Intuitively, the first two reactions must eventually produce $x_1 + x_2$ of $Y$, and $x_1$, $x_2$ of $Z_1$ and $Z_2$, respectively.
This is enforced by the stoichiometric constraint that the amount of $Z_1$ and $Y$ produced is equal to the amount of $X_1$ consumed (and analogously for the second reaction).
Stoichiometric constraints require the third reaction to produce the amount of $K$ that is the minimum of the amount of $Z_1$ and $Z_2$ eventually produced in the first two reactions.
Thus $\min(x_1,x_2)$ of $K$ is eventually produced.
Therefore, the fourth reaction eventually consumes $\min(x_1,x_2)$ molecules of $Y$ leaving $x_1 + x_2 - \min(x_1 , x_2) = \max(x_1 , x_2)$ of $Y$ behind.
We can imagine an adversary pushing flux through these four reactions in any devious stratagem,
but as long as he cannot take any concentration negative,
the CRN can only converge to the correct output.

In this paper we further consider the natural extension of such computation to handle negative real values.
The example shown in Fig.~\ref{fig:ex}(b) computes $f(x_1, x_2) = \max(x_1,x_2)$ ($f: \mathbb{R}^2 \to \mathbb{R}$).
In order to handle negative input and output values, we represent the value of each input and output by a pair of species (so-called ``dual-rail'' representation).
For example, in state $\vec{c}$, $x_1 = \vec{c}(X_1^+)-\vec{c}(X_1^-)$ --- i.e.~the difference between the concentrations of species $X_1^+$ and $X_1^-$.
Note that when $X_1^-$ and $X_2^-$ are initially absent, the CRN becomes equivalent to the first three reactions of Fig.~\ref{fig:ex}(a) under relabeling of species.
We do not need the last reaction of (a) because the output is represented as the difference of $Y^+$ and $Y^-$ by our convention.
For the argument that the computation is correct even if $X_1^-$ and $X_2^-$ are initially present, we refer the reader to Section~\ref{negative-piecewise-linear-implies-computable}.

In addition to handling negative values, the dual-rail representation has the benefit of allowing composition.
Specifically, the dual-rail representation allows CRNs to never consume their output species (e.g.~rather than consuming $Y^+$, it can produce $Y^-$).
This monotonicity in the production of output allows directly composing CRN computations simply by mixing CRNs and relabeling species (e.g.~to make the output of one be input to the other).
Since the upstream CRN never consumes its output species, the downstream CRN is free to consume them without interfering with the upstream computation.

In order to formally delineate the class of functions (direct and dual-rail) computable in a rate-independent manner, we take the following approach.
We first define a reachability relation that captures motion along trajectories satisfying the two intuitive properties above.
Then we define rate-independent computation using this reachability relation.
Roughly, to say that a function is correctly computed, it must be the case that from every reachable state, the correct output can be reached, and once reached the output cannot change.
Our main results are that exactly functions that are positive-continuous, piecewise linear (direct) or continuous, piecewise linear (dual-rail) can be computed.
(Positive-continuous means that the only discontinuities occur on a ``face'' of $\mathbb{R}_{\geq 0}^k$ --- i.e., the function may discontinuously jump only at a point where some input goes from $0$ to positive.)

In the constructive portion of our results,
we supply rate-independent CRNs for computing any function in the above classes.
Further, our constructions have the following property:
If the same CRNs were simulated under mass-action kinetics from any reachable state, as the time $t \to \infty$ the concentration of the output species would approach its intended value.
In other words, no matter how an adversary might have pushed us initially, letting the system evolve by mass-action will yield the correct answer.
We prove this by showing that our constructions satisfy a general feedforward property that guarantees mass-action convergence to the rate-independent output.

\subsection{Related Works} \label{sec:prev}

An earlier conference version of this paper appeared as~\cite{CheDotSol14}.
Besides replacing a number of informal arguments with rigorous proofs, this journal version also expands and generalizes the results of the conference version.
For example, we introduce new machinery for representing and manipulating trajectories as linear objects (piecewise linear paths).
For the constructive part, this version also generalizes Lemma 3.4 of \cite{CheDotSol14} (in addition to correcting its proof) by introducing feedforward CRNs and proving that correct computation in our setting implies mass-action convergence for any CRNs in this class (Lemma~\ref{lem:mass-action-convergence-stable-computation}).

The computational abilities of discrete CRNs have been investigated more thoroughly than of continuous CRNs, and have been shown to have a surprisingly rich computational structure.
Of most relevance here is the work in the discrete setting showing that the class of functions that can be computed  depends strongly on whether the computation must be deterministic (guaranteed to be correct), or just likely to be correct.
While Turing universal computation is possible with an arbitrarily small, non-zero probability of error over all time~\cite{SolCooWinBru08},
forbidding error altogether limits the computational power severely:
Error-free computation by stochastic CRNs is limited to semilinear predicates and functions~\cite{AngluinAE06,CheDotSol13}.
(Intuitively, semilinear functions are expressible as a finite union of affine functions, with ``simple, periodic'' domains of each affine function~\cite{CheDotSol13}.)

Our paper was motivated by trying to extend the results on error-free computation to the continuous CRN model.
As mentioned above, our notion of rate-independent computation is the natural extension of  deterministic computation in the discrete model.
However, there are many differences in the two settings.
As broached in ref.~\cite{CheDotSol13}, many of the CRNs that work in the discrete setting appear not to work in the continuous setting.
For example, the CRNs computing discontinuous functions such as ``$f(x_1,x_2) = x_2$ if $x_1 > x_2$ and $0$ otherwise'' provably fail to work in the continuous setting.
Indeed, discrete CRNs can, for example, distinguish between even and odd inputs, whereas it does not even make sense to talk about the ``parity'' of a real-valued input.
Further, the proof techniques appear to require very different machinery.

The relationship between the discrete and continuous CRN models is a complex and much studied one in the natural sciences~\cite{samoilov2006deviant}.
While computational differences in the models are less understood,
continuous CRNs have been proven to be Turing universal under mass-action rate laws~\cite{fages2017strong}.

Our notion of reachability is intended to capture a wide diversity of possible rate laws.
A related idea in the literature, albeit restricted to mass-action, is differential inclusion~\cite{gopalkrishnan2013projection}.
Generalized rate laws (extending mass-action, Michaelis-Menten, etc) have been previously studied, although not in a computational setting.
For example, certain conditions were identified on global convergence to equilibrium based on properties intuitively similar to ours~\cite{angeli2006structural}.

Since the original publication of the conference version of this paper, a number of works have used our framework.
A key concept in capturing rate-independent computation is the reachability relation (segment-reachability, Definition~\ref{defn-reachable-segment}).
Reference~\cite{case2018reachability} showed that, given two states, deciding whether one is reachable from the other is solvable in polynomial time.
This contrasts sharply with the hardness of the reachability problem for discrete CRNs, which is not even primitive recursive~\cite{leroux2021reachability,czerwinski2021reachability}.

The question of deciding whether a given CRN is rate-independent was studied in~\cite{degrand2020graphical}.
The work provides sufficient graphical conditions on the structure of the CRN which ensure rate-independence for the whole CRN or only for certain output species.
Interestingly, the authors of~\cite{degrand2020graphical} applied this method to the Biomodels repository of curated CRNs of biological origin and found a number of CRNs that satisfy the rate-independence conditions.

An important motivation for the dual-rail representation in this work is to allow composition of rate-independent CRN modules.
Such rate-independent modules can be composed into overall rate-independent computation simply by
concatenating their chemical reactions and relabeling species (such that the output species of the first is the input species of the second, and all other species are distinct).
In contrast, rate-independent composition with the direct (non-dual rail) representation,
introduces an additional ``superadditivity'' constraint that for all input vectors $\vec{x}$ and $\vec{x}'$, $f(\vec{x}) + f(\vec{x}') \leq f(\vec{x} + \vec{x}')$~\cite{chalk2021composable}.
Thus, for example, the max function (Figure~\ref{fig:ex}) provably cannot be composably computed with a rate-independent CRN in the direct representation.
Composable computation has also been characterized in the discrete model~\cite{severson2020composable,hashemi2020composable}.

Other notions of chemical ``rate-independence'' include CRNs that work independently of the rate law as long as there is a separation into fast and slow reactions~\cite{senum2011rate}.

\section{Acknowledgements}
We thank Manoj Gopalkrishnan, Elisa Franco, Damien Woods, and the organizers and participants of the American Mathematical Institute workshop on Mathematical Problems Arising from Biochemical Reaction Networks for insightful discussions.
We are grateful to anonymous reviewers for insightful comments and suggestions that have improved this paper.
DD was supported by NSF grants CCF-1900931 and CCF-1844976.
DS was supported by NSF grant CCF-1901025 and a Sloan Foundation Research Fellowship.
WR was supported by the National Science Foundation Graduate Research Fellowship under Grant No. DGE1745303. HC was supported by MOST (Taiwan) grants 107-2221-E-002-031-MY3 and 110-2223-E-002-006-MY3.

\bibliographystyle{abbrv}

\section{Statement of Results}
\label{sec:results-statement}

This section summarizes our main results.
Subsequent sections prove them, split into positive results
(constructing CRNs to compute functions, \cref{sec:positive-results})
and negative results
(proving limitations on what functions CRNs can compute, \cref{sec:negative-results}).

\begin{defn}\label{def:rational-linear}
A function $f: \mathbb{R}^k \to \mathbb{R}$ is \emph{rational linear} if there exist $a_1,\ldots,a_k \in \mathbb{Q}$ such that $f(\vec{x}) = \sum_{i=1}^k a_i \vec{x}(i).$
A function $f: \mathbb{R}^k \to \mathbb{R}$ is \emph{rational affine} if there exist $a_1,\ldots,a_k, c \in \mathbb{Q}$ such that $f(\vec{x}) = \sum_{i=1}^k a_i \vec{x}(i) + c.$
\end{defn}

We note that rational linearity has the equivalent characterization that $f$ is linear and maps rational inputs $\vec{x} \in \mathbb{Q}^n$ to rational outputs.

\begin{defn}\label{def:piecewise-rational-linear}
A function $f: \mathbb{R}^k \to \mathbb{R}$ is \emph{piecewise rational linear (affine)} if there is a finite set of partial rational linear (affine) functions $f_1,\ldots,f_p:\mathbb{R}^k \dashrightarrow \mathbb{R}$, with
$\bigcup_{j=1}^p {\rm dom} \; f_j = \mathbb{R}^k$, such that, for all $j \in \{1,\ldots,p\}$ and all $\vec{x} \in {\rm dom} \; f_j$, $f(\vec{x}) = f_j(\vec{x})$.
In this case, we say that $f_1,\ldots,f_p$ are the \emph{components} of $f$.
\end{defn}

\begin{defn}\label{def:positive-continuous}
A function $f: \mathbb{R}_{\geq 0}^k \to \mathbb{R}_{\geq 0}$ is  \emph{positive-continuous} if, for all $U \subseteq \{1,\ldots,k\}$, $f$ is continuous on the domain
\[
D_U = \setl{\vec{x} \in \mathbb{R}_{\geq 0}^k}{(\forall i \in \{1,\ldots,k\})\ \vec{x}(i) > 0 \iff i \in U}.
\]
\end{defn}
In other words, $f$ is continuous on any subset $D \subset \mathbb{R}_{\geq 0}^k$ that does not have any coordinate $i \in \{1,\ldots,k\}$ that takes both zero and positive values in $D$.

The following are the main theorems of this paper.
The first exactly characterizes functions computable with the direct representation of inputs and outputs,
while the second characterizes the functions computable with the dual-rail representation.

\begin{thm}\label{thm-computable-iff-piecewise-linear}
  A function $f:\mathbb{R}^k \to \mathbb{R}$ is stably dual-computed by a CRC if and only if it is continuous and piecewise rational linear.
\end{thm}

We prove each direction of Theorem~\ref{thm-computable-iff-piecewise-linear} separately via Lemmas~\ref{lem-piecewise-linear-implies-computable} and~\ref{lem-computable-implies-piecewise-linear}.

\begin{thm}\label{thm-nonnegative-computable-iff-piecewise-linear}
  A function $f:\mathbb{R}_{\geq 0}^k \to \mathbb{R}_{\geq 0}$ is stably computable by a CRC if and only if $f$ is positive-continuous and piecewise rational linear.
\end{thm}

We prove each direction of Theorem~\ref{thm-nonnegative-computable-iff-piecewise-linear} separately via Lemmas~\ref{lem-nonnegative-piecewise-linear-implies-computable} and~\ref{lem:positive-continuous-piecewise-rational-linear}.

Note that for direct computation,
since concentrations are nonnegative, we may only compute functions $f:\mathbb{R}_{\geq 0}^k \to \mathbb{R}_{\geq 0}$.
Interestingly,
compared to Theorem~\ref{thm-computable-iff-piecewise-linear},
the class of computable functions expands slightly to include certain discontinuous functions, specifically the positive-continuous functions where the discontinuity occurs when some inputs switch from zero to positive.

\section{Positive Results}
\label{sec:positive-results}

In this section, we construct dual-rail CRNs that compute continuous piecewise rational linear functions (Section~\ref{negative-piecewise-linear-implies-computable}) and direct CRNs that compute positive-continuous piecewise rational linear functions (Section~\ref{sec:positive-continuous-piecewise-rational-linear-computable}).

\subsection{Continuous Piecewise Rational Linear Functions are Dual-Rail Computable}\label{negative-piecewise-linear-implies-computable}

Definition~\ref{def:piecewise-rational-linear} does not stipulate how complex the ``boundaries'' between the linear pieces of a piecewise rational linear function can be. They can even be irrational in some sense, e.g., the function $f(x_1,x_2) = 0$ if $x_1 > \sqrt{2} \cdot x_2$ and $f(x_1,x_2) = x_1+x_2$ otherwise. However, if we additionally require that $f$ be \emph{continuous}, then the following theorem
states that $f$ has a particularly clean form,
conducive to computation by CRCs.

\begin{thm}[\cite{ovchinnikov2002max}]\label{thm-min-max-representation}
  Let $D \subseteq \mathbb{R}^k$ be convex.
  For every continuous piecewise affine function $f:D \to \mathbb{R}$ with components $f_1,\ldots,f_p$, there exists a family $S_1,\ldots,S_q \subseteq \{1,\ldots,p\}$ such that, for all $\vec{x} \in D$,
  $
    f(\vec{x}) = \max_{i \in \{1,\ldots,q\}} \min_{j \in S_i} f_j(\vec{x}).
  $
\end{thm}

Note that as a special case, the above result applies when $f$ is continuous piecewise linear. The above theorem as stated slightly generalizes the result due to Ovchinnikov~\cite{ovchinnikov2002max} (by not requiring $D$ to be closed), although the proof technique is essentially the same.
For completeness, we provide the proof in Appendix~\ref{app:A}.

The following lemma shows that any continuous piecewise rational linear function is stably computable by a CRC using the dual-rail representation.

\begin{lem}\label{lem-piecewise-linear-implies-computable}
  Let $D \subseteq \mathbb{R}^k$ be convex, and let $f:D \to \mathbb{R}$ be a continuous piecewise rational linear function.
  Then $f$ is stably dual-computed by a CRC.

\end{lem}

\begin{proof}
  By Theorem~\ref{thm-min-max-representation}, it suffices to show how to compute a dual-rail representation of any rational linear function, a dual-rail representation of the minimum function with two inputs, and a dual-rail representation of the maximum function with two inputs.
  The latter two can be composed in a tree of depth $\log l$ to compute the minimum or maximum functions with input arity $l$.

  Let $g:\mathbb{R}^k \to \mathbb{R}$ be a rational linear function $g(\vec{x}) = \sum_{i=1}^k a_i \vec{x}(i)$.
  By appropriate integer arithmetic, there exist $n_1,\ldots,n_k \in \mathbb{Z}$ and $d \in \mathbb{Z}^+$ such that
  $g(\vec{x}) = \frac{1}{d} \sum_{i=1}^k n_i \vec{x}(i).$
  The following reactions compute a dual-rail representation of $g$ with input species $X_1^+,\ldots,X_k^+, X_1^-,\ldots,X_k^-$ and output species $Y^+,Y^-$.
  For each $i$ such that $n_i > 0$, add the reactions
    \begin{eqnarray*}
    X_i^+ &\to& n_i W^+
    \\ X_i^- &\to& n_i W^-
    \end{eqnarray*}
  For each $i$ such that $n_i < 0$, add the reactions
    \begin{eqnarray*}
    X_i^+ &\to& |n_i| W^-
    \\ X_i^- &\to& |n_i| W^+
    \end{eqnarray*}
  To divide the values of $W^-$ and $W^+$ by $d$, add the reactions
    \begin{eqnarray*}
    d W^+ &\to& Y^+
    \\
    d W^- &\to& Y^-
    \end{eqnarray*}
  To see that this works, for all states $\vec{c}$, define $x_i(\vec{c}) = \vec{c}(X_i^+) - \vec{c}(X_i^-)$, $w(\vec{c}) = \vec{c}(W^+) - \vec{c}(W^-)$, and $y(\vec{c}) = \vec{c}(Y^+) - \vec{c}(Y^-).$
  Let $\vec{i}$ be the initial state.
  It is routine to check that the reactions enforce that for any state $\vec{c}$ reachable from $\vec{i}$,
  \begin{equation}\label{eq-linear-conservation-law}
    y(\vec{c}) + \frac{1}{d} w(\vec{c}) + \frac{1}{d} \sum_{i=1}^k n_i x_i(\vec{c}) = \frac{1}{d} \sum_{i=1}^k n_i x_i(\vec{i}).
  \end{equation}
  (The right side is a constant depending only on the initial state, and each reaction increases one term on the left side by the same amount it decreases another term.)

  If $\vec{c}$ is output stable, then $\vec{c}(X_i^+)=\vec{c}(X_i^-)=\vec{c}(W^+)=\vec{c}(W^-)=0$, whence by \eqref{eq-linear-conservation-law} $y(\vec{c})= \frac{1}{d} \sum_{i=1}^k n_i x_i(\vec{i})$, i.e, the output value of the CRC is the desired rational linear function of the inputs.
  Furthermore, observe that from any reachable state, it is always possible to reach an output stable state by executing the reactions above to completion in the order in which they are listed.
  This shows that a dual-rail representation of any rational linear function can be stably dual-computed by a CRC.

  The following reactions stably compute a dual-rail representation of $\min$ with input species $X_1^+$, $X_2^+$, $X_1^-$, $X_2^-$ and output species $Y^+$, $Y^-$.
  Add the reactions
  \begin{eqnarray}
    X_1^+ + X_2^+ &\to& Y^+ \label{rxn-min-1}
    \\
    X_1^- &\to& X_2^+ + Y^- \label{rxn-min-2}
    \\
    X_2^- &\to& X_1^+ + Y^- \label{rxn-min-3}
  \end{eqnarray}
  To see that this works, for all states $\vec{c}$, define $x_1(\vec{c}) = \vec{c}(X_1^+) - \vec{c}(X_1^-)$, $x_2(\vec{c}) = \vec{c}(X_2^+) - \vec{c}(X_2^-)$, and $y(\vec{c}) = \vec{c}(Y^+) - \vec{c}(Y^-).$
  Let $\vec{i}$ be the initial state, and let $\vec{c}$ be a state reachable from $\vec{i}$.
  Let $c_1$, $c_2$, and $c_3$ be the amount of reactions \eqref{rxn-min-1}, \eqref{rxn-min-2} and \eqref{rxn-min-3}, respectively, that have executed to get from state $\vec{i}$ to state $\vec{c}$.
  Then we have
  $x_1(\vec{i}) - c_1 + c_2 + c_3 = x_1(\vec{c}), x_2(\vec{i}) - c_1 + c_2 + c_3 = x_2(\vec{c}), c_1 - c_2 - c_3 = y(\vec{c}),$

  which implies that
  $x_1(\vec{i}) = x_1(\vec{c}) + y(\vec{c}), x_2(\vec{i}) = x_2(\vec{c}) + y(\vec{c}).$

  In a stable state $\vec{c}$, either $\vec{c}(X_1^+)=0$ or $\vec{c}(X_2^+) = 0$, otherwise reaction \eqref{rxn-min-1} is applicable.
  Further, in a stable state $\vec{c}$, $x_1(\vec{c}) = \vec{c}(X_1^+)$ and $x_2(\vec{c}) = \vec{c}(X_2^+)$, because $\vec{c}(X_1^-) = \vec{c}(X_2^-) = 0$ for reactions \eqref{rxn-min-2} and \eqref{rxn-min-3} not to be applicable.
  Thus, $x_1(\vec{c}) = 0$ or $x_2(\vec{c}) = 0$.

  Thus, $x_1(\vec{i}) = y(\vec{c})$ and $x_2(\vec{i}) = x_2(\vec{c}) + y(\vec{c})$, or $x_2(\vec{i}) = y(\vec{c})$ and $x_1(\vec{i}) = x_1(\vec{c}) + y(\vec{c})$.
  So if $x_1(\vec{i}) < x_2(\vec{i})$, then it must be the first case (since $x_2(\vec{c}) > 0$).
  Otherwise, the second case holds.
  This shows that if stable state is reached, then computation is correct.
  Finally, observe that from any reachable state, by executing to completion the last applicable reaction among \eqref{rxn-min-2} and \eqref{rxn-min-3}, followed by executing to completion \eqref{rxn-min-1}, we obtain concentration zero of $X_1^-$, $X_2^-$, and one of $X_1^+$ or $X_2^+$, which implies that no reaction is applicable and the state is output stable.

  To stably compute a dual-rail representation of max, observe that it is equivalent to computing the min function with the roles of the ``plus'' and ``minus'' species reversed (which negates the value represented in dual-rail),
  because $\max(x_1,x_2) = - \min(-x_1,-x_2)$.
  In other words, add the reactions
  \begin{eqnarray*}
    X_1^- + X_2^- &\to& Y^-
    \\
    X_1^+ &\to& X_2^- + Y^+
    \\
    X_2^+ &\to& X_1^- + Y^+
  \end{eqnarray*}
  By appropriate renaming of input and output species of the three types of CRCs described above, they can be composed to compute $f(\vec{x}) = \max_{i \in \{1,\ldots,q\}} \min_{j \in S_i} f_j(\vec{x})$ as in Theorem~\ref{thm-min-max-representation}.
\end{proof}

Given any continuous piecewise linear function,
the above construction describes a CRC that stably dual-computes it.
Moreover, we can confirm by inspection that our construction is feedforward (see Section~\ref{sec:feedforward}).
Therefore, Lemma~\ref{lem:mass-action-convergence-stable-computation} implies that our CRC actually converges to the correct output value under mass-action no matter how an adversary might have pushed us initially:
\begin{cor} \label{cor:1}
For any input state $\vec{x}$, for any state $\vec{z}$ reachable from $\vec{x}$, the mass-action trajectory of the CRC of Lemma~\ref{lem-piecewise-linear-implies-computable} starting at $\vec{z}$ converges to the output stable state in the limit $t \to \infty$.
\end{cor}

\subsection{Positive-Continuous Piecewise Rational Linear Functions are Directly Computable}\label{sec:positive-continuous-piecewise-rational-linear-computable}

\begin{lem}\label{lem-nonnegative-piecewise-linear-implies-computable}
  Every positive-continuous piecewise rational linear function $f:\mathbb{R}_{\geq 0}^k \to \mathbb{R}_{\geq 0}$ is stably computable by a CRC.
\end{lem}

\begin{proof}
  The CRC will have input species $X_1,\ldots,X_k$ and output species $Y^+$.
(While it will be helpful to think of a $Y^+$ and $Y^-$ species, and during the computation the output will be encoded in their difference, the output of the CRC is only the $Y^+$ species as per direct computability.)

  Let $f:\mathbb{R}_{\geq 0}^k \to \mathbb{R}_{\geq 0}$ be a positive-continuous piecewise linear function.
  Since it is positive-continuous, there exist $2^k$ domains
  $$D_U = \{ \vec{x} \in \mathbb{R}_{\geq 0}^k \ |\ (\forall i \in \{1,\ldots,k\})\ \vec{x}(i) > 0 \iff i \in U \},$$
  one for each subset $U \subseteq \{1,\ldots,k\}$, such that $f \upharpoonright D_U$ is continuous on $D_U$.
  Define $f_U = f \upharpoonright D_U$. Since $D_U$ is convex, by Lemma~\ref{lem-piecewise-linear-implies-computable} there is a CRC $\mathcal{C}_U$ computing a dual-rail representation $\hat{f}_U:\mathbb{R}_{\geq 0}^k\times\mathbb{R}_{\geq 0}^k\to\mathbb{R}\times\mathbb{R}$ of $f_U$.
  By letting the initial concentration of the ``minus'' version of the $i$'th input species $X_i^-$ be 0, we convert $\mathcal{C}_U$ into a CRC that directly computes an output dual-rail representation of $f_U$.

  The intuition of the proof is as follows.
The case $U=\emptyset$ is trivial, as we will have no reactions of the form $\emptyset \to A$ for any species $A$, so if no species are initially present, no species (including $Y^+$) will ever be produced.
For each non-empty $U$, we compute  $f_U$ independently in parallel by CRC $\mathcal{C}_{U}$, modifying each reaction producing $Y^+$ to produce an equivalent amount of species $Y_U$, which is specific to $U$.
For each such $U$ there are inactive and active ``indicator'' species $J_U$ and $I_U$.
  In parallel, there are reactions that will activate indicator species $I_U$ (i.e.~convert $J_U$ to $I_U$) if and only if all species $X_i$ are present initially for each $i \in U$.
  These $I_U$ species will then counteract the effect of any CRC computing $f_{U'}$ for $U' \subset U$ by catalytically converting all $Y_{U'}$ to $Y^-$.
  If $U$ is the complete set of indices of non-zero inputs, then only CRCs computing $f_{U'}$ for subsets $U' \subset U$ have produced any amount of $Y^+$, so eventually all of these will be counteracted by $I_U$.

  Formally, construct the CRC as follows.
  For each $i \in \{1,\ldots,k\}$, add the reaction
    $X_i \to I_{\{i\}} + J_{\{i\}} +  J_{U_1} + X_i^{U_1} + J_{U_2} + X_i^{U_2} + \ldots + J_{U_{l}} + X_i^{U_{l}},$
  where $U_1,U_2,\ldots,U_{l}$ are all subsets of $\{1,\ldots,k\}$ that are strict supersets of $\{ i \}$.
  The extra versions of $X_i$ are used as inputs to the parallel computation of each $f_U$.
  We generate the inactive indicator species from the input species in this manner, because the CRC is not allowed to start with anything other than the input.

  The indicator species are activated as follows. For each nonempty $U,U' \subseteq \{1,\ldots,k\}$ such that $U \neq U'$, add the reaction
  $
    I_U + I_{U'} + J_{U \cup U'} \to I_U + I_{U'} + I_{U \cup U'}.
  $

  For each nonempty $U \subseteq \{1,\ldots,k\}$, let $\mathcal{C}_U$ be the CRC computing an output dual-rail representation of $f_U$ (i.e.~dual rail on the output).
  Modify $\mathcal{C}_U$ as follows.
  Rename the output species of $\mathcal{C}_U$ to $Y^+$ and $Y^-$, i.e., all parallel CRCs share the same output species.
  For each reaction producing the output species $Y^+$, add the product $Y^+_U$ (which is a species specific to $\mathcal{C}_U$) with the same net stoichimetry.
  Similarly, for each reaction producing the output species $Y^-$, add the product $Y^-_U$ with the same net stoichimetry.
  For instance, replace the reaction $A + B \to Y^+$ by the reaction $A + B \to Y^+ + Y^+_U$, and replace the reaction $A + Y^+ \to B + 4 Y^+$ by the reaction $A + Y^+ \to B + 4 Y^+ + 3 Y^+_U$.
  Therefore the eventual amount of $Y_U^+$ is equal to the total amount of $Y^+$ produced by $\mathcal{C}_U$, and similarly for $Y_U^-$ and $Y^-$.
  For each $U' \subset U$, add the reactions

    $I_U + Y^+_{U'} \to I_U + Y^-$,

    $I_U + Y^-_{U'} \to I_U + Y^+.$

  Also, for each reaction in $\mathcal{C}_U$, add $I_U$ as a catalyst.
  This ensures that $\mathcal{C}_U$ cannot execute any reactions (and therefore cannot produce any amount of $Y^+$ or $Y^-$) unless all species $X_i$ for $i \in U$ are present.
  Finally, add the reaction $Y^+ + Y^- \to \emptyset$.
\end{proof}

Similarly to Corollary~\ref{cor:1}, since our construction is again feedforward,
the CRC converges to the correct output value under mass-action kinetics from any reachable state:
\begin{cor}
\label{cor:2}
For any input state $\vec{x}$, for any state $\vec{z}$ reachable from $\vec{x}$, the mass-action trajectory of the CRC of Lemma~\ref{lem-nonnegative-piecewise-linear-implies-computable} starting at $\vec{z}$ converges to the output stable state in the limit $t \to \infty$.
\end{cor}

\section{Negative Results}
\label{sec:negative-results}

\cref{subsec-negative-computable-implies-piecewise-linear} concerns inputs represented \emph{directly} by nonnegative concentrations.
\cref{subsec:negative-dual-rail} concerns \emph{dual-rail} representation as defined in Subsection~\ref{subsec:dual-rail-defn}.

\subsection{Directly Computable Functions are Positive-Continuous Piecewise Rational Linear}\label{subsec-negative-computable-implies-piecewise-linear}

\subsubsection{Siphons and output stability}

In order to characterize stable function computation for CRCs, we will crucially rely on the notion of siphons, which we recall from~\cref{sec:mass-action-reachability}.
Lemma~\ref{lem:siphon-stable} shows the underlying relationship between output stability and siphons.

Let $\mathcal{C}=(\Lambda,R,\Sigma,Y)$ be a CRC.
We call any siphon $\Omega$ such that $(\vec{c}  \upharpoonright \Omega = \vec{0}) \implies$ ($\vec{c}$ is output stable) an \emph{output stable siphon}.

\begin{lem}  \label{lem:siphon-stable}
  Either every state is output stable,
  or every state is output unstable,
  or there is a set of output stable siphons $\mathcal{S}$ such that a state $\vec{c}$ is output stable if and only if $\exists \Omega \in \mathcal{S}$ such that\ $\vec{c} \upharpoonright \Omega = \vec{0}$.
\end{lem}

In order to prove the above lemma,
we first prove a useful fact about siphons.
The next lemma shows that if a set of species has even a single state from which none of the species can be produced, then it is a siphon.

\begin{lem}  \label{lem:siphonexists}
    If $\vec{c}$ is a state and $\Omega'$ is a set of species such that for all $\vec{d}$ reachable from $\vec{c}$, $\vec{d} \upharpoonright \Omega' = \vec{0}$,
    then there exists a siphon $\Omega \supseteq \Omega'$ such that $\vec{c} \upharpoonright \Omega = \vec{0}$.
\end{lem}
\begin{proof}
    There is a unique largest set of species $\overline{\Omega}$ such that $\forall S \in \overline{\Omega}$, $\exists \vec{d}$ reachable from $\vec{c}$ and $\vec{d}(S) > 0$, i.e., $\overline{\Omega}$ is the set of species producible from $\vec{c}$.
    Let $\vec{d}$ be a state reachable from $\vec{c}$ such that, for all $S \in \overline{\Omega}$,  $\vec{d}(S) > 0$; such a state exists by Lemma~\ref{lem:produce-all}.
    Let $\Omega = \Lambda \setminus \overline{\Omega}$; we must show $\Omega$ is a siphon.

    Suppose for the sake of contradiction that $\Omega$ is not a siphon.
    Then there exists some state $\vec{c}'$ with $\vec{c}' \upharpoonright \Omega = 0$ (implying $[\vec{c}'] \subseteq [\vec{d}]$), some state $\vec{d}'$ reachable from $\vec{c}'$, and $S \in \Omega$, such that $\vec{d}'(S) > 0$.
    Let $\epsilon > 0$ be sufficiently small that $\epsilon \cdot \vec{c}' \leq \vec{d}$; such an $\epsilon$ exists because $[\vec{c}'] \subseteq [\vec{d}]$.
    Then $\epsilon \cdot \vec{d}'$ is reachable from $\epsilon \cdot \vec{c}'$, and $\epsilon \cdot \vec{d}'(S) > 0$.
    Since $\epsilon \cdot \vec{c}' \leq \vec{d}$ and reachability respects addition, this implies that $S$ is producible from $\vec{d}$ (hence from $\vec{c}$) as well, implying $S \in \overline{\Omega}$, a contradiction since we chose $S \in \Omega$ and $\Omega \cap \overline{\Omega} = \emptyset.$
\end{proof}

We are now ready to prove Lemma~\ref{lem:siphon-stable}.

\begin{proof}(of Lemma~\ref{lem:siphon-stable})
    We create the set of siphons as follows.
    Let $\{r_j = (\vec{r}_j,\vec{p}_j)\}_j$ be the set of all reactions that change $Y$ (consume or produce; i.e., $\vec{r}_j(Y) \neq \vec{p}_j(Y)$).
    We construct sets of species $\{ \Omega'_k \}_k$ by taking one reactant from each reaction in every possible way (i.e., the set of subsets of species $\setr{\Omega'_k \subseteq \Lambda}{(\forall j)\ \Omega'_k \cap \vec{r}_j \neq \emptyset}$).
    For each possible siphon $\Omega$ such that $\Omega \supseteq \Omega'_k$, add $\Omega$ to $\mathcal{S}$.
    It is easy to see that if $\vec{c}$ is zero on some siphon $\Omega \in \mathcal{S}$ then it is output stable.

    For the other direction:
    Let $O(\vec{c}) = \setl{\Omega'_k}{\vec{c} \upharpoonright \Omega'_k = \vec{0}}$.
    If in some state $\vec{c}$, we have $O(\vec{c}) = \emptyset$,
    then there is a reaction $r_j$ that changes $Y$ and is applicable in $\vec{c}$.
    Then $Y$ can change by this reaction and $\vec{c}$ cannot be output stable.
    So for output stable $\vec{c}$,  $O(\vec{c})$ is non-empty.
    Now let $\vec{d}_1, \dots, \vec{d}_l$ be some states reachable from $\vec{c}$ such that if $\vec{c} \to \vec{d}$ then $\exists i, O(\vec{d}_i) = O(\vec{d})$ (i.e.\ these states cover the whole variety of $O(\vec{d}_i)$'s).
    Lemma~\ref{lem:produce-all} implies that if $\cap_{i=1}^l O(\vec{d}_i) = \emptyset$
    then $\vec{c} \to \vec{d}$ such that $O(\vec{d}) = \emptyset$.
    Thus, for an output stable $\vec{c}$,
    at least one of the original sets $\Omega'_k \in O(\vec{c})$ stays zero on all states reachable from $\vec{c}$.
    This implies that there is some siphon $\Omega \in \mathcal{S}$ that includes $\Omega'_k$ and $\vec{c} \upharpoonright \Omega = \vec{0}$ (by Lemma~\ref{lem:siphonexists}).
\end{proof}

\input{wyatts-proof-2}

\section{Defining Rate-Independent Computation}
\label{sec-prelim}

\subsection{Chemical Reaction Networks}

We first explain our notation for vectors of concentrations of chemical species, and then formally define chemical reaction networks.

Given $S\in \Lambda$ and $\vec{c} \in \mathbb{R}_{\geq 0}^\Lambda$, we refer to $\vec{c}(S)$ as the \emph{concentration of $S$ in $\vec{c}$}.
For any $\vec{c}\in \mathbb{R}_{\geq 0}^\Lambda$, let $[\vec{c}] = \{S \in \Lambda \ |\ \vec{c}(S) > 0 \}$, the set of species \emph{present} in $\vec{c}$.
We write $\vec{c} \leq \vec{c}'$ to denote that $\vec{c}(S) \leq \vec{c}'(S)$ for all $S \in \Lambda$.
Given $\vec{c},\vec{c}' \in \mathbb{R}_{\geq 0}^\Lambda$, we define the vector component-wise operations of addition $\vec{c}+\vec{c}'$, subtraction $\vec{c}-\vec{c}'$, and scalar multiplication $x \vec{c}$ for $x \in \mathbb{R}$.
If $\Delta \subset \Lambda$, we view a vector $\vec{c} \in \mathbb{R}_{\geq 0}^\Delta$ equivalently as a vector $\vec{c} \in \mathbb{R}_{\geq 0}^\Lambda$ by assuming $\vec{c}(S)=0$ for all $S \in \Lambda \setminus \Delta.$
For $\Delta \subset \Lambda$, we write $\vec{c}  \upharpoonright \Delta$ to denote $\vec{c}$ \emph{restricted to} $\Delta$; in particular, $\vec{c}  \upharpoonright \Delta = \vec{0} \iff (\forall S\in\Delta)\ \vec{c}(S)=0.$

Given a finite set of chemical species $\Lambda$, a \emph{reaction} over $\Lambda$ is a pair $\alpha = \langle \mathbf{r},\mathbf{p} \rangle \in \mathbb{N}^\Lambda \times \mathbb{N}^\Lambda$, specifying the stoichiometry of the reactants and products, respectively.\footnote{It is customary to define, for each reaction, a \emph{rate constant} $k \in \mathbb{R}_{>0}$ specifying a constant multiplier on the mass-action rate (i.e., the product of the reactant concentrations), but as we are studying CRNs whose output is independent of the reaction rates, we leave the rate constants out of the definition.}
In this paper, we assume that $\mathbf{r} \neq \vec{0}$, i.e., we have no reactions of the form $\emptyset \to \ldots$.\footnote{We allow high order reactions; i.e., those that consume more than two reactants.
Such higher order reactions could be eliminated from our constructions using the transformation that replaces $S_1 + S_2 + \ldots + S_n \to P_1 + \ldots + P_m$ with bimolecular reactions $S_1 + S_2 \mathop{\rightleftharpoons}\limits S_{12}, S_{12} + S_3 \mathop{\rightleftharpoons}\limits S_{123}, S_{123} + S_4 \mathop{\rightleftharpoons}\limits S_{1234}, \ldots, S_n + S_{12 \ldots n-1} \to P_1 + \ldots + P_m$.
}
For instance, given $\Lambda=\{A,B,C\}$, the reaction $A+2B \to A+3C$ is the pair $\pair{(1,2,0)}{(1,0,3)}.$
Note that we represent reversible reactions such as $A \mathop{\rightleftharpoons}\limits B$ as two irreversible reactions $A \to B$ and $B \to A$.
A \emph{(finite) chemical reaction network (CRN)} is a pair $\mathcal{C}=(\Lambda,R)$, where $\Lambda$ is a finite set of chemical \emph{species},
and $R$ is a finite set of reactions over $\Lambda$.
A \emph{state} of a CRN $\mathcal{C}=(\Lambda,R)$ is a vector $\vec{c} \in \mathbb{R}_{\geq 0}^\Lambda$.
Given a state $\vec{c}$ and reaction $\alpha=\pair{\mathbf{r}}{\mathbf{p}}$, we say that $\alpha$ is \emph{applicable} in $\vec{c}$ if $[\mathbf{r}] \subseteq [\vec{c}]$ (i.e., $\vec{c}$ contains positive concentration of all of the reactants).

\subsection{Reachability}
\label{subsec-reachability}

In the previous section we defined the syntax of CRNs.
We wish to define a semantic interpretation of them suitable for defining how they compute functions.
In particular, we want to consider CRNs guaranteed to correctly compute a function of their inputs, regardless of the rate at which reactions proceed, calling this \emph{stable computation}, defined in Section~\ref{subsec-stable-crns}.
This definition rests on another, which we must take care in defining, namely what it means for one state to be \emph{reachable} from another, which is the focus of this section.
Intuitively, $\vec{d}$ is reachable from $\vec{c}$ if applying some amount of reactions to $\vec{c}$ results in $\vec{d}$, such that no reaction is ever applied when any of its reactants are concentration 0.
Formalizing this concept is a bit tricky and constitutes one of the contributions of this paper.
Intuitively, we'll think of reachability via straight line segments.
This may appear overly limiting; after all mass-action and other rate laws trace out smooth curves.
However in this and subsequent sections we show a number of properties of our definition that support its reasonableness.

Throughout this section, fix a CRN $\mathcal{C} = (\Lambda,R)$.
All states $\vec{c}$, etc., are assumed to be states of $\mathcal{C}$.
Let $m=|R|$ be the number of reactions in CRN $\mathcal{C}$, and let $n = |\Lambda|$ be the number of species in $\mathcal{C}$.
We define the $n \times m$ \emph{reaction stoichiometry matrix} $\vec{M}$ such that
$\vec{M}(i,j)$ is the net amount of the $i$'th species that is produced by the $j$'th reaction (negative if the species is consumed).\footnote{Note that $\vec{M}$ does not fully specify $\mathcal{C}$, since catalysts are not modeled: reactions $Z + X \to Z + Y$ and $X \to Y$ both correspond to the column vector $(-1,1,0)^\top$.}
For example, if we have the reactions $X \to Y$ and $X + A \to 2X + 3Y$, and if the three rows correspond to $X$, $A$, and $Y$, in that order, then
  $$
    \vec{M} =
    \left(
      \begin{array}{cc}
        -1 & 1 \\
        0 & -1 \\
        1 & 3 \\
      \end{array}
    \right)
  $$

\begin{definition}\label{defn-reachable-line}
State $\vec{d}$ is \emph{straight-line reachable (aka $1$-segment reachable)} from $\vec{c}$, written $\vec{c} \slto \vec{d}$, if $(\exists \vec{u} \in \mathbb{R}_{\geq 0}^m)\ \vec{c} + \vec{M} \vec{u} = \vec{d}$
and $\vec{u}(j) > 0$ only if reaction $j$ is applicable at $\vec{c}$.
In this case write $\vec{c} \slto_\vec{u} \vec{d}$.
\end{definition}

Intuitively, by a single segment we mean running the reactions applicable at $\vec{c}$ at a constant (possibly 0) rate to get from $\vec{c}$ to $\vec{d}$.
In the definition, $\vec{u}(j)$ represents the flux of reaction $j$.

\begin{definition}\label{defn-reachable-lines}
State $\vec{d}$ is \emph{$l$-segment reachable}, written $\vec{c} \segto^l \vec{d}$ from $\vec{c}$ if $(\exists \vec{b}_1, \dots, \vec{b}_{l+1})\ \vec{c}  = \vec{b}_1 \slto \vec{b}_2 \slto \vec{b}_3 \slto \dots  \slto \vec{b}_{l+1} = \vec{d}.$
\end{definition}

\begin{definition}\label{defn-reachable-segment}
State $\vec{d}$ is \emph{segment-reachable} (or simply \emph{reachable}) from $\vec{c}$, written $\vec{c} \segto \vec{d}$, if $(\exists l\in\mathbb{N})\ \vec{c} \segto^l \vec{d}$.
\end{definition}
Although more effort will be needed to justify its reasonableness, segment-reachability will serve as the main notion of reachability in this paper.

Suppose the reactions are $X \to C$ and $C + Y \to C + Z$, and we are in state $\{0 C, 1 X, 1 Y, 0 Z\}$.
With straight-line segments, any state with a positive amount of $Z$ must be reached in at least two segments: first to produce $C$, which allows the second reaction to occur, and then any combination of the first and second reactions.
For example,
$\{0 C$, $1 X$, $1 Y$, $0 Z\}$  $\slto$  $\{0.1 C$, $0.9 X$, $1 Y$, $0 Z\}$ $\slto$  $\{1 C$, $0 X$, $0 Y$, $1 Z\}$.
This is a simple example showing that more states are reachable with $\segto$ than $\slto$.
Often Definition~\ref{defn-reachable-segment} is used implicitly, when we make statements such as, ``Run reaction 1 until its first reactant is 0, then run reaction 2'', which implicitly defines two straight lines in concentration space.

Given a curve, we can think about approximating it to an arbitrary accuracy using straight-line segments.
But it may seem that we can never achieve the ``full diversity'' of states reachable with curves if we use only a bounded number of line segments.
However, Theorem~\ref{thm-reachable-segment-bound} shows that increasing the number of straight-line segments beyond a certain point does not make any additional states reachable.
Thus using a few line segments captures all the states reachable in the limit of infinitely many line segments.

In order to prove  Theorem~\ref{thm-reachable-segment-bound} we first develop important machinery for representing and manipulating paths under $\segto$.
Note that reachability is closed under addition and scaling in the sense that if $\vec{c} \segto \vec{d}$ and $\vec{c}' \segto \vec{d}'$ then $\alpha \vec{c} + \beta \vec{c}' \segto \alpha \vec{d} + \beta \vec{d}'$ for all $\alpha, \beta \in \mathbb{R}_{\ge 0}$.
The following definition captures this property by defining a linear space of all paths.
The vector space as a whole is infinite dimensional,
even though all but finitely many entries are 0 in any particular vector we consider.
However, the infinite dimensions allow us to handle arbitrarily long paths in a uniform way,
with each dimension corresponding to a segment of a path.
This machinery will also be key to proving the piecewise linearity of the computed function in Section~\ref{subsec-negative-computable-implies-piecewise-linear}.

For infinite collections of vector spaces, the notation $\oplus$ indicates the infinite direct sum, which is a restriction of $\times$ allowing only finitely many entries to be nonzero.

\begin{defn}\label{def:prepaths}
Let $V$ be the vector space $V = \mathbb{R}^\Lambda \times \bigoplus_{i = 1}^\infty \mathbb{R}^R$. We call an element of $V$ a \emph{prepath}. In other words, a prepath $\gamma \in V$ is specified by a sequence of vectors $(\vec{x}_0, \vec{u}_1, \vec{u}_2, \ldots)$ with $\vec{x}_0 \in \mathbb{R}^\Lambda$ and $\vec{u}_i \in \mathbb{R}^R$ for all $i$, with $\vec{u}_i = 0$ for all $i$ sufficiently large. Intuitively, $\vec{x}_0$ is the initial state of $\gamma$ and $\vec{u}_i$ is the flux vector that is fired along the $i$th segment of $\gamma$.

We also define linear maps $\vec{x}_i: V \to \mathbb{R}^\Lambda$, which take as input a prepath $\gamma = (\vec{x}_0, \vec{u}_1, \vec{u}_2, \ldots) \in V$ and produce as output
\[\vec{x}_i(\gamma) = \vec{x}_0 + \sum_{i = 1}^n M \vec{u}_i,\]
which intuitively is the state reached after traversing $i$ segments along $\gamma$.
\end{defn}

\begin{defn}\label{def:paths}
Let $\Gamma$ be the subset of $V$ consisting of vectors $\gamma = (\vec{x}_0, \vec{u}_1, \vec{u}_2, \ldots)$ that are required to satisfy the following two conditions:
\begin{enumerate}
    \item $\vec{x}_0 \in \mathbb{R}_{\geq 0}^\Lambda$ and $\vec{u}_i \in \mathbb{R}_{\geq 0}^R$ for all $i$.

    \item for all $i$ the vector $\vec{x}_i(\gamma) \in \mathbb{R}^\Lambda$ is in $\mathbb{R}_{\geq 0}^\Lambda$ and every reaction with positive flux in $\vec{u}_{i+1}$ is applicable at $\vec{x}_i$.
\end{enumerate}
We call an element of $\Gamma$ a \emph{piecewise linear path} or sometimes just a \emph{path}.
\end{defn}

\begin{defn}
For $k\in \mathbb{N}$, define $\Gamma_k$ to be the subset of $\Gamma$ consisting of all paths $\gamma = (\vec{x}_0, \vec{u}_1, \vec{u}_2, \ldots)$ such that $\vec{u}_i = 0$ for all $i > k$.
\end{defn}

Intuitively, $\Gamma$ is the space of all of the valid piecewise linear paths that the system can take starting from any given initial state and $\Gamma_k$ is the set of all such paths that have length at most $k$.

\begin{lem}\label{lem:Pathspace-convex}
$\Gamma$ is convex and so is $\Gamma_k$ for each $k$.
\end{lem}

\begin{proof}
Let $\gamma_0, \gamma_1 \in \Gamma$ be two paths and consider $\lambda \in (0,1)$. We need to show that $\gamma_\lambda = (1 - \lambda)\gamma_0 + \lambda \gamma_1$ is in $\Gamma$. Note that for any $n$,
\[\vec{x}_n(\gamma_\lambda) = (1- \lambda)\vec{x}_n(\gamma_0) + \lambda \vec{x}_n(\gamma_1).\]
Since $\mathbb{R}_{\geq 0}^\Lambda$ is convex and both $\vec{x}_n(\gamma_1)$ and $\vec{x}_n(\gamma_2)$ are in $\mathbb{R}_{\geq 0}^\Lambda$, we conclude that $\vec{x}_n(\gamma_\lambda)$ is in $\mathbb{R}_{\geq 0}^\Lambda$, too. Since
\[\vec{u}_n(\gamma_\lambda) = (1 - \lambda)\vec{u}_n(\gamma_0) + \lambda \vec{u}_n(\gamma_1),\]
the $j$-th coordinate of $\vec{u}_n(\gamma_\lambda)$ is positive only if the $j$-th coordinate of $\vec{u}_n(\gamma_i)$ is positive for $i = 0$ or 1. Without loss of generality, suppose that $\vec{u}_n(\gamma_0) > 0$. Then reaction $j$ is applicable at $\vec{x}_{n-1}(\gamma_0)$, so the reactants are all present in positive concentrations in $\vec{x}_{n - 1}(\gamma_0)$. This implies that they are present with positive concentrations in $\vec{x}_{n - 1}(\gamma_\lambda)$ (note that we have excluded the case $\lambda = 1$ from the outset). Therefore reaction $j$ is applicable at $\vec{x}_{n-1}(\gamma_\lambda)$.
This argument applies to any coordinate of $\vec{u}_n(\gamma_\lambda)$ which is positive, so we conclude that $\vec{u}_n(\gamma_\lambda)$ is applicable at $\vec{x}_{n-1}(\gamma_\lambda)$. This shows that $\Gamma$ is convex.

To see that $\Gamma_k$ is also convex, note that if $\vec{u}_n(\gamma_0) = 0$ and $\vec{u}_n(\gamma_1) = 0$ then $\vec{u}_n(\gamma_\lambda)$ will also be zero.
\end{proof}

\begin{lem}  \label{lem:produce-all}
    Let $k \in \mathbb{N}$  and let $\vec{c},\vec{d}_1,\ldots,\vec{d}_l$ be states such that $\vec{c} \segto^k \vec{d}_1$, $\ldots$, $\vec{c} \segto^k \vec{d}_l$. Then there exists $\vec{d}$ such that $\vec{c} \segto^k \vec{d}$ and $[\vec{d}] = \bigcup_{i=1}^l [\vec{d}_i]$.
\end{lem}

\begin{proof}
    Write $\gamma_i$ for the path from $\vec{c}$ to $\vec{d}_i$; the convexity of $\Gamma_k$ shows that the convex combination
    \[\gamma = \frac{1}{l}\sum_{1 \le i \le l} \gamma_i\]
    is a valid path in $\Gamma_k$. Letting
    \[\vec{d} = \frac{1}{l}\sum_{1 \le i \le l} \vec{d}_i,\]
    $\gamma$ exhibits a $k$-segment path from $\vec{c}$ to $\vec{d}$.  If $S$ is a species that is present at $\vec{d}_i$ for any $i$ then $S$ is also present at $\vec{d}$. On the other hand, if $S$ is present in none of the $\vec{d}_i$ then $S$ is not present in $\vec{d}$. As a result, $[\vec{d}] = \bigcup_{i=1}^l [\vec{d}_i]$.
\end{proof}

\begin{definition}
Given a state $\vec{c}$, let $\mathcal{P}(\vec{c})$ be the set of all species that are present in some state that is segment-reachable from $\vec{c}$.
\end{definition}

\begin{lemma}\label{lem-all-species-present}
Let $m$ be the minimum of $|R|$ and $|\Lambda|$ and let $\vec{c}$ be any state. Then there is a state $\vec{d}$ such that $\vec{c} \segto^{m} \vec{d}$ and $[\vec{d}] = \mathcal{P}(\vec{c})$.
\end{lemma}

\begin{proof}
    For all $i \in \mathbb{N}$, let $\Lambda_i$ be the set of species $S$ such that there exists a $\vec{d}$ with $\vec{c} \segto^i \vec{d}$ and $S \in [\vec{d}]$. Similarly, let $R_i$ be the set of reactions such that there exists a $\vec{d}$ with $\vec{c} \segto^i \vec{d}$ and $R$ is applicable at $\vec{d}$. Note that $\Lambda_0 = [\vec{c}]$ and $R_0$ is the set of reactions applicable at $\vec{c}$. Also, since $\vec{c} \segto^i \vec{d}$ implies $\vec{c} \segto^{i + 1} \vec{d}$ we see that $\Lambda_i \subseteq \Lambda_{i + 1}$ and $R_i \subseteq R_{i + 1}$ for all $i$.

    Now we show that for all $i$ there exists some $\vec{x}_i$ such that $[\vec{x}_i] = \Lambda_i$ and $\vec{c} \segto^i \vec{x}_i$ (and therefore $R_i$ consists of the reactions applicable at $\vec{x}_i$). To see this, for each $S \in \Lambda_i$ let $\vec{d}_S$ be a state such that $\vec{c} \segto^i \vec{d}_S$ and $S \in [\vec{d}_S]$. By applying Lemma~\ref{lem:produce-all} to the set of all $\vec{d}_S$, there is some $\vec{d}$ such that $\vec{c} \segto^i \vec{d}$ and $[\vec{d}] = \Lambda_i$; this $\vec{d}$ is our desired $\vec{x}_i$.

    Now we will show that if $\Lambda_i = \Lambda_{i + 1}$ then $R_i = R_{i + 1}$ and, independently, if $R_i = R_{i + 1}$ then $\Lambda_{i + 1} = \Lambda_{i + 2}$ for all $i$. First suppose that $\Lambda_i = \Lambda_{i + 1}$ and let $\alpha$ be a reaction in $R_{i + 1}$. Then there is some state $\vec{d}$ such that $\vec{c} \segto^i \vec{d}$ and $\alpha$ is applicable at $\vec{d}$. Since all of the reactants of $\alpha$ are present at $\vec{d}$, they are a subset of $\Lambda_{i + 1} = \Lambda_i$. They are therefore present at $\vec{x}_i$, so $\alpha$ is applicable at $\vec{x}_i$. We conclude that $\alpha \in R_i$ so $R_{i + 1} = R_i$.

    Now suppose that $R_i = R_{i + 1}$ and let $S$ be a species in $\Lambda_{i + 2}$. Then there is some $\vec{d}$ such that $\vec{c} \segto^{i + 2} \vec{d}$ and $S \in [\vec{d}]$. Since $S$ must be produced by some reaction $\alpha$ in $R_{i + 1} = R_i$, we can apply $\alpha$ to $\vec{x}_i$ to obtain a state $\vec{d}'$ such that $\vec{c} \segto^i \vec{x}_i \to^1 \vec{d}'$ and $S \in [\vec{d}']$. We conclude that $S \in \Lambda_{i + 1}$ so $\Lambda_{i + 2} = \Lambda_{i + 1}$.

    Combining the two statements we just proved, we see that if $\Lambda_i = \Lambda_{i + 1}$, then $\Lambda_i = \Lambda_j$ for all $j \ge i$, so $\Lambda_i = \mathcal{P}(\vec{c})$. Similarly, if $R_i = R_{i + 1}$, then $\Lambda_{i + 1} = \mathcal{P}(\vec{c})$.

    If $|\Lambda| \le |R|$, then since $\Lambda_0 \subseteq \Lambda_1 \subseteq \ldots$ is an increasing sequence of subsets of $\Lambda$, it must be the case that $\Lambda_j = \Lambda_{j + 1}$ for some $j \le |\Lambda|$, and in this case $\vec{x}_j$ gives our desired $\vec{d}$. If, on the other hand, $|R| \le |\Lambda|$, the proof is similar: first note that if $R_0 = \emptyset$ we're done. Otherwise $|R_0| \ge 1$ so since $R_i$ is an increasing sequence of subsets of $R$ there is some $j \le |R| - 1$ such that $R_j = R_{j + 1}$. Then $\Lambda_{j + 1} = \mathcal{P}(\vec{c})$ so $\vec{x}_{j + 1}$ gives our desired $\vec{d}$.
\end{proof}

\begin{lem}\label{lem-all-producible-present}
Suppose $\vec{c}$ is a state in $\mathbb{R}_{\geq 0}^\Lambda$ such that every species
{producible from $\vec{c}$}
is present in $\vec{c}$ (i.e., $[c] = \mathcal{P}(c)$).
Then every state $\vec{d}$  segment-reachable from $\vec{c}$ is straight-line reachable from $\vec{c}$.
\end{lem}

\begin{proof}
Let $\vec{u}_1, \ldots, \vec{u}_n$ be the flux vectors corresponding to the segments in the path from $\vec{c}$ to $\vec{d}$. Then $\vec{u} = \vec{u}_1 + \ldots + \vec{u}_n$ is a vector in $\mathbb{R}_{\geq 0}^R$. Since every reaction with positive flux in $\vec{u}$ has positive flux in one of the $\vec{u}_i$, since these reactions can only use species producible from $\vec{c}$, and since every species producible from $\vec{c}$ is already present at $\vec{c}$, we see that $\vec{u}$ is applicable at $\vec{c}$.  The straight-line from $\vec{c}$ corresponding to $\vec{u}$ takes $\vec{c}$ to
\[\vec{c} + M\vec{u} = \vec{c} + \sum_{i = 1}^n M\vec{u}_i = \vec{d},\]
so $\vec{c} \to_\vec{u}^1 \vec{d}$.
\end{proof}

\begin{thm}\label{thm-reachable-segment-bound}
  If $\vec{c} \segto \vec{d}$, then $\vec{c} \segto^{m+1} \vec{d}$, where $m$ is the minimum of $|R|$ and $|\Lambda|$.
\end{thm}

\begin{proof}
    First, without loss of generality we can consider the reduced CRN where we remove all of the reactions that are not used with positive flux in the given path from $\vec{c}$ to $\vec{d}$. By Lemma~\ref{lem-all-species-present}, we can find a state $\vec{c}'$ such that $\vec{c} \segto^m \vec{c}'$ and $[\vec{c}'] = \mathcal{P}(\vec{c})$.
    We now show that we can ``scale-down'' the path $\vec{c} \segto^m \vec{c}'$ such that no reaction occurs more than in the original path $\vec{c} \segto \vec{d}$, allowing us to complete the path to $\vec{d}$ using Lemma~\ref{lem-all-producible-present}.

    If we let $\gamma \in \Gamma$ be a path, let $F_{\gamma, \alpha}$ be the total flux through the reaction $\alpha$ along $\gamma$, i.e.
    \[F_{\gamma, \alpha} = \sum_{i = 1}^n \alpha(\vec{u}_i).\]
    Note that if $\gamma = \lambda \gamma_1 + (1 - \lambda) \gamma_0$, then
    \[F_{\gamma, \alpha} = \lambda F_{\gamma_1, \alpha} + (1 - \lambda) F_{\gamma_0, \alpha}.\]

    Let $\sigma \in \Gamma_m$ be the path from $\vec{c}$ to $\vec{c}'$, let $\sigma_0 \in \Gamma_0 \subseteq \Gamma_m$ be the constant path at $\vec{c}$, and let $\gamma \in \Gamma$ be the given path from $\vec{c}$ to $\vec{d}$. We can find some small $\varepsilon > 0$ such that
    \[\varepsilon F_{\sigma, \alpha} < F_{\gamma, \alpha}\]
    for all $\alpha \in R$. As a result, letting $\gamma' = \varepsilon \sigma + (1 - \varepsilon) \sigma_0$, we see that
    \[F_{\gamma', \alpha} = \varepsilon F_{\sigma, \alpha} + ( 1- \varepsilon) F_{\sigma_0, \alpha}  = \varepsilon F_{\sigma, \alpha} < F_{\gamma, \alpha}.\]

    If we let $\vec{a}$ be the state reached via $\gamma'$
    (in particular $\vec{c} \segto^m \vec{a}$), we claim that $\vec{d}$ is straight-line reachable from $\vec{a}$. Because we are considering the reduced CRN, every reaction is applicable from a state reachable from $\vec{c}$, so since $[\vec{a}] = \mathcal{P}(\vec{c})$ all reactions are applicable at $\vec{a}$.
    By Lemma~\ref{lem-all-producible-present},
    the final straight line from $\vec{a}$ can be defined by the flux vector $\vec{u}_\alpha = F_{\gamma, \alpha} - F_{\gamma', \alpha}$, so that $\vec{a} + \vec{M} \vec{u} = \vec{d}$.
    This shows that
    $\vec{a} \to^1 \vec{d}$, so
    $\vec{c} \segto^{m+1} \vec{d}$.
\end{proof}

\subsection{Mass-Action Trajectories Follow Reachability}
\label{sec:mass-action-reachability}
For understanding the results of this paper, it is not necessary to be familiar with mass-action kinetics.
However, as mass-action is the most commonly used model of chemical kinetics, we want to be satisfied that our notion of reachability at least considers states that can be reached by mass-action trajectories.
Indeed, Theorem~\ref{thm:mass-action-reachable} shows that our notion of reachability is more general than mass-action.

While a thorough discussion of mass-action kinetics is beyond the scope of this paper,
we remind the reader that a CRN with rate constants assigned to each reaction defines a mass-action ODE (ordinary differential equation) system with a variable for each species,
which  represents the time-varying concentration of that species. We follow the convention of upper-case species names and lower-case concentration variables.
Each reaction contributes a term to the ODEs for all the species participating in it (except catalysts that are unchanged in the reaction).
The term from reaction $\alpha$ appearing in the ODE for $x$ is the product of:
the rate constant,
the reactant concentrations,
and the net stoichiometry of $X$ in $\alpha$.
For example, the CRN
\begin{align*}
X + X &\to C \\
C + X &\to C + Y
\end{align*}
corresponds to ODEs:
\begin{align*}
dx/dt &= -2 k_1 x^2 - k_2 c x \\
dc/dt &= k_1 x^2 \\
dy/dt &=  k_2 c x.
\end{align*}
where $k_1, k_2$ are the rate constants of the two reactions.
We restrict our attention to CRNs whose mass-action trajectories are well-defined at all times $t \geq 0$, and where concentrations remain finite for all finite $t$.\footnote{Although mass-action systems are free of many pathologies of more general dynamical systems, there are mass-action CRNs that reach infinite concentration in finite time: e.g.~$2X \to 3X$.}

\begin{definition}
A state $\vec{d}$ is \emph{mass-action reachable} from $\vec{c}$ if there are non-zero rate constants such that the corresponding mass-action trajectory starting in $\vec{c}$ passes through $\vec{d}$, or approaches $\vec{d}$ as $t \rightarrow \infty$.
\end{definition}

In order to prove Theorem~\ref{thm:mass-action-reachable} we need to introduce the notion of a \emph{siphon} from the Petri net literature.
This notion will be used, as well, to prove negative results in later sections.
Let $\mathcal{C}=(\Lambda,R)$ be a CRN.
A \emph{siphon} is a set of species $\Omega \subseteq \Lambda$ such that, for all reactions $\alpha=(\vec{r},\vec{p}) \in R$, $[\vec{p}] \cap \Omega \neq \emptyset \implies [\vec{r}] \cap \Omega \neq \emptyset$, i.e., every reaction that produces an element of $\Omega$ requires a positive concentration of an element of $\Omega$ to be applicable.
The following lemma, due to Angeli, De Leenheer, and Sontag~\cite{angeli2007petri}, shows that this is equivalent to the notion that ``the absence of $\Omega$ is forward-invariant'' under mass-action: if all species in $\Omega$ are absent, then they can never again be produced (under mass-action).\footnote{It may appear obvious that if the rates of all reactions producing a particular species are zero, the species cannot be produced.
However, this is a rather deep fact about mass-action ODEs.
Consider the CRN $2X \to 3X$. The corresponding mass-action ODE is $dx/dt = x^{2}$, and has the property that if you start with $x(0) = 0$, it cannot become positive.
However, the very similar non-mass-action ODE
$dx/dt = x^{1/2}$
has a perfectly valid solution $x(t) = t^2/4$ which starts at $0$ but becomes positive,
despite the fact that at $t=0$, $dx/dt = 0$.
The difference is that mass-action polynomial rates are locally Lipschitz and so are guaranteed to have a unique solution by the
Picard-Lindel\"of theorem.

}

\begin{lem}[\cite{angeli2007petri}, Proposition 5.5]\label{lem-mass-action-forward-invariant-siphon}
  Let $\Omega \subseteq \Lambda$ be a set of species.
  Then $\Omega$ is a siphon if and only if, for any state $\vec{c}$ such that $\Omega \cap [\vec{c}] = \emptyset$ and any state $\vec{d}$ that is mass-action reachable from $\vec{c}$, $\Omega \cap [\vec{d}] = \emptyset$.
\end{lem}

We show that the same holds true for segment-reachability.

\begin{lem}\label{lem-seg-reachable-forward-invariant-siphon}
  Let $\Omega \subseteq \Lambda$ be a set of species.
  Then $\Omega$ is a siphon if and only if, for any state $\vec{c}$ such that $\Omega \cap [\vec{c}] = \emptyset$ and any state $\vec{d}$ such that $\vec{c} \segto \vec{d}$, $\Omega \cap [\vec{d}] = \emptyset$.
\end{lem}

\begin{proof}
  Suppose $\Omega$ is a siphon, let $\vec{c}$ be a state such that $[\vec{c}] \cap \Omega = \emptyset$, and let $\vec{d}$ be such that $\vec{c} \segto \vec{d}$.
  Every straight line with end points $\vec{b}_i$ and $\vec{b}_{i+1}$ in the path from $\vec{c}$ to $\vec{d}$ is expressible as a sum of reaction vectors for reactions applicable in $\vec{b}_i$.
  Assuming inductively that $[\vec{b}_i] \cap \Omega = \emptyset$, the definition of siphon gives that $[\vec{b}_{i+1}] \cap \Omega = \emptyset$ as well.
  Therefore $\vec{d} \cap \Omega = \emptyset$.

  To show the reverse direction, suppose that $\Omega$ is not a siphon.
  Then there is a reaction $\alpha=(\vec{r},\vec{p})$ such that $[\vec{p}]$ contains an element $S \in \Omega$, but $[\vec{r}] \cap \Omega = \emptyset$.
  Then from any state $\vec{c}$ such that $[\vec{c}] = \Lambda \setminus \Omega$ (i.e., all species not in $\Omega$ are present), $\alpha$ is applicable.
  Running $\alpha$ produces $S$, hence results in a state $\vec{d}$ such that $\vec{c} \segto \vec{d}$ with $\Omega \cap [\vec{d}] \neq \emptyset$, since $S \in \Omega$.
\end{proof}

The next lemma shows that the set of species that can't ever be produced from a given state is a siphon.

\begin{lem}\label{lem:not-producible-is-siphon}
If $\vec{c}$ is any state then $\Omega = \Lambda \setminus \mathcal{P}(\vec{c})$ is a siphon.
\end{lem}

\begin{proof}
By Lemma~\ref{lem-all-species-present} there is a state $\vec{c}'$ that is segment reachable from $\vec{c}$ with all of the species in $\mathcal{P}(\vec{c})$ present. If $\Omega$ were not a siphon, there would be a reaction $\alpha$ that produced a species $S$ of $\Omega$ such that all of the reactants of $\alpha$ would be contained in $\Lambda \setminus \Omega = \mathcal{P}(\vec{c})$. This implies that $\alpha$ would be applicable at $\vec{c}'$, so $S$ would be in $\mathcal{P}(\vec{c})$, giving a contradiction.
\end{proof}

Besides siphons, another useful property of
mass-action paths is captured in Corollary~\ref{cor-all-species-present-immediately}: all species present at some point in a path are present at all times.
(Recall that in this section we consider only CRNs with mass-action trajectories that are well-defined and have finite concentrations for all times $t \ge 0$.)
This corollary follows from the following lemma, which we do not use elsewhere.

\begin{lem}[\cite{angeli2007petri}, Proposition 5.1]
Let $f$ be a real-analytic vector field defined on an open neighborhood of $\mathbb{R}_{\geq 0}^n$, and suppose $\mathbb{R}_{\geq 0}^n$ is forward-invariant for the flow of $f$. Let $J \subseteq \mathbb{R}$ be an open interval. If $\rho: J \to \mathbb{R}^n$ is a solution to the differential equation $\rho'(t) = f(\rho(t))$, then $\mathrm{sign} \rho(t)$ is constant on $J$.
\end{lem}

Taking $f$ to be the vector field obtained from the mass-action ODEs associated to a CRN $\mathcal{C}$ and letting $J = (0,\infty)$ in the above, we obtain:

\begin{cor} \label{cor-all-species-present-immediately}
Let $\rho(t)$ be a mass-action trajectory for a CRN $\mathcal{C}$ defined for all $t \geq 0$. If a species $S$ is present at $\rho(t_0)$ for some $t_0 > 0$, then $S$ is present at $\rho(t)$ for all $t > 0$.
\end{cor}

The final piece of technical machinery we need to prove Theorem~\ref{thm:mass-action-reachable} is that for any state, the set of straight-line reachable states is closed.

\begin{lemma} \label{lem-one-seg-closed}
Let $\vec{c}$ be any state in $\mathbb{R}_{\geq 0}^\Lambda$ and let $S_\vec{c}$ be the set of states that are straight-line reachable from $\vec{c}$. Then $S_\vec{c}$ is closed.
\end{lemma}

\begin{proof}
Let $R_\vec{c}$ be the set of reactions that are applicable at $\vec{c}$. Then $C = \{u \in \mathbb{R}_{\ge 0}^R | \alpha(u) = 0 \text{ for } \alpha \notin R_\vec{c}\}$ is a polyhedron, so by \cite{ziegler1995polytopes}, $\vec{c} + M C$ is also a polyhedron, and is in particular closed. $S_c$ is just $\mathbb{R}_{\ge 0}^\Lambda \cap (\vec{c} + MC)$, and is therefore also closed.
\end{proof}

Note that Lemma~\ref{lem-one-seg-closed} is false if we replace ``straight-line reachable'' with ``segment-reachable''.
For example, consider $X \to Y$ and $X + Y \to Z + Y$, where we take the initial state
$\vec{c} = \{1X, 0Y, 0Z\}$.
Note that for any $\varepsilon > 0$ we can reach the state $\vec{d}_\varepsilon = \{0 X, \varepsilon Y, (1 - \varepsilon) Z \}$.
However, the state
$\vec{d}_0 = \{ 0X, 0Y, 1 Z\}$
is not reachable from $\vec{c}$, even though $\vec{d}_0 = \lim_{\varepsilon \to 0} \vec{d}_{\varepsilon}$.

We are now ready to prove the main result of this section.

\begin{thm}  \label{thm:mass-action-reachable}
    If $\vec{d}$ is mass-action reachable from $\vec{c}$, then $\vec{c} \segto \vec{d}$.
\end{thm}

\begin{proof}
This proof is similar to the proof of Theorem~\ref{thm-reachable-segment-bound};
the main difference is that we need to define the ``reaction fluxes'' each reaction experiences on the mass-action trajectory from $\vec{c}$ to $\vec{d}$, and that we need to find an ordering on those reactions with positive flux that allows us to apply them one-by-one in order to show $\vec{c} \segto^{m+1} \vec{d}$
(although in this proof we let $m$ be the number of reactions).

\newcommand{\mathsf{PROD}}{\mathsf{PROD}}
\newcommand{\mathsf{RXN}}{\mathsf{RXN}}

First, suppose $\vec{d}$ is reached in finite time $t_f$.
The trajectory followed by mass-action kinetics to get from $\vec{c}$ to $\vec{d}$ defines a differentiable curve $\rho:[0,t_f] \to \mathbb{R}_{\geq 0}^n$.
Let $\rho' = \frac{d \rho}{dt}$ be the corresponding mass-action differential equations.
Let the reactions $R$ be $\alpha_0, \alpha_1,\ldots.$
Let $f_j:[0,t_f] \to \mathbb{R}_{\geq 0}$ be the ``instantaneous flux'' through the $j$'th reaction at time $t$.
In other words, $\rho'(t) = \sum_{j} f_j(t) \vec{v}_j$, where index $j$ ranges over all reactions, $\vec{v}_j$ represents the $j$'th reaction vector ($\vec{p}-\vec{r}$ if $\alpha_j = (\vec{r},\vec{p})$, i.e., the $j$'th column of $\vec{M}$).

By the fundamental theorem of calculus,
\begin{eqnarray*}
    \vec{d} - \vec{c}
    &=& \rho(t_f) - \rho(0)
    =
    \int_0^{t_f} \rho'(t) dt
    \\&=&
    \int_0^{t_f} \sum_j f_j(t) \vec{v}_j dt
    =
    \sum_j \vec{v}_j \int_0^{t_f} f_j(t) dt,
\end{eqnarray*}
Let $F_j = \int_0^{t_f} f_j(t) dt$ be the total flux through the $j$'th reaction.
Then $\vec{d} = \vec{c} + \sum_{j} F_j \vec{v}_j$.

Let $R_\rho = \setl{\alpha_j\in R}{F_j > 0}$ be the reactions that occurred with strictly positive flux along the curve $\rho$,
and let $\Lambda_\rho$ be the species that are present with strictly positive concentration at some point along the path $\rho$.

Consider the CRN in which we remove all of the reactions not in $R_\rho$.
We observe that the remaining reactions only have reactants and products in $\Lambda_\rho$ and so we
can think of this as a reduced CRN $(\Lambda_\rho, R_\rho)$.
This is because if $S$ is a reactant of a reaction $\alpha \in R_\rho$, then $S$ must be present with positive concentration at some time or else $\alpha$ couldn't ever fire. Furthermore, suppose for the sake of contradiction that a product $S$ of a reaction $\alpha \in R_\rho$ is zero at all times along $\rho$. Then none of the reactions using $S$ can fire, so $S$ can never be consumed---in particular $S$ can't be a reactant of $\alpha$. But then since $\alpha$ fires with positive flux, it must produce an amount of $S$, giving a contradiction.

Now we claim that every species in this reduced CRN is segment-producible from $\vec{c}$. If not, then $\Omega = \Lambda_\rho \setminus \mathcal{P}(\vec{c})$ is non-empty. Letting $S^*$ be some element of $\Omega$, we know that $S^*$ has positive concentration along $\rho$ by our construction of the reduced CRN. However, by Lemma~\ref{lem:not-producible-is-siphon}, $\Omega$ is a siphon. Since $\vec{c}$ is zero on $\Omega$ and $S^* \in \Omega$, this violates Lemma~\ref{lem-mass-action-forward-invariant-siphon}.

Since every species in our reduced CRN is segment-producible from $\vec{c}$, by Lemma~\ref{lem-all-species-present} we can construct a state $\vec{c}'$ segment-reachable from $\vec{c}$ where all of the species in the reduced CRN are present simultaneously. Since every reaction in $R_\rho$ can be fired from $\vec{c}'$, the remainder of the proof is identical to the proof of Theorem~\ref{thm-reachable-segment-bound}.
This handles the case that $\vec{d}$ is reached in finite time.

On the other hand, suppose that $\vec{d}$ is not reached from $\vec{c}$ in finite time, but instead $\vec{d} = \lim_{t \to \infty} \rho(t)$.
By Corollary~\ref{cor-all-species-present-immediately}, we know that every species in $\Lambda_\rho$ is already present in $\rho(1)$.
Let $\vec{c}' = \rho(1)$.
Because $\vec{c}'$ is mass-action reachable from $\vec{c}$ in finite time, we already know that $\vec{c} \segto \vec{c}'$. Additionally, for any $t > 1$ since $\rho(t)$ is mass-action reachable from $\vec{c}'$ in finite time, we know that $\vec{c}' \segto \rho(t)$. Since every species in $\Lambda_\rho$ is already present at $\vec{c}'$, Lemma~\ref{lem-all-producible-present} implies that $\rho(t)$ is actually straight-line reachable from $\vec{c}'$. Since $S_{\vec{c}'}$ is closed by Lemma~\ref{lem-one-seg-closed} and $\rho(t) \in S_{\vec{c}'}$ for all $1 < t < \infty$, this implies that $\vec{d} = \lim_{t \to \infty} \rho(t)$ is also in $S_{\vec{c}'}$. As a result, $\vec{c} \segto \vec{c}' \to^1 \vec{d}$, so $\vec{c} \segto \vec{d}$.
\end{proof}

Theorem~\ref{thm:mass-action-reachable} shows that our definition of reachability is at least as general as mass-action kinetics.
In the other direction, ultimately we must appeal to intuition to justify that our definition does not reach too far.
Our intuition says that the following properties are required of any reasonable notion of reachability:
(1) concentrations must be nonnegative in all reachable states,
(2) a reaction cannot execute in any state in which some reactant is 0,\footnote{In particular, we want siphons to behave reasonably in that their absence is forward-invariant; i.e., that Lemmas~\ref{lem-mass-action-forward-invariant-siphon} and~\ref{lem-seg-reachable-forward-invariant-siphon} should apply to any reasonable notion of reachability.}
(3) the relation should be reflexive, transitive, and ``respect addition'' (if $\vec{x}$ can reach to $\vec{y}$ then for all $\vec{c}$, $\vec{x}+\vec{c}$ can reach to $\vec{y}+\vec{c}$,
since the presence of additional chemicals should not \emph{prevent} reactions from being possible).
Our definition was the most general one we could conceive that satisfied these properties.

\subsection{Stable Computation}
\label{subsec-stable-crns}

In this section, we use our notion of reachability introduced above to formally define our notion of rate-independent computation.
Intuitively, devious rate laws might take the system along trajectories anywhere in the reachable space.
For the computation to be correct despite the rate laws, it must be able to reach a state with the final correct output from any reachable state.
Further, in this setting an output can reasonably be called final only if no rate law can falsify it.

First, to formally define what it means for such a CRN to compute a function, we must first single out some aspects of the CRN as semantically meaningful.
Formally, a \emph{chemical reaction computer (CRC)} is a tuple $\mathcal{C} = (\Lambda,R,\Sigma,Y)$, where $(\Lambda,R)$ is a CRN, $\Sigma \subset \Lambda$, written as $\Sigma = \{X_1,\ldots,X_k\}$,\footnote{We assume a canonical ordering of $\Sigma=\{X_1,\ldots,X_k\}$ so that a vector $\vec{x}\in\mathbb{R}_{\geq 0}^k$ (i.e., an input to $f$) can be viewed equivalently as a state $\vec{x}\in\mathbb{R}_{\geq 0}^\Sigma$ of $\mathcal{C}$ (i.e., an input to $\mathcal{C}$).
Note that we have defined valid initial states to contain only the input species $\Sigma$; other species must have initial concentration 0.
Our results would change slightly if we relaxed this assumption---see Conclusion.
}
is the \emph{set of input species}, and $Y \in \Lambda \setminus \Sigma$ is the \emph{output species}.

\begin{definition}
A state $\vec{o} \in \mathbb{R}_{\geq 0}^\Lambda$ is \emph{output stable} if, for all $\vec{o}'$ such that $\vec{o} \to \vec{o}'$, $\vec{o}(Y) = \vec{o}'(Y)$,  i.e., once $\vec{o}$ is reached, no reactions can change the concentration of the output species $Y$.
\end{definition}

\begin{definition} \label{def:direct-computation}
Let $f:\mathbb{R}_{\geq 0}^k \to \mathbb{R}_{\geq 0}$ be a function\footnote{Our results extend easily to functions $f:\mathbb{R}^k \to \mathbb{R}^l$, i.e., whose output is a vector of $l$ real numbers.
This is because such a function is equivalently $l$ separate functions $f_i:\mathbb{R}^k\to\mathbb{R}$.}
and let $\mathcal{C}$ be a CRC.
We say that $\mathcal{C}$ \emph{stably computes} $f$ if, for all $\vec{x} \in \mathbb{R}_{\geq 0}^k$, for all $\vec{c}$ such that $\vec{x} \to \vec{c}$, there exists an output stable state $\vec{o}$ such that $\vec{c} \to \vec{o}$ and $\vec{o}(Y) = f(\vec{x})$.
\end{definition}

It seems justified that a reasonably rate-independent CRC must stably compute.
This direction is sufficient for our negative results showing the limits of stable computation.
However, the other direction does not follow in general:
there are stably computing CRCs that do not actually compute the correct output under the usual rate laws like mass-action.
We consider this in the next section, and also show a class of CRCs for which stable computation does imply mass-action convergence.

\subsection{Feedforward CRNs}
\label{sec:feedforward}

In this section we define a class of CRCs (feedforward) for which stable computation implies reaching to the output stable state from any reachable state under mass-action kinetics.
For the positive results, all our constructions will be in this class.

Note that for non-feedforward CRCs it is possible that the output stable state is always reachable but the mass-action trajectory does not converge to it.
As a simple example consider the system
\begin{align*}
X + X &\to Y + Y \\
Y + X &\to X + X
\end{align*}
with $X$ as the input species and $Y$ as the output species.
From any reachable state we can reach the output stable state with all $X$ converted to $Y$.
However, the mass-action trajectory converges to a dynamic equilibrium with $k_2/(2 k_1 + k_2)$ fraction of $X$, where $k_1$, $k_2$ are rate constants of the two reactions.

In contrast to the above example, the feedforward property allows us to bridge the definition of stable computation, defined in terms of reachability, to mass-action convergence.
We say a CRN is \emph{feedforward} if the species can be ordered so that every reaction that (net) produces $S_i$ also (net) consumes some $S_{i'}$ for $i' < i$.
Formally:
\begin{definition}\label{feed-forward}
A CRN $\mathcal{C} = (\Lambda, R)$ is \emph{feedforward} if $\Lambda=\set{S_1, ..., S_n}$ and its stoichiometry matrix satisfies $\vec{M}(i,j) > 0 \implies \exists (i' < i) \vec{M}(i',j) < 0$.
\end{definition}

The following lemma says that all mass-action equilibria (i.e., no concentration is changing) of feedforward CRNs are static (i.e., no reactions are firing, as opposed to multiple reactions firing with canceling effects).

\begin{lemma}\label{lem:static-eq}
If a feedforward CRN $\mathcal{C}$ is in a mass-action equilibrium $\vec{x}$ then no reaction is applicable at $\vec{x}$.
\end{lemma}

\begin{proof}
Suppose there is at least one reaction which is applicable at $\vec{x}$. As a result, the set of all pairs $(i, j)$ where reaction $r_j$ is applicable and $\vec{M}(i, j) > 0$ is non-empty. Take a pair $(i_0, j_0)$ where $i_0$ is chosen to be as small as possible. Since $\mathcal{C}$ is feedforward and $\vec{M}(i_0, j_0) > 0$, there is some $i' < i$ such that $\vec{M}(i', j_0) < 0$. Furthermore, from our choice of $i$, we know that $\vec{M}(i', j) \le 0$ for any applicable reaction $r_j$. As a result, $\frac{dS_{i'}}{dt} < 0$, so $\vec{x}$ is not a mass-action equilibrium.
\end{proof}

\begin{lemma}  \label{lem:mass-action-convergence-stable-computation}
For any input state $\vec{x}$, for any state $\vec{z}$ reachable from $\vec{x}$, the trajectory of a feed-forward, stably computing CRC evolving via mass-action rate law and starting at $\vec{z}$ converges to the output stable state in the limit $t \to \infty$.
\end{lemma}
\begin{proof}
Our proof strategy is as follows: Using the fact that the CRN is feedforward, we will show that the total flux through all of its reactions is bounded. This implies that from any reachable state $\vec{z}$, the total distance that the system travels as it evolves through species space is finite. This property implies that the trajectory converges to a state, which has to be output-stable because the CRN is feedforward. Since mass-action reachability (even in the limit) implies segment-reachability by Theorem~\ref{thm:mass-action-reachable}, the convergence to steady-state implies convergence to the correct output.

We now show by induction that the total flux through all of the reactions is bounded. In particular, we will induct on the species and at each step of the induction show that the flux through the reactions that net consume the given species is finite.

Let $S_1, S_2, \dots$ be the feedforward ordering of the species.
As before, let $F_j = \int_0^\infty f_j(t) dt$ be the total flux through reaction $j$, and let $\vec{v}_j$ be the $j$'the reaction vector (i.e., $\vec{v}_j(i)$ is the net change of species $i$ in reaction $j$).
By the definition of feedforward, no reaction can net produce $S_1$.
Thus any reaction $j$ net consuming $S_1$ has $F_j \leq \vec{z}(S_1)/\vec{v}_j(1) < \infty$.

Now consider any species $S_i$ for $i>1$.
We make the induction assumption that for every $S_{i'}$ such that $i' < i$, every reaction $j'$ net consuming $S_{i'}$ has $F_{j'} < \infty$.
We want to show that every reaction $j$ net consuming $S_i$ has $F_j < \infty$ as well.
All reactions net producing $S_i$ net consume some $S_{i'}$ earlier in the ordering, so their total flux is bounded. Let $K < \infty$ be the total amount of $S_i$ produced.
Then we have $F_j \leq (\vec{z}(S_i) + K)/\vec{v}_j(i) < \infty$.

If we let $\gamma(t)$ be the path that the system takes through species-space, then we see that
\begin{align*}
\int_0^\infty |\gamma'(t)| dt &= \int_0^\infty \left|\sum_{j} f_j(t)\vec{v}_j\right| dt \\
&\le \int_0^\infty \sum_{j} f_j(t)|\vec{v}_j| dt \\
&= \sum_{j}|\vec{v}_j| \int_0^\infty  f_j(t) dt  = \sum_{j}|\vec{v}_j| F_j\\
&< \infty.
\end{align*}
In other words, $\gamma$ has finite length.

To see that this implies that $\gamma$ must converge, suppose that there is some $\epsilon > 0$ such that for all $M \in \mathbb{R}_{\ge 0}$, there exists some $t > s > M$ such that $d(\gamma(t), \gamma(s)) \ge \epsilon$. Then take $M_1 = 0$, and label the points we get by this assumption $t_1, s_1$. Then for any $n > 1$, take $M_n = t_{n-1}$ and label the next pair of points $t_n, s_n$. Then
\begin{align*}
\int_0^\infty |\gamma'(t)| dt &\ge \sum_{i = 1}^\infty \int_{s_i}^{t_i}|\gamma'(t)| dt \\
&\ge \sum_{i = 1}^\infty d(\gamma(t_i), \gamma(s_i)) \\
&\ge \sum_{i = 1}^\infty \epsilon = \infty,
\end{align*}
which gives a contradiction.
So for all $\epsilon > 0$, there is some $M \in \mathbb{R}_{\ge 0}$ such that for all $t, s > M$, we know $d(\gamma(t), \gamma(s)) < \epsilon$. As a result, if $\vec{x}_k = \gamma(k)$, then $\set{\vec{x}_k}_{k = 1}^\infty$ is a Cauchy sequence in $\mathbb{R}^n$, so it must converge to some point $\vec{x}_0$. Moreover, we know that $\gamma(t) \to \vec{x}_0$ as $t \to \infty$, since for any $\epsilon > 0$ there is some $N$ such that for all $n > N$, we know $d(\vec{x}_n, \vec{x}_0) < \epsilon/2$ and there is some $M$ such that for all $t, s > M$ we know $d(\gamma(t), \gamma(s)) < \epsilon/2$. In particular, taking $m$ to be an integer larger than $N$ and $M$ we see that
\[d(\gamma(t), \vec{x}_0) \le d(\gamma(t), \vec{x}_m) + d(\vec{x}_m, \vec{x}_0) < \epsilon.\]

We now establish that $\vec{x}_0$ is an equilibrium point.
Since $\gamma$ has finite length, we know that $|\gamma'(t)| \to 0$ as $t \to \infty$. Since the mass-action differential equations are polynomials
and thus continuously change with concentrations, this implies that $\vec{x}_0$ is an equilibrium point.

Since the CRN is feed-forward,
by Lemma~\ref{lem:static-eq},
$\vec{x}_0$ must actually be a static equilibrium point, so it is output stable. Since $\vec{x}_0$ is reachable from $\vec{z}$ via mass-action, by Theorem~\ref{thm:mass-action-reachable} it is segment-reachable, and because the CRC stably computes the desired function, $\vec{x}_0$ must have the correct amount of the output species present.
\end{proof}

\subsection{Dual-rail Representations}
\label{subsec:dual-rail-defn}
In general, the output species of an upstream CRC may be used as the inputs to a downstream CRC if the upstream CRC only produces but never consumes the output species.
We say that such a CRC computes its output \emph{monotonically}.
This is impossible for general stable CRCs.
For example, any CRC computing the function $f(x_1,x_2) = x_1 - x_2$ must necessarily be able to consume its output species in order to account for some amount of species $X_2$ that has not yet reacted.
(The class of functions that can be computed without consuming the output species has been studied; see Section~\ref{sec:prev}.)
Therefore, some of our CRCs represent their output $Y$ in a ``dual-rail'' fashion as the difference of two species $Y^+$ and $Y^-$, both of which are only produced but never consumed by the CRC.
Since these outputs are given as input to a downstream subroutine CRC, the downstream CRC must also be designed to accept inputs in this same dual-rail representation.
Furthermore, representing values in this way allows us to take negative inputs and produce negative outputs, using only nonnegative concentrations, representing for example a negative output by a higher concentration of $Y^-$ than $Y^+$.

Formally, let $f:\mathbb{R}^k \to \mathbb{R}$ be a function.
A function $\hat{f}:\mathbb{R}^{2k} \to \mathbb{R}^2$ is a \emph{dual-rail representation} of $f$ if, for all $\vec{x}^+,\vec{x}^- \in \mathbb{R}^k$, if $(y^+,y^-) = \hat{f}(\vec{x}^+,\vec{x}^-)$, then $f(\vec{x}^+ - \vec{x}^-) = y^+ - y^-$.
In other words, $\hat{f}$ represents $f$ as the difference of its two outputs $y^+$ and $y^-$, and it works for any input pair $(\vec{x}^+,\vec{x}^-)$ whose difference is the input value to $f$.
We can define a CRC to stably compute such a function in the same manner as in Section~\ref{subsec-negative-computable-implies-piecewise-linear}, but having input species $X_1^+,X_1^-,X_2^+,X_2^-,\ldots,X_k^+,X_k^-,\ldots,$ and two output species $Y^+$ and $Y^-$.
We further require that the output species are only produced and never consumed (the output is computed monotonically).

\begin{definition}
We say that a CRC \emph{stably dual-computes} $f:\mathbb{R}^k \to \mathbb{R}$ if it stably computes a dual-rail representation $\hat{f}:\mathbb{R}^k \times \mathbb{R}^k \to \mathbb{R} \times \mathbb{R}$ of $f$.
\end{definition}

Note that if a CRC outputs $Y^+$ and $Y^-$ according to the dual-rail convention, and the output value is never negative, then it can be trivially modified to produce its output according to the direct computation convention (Def.~\ref{def:direct-computation}) by adding the reaction $Y^+ + Y^- \to \emptyset.$
Note that a single function has an infinite number of dual-rail representations.
We require only that a CRC exists to compute one of them to say that the function is stably dual-computable by a CRC.

\subsubsection{Linearity restricted to inputs draining a siphon}

This section aims towards proving that the function computed by $\mathcal{C}$, when restricted to inputs that can drain a particular output staple siphon, is linear.
Since there are a finite number of siphons,
this will establish the ``piecewise linear'' portion of the ``piecewise rational linear and continuous'' claims in  Theorems~\ref{thm-computable-iff-piecewise-linear} and~\ref{thm-nonnegative-computable-iff-piecewise-linear}.

Recall that $V$, defined in Definition~\ref{def:prepaths},
is the space of all prepaths
(i.e., the vector space in which paths live),
and $\Gamma$, defined in Definition~\ref{def:paths}, is the space of all paths.
We now define a map $\vec{o}$ which intuitively sends a path to the final state that it reaches.

\begin{lem}
The map $\vec{o}: V \to \mathbb{R}^\Lambda$ sending
\[\gamma \mapsto \lim_{n \to \infty} \vec{x}_n(\gamma)\]
is linear.
\end{lem}

\begin{proof}
To see that the limit converges, simply note that $\vec{x}_{n+1}(\gamma) - \vec{x}_n(\gamma) = M\vec{u}_n(\gamma)$ is zero for large enough $n$ (depending on $\gamma$), since by definition $\vec{u}_n(\gamma) = 0$ for large enough $n$.
To check that $\vec{o}$ is a linear function, note that for any $\gamma_0, \gamma_1 \in V$ and $\lambda \in \mathbb{R}$ we have
\begin{align*}
    \vec{o}(\gamma_0 + \lambda \gamma_1) &= \lim_{n \to \infty} \vec{x}_n( \gamma_0 + \lambda \gamma_1) \\
    &= \lim_{n \to \infty} \vec{x}_n(\gamma_0) + \lambda\vec{x}_n(\gamma_1) \\
    &= \lim_{n \to \infty} \vec{x}_n(\gamma_0) + \lambda\lim_{n \to \infty}\vec{x}_n(\gamma_1) \\
    &= \vec{o}(\gamma_0) + \lambda \vec{o}(\gamma_1). \qedhere
\end{align*}
\end{proof}

\begin{defn}
Let $\Omega$ be an output-stable siphon. Define $\Gamma(\Omega)$ to consist of $\gamma \in \Gamma$ such that $\vec{o}(\gamma)\upharpoonright \Omega = \vec{0}$.
\end{defn}

These are the paths that terminate at a state where a given output stable siphon is drained.

\begin{lem}
$\Gamma(\Omega)$ is convex for each output-stable siphon $\Omega$.
\end{lem}

\begin{proof}
Suppose that $\gamma_0$ and $\gamma_1$ are in $\Gamma(\Omega)$ and let $\gamma_\lambda = (1-\lambda)\gamma_0 + \lambda \gamma_1$. By Lemma~\ref{lem:Pathspace-convex} we know that $\gamma_\lambda$ is in $\Gamma$. Moreover
\[\vec{o}(\gamma_\lambda) = (1 - \lambda)\vec{o}(\gamma_0) + \lambda \vec{o}(\gamma_1).\]
Since $\Omega$ is drained at both $\vec{o}(\gamma_0)$ and $\vec{o}(\gamma_1)$, we conclude that it must also be drained at $\vec{o}(\gamma_\lambda)$, so $\gamma_\lambda \in \Gamma(\Omega)$.
\end{proof}

\begin{defn}
Let
\[\Sigma(\Omega) = \{ \left. \vec{x} \in \mathbb{R}_{\geq 0}^\Lambda \ \right|\ [\vec{x}] \subseteq \Sigma,\ (\exists \vec{o})\ \vec{x} \segto \vec{o}, \text{ and } \vec{o} \upharpoonright \Omega = \vec{0} \}\]
denote those input states from which the siphon $\Omega$ is drainable.
\end{defn}

\begin{lem}\label{lem-siphon-implies-linear-nondual}
  Let $f:\mathbb{R}_{\geq 0}^k \to \mathbb{R}_{\geq 0}$ be stably computed by a CRC $\mathcal{C}=(\Lambda,R,\Sigma,Y)$.
  Let $\Omega$ be an output stable siphon.
  Then $f$ restricted $\Sigma(\Omega)$ is a linear function.
\end{lem}

\begin{proof}
First project $\Gamma(\Omega)$ to $\mathbb{R}_{\geq 0}^\Lambda \times \mathbb{R}_{\geq 0}^\Lambda$ by the map $\gamma \mapsto (\vec{x}_0(\gamma), \vec{o}(\gamma))$. Let $G \subseteq \mathbb{R}^{k+1}$ be the further projection to the $(k+1)$-dimensional subspace corresponding only to the inputs and output. $G$ is the graph of the function $y = f(\vec{x})$ restricted to inputs $\vec{x} \in \Sigma(\Omega)$. Since $G$ is the image of a convex set under a linear transformation, it is also convex. We claim that $G$ must be a subset of a $k$-dimensional hyperplane.

For the sake of contradiction, suppose not. Then there are $k+1$ non-coplanar points in $G$. Since $G$ is convex, it contains the entire $(k+1)$-dimensional convex hull $H$ of these points. Since $H$ is a $(k+1)$-dimensional convex polytope, it contains two different values of $y$ corresponding to the same value of $\vec{x}$, contradicting the fact that only a single $y$ value exists in all output-stable states reachable from $\vec{x}$. This establishes the claim that $G$ must be a subset of a $k$-dimensional hyperplane.

Since the graph of $f$ is a subset of a $k$-dimensional hyperplane, it is a affine function. Since there are no reactions of the form $\emptyset \to \ldots$, $Y$ cannot be produced from the initial state $\vec{x}=\vec{0}$ (nor can any other species), so $f(\vec{0})=0$. Therefore this hyperplane passes through the origin, so it defines a linear function.
\end{proof}

In Lemma~\ref{lem-siphon-implies-linear-nondual}, the reason that we restrict attention to a single output siphon $\Omega$ is as follows. If different output siphons are drained, then different linear functions may be computed by the CRC. For example, $X_1+X_2\to Y$ computes $f(x_1,x_2) = x_1$ if siphon $\{X_2\}$ is drained and $f(x_1,x_2) = x_2$ if siphon $\{X_1\}$ is drained.

\subsubsection{Positive-Continuity}

Ideally, in order to prove that the function stably computed by a CRC is positive-continuous,
we would like to prove the following:
for any output stable siphon $\Omega$, the set $\Sigma(\Omega)$ of input states that can drain $\Omega$ is closed relative to the positive orthant.
If that were true, then we could use a fundamental topological result that if a function is piecewise continuous with finitely many pieces
(e.g., piecewise linear functions),
and if the domain defining each piece is closed
(with agreement between pieces on intersecting domains),
then the whole function is continuous.
However, the above statement is not true in general.
Consider the following counterexample:
\begin{align*}
    X_1 &\to C
    \\
    X_1 + X_2 + C &\to C + Y
\end{align*}
If initially $\vec{x}(X_1) > \vec{x}(X_2)$, then the output stable siphon $\{X_2\}$ is drainable, by producing $(\vec{x}(X_1) - \vec{x}(X_2)) / 2$ of $C$ via the first reaction (leaving an excess of $X_1$ over $X_2$ still),
then running the second reaction until $X_2$ is gone to produce $Y$.
Because $X_2$ can only be consumed if $C$ is produced,
which requires consuming a positive amount of $X_1$,
the set of inputs from which $\{X_2\}$ can be drained is the non-closed set $\{ \vec{x} \mid \vec{x}(X_1) > \vec{x}(X_2)\}$.
Note that the above CRC does not stably compute anything because,
starting from a state with $\vec{x}(X_1) > \vec{x}(X_2)$,
the first reaction could run until $X_2$ exceeds $X_1$ before starting the second reaction.
It is still unclear whether such counterexamples exist for CRCs stably computing some function that is not identically $0$.

Instead of relying on $\Sigma(\Omega)$ being closed, we must make a more careful argument.
In lieu of working directly with the sets $\Sigma(\Omega)$ we consider ``shifted'' sets $\Tilde{\Sigma}_{(\vec{y} \segto \vec{z})}(\Omega)$ (see Definition~\ref{defn:shifted_set} below). Each $\Tilde{\Sigma}_{(\vec{y} \segto \vec{z})}(\Omega)$ is (possibly strictly) contained in the original $\Sigma(\Omega)$, but they still cover the set of inputs. Crucially, we are able to show that the shifted sets $\Tilde{\Sigma}_{(\vec{y} \segto \vec{z})}(\Omega)$ are closed, allowing us to apply the argument at the start of this section to prove that every function stably computed by a CRC is positive-continuous.

\begin{defn}
Let
\[X(\Omega) = \{ \left. \vec{x} \in \mathbb{R}_{\geq 0}^\Lambda\ \right|\ (\exists \vec{o})\ \vec{x} \to^1 \vec{o} \text{ and } \vec{o} \upharpoonright \Omega = \vec{0} \}\]
denote those states from which siphon $\Omega$ is drainable via a single straight line segment.
\end{defn}

\begin{lem}\label{lem-siphon-inputs-closed}
  Let $\Omega$ be a siphon.
  Let $\vec{a}_1,\vec{a}_2,\ldots \in X(\Omega)$ be a convergent sequence of states, where $\vec{a}=\lim_{i\to\infty} \vec{a}_i$.
  Suppose $[\vec{a}] = \Lambda$.
  Then $\vec{a} \in X(\Omega).$
\end{lem}

\begin{proof}

Consider the set $P$ of $\gamma = (\vec{x}_0, \vec{u}) \in \mathbb{R}^\Lambda_{\ge 0} \times \mathbb{R}^R_{\ge 0}$ such that $\vec{o}(\gamma) \in \mathbb{R}^\Lambda_{\ge 0}$ and $\vec{o}(\gamma) \upharpoonright \Omega = \vec{0}$.
Note that reactions occuring with positive flux in $\vec{u}$ might not be applicable at $\vec{x}_0$.
$P$ is cut out by a system of non-strict linear inequalities (in other words, it is a polyhedron). By \cite{ziegler1995polytopes}, $\vec{x}_0(P)$ is also a polyhedron, and is in particular closed.

Note that $X(\Omega) \subseteq \vec{x}_0(P)$ and $\vec{x}_0(P) \cap \mathbb{R}_{> 0}^\Lambda = X(\Omega) \cap \mathbb{R}_{> 0}^\Lambda$. The first relation follows since if $\vec{x} \in X(\Omega)$, then the straight-line path draining $\Omega$ produces a $\gamma \in P$ such that $\vec{x}_0(\gamma) = \vec{x}$. The second relation holds since if every species is present in $\vec{x}_0$ then every reaction is applicable at $\vec{x}_0$, so any of the points $\gamma \in P$ that project to $\vec{x}_0$ are valid paths that drain $\Omega$.

Since $\vec{a} = \lim_{i\to\infty} \vec{a}_i$, we have that for all but finitely many $i$, $\vec{a}_i \in X(\Omega) \cap \mathbb{R}_{> 0}^\Lambda$. As a result, these $\vec{a}_i$ are in $\vec{x}_0(P)$, so $\vec{a}$ in in $\vec{x}_0(P)$, too, since the set is closed.
Since $\vec{a} \in \vec{x}_0(P) \cap \mathbb{R}_{>0}^\Lambda$, we conclude that $\vec{a} \in X(\Omega).$
\end{proof}

\begin{defn}
A pair $(\vec{y} \segto \vec{z}) \in \mathbb{R}_{\geq 0}^\Lambda \times \mathbb{R}_{\geq 0}^\Lambda$ of states is a \emph{good pair} if $[\vec{y}] = \Sigma$, $[\vec{z}] = \Lambda$, and $\vec{y} \segto \vec{z}$.
\end{defn}

\begin{defn}\label{defn:shifted_set}
If $(\vec{y} \segto \vec{z})$ is a good pair and $\Omega$ is an output-stable siphon, define
\begin{align*}
\Tilde{\Sigma}_{(\vec{y} \segto \vec{z})}(\Omega) = \{\vec{x} \in \mathbb{R}_{\geq 0}^\Lambda \ |\ [\vec{x}] = \Sigma \text{ and } \forall \lambda > 0 \text{ such that } \lambda\vec{y} < \vec{x}, \\
\text{it is the case that }\vec{x} - \lambda\vec{y} + \lambda\vec{z} \in X(\Omega)\}
\end{align*}
to be the set of states that can drain $\Omega$ after being shifted by $(\vec{y} \segto \vec{z})$.
\end{defn}

\begin{lem}\label{lem-shifted-sets-cover}
For any fixed good pair $(\vec{y}, \vec{z})$, as $\Omega$ varies among all of the output-stable siphons, the sets $\Tilde{\Sigma}_{(\vec{y}, \vec{z})}(\Omega)$ cover $\mathbb{R}_{>0}^\Sigma$.
\end{lem}

\begin{proof}
Let $\vec{x}$ be an input state such that $[\vec{x}] = \Sigma$. Define
\[\lambda_0 = \min_{S \in \Sigma}\left\{\frac{\vec{z}(S)}{\vec{x}(S)}\right\}\]
so that $\lambda\vec{y} < \vec{x}$ if and only if $\lambda < \lambda_0$. We know that $(\vec{x} - \lambda_0 \vec{y}) \segto (\vec{x} - \lambda_0 \vec{y})$ by the constant path and $\lambda_0\vec{y} \segto \lambda_0 \vec{z}$ because $(\vec{y}, \vec{z})$ is a good pair. As a result,
\[\vec{x} = (\vec{x} - \lambda_0 \vec{y}) + \lambda_0 \vec{y} \segto (\vec{x} - \lambda_0 \vec{y}) + \lambda_0 \vec{z} \]
so since $\mathcal{C}$ is a CRC there must be some output-stable siphon $\Omega$ and some state $\vec{o}$ such that $\vec{x} - \lambda_0 \vec{y} + \lambda_0 \vec{z} \segto \vec{o}$ and $\Omega$ is drained at $\vec{o}$.

For any $\lambda > 0$ such that $\lambda\vec{y} < \vec{x}$, we know that $\lambda < \lambda_0$, so
\begin{align*}
&\vec{x} - \lambda\vec{y} + \lambda\vec{z} = (\vec{x} - \lambda_0\vec{y} + \lambda\vec{z}) + (\lambda_0 - \lambda)\vec{y} \\
\segto &(\vec{x} - \lambda_0\vec{y} + \lambda\vec{z}) + (\lambda_0 - \lambda)\vec{z} = \vec{x} - \lambda_0 \vec{y} + \lambda_0 \vec{z}
\end{align*}
Since $\vec{x} - \lambda_0 \vec{y} + \lambda_0 \vec{z} \segto \vec{o}$ we see that $\vec{x} - \lambda \vec{y} + \lambda \vec{z} \segto \vec{o}$, and since $[\vec{z}] = \Lambda$, by Lemma~\ref{lem-all-producible-present} we conclude that $\vec{x} - \lambda\vec{y} + \lambda\vec{z} \to^1 \vec{o}$. Since this is true for any $\lambda > 0$ such that $\lambda\vec{y} < \vec{x}$, we conclude that $\vec{x} \in \Tilde{\Sigma}_{(\vec{y}, \vec{z})}(\Omega)$. This shows that every $\vec{x}$ with $[\vec{x}] = \Sigma$ is in $\Tilde{\Sigma}_{(\vec{y}, \vec{z})}(\Omega)$ for some $\Omega$, as desired.
\end{proof}

The following lemma is almost immediate from the definition. The only possible concern one might have is that an input state $\vec{x}$ is contained in $\Tilde{\Sigma}_{(\vec{y} \segto \vec{z})}(\Omega)$ ``vacuously"--in other words, that there simply does not exist a $\lambda > 0$ such that $\lambda\vec{y} < \vec{x}$.

\begin{lem}\label{lem-shifted-in-unshifted}
For any good pair $(\vec{y}, \vec{z})$ and any output-stable siphon $\Omega$, $\Tilde{\Sigma}_{(\vec{y}, \vec{z})}(\Omega) \subseteq \Sigma(\Omega)$.
\end{lem}

\begin{proof}
Let $\vec{x}$ be in $\Tilde{\Sigma}_{(\vec{y}, \vec{z})}$. By definition, $[\vec{x}] = \Sigma$, so let $\lambda_0$ be as in the proof of Lemma~\ref{lem-shifted-sets-cover}. Then $\vec{x} \segto \vec{x} - (\lambda_0/2) \vec{y} + (\lambda_0/2) \vec{z} \to^1 \vec{o}$, where $\Omega$ is drained at $\vec{o}$. We conclude that $\vec{x} \segto \vec{o}$, so $\vec{x} \in \Sigma(\Omega)$.
\end{proof}

\begin{lem}\label{lem-shifted-closed}
For any good pair $(\vec{y}, \vec{z})$ and any output-stable siphon $\Omega$, $\Tilde{\Sigma}_{(\vec{y}, \vec{z})}(\Omega)$ is closed relative to $\mathbb{R}_{>0}^\Sigma$.
\end{lem}

\begin{proof}
Let $\vec{x}$ be a state such that $[\vec{x}] = \Sigma$ and let $\{\vec{x}_i\}$ be a sequence such that $\vec{x} = \lim_{i \to \infty} \vec{x}_i$ and $\vec{x}_i \in \Tilde{\Sigma}_{(\vec{y}, \vec{z})}(\Omega)$. For any $\lambda > 0$ such that $\lambda\vec{y} < \vec{x}$, by throwing out finitely many terms in the sequence $\{\vec{x}_i\}$, we can guarantee that $\lambda \vec{y} < \vec{x}_i$ for all $i$, too. Since $\vec{x}_i \in \Tilde{\Sigma}_{(\vec{y}, \vec{z})}(\Omega)$, we know that $\vec{x}_i - \lambda \vec{y} + \lambda\vec{z} \in X(\Omega)$ for all $i$. Since $X(\Omega)$ is closed, we see that
\[\vec{x} -\lambda \vec{y} + \lambda\vec{z} = \left(\lim_{i \to \infty} \vec{x}_i\right) -\lambda \vec{y} + \lambda\vec{z} = \lim_{i \to \infty} (\vec{x}_i -\lambda \vec{y} + \lambda\vec{z})\]
is also in $X(\Omega)$. Since this is true for every $\lambda$ such that $\lambda\vec{y} < \vec{x}$, we conclude that $\vec{x} \in \Tilde{\Sigma}_{\vec{y}, \vec{z}}(\Omega)$. Since this is true for any $\vec{x}$ in $\mathbb{R}_{>0}^\Sigma$, we conclude that $\Tilde{\Sigma}_{\vec{y}, \vec{z}}(\Omega)$ is closed relative to $\mathbb{R}_{>0}^\Sigma$.
\end{proof}

Note that the hypothesis $[\vec{a}]=\Lambda$ is necessary.
Otherwise, consider the reactions $A\to C$, $A+B\to\emptyset$, and $F+C\to C$, with $\vec{a}_i(C)=0$, $\vec{a}_i(F)=1$, $\vec{a}_i(B)=1$, and $\vec{a}_i(A)$ approaching 1 from above as $i \to \infty$ (whence $C \not \in [\vec{a}]$).
Then the siphon $\Omega=\{A,B,F\}$ is drainable from each $\vec{a}_i$ by running $A \to C$ until $A$ and $B$ have the same concentration, then running the other two reactions to completion.
However, $\vec{a}(A)=\vec{a}(B)$, so running any amount of reaction $A \to C$ prevents reaction $A+B\to\emptyset$ from draining $B$.
Therefore $\vec{a} \not\in X(\Omega)$ but $\vec{a}_i \in X(\Omega)$ for all $i$.

We now use the above technical machinery to prove the following result, which is \emph{almost} the full negative result for direct computation, but leaves out the constraint that $f$ is \emph{rational} linear.
Rationality is shown in Subsection~\ref{subsec:rationality} below.
Recall the definition of \emph{positive-continuous} functions in Section~\ref{sec:results-statement}.

\begin{lem}\label{lem-nonnegative-computable-implies-positive-continuous}
  Let $f:\mathbb{R}_{\geq 0}^k \to \mathbb{R}_{\geq 0}$ be stably computed by a CRC.
  Then $f$ is positive-continuous and piecewise linear.
\end{lem}

\begin{proof}
Let $U \subseteq \{1,\ldots,k\}$, let $\vec{x} \in D_U$, and let $\vec{x}_1$, $\vec{x}_2$, $\ldots \in D_U$ be an infinite sequence of points such that $\lim_{i\to\infty} \vec{x}_i = \vec{x}$. It suffices to show that $\lim_{i\to\infty} f(\vec{x}_i) = f(\vec{x})$ --- i.e.~that $f$ is continuous on $D_U$. We take $\vec{x}_i$ and $\vec{x}$ equivalently to be the initial state of the CRC giving the concentrations of species in $\Sigma=\{X_1,\ldots,X_k\}$.

In analyzing the behavior of the CRC on states in $D_U$, it will help us to consider the functionally equivalent CRC in which we remove species that are not producible from states in $D_U$. For the purposes of this proof we consider this reduced CRC, and let $\Lambda$ be the corresponding reduced set of species.

Let $(\vec{y}, \vec{z})$ be some good pair. Then as $\Omega$ varies among the output-stable siphons, $\Tilde{\Sigma}_{(\vec{y}, \vec{z})}(\Omega)$ gives a finite collection of closed sets covering $\mathbb{R}_{>0}^\Sigma$ by Lemmas~\ref{lem-shifted-sets-cover} and~\ref{lem-shifted-closed}. Since $\Tilde{\Sigma}_{(\vec{y}, \vec{z})}(\Omega) \subseteq \Sigma(\Omega)$ by Lemma~\ref{lem-shifted-in-unshifted} and since $f$ is linear (and therefore continuous) on $\Sigma(\Omega)$ by Lemma~\ref{lem-siphon-implies-linear-nondual}, we see that $f$ is continuous on each of the closed sets in this covering. By \cite{munkres2000topology}, if a topological space is a union of finitely many closed sets and $f_i$ are continous function on each closed set that agree on overlaps, then they combine to give a continous function. From this result, we conclude that $f$ is continuous on $D_U$, as desired.
\end{proof}

\subsubsection{Rationality}
\label{subsec:rationality}

Recall Definition~\ref{def:rational-linear} defining rational linear functions and
Definition~\ref{def:piecewise-rational-linear} defining piecewise rational linear functions.

The main ideas of this section are as follows: to show that a function is piecewise rational linear, we need to show that it is rational linear on some finite set of domains that cover the input space.

A linear function $f: \mathbb{R}^n \to \mathbb{R}$ which sends $\mathbb{Q}^n$ to $\mathbb{Q}$ is necessarily rational linear.
Since a linear function on $\mathbb{R}^n$ is completely determined by its behavior on any open ball, we can check this condition ``locally" on any domain that contains an open ball.
(Since $f$ is continuous and all of the points of domains that don't contain an open ball are limit points of the other domains,
we can ignore domains that don't contain open balls.)
The fact that the function sends $\mathbb{Q}^n$ to $\mathbb{Q}$ on such a domain is ultimately a consequence of the fact that the stoichiometry matrix of a CRN has only integer coefficients, so it preserves rationality.

Recall that $V$, defined in Definition~\ref{def:prepaths}, is the space of all prepaths, and $\Gamma$, defined in Definition~\ref{def:paths}, is the space of all paths.

\begin{defn}
A path $\gamma \in \Gamma$ is a \emph{rational path} if it has rational initial concentrations and all of its segments have rational fluxes. In other words, $\vec{x}_0(\gamma) \in \mathbb{Q}^\Lambda$ and $\vec{u}_i(\gamma) \in \mathbb{Q}^R$ for all $i$.
\end{defn}

Note that since the stoichiometry matrix is an integer-valued matrix, it is automatically the case that $\vec{o}(\gamma)$ and every $\vec{x}_i(\gamma)$ is in $\mathbb{Q}^\Lambda$ for any rational path $\gamma$.

\begin{defn}
We say that two prepaths $\gamma, \gamma' \in V$ \emph{have the same sign} if for all species $S$, reactions $\alpha$, and $i \in \mathbb{N}$, it is the case that $\sgn \vec{x}_i(\gamma)_S = \sgn \vec{x}_i(\gamma')_S$ and $\sgn \vec{u}_i(\gamma)_\alpha = \sgn \vec{u}_i(\gamma')_\alpha$.
\end{defn}

\begin{lem}\label{lem-rational-path}
Let $\gamma \in \Gamma$ be a piecewise linear path. Then for any $\varepsilon > 0$, there is a rational path $\gamma' \in \Gamma$ such that $\gamma'$ has the same sign as $\gamma$ and $||\gamma' - \gamma|| < \varepsilon$. If $\gamma$ already has rational initial concentrations, then $\gamma'$ can be chosen with the same initial concentrations.
\end{lem}

\begin{proof}
First, let $N$ be the largest natural number such that $\vec{u}_N(\gamma) \neq 0$. For any reaction $\alpha \in R$ and any $n \in \mathbb{N}_{>0}$ such that $\vec{u}_n(\gamma)_\alpha = 0$, set $\vec{u}_n(\gamma)_\alpha = 0$. Now for each species $S \in \Lambda$ such that $\vec{x}_k(\gamma)_S = 0$ and $k \le N$, consider the following linear equation:
\[\vec{x}_0(\gamma')_S + \sum_{\substack{1 \le n \le k \\ \alpha \in R \\ \vec{u}_n(\gamma)_\alpha \neq 0}} M_{S\alpha} \vec{u}_n(\gamma')_\alpha = 0.\]
Aggregating these equations for all $0 \le k \le N$ and all $S \in \Lambda$ such that $\vec{x}_k(\gamma)_S = 0$ gives a system of equations, linear in $\vec{x}_0(\gamma')_S$ and $\vec{u}_n(\gamma')_\alpha$, with rational coefficients. This equation has a real-valued solution, namely $\vec{x}_0(\gamma') = \vec{x}_0(\gamma)$ and $\vec{u}_n(\gamma') = \vec{u}(\gamma)$, so by Lemma~\ref{lem-rational-sols}, it must have a solution with rational coefficients that is $\delta$-close for any $\delta > 0$. By taking $\delta$ small enough, we can of course make $\delta < \varepsilon$, but we can also guarantee that $\vec{x}_0(\gamma')_S$ is positive whenever $\vec{x}_0(\gamma)_S$ is positive and similarly for $\vec{u}_n(\gamma')_\alpha$. We have therefore specified a $\gamma' \in V$ with the same sign as $\gamma$. Since $\gamma'$ has the same sign as $\gamma$, and since $\gamma$ is a valid path, we conclude that $\gamma'$ is also a valid path, so $\gamma' \in \Gamma$.

If $\vec{x}_0(\gamma)$ is already in $\mathbb{Q}^\Lambda$, then the same argument applies, with the modification that you fix $\vec{x}_0(\gamma') = \vec{x}_0(\gamma)$, and instead solve the inhomogeneous system of equations
\[\sum_{\substack{1 \le n \le k \\ \alpha \in R \\ \vec{u}_n(\gamma)_\alpha \neq 0}} M_{S\alpha} \vec{u}_n(\gamma')_\alpha = -\vec{x}_0(\gamma)_S\]
when $\vec{x}_k(\gamma)_S = 0$.
\end{proof}

\begin{lem}\label{lem:open-ball-implies-rational}
Let $\Omega$ be an output stable siphon. If $\Sigma(\Omega)$ contains an open ball, then $f$ is rational linear when restricted to inputs in $\Sigma(\Omega)$.
\end{lem}

\begin{proof}
Let $B$ be the open ball contained in $\Sigma(\Omega)$ and let $\vec{x}$ be in $\mathbb{Q}^\Lambda \cap B$. We know that there is a piecewise linear path $\gamma$ starting at $\vec{x}$ such that $f(\vec{x}) = \vec{o}(\gamma)_Y$. By Lemma~\ref{lem-rational-path}, there is a rational path $\gamma'$ with the same sign as $\gamma$ such that $\vec{x}_0(\gamma') = \vec{x}_0(\gamma) = \vec{x}$. Because $\vec{o}(\gamma)$ is an output-stable state, some siphon $\Omega$ is drained at $\vec{o}(\gamma)$. Since $\gamma'$ has the same sign as $\gamma$, we know that $\Omega$ is also drained at $\vec{o}(\gamma')$, so $\vec{o}(\gamma')$ is also output stable. We must then have that $f(\vec{x}) = \vec{o}(\gamma')_Y$, but by the construction of $\gamma'$ we know that $\vec{o}(\gamma')_Y \in \mathbb{Q}$. Since $B \subseteq \Sigma(\Omega)$, we know that $f|_B$ is linear by Lemma~\ref{lem-siphon-implies-linear-nondual}. Since $B$ is an open ball we know that $\mathbb{Q}^\Lambda \cap B$ contains a basis for $\mathbb{Q}^\Lambda$, so $f|_B$ is a linear function that maps $\mathbb{Q}^\Lambda$ to $\mathbb{Q}$. Since every linear function $\mathbb{R}^\Lambda \to \mathbb{R}$ that sends $\mathbb{Q}^\Lambda$ to $\mathbb{Q}$ is rational linear, we are done.
\end{proof}

Recall that a \emph{closed domain} is the closure of an open set.

\begin{lem}
\label{lem:replace-domains-of-defn-with-closed-domains}
Let $f: X \to Y$ be a continuous function defined piecewise on closed sets, so $X$ is covered by finitely many closed sets $D_1 \ldots D_k$ and there are continuous functions $g_i: X\to Y$ such that $f|_{D_i} = g_i|_{D_i}$. Then there are (possibly empty) closed domains $E_1 \ldots E_k$ that cover $X$ such that $f|_{E_i} = g_i|_{E_i}$.
\end{lem}

\begin{proof}
We show how to convert each $D_i$ that is not a closed domain to a corresponding $E_i$ that is.
Let $D_i$ be some set that isn't a closed domain. Let
\[D_+ = \bigcup_{j\neq i} D_j.\]
Note that $D_1, \ldots D_{i - 1}, X \setminus D_+, D_{i + 1}, \ldots D_k$ cover $X$.
Let $E_i$ be the closure of $X \setminus D_+$.
Clearly $E_i$ is a closed domain. Since our original sets $D_1 \ldots D_k$ cover $X$ we know that $X \setminus D_+ \subseteq D_i$, and since $D_i$ is closed this implies that $E_i \subseteq D_i$. Because of this we also have that $f|_{E_i} = g_i|_{E_i}$. Finally, because $X \setminus D_+ \subseteq E_i$, we know that the sets
$D_1, \ldots D_{i - 1}, E_i, D_{i + 1}, \ldots D_k$ cover $X$.
\end{proof}

The following is the main result of Subsection~\ref{subsec-negative-computable-implies-piecewise-linear}.

\begin{lem}\label{lem:positive-continuous-piecewise-rational-linear}
  Let $f:\mathbb{R}_{\geq 0}^k \to \mathbb{R}_{\geq 0}$ be stably computed by a CRC $\mathcal{C}=(\Lambda,R,\Sigma,Y)$. Then $f$ is positive-continuous and piecewise rational linear.
\end{lem}

\begin{proof}
By Lemma~\ref{lem-nonnegative-computable-implies-positive-continuous}, we know that $f$ is positive-continuous and piecewise linear. By a general topological argument one could show that any function with these properties has domains of definition that are closed relative to $\mathbb{R}_{>0}^\Sigma$, but since by Lemma~\ref{lem-shifted-closed} the domains we constructed earlier already have this property, we won't give the general proof here. By Lemma~\ref{lem:replace-domains-of-defn-with-closed-domains} we can replace the closed sets that give the domains of definition of $f$ by closed domains. If some of the domains produced by Lemma~\ref{lem:replace-domains-of-defn-with-closed-domains} are empty we can simply ignore them in what follows. Since all of the nonempty domains are the closures of nonempty open sets, they must each contain some open ball. By Lemma~\ref{lem:open-ball-implies-rational}, $f$ is a rational linear function when restricted to each of these closed domains, so $f$ is piecewise rational linear on $\mathbb{R}_{>0}^\Sigma$.

For any proper subset $U$ of the input species, one can apply the above argument to the reduced CRN that  discards all species not producible from the given inputs to show that $f$ is continuous and piecewise rational linear on $D_U$. This shows that $f$ is a positive-continuous piecewise rational linear function on all of $\mathbb{R}_{\geq 0}^\Sigma$.
\end{proof}

\subsection{Dual-Rail Computable Functions are Continuous Piecewise Rational Linear}
\label{subsec:negative-dual-rail}

The following result,
a dual-rail analog of Lemma~\ref{lem:open-ball-implies-rational},
is not necessary for the proof of the main result of this section (Lemma~\ref{lem-computable-implies-piecewise-linear}), but it may be of independent interest.

\begin{proposition}\label{prop-siphon-implies-linear}
  Let $f:\mathbb{R}^k \to \mathbb{R}$ be stably dual computed by a CRC.
  Let $\Omega$ be an output stable siphon.
  Then $f$ restricted to inputs that have a dual rail representation in $\Sigma(\Omega)$ is linear.
\end{proposition}

\begin{proof}
A dual-rail computing CRC can be thought to \emph{directly} compute two separate functions $\hat{f}^+, \hat{f}^-: \mathbb{R}_{\geq 0}^{2k} \to \mathbb{R}_{\geq 0}$ such that $\hat{f} = \hat{f}^+ - \hat{f}^-$ where $\hat{f}$ is a dual rail representation of $f$.
By Lemma~\ref{lem-siphon-implies-linear-nondual} we know that $\hat{f}^+$ and  $\hat{f}^-$ are rational linear when restricted to $\Sigma(\Omega)$.
The proposition follows because linearity is closed under subtraction.
\end{proof}

\begin{lem}\label{lem-computable-implies-piecewise-linear}
  Let $f:\mathbb{R}^k \to \mathbb{R}$ be stably dual-computable by a CRC.
  Then $f$ is continuous and piecewise rational linear.
\end{lem}

\begin{proof}
  Let $\mathcal{C}$ be the CRC stably computing a dual-rail representation $\hat{f}$ of $f$, with input species
  $X_1^+$, $\ldots$, $X_k^+$, $X_1^-$, $\ldots$, $X_k^-$
  and output species $Y^+,Y^-$.

  Similarly to the proof of Proposition~\ref{prop-siphon-implies-linear}, a dual-rail computing CRC can be thought to \emph{directly} compute two separate functions $\hat{f}^+, \hat{f}^-: \mathbb{R}_{\geq 0}^{2k} \to \mathbb{R}_{\geq 0}$ such that $\hat{f} = \hat{f}^+ - \hat{f}^-$ where $\hat{f}$ is a dual rail representation of $f$.
  Let $\delta>0$.
  Then for \emph{any} input $\vec{x}' \in \mathbb{R}^k$ to $f$, there is an initial state $\vec{x}\in\mathbb{R}^{\Sigma}_{\geq \delta}$ representing $\vec{x}'$.
  Any sequences inputs $\vec{x}'_1,\vec{x}'_2,\ldots \in \mathbb{R}^k$ to $f$ such that $\lim_{i\to\infty} \vec{x}'_i = \vec{x}'$ are similarly represented by a sequence $\vec{x}_1,\vec{x}_2,\ldots \in\mathbb{R}_{\geq 0}^\Sigma$ of initial states of the CRC such that $\lim_{i\to\infty} \vec{x}_i = \vec{x}$ has the property that all but finitely many $\vec{x}_i$ obey $[\vec{x}_i]=\Sigma$.
  By Lemma~\ref{lem-nonnegative-computable-implies-positive-continuous}, $f$ is continuous on the domain in which all input species are positive, which includes the input represented by $\vec{x}$ and the inputs represented by all but finitely many of $\vec{x}_i$.
  Therefore, $f(\vec{x}') = \lim_{i\to\infty} f(\vec{x}'_i)$, so $f$ is continuous. Since $\hat{f}^+$ and $\hat{f}^-$ are stably computed by a CRC, Lemma~\ref{lem:positive-continuous-piecewise-rational-linear} implies that they are both piecewise rational linear, and since piecewise rational linear functions are closed under subtraction, this implies that $f$ is also piecewise rational linear.
\end{proof}

Emerging Technologies (cs.ET); Molecular Networks (q-bio.MN)