Group Abstract Group Abstract

Message Boards Message Boards

Improving calculation speed for finding perfect squares using two variables

Posted 6 years ago
POSTED BY: Jan Eerland
5 Replies
Posted 6 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 6 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 6 years ago

You could try this.

POSTED BY: Rohit Namjoshi
Posted 6 years ago

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

POSTED BY: Jan Eerland
Posted 6 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