It is ancient knowledge that every non-negative integer can be rewritten as the sum of four squared integers. For example the number 1 can be expressed as \$0^2+0^2+0^2+1^2\$. Or, in general, for any non-negative integer \$n\$, there exist integers \$a,b,c,d\$ such that
$$n = a^2+b^2+c^2+d^2$$
Joseph-Louis Lagrange proved this in the 1700s and so it is often called Lagrange's Theorem.
This is sometimes discussed in relation to quaternions – a type of number discovered by William Hamilton in the 1800s, represented as $$w+x\textbf{i}+y\textbf{j}+z\textbf{k}$$ where \$w,x,y,z\$ are real numbers, and \$\textbf{i}, \textbf{j}\$ and \$\textbf{k}\$ are distinct imaginary units that don't multiply commutatively. Specifically, it is discussed in relation to squaring each component of the quaternion $$w^2+x^2+y^2+z^2$$This quantity is sometimes called the norm, or squared norm, or also quadrance. Some modern proofs of Lagrange's Theorem use quaternions.
Rudolf Lipschitz studied quaternions with only integer components, called Lipschitz quaternions. Using quadrance, we can imagine that every Lipschitz quaternion can be thought of having a friend in the integers. For example quaternion \$0+0\textbf{i}+0\textbf{j}+1\textbf{k}\$ can be thought of as associated with the integer \$1=0^2+0^2+0^2+1^2\$. Also, if we go backwards, then every integer can be thought of as having a friend in the Lipschitz quaternions.
But there is an interesting detail of Lagrange's theorem – the summation is not unique. Each integer may have several different sets of four squares that can be summed to create it. For example, the number 1 can be expressed in 4 ways using non-negative integers (let us only consider non-negatives for this challenge): $$1=0^2+0^2+0^2+1^2$$ $$1=0^2+0^2+1^2+0^2$$ $$1=0^2+1^2+0^2+0^2$$ $$1=1^2+0^2+0^2+0^2$$
The summands are always squares of 0, or 1, but they can be in different positions in the expression.
For this challenge, let us also "sort" our summands lowest to highest, to eliminate duplicates, so that we could consider, for this exercise, that 1 only has one way of being represented as the sum of four squares:
$$1=0^2+0^2+0^2+1^2$$
Another example is the number 42, which can be expressed in four ways (again, only considering non-negative a,b,c,d, and eliminating duplicate component arrangements)
$$42=0^2+1^2+4^2+5^2$$ $$42=1^2+1^2+2^2+6^2$$ $$42=1^2+3^2+4^2+4^2$$ $$42=2^2+2^2+3^2+5^2$$
What if we imagine each of these different ways of expressing an integer as being associated to a specific quaternion? Then we could say the number 42 is associated with these four quaternions:
$$0+1\textbf{i}+4\textbf{j}+5\textbf{k}$$ $$1+1\textbf{i}+2\textbf{j}+6\textbf{k}$$ $$1+3\textbf{i}+4\textbf{j}+4\textbf{k}$$ $$2+2\textbf{i}+3\textbf{j}+5\textbf{k}$$
If we imagine the standard computer graphics interpretation of a quaternion, where \$\textbf{i}\$, \$\textbf{j}\$ and \$\textbf{k}\$ are vectors in three dimensional Euclidean space, and so the \$x\$, \$y\$ and \$z\$ components of the quaternion are 3 dimensional Cartesian coordinates, then we can imagine that each integer, through this thought process, can be associated with a set of 3 dimensional coordinates in space. For example, the number 42 is associated with the following four \$(x,y,z)\$ coordinates: $$(1,4,5),(1,2,6),(3,4,4),(2,3,5)$$
This can be thought of as a point cloud, or a set of points in space. Now, one interesting thing about a set of finite points in space is that you can always draw a minimal bounding box around them – a box that is big enough to fit all the points, but no bigger. If you imagine the box as being an ordinary box aligned with the \$x,y,z\$ axes, it is called an axis-aligned bounding box. The bounding box also has a volume, calculable by determining its width, length, and height, and multiplying them together.
We can then imagine the volume of a bounding box for the points formed by our quaternions. For the integer 1, we have, using the criteria of this exercise, one quaternion whose quadrance is 1, \$0+0\textbf{i}+0\textbf{j}+1\textbf{k}\$. This is a very simple point cloud, it only has one point, so it's bounding box has volume 0. For the integer 42, however, we have four quaternions, and so four points, around which we can draw a bounding box. The minimum point of the box is \$(1,2,4)\$ and the maximum is \$(3,4,6)\$ resulting in a width, length, and height of 2, 2, and 2, giving a volume of 8.
Let's say that for an integer \$n\$, the qvolume is the volume of the axis-aligned bounding box of all the 3D points formed by quaternions that have a quadrance equal to \$n\$, where the components of the quaternion \$w+x\textbf{i}+y\textbf{j}+z\textbf{k}\$ are non-negative and \$w<=x<=y<=z\$.
Create a program or function that, given a single non-negative integer \$n\$, will output \$n\$'s qvolume.
Examples:
input -> output
0 -> 0
1 -> 0
31 -> 4
32 -> 0
42 -> 8
137 -> 96
1729 -> 10032
This is code-golf, smallest number of bytes wins.