# Binomial coefficient fun, mathematicians welcome

**URL:** <https://boards.straightdope.com/t/binomial-coefficient-fun-mathematicians-welcome/632245>\
**Category:** Factual Questions\
**Created:** [August 22, 2012, 3:02am UTC](https://boards.straightdope.com/t/binomial-coefficient-fun-mathematicians-welcome/632245 "2012-08-22T03:02:11Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Punoqllads](https://avatars.discourse-cdn.com/v4/letter/p/d2c977/32.png) [@Punoqllads](https://boards.straightdope.com/u/Punoqllads)\
**Post date:** [August 22, 2012, 3:02am UTC](https://boards.straightdope.com/t/binomial-coefficient-fun-mathematicians-welcome/632245/1 "2012-08-22T03:02:11Z")

</div>

This is not for homework. This is not for work work either. This is related to some stuff at work that I’ve already solved numerically, but I’m wondering if there’s an elegant algebraic solution, and hoping that a more mathematically astute Doper can lend a hand.

Let me introduce Gary the Gambler. Gary gambles, but he’s not addicted to gambling. To prove to himself that he’s not addicted, whenever he goes out for a night of gambling, he sets a limit on the number of games he’ll let himself lose. Once he’s lost that many games, regardless of how many he’s won, he’ll quit for the night and head home to play Farmville. But some nights he won’t hit his limit. Maybe he gets on a winning streak until it gets to be closing time at the gambling den, or maybe the DVR is busted and _Fringe_ is on, or he gets kicked out for excessive punning or whatever.

What we’d like to know is, assuming we know the maximum number of games he’d be able to play on a given night, and assuming he has a constant probability of winning a given game, how many games do we expect him to lose?

Let’s call the probability that he’d win a given game _a_. For convenience, we’ll call the probability that he’ll lose a game _b_ even though by definition it’s merely 1 - _a_. The maximum number of games he can play that night we’ll call _m_ and his self-imposed loss limit we’ll call _L_.

A while back, **Omphaloskeptic** (if I recall correctly) mentioned in this forum that if you consider the generating polynomial (_b_x + _a_)[sup]_m_[/sup], the probability that there will be _n_ successes (in our case, losses) in _m_ trials will be equal to the coefficient for x[sup]_n_[/sup] when you multiply out the terms. For example, if Gary will only have a chance to play 5 games that night, then the probability that he’ll lose exactly 3 games is (5 choose 3) \* _b_[sup]3[/sup] \* _a_[sup]2[/sup]. If _a_ = 75%, then there’s a 10 \* 0.25[sup]3[/sup] \* 0.75[sup]2[/sup] =~ 8.8% chance that he’ll lose 3 games.

To calculate the expected number of losses, then, we need merely multiply each coefficient by the number of losses associated with that term and sum up those values. For a given term where _n_ \<= _L_, this is multiplying the coefficient by the power of x that it’s associated with. When _m_ \<= _L_, this turns out to be calculating the derivative of our generating polynomial with respect to x and solving for x = 1.

This breaks down, however, then _m_ \> _L_. I’ve been trying to think of some kind of manipulation of **Omphaloskeptic** ’s generating polynomial that will somehow remove the terms that have _n_ \> _L_ and put back in the coefficients for those terms but multiplied by x[sup]_L_[/sup]. But I’ve had no luck, having neither a strong enough mathematical background nor powerful enough Google-fu.

Any ideas?

---

<div class="post-metadata">

**Author:** ![OldGuy](https://avatars.discourse-cdn.com/v4/letter/o/3bc359/32.png) [@OldGuy](https://boards.straightdope.com/u/OldGuy)\
**Post date:** [August 22, 2012, 3:21am UTC](https://boards.straightdope.com/t/binomial-coefficient-fun-mathematicians-welcome/632245/2 "2012-08-22T03:21:13Z")

</div>

First let’s assume M \> L otherwise he just plays M games every night and the expected number of losses is aM

Then he can lose L straight games with probability a[sup]L[/sup]

or he can lose L-1 games out of the first L then lose the last with probability [sub]L-1[/sub]C[sub]L[/sub]a[sup]L[/sup]b

or he can lose L-1 games out of the first L+1 then lose the last with probability [sub]L-1[/sub]C[sub]L+1[/sub]a[sup]L[/sup]b[sup]2[/sup]

…

or he can lose L-1 games out of the first M-1 then lose the last with probability [sub]L-1[/sub]C[sub]M-1[/sub]a[sup]L[/sup]b[sup]M-L[/sup]

or he can lose L-1 out of M with probability [sub]L-1[/sub]C[sub]M[/sub]a[sup]L-1[/sup]b[sup]M-L+1[/sup]

…

or he can lose 0 out of M with probability b[sup]M[/sup]

Multiply each of those by the number of losses and add.

ETA [sub]i[/sub]C[sub]j[/sub] is the binomial coefficient.

---

<div class="post-metadata">

**Author:** ![ultrafilter](https://avatars.discourse-cdn.com/v4/letter/u/3d9bf3/32.png) [@ultrafilter](https://boards.straightdope.com/u/ultrafilter)\
**Post date:** [August 22, 2012, 3:21am UTC](https://boards.straightdope.com/t/binomial-coefficient-fun-mathematicians-welcome/632245/3 "2012-08-22T03:21:32Z")

</div>

I don’t see how to do it with generating functions, but there’s a random walk approach that shouldn’t be too bad. Gary starts at (0, 0), and when he’s at (i, j), he moves to (i + 1, j) with probability p, and (i + 1, j + 1) with probability 1 - p. The game is over when the first coordinate hits m or the second coordinate hits L. There’s a pretty straightforward recurrence relation based on the next step from any given position, but I’m not up to working it out tonight.

---

<div class="post-metadata">

**Author:** ![Punoqllads](https://avatars.discourse-cdn.com/v4/letter/p/d2c977/32.png) [@Punoqllads](https://boards.straightdope.com/u/Punoqllads)\
**Post date:** [August 22, 2012, 3:36am UTC](https://boards.straightdope.com/t/binomial-coefficient-fun-mathematicians-welcome/632245/4 "2012-08-22T03:36:26Z")

</div>

Yes, I’ve already solved it numerically. It’s not that much work to compute it that way, but I was hoping to be able to put a nice function in a slide to describe what I’m calculating, even if solving it algebraically is more work in practice.

---

<div class="post-metadata">

**Author:** ![Punoqllads](https://avatars.discourse-cdn.com/v4/letter/p/d2c977/32.png) [@Punoqllads](https://boards.straightdope.com/u/Punoqllads)\
**Post date:** [August 22, 2012, 10:22am UTC](https://boards.straightdope.com/t/binomial-coefficient-fun-mathematicians-welcome/632245/5 "2012-08-22T10:22:27Z")

</div>

Oh, and the numeric solution:

Create array A of size L+1  
A[0] = 1  
A[1 … L] = 0  
for(i = 0 to m-1) doCreate array B of size L  
for(j = 0 to L-1) do[INDENT]B[j] = A[j] \* bdone  
A[0] = A[0] - B[0]  
for(j = 1 to L-1) doA[j] = A[j] - B[j] + B[j-1]done  
A[L] = A[L] + B[L-1]  
[/INDENT]done  
result = 0  
for(i = 1 to L) doresult = result + A\* \* idone

So for the case where a = 75%, b = 25%, m = 5, L = 3  
Initially A = [1 0 0 0]  
Iteration 1  
B = [0.25 0 0]  
A = [0.75 0.25 0 0]  
Iteration 2  
B = [0.19 0.06 0]  
A = [0.56 0.38 0.06 0]  
Iteration 3  
B = [0.14 0.09 0.2]  
A = [0.42 0.42 0.14 0.02]  
Iteration 4  
B = [0.11 0.11 0.04]  
A = [0.32 0.42 0.21 0.05]  
Iteration 5  
B = [0.08 0.11 0.05]  
A = [0.24 0.40 0.26 0.10]  
Result = 0.40 \* 1 + 0.26 \* 2 + 0.10 \* 3 = 1.23

---

<div class="post-metadata">

**Author:** ![septimus](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/septimus/32/410_2.png) [@septimus](https://boards.straightdope.com/u/septimus)\
**Post date:** [August 22, 2012, 6:23pm UTC](https://boards.straightdope.com/t/binomial-coefficient-fun-mathematicians-welcome/632245/6 "2012-08-22T18:23:48Z")

</div>

The solution for the unbounded problem is, in your example:  
1 \* (5_a^4_b) + 2 \* (10_a^3_b^2) + 3 \* (10_a^2_b^3) + 4 \* (5_a_b^4) + 5 \* (b^5)  
with the front multipliers (1, 2, 3, 4, 5) being the number of losses associated with that term. With a limit (e.g. 3) on losses, simply replace each multiplier larger than 3 with 3:  
1 \* (5_a^4_b) + 2 \* (10_a^3_b^2) + 3 \* (10_a^2_b^3) + 3 \* (5_a_b^4) + 3 \* (b^5)

---

<div class="post-metadata">

**Author:** ![Buck\_Godot](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/buck_godot/32/6573_2.png) [@Buck\_Godot](https://boards.straightdope.com/u/Buck_Godot)\
**Post date:** [August 23, 2012, 5:57pm UTC](https://boards.straightdope.com/t/binomial-coefficient-fun-mathematicians-welcome/632245/7 "2012-08-23T17:57:17Z")

</div>

Lets let K be the number of wins.

The two cases is either K\<=M-L and he stops at L losses or K\>M-L and he stops with M games.

In the first case the probability of getting K wins is defined by the[negative binomial](http://en.wikipedia.org/wiki/Negative_binomial_distribution).

In the second it is defined by the binomial you mentioned in your OP.  
Alternatively you could solely use the binomial distribution but when computing the expectation set the values for for all cases in which the number of losses was more than L, set it equal to L.

From the expected losses you can calculate the expected number of games and wins by

E(games) = Expected (losses)/b  
E(wins) = a\*Expected (losses)/b
