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?