On 5/7/13, Bill Gosper <billgosper@gmail.com> wrote:
------- Yow! In[36]:= tim[Length[PowersRepresentations[31415, 4, 2]]]
During evaluation of In[36]:= 1.875057
Out[36]= 829
Anybody feel like speedbumming this in C? --rwg
Magma running on iMac core-i7 is 10x faster (if I haven't misunderstood above) !! // List unordered decompositions of integer as sum of 4 natural squares function foursquares (n) local w,x,y,z,reslist; reslist := []; for w in [Ceiling(Sqrt(n/4)) .. Floor(Sqrt(n))] do for x in [Ceiling(Sqrt((n - w^2)/3)) .. Min(w, Floor(Sqrt(n - w^2)))] do for y in [Ceiling(Sqrt((n - w^2 - x^2)/2)) .. Min(x, Floor(Sqrt(n - w^2 - x^2)))] do z := Floor(Sqrt(n - w^2 - x^2 - y^2)); // w >= x >= y >= z if w^2 + x^2 + y^2 + z^2 eq n then Append(~reslist, [w,x,y,z]); end if; end for; end for; end for; return reslist; end function;
q := 31415; time squsq := foursquares(q); Time: 0.170 #squsq; 829
WFL