How this calculation works
Every positive integer is a sum of four integer squares,but the representation need not be unique. This page separates the existence of a decomposition from two counting questions:sorted nonnegative quadruples and ordered signed quadruples. Those conventions give very different answers even for a small input.
r4(n)=8 sum_(d|n,4∤d)d;canonical rows satisfy0≤a≤b≤c≤d.A worked example
At n=30,the two canonical rows(0,1,2,5) and(1,2,3,4) contribute192+384=576 ordered signed solutions.
Good to know
Positive integer1–20,000;complete canonical count,at most150 displayed rows;zeros allowed,signs of zero not doubled.
Reference: Four-square enumeration and Jacobi count method reference (opens in a new tab) ↗
Four entries are different from two squares
Every positive integer is a sum of four integer squares,but the representation need not be unique. This page separates the existence of a decomposition from two counting questions:sorted nonnegative quadruples and ordered signed quadruples. Those conventions give very different answers even for a small input.
The existing two-square calculator asks whether two coordinates suffice. Here zeros are permitted and all four coordinate positions matter in the signed count. A representation such as zero,one,two,five is a single canonical row even though rearrangements and sign choices create many ordered solutions.
Compare this with the Sum of two squares calculator for integer representations. Find nonnegative four-square representations and separately report ordered signed counts,with zero/sign conventions explicit.
Enter one exact positive integer
Enter n without commas or an exponent notation that changes its value. The supported interval ends at twenty thousand so the enumeration can finish in the browser. The input describes an integer identity;there are no measurement units,rounding tolerances or probabilistic assumptions involved.
Zero is deliberately outside this page's interface. Its lone all-zero representation follows a different boundary convention from Jacobi's positive-integer formula. Negative values cannot equal a sum of real integer squares,and decimals would change the underlying Diophantine problem rather than create a nearby approximation.
Canonical enumeration avoids permutation duplicates
The search enforces a≤b≤c≤d and uses the partial square sum to bound each loop. Once the first three coordinates are chosen,the final coordinate must be the integer square root of the remainder. An exact square check decides membership without accepting a rounded near-square.
Ordering the coordinates makes the displayed rows unique. It also cuts the search substantially compared with trying every signed four-tuple. Arithmetic remains integral throughout the membership tests,so cancellation,decimal precision and a floating tolerance do not determine whether a representation is accepted.
Jacobi gives an independent counting identity
The total ordered signed count is eight times the sum of positive divisors of n that are not divisible by four. That identity counts coordinate order and sign. It is not the number of rows in the canonical table,and dividing by a universal symmetry factor would be incorrect.
For each canonical row,the calculator independently counts distinct permutations using repeated-coordinate factorials and multiplies by two for every nonzero coordinate. Repeated entries reduce the permutation count;zeros do not have separate positive and negative signs. The sum must agree with the divisor identity before a result is returned.
Thirty has two canonical patterns
For n=30,the canonical decompositions are 0²+1²+2²+5² and 1²+2²+3²+4². The first contributes 24 permutations times eight sign patterns,or 192 ordered solutions. The second contributes 24 times sixteen,or 384,because every coordinate is nonzero.
Their sum is 576. Independently,the positive divisors of thirty sum to seventy-two,and none is divisible by four. Jacobi's expression gives eight times seventy-two,again 576. This checks the table convention and the signed-count convention through different calculations rather than matching only a single familiar identity.
A shortened table is labeled explicitly
The total canonical count is computed even when there are more than 150 rows. Only the first 150 representatives are displayed in that situation,and the complete-list flag becomes false. A table length is therefore not a substitute for the canonical-count metric.
The signed count still includes every canonical pattern. A shortened witness table does not shorten that count. This distinction matters when comparing results with a database that lists only primitive representations,forbids zero,or identifies signs and permutations through a different equivalence relation.
Read the certificate before reusing the count
The equality between weighted enumeration and the divisor formula is a useful implementation check. It does not establish that a four-square representation is minimal in maximum coordinate,lexicographic order or another optimization criterion. The displayed order is an enumeration order,not an optimality promise.
If you need primitive solutions,filter by the common gcd of all four coordinates and recount under the desired symmetry convention. This page reports unrestricted integer representations. Keep the input,the zero convention,the canonical count and the ordered signed count together when using the result in a proof or exercise.
A few questions, answered
Why is the signed count larger than the table?
The table identifies coordinate permutations and signs by listing sorted nonnegative representatives. The signed count restores all distinct orders and nonzero sign choices.
Are zeros allowed?
Yes. A zero has one sign,so it does not double a representation count.
Does a shortened list change the count?
No. All canonical patterns are counted;only the display is capped at150 rows and its completeness flag is explicit.
Does this find a smallest representation?
It enumerates canonical rows rather than optimizing maximum coordinate or any other objective.