Timeline for Count sums of two squares
Current License: CC BY-SA 3.0
7 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Nov 27, 2015 at 18:44 | comment | added | Alex A. | @GlenO That simplification is seriously genius. I recommend you submit that as an alternative formula for the sequence on OEIS! | |
Nov 27, 2015 at 18:43 | history | edited | Alex A. | CC BY-SA 3.0 |
This simplification is incredible
|
Nov 27, 2015 at 3:11 | comment | added | Glen O |
So, it can be recovered - if you let the i=0 case happen in the sum, you can switch the sign on 4g(n) . So (n==0)-4g(n)-4g(n/2)+8sum(i->g(i)g(n-i),0:n/2) , which will not run into the error. But you can do even better, by noting the symmetries - (n==0)+4sum([g(i)g(n-i)for i=1:n])
|
|
Nov 26, 2015 at 3:45 | comment | added | Alex A. |
@GlenO Great suggestions, thanks. The sum trick fails for n=0 though, so I kept array comprehension.
|
|
Nov 26, 2015 at 3:43 | history | edited | Alex A. | CC BY-SA 3.0 |
saved 10
|
Nov 26, 2015 at 3:12 | comment | added | Glen O |
Use x^.5 rather than sqrt(x) to save 3 bytes. And (n==0) saves 2 bytes over 1÷(n+1) . And you can save 4 more characters by using cos(π*sqrt(x))^2÷1 rather than floor(cos(π*sqrt(x))^2) . Also, use 1:n/2 rather than 1:n÷2 , because there's no harm using a float in g(x) and it'll be locked to the integers for i anyway. And sum(i->g(i)g(n-i),1:n/2) will shave some more characters, too.
|
|
Nov 26, 2015 at 1:25 | history | answered | Alex A. | CC BY-SA 3.0 |