Jeju's Semi-Pólya Cauldron and Extended Partial Fractions
Curse of Ra times infinity
timer
9 min
Background: 20x Going Viral
I think Plants Vs. Zombies Heroes is an underrated game.
It's not lacking in the lore (the Earth is canonically hollow), but it's even richer in meta-lore -
you can trace the downfall of PopCap through its update history and concept art,
and also see it clearly though the extremely buggy state in which they released the latest update
(after five years of silence, overturning years of optimization at the highest level of play).
Anyway, there's this card called Going Viral, which buffs your zombies (you can play as zombies)
and shuffles two copies of itself into your deck when played.
Combined with cost-reduction effects from Zombology Teacher,
you see a lot of hackers running 20x Going Viral + 20x Zombology Teacher decks to secure cheap wins.
But of course, if your deck gets flooded with Going Virals, you won't be able to draw any Teachers,
so you won't have any zombies to buff. And then you will lose.
So, basically, if you're a hacker, you want to draw exactly four Zombology Teachers - the maximum playable on field at one time -
and then nothing but Going Viral, to close out the game.
The Puzzle: Jeju's Cursed Cauldron
A witch doctor's cauldron contains 5 blessing orbs and 5 curse orbs. Jeju wants to retrieve the 5 blessing orbs.
When reaching into the cauldron he has a uniform probability of retrieving any of the orbs in the cauldron.
When retrieving a blessing orb, the orb will bless him and vanish.
When retrieving a curse orb, the orb will curse him, put two copies of itself in the cauldron, and vanish.
How many times should Jeju expect to be cursed until he retrieves the k-th blessing for 1≤k≤5?
The Dipping In of the Fingertips
Letting E[Xk] be the expected number of curses until the k-th blessing,
we have a straightforward expression for E[X1]:
It's at this point that I briefly got stuck, because this doesn't immediately telescope well.
But the official Mathematics Discord weighed in with a beautiful trick -
we can express the numerator - that is, x - in terms of things that telescope:
As a sanity check, if each curse orb added only one copy of itself to the cauldron when drawn,
Jeju should expect to be cursed E[Geom(105)]=1 time(s) before being blessed.
Each curse orb adding two copies of itself to the cauldron should only be a little bit worse than that. So it checks out!
That's a pretty good start, isn't it?
Crunching Nested Telescopes
Seeing the success of that first step, the next thing I did was carry that approach forward.
Letting Δxk=xk−xk−1:
This is starting to look hairy. Maybe it's a better idea to pause for now, and look for a better approach.
In other news, here's a picture of the scrap paper on which I crunched the nested telescopes.
oof ow my wrists
In the top right, there's a Δx2=1225, meaning that E[X2]=45+1225=310.
Still... Let's try not to do any more of that.
And Then There Were Nine (Capital Greek Letters)
Instead of doing any more layers of these nested telescopes, let's just do all the layers in one go
by solving the expectation in generality. Let e(b,c) be the expected number of curses drawn before drawing 1 blessing
from a cauldron starting with b blessings and c curses. Then E[Xk]=∑c=0∞e(6−k,c+5)P(Xk−1=c), and
e(b,c)=n=0∑∞nb+c+nbk=0∏n−1b+c+kc+k
=n=0∑∞nb+c+nb∏k=n−1−(b−1)n−1b+c+k∏k=0b−1c+k
=n=0∑∞n∏k=n−bnb+c+kb∏k=0b−1c+k
=(bk=0∏b−1(c+k))(n=0∑∞∏k=n−bnb+c+kn)
So far so good. Now we do the fractional decomposition
This matches up with what we crunched earlier: taking E[X0] to be 0,
we see that E[X1]=45+5(0)=45 and E[X2]=35+445=310, as we would hope.
And as an added bonus, the denominator of E[Xk] (if present) looks to be always equal to 5−k. ^_^
So now it's extremely easy to get values for E[X3]=215 and E[X4]=20.
And then we hit k=5, and the denominator becomes 0.
In Retrospect, The Sandpiles Were Suspiciously High
Unfortunately for Jeju, this isn't a mistake: E[X5]=∞. To get an intuition as to why, let's consider a cauldron starting with 1 blessing and 1 curse. Then
the partial sums of which ∑x1′=0n are clearly growing according to the harmonic numbers Hn=∑x=1nx1, so this infinite summation diverges. Unlucky! Infinitely many curses for you!
I originally came up with this question on a whim and asked it to DeepSeek, who proceeded to pretend it knew what it was on about for about ten minutes before giving me a partially correct answer.
DeepSeek's best effort
In the process, it brought up something called the Pólya urn.
The Pólya urn is a "rich get richer" kind of model. It does the opposite of "drawing balls without replacement":
when you draw a ball from the urn, that ball is replaced twice over for the next draw.
Its equilibrium state is unstable and is almost surely not converged to (for some physics-adjacent notion of equilibrium, at least).
In fact, letting the two colors of balls in the urn be red and blue,
the proportion of red balls in the urn converges to a random variable on [0,1][1].
The base Pólya urn is (from what I've read, I didn't take the martingales course)
closely related to the beta distribution and its multivariate extension, the Dirichlet distribution[2].
Using these, we can answer questions about things like the stopping times for ball-drawing processes on Pólya urns containing more than two colors of balls.
But Jeju's cauldron only follows Pólya's model on the curse orbs. It draws the blessing orbs without replacement. Hence, it's only semi-Pólya.
For the similar mixed-replacement urn (where blessings vanish but curses are replaced),
Wikipedia makes note of the recursion for P(n,k)=P(kblessings in ndraws)[3],
I'll think I'll leave it as an exercise to check whether or not P(n,k)=0 for all k>b for both recurrences.
In any case, for the generalized semi-Pólya urn
where colors b0...bn drawn without replacement have counts x0,t...xn,t after draw t
and colors c0...cn drawn with Pólya duplication have counts y0,t...ym,t after draw t,
we would expect that
Xt=i∑xi,t and Yt=i∑yi,t
should evolve according to the two-color semi-Pólya urn,
and within those color groups we should see evolution according to their respective multivariate generalizations
(the multivariate hypergeometric and multinomial Dirichlet distributions respectively;
and yes, "multinomial Dirichlet distribution" for Dirichlet distribution being "multivariate beta distribution"
is indeed "multinomial multivariate beta distribution". Phew.)
In conclusion, regardless of the exact distribution of blessing types, we should expect to never (in no finite amount of time) fully empty the cauldron of its blessings.
If you spin it juuust right, maybe you could convince someone that that's a good thing and fleece them for a respectable sum.
Well, you can't sell a cursed cauldron that you don't have.
Don't ask me to put you in contact with any witch doctors that might make one for you.
I only know one, and he's not taking commissions at the moment.
Further Questions
Telescope-crunching tricks. Is there any way to improve on mdoern partial fraction algorithms using telescope-crunching?
My instinct says no - solving a system of linear equations probably perfectly mirrors the process of isolating telescopic terms.
But maybe we can say something about the special case of Pochhammer denominators?
The finite state machurn. A Turing machine may behave differently when it reads the same tape symbol while in different internal states.
Hence, the finite state machurn, and its associated mapping function δ::Q×C→N∣C∣×Q, where pulling a ball of color c∈C while in state q∈Q adds back in the specified count and colors' worth of balls and transitions to state q′∈Q. This (from a cursory search) seems like it would add a notion of convergence to probabilistic automata.