Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Solving quadratic congruence equation in Mathematica

In order to solve

   x^2 == 123456 mod 1299709 

in Mathematica I have used:

  Reduce[x^2 == 123456 + 1299709 k, {x, k}, Integers]

which yields the correct answer.

Question: Is Reduce the best way ( performance, elegance or otherwise ) to solve quadratic congruence equations?

like image 867
nilo de roock Avatar asked Oct 21 '11 20:10

nilo de roock


2 Answers

Apparently you are seeking the Modulus option.

Reduce[x^2 == 123456, x, Modulus -> 1299709]
(*Out[]=  x == 427784 || x == 871925 *)

Quoting the documentation:

Modulus -> n
is an option that can be given in certain algebraic functions to specify that integers should be treated modulo n.

  • Equations for Modulus can be given in Solve and related functions.

  • Modulus appears as an option in Factor, PolynomialGCD and PolynomialLCM, as well as in linear algebra functions such as Inverse, LinearSolve and Det.

  • Arithmetic is usually done over the full ring ℤ of integers; setting the option Modulus specifies that arithmetic should instead be done in the finite ring ℤn.

  • The setting Modulus->0 specifies the full ring ℤ of integers.

  • Some functions require that Modulus be set to a prime, or a power of a prime. ℤn is a finite field when n is prime.

like image 123
Mr.Wizard Avatar answered Sep 27 '22 23:09

Mr.Wizard


In[1]:= PowerModList[123456, 1/2, 1299709]
Out[1]= {427784, 871925}

Daniel Lichtblau

like image 31
Daniel Lichtblau Avatar answered Sep 27 '22 23:09

Daniel Lichtblau