mersenneforum.org > Math Sums of three squares
 Register FAQ Search Today's Posts Mark Forums Read

 2009-11-05, 07:01 #1 CRGreathouse     Aug 2006 135418 Posts Sums of three squares There's a well-known formula for the number of ways that a number can be expressed as the sum of two squares: the product of one more than the exponents of the primes = 1 mod 4, assuming that all primes = 3 mod 4 appear to an even power (and 0 if any appear to an odd power). Is there a similarly nice formula for sums of three squares? I was trying to do some calculations with them but the inefficiency of my current program makes that difficult. I'm able to use some properties of such numbers (removing factors of 4, checking mod 8, using an efficient sum of two primes subroutine to remove some cases) but it's still slow -- getting to ten million will take all night, where with sums of two primes that would take 25 seconds.
2009-11-05, 12:47   #2
R.D. Silverman

Nov 2003

11101001001002 Posts

Quote:
 Originally Posted by CRGreathouse There's a well-known formula for the number of ways that a number can be expressed as the sum of two squares: the product of one more than the exponents of the primes = 1 mod 4, assuming that all primes = 3 mod 4 appear to an even power (and 0 if any appear to an odd power). Is there a similarly nice formula for sums of three squares? I was trying to do some calculations with them but the inefficiency of my current program makes that difficult. I'm able to use some properties of such numbers (removing factors of 4, checking mod 8, using an efficient sum of two primes subroutine to remove some cases) but it's still slow -- getting to ten million will take all night, where with sums of two primes that would take 25 seconds.
I don't know. I would write to Bob Vaughan. He would know the answer.

Last fiddled with by R.D. Silverman on 2009-11-05 at 12:52 Reason: typo

 2009-11-06, 13:46 #3 maxal     Feb 2005 3748 Posts See formula (35) at http://mathworld.wolfram.com/SumofSquaresFunction.html
 2009-11-06, 14:39 #4 CRGreathouse     Aug 2006 32×5×7×19 Posts Let me look at that formula and see if there is a good way to translate between it and my problem (essential solutions, not including sign and ordering). Since this formula applies only for squarefrees, how do I solve r_3(n * s^2)? Is there a good upper bound on the number of representations? Even a weak one like r_3(n) < n would be nice. Last fiddled with by CRGreathouse on 2009-11-06 at 14:55
2009-11-06, 17:48   #5
flouran

Dec 2008

72·17 Posts

Quote:
 Originally Posted by CRGreathouse Is there a good upper bound on the number of representations? Even a weak one like r_3(n) < n would be nice.
This should be a common application of sieve theory. Have you tried Halberstam and Richert's text? If that doesn't work, then I would take Bob's advice on contacting Vaughan (although he may be too busy to respond).

I should note that the methods used to achieve an upper bound on the number of representations as the sum of three squares of primes can be modified without much difficulty to provide a corresponding estimate (of the same quality, at worst) for the sum of three squares. The reason for this is that the situation becomes harder if we restrict some variables to primes. Thus, I am sure that the problem of the sum of three squares of primes (or a variant of this problem, at best) is treated in the H-R text.

Last fiddled with by flouran on 2009-11-06 at 17:49

2009-11-06, 17:53   #6
maxal

Feb 2005

22·32·7 Posts

Quote:
 Originally Posted by CRGreathouse Let me look at that formula and see if there is a good way to translate between it and my problem (essential solutions, not including sign and ordering).
Consider different cases depending on the number of nonzero squares in the expansion. If the number of nonzero squares is k, then this expansion is counted 2^k times if signs are taken into account.
Ordering is also possible to take into account by considering cases with distinct/equal squares.

2009-11-06, 19:20   #7
CRGreathouse

Aug 2006

32·5·7·19 Posts

Quote:
 Originally Posted by maxal Consider different cases depending on the number of nonzero squares in the expansion. If the number of nonzero squares is k, then this expansion is counted 2^k times if signs are taken into account. Ordering is also possible to take into account by considering cases with distinct/equal squares.
Of course I'm not enumerating the cases, so telling properties of each isn't obvious. I'll assume n is a positive integer.

If n is a square, there are 6 representations (1 unique) of the number as 0^2 + 0^2 + a^2. If n is twice a square, there are 12 representations (1 unique) of the number as 0^2 + a^2 + b^2, |a| = |b|.

So I guess I can use these and the algorithm for unique representations as two squares to determine the number of unique and nonunique representations as the sum of three squares, the least of which must be 0. So using the formula for r_3 I can determine the number of nonunique representations of n as the sum of three nonzero squares (and the corresponding number of unique representations skipped).

The number of representations as a^2 + b^2 + c^2 with |a| = |b| but |c| distinct from |a| and |b| can be counted directly. The number of representations as a^2 + b^2 + c^2 with |a| = |b| = |c| is 8 if n is thrice a square and 0 otherwise. The total can be subtracted from the above and divided by 48 to get the number of unique representations of the form a^2 + b^2 + c^2 with 0 < a < b < c; the skipped totals can be added on and I'm done.

Computational analysis:
r_3(n) can be computed in time O(n^.25) with Shanks' method. r_2(n) can be computed in time O(n^o(1)). The case with two equal squares can be computed in time O(sqrt(n) log(n)^2) -- the log term is improvable but realistically at the small sizes this is practical at the square root is likely to be quadratic rather than Karatsuba or Toom. So this case dominates the analysis. Is there a better way to count this case?

 Similar Threads Thread Thread Starter Forum Replies Last Post davar55 Puzzles 183 2019-12-12 22:31 a1call Miscellaneous Math 42 2017-02-03 01:29 Nick Number Theory Discussion Group 0 2016-12-11 11:30 m_f_h Puzzles 45 2007-06-15 17:46 TTn Math 2 2002-10-25 21:47

All times are UTC. The time now is 09:24.

Thu May 6 09:24:41 UTC 2021 up 28 days, 4:05, 0 users, load averages: 1.24, 1.41, 1.44