Message Boards Message Boards

Improving calculation speed for finding perfect squares using two variables

Posted 4 years ago

Well, I have the following code:

ParallelTable[
   If[TrueQ[
     Sqrt[123*(3*(2*x)^2+167*y^2*x+y*x+4*y^3*x^2)] \[Element] Integers], {{x, y}, 
     Nothing}], {x, 2000,5000}, {y, 1000000000, 1000001000}] //. 
  Null -> Nothing //. {} -> Nothing

And using this code I am trying to determine for what $(x,y)$ the function $123(3(2x)^2+167y^2x+yx+4y^3x^2)$ gives a perfect square. Is there a way to improve the speed of this calculation? Every $1000$ possibilities take now round about 14 minutes, which is a bit slow.

Is there a way to check if the function I stated in the question is a perfect square, in a more sophisticated way?

POSTED BY: Jan Eerland
5 Replies
Posted 4 years ago

Quick comparison

Simplify[123*(3*(2*x)^2 + 167*y^2*x + y*x + 4*y^3*x^2)]
(* 123 x (y (1 + 167 y) + 4 x (3 + y^3) *)

f[x_, y_] := 123 x (y (1 + 167 y) + 4 x (3 + y^3);

Table[If[TrueQ[Sqrt[f[x, y]] \[Element] Integers], {x, y}, Nothing], {x, 2000, 5000},
  {y, 2000, 5000}] // AbsoluteTiming // First
(* I gave up after waiting for 6 minutes *)

Table[If[sQ[f[x, y]], {x, y}, Nothing], {x, 2000, 5000}, {y, 2000, 5000}] // 
 AbsoluteTiming // First
(* 49.3531 *)
POSTED BY: Rohit Namjoshi
Posted 4 years ago

What is the definition of sQ[.]? Now it does not work in my Mathematica.

POSTED BY: Jan Eerland
Posted 4 years ago

See the link I posted earlier.

sQ[n_] := FractionalPart@Sqrt[n + 0``1] == 0

sQ[17]
(* False *)

sQ[900]
(* True *)
POSTED BY: Rohit Namjoshi
Posted 4 years ago

You could try this.

POSTED BY: Rohit Namjoshi
Posted 4 years ago

Can you show me how to imply that in om my problem?

POSTED BY: Jan Eerland
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract