Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #9362

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

From Dana DeLouis <dana01@me.com>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Integers that are the sum of 2 nonzero squares in exactly 2 ways
Date 2012-04-02 08:26 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <jlbns2$463$1@smc.vnet.net> (permalink)

Show all headers | View raw


> 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...@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.


Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread


Thread

Re: Integers that are the sum of 2 nonzero squares in exactly 2 ways Dana DeLouis <dana01@me.com> - 2012-04-02 08:26 +0000

csiph-web