Dice Rolls – When the Product Yields a Square

combinatoricsgenerating-functionslinear algebramarkov chainsnumber theory

Succinct Question:

Suppose you roll a fair six-sided die $n$ times.

What is the probability that the product of the rolls is a square?

Context:

I used this as one question in a course for elementary school teachers when $n=2$, and thought the generalization might be a good follow-up question for secondary school math teachers. But I encountered quite a bit of difficulty in tackling it, and I am wondering if there is a neater solution than what I have already seen, and to what deeper phemonena it connects.

Known:

Since the six sides of a die are $1, 2, 3, 2^2, 5,$ and $2\cdot3$, the product of the rolls is always of the form $2^{A}3^{B}5^{C}$, and the question is now transformed into the probability that $A, B, C$ are all even. The actual "probability" component is mostly for ease of phrasing; its only contribution is a $6^n$ in the denominator, and my true question is of a more combinatorial nature: namely,

In how many ways can the product of $n$ rolls yield a square?

One approach that I have seen involves first creating an $8 \times 8$ matrix corresponding to the eight cases around the parity of $A, B, C$; one can then take the dot product of each roll with this matrix, and hope to spot a pattern. In this way, one may discover the formula:

$$\frac{6^n + 4^n + 3\cdot2^n}{8}$$

and the "probability" version is simply this formula with another $6^n$ multiplied in the denominator.

As for proving this: Some guesswork around linear combinations of the numerator yields a formula for each of the eight cases concerning $A,B,C$ parity, and one can then prove all eight of them by induction. And so I "know" the answer in the sense that I have all eight of the formulae (and the particular one listed above is correct) but they were not found in a particularly organized fashion.

My Actual Question:

What is a systematic way to deduce the formula, given above, for the number of ways the product of $n$ rolls yields a square, and to what deeper phenomena does this connect?

Best Answer

For $1\le i\le6,\;$ let $a_i$ be the number of dice which have the digit $i$ appearing.

The product of the rolls will be a perfect square when $a_2+a_6,\;$ $a_3+a_6,\;$ and $a_5$ are all even;

so we can consider two cases:

$\textbf{1)}$ When $a_2, a_3, a_6$ are all odd, we get the exponential generating function

$\;\;\;\displaystyle\underbrace{\big(1+x+\frac{x^2}{2!}+\cdots\big)^2}_{a_1, a_4}\underbrace{\big(x+\frac{x^3}{3!}+\frac{x^5}{5!}+\cdots\big)^3}_{a_2, a_3, a_6}\underbrace{\big(1+\frac{x^2}{2!}+\frac{x^4}{4!}+\cdots\big)}_{a_5}$

$\;\;\;\displaystyle=e^{2x}\left(\frac{e^x-e^{-x}}{2}\right)^3\left(\frac{e^x+e^{-x}}{2}\right)=\color{red}{\frac{1}{16}\big(e^{6x}-2e^{4x}-e^{-2x}+2\big)}$

$\textbf{2)}$ When $a_2, a_3, a_6$ are all even, we get the exponential generating function

$\;\;\;\displaystyle\underbrace{\big(1+x+\frac{x^2}{2!}+\cdots\big)^2}_{a_1,a_4}\underbrace{\big(1+\frac{x^2}{2!}+\frac{x^4}{4!}+\cdots\big)^4}_{a_2,a_3, a_5, a_6}$

$\;\;\;\displaystyle=e^{2x}\left(\frac{e^x+e^{-x}}{2}\right)^4=\color{red}{\frac{1}{16}\big(e^{6x}+4e^{4x}+6e^{2x}+e^{-2x}+4\big)}$

Adding the two cases gives the generating function

$\;\;\;\displaystyle g_e(x)=\frac{1}{16}\big[2e^{6x}+2e^{4x}+6e^{2x}+6\big]=\color{red}{\frac{1}{8}\big[e^{6x}+e^{4x}+3e^{2x}+3\big]}$

$\hspace{.3 in}\displaystyle=1+\frac{1}{8}\sum_{n=1}^{\infty}\left(6^n+4^n+3\cdot2^n\right)\frac{x^n}{n!},\;\;$ so there are

$\displaystyle \hspace{.5 in}\color{blue}{\frac{1}{8}\big(6^n+4^n+3\cdot2^n\big)}$ ways to roll $n$ dice and get a product which is a perfect square.