1 Introduction

Living organisms perform a variety of functions that can be described in abstract terms as information processing and regulation. Analogies have been drawn between the biochemical reaction networks that perform such functions and electric circuits of similar nature (Arkin 2000; Del Vecchio et al. 2008). The comparison is useful in systems biology, in trying to understand the function of natural systems, and in synthetic biology, in trying to engineer desired functionality in a biochemical context.

An obstacle to exploiting this analogy is that the fundamental components of biochemistry and electronics are very different: the phenomena of resistance, induction, and capacitance based on the interplay between electric and magnetic fields have no immediate parallel in terms of chemical concentrations. Hence, it is not clear how to take systematic advantage of engineering knowledge developed in electronics in understanding biochemical systems. Instead, the search for components of biological network has progressed in different and certainly more appropriate directions (Hart et al. 2012; Milo et al. 2002).

Even within electronics, though, the precise nature of electric components is incidental to the desired function. For example, one may wish to filter the high frequencies of a signal represented by an oscillating voltage. There are countless electric circuits that can perform this function, based on different classes of components in different configurations. Some of those circuits are based on operational amplifiers, which are themselves built from a large network of components to perform an abstract function to which they are incidental. The nature of the fundamental components is inessential, as long as they can be combined to provide a wide range of functionality.

A common way to describe essential function, both in electronics and in biochemistry, is through a system of ordinary differential equations (ODEs). Once the function of a circuit is reduced to this form, it does not matter if the quantities represented are voltages or concentrations: it only matters the way in which they vary over time. Conversely, given an ODE system, one may ask the engineering question of how to realize a circuit (electronic or biochemical) that can perform that function. An early example of this inverse process is the synthesis of mechanical and then electric analog circuits from differential equations (Bush 1931; Shannon 1941).

Certain classes of polynomial ODE systems can be systematically turned into chemical reaction networks (CRNs) that obey the same kinetics (Hars and Toth 1979). Further, CRNs can be compiled systematically into a collection of molecules that can be engineered to obey the kinetics of those reactions (Soloveichik et al. 2010). In this paper we wish to go one step further on the front end of this process. Taking advantage of the large libraries of known electric circuits, we wish to take an arbitrary (but linear, for now) electric circuit and show how to turn it into a set of molecules that obey the kinetics of the quantities in that circuit.

The first obstacle we need to confront is that even common electric circuits describe behaviors that go beyond ODEs. Algorithmic approaches for the analysis of linear circuits such as Modified Nodal Analysis produce, in general, systems of differential algebraic equations (DAEs), where the algebraic equations are induced by classical node analysis based on Kirchhoff laws (Ho et al. 1975). Hence we first reduce DAEs to ODEs, after which we can apply some further techniques. The second obstacle is to take an ODE that may be about voltages and currents, and turn it into a form that can be interpreted chemically. This means that each variable should only take nonnegative quantities (for concentrations), and that appropriate chemical reactions should be derived about those quantities.

This approach has a dual purpose. From a systems biology point of view, we may want to compare the CRNs derived from electric circuits to the ones occurring in nature. This might help elucidate the function of natural networks. Or, at least, it will provide a spectrum of possible chemical networks of known function, whose structure may not be obvious, therefore broadening our expectations of what is possible chemically. From a systems biology point of view, we take it as given that an abstract CRN can be turned into a collection of molecules. In fact, multiple target architectures are possible, from short oligonucleotides in solution (Soloveichik et al. 2010) to gene networks (Schwarz-Schilling et al. 2016). The ability to generate molecular configurations from a vast existing library of (electric, or other) circuits is appealing for systematizing the generations of synthetic organisms. In extending the known techniques from ODEs to DAEs, we extend the scope of potential libraries we can draw from.

Contributions Our main result is a systematic technique that transforms linear DAE systems into CRNs. Our technique is, to the best of our knowledge, novel. DAE systems are either solved symbolically by relying on index reduction (Pantelides 1988), or numerically by relying on numerical methods that compute the trajectories for a given initial condition (Kunkel and Mehrmann 2006). In contrast to our approach, index reduction introduces additional derivatives of signals that may not be available to the circuit, while numerical methods do not transform the DAEs into ODEs, which seems necessary for transforming DAE systems into CRNs. We analyze, as an example, an electric high pass filter and provide a chemical reaction network for it, whose function and architecture can be independently interpreted in a biological context.

2 Outline of methods

We start from a linear electric circuit composed of resistors, capacitors and inductors, with variables ranging over voltages and currents, and we systematically derive an equivalent CRN where chemical species (or more precisely their differences) approximate the trajectories of the original variables.

The basis for this process is the so-called Hungarian Lemma (Hars and Toth 1979), which provides a method for converting certain polynomial ODEs into CRNs by converting each monomial on the right hand side of a differential equation into a separate chemical reaction. Polynomial ODEs can represent, exactly, a much broader class of ODEs, including fractional, trigonometric, and exponential terms (Liu et al. 2015), thus covering a broad range of chemical behavior including Hill kinetics (Cardelli 2014).

The Hungarian Lemma, however, has specific requirements. First, the concentrations of the chemical species must be nonnegative, while ordinary ODE variables, and in particular voltages and currents, may be negative. Second, if a monomial has a negative sign, then the differential variable on the left-hand side of the equation must appear as a factor in the monomial. This means, for example, that the ODE \(\partial _{t}x = y\) (where the growth rate of x is given by the concentration of y, with \(\partial _{t}x\) denoting the time derivative of x) can be reduced to the reaction \(y \rightarrow x + y\). And the ODE \(\partial _{t}x = -xy\) can be reduced to the reaction \(x+y \rightarrow y\). But the ODE \(\partial _{t}x = -y\) (where the decrease in rate of x is given by the concentration of y) cannot be reduced: for x to decrease it must appear on the left-hand-side of a chemical reaction, which implies it should appear in a monomial for \(\partial _{t}x\) by the law of mass action. An ODE system with no such forbidden negative monomial is said to be Hungarian, and any Hungarian ODE system can be reduced to a CRN (although not uniquely) whose mass action kinetics reproduces the original ODE. We use a technique to reduce a polynomial non-Hungarian ODE to an Hungarian one in twice as many variables, thus allowing us to produce CRNs also for non-Hungarian ODEs. In the same step, we make all trajectories nonnegative so that they can be realized by chemical species.

Some simple electric circuits yield ODE systems that can be converted to CRNs as outlined. Pure resistor circuits yield simple algebraic equations. But more complex circuits yield general DAEs (Ho et al. 1975), which we must be prepared to handle. Our main technique applies to linear DAE systems of the form

$$\begin{aligned} E \partial _{t}x = A x + Bu \end{aligned}$$

Here, \(x \in \mathbb {R}^n\) is the (column) vector of dependent variables, \(E \in \mathbb {R}^{n \times n}\) produces a linear combination of their derivatives, \(A \in \mathbb {R}^{n \times n}\) produces a linear combination of the variables, and the term \(B \in \mathbb {R}^{n \times m}\) is the input matrix, and \(u \in \mathbb {R}^m\) is the vector of inputs, such as voltage or current sources. That is, A and E are real matrices which produce linear combinations of variables and their derivatives by multiplication with the corresponding column vectors.

In general, inputs are assumed to be arbitrary, known functions of time. However, for the purposes of converting electric circuits into CRNs, it is necessary to appropriately encode also the inputs as chemical species. In this paper, we will assume that the input vector u can be itself described as the solution of a system of equations. Specifically, we assume that it satisfies an affine ODE system of the form

$$\begin{aligned} \begin{pmatrix} \partial _{t}u \\ \partial _{t}z \end{pmatrix} = D \cdot \begin{pmatrix} u \\ z \end{pmatrix} + d \end{aligned}$$

for some matrix \(D \in \mathbb {R}^{(m+k) \times (m+k)}\) and \(\left( u(0),z(0) \right) ^T, d \in \mathbb {R}^{m+k}\). Intuitively, the input u in (1) is part of an ODE solution which may depend on auxiliary ODE variables z that do not appear in the DAE. This is a rather general setting that allows us to encode arbitrary time-varying inputs by approximating them with Fourier series, which can be expressed as solutions of linear ODEs (see Sect. 4).

Our technique converts the overall system (1), (2) into an ODE system over the same variables, up to a controllable approximation. That ODE system can then be transformed into a CRN as discussed above.

Fig. 1
figure 1

A high pass filter, with input voltage \(v_{in}\) and output voltage \(v_{out}\) with respect to ground. The symbols at the left, top, right and bottom of the diagram denote, respectively, a DC voltage source, a resistor, an inductor and the ground

We now describe in detail the entire process of converting linear electric circuits to CRNs, through a small textbook example involving a single differential equation and a single algebraic equation for the well-known RL (resistor–inductor) circuit in Fig. 1 (Agarwal and Lang 2005). The analysis of the circuit proceeds as follows. We let \(v_{ in }\) denote the input voltage (measured with respect to the ground node); the output is the voltage \(v_{ out }\) across the inductor. By standard node analysis, using Kirchhoff’s current law at each node, we obtain that the three currents are equal, so \(i \triangleq i_T = i_R = i_L\). Faraday’s law for the inductor L, and Ohm’s law for the resistor R, then give us:

$$\begin{aligned} \partial _{t}i&= v_{ out }/L \end{aligned}$$
$$\begin{aligned} iR&= v_{ in }- v_{ out } \end{aligned}$$

This is a DAE, where (3a) is a differential equation, and (3b) is an algebraic equation. To find its solution, we can replace \(v_{ out }= v_{ in }- iR\) from (3b) in (3a), obtaining (4a), which can be integrated to obtain i(t). From that solution we can then obtain \(v_{ out }(t)\) via (4b).

$$\begin{aligned} \partial _{t}i&= v_{ in }/L - iR/L \end{aligned}$$
$$\begin{aligned} v_{ out } &= v_{ in }- iR \end{aligned}$$

If we briefly assume that \(v_{ in }\) is a non-negative input source, then (4a) can be converted to a mass action CRN as follows (using chemical species with the same names as our variables):

$$ v_{{in}} \xrightarrow{{1/L}}{\text{ }}i + v_{{in}} \quad i\xrightarrow{{R/L}}\emptyset {\text{ }} $$

where with the symbol \(\emptyset \) we have denoted the empty set of products. These two chemical reactions yield (4a) for the evolution of the concentration of species i. However, a voltage \(v_{ in }\) may be negative, which cannot be modeled with chemical concentrations. Additionally, we are interested in the output \(v_{ out }\), not i, and therefore we need to find a way to realize chemically Eq. (4b) as well.

Because of those difficulties, we cannot make much progress without a more general technique to implement DAEs as CRNs. Our technique involves an approximation, like the one that seems necessary just for algebraic equations, but it can be used in the general case of linear DAEs. We now illustrate it by applying it to the example of Fig. 1. We first rearrange our DAE as (5a,5b). Setting \(x=(i, v_{ out })^T\) we have:

$$\begin{aligned} \partial _{t}i&= v_{ out }/L \end{aligned}$$
$$\begin{aligned} 0&= i + v_{ out }/R - v_{ in }/R \end{aligned}$$

which can be arranged into the form (1):

$$\begin{aligned} \underbrace{ \begin{pmatrix} 1 &{} 0 \\ 0 &{} 0 \end{pmatrix} }_{E} \underbrace{ \begin{pmatrix} \partial _{t}i \\ \partial _{t}v_{ out }\end{pmatrix} }_{\partial _{t}x}&= \underbrace{ \begin{pmatrix} 0 &{} 1/L \\ 1 &{} 1/R \end{pmatrix} }_{A} \underbrace{ \begin{pmatrix} i \\ v_{ out }\end{pmatrix} }_{x} + \underbrace{ \begin{pmatrix} 0 \\ -v_{ in }/R \end{pmatrix} }_{b} \end{aligned}$$

where we have fixed the constant vector \(b := Bu\) under the assumption of a constant input source \(u := v_{ in }\).

We approximate the DAE, for a parameter \(h>0\), by symbolically computing \(F_h(x) = (E-hA)^{-1}(Ax+b)\), which is related to the numerical backward Euler method. Taking \(R = L = 1\) for simplicity, we obtain:

$$\begin{aligned} F_h \begin{pmatrix} i \\ v_{ out }\end{pmatrix} = \begin{pmatrix} \dfrac{v_{ in }-i}{1+h} \\ \dfrac{v_{ in }-i-(1+h)v_{ out }}{h(1+h)} \end{pmatrix} \end{aligned}$$

We next use \(F_h(x)\) as the right-hand side of a new ODE system \(\partial _{t}x = F_h(x)\), which is such that for \(h \rightarrow 0\) the solution of the ODE system (7a), (7b) converges to the solution of the original DAE system (5a), (5b) (see Theorem 1).

$$\begin{aligned} \partial _{t}i&= v_{ in }/(1+h) - i/(1+h) \end{aligned}$$
$$\begin{aligned} \partial _{t}v_{ out }&= v_{ in }/(h+h^2) - i/(h+h^2) - v_{ out }/h \end{aligned}$$

Indeed, we can easily see that for \(h \rightarrow 0\), (7a) converges exactly to the ODE (4a). As for (7b), this is now a differential equation approximating Eq. (5b) for \(h \rightarrow 0\), where we notice that a small value of h makes (7b) evolve much faster than (7a).

We have reduced a DAE to an ODE, but (7a), (7b) is not Hungarian because of the \(-i\) monomial in (7b). Keeping in mind that we need to deal eventually with non-Hungarian ODEs, we now apply a positivation technique in the style of Oishi and Klavins (2011) and Fages et al. (2017), also known as dual-rail encoding, where each variable is represented as the difference of two non-negative variables:

$$\begin{aligned} i= i^{+}- i^{-}\quad v_{ in }= v_{ in }^{+}- v_{ in }^{-}\quad v_{ out }= v_{ out }^{+}- v_{ out }^{-}\end{aligned}$$

Let us now abbreviate \(p=1/(1+h)\), \(q=1/(h+h^2)\), and \(r=1/h\), and consider the ODE system where we separate the positive and negative monomials of each ODE in (7a), (7b) into two ODEs:

$$\begin{aligned} \partial _{t}i^{+}= pv_{ in }^{+}+ pi^{-}\quad \partial _{t}i^{-}= pv_{ in }^{-}+ pi^{+} \end{aligned}$$
$$\begin{aligned} \partial _{t}v_{ out }^{+}= qv_{ in }^{+}+ qi^{-}+ rv_{ out }^{-}\quad\partial _{t}v_{ out }^{-}= qv_{ in }^{-}+ qi^{+}+ rv_{ out }^{+} \end{aligned}$$

The initial conditions for this new system must satisfy \(i^{+}_0 - i^{-}_0 = i_0\) with \(i^{+}_0,i^{-}_0\ge 0\), etc. Since differentiation is a linear operator, the solutions of (7a), (7b) can be recovered as differences from the solutions of (8a), (8b): \(\partial _{t}i^{+}- \partial _{t}i^{-}= \partial _{t}i\) and \(\partial _{t}v_{ out }^{+}- \partial _{t}v_{ out }^{-}= \partial _{t}v_{ out }\). Although the goal was to make all variables non-negative, we now also have a Hungarian ODE system because all the monomials in (8a), (8b) are positive. Hence there is no further difficulty in converting these ODEs to mass action reactions, obtaining the following CRN with unary reagents, with one reaction for each monomial in (8a), (8b), and with the parameter h appearing in the reaction rates:

$$\begin{aligned} v_{ in }^{+}\mathop {\longrightarrow }\limits _{}^{p} v_{ in }^{+}+ i^{+}\quad i^{-}\mathop {\longrightarrow }\limits _{}^{p} i^{-}+ i^{+}\nonumber \cr v_{ in }^{-}\mathop {\longrightarrow }\limits _{}^{p} v_{ in }^{-}+ i^{-}\quad i^{+}\mathop {\longrightarrow }\limits _{}^{p} i^{+}+ i^{-}\nonumber \cr v_{ in }^{+}\mathop {\longrightarrow }\limits _{}^{q} v_{ in }^{+}+ v_{ out }^{+}\quad i^{-}\mathop {\longrightarrow }\limits _{}^{q} i^{-}+ v_{ out }^{+}\nonumber \cr v_{ in }^{-}\mathop {\longrightarrow }\limits _{}^{q} v_{ in }^{-}+ v_{ out }^{-}\quad i^{+}\mathop {\longrightarrow }\limits _{}^{q} i^{+}+ v_{ out }^{-}\nonumber \cr v_{ out }^{-}\mathop {\longrightarrow }\limits _{}^{r} v_{ out }^{-}+ v_{ out }^{+}\quad v_{ out }^{+}\mathop {\longrightarrow }\limits _{}^{r} v_{ out }^{+}+ v_{ out }^{-}\end{aligned}$$

Here the input \(v_{ in }^\pm \) always acts as a simple catalyst. We note that the CRN implementation does not depend on the actual value of \(v_{ in }\), which only affects the initial condition of the chemical species that represent \(v_{ in }^\pm \). This decoupling between the CRN implementation of the circuit and that of the input sources carries over to the more general case when the sources are time-varying solutions of the ODEs (2), see Theorem 3 and the subsequent discussion.

Inspecting (9), the chemical species \(v_{ out }^\pm \) and \(i^\pm \) are involved in autocatalytic cycles. For example both \(i^{+}\) and \(i^{-}\) grow exponentially over time, while their difference i remains bounded. It is possible to eliminate such exponential growths by adding non-linear dampening reactions to the CRN:

$$\begin{aligned} i^{+}+ i^{-}\mathop {\longrightarrow }\limits _{}^{\gamma } \emptyset\quad v_{ out }^{+}+ v_{ out }^{-}\mathop {\longrightarrow }\limits _{}^{\gamma } \emptyset \end{aligned}$$

The first reaction, for example, preserves the difference \(i^{+}- i^{-}\), and results in two new identical monomials in the ODEs for \(i^{+}\) and \(i^{-}\), that then cancel in \(\partial _{t}i^{+}- \partial _{t}i^{-}\). Hence that reaction does not change the i solution, but keeps \(i^{+}\) and \(i^{-}\) bounded.

The network consisting of reactions (9), (10) is depicted in Fig. 2, where for small h we have \(1 \approx p \ll q \approx r\), and we can take \(\gamma = r\). This network has the flavor of an incoherent feedforward motif (Milo et al. 2002), considering parallel pairs \(x^\pm \rightarrow y^\pm \) as activations and cross pairs \(x^\pm \rightarrow y^\mp \) as inhibitions, thereby \(v_{ in }\) activates both i and \(v_{ out }\), and i ‘incoherently’ inhibits \(v_{ out }\). Additionally, the motif of mutual catalysis and join degradation around \(i^\pm \) makes that pair stabilize to a copy of its input \(v_{ in }^\pm \) (in the sense that at steady state \(i^{+}- i^{-}= v_{ in }^{+}- v_{ in }^{-}\)) regardless of the value of the rate p. This motif is repeated around \(v_{ out }^\pm \). When the input \(v_{ in }^\pm \) remains constant, \(i^\pm \) becomes a copy of \(v_{ in }^\pm \), and \(v_{ out }^\pm \) becomes a copy of the sum of its two opposite inputs, \(v_{ in }^\pm \) and \(i^\mp \), and so it converges to a baseline output of \(v_{ out }^{+}- v_{ out }^{-}\approx 0\). When the input \(v_{ in }\) changes, it affects \(v_{ out }\) quickly and i slowly, with a delayed inhibition of \(v_{ out }\) by i. It has been shown that feedforward motifs can behave like high-pass filters (de Ronde et al. 2012).

The subnetwork in Fig. 2 consisting of \(v_{ in }^\pm \), \(v_{ out }^\pm \), and the connecting q,r,\(\gamma \) arcs, is in itself also a low-pass filter. It is exactly what is obtained when replacing the inductor with a capacitor of capacitance C in Fig. 1, yielding a well known low-pass filter, and deriving the CRN from it by positivation (with \(q=r=1/RC\)). The process is simpler in this case, since a single ODE is generated from that circuit, and no approximation via \(h \rightarrow 0\) is required.

In summary, we have derived an intelligible chemical reaction network from an electric circuit, and we are guaranteed that it implements the same functionality, as shown in the next section.

Fig. 2
figure 2

The CRN for the high-pass filter of Fig. 1, consisting of reactions (9, 10). A ball-headed arc from x to y denotes a reaction \(x \rightarrow x + y\), and a double-tailed arc from x and y denotes a reaction \(x + y \rightarrow \emptyset \). Black arcs have much faster rates than blue arcs

3 Methods

3.1 From DAEs to ODEs

We first show how to convert a linear DAE system into a linear ODE system. To this end we start with a DAE system in the form

$$\begin{aligned} E \partial _{t}x = A x + b, \quad \text {with}\, E, A \in \mathbb {R}^{n \times n}, b \in \mathbb {R}^n, \end{aligned}$$

which corresponds to (1) under the assumption of constant inputs u. Following Hadamard’s concept of well-posedness, we next assume regularity. A DAE system is regular if there exists no initial condition \(x(0) \in \mathbb {R}^n\) which admits more than one solution. We let \(\mathcal {D}\) denote the set of initial conditions for which a regular DAE admits solutions. Elements of \(\mathcal {D}\) are called consistent initial conditions (see, e.g., Kunkel and Mehrmann 2006, Section 2.1 for details). In the case of electric circuits, for instance, non-regular DAE systems may arise in the presence of short circuits and other erroneous designs.

If E is invertible, this DAE can be directly recast into a linear ODE system via

$$\begin{aligned} \partial _{t}x = E^{-1} A x + E^{-1} b. \end{aligned}$$

However, in the case of linear electric circuits E is in general not invertible. In this case, a transformation of a DAE system into an ODE system requires index reduction (Pantelides 1988; Kunkel and Mehrmann 2006), which relies on expensive symbolic computations. Our method consists in circumventing this analysis by considering an explicit scheme arising from numerical methods for the solution of DAE systems.

A numerical method is an algorithm that generates, for a given small time step \(h > 0\) and initial condition x(0), a sequence \((x[i])_i\) such that \(x[i] \approx x(i h)\), where \(x : [0;\infty ) \rightarrow \mathbb {R}^n\) denotes the solution of (11). Numerical methods are guaranteed to converge to the solution x when h approaches zero. That is, that for any error threshold \(\varepsilon > 0\) and finite time horizon \(T > 0\), one can find a sufficiently small time step \(h > 0\) such that \(\max _{0 \le i \le N} ||x[i] - x(i h) || \le \varepsilon \) and \(T / h = N \in \mathbb {N}\).

A common numerical method for the solution of DAE systems is the backward Euler method (Kunkel and Mehrmann 2006, Section 5.2) which is given by

$$\begin{aligned} &x[i + 1]= x[i] + h F_h(x[i]), \text {with }\\ & F_h(x) := (E - hA)^{-1}(A x + b).\end{aligned} $$

The function \(F_h\) is well-defined for sufficiently small \(h > 0\) because the DAE system is regular (Kunkel and Mehrmann 2006, Section 2.1).

Noting that the “slope” of the Euler method at point x[i], \((x[i + 1] - x[i]) / h\), is given by \(F_h(x[i])\), we expect that the Euler sequence \((x[i])_{i \ge 0}\) will match the solution of the ODE system \(\partial _t x_h = F_h(x_h)\). That is, we expect that \(x_h(i h) \approx x[i]\) for all \(0 \le i \le N\). Then, the convergence of the Euler sequence to the DAE solution x would allow us to conclude that \(x_h(i h) \approx x[i] \approx x(i h)\).

The next theorem is our first main result and proves that this is indeed the case.

Theorem 1

For any \(\varepsilon > 0\), \(x(0) \in \mathcal {D}\) and \(T > 0\), there exists an \(h > 0\) such that \(\sup _{0 \le t \le T} ||x(t) - x_h(t) || \le \varepsilon \), where \(\partial _{t}x_h = F_h(x_h)\) and \(x_h(0) = x(0)\).

We now extend Theorem 1 to systems (1), (2).

Theorem 2

Given a DAE system via (1) and (2), consider the ODE system

$$\begin{aligned} \partial _{t}x_h = (E - hA)^{-1}\left( A x_h + B u_h^{\langle 0 \rangle } + h B u_h^{\langle 1 \rangle } \right) , \end{aligned}$$

where \(h > 0\) is small and the functions \(u_h^{\langle 0 \rangle }, u_h^{\langle 1 \rangle } \in \mathbb {R}^m\) satisfy

$$\begin{aligned} \begin{pmatrix} \partial _{t}u^{\langle 0 \rangle }_h \\ \partial _{t}z^{\langle 0 \rangle }_h \end{pmatrix}&= (I - h D)^{-1} D \begin{pmatrix} u_h^{\langle 0 \rangle } \\ z_h^{\langle 0 \rangle } \end{pmatrix} + (I - h D)^{-1} d \end{aligned}$$
$$\begin{aligned} \begin{pmatrix} \partial _{t}u^{\langle 1 \rangle }_h\\ \partial _{t}z^{\langle 1 \rangle }_h \end{pmatrix}&= (I - h D)^{-1} D \begin{pmatrix} u_h^{\langle 1 \rangle }\\ z_h^{\langle 1 \rangle }\\ \end{pmatrix} \end{aligned}$$

with initial conditions

$$\begin{aligned} u_h^{\langle 0 \rangle }(0)= u(0)\quad u_h^{\langle 1 \rangle }(0)= (I - h D)^{-1} D u(0) \\ z_h^{\langle 0 \rangle }(0)= z(0)\quad z_h^{\langle 1 \rangle }(0)= (I - h D)^{-1} D z(0) \end{aligned}$$

Then, for any \(\varepsilon > 0\), \(x(0) \in \mathcal {D}\) and \(T > 0\), there exists an \(h > 0\) such that \(\sup _{0 \le t \le T} ||x(t) - x_h(t) || \le \varepsilon \) if \(x_h(0) = x(0)\).

Note that \(I - h D\) is strictly diagonal dominant and therefore invertible for sufficiently small values of h. It can be shown that \((u^{\langle 0 \rangle }_h, v^{\langle 0 \rangle }_h)^T\) converges to \((u,v)^T\) from (2) as \(h \rightarrow 0\). Hence, Theorem 2 essentially replaces the constant vector b in \(F_h(x) = (E - hA)^{-1}(A x + b)\) by the function Bu.

3.2 From ODEs to CRNs

We next present a technique that transforms the ODE approximation from Sect. 3.1 into a CRN. The approach borrows ideas from Oishi and Klavins (2011) that transforms linear ODE systems (i.e., systems without algebraic constraints) into CRNs. We wish to point out, however, that our approach considers state space representation, while (Oishi and Klavins 2011) acts on the frequency domain.

In the following, let \(\partial _{t}x = \hat{A}x + \hat{b}\) denote some ODE system with initial condition x(0).

Proposition 1

Any non-negative quadruple \((\hat{A}^+,\hat{A}^-,\hat{b}^+,\hat{b}^-)\) satisfying \(\hat{A}= \hat{A}^+ - \hat{A}^-\) and \(\hat{b}= \hat{b}^+ - \hat{b}^-\) induces the positivation

$$\begin{aligned} \begin{aligned} \partial _{t}x^+&= \hat{A}^+ x^+ + \hat{A}^- x^- + \hat{b}^+ \\ \partial _{t}x^-&= \hat{A}^+ x^- + \hat{A}^- x^+ + \hat{b}^- \end{aligned} \end{aligned}$$

If (15) is subject to non-negative \(x^+(0), x^-(0) \in \mathbb {R}^n_{\ge 0}\) with \(x(0) = x^+(0) - x^-(0)\), the corresponding solution \((x^+, x^-)\) is non-negative and satisfies \(x = x^+ - x^-\).

While positivations trivially satisfy the properties of the Hungarian lemma discussed in Sect. 2 and can therefore be readily translated into CRNs, they may exhibit divergence even if the original system is bounded, see for instance (8a), which implies that \(i^+\) and \(i^-\) diverge. Fortunately, one can apply a correction that leads to bounded positivations.

Proposition 2

Given a positivation \((\hat{A}^+,\hat{A}^-,\hat{b}^+,\hat{b}^-)\), define the quadratic function \(Q(x^+,x^-) = (x_1^+ x_1^-,\ldots ,x_n^+ x_n^-)^T\). For any \(\gamma > 0\), the corresponding Hungarization is given by

$$\begin{aligned} \begin{aligned} \partial _{t}x^+&= \hat{A}^+ x^+ + \hat{A}^- x^- + \hat{b}^+ - \gamma Q(x^+,x^-) \\ \partial _{t}x^-&= \hat{A}^+ x^- + \hat{A}^- x^+ + \hat{b}^- - \gamma Q(x^+,x^-) \end{aligned} \end{aligned}$$

If (16) is subject to non-negative \(x^+(0), x^-(0) \in \mathbb {R}^n_{\ge 0}\) with \(x(0) = x^+(0) - x^-(0)\), ODE system (16) admits a non-negative solution on \([0;\infty )\) that satisfies \(x = x^+ - x^-\). Moreover, if x is bounded on \([0;\infty )\), then so is \((x^+, x^-)\).

By applying the law of mass action, it can be easily seen that the Q terms in (16) are captured by the annihilation reactions \(x^{+}_1 + x^{-}_1 \mathop {\longrightarrow }\limits _{}^{\gamma } \emptyset , \ldots , x^{+}_n + x^{-}_n \mathop {\longrightarrow }\limits _{}^{\gamma } \emptyset \). Combining this with Proposition 2, we arrive at the following statement.

Proposition 3

Define the chemical reactions of the Hungarization (16) as

$$\begin{aligned} \mathcal {R}&= \left\{ x^+_i + x^-_i \mathop {\longrightarrow }\limits _{}^{\gamma } \emptyset \big | i \right\} \cup \left\{ \mathop {\longrightarrow }\limits _{}^{\hat{b}^+_i} x^+_i \big | i \right\} \cup \left\{ \mathop {\longrightarrow }\limits _{}^{\hat{b}^-_i} x^-_i \big | i \right\} \\&\cup \left\{ x^+_j \mathop {\longrightarrow }\limits _{}^{\hat{A}^+_{i,j}} x^+_j + x^+_i \big | i,j \right\} \cup \left\{ x^-_j \mathop {\longrightarrow }\limits _{}^{\hat{A}^-_{i,j}} x^-_j + x^+_i \big | i,j \right\} \\&\cup \left\{ x^+_j \mathop {\longrightarrow }\limits _{}^{\hat{A}^-_{i,j}} x^+_j + x^-_i \big | i,j \right\} \cup \left\{ x^-_j \mathop {\longrightarrow }\limits _{}^{\hat{A}^+_{i,j}} x^-_j + x^-_i \big | i,j \right\} \end{aligned}$$

Then, the reactions \(\mathcal {R}\) induce, via the law of mass action, the ODE system (16).

For instance, if the positivation is given by (7a, 7b), then (9, 10) constitute \(\mathcal {R}\).

Proposition 3 and Theorem 2 yield our main result.

Theorem 3

Given a DAE system via (1) and (2), let

  • \(\mathcal {H}_{1,h}\) and \(\mathcal {H}_{2,h}\) denote the Hungarization of (12) and (13, 14), respectively.

  • \(\mathcal {R}_{1,h}\) and \(\mathcal {R}_{2,h}\) refer to the chemical reactions of \(\mathcal {H}_{1,h}\) and \(\mathcal {H}_{2,h}\), respectively.

Then, the following holds.

  1. (a)

    The solution of the CRN given by \(\mathcal {R}_{1,h} \cup \mathcal {R}_{2,h}\) converges to the DAE solution as \(h \rightarrow 0\).

  2. (b)

    A change of D and d affects the reactions of \(\mathcal {R}_{2,h}\) but does not alter the reactions of \(\mathcal {R}_{1,h}\).

As anticipated in Sect. 2, Theorem 3 ensures that a) our encoding is correct up to a controllable error and b) that the CRN implementation of the circuit, \(\mathcal {R}_{1,h}\), does not depend on the CRN implementation of the input, \(\mathcal {R}_{2,h}\).

Theorems 2 and 3 allow for composition of circuits: a circuit expressed as a DAE (1), with input provided by an ODE (2), yields another ODE (12) that can be supplied as input to a further circuit. The corresponding CRNs can be composed as well.

4 Methods applied to example

The RL circuit discussed in Sect. 2 is a high-pass filter, attenuating the low frequencies of the input while transmitting the high frequencies to the output. The cutoff frequency is the frequency at which the input signal is attenuated by \(\frac{1}{2}\) its power, or equivalently its amplitude is attenuated by \(-3\,\text {dB} \approx \sqrt{\frac{1}{2}} \approx 0.707\). In our circuit, the cutoff frequency is \(f_c = \frac{R}{2\pi L} \text {Hz}\), where R is the value of the resistance (measured in ohm) and L is the inductance (in henry).

Here we show how we can apply Theorem 3 to the RL circuit with a time-varying input represented by an arbitrary differentiable function. Such a function can be approximated arbitrarily well by a Fourier series u(t) given by

$$\begin{aligned} u(t)&= \alpha + \sum _{i = 1}^N \beta _i \sin (\omega _i t + \gamma _i) , \end{aligned}$$

where \(\alpha \), \(\beta _i\), \(\omega _i\), and \(\gamma _i\) are constant parameters. It can be seen that u(t) can be written as the solution of the ODE system:

$$\begin{aligned} \partial _t u= \sum _{i = 1}^N \beta _i\omega _i \bar{z}_i\quad \partial _t z_i= \omega _i \bar{z}_i \quad \partial _t \bar{z}_i= - \omega _i z_i \end{aligned}$$

with initial conditions \(z_i(0) = \sin (\gamma _i)\), \(\bar{z}_i(0) = \cos (\gamma _i)\) and \(u(0) = \alpha + \sum _{i = 1}^N \beta _i \sin (\gamma _i)\) with \(1 \le i \le N\), whereby \(z_i\) and \(\bar{z}_i\) are auxiliary variables whose solutions give the sinusoidal components of the series. We can recognize the system (17) to be in the required form (2).

Fig. 3
figure 3

Left: simulation of the CRN from Fig. 2, plotting variables differences, with \(L=R=1\), input \(v_{ in }= v_{ in }^{+}- v_{ in }^{-}\) of frequency \(\frac{1}{2\pi } \text {Hz}\), and output \(v_{ out }= v_{ out }^{+}- v_{ out }^{-}\). Horizontal axis is time. Right: the same, but plotting the individual variables

As a first example of an input waveform, we consider the ODE system

$$\begin{aligned} \begin{pmatrix} \partial _t u \\ \partial _t z \end{pmatrix} = \begin{pmatrix} 0 &{} 1 \\ -1 &{} 0 \\ \end{pmatrix} \cdot \begin{pmatrix} u \\ z \end{pmatrix} \end{aligned}$$

With initial conditions \(u(0) = 0\) and \(z(0) = 1\), this yields the solution \(u(t) = \sin (t)\) for all t, whose frequency is the cutoff frequency. Figure 3 shows simulations of the \(\sin (t)\) CRN composed with the high-pass filter CRN, taking \(h = 0.01\) for a sufficiently good approximation, and \(\gamma = r\) for a sufficiently fast degradation. As expected, the output \(v_{ out }\) is attenuated by \(-3\text {dB} \approx 0.707\), and its phase is shifted by \(45^{\circ }\). The variation of the underlying non-negative variables is shown on the right.

Fig. 4
figure 4

The circuit from Fig. 2 exhibiting perfect adaptation. Input \(v_{ in }= v_{ in }^{+}- v_{ in }^{-}\), and output \(v_{ out }= v_{ out }^{+}- v_{ out }^{-}\). Horizontal axis is time

As a second example, in a biological context, high pass filters exhibit perfect adaptation (Ferrell 2016): they adapt to slow but possibly large variations in input stimulus and still react to quick changes. In Fig. 4 we supply stepped inputs via an appropriate Fourier series to our filter. At each sudden increase or decrease, the output reacts quickly and then settles back to its original level. The size of the transient response is proportional to the step size, but independent of the level of the input. The adaptation level can be set to any level, not just zero, by adding a constant contribution to \(v_{ out }^+\), so that the output can represent the (positive) concentration of a certain protein.

5 Discussion

We have presented a method to convert linear DAEs to CRNs which hinges on a transformation into an approximate linear ODE system with arbitrary accuracy. This is then translated into a set of reactions where the time-course evolutions of the concentrations of the chemical species can be directly related to the original DAE solution.

In principle, any DAE system can be exactly transformed into an ODE system by means of the so-called index reduction (Kunkel and Mehrmann 2006). However, this relies on symbolic computations. Moreover, the so-obtained ODE system will contain derivatives of the input signal, thus requiring for additional approximations. For instance, by differentiating (3b) and using (3a) we obtain \(\partial _t v_{ out }= \partial _t v_{ in }- \frac{R}{L}v_{ out }\), which together with (3a) is a simple ODE system in the dependent variables with no algebraic equations. This system now depends on the derivative of the input, \(\partial _t v_{ in }\), and would have to be combined with another circuit to supply that derivative from the given input \(v_{ in }\). In contrast to index reduction our technique does not require input derivatives. Moreover, while index reduction requires symbolic computations, the matrix inversion at the basis of the construction of the approximate linear ODE system can also be performed using numerical techniques.

Fig. 5
figure 5

An electric circuit which gives the DAE system (19) that is not in semi-explicit form. Here, \(C_1\), \(C_2\) and R refer, respectively, to the first capacitor, the second capacitor and the resistor

The precision of the linear ODE depends on a parameter which, when taken asymptotically small, has the effect of rapidly equilibrating certain components of the ODE system. Therefore, in this respect our approach can be related to quasi steady-state approximation (QSSA, Verhulst 2005; Pantea et al. 2014), which applies to semi-explicit DAEs in the special form

$$\begin{aligned} \begin{aligned} \partial _t x&= A_1 x + B_1 u \\ 0&= A_2 y + B_2 u\\ \end{aligned} \end{aligned}$$

Essentially, QSSA replaces the algebraic constraints \(0 = A_2 y + B_2 u\) with \(\varepsilon \partial _t y = A_2 y + B_2 u\) for some \(\varepsilon \approx 0\). However, DAEs of electric circuits are not semi-explicit in general. For instance, the circuit given in Fig. 5 yields the DAE system

$$\begin{aligned} \begin{aligned} (C_1 + C_2) \partial _t v_1 - C_2 \partial _t v_2&= i_S \\ C_2 \partial _t v_1 - C_2 \partial _t v_2&= \frac{1}{R} v_2 , \end{aligned} \end{aligned}$$

which is not semi-explicit because it has two differential variables on the left-hand side.

Extensions of this work are needed to tackle non-linear DAE systems arising from non-linear electronic components such as diodes and transistors. The conversion of polynomial ODEs to Hungarian and positive ones, and thus to CNRs, works essentially unchanged also for non-linear polynomial systems, and further extends to ODE systems including trigonometric and exponential functions, which can model transistors. However, this must be coupled with a general method for converting non-linear DAEs arising from electronic circuits to ODEs.