2

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?

1 Answers1

2

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} $$

Sudix
  • 3,630
  • Not the answer I was expecting, but definitely a very workable answer. Thank you kindly! – Lee Davis-Thalbourne Sep 12 '23 at 04:16
  • I keep trying to get this to work, but I think the initial equation has an error? at $r=0$, I think the formula should be $\frac{(t-1)z}{d}+\frac{(d-t+1)z}{d}$ - as it stands that part of the function doesn't add up to 1. I've tried to compensate through the rest of the steps but it's not returning the answer that I know is correct. Any chance of a second glance? – Lee Davis-Thalbourne Sep 29 '23 at 07:18
  • Yes, you're right. If we don't reroll, then we either have 0 hits, with probability $\frac{t-1}d$, or 1 hit, with probability $\frac{d-t+1}d$. Because we want it expressed as probability generating function, we have to multiply each of those two fractions with $z^\text{#hits}$. So it should be $F(z,0):=\frac{t-1}{d} + \frac{(d-t+1)z}{d}$. – Sudix Sep 29 '23 at 09:29
  • The case $F(z,r)$ on the other hand was correct (assuming we're in the scenario of the linked answer from 7 years ago): We have again a probability of $\frac{t-1}{d}$ for 0 hits, now a probability of $\frac{(d-t)z}{d}$ for exactly 1 hit, and if we roll a $d$, that is with probability $\frac1d$, we repeat the experiment, but remember that we already have 1 hit ($\to z^1$) , and the maximum reroll count reduces by 1. – Sudix Sep 29 '23 at 09:30
  • I'll update the answer to reflect this correction – Sudix Sep 29 '23 at 09:30
  • Thanks for that - I've just checked out the expected value and variance, and the answers are coming out 100% correct! Thank you for the second glance! – Lee Davis-Thalbourne Sep 30 '23 at 02:51