Probability Generating Functions, Dice Pools and Encoding closed-ended rerolls

dicegenerating-functionsprobability

I have been going through some self-learning around Probability Generating Functions (mostly inspired by this answer from 7 years ago) and while I'm making a lot of progress I'm not having much luck with how to encode the below:

Say we roll $n$ $d$-sided dice. We look at each dice to see if the dice face reads our target number $t$ or higher, and if it does, we count it as a "hit". The result of our roll that we're interested in then is the number of "hits", or $h$.

We then decide that if we roll $e$ or higher $(e \geq t)$, that we not only count our roll as a "hit", but we get to roll that dice again, and if the result on that dice continues to be e or higher, then we count the roll as a hit, and roll again. However, this can only occur $r$ times – If a dice has shown $e$ or higher on $r$ consecutive rerolls, we stop rerolling, regardless of the face of that dice.

If we were building a Probability Generating Function to model this process, how do we encode the limit on rerolling?

The link above provides us with a simple way of encoding an open-ended reroll (where we can reroll into perpetuity), where we simply multiply the probability of our reroll outcome by the entire probability function again. Given the parameters above, such a probability function for a single die would be the following:

$$f(z)= \frac{(t-1)}{d} + \frac{(e-t)z}{d} + \frac{(1+d-e)zf(z)}{d}$$

which, once solved for $f(z)$, looks like:

$$f(z)= \frac{(t-1)+(e-t)z}{d-(1+d-e)z}$$

Which shows the approximate effect of an open-ended reroll – it subtracts the probability of reroll outcomes from the overall probability space. We can then, of course, calculate $[f(z)]^{n}$ to generalise this to $n$ dice, and then build the closed-form to be able to find the probability of $h$ hits, but that part I understand – I have a strong intuition on that set of calculations, and if I have a PGF, I'm pretty confident that I can continue from there.

However, I lack an intuition on how to encode reroll limits, and I don't even really know what to try from here. Is this even possible within a PGF paradigm?

Best Answer

The method closest to the one of the link is to write the generating function as $F(z,r)$.

So, expanding on the scenario of the linked answer from 7 years ago, we have $$ F(z,r) =\begin{cases} \frac{t-1}{d} + \frac{(d-t+1)z}{d} &, r=0\\ \frac{t-1}{d} + \frac{(d-t)z}{d} + \frac{zF(z,r-1)}{d} &, else \end{cases} $$

Unrolling the recursion then gives $$ F(z,r)=\frac{z^r}{d^r}\cdot F(z,0)+\sum_{i=0}^{r-1}\left(\frac zd\right)^i·\left(\frac{t - 1}d + \frac{(d - t)·z}d\right) $$

As geometric series, we can compute its closed form: $$ F(z,r)=\frac{d^{-r-1}\cdot z^{r+1}\cdot (d-t+1)\cdot (z-1)}{z-d}+\frac{z\cdot (d-t)+t-1}{d-z} $$