I came across a problem the other day while joking with my friends about skill checks and such things from D&D. A "skill check" is performed by rolling a 20-sided die and comparing the result against a set value; if the roll exceeds the value, the player has passed their skill check, if it does not they fail. A roll of either 1 or 20 often has additional effects. The problem with this joke was that it was taking place in a chat window which offered a dice-rolling effect, but could only roll a single 6-sided die.
This led me to ask the following question: How accurately can you approximate a die roll using a polynomial of dice?
Throughout this post, we can assume that all dice are fair (that is, the results of each die are a discrete uniform distribution). We will also abbreviate the different dice as $\mathbf{d}n$ where $n$ is the number of sides on the die (e.g., I am attempting to approximate a $\mathbf{d}20$ roll using only a $\mathbf{d}6$). Additionally, we let the result of a roll on a $\mathbf{d}n$ be written as $r^n$ and the final result of a process as $r^X$. We set these latter two conventions to allow for indexing of results for summation.
The basic operations out of which I am building these "polynomials of dice" are:
- Addition: $\mathbf{d}m+\mathbf{d}n=r^m+r^n$.
- Scalar Multiplication: $k\cdot \mathbf{d}m = kr^m = \sum_i^k r^m_i$.
- Die Multiplication: $(\mathbf{d}m)(\mathbf{d}n) = r^m r^n$.
- Translation: $\mathbf{d}m-k = r^m-k$.
- Division: $\frac{\mathbf{d}m}{k}$ is equal to $\lfloor{\frac{r^n}{k}}\rfloor$
- Truncation: We set a range, $[a,b]$, and if $r^X\not\in[a,b]$ we reroll process $X$.
Using these 6 operations, we can build polynomial-type expressions consisting of a finite process including a combination of rolls of dice (which may be of one size, but which could be generalised to include multiple sizes). For example, $X:\mathbf{d}6\left(\frac{\mathbf{d}6}{3}\right)$ would be the results of multiplying the results of a $\mathbf{d}6$ by $1$ or $2$ with equal probability which in turn is equivalent to rolling a single $\mathbf{d}12$. Which is to say $r^X\equiv r^6r^2 \equiv r^{12}$.
This brings me to my main result that I was able, through trial and error, to come up with as far as approximating a $\mathbf{d}20$ using only $\mathbf{d}6$ rolls is concerned:
$$X:\mathbf{d}6\left(3\frac{\mathbf{d}6}{3}\right)+\mathbf{d}6+5\frac{\mathbf{d}6}{3}-14$$
If this is truncated to the range $[1,20]$, the range of probabilities for the different values in that range differs from uniform by no more than $0.00711$ which is a percentage error of approximately $14\%$. Unfortunately, there is also a greater than $25\%$ chance that you will have to reroll at least once, but I'm not concerned with efficiency here, only the accuracy of the approximation. Lastly, although the Kolmogorov-Smirnov test can tell the two distributions apart up to a vanishingly small $\alpha$, the $\chi^2$ test I ran couldn't detect the difference between the two. Granted, it's been a while since I've done stats, so I could be out to lunch on calculating those statistics.
My question, finally, is this:
For $m,n$ which have at least one prime factor up to exponents differing (that is, $6$ and $20$ differ by two prime factors, $3$ and $5$, although $20$ contains an extra factor of $2$ this is not for our purposes a "differing prime factor"), how accurately is it possible to approximate $\mathbf{d}m$ by using the results of some process $X(\mathbf{d}n)$? Furthermore, how does the accuracy of this approximation relate to the probability that you will need to reroll?
I've had a vague idea that one could likely use something along the lines of a Fourier or other integral transform to allow for the construction of arbitrarily accurate approximations, but I've not been able to work out the details. Similarly, I've wondered if it would be possible to construct a Taylor-type series for these probability distributions to be able to better compare one to the other or to come up with some procedural method for generating approximations. I apologise if this is somewhat unclear, I've never asked a question here before and a lot of this has been done scattered around on scratchpaper at the office while on break. Hopefully it's an interesting enough question to make it worth going through my ramblings! :)
Edit: I implicitly used a couple of restrictions in my methods and forgot to include them. As Michael Lugo and Jean Marie both pointed out, there are ways to perfectly approximate dice using other dice by either finding a $k$ such that for $\sum_i k_i\cdot (r^m-s_i)$ our probability space is large enough that we can simply truncate a very large number of possibilities. Alternately, we can use an $m$-ary expansion of our target $n$ and truncate individual $m$-digits as necessary. When I was attempting to come up with my approximations, I was specifically looking for those where only a single translation could occur, and it must happen after all additions, multiplications, or divisions; and additionally, only one truncation can occur, and it must be the final operation in the process. While there are likely still similar methods that would be allowed, I'm specifically looking for those which rely on methods other than exceedingly large truncations.