Consider the following water-pouring puzzle. Given $n$ initially empty jugs with maximum volumes $V_1, V_2,\dots ,V_n$, and the following three actions on a jug:
- A jug is filled completely.
- A jug is emptied completely.
- The contents of a jug are poured into another jug until it is completely full, leaving any excess in the original jug.
Is the closed form for the total number of possible configurations of $(V_{\rm jug\,1},V_{\rm jug\,2},\dots,V_{{\rm jug}\,n})$ given by $$\prod_{i=1}^{n}\left(\frac{V_i}{\gcd(V_1,\dots,V_n)}+1\right)-\prod_{i=1}^{n}\left(\frac{V_i}{\gcd(V_1,\dots,V_n)}-1\right)?$$
Example: Suppose we have two jugs with specified volumes, $V_1=4, V_2=3$. Then the possible permutations of $(V_1, V_2)$ are $(0,0),(0,3),(3,0),(3,3),(4,0),(1,3),(1,0),(0,1),(4,1),(2,3)$, $(2,0),(0,2),(4,2),(4,3)$ i.e. $14$ tuples, agreeing with $(4+1)(3+1)-(4-1)(3-1)=14$, since $\gcd(4,3)=1$.
By considering the expansion of the monic polynomial $\prod\limits_{i=1}^n(\lambda-V_i)$ and substituting $\lambda=\pm1$, we can also express this in terms of the elementary symmetric polynomial as the following $$2\sum_{k=1}^{n/2}\frac{e_{2k-1}(V_1,\dots ,V_n)}{\gcd(V_1,\dots ,V_n)^{2k-1}}\quad\text{for $n$ even and }2+2\sum_{k=1}^{(n-1)/2}\frac{e_{2k}(V_1,\dots ,V_n)}{\gcd(V_1,\dots ,V_n)^{2k}}\quad\text{for $n$ odd}, $$ for which I credit @TheSimpliFire for finding all the above general expressions.
For example:
- $n=2$ (the $2$ jug case): the number of possible permutations for $2$ jugs of maximum volume $V_1,V_2$ is $2(V_1+V_2)/\gcd(V_1,V_2)$; or
- $n=3$ (the $3$ jug case): with maximum volumes $V_1,V_2,V_3$, this has a total number of possible permutations of $2+2(V_1V_2+V_1V_3+V_2V_3)/\gcd(V_1,V_2,V_3)^2$.
However, one can simplify the problem by assuming WLOG that $V_1,V_2,\dots ,V_n$ are all coprime to each other and asking whether the closed form for the total number of possible combinations is given by $$\prod_{i=1}^{n} (V_i+1) - \prod_{i=1}^{n}(V_i-1)$$ since suppose for example that $\gcd(V_1,\dots ,V_n)=3$, then we cannot make a jug have a volume that is not a multiple of $3$, giving the same number of possible combinations as if we began with an initial step of scaling all the maximum volumes down by a factor of $3$ such that all the maximum volumes would now be coprime.
Since writing this question, I have uploaded a Python script of mine, which is able to generate a table of the number of possible states for up to $4$ jugs, to GitHub and which was used to greatly assist in determining the formula in the question. I have linked it here in the hope of aiding anyone attempting to determine the number of states without the need for tedious by-hand computations. The code can likely be optimised massively, and I would be interested if anyone knows how to make it better.
The context for this problem is due to a computer science coursework question of a friend of mine which asked to write a Java program using the DFS algorithm to find the number of possible states for the $V_1=8,V_2=5,V_3=3$ case, however, I wanted to think of the problem more mathematically and abstractly and out of my own interest tried to generalise it and find a general formula. Note that there are $160$ possible states with $V_1=8,V_2=5,V_3=3$ for which the above formulae agree.