Processing math: 100%

Monday, 2 July 2012

Berlekamp

Yesterday I finished porting Berlekamp's algorithm from nmod_poly module to fmpz_mod_poly_factor module.

Unlike Cantor-Zassenhaus and Kaltofen-Shoup algorithms this algorithm uses linear algebra -- not number theory. Berlekamp algorithm consists of two parts. The first part is standard: squarefree factorization. The second part is more specific.

Assume for simplicity that q is an odd prime number. R=Fq[x]/<f> is a vector space of dimension n=degf over Fq. Let β:RR be a mapping: β(a)=aqaConsider the kernel of βIf f = f1 ... fr where fi is irreducible i, then for aFq[x] we have
amodfkerβaqamodfaqamodfii
(by Fermat's little theorem)


Thus kerβ=Fq×...×Fq=Frq. amodfkerβ(amodf1,...,amodfr)=(a1modf1,...,armodfr) for some aiFq Denote by Q the matrix representing the Frobenius map S:S(a)=aq with respect to the polynomial basis xn1modf,...,xmodf,1modf of R.


Fact. f is irreducible r=1rank(QI)=n1

Now we can formulate the second part of the algorithm. 

Berlekamp's algorithm (second part).

Input and Output.
On input we have a monic squarefree polynomial fFq[x] of degree n
On output we get an irreducible divisor of f or "failure".
Step 1. Compute xqiremf for i=0,...,n1
Step 2. Form matrix Q using the result of Step 1
Step 3. Compute rank of (QI) and basis b1,...,br of kerβ (e.g. using Gaussian elimination for QI). If rank=n1 return f.
Step 4. Choose arbitrary element a=c1b1+...+crbr,ciFq
Step 5. g1=gcd(a,f). If g11 return g1.
Step 6. g2=gcd(a(q1)/2remf1,f). If g21,g2f return g2, else return "failure"


To get the full variant of factorization algorithm one has to call the second part many times until f is irreducible.

I also made Kaltofen-Shoup algorithm to use Brent-Kung algorithm for modular composition. I measured working time of Cantor-Zassenhaus, Kaltofen-Shoup and Berlekamp algorithms in the simplest case when an input polynomial has 1..6 factors of degree 1..8 and multiplicity 1..31. On each iteration (one iteration is a complete factorization of one polynomial) all parameters of input polynomial are randomly chosen (with uniform distribution). There is a table describing results on my computer (NI number of iterations, CZ  Cantor-Zassenhaus, B  Berlekamp, KS  Kaltofen-Shoup):

NI                  :    100      200     300     400     500     600     700     800     900    1000
CZ time (sec) :   10.71   18.98   27.20  35.53  46.02  55.36   64.10  72.11  82.54  91.79
time (sec)   :    1.65     2.98    4.34    6.65    8.36    9.79    11.44  12.92  14.53  15.91
KS time (sec) :    1.55     2.92    4.09    5.80    7.23    8.56    10.06  11.56  12.91  14.13

Of course it's necessary to make more tests because algorithm effectiveness can depend on some special properties of input polynomials or on field characteristic. 


3 comments:

  1. just a remark - one can make TeX much more readable on blogspot:
    http://tex.stackexchange.com/questions/13865/how-to-use-latex-on-blogspot

    ReplyDelete
  2. Oh wow! Your explanations on Berelekamp, Cantor-Zassenhaus, and Kaltofen-Shoup are very helpful for understanding what they are doing. KS is new to me but I have seen B and CZ in coding theory many times but have never understood how they work (I just accepted them as "magic"). Thanks!

    ReplyDelete