# Expected coin tosses until at least h heads and t tails are obtained

I am also wondering about the same question for any Bernoulli variable. I have got as far as saying for any Bernoulli variable: $$\mathbb{E}[X] = h \sum\limits_{n \geq h + t}^{\infty} {n \choose h} p^h (1-p)^{n-h}+ t \sum\limits_{n \geq h + t}^{\infty} {n \choose t} p^{n-t} (1-p)^t$$ For the case $$p = \frac{1}{2}$$ (A fair coin), we have: $$\mathbb{E}[X] = h \sum\limits_{n \geq h + t}^{\infty} {n \choose h} \frac{1}{2^n} + t \sum\limits_{n \geq h + t}^{\infty} {n \choose t} \frac{1}{2^n}$$ Where $$X$$ is the rv required. I did this by a method analogous to here: Expected value of number of tosses until we get $$k$$ tails and $$k$$ heads but the method breaks down at this point if $$h \neq t$$ (and if $$p \neq \frac{1}{2}$$). At this point I'm stuck wondering if there's a 'nicer' form to this.

• You should be able to rewrite the term ${n \choose t} p^{n-t}$ as $\frac{1}{t!}\frac{\partial^t p^n}{\partial p^t}$. If you then swap summation and differentiation you can evaluate the geometric sum explicitly. But you end up with a formula that contains a $t$ times differentiation. The same can be done for the other sum. Commented Jan 10, 2019 at 11:08
• Although this yields a shorter form, I'm pretty sure we can't simplify the derivatives out, so it would give a computationally slow method. It comes down to finding the $k$th derivative of $\frac{x^{m+k}}{1-x}$ w.r.t. $x$, which doesn't have a nice form as far as I can tell, though it is at least finite. Commented Jan 10, 2019 at 22:44

I cannot give you a closed form, but I would have thought that if you made $$h+t$$ tosses and then however many more are needed to get the missing result then the expected total numbe of tosses may be

$$h+t+\sum_{s=0}^{h-1} {h+t \choose s}p^s(1-p)^{h+t-s} \frac{h-s}{p} + \sum_{s=h}^{h+t} {h+t \choose s}p^s(1-p)^{h+t-s} \frac{s-h}{1-p}$$

which with some manipulation may be

$$= \frac{t}{1-p}+\sum_{s=0}^{h-1} {h+t \choose s}p^s(1-p)^{h+t-s}(h-s)\left(\frac1p+\frac1{1-p}\right)$$

only requiring a finite sum. It may be possible to simplify this.

Note that if $$\frac{h}{h+t}$$ is substantially less than $$p$$ then the sum will be small so the expectation will be only slightly more than $$\frac{t}{1-p}$$ and will be equal to that if $$h=0$$. Similarly if $$\frac{h}{h+t}$$ is substantially more than $$p$$ then the expectation will be only slightly more than $$\frac{h}{p}$$ and will be equal to this if $$t=0$$

• Could you provide more detail on how you got to the first line? Commented Jan 11, 2019 at 0:52
• It is the application of "if you made $h+t$ tosses and then however many more are needed to get the missing result", so first $h+t$; if that gave you $s$ heads with probability ${h+t \choose s}p^s(1-p)^{h+t-s}$ then with $s \lt h$ you need $h-s$ more heads which needs an expected $\frac{h-s}{p}$ more tosses, and similarly with $s \gt h$ you need extra tosses to get the remaining tails Commented Jan 11, 2019 at 8:08