Gated reactions in discrete time and space

How much time does it take two molecules to react? If a reaction occurs upon contact, the answer to this question boils down to the classic first-passage time problem: find the time it takes the two molecules to meet. However, this is not always the case as molecules switch stochastically between reactive and non-reactive states. The reaction is then said to be"gated"by the internal states of the molecules involved which could have a dramatic influence on kinetics. A unified, continuous-time, approach to gated reactions on networks was presented in [Phys. Rev. Lett. 127, 018301, 2021]. Here, we build on this recent advancement and develop an analogous discrete-time version of the theory. Similar to continuous-time, we employ a renewal approach to show that the gated reaction time can always be expressed in terms of the corresponding ungated first-passage and return times; which yields formulas for the generating function of the gated reaction-time distribution and its corresponding mean and variance. In cases where the mean reaction time diverges, we show that the long-time asymptotics of the gated problem is inherited from its ungated counterpart. However, when molecules spend most of their time non-reactive, an interim regime of slower power-law decay emerges prior to the terminal asymptotics. The discretization of time also gives rise to resonances and anti-resonances, which were absent from the continuous time picture. These features are illustrated using two case studies that also demonstrate how the general approach presented herein greatly simplifies the analysis of gated reactions.

How much time does it take two molecules to react? If a reaction occurs upon contact, the answer to this question boils down to the classic first-passage time problem: find the time it takes the two molecules to meet. However, this is not always the case as molecules switch stochastically between reactive and non-reactive states. The reaction is then said to be "gated" by the internal states of the molecules involved which could have a dramatic influence on kinetics. A unified, continuous-time, approach to gated reactions on networks was presented in [Phys. Rev. Lett. 127, 018301, 2021]. Here, we build on this recent advancement and develop an analogous discrete-time version of the theory. Similar to continuous-time, we employ a renewal approach to show that the gated reaction time can always be expressed in terms of the corresponding ungated first-passage and return times; which yields formulas for the generating function of the gated reaction-time distribution and its corresponding mean and variance. In cases where the mean reaction time diverges, we show that the long-time asymptotics of the gated problem is inherited from its ungated counterpart. However, when molecules spend most of their time non-reactive, an interim regime of slower power-law decay emerges prior to the terminal asymptotics. The discretization of time also gives rise to resonances and anti-resonances, which were absent from the continuous time picture. These features are illustrated using two case studies that also demonstrate how the general approach presented herein greatly simplifies the analysis of gated reactions.

I. INTRODUCTION
Gated processes are ubiquitous in the chemical, 1-5 biological 6-10 and physical sciences. [11][12][13][14][15][16][17] An example of a gated process is given in Fig. 1, which illustrates a gated cleavage reaction. Adopting a chemical prone nomenclature, we imagine a "particle", e.g., enzyme, that can react with a "target", e.g., a cleavage site on a peptide or DNA strand. The particle switches between two states -a reactive state and a non-reactive state. Importantly, a reaction occurs only when the particle meets the target while being in the reactive state. Thus, the reaction is said to be "gated" by the particle's internal state.
More generally, a gated reaction has an underlying spatial component on top of which an internal (gating) component is added. The spatial component can be any stochastic motion that the particle undertakes in search of the target. [18][19][20][21] Similarly, one can in principal consider any internal dynamics, e.g, multiple reactive and/or non-reactive states; 14 or even non-Markovian dynamics. 12 Recently, gated processes enjoyed renewed attention across a wide range of disciplines and directions: Kochugaeva, Shvets and Kolomeisky considered the switching dynamics of a protein undertaking facilitated diffusion on a DNA strand. 22 A later general model, that bears some similarity, is the gated continuous-time and discrete-space random search for a target on a 1D interval by Shin and Kolomeisky. 23 Markedly, both models allow for diffusion rates which depend on the internal state. Gated diffusion with different diffusivities was also considered by Godec and Metzler, for 3D Brownian motion inside a spherical domain, with a spherical target at its a) Electronic mail: yuvalscher@mail.tau.ac.il b) Electronic mail: shlomire@tauex.tau.ac.il FIG. 1. An illustration of a gated reaction in discrete time and space. A particle, here a cleaving enzyme, switches between a reactive state (red) and a non-reactive state (blue). A cleaving reaction occurs when the enzyme reaches the cleavage site (target), which is denoted here by a red patch on a gray peptide, while being in the reactive state. Different stages of the reaction were denoted as follows: (a) The enzyme is away from the cleavage site and in the non-reactive state, (b) The enzyme is on the cleavage site and in the non-reactive state, (c) The enzyme is away from the cleavage site and in the reactive state, (d) The enzyme is on the cleavage site and in the reactive state, which results in a reaction.
center, 24 thus generalizing the pioneering works of Szabo et al. 1,25 Even when considering a particle with diffusivity that is decoupled from the internal state there are still plenty directions to explore. Mercado-Vásquez and Boyer studied the reaction time of a gated 1D diffusing particle on the semi-infinite line, 26 adding novel insights to the works of Budde, Cáceres and Ré. [11][12][13] They then proceeded to extend their theory to the cases of a gated run-and-tumble particle 27 and a gated diffusive particle under restart. 28 The latter was also previously considered by Bressloff with a slightly different model. 29 Gopic and Szabo deepened the exploration of multiple gated particles/targets in a model that allows for reversible binding. 30 Lawley and Keener demonstrated mathematically the connection between the Robin (radiation) boundary condition, which is central in the theory of diffusion-influenced reactions, 31,32 and a gated boundary. 33 In a previous letter this year, we developed a unifying approach to gated reactions on networks in the framework of the Montroll-Weiss Continuous-Time Random-Walk (CTRW). 34 We showed that the mean and distribution of the gated reaction time can always be expressed in terms of ungated first-passage and return times. A related result is that of Spouge, Szabo and Weiss, that connected between gated and ungated propagators of Markovian diffusion processes. 14 We instead focused on the reaction time distribution, which is generally more attainable, be it analytically, experimentally or numerically. Utilizing a renewal framework, we were able to treat general spatial processes, which can be non-homogenous and non-Markovian. 34 Here, we develop an analogous discrete-time version of this framework, and illustrate its applicability with examples.
Previously, a discrete time multi-particle gating reaction on a d-dimensional regular lattice was considered by Bénichou, Moreau and Oshanin. 5 However, to the best of our knowledge, single-particle discrete time and space gating problems were not considered before. One reason to do so is because discrete space-time models are the bread-and-butter of stochastic analysis and first-passage modelling. [19][20][21]35 Discrete-time Markov chains in particular are widely applied in this context, and extending these to include gating dynamics is thus desirable. Not less important is the fact that discrete space-time models of gating provide a convenient testbed for resonance and antiresonance effects that were completely absent from the class of continuous time models considered in our previous work. 34 While such effects can still be studied in continuous time using models of non-Markovian internal gating dynamics, understanding their origin within a much simpler discrete-time Markovian framework has significant advantages in terms of analytical tractability.
The remainder of this paper is structured as follows. In section II, we develop a general theory for gated reactions on networks. Working in discrete time, we employ a renewal approach to express the gated reaction-time in terms of the corresponding ungated reaction-time. Formulas for the generating function of the gated reaction-time distribution, as well its mean and variance, are derived. In cases where the mean reaction time diverges, we prove that the long-time asymptotics of the gated problem is inherited from its ungated counterpart, where only the pre-factor of the power-law tail changes. We also study these cases under conditions of high-cripticity, i.e., when the molecules spend most of their time in the non-reactive state. We show that the terminal asymptotic regime is then preceded by a transient regime of slower power-law decay which we determine exactly.
In sections III and IV, we utilize the general results obtained to analyze two case studies. The first is of a particle moving in a unidirectional manner on a circle in search of a target. While the ungated version of this problem is nothing but trivial, it is more challenging to solve the gated version, and indeed interesting features arise when gating is added. Specifically, we see that while the results in section II bear resemblance to the results of Ref. 34 , the dis-cretization of time introduces new features that do not exist in the continuous-time analogue. Noticeably, resonance and anti-resonance effects emerge, when the internal gating dynamics is in, or out of, phase with the spatial process governing particle-target encounters.
The case study considered in section III belongs to a wide class of problems in which the mean reaction time is well-defined. Yet, one often encounters problems in which the mean diverges, e.g., when considering open systems. In such cases, one is usually interested in the reaction time distribution itself, and especially in its long-time asymptotics. In section IV we demonstrate how our formalism can be used to deal with such cases by using it to solve for the gated reaction time of a symmetric random-walk on a 1D lattice. As this problem was not solved previously, we offer two approaches for the solution: (a) writing the corresponding master equation and solving it brute-force, (b) using the renewal approach developed in section II of this paper. One can then appreciate how the latter elegantly replaces a complex calculation in favour of a straight forward solution method which readily reveals key features of the gated analogue of a classic first-passage problem. To put things in context, we conclude section IV with a general perspective on gated 1D random walks and reactions.
The modus operandi employed in sections III and IV is not limited to 1D systems, and applies without change to gated reactions on lattices of higher dimensions and to gated reactions on networks of arbitrary topology. This fact is further stressed in section V which concludes this work with a simple "algorithm" that allows one to generate solutions to gated reaction problems from solutions to their ungated counterparts, thus circumventing the need to solve gated problems directly. Importantly, this approach can be utilized even when an analytical solution to the ungated first-passage problem is not known, and as long as it can be estimated numerically. In this way, the analysis of gated problems is greatly simplified.

II. GENERAL THEORY
Consider a single particle in search of a single target site that is embedded in a general network (N.B., the network can be a lattice, but it need not be). To find the target, the particle conducts a general random walk on the network. This is done in discrete time. Namely, in each time step the particle jumps from its site of origin to a different site according to some prescribed law of motion. To keep things general, we allow for non-homogeneous random walks, where the set of accessible sites and the probabilities to reach each one of them can depend on the site of origin. Our only requirement is that the prescribed law of motion is not time dependent, i.e., that the connectivity at each site, and its jumping probabilities, do not change in time. We will refer to this property as time-homogeneity.
In contrast to classical first-passage problems, 18-21 in gated problems the particle stochastically transitions between a reactive state and a non-reactive state, such that arrival to the target is not sufficient by itself. To react, the particle must reach the target in the reactive state. We are interested in the statistics of the reaction time, defined to be the first-passage to target while in the reactive state. Our theory yields close formulas for the mean, variance and the generating function of the probability mass function (PMF) of the reaction time in terms of the corresponding ungated first-passage statistics. It is important to note that we hereby focus on a single particle and a single target, and it is of no matter whether gating occurs on the particle, on the target, or is due to a joint effect. We will thus often remain general and consider "a gated system". In the case of multiple particles, however, the statistics for gated particles and gated targets do differ. 2,3,30,36 In what follows, we use X , σ (X) andX(z) ≡ z X = ∑ ∞ n=0 P(X = n)z n to denote, respectively, the expectation, standard deviation, and Z-transform of a integer-valued random variable X.

Internal Dynamics of a Two-State System
The internal dynamics of the particle is described by a discrete-time Markov chain composed of two states ( Fig.  2): Reactive (R) and Non-Reactive (NR). The transition probability from R to NR is denoted by p and the complementary self-transition probability is denoted by 1 − p. Similarly, the transition probability from NR to R is denoted by q and the complementary self-transition probability is denoted by 1 − q.
We are interested in P(R, n | ω 0 ), the conditional probability to be in the reactive state after n steps, given an initial internal state ω 0 ∈ {R, NR, eq}, where 'eq' stands for equilibrium. Solving, we obtain (Appendix A) where ∆ := 1 − p − q and the equilibrium occupancies of the two states are π R = P(R, n | eq) = q/(p + q) and π NR = P(NR, n | eq) = p/(p + q). The complementary probabilities to be in the non-reactive state are given by P(NR, n | NR) = π NR + π R ∆ n , In case of symmetric internal dynamics, q = p, Eqs. (1) and (2) simplify to where ∆ = 1 − 2p and π R = π NR = 1 2 .

The Renewal Approach
We now set out to find the statistics of the discrete random reaction time N(x 0 ), which is defined as the number of steps it takes for the particle to react with a target that is placed at the origin. This happens when the particle reaches the origin reactive for the first time. Here, we let r 0 denote the particle's initial position, and ω 0 its initial internal state, which we jointly denote by x 0 = (r 0 , ω 0 ). Setting 0 NR ≡ (0, NR), we consider first N(0 NR ): the reaction time of a particle that starts at the origin, albeit in the non-reactive state. We observe that N(0 NR ) can be thought of as a gated first-return time to the origin. Starting at the origin, the particle can leave and return multiple times, but the overall reaction ends only when the particle arrives at the origin in the reactive state. We can thus write the following renewal equation where N i is the number of steps the particle takes to return to the origin for i-th time, and I i = 0, if the particle is reactive at the i-th return, 1, otherwise, (5) are indicator random variables. Since the walk is Markovian and time-homogeneous, return processes are independent of each other and statistically identical. Thus, {N 1 , N 2 , ...} are independent and identically distributed (IID) copies of a generic return-time which we will henceforth denote N FR (where "FR" stand for First-Return). Similarly, {I 1 , I 2 , ...} are IID copies of a generic indicator, which we will henceforth denote I FR . To see that the indicators are IID, recall that the internal dynamics are also taken to be Markovian, so that the future internal state depends solely on the current one. Furthermore, note that in the beginning of each return process the overall state of the system is the same: the particle is at the origin in the nonreactive state (otherwise, reaction would have occurred). Indeed, this is exactly the renewal property that allows for the solution presented below.

Distribution of the Reaction Time
In principle, Eq. (4) allows us to compute the distribution of N(0 NR ) directly. For example, the probability that N(0 NR ) = 4 can be found by summing over all possible combinations with this reaction time: N 1 = 4, I 1 = 0 being the first; and N 1 = 2, I 1 = 1 followed by N 2 = 2, I 2 = 0 being the second. However, this straightforward approach complicates rather quickly, yielding cumbersome expres-sions. Instead, we use a trick of the trade and compute the Z-transform, a.k.a the generating function, of N(0 NR ): By using the law of iterated expectations: For a given value of N 1 , the inner expectation in Eq. (7) reads where we have used the fact that I 1 = 0 with probability P(R, n | NR) and I 1 = 1 with probability P(NR, n | NR). Plugging this result back into Eq. (7), we obtaiñ We now observe that due to statistical identity of the return processes z N 2 +I 2 [...] = z N(0 NR ) =Ñ(0 NR , z). Then, by plugging the relations in Eqs. (1) and (2) into Eq. (9) and rearranging we get where K eq = p/q andÑ FR (z) is the Z-transform of N FR , which was defined below Eq. (5) as the time it takes the particle to return to the origin. This is the first main result of this manuscript, as it shows that the gated reaction time when starting at the origin at the non-reactive state can be expressed in terms of the corresponding ungated first-return time. Thus, via Eq. (10), the solution of a gated problem is reduced to that of the much simpler ungated problem. We stress that this result is general and holds for any gated reaction in discrete time and space. In the case of symmetric internal dynamics, K eq = 1, Eq. (10) simplifies tõ where ∆ = 1 − 2p. There is an interesting case in which Eq. (11) displays a striking symmetry under the transformation p → 1 − p, which is here equivalent to ∆ → −∆.
Consider a situation where return to the origin can only be made in an even number of steps, as happens for example in a simple random walk in 1D. In this caseÑ FR (z) is an even function since all terms with odd powers of z vanish in the Z-transform. We thus haveÑ FR (∆z) =Ñ FR (−∆z), which means thatÑ(0 NR , z) is itself invariant under the transformation p → 1 − p. In section IV, we return to this symmetry and its consequences when we treat the problem of a 1D random walk with a gated target. Now that we have an expression forÑ(0 NR , z), we can generalize to an arbitrary initial condition x 0 = (r 0 , ω 0 ), where we recall that r 0 denotes the particle's initial position, and ω 0 its initial internal state. To compute the reaction time, we observe that a particle which start at r 0 must first arrive to the origin. Letting N FP (r 0 ) denote the firstpassage time from r 0 to the origin, we now consider what happens next. When arriving at the origin there are two options: i) The particle is in the reactive state and a reaction takes place immediately; ii) The particle is the non-reactive state and the reaction does not take place. The second scenario brings us back to the situation described and solved above: an additional time N(0 NR ) is required for the reaction to complete. The total reaction time is thus where I FP is defined as in Eq. (5), but for first-passage rather than return. We proceed as before, Z-transforming Eq. (12) we ob-tainÑ and by plugging the relevant expressions in Eqs. (1) and (2) into Eq. (13) we get: whereÑ FP (r 0 , z) andÑ FP (r 0 , ∆z) are the Z-transforms of N FP (r 0 ) evaluated at z and ∆z respectively,Ñ(0 NR , z) was defined in Eq. (10), and where Equation (14) is the second main result of this manuscript. It shows that the gated reaction time can always be expressed in terms of the corresponding, and much simpler, ungated first-return and passage times. Note that for an equilibrium initial condition of the internal state, ω 0 = eq, the result simplifies considerably as the second row of Eq. (14) vanishes. Also, when the starting position r 0 is far away from the origin, the internal state equilibrates before the particle arrives there and all information on the internal initial condition is lost. Mathematically, this can be seen by observing that N FP (r 0 ) is then typically very large, makingÑ FP (r 0 , ∆z) = (∆z) N FP (r 0 ) negligible with respect toÑ FP (r 0 , z) = z N FP (r 0 ) . Thus, this case if effectively equivalent to that of the equilibrium initial condition.

Mean and Variance
The Z-transform is a moment generating function, so the moments of N(0 NR ) can be calculated directly from Eq. (10) by taking derivatives. 20 Nonetheless, we think the following independent calculation of the mean of N(0 NR ) is instructive. To find N(0 NR ) , we take the mean of both sides of Eq. (4) Using the independence of the random variables at hand we get Now recalling that the return times are IID, we have N i = N FR and I i = I FR , and thus Observe that the probability that the particle returns to the origin in the reactive state is given by P(R, N FR | NR) = 1 − P(NR, N FR | NR) . Thus, on average, the particle returns to the origin P(R, N FR | NR) −1 times, with each return taking N FR time units on average, before a reaction occurs. Recalling Eq. (1), we have P(R, Plugging this result into Eq. (18) and rearranging we conclude that Once again, note that this result is completely general.
In the same manner one can average Eq. (12) to get Noting that I FP = P(NR, N FP (r 0 ) | ω 0 ) , we can plug in the relevant term from Eqs. (1) and (2) for ω 0 ∈ {R, NR, eq} to calculate the corresponding I FP and plug it into Eq. (20). This gives where I ω 0 was defined in Eq. (15), and whereÑ FP (r 0 , ∆) = Here as well, if the particle starts far enough such that the internal state equilibrates before the particle arrives at the origin, the Z-transform is negligible and the mean reaction time in Eq. (21) becomes independent of the initial internal state (Clearly ∆ N FP (r 0 ) is then typically very small, as |∆| < 1 for all cases but the redundant cases of p = q = 0 or p = q = 1). The result is then equivalent to that obtained in the case of ω 0 = eq, and is very intuitive: The first arrival to the origin occurs after N FP (r 0 ) on average. With probability π R the first arrival is fertile, so it is also the last one. With the complementary probability, π NR , the first arrival is infertile, and the reaction continues for an additional N(0 NR ) steps on average. As mentioned in the beginning of this section, we could have reached Eq. (19) by using the fact that the Z-transform in Eq. (10) is in fact a moment generating function. For the mean one employs , which reproduces Eq. (10) with little algebra. For the second moment, we have and a result for Var(N(x 0 )) can be obtained in a similar way.

When the Mean Diverges
When deriving Eq. (19) we implicitly assumed that N FR is finite. The expression is of course meaningless if N FR diverges as in this case N(0 NR ) must also diverge. This is easy to see from Eq. (4) which implies that the gated reaction time N(0 NR ) is always larger or equal to the return time N FR . Nonetheless, even when the mean diverges, Eq. (10) which gives the Z-transform of N(0 NR ) is still valid and of use. This is not to say that the inverse transformation is a simple task, or that the distribution can always be obtained in closed form. Rather, we hereby focus on the long-time asymptotics, and show that when the underlying ungated process is controlled by a heavy power-law tail, this tail is inherited by the corresponding gated process. More precisely, we show that the power law remains the same and that the asymptotics differ only in the corresponding prefactor, which is determined exactly. Consider the ungated process, and let f 0 (n) be the PMF of the random variable N FR , i.e., f 0 (n) is the probability that the first return to the origin occurs exactly after n steps. The survival is defined to be S(n) = ∑ ∞ n+1 f 0 (n), namely the probability that the particle did not return to the origin by step n. The following relation between the Z-transforms S(z) = ∑ ∞ n=0 S(n)z n andÑ FR (z) = ∑ ∞ n=0 f 0 (n)z n holds 37 The derivation of this relation can found in Appendix C of Ref. 37.
Let us now assume that f 0 (n) is monotonic (at least asymptotically) with a heavy power-law tail such that for n 1 we have with 1 < γ < 2; and note that in this case N FR diverges. The asymptotics of the survival function is then given by S(n) C γ−1 n 1−γ . By applying the Tauberian theorem, 20 we To emphasize, we have found that if the long-time asymptotics of the first return time is given by Eq. (24), then its Z-transform is given by Eq. (25).
Plugging the result of Eq. (25) into Eq. (10), and taking the limit z → 1, we obtain (after some algebra) Equation (26) is of the same form of Eq. (25), up to a different pre-factor. Thus, their inversions are also the same, up to the same pre-factor: where f 0,NR (n) is the PMF of the gated reaction time N(0 NR ). We have thus proved that the asymptotic power law of the ungated problem is inherited by its gated counterpart. The pre-factor is changed, however, by a factor of π −1 R 1−Ñ FR (∆) as can be seen by comparing Eqs. (24) and (27). Note that this is the same factor appearing in Eq. (19). There is one last subtle point to note here. In Eq. (24) we have assumed that f 0 (n) is asymptotically monotonic. In reality, discrete time random walks on networks often possess non-monotonic first-return PMFs. For example, in the simple 1D random walk return on odd number of steps has zero probability. However, the even sequence { f 0 (2n)} is indeed monotonic. In this case, Eq. (24) should be understood as an average of subsequent even and odd steps. Then, f 0 (n) is zero for odd n and two times the quantity of Eq. (24) for even n. Alternatively, one can solve directly for the sequence { f 0 (2n)}, and obtain the same factor of 2. In more complicated networks, one should be careful and apply similar considerations if needed.

Transient Power-Law Behaviour in High Crypticity
Let us continue with the exact same scenario of the heavytailed f 0 (n) given in Eq. (24). But now, let us also assume high crypticity, i.e., K eq = p/q 1. To study the transition to the long-time asymptotics under the high-cripticity assumption, we take z close to 1 in Eq. (10), but keep K eq large enough such that K eq 1 −Ñ FR (z) 1 holds. Using Applying the Tauberian theorem gives Equation (29) means that under high crypticity there is a transient regime, possibly very long, which is governed by a ∼ n γ−2 power law, before the terminal ∼ n −γ asymptotics enters. It is interesting to note that by using Euler's reflection formula, Eq. (29) can be re-written as where we have denoted x := γ − 1, such that 0 < x < 1. We can thus easily see that the pre-factor is maximized for the case x = 1/2 (which corresponds to γ = 3/2), and that it decreases towards zero for both larger and smaller values of x, but in an asymmetric manner, as the sine function is multiplied by x. Finally, note that by employing the same technique, one can obtain the analogous result for the continuous-time case, starting from Eq. 7 of Ref. 34.

III. EXAMPLE: GATED REACTION WITH UNIDIRECTIONAL MOTION ON A RING
To illustrate the framework developed above, consider the following problem: A particle is bound to a ring lattice of N sites. The particle's motion is unidirectional, namely at every time step, the particle takes one step clockwise. In addition, the particle switches between a reactive (red) and non-reactive (blue) states as described in Fig. 3. Starting the particle at the origin, in the non-reactive state, we are interested in the gated reaction time. Namely, the time it takes the particle to return to the origin in the reactive state.
Recall that in the previous section we showed that the statistics of the gated reaction time N(0 NR ) can be expressed in terms of the corresponding ungated reaction time N FR , i.e., the first return time to the origin. Specifically, in the case considered above, calculation of the ungated reaction time is extremely simple. Since the particle's motion is unidirectional, it will return to the origin after taking exactly N steps. In other words, we have N FR = N and Var(N FR ) = 0, which meansÑ FR (∆) = ∆ N . The mean of the gated reaction time, which is less trivial, now follows directly from Eq. (19) FIG. 3. An illustration of a gated reaction on a ring. A particle transitions between a reactive state (red) and a non-reactive state (blue) according to the Markov chain illustrated inside the square box. In addition, at every time step, the particle jumps to its right neighbouring site. The particle starts on the target in the nonreactive state. A reaction occurs when the particle first returns to the target in the reactive state.
which for the symmetric case, p = q, boils down to A few interesting features can be deduced from Eq. (31). For −1 < ∆ < 1, we have N(0 NR ) → π −1 R N as N → ∞. To understand this, observe that when N is large enough the internal state has enough time to equilibrate within a single revolution of the ring. Thus, the probability to find the particle in the reactive state when it returns to the origin is the equilibrium probability π R . For example, when p = q we have π R = 1 2 and so N(0 NR ) → 2N. Thus, on average, the particle misses the target in half of its returns, yielding a mean reaction time that is twice that of the ungated problem. Note that this limit is independent on the value of ∆, and that it can give a fair approximation for N(0 NR ) even for moderate values of N. This is illustrated in Fig. 4, where we compare numerical simulations with theory for the symmetric, p = q, case. Observe that N(0 NR ) 2N, except for extreme values of p, where this approximation is expected to break.
The mean gated reaction time displays clear parity effects with regard to the size of the ring. This happens because the internal gating dynamics can be in, or out of, phase with the molecular encounters of the particle with the target, thus leading to resonance and anti-resonance effects. For example, in the symmetric case illustrated in Fig.  4, two distinct behaviours arise in the limit p → 1: i) If N is even the mean reaction time diverges. Indeed, for p = 1 the particle changes its internal state with every step, and  Fig. 3. Here, we consider symmetric internal dynamics (p = q) and various lattice sizes N = 4, 5, 20 and 21. Solid lines represent the theory coming from Eq. (32), and full circles come from numeric simulations. Observe that N(0 NR ) 2N, except for extreme values of p, where this approximation is expected to break. As p → 0, the probability to leave the initial non-reactive state vanishes and the mean reaction time diverges. In the other limit, p → 1, clear parity effects arise: for even N the mean diverges, while for odd N the mean is approximately N itself.
given that it started non-reactive it is sure to return to the origin non-reactive. ii) Contrary, when N is odd, the mean reaction time approaches N because the particle is almost sure to transition to the reactive state as it steps back into the origin at the end of a revolution. The same effect is apparent in Fig. 5a and 5b, where either q or p is set constant to a high value of 0.9 and the other parameter is swept across the unit interval. As this parameter approaches 1, we reach a scenario in which both p and q are large and similar parity effects are observed.
An interesting scenario is that of Fig. 5c, where q is set to the low value of 0.1. If p is also low, once the particle becomes reactive it will stay that way for a long time. We thus observe a mean reaction time which corresponds to the number of revolutions needed for the particle to become reactive for the first time. However, as p increases it becomes much more likely that the particle reverts back to the non-reactive state before completing a revolution. As a result, the mean reaction time is greatly prolonged. In Fig. 5a we set q to high value of 0.9 and the effects are much less pronounced: When p is low, the mean reaction time tends to the size of the ring, as it is very likely that the particle will become reactive within the first revolution and stay that way. As p is increased, we again have the same effect of prolonged reaction times, but to a lesser extent (note differences in slopes compared to Fig. 5c).
Lastly, in Fig. 5d we set p = 0.1 and vary q. When q → 0 the probability to leave the initial non-reactive state vanishes and the mean reaction time diverges. When q → 1 the particle transitions from the non-reactive state to the reactive state very fast relative to opposite transition, and it is very likely to arrive reactive at the end of the first revolution.
We can also obtain the PMF of the reaction time when starting on the target in the non-reactive state. By plugging N FR (z) = z N in Eq. (10) we obtaiñ By denoting ζ = z N and recalling Eq. (1): P(R, n | NR) = π R (1 − ∆ n ) we can rewrite Eq. (33) as which is a Z-transform of a geometric distribution evaluated at ζ . Here the success probability is P(R, N | NR), as each geometric trial is equivalent to a full revolution of N steps. To understand this result we observe that the particle returns to the target every N steps. The probability of the particle to be reactive on return is exactly P(R, N | NR).
If the particle is reactive on return then the walk is over. However if it is non-reactive, the process is renewed and again the probability to be reactive in the next revolution is P(R, N | NR). This is indeed a geometric distribution. In fact, because the N FR is deterministic the gated problem is effectively reduced to that of a radiating boundary condition, i.e., following each revolution there is a constant probability of reacting. We stress that this reduction is not due to equilibration of the internal state, but rather due to the deterministic return time. This, of course, makes the gated problem considerably easier to solve, but our formalism also allows us to treat cases where the return time fluctuates. For such cases, the reduction above is impossible (unless internal state equilibrium is certain to be reached between any two consecutive returns to the target). In the next section, we consider a problem in which not only that the return time fluctuates -it varies so greatly that the mean return time diverges.

IV. EXAMPLE: SYMMETRIC RANDOM-WALK ON A SEMI-INFINITE INTERVAL WITH A GATED BOUNDARY
Consider a random walk on a semi-infinite onedimensional lattice with a two-state gated boundary as depicted in Fig. 6. Assuming the particle starts at an initial location x 0 , we are interested in the first-reaction time PMF, namely the probability distribution of its first-return (or passage) to the origin while in the reactive state.
The conventional way in which one would approach such a problem is by writing and solving the Master equation for C i (x, n), the probability that the boundary is at state i ∈ {R, NR}, and the particle is at position x, after n steps. The master equation for the bulk lattice sites reads FIG. 6. Discrete-time symmetric random-walk on a semi-infinite interval with a gated boundary. At every time step the particle makes a jump left or right with equal probabilities. In addition, the boundary evolves, changing from being absorbing to reflecting (and vice versa), according to the transition probabilities in the figure.
while the equations for the boundary (x = 0) and near boundary (x = 1) sites are given by These equations are supplemented by an initial condition. For example, if we assume the particle starts at the boundary (x 0 = 0) in the non-reactive state, we have C R (x, 0) = 0 and C NR (x, 0) = δ x,0 .
Although doable, solving the above set of equations brute force is a laborious task. To demonstrate this, we present a solution for the symmetric case, p = q, in Appendix B. In the following, we instead note that the problem of a gated boundary is completely equivalent to the problem of gated particle switching between a reactive state and non-reactive state. We can thus evoke the results derived in Sec. II, and calculate the generating function of the first-reaction time by a simple "plug and play" method.

Applying the Renewal Approach
To calculate the gated reaction time using Eq. (10), we require the Z-transform of the ungated first return-time N FR . This is known to be given by 20 where f 0 (n) = 1 2 n (n−1) n n/2 , Even n, 0, Odd n, (38) is the probability that a symmetric random walker which started at the origin returns to the origin for the first time at the n-th step. Substituting Eq. (37) into Eq. (10), we immediately obtain the Z-transform of the gated reaction timẽ In appendix C, we show how Eq. (39) can be inverted to find f 0,NR (n), the probability that a reaction occurs exactly after n steps where the walker starts on the boundary in the non-reactive state. In the symmetric case, K eq = 1, we find where h(n) = and Odd n. (42) Exact formulas for the case K eq = 1 are given in Appendix C.
Equation (40) gives the full distribution of the gated reaction time, but since it is given in the form of a convolution it is hard to extract insight from it directly and without further analysis (one might say it is convoluted). Of main interest is the long time asymptotics, which can instead be readily obtained by utilizing the fact that the gated asymptotics inherits the ungated asymptotics.
For the ungated problem, by use of the Stirling approximation in Eq. (38), an asymptotic behaviour f 0 (n) 2 π n −3/2 is obtained for the even step sequence, while the probability of return on an odd step is zero. Averaging subsequent even and odd steps we get an average asymptotic behaviour of f 0 (n) ∼ 1 √ 2π n −3/2 . 20 Note that the mean of the first return-time N FR diverges, and that the same is true for all its higher order moments. To obtain the gated problem asymptotics, all we need to do is identify Realizations of the gated reaction from Fig. 6 with symmetric internal dynamics (p = q), for p = 0, 0.1, 0.9 and 1 (a, b, c and d respectively). Blue (red) circles symbolize the walker being in a non-reactive (reactive) state. Gold circles symbolize reactions. Here, the particle starts at x 0 = 0 in the non-reactive state. It can be observed that for p = 0 and p = 1 a reaction cannot occur. and γ = 3/2 in Eq. (24) and to substitute them, along with N FR (∆) = 1 − √ 1 − ∆ 2 , into Eq. (27). We then get, without any further calculation, that the average asymptotic behaviour for the gated problem is where we have defined As expected Eq. (43) asserts that the mean of the gated reaction time diverges along with all its higher moments.

The Case of Symmetric Internal Dynamics
In Fig. 7, we provide some realizations of the gated reaction depicted in Fig. 6. We focus on the symmetric case p = q. It can be seen that for p = 0 and p = 1 a reaction will never occur, albeit for completely different reasons. In the former case, the probability to transition to the reactive state is zero, and since the walker starts in the non-reactive state it simply stays in it. In the latter case, the walker is sure to switch internal states with every step it takes, such that it is in the reactive state for odd number of steps and in the non-reactive state for even number of steps. Furthermore, it is generally true that the walker can return to the origin only after taking an even number of steps. Thus the walker will never arrive there in the reactive state. We thus conclude that for p ∈ {0, 1} we have f 0,NR (n) = 0, and equivalently that the survival probability is S(n) = 1, for all n.
To better understand what happens for p ∈ (0, 1) we set p = q, in Eq. (43) to obtain (N.B. averaged subsequent even and odd steps) which corresponds to a survival probability of The asymptotics of Eq. (45) is corroborated in Fig. 8 for even n. To do so we multiply the averaged result in Eq. Here, the scenario considered is identical to that in Fig. 7, and two values of p = q are considered. The color coded open circles are exact analytical results coming from Eq. (40), and the X's come from simulations (10 6 walkers were simulated). Lines are the respective asymptotics of Eq. (45), but with an added factor of 2 which takes care of parity (see main text). and the survival probabilities. Indeed, in Sec. II we have derived a general expression forÑ(0 NR , z) for the case of symmetric internal dynamics, given by Eq. (11). In a short discussion below that equation, we have shown that when return to the origin is possible only on an even number of steps, the reaction time is invariant under the transformation p → 1 − p. The case under consideration here fulfills this criteria, and one can easily verify that this symmetry holds for all n. This is illustrated in Fig. 9a, where we calculated the reaction time probability after n = 2, 20, 50 and 100 steps for different values of p. Interestingly, the reaction time probability function obtains two maxima at optimal transition probabilities p * and 1 − p * which depend on n. As we explain below, this feature arises due to a certain resonance between the internal gating dynamics and the spatial dynamics which governs molecular encounters of the particle with the target at the origin.
As n becomes large, p * tends to zero and the existence of its corresponding maximum becomes more pronounced. Note that the curvature is very different to the left and right of the optimal transition probability p * . To the left there is a rapid drop in reaction probability. To the right, the decrease in reaction probability is quite moderate. Of course, a mirror image is obtained for the maximum point at 1 − p * , thus creating a "safe zone" around p = 0.5. While transition probabilities in this zone are not optimal, they still provide relatively high values for the reaction probability regardless of the specific value of n. This is interesting as it highlights an inherent trade-off between point-optimization and robustness in our problem. If one ever finds applications of this model in biological systems, it would be interesting to check whether evolution tuned the system to work with p * where small deviations from the optimum could decimate the probability to react, or rather in the safe zone which is fairly robust to changes in parameters.
We find that p * is inversely proportional to n. The exact proportionality factor can easily be determined by numeric maximization of Eq. (40), but let us give instead the fol-lowing heuristic estimation. To increase the likelihood of a reaction occurring, we want to chose a transition probability p that maximizes the probability of the particle to be reactive upon return to the origin. Focusing on situations where a return occurs exactly after n steps, it makes sense to try and time things such that this return falls in the middle of a reactive period. As the transition probability is p, the average length of a reactive period is 1/p; and one would want to maximize this duration to ensure that the reactive period covers the return time despite stochastic fluctuations. Naively, this could be done by taking p to zero. However, recall that the particle starts in the non-reactive state and that transitioning to the reactive state takes 1/q units of time on average. As we have assumed p = q, it is clear that p = 3/2n is the smallest transition probability for which the return on average occurs in the middle of a reactive period (Fig. 9b inset). In Fig. 9b, we show that this intuitive argument approximates p * to a surprising accuracy, leaving just a mere ∼ 3% systemic relative error for large n.

Additional Interesting Cases
So far we have only discussed the intriguing symmetric case of p = q. This case eloquently reveals new features that are not observed in the analogous continuoustime problem, and that are in fact due to the discretization of time. However, as mentioned above, we have also solved the problem for any choice of p and q, and we refer the reader to Appendix C for the inversion of Eq. (39). In previous continuous-time works it was shown that for a certain range of transition rates an interesting transient behaviour can be observed. 26,34 In this so called "cryptic regime" the transition rate from the non-reactive state to the reactive state is low with respect to the rate of the reversed transition. Markedly, there is a prolonged transient regime governed by a ∼ t −1/2 power law before the known ∼ t −3/2 asymptotics kicks in. The analogous ∼ n −1/2 cryptic regime can also be observed here by taking p q.
Indeed, to obtain the gated problem transient behaviour under high cripticity, all we need to do is identify C = 1 √ 2π and γ = 3/2 in Eq. (24) and to substitute them, along with where we understand this result as an average of subsequent even and odd steps. Since f 0,NR (n) = 0 for odd n, the result for the even sequence is two times that given in Eq. (47). Finally, note that we have only considered here the case in which the particle is initially on the target in the nonreactive state. However, plugging the result in Eq. (39) into Eq. (14) one can solve for any initial condition. As in the continuous-time analogue, 34 a bi-modal reaction time distribution can be observed when the particle starts away from the target in the reactive state, and for the right choice  45), and X's come from simulations (10 6 walkers were simulated for each case). Note the symmetry about p = 0.5 and the two limiting cases of p = 0 and p = 1, in which f 0,NR (n) = 0 for all n. The reaction time probability function obtains two maxima at optimal transition probabilities p * and 1 − p * which depend on n. (b) The plot shows that p * 3/2n, which for large n is accurate to within ∼ 3%. The inset illustrates why this approximation works so well. In case the particle returns to the origin after n steps, taking p = 3/2n would (on average) place the return time in the middle of the particle's first reactive period.
of p and q. We trace this effect to the existence of two populations of particles: those which reached the origin and reacted without ever switching to the non-reactive state, and those which switched to the non-reactive state prior to reaching. As the latter are blocked from reacting for 1/q steps on average, two distinct peaks are formed when this time period is taken to be much larger than the median return time to the origin.

General Perspective on Gated 1D Random Walks and Reactions
To put the example solved above in its right context, we offer a very brief review of previous works on gated 1D random walks on the semi-infinite line. Specifically, while a lot of work has been dedicated to the classical random walk in discrete space and time, it seems that the gated version of the corresponding first-passage and return problems was first solved here. That said, solutions to the gated problem in continuous time and space and in continuous time and discrete space have been presented before, and in the following we will review these cases for comparison.
Continuous time and space -In his work on coagulation, Smoluchowski's was the first to build a model where diffusive transport is the rate limiting step of the reaction kinetics. To find this so called diffusion-controlled reaction rate, Smoluchowski solved for the flux of particles, initially uniformly distributed in an infinite pool of particles, into a 3D spherical symmetric sink fixed to the origin. 38 Many great reviews have been written on Smoluchowski's model and its generalizations. 31,32,39,40 Although here we consider the first-passage to the boundary of a single-particle diffusing on the semi-infinite line, the treatment of the boundary is essentially the same. The solution can be obtained by solving the diffusion equation with an absorbing boundary condition c(0,t) = 0, where the first-passage distribution through the origin is given by the flux to the origin f (0,t) = D ∂ c(x,t) ∂ x | x=0 . The equation is supplemented with the delta initial condition c(x, 0) = δ (x 0 ). Note that here x 0 = 0 is the trivial case in which the particle is immediately absorbed. Solving for x 0 > 0, one gets a heavy-tailed distribution f abs (0,t) = x 0 √ 4πDt 3 e −x 2 0 /4Dt , with an asymptotic behaviour of ∼ x 0 t −3/2 in the long-time limit. 19 In their seminal paper on diffusion-controlled reaction rates, Collins and Kimball extented Smoluchowski's model to allow for the case in which the target is reactive only in a fraction of the visits, leading naturally to a radiating (partially absorbing) boundary condition D ∂ c(x,t) ∂ x | x=0 = κc(0,t). 41 When κ = 0 there is zero flux through the origin, i.e., a reflecting boundary. Similarly, if κ is taken to be very large, the absorbing boundary condition is restored. The corresponding single-particle model was solved by Sano and Tachiya for several cases of practical interest. 42 Surprisingly enough, only recently Pal, Castillo and Kundu conducted a comprehensive study on diffusion in finite and semi-infinite 1D intervals, where analytical expressions for the probability density of the particle displacement and its first-passage distribution were computed. 43 A subtle point to notice is that gating is implicit in the radiating boundary condition. Indeed, consider a gate for which the internal dynamics is much faster than the time between consecutive particle-target collisions. In this case, the time it takes for the internal gating state to reach equilibrium can be neglected, and the probability of the system to be in a reactive state when a collision occurs is always the equilibrium fractional population π R . Thus, the partially-absorbing case can be thought of as a special case of the gated problem.
Recently, the gated version of diffusion on the 1D infinite line was solved for the survival probability. 26 No-tably, it was shown that when the transition rate from the non-reactive state to the reactive state is much lower with respect to reversed transition, there is an intermediate regime governed by a power law ∼ t −1/2 , before the known ∼ t −3/2 asymptotic kicks in. In Sec. II of work, when exploring transient behaviour in high crypticity, we showed that this result is not limited to 1D, and extends to general networks via Eq. (29).
Continuous time and discrete space -Here the underlying process can be formulated using the framework of the CTRW. 20 In a similar manner of invoking the Tauberian theorem, one can show that the probability density of the first-passage time to the origin follows f (x 0 ,t) ∼ νt −3/2 , where ν is some pre-exponential that depends on the initial location and the hopping rate of the random-walker. The gated counterpart of this problem was solved. 12,13,34 Curiously enough, it was shown that the ungated problem and its gated counterpart share the same power law in the asymptotic behaviour, while differing only in the pre-exponential factor (the gated pre-exponential is dependent also on the internal dynamics). Here and in a previous work 34 , we have proved that this is a universal feature of CTRW and discrete time gating, which extends beyond 1D problems and onto general networks in arbitrary dimensions.

V. SUMMARY
Stochastic gating, i.e., the random switching of molecules between reactive and non-reactive states, poses a barrier to the understanding and proper description of reaction kinetics. To overcome this, we presented a unified approach to gated reactions in discrete time and space. We showed that one can always express the distribution of the gated reaction time in terms of ungated first-passage and return times. Thus, instead of solving directly for the gated reaction time, which can be extremely difficult even for relatively straightforward scenarios, one can instead apply an indirect, but much simpler, solution algorithm. Given a network of interest, and the time-independent laws which govern stochastic motion on this network, act as follows to obtain the distribution of the gated reaction time: • Obtain the distribution of the ungated first-passage time N FP (r 0 ), i.e., the number of steps a particle takes to go from its starting position r 0 to a target whose position is set to the origin (by convention and without loss of generality).
• Obtain the distribution of the ungated first-return time to the origin N FR , i.e., the number of steps that a particle which starts at the origin takes to get back to the origin.
• Compute the generating functions of the ungated first-passage and return times:Ñ FP (r 0 , z) = z N FP (r 0 ) andÑ FR (z) = z N FR correspondingly. Note, that in many cases it is actually easier to obtain these functions directly, thus bypassing computation of the first-passage and return distributions. One can then skip the first two stages.
• SubstituteÑ FR (z) into Eq. (10) to obtain the generating function of the gated reaction time N(0 NR ), i.e., the total time it takes the particle to react given that it started from the origin in the non-reactive state.
• SubstituteÑ FP (r 0 , z),Ñ FR (z), and Eq. (10) into Eq. (14) to obtain the generating function of the gated reaction time N(x 0 ), i.e., the total number of steps it takes the particle to react given that it started from an arbitrary initial condition x 0 = (r 0 , ω 0 ), where r 0 stands for the particle's initial position, and ω 0 for its initial internal state which can be reactive or nonreactive.
As we have shown, the mean, variance, asymptotics and additional properties of the gated reaction time can all be extracted from the generating functions in Eqs. (10) and (14). We stress that the gated reaction times in Eqs. (10) and (14) depend on the probabilities p and q, which govern stochastic transitions between the reactive state and the non-reactive state as depicted in Fig. 2. This dependence is manifested not only via the internal equilibrium constant K eq = p/q and occupancies π R = q/(p + q) and π NR = p/(p + q), but also via ∆ = 1 − p − q which governs the rate of internal-state equilibration by Eqs. (1) and (2). From a physical stand-point, this can be traced back to the fact that the probability to react upon a particle-target encounter is not constant, but rather time dependent. Indeed, replacing the probability to react with the equilibrium probability to be reactive is an approximation which fails to take into account correlations between consecutive particle-target encounters. Hence, the need for the fully fledged theory of gated reactions that was developed here and in previous work. 34 The implementation of the solution algorithm presented above clearly hinges upon prior knowledge or computation of the ungated first-passage and return times. Luckily, these are known analytically in cases of particular interest, [19][20][21] and newly made discoveries add to this knowledge routinely. 44 Relating gated reaction times to their ungated counterparts, the framework developed herein extends our knowledge on the long studied topic of first-passage. Importantly, all the results obtained apply beyond the context of chemical reactions and could e.g., be used to analyze analogous scenarios which arise when considering search of stochastically gated targets 27,28 and to the problem of first-detection with intermittent sensing. 17

ACKNOWLEDGMENTS
The authors wish to thank Ofek Lauber Bonomo for commenting on early versions of this manuscript. The authors wish to thank an anonymous reviewer for suggesting a calculation that led to the addition of a subsection dedicated to the transient power-law behaviour in the limit of high crypticity. S.R. acknowledges support from the Israel Science Foundation (grant No. 394/19).

DATA AVAILABILITY
The data that supports the findings of this study are available within the Communication and its appendixes.