Recently I was stumped by the calculation of the probability
$$\mathbb{P} \big(\sum\_{i=1}^{m} (A\_i + S\_i) \le L < \sum\_{i=1}^{m+1} (A\_i + S\_i) \big)$$ 
where $A\_i \sim \text{exp}(\lambda), S\_i \sim \text{exp}(\mu), L \sim \text{exp}(\lambda)$ are mutually independent, $\lambda \neq \mu$ are two positive integers, and $m$ is an integer parameter.




---


**My attempt:**


I failed at the very start while calculating the density function of $\sum\_{i=1}^{m} (A\_i + S\_i)$:
$$\sum\_{i=1}^{m} (A\_i + S\_i) = \sum\_{i=1}^{m}{A\_i} + \sum\_{i=1}^{m}{S\_i} = \big( A \sim \Gamma(m, \lambda) \big) + \big( S \sim \Gamma(m, \mu) \big)$$
Considering the two Gamma random variable $A$ and $S$, their convolution is:
$$p\_{A+S}(a) = p\_{A} \ast p\_{S} (a) = \int\_{0}^{a} f\_{A}(a-y) f\_{S}(y) dy \\ = \int\_{0}^{a} \frac{\lambda e^{-\lambda (a-y)} (\lambda (a-y))^{m-1}}{\Gamma(m)} \frac{\mu e^{-\mu y} (\mu y)^{m-1}}{\Gamma(m)} dy \\ = e^{-\lambda a} \frac{\lambda^m \mu^m}{\Gamma(m) \Gamma(m)} \int\_{0}^{a} e^{(\lambda - \mu) y} \large((a-y)y \large)^{m-1} dy$$




---


**And my failure:**


I was not able to go any further with the integral. And you can image what a messy calculation we will run into when we are going to take the second step involving $\sum\_{i=1}^{m} (A\_i + S\_i) \le L$.




---


**My questions:**


Generally, my question is how to make the calculation tractable.


Specifically,



> 
> 1. Has the probability been studied in research papers?  
> 
>  People interested in its background in "alternating renewal process" are referred to the following part of the post.
> 2. What is the density function of $\big( A \sim \Gamma(m, \lambda) \big) + \big( S \sim \Gamma(m, \mu) \big)$ given that $m$ is an integer and $\lambda \neq \mu$ are positive integers?  
> 
>  If there is no nice closed form, can we make some good approximation?  
> 
>  Related post: [at Math.SE (without proper answers yet)](https://math.stackexchange.com/q/803867/51434).
> 3. For the whole calculation, is it feasible to obtain numerical solution using mathematical softwares?  
> 
>  Are there any off-the-shelf libraries for this purpose?
> 
> 
> 




---




---


**For people who want to know the background of the probability in "alternating renewal process":**



> 
> **Background:** Consider an alternating renewal process, in which a system can be in one of two states: on or off. Whenever it is off, it takes a time $A\_i \sim \text{exp}(\lambda)$ before turning on. Whenever it becomes on, it remains on for a time $S\_i \sim \text{exp}(\mu)$. Initially the system is off. A cycle $c\_i$ consists of the $i$th off-state and the $i$th on-state. All $A\_i$ and $S\_i$ are mutually independent and $\lambda \neq \mu$ are two positive integers. 
> 
> 
> **Problem:** Given a time period $L \sim \text{exp}(\lambda)$, what is the probability that exactly $m$ cycles occur in $L$?  
> 
>  Related post: [at MO: its origin; many thanks to @user137846](https://mathoverflow.net/q/163869/28199).
> 
> 
> 



How to calculate $P(\sum_{i=1}^{m}(A_i+S_i)\le L)$ with $A_i,L\sim\text{exp}(\lambda),S_i\sim\text{exp}(\mu)$ and positive integers $\lambda\neq\mu$?
Call the left resp. right hand sum $R\_m$ resp. $R\_{m+1}$. As $L$ is $\exp(\lambda)$ and independent of $(R\_m,R\_{m+1})$ , taking expection with resp. to $L$ first gives
$$\mathbb{P}(R\_m\leq L < R\_{m+1})=\mathbb{E}(e^{-\lambda R\_m}-e^{-\lambda R\_{m+1}})= \left(\dfrac{1}{2}\dfrac{\mu}{\mu+\lambda}\right)^m\left(1-\dfrac{1}{2}\dfrac{\mu}{\mu+\lambda}\right)$$
where we have used that the individual summands of $R\_m$ resp. $R\_{m+1}$ have Laplace-transform
$$\mathbf{E}(e^{-p(S\_i+A\_i)})=\dfrac{\lambda}{\lambda+p}\dfrac{\mu}{\mu+p}$$


