MathGroup Archive 2012

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Integers that are the sum of 2 nonzero squares in exactly 2 ways

  • To: mathgroup at smc.vnet.net
  • Subject: [mg125781] Re: Integers that are the sum of 2 nonzero squares in exactly 2 ways
  • From: Dana DeLouis <dana01 at me.com>
  • Date: Mon, 2 Apr 2012 04:24:33 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com

> and the first problem I see is 100 - This is perhaps using {10,10}  twice, 

Hi.  Me bad!   I forgot that PowersRepresentations considers zero a solution.
The 2 solutions are:

PowersRepresentations[100,2,2]
{{0,10},{6,8}}

But you didn't want 0 as a solution!

< your code set2 >  .. it works, except for the higher numbers. 

Just to point out... even at small numbers, your code shows 325 as a solution.

set2[1,17]
{50,65,85,125,.. ..,265,290,305,325,338}

However, 325 has 3 solutions. :>(

PowersRepresentations[325,2,2]
{{1,18},{6,17},{10,15}}

> ...set2[1,2000] which took 76 seconds

Here's a brute-force method that took about 5 seconds for 2 numbers.

fx[n_]:=Module[{w,r,t=n*n},
r=Power[Range[n],2];
w=Plus@@@Tuples[r,2];
w=Tally[w];
w=Cases[w,{x_,3|4}->x];
w=Sort[w];
Select[w,#<=t&]
]

fx[2000] //Length //Timing
{4.36819, 318173}

This is 600 more than James had.
This is due to his code not considering numbers that were equal.  (ie {5,5}).
I believe you considered this valid, as 50 was a solution.

The logic is for 2 numbers, one has either
{x,y},{y,x},{u,v},{v,u}
or
{x,y},{y,x},{v,v}
ie 3 or 4

= = = = = = = = = =
HTH  :>)
Dana DeLouis
Mac & Math 8
= = = = = = = = = =


On Mar 30, 5:36 am, Cisco Lane <travl... at yahoo.com> wrote:
> Hi - thanks for the help. I should have said 2 positive squares, without respect to order. So for the case of 50, its {5,5} and {1,7} only. SquaresR gives {5,5},{1,7},{7,1} times four, for the four permutations of sign {+,+},{+,_},{-,+} and {-,-}.
> 
> I'm trying to find energy eigenfunctions, with energy proportional to n^2. An eigenfunction will be a linear combination of all wave functions with the same energy. Right now, I'm just concerned with pairs. Then triplets, etc.
> 
> The slope is an average, so the first 3 does not have enough data points to draw any conclusions, I think.
> 
> I tried using your method out to 500 to get:
> 
> t=Table[{n,PowersRepresentations[n,2,2]},{n,500}];
> tt=First/@Select[t,Length[Last[#]]==2 &] //Rest
> 
> {50, 65, 85, 100, 125, 130, 145, 169, 170, 185, 200, 205,
> 221, 225, 250, 260, 265, 289, 290, 305, 338, 340, 365, 370, 377, 400,
> 410, 442, 445, 450, 481, 485, 493, 500}
> 
> and the first problem I see is 100 - This is perhaps using {10,10} twice, but I don't think 100 is the sum of the squares of a different pair of positive  integers. The expression I use is:
> 
> set2[nmin_, nmax_] := Module[{w, data},
>   w = Table[{n1, n2, n1^2 + n2^2}, {n1, nmin, nmax}, {n2, n1, nmax}];
>   w = Flatten[w, 1];
>   w = Sort[w, #1[[3]] <= #2[[3]] &];
>   data = {};
>   data = Reap[    
>     For[i = 1, i <= Length[w] - 2, i++,
>      If[(w[[i, 3]] == w[[i + 1, 3]]) && (w[[i, 3]] != w[[i + 2, 3]]),
>       Sow[w[[i, 3]]]        ]]  ];
>   data[[2, 1]]
>   ]
> 
> which takes the sums of two squares of all numbers between nmin and nmax, without respect to order, and picks out the ones that occur only twice. Kind of inelegant, but it works, except for the higher numbers. For example, if you calculate set2[1,250], you get 7656 entries. You will miss the ones that match {250,250} that are of the form e.g. {1,250^2}. So the "line" goes straight, then takes a jump as some are missed.
> 
> I have gone out as far as set2[1,2000] which took 76 seconds on my machine and yielded 528,041 pairs of which about 450,000 seem good.





  • Prev by Date: vlookup like function sugestion
  • Next by Date: Re: typesetting derivative at a value
  • Previous by thread: vlookup like function sugestion
  • Next by thread: Re: Integers that are the sum of 2 nonzero squares in