11

I'm looking for a speedy algorithm to find the roots of a univariate polynomial in a prime finite field.

That is, if f = a0 + a1x + a2x2 + ... + anxn (n > 0) then an algorithm that finds all r < p satisfying f(r) = 0 mod p, for a given prime p.

I found Chiens search algorithm https://en.wikipedia.org/wiki/Chien_search but I can't imagine this being that fast for primes greater than 20 bits. Does anyone have experience with Chien's search algorithm or know a faster way? Is there a sympy module for this?

Vincent van der Weele
  • 12,311
  • 1
  • 28
  • 58
Kevin Johnson
  • 710
  • 7
  • 23
  • http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.133.1907&rep=rep1&type=pdf makes the point that solving polynomials over finite fields is a special case of factoring them, and there are randomized polynomial time algorithms for factoring polynomials over finite fields (see e.g. http://en.wikipedia.org/wiki/Factorization_of_polynomials_over_finite_fields). It says it goes on to describe deterministic polynomial time algorithms for root-finding, but I haven't read that far. – mcdowella Mar 12 '15 at 05:39

2 Answers2

13

This is pretty well studied, as mcdowella's comment indicates. Here is how the Cantor-Zassenhaus random algorithm works for the case where you want to find the roots of a polynomial, instead of the more general factorization.

Note that in the ring of polynomials with coefficients mod p, the product x(x-1)(x-2)...(x-p+1) has all possible roots, and equals x^p-x by Fermat's Little Theorem and unique factorization in this ring.

Set g = GCD(f,x^p-x). Using Euclid's algorithm to compute the GCD of two polynomials is fast in general, taking a number of steps that is logarithmic in the maximum degree. It does not require you to factor the polynomials. g has the same roots as f in the field, and no repeated factors.

Because of the special form of x^p-x, with only two nonzero terms, the first step of Euclid's algorithm can be done by repeated squaring, in about 2 log_2 (p) steps involving only polynomials of degree no more than twice the degree of f, with coefficients mod p. We may compute x mod f, x^2 mod f, x^4 mod f, etc, then multiply together the terms corresponding to nonzero places in the binary expansion of p to compute x^p mod f, and finally subtract x.

Repeatedly do the following: Choose a random d in Z/p. Compute the GCD of g with r_d = (x+d)^((p-1)/2)-1, which we can again compute rapidly by Euclid's algorithm, using repeated squaring on the first step. If the degree of this GCD is strictly between 0 and the degree of g, we have found a nontrivial factor of g, and we can recurse until we have found the linear factors hence roots of g and thus f.

How often does this work? r_d has as roots the numbers that are d less than a nonzero square mod p. Consider two distinct roots of g, a and b, so (x-a) and (x-b) are factors of g. If a+d is a nonzero square, and b+d is not, then (x-a) is a common factor of g and r_d, while (x-b) is not, which means GCD(g,r_d) is a nontrivial factor of g. Similarly, if b+d is a nonzero square while a+d is not, then (x-b) is a common factor of g and r_d while (x-a) is not. By number theory, one case or the other happens close to half of the possible choices for d, which means that on average it takes a constant number of choices of d before we find a nontrivial factor of g, in fact one separating (x-a) from (x-b).

Douglas Zare
  • 3,215
  • 1
  • 12
  • 19
  • The polynomial GCD is not as fast as I stated. The number of steps is bounded by the degree of the smaller polynomial, which is good enough here. – Douglas Zare Oct 28 '15 at 23:57
1

Your answers are good, but I think I found a wonderful method to find the roots modulo any number: This method based on "LATTICES". Let rR be a root of mod p. We must find another function such as h(x) such that h isn't large and r is root of h. Lattice method find this function. At the first time, we must create a basis of polynomial for lattice and then, with "LLL" algorithm, we find a "shortest vector" that has root r without modulo p. In fact, we eliminate modulo p with this way.

For more explanation, refer to "Coppersmith D. Finding small solutions to small degree polynomials. In Cryptography and lattices".

Laurel
  • 5,522
  • 11
  • 26
  • 49