Loading....
Recent Article links:

Archive for March, 2008

A simple script to find small integer solutions to equations

For the class in elliptic curves that I am currently following, it came in handy to have a script to find small integer solutions to equations such as Y^2=X(X+1)(X-1). For this, I wrote a small Perl script that generates code to check all small values for all variables in the equation, and then runs the code. For instance, consider

meilof@meilof-laptop:~$ perl solfinder.pl "y*y==x*(x*x+4*x-6)"
(y,x)=-18,6
(y,x)=-3,-1
(y,x)=0,0
(y,x)=3,-1
(y,x)=18,6

This works for an arbitrary number of variables (as long as they are single characters), and any boolean expression in Perl syntax. It looks for solutions in which all variables have values with absolute value smaller than 50. Internally, this generates and then runs the following Perl code:

for ($y = -50; $y <= 50; $y++) {
  for ($x = -50; $x <= 50; $x++) {
  if($y*$y==$x*($x*$x+4*$x-6)) { print "(y,x)=$y,$x\n" }
  }
}

Grab the script here.