Consider a two-state Markov process in continuous time, with states labelled $A$ and $B$. The transition rates for going from state $A$ to $B$, and state $B$ to $A$ are $\alpha$ and $\beta$ respectively. We are interested in the quantity $p\_t(A,x,t\_A|A)$, which denotes the probability that, at time $t$, the Markov process is in state $A$, has made a total of $x$ jumps, and has spent time equal to $t\_A$ in state $A$, given that it started from state $A$.


I was thinking of two approaches (and both are likely to be equivalent). But I seem to be running into hurdles in both of them, and would be grateful for some help.


My first approach was to write a set of coupled recurrence relations in the following way:
\begin{align}
p\_t(A,x,t\_A|A) &= \int\_0^t e^{-\alpha t'}\cdot \alpha \cdot p\_{t-t'}(A,x-1,t\_A-t'|B)\cdot dt'\\
p\_t(A,x,t\_A|B) &= \int\_0^t e^{-\beta t'}\cdot \beta \cdot p\_{t-t'}(A,x-1,t\_A|A)\cdot dt'
\end{align}
The basic idea behind the above equations is that the first jump takes place at time $t'$, and thus, the rest of the $x-1$ jumps have to be made in the remaining $t-t'$ amount of time. Similarly, depending on what the initial state was, the time needed to be spent in state $A$ in the remaining $t-t'$ time is stated in the argument (e.g. if the first $t'$ amount of time was spent in state $A$, then in the remaining amount of time, only $t\_A-t'$ amount of time needs to be spent there). There is a minor issue here that the above equation does not necessarily restrict the possibility of $t'>t\_A$, which is unphysical. But that can be taken care of by changing the upper limit of the integral in the first equation to $t\_A$.


Naively, one would expect that taking a Laplace transform of the two equations with respect to $t$ should simplify matters a lot. For the second equation, it indeed does, as the equation is a simple convolution in $t$. However, the first is not **(please correct me if I am wrong)** and thus, naive Laplace transform with respect to $t$ might not be helpful. Is there any other approach which makes the problem easier?


My second approach was to derive the differential equation satisfied by the quantity $p\_t(A,x,t\_A|A)$, by working in discrete time-steps of $\Delta t$, and finally taking the limit $\Delta t \to 0$:


\begin{align}
p\_{t+\Delta t}(A,x,t\_A|A) = p\_t(A,x,t\_A-\Delta t|A)\cdot (1-\alpha \Delta t) + p\_t(B,x-1,t\_A-\Delta t|A)\cdot \beta \Delta t 
\end{align}
which upon rearranging gives us
\begin{align}
\frac{p\_{t+\Delta t}(A,x,t\_A|A) - p\_{t}(A,x,t\_A- \Delta t|A)}{\Delta t} = -\alpha\cdot p\_t(A,x,t\_A-\Delta t|A) + \beta \cdot p\_t(B,x-1,t\_A - \Delta t|A).
\end{align}
In the limit of $\Delta t \to 0$, we get:
$$\frac{\partial{p\_{t}(A,x,t\_A|A)}}{\partial{t}}+\frac{\partial{p\_{t}(A,x,t\_A|A)}}{\partial{t\_A}} = -\alpha\cdot p\_t(A,x,t\_A|A) + \beta \cdot p\_t(B,x-1,t\_A|A). $$


Similarly, one could write equations for $p\_t(B,x,t\_A|A)$. Here (again naively), it seems like one could take a Laplace transform with respect to $t$ and $t\_A$, and define a generating function for $x$ to simplify the problem. However, one thing that scares me is that $t\_A$ cannot take any value. It must always take values less than $t$. Thus, independently taking Laplace transforms with respect to $t$ and $t\_A$ seems shady.


Is there a way to overcome one (or both) of the hurdles?



Occupation times for two-state Markov processes
Without loss of generality, let the final time to be $t=1$ (if it is not, we can make it so by rescaling time as $\alpha'=t\alpha$ and $\beta'=t\alpha$).


Then, consider a single trajectory of the process that starts and ends on state $A$ and makes $x$ jumps ($x$ has to be even). We can represent any such trajectory in terms of the jump times, $$\vec{t}=(t\_{0}=0\le t\_{1}\le\dots\le t\_{x}\le1) \tag{1}$$
The conditional probability of the trajectory is given by the product of the jump probabilities, multiplied by the probability of not leaving state $A$ after the last jump:
$$p(\vec{t}\vert A)=e^{-\alpha(1-t\_{x})}\prod\_{i=0}^{x-1}p\_{i}(t\_{i+1}\vert t\_{i}).\tag{2}$$
We will assume below that $x\ge 2$ (otherwise $t\_A=1$ and $p(A,x,t\_A|A)=e^{-\alpha}$).


Now, if $i$ is even, then the jump at $t\_{i+1}$ is from state $A$ to state $B$ and has probability density $p\_{i}(t\_{i+1}\vert t\_{i})=\alpha e^{-(t\_{i+1}-t\_{i})\alpha}$. Otherwise the jump is from state $B$ to state $A$ and has probability density $p\_{i}(t\_{i+1}\vert t\_{i})=\beta e^{-(t\_{i+1}-t\_{i})\beta}$. Plugging into $(2)$ and simplifying gives
$$p(\vec{t}\vert A)=e^{-[t\_{A}(\vec{t})\alpha+(1-t\_{A}(\vec{t}))\beta]}\alpha^{x/2}\beta^{x/2}\tag{3},$$
where $t\_A(\vec{t})$ indicates the amount of time that trajectory $\vec{t}$ spends in state $A$.


To get your answer, we integrate over the set of all ordered sequences $\vec{t}$ that obey $(1)$ and spend $t\_A$ time in state $A$, which we indicate as $\Omega$. This gives:
\begin{align}P(A,x,t\_{A}\vert A)=\int\_{\Omega}p(\vec{t}\vert A)d\vec{t}=e^{-[t\_{A}\alpha+(1-t\_{A})\beta]}\alpha^{x/2}\beta^{x/2}\int\_{\Omega} d\vec{t}.\tag{4}\end{align}


It remains to calculate the volume of $\Omega$. Let us indicate this set as
$$\Omega=\{t\in\mathbb{R}\_{+}^{x}:0\le t\_{1}\le\dots t\_{x}\le1,\sum\_{i=1}^{x/2}t\_{2i}-t\_{2i-1}=1-t\_{A}\}$$
Note that $\Omega$ has the same volume as the following subset of the unit $x$-simplex:
$$\Omega'=\{g\in\mathbb{R}\_{+}^{x+1}:\sum\_{i=1}^{x+1} g\_{i}=1,\sum\_{i=1}^{x/2}g\_{2i}=1-t\_{A}\},$$
which follows from the simple transformation $g\_{i}=t\_{i}-t\_{i-1}$ for $i=1..x+1$ (where $t\_0=0$ and $t\_{x+1}=1$). Then, by rearranging the odd and even coordinates, it is easy to see that $\Omega'$ is itself a cross product of two scaled unit simplices:
$$\Omega'=\{g\in\mathbb{R}\_{+}^{x/2+1}:\sum\_{i=1}^{x/2+1}g\_{i}=t\_{A}\}\times\{g\in\mathbb{R}\_{+}^{x/2}:\sum\_{i=1}^{x/2} g\_{i}=1-t\_{A}\}$$
The volume of $\Omega'$ is the product of the volumes of these simplices,
$$\mathrm{Vol}(\Omega') =\mathrm{Vol}(\Omega) = \frac{t\_{A}^{x/2}}{(x/2)!}\frac{(1-t\_{A})^{x/2-1}}{(x/2-1)!}$$
Combined with $(4)$ this gives
\begin{align}P(A,x,t\_{A}\vert A)=e^{-[t\_{A}\alpha+(1-t\_{A})\beta]}\alpha^{x/2}\beta^{x/2}\frac{t\_{A}^{x/2}}{(x/2)!}\frac{(1-t\_{A})^{x/2-1}}{(x/2-1)!}.\end{align}


