source: git/factory/facFqFactorize.h @ 9c6887

spielwiese
Last change on this file since 9c6887 was c79a9d, checked in by Martin Lee <martinlee84@…>, 13 years ago
bug fix in squarefree factorization and faster way to recover factors in factorization git-svn-id: file:///usr/local/Singular/svn/trunk@14411 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 22.8 KB
Line 
1/*****************************************************************************\
2 * Computer Algebra System SINGULAR
3\*****************************************************************************/
4/** @file facFqFactorize.h
5 *
6 * This file provides functions for factorizing a multivariate polynomial over
7 * \f$ F_{p} \f$ , \f$ F_{p}(\alpha ) \f$ or GF.
8 *
9 * @author Martin Lee
10 *
11 * @internal @version \$Id$
12 *
13 **/
14/*****************************************************************************/
15
16#ifndef FAC_FQ_FACTORIZE_H
17#define FAC_FQ_FACTORIZE_H
18
19#include <config.h>
20
21#include "facFqBivar.h"
22#include "DegreePattern.h"
23#include "ExtensionInfo.h"
24#include "cf_util.h"
25#include "facFqSquarefree.h"
26#include "facFqBivarUtil.h"
27
28/// Factorization over a finite field
29///
30/// @return @a multiFactorize returns a factorization of F
31/// @sa biFactorize(), extFactorize()
32CFList
33multiFactorize (const CanonicalForm& F,    ///< [in] poly to be factored
34                const ExtensionInfo& info  ///< [in] info about extension
35               );
36
37/// factorize a squarefree multivariate polynomial over \f$ F_{p} \f$
38///
39/// @return @a FpSqrfFactorize returns a list of monic factors, the first
40///         element is the leading coefficient.
41/// @sa FqSqrfFactorize(), GFSqrfFactorize()
42inline
43CFList FpSqrfFactorize (const CanonicalForm & F ///< [in] a multivariate poly
44                       )
45{
46  if (getNumVars (F) == 2)
47    return FpBiSqrfFactorize (F);
48  ExtensionInfo info= ExtensionInfo (false);
49  CFList result= multiFactorize (F, info);
50  result.insert (Lc(F));
51  return result;
52}
53
54/// factorize a squarefree multivariate polynomial over \f$ F_{p} (\alpha ) \f$
55///
56/// @return @a FqSqrfFactorize returns a list of monic factors, the first
57///         element is the leading coefficient.
58/// @sa FpSqrfFactorize(), GFSqrfFactorize()
59inline
60CFList FqSqrfFactorize (const CanonicalForm & F, ///< [in] a multivariate poly
61                        const Variable& alpha    ///< [in] algebraic variable
62                       )
63{
64  if (getNumVars (F) == 2)
65    return FqBiSqrfFactorize (F, alpha);
66  ExtensionInfo info= ExtensionInfo (alpha, false);
67  CFList result= multiFactorize (F, info);
68  result.insert (Lc(F));
69  return result;
70}
71
72/// factorize a squarefree multivariate polynomial over GF
73///
74/// @return @a GFSqrfFactorize returns a list of monic factors, the first
75///         element is the leading coefficient.
76/// @sa FpSqrfFactorize(), FqSqrfFactorize()
77inline
78CFList GFSqrfFactorize (const CanonicalForm & F ///< [in] a multivariate poly
79                       )
80{
81  ASSERT (CFFactory::gettype() == GaloisFieldDomain,
82          "GF as base field expected");
83  if (getNumVars (F) == 2)
84    return GFBiSqrfFactorize (F);
85  ExtensionInfo info= ExtensionInfo (getGFDegree(), gf_name, false);
86  CFList result= multiFactorize (F, info);
87  result.insert (Lc(F));
88  return result;
89}
90
91/// factorize a multivariate polynomial over \f$ F_{p} \f$
92///
93/// @return @a FpFactorize returns a list of monic factors with
94///         multiplicity, the first element is the leading coefficient.
95/// @sa FqFactorize(), GFFactorize()
96inline
97CFFList FpFactorize (const CanonicalForm& F ///< [in] a multivariate poly
98                    )
99{
100  if (getNumVars (F) == 2)
101    return FpBiFactorize (F);
102  ExtensionInfo info= ExtensionInfo (false);
103  Variable a= Variable (1);
104  CanonicalForm LcF= Lc (F);
105  CanonicalForm pthRoot, A;
106  CanonicalForm sqrfP= sqrfPart (F/Lc(F), pthRoot, a);
107  CFList buf, bufRoot;
108  CFFList result, resultRoot;
109  int p= getCharacteristic();
110  int l;
111  if (degree (pthRoot) > 0)
112  {
113    pthRoot= maxpthRoot (pthRoot, p, l);
114    result= FpFactorize (pthRoot);
115    result.removeFirst();
116    for (CFFListIterator i= result; i.hasItem(); i++)
117      i.getItem()= CFFactor(i.getItem().factor(),i.getItem().exp()*ipower(p,l));
118    result.insert (CFFactor (LcF, 1));
119    return result;
120  }
121  else
122  {
123    buf= multiFactorize (sqrfP, info);
124    A= F/LcF;
125    result= multiplicity (A, buf);
126  }
127  if (degree (A) > 0)
128  {
129    resultRoot= FpFactorize (A);
130    resultRoot.removeFirst();
131    result= Union (result, resultRoot);
132  }
133  result.insert (CFFactor (LcF, 1));
134  return result;
135}
136
137/// factorize a multivariate polynomial over \f$ F_{p} (\alpha ) \f$
138///
139/// @return @a FqFactorize returns a list of monic factors with
140///         multiplicity, the first element is the leading coefficient.
141/// @sa FpFactorize(), GFFactorize()
142inline
143CFFList FqFactorize (const CanonicalForm& F, ///< [in] a multivariate poly
144                     const Variable& alpha   ///< [in] algebraic variable
145                    )
146{
147  if (getNumVars (F) == 2)
148    return FqBiFactorize (F, alpha);
149  ExtensionInfo info= ExtensionInfo (alpha, false);
150  CanonicalForm LcF= Lc (F);
151  CanonicalForm pthRoot, A;
152  CanonicalForm sqrfP= sqrfPart (F/Lc(F), pthRoot, alpha);
153  CFList buf, bufRoot;
154  CFFList result, resultRoot;
155  int p= getCharacteristic();
156  int q= ipower (p, degree (getMipo (alpha)));
157  int l;
158  if (degree (pthRoot) > 0)
159  {
160    pthRoot= maxpthRoot (pthRoot, q, l);
161    result= FqFactorize (pthRoot, alpha);
162    result.removeFirst();
163    for (CFFListIterator i= result; i.hasItem(); i++)
164      i.getItem()= CFFactor(i.getItem().factor(),i.getItem().exp()*ipower(p,l));
165    result.insert (CFFactor (LcF, 1));
166    return result;
167  }
168  else
169  {
170    buf= multiFactorize (sqrfP, info);
171    A= F/LcF;
172    result= multiplicity (A, buf);
173  }
174  if (degree (A) > 0)
175  {
176    resultRoot= FqFactorize (A, alpha);
177    resultRoot.removeFirst();
178    result= Union (result, resultRoot);
179  }
180  result.insert (CFFactor (LcF, 1));
181  return result;
182}
183
184/// factorize a multivariate polynomial over GF
185///
186/// @return @a GFFactorize returns a list of monic factors with
187///         multiplicity, the first element is the leading coefficient.
188/// @sa FpFactorize(), FqFactorize()
189inline
190CFFList GFFactorize (const CanonicalForm& F ///< [in] a multivariate poly
191                    )
192{
193  ASSERT (CFFactory::gettype() == GaloisFieldDomain,
194          "GF as base field expected");
195  if (getNumVars (F) == 2)
196    return GFBiFactorize (F);
197  Variable a= Variable (1);
198  ExtensionInfo info= ExtensionInfo (getGFDegree(), gf_name, false);
199  CanonicalForm LcF= Lc (F);
200  CanonicalForm pthRoot, A;
201  CanonicalForm sqrfP= sqrfPart (F/LcF, pthRoot, a);
202  CFList buf;
203  CFFList result, resultRoot;
204  int p= getCharacteristic();
205  int q= ipower (p, getGFDegree());
206  int l;
207  if (degree (pthRoot) > 0)
208  {
209    pthRoot= maxpthRoot (pthRoot, q, l);
210    result= GFFactorize (pthRoot);
211    result.removeFirst();
212    for (CFFListIterator i= result; i.hasItem(); i++)
213      i.getItem()= CFFactor(i.getItem().factor(),i.getItem().exp()*ipower(p,l));
214    result.insert (CFFactor (LcF, 1));
215    return result;
216  }
217  else
218  {
219    buf= multiFactorize (sqrfP, info);
220    A= F/LcF;
221    result= multiplicity (A, buf);
222  }
223  if (degree (A) > 0)
224  {
225    resultRoot= GFFactorize (A);
226    resultRoot.removeFirst();
227    result= Union (result, resultRoot);
228  }
229  result.insert (CFFactor (LcF, 1));
230  return result;
231}
232
233/// Naive factor recombination for multivariate factorization over an extension
234/// of the initial field. No precomputed is used to exclude combinations.
235///
236/// @return @a extFactorRecombination returns a list of factors of @a F, whose
237///         shift to zero is reversed.
238/// @sa factorRecombination()
239CFList
240extFactorRecombination (
241                 const CFList& factors,     ///< [in] list of lifted factors
242                                            ///< that are monic wrt Variable (1)
243                 const CanonicalForm& F,    ///< [in] poly to be factored
244                 const CFList& M,           ///< [in] a list of powers of
245                                            ///< Variables
246                 const ExtensionInfo& info, ///< [in] info about extension
247                 const CFList& evaluation   ///< [in] evaluation point
248                       );
249
250/// Naive factor recombination for multivariate factorization.
251/// No precomputed is used to exclude combinations.
252///
253/// @return @a factorRecombination returns a list of factors of @a F
254/// @sa extFactorRecombination()
255CFList
256factorRecombination (const CanonicalForm& F,///< [in] poly to be factored
257                     const CFList& factors, ///< [in] list of lifted factors
258                                            ///< that are monic wrt Variable (1)
259                     const CFList& M        ///< [in] a list of powers of
260                                            ///< Variables
261                    );
262
263/// Lift bound adaption. Essentially an early factor detection but only the lift
264/// bound is adapted.
265///
266/// @return @a liftBoundAdaption returns an adapted lift bound.
267/// @sa earlyFactorDetect(), earlyFactorDetection()
268int
269liftBoundAdaption (const CanonicalForm& F, ///< [in] a poly
270                   const CFList& factors,  ///< [in] list of list of lifted
271                                           ///< factors that are monic wrt
272                                           ///< Variable (1)
273                   bool& success,          ///< [in,out] indicates that no
274                                           ///< further lifting is necessary
275                   const int deg,          ///< [in] stage of Hensel lifting
276                   const CFList& MOD,      ///< [in] a list of powers of
277                                           ///< Variables
278                   const int bound         ///< [in] initial lift bound
279                  );
280
281/// Lift bound adaption over an extension of the initial field. Essentially an
282///early factor detection but only the lift bound is adapted.
283///
284/// @return @a liftBoundAdaption returns an adapted lift bound.
285/// @sa earlyFactorDetect(), earlyFactorDetection()
286int
287extLiftBoundAdaption (
288            const CanonicalForm& F,    ///< [in] a poly
289            const CFList& factors,     ///< [in] list of list of lifted
290                                       ///< factors that are monic wrt
291            bool& success,             ///< [in,out] indicates that no further
292                                       ///< lifting is necessary
293            const ExtensionInfo& info, ///< [in] info about extension
294            const CFList& eval,        ///< [in] evaluation point
295            const int deg,             ///< [in] stage of Hensel lifting
296            const CFList& MOD,         ///< [in] a list of powers of
297                                       ///< Variables
298            const int bound            ///< [in] initial lift bound
299                     );
300
301/// detects factors of @a F at stage @a deg of Hensel lifting.
302/// No combinations of more than one factor are tested. Lift bound is adapted.
303///
304/// @return @a earlyFactorDetect returns a list of factors of F (possibly
305///         incomplete), in case of success. Otherwise an empty list.
306/// @sa factorRecombination(), extEarlyFactorDetect()
307CFList
308earlyFactorDetect (
309                CanonicalForm& F,      ///< [in,out] poly to be factored,
310                                       ///< returns poly divided by detected
311                                       ///< factors in case of success
312                CFList& factors,       ///< [in,out] list of factors lifted up
313                                       ///< to @a deg, returns a list of factors
314                                       ///< without detected factors
315                int& adaptedLiftBound, ///< [in,out] adapted lift bound
316                bool& success,         ///< [in,out] indicating success
317                const int deg,         ///< [in] stage of Hensel lifting
318                const CFList& MOD,     ///< [in] a list of powers of
319                                       ///< Variables
320                const int bound        ///< [in] initial lift bound
321                  );
322
323/// detects factors of @a F at stage @a deg of Hensel lifting.
324/// No combinations of more than one factor are tested. Lift bound is adapted.
325///
326/// @return @a extEarlyFactorDetect returns a list of factors of F (possibly
327///         incomplete), whose shift to zero is reversed, in case of success.
328///         Otherwise an empty list.
329/// @sa factorRecombination(), earlyFactorDetection()
330CFList
331extEarlyFactorDetect (
332            CanonicalForm& F,          ///< [in,out] poly to be factored,
333                                       ///< returns poly divided by detected
334                                       ///< factors in case of success
335            CFList& factors,           ///< [in,out] list of factors lifted up
336                                       ///< to @a deg, returns a list of factors
337                                       ///< without detected factors
338            int& adaptedLiftBound,     ///< [in,out] adapted lift bound
339            bool& success,             ///< [in,out] indicating succes
340            const ExtensionInfo& info, ///< [in] info about extension
341            const CFList& eval,        ///< [in] evaluation point
342            const int deg,             ///< [in] stage of Hensel lifting
343            const CFList& MOD,         ///< [in] a list of powers of Variables
344            const int bound            ///< [in] initial lift bound
345                     );
346
347/// evaluation point search for multivariate factorization,
348/// looks for a (F.level() - 1)-tuple such that the resulting univariate
349/// polynomial has main variable Variable (1), is squarefree and its degree
350/// coincides with degree(F) and the bivariate one is primitive wrt.
351/// Variable(1), and successively evaluated polynomials have the same degree in
352/// their main variable as F has, fails if there are no valid evaluation points,
353/// eval contains the intermediate evaluated polynomials.
354///
355/// @return @a evalPoints returns an evaluation point, which is valid if and
356///         only if fail == false.
357CFList
358evalPoints (const CanonicalForm& F,  ///< [in] a compressed poly
359            CFList & eval,           ///< [in,out] an empty list, returns @a F
360                                     ///< successive evaluated
361            const Variable& alpha,   ///< [in] algebraic variable
362            CFList& list,            ///< [in,out] a list of points already
363                                     ///< considered, a point is encoded as a
364                                     ///< poly of degree F.level()-1 in
365                                     ///< Variable(1)
366            const bool& GF,          ///< [in] GF?
367            bool& fail               ///< [in,out] indicates failure
368           );
369
370/// hensel Lifting and early factor detection
371///
372/// @return @a henselLiftAndEarly returns monic (wrt Variable (1)) lifted
373///         factors without factors which have been detected at an early stage
374///         of Hensel lifting
375/// @sa earlyFactorDetectn(), extEarlyFactorDetect()
376CFList
377henselLiftAndEarly (
378            CanonicalForm& A,         ///< [in,out] poly to be factored,
379                                      ///< returns poly divided by detected
380                                      ///< factors, in case of success
381            CFList& MOD,              ///< [in,out] a list of powers of
382                                      ///< Variables
383            int*& liftBounds,         ///< [in,out] initial lift bounds, returns
384                                      ///< adapted lift bounds
385            bool& earlySuccess,       ///< [in,out] indicating success
386            CFList& earlyFactors,     ///< [in,out] early factors
387            const CFList& Aeval,      ///< [in] @a A successively evaluated at
388                                      ///< elements of @a evaluation
389            const CFList& biFactors,  ///< [in] bivariate factors
390            const CFList& evaluation, ///< [in] evaluation point
391            const ExtensionInfo& info ///< [in] info about extension
392                   );
393
394/// Factorization over an extension of initial field
395///
396/// @return @a extFactorize returns factorization of F over initial field
397/// @sa extBiFactorize(), multiFactorize()
398CFList
399extFactorize (const CanonicalForm& F,   ///< [in] poly to be factored
400              const ExtensionInfo& info ///< [in] info about extension
401             );
402
403/// compute the LCM of the contents of @a A wrt to each variable occuring in @a
404/// A.
405///
406/// @return @a lcmContent returns the LCM of the contents of @a A wrt to each
407///         variable occuring in @a A.
408CanonicalForm
409lcmContent (const CanonicalForm& A, ///< [in] a compressed multivariate poly
410            CFList& contentAi       ///< [in,out] an empty list, returns a list
411                                    ///< of the contents of @a A wrt to each
412                                    ///< variable occuring in @a A starting from
413                                    ///< @a A.mvar().
414           );
415
416/// compress a polynomial s.t. \f$ deg_{x_{i}} (F) >= deg_{x_{i+1}} (F) \f$ and
417/// no gaps between the variables occur
418///
419/// @return a compressed poly with the above properties
420CanonicalForm myCompress (const CanonicalForm& F, ///< [in] a poly
421                          CFMap& N                ///< [in,out] a map to
422                                                  ///< decompress
423                         );
424
425/// evaluate a poly A with main variable at level 1 at an evaluation point in
426/// K^(n-1) wrt different second variables. If this evaluation is valid (see
427/// evalPoints) then Aeval contains A successively evaluated at this point,
428/// otherwise this entry is empty
429void
430evaluationWRTDifferentSecondVars (
431                    CFList*& Aeval,          ///<[in,out] an array of length n-2
432                                             ///< if variable at level i > 2
433                                             ///< admits a valid evaluation
434                                             ///< this entry contains A
435                                             ///< successively evaluated at this
436                                             ///< point otherwise an empty list
437                    const CFList& evaluation,///<[in] a valid evaluation point
438                                             ///< for main variable at level 1
439                                             ///< and second variable at level 2
440                    const CanonicalForm& A   ///<[in] some poly
441                                 );
442
443/// evaluate F successively n-2 at 0
444///
445/// @return returns a list of successive evaluations of F, ending with F
446CFList evaluateAtZero (const CanonicalForm& F ///< [in] some poly
447                      );
448
449/// divides factors by their content wrt. Variable(1) and checks if these polys
450/// divide F
451///
452/// @return returns factors of F
453CFList recoverFactors (const CanonicalForm& F, ///< [in] some poly F
454                       const CFList& factors   ///< [in] some list of
455                                               ///< factor candidates
456                      );
457
458/// divides factors shifted by evaluation by their content wrt. Variable(1) and
459/// checks if these polys divide F
460///
461/// @return returns factors of F
462CFList recoverFactors (const CanonicalForm& F,  ///< [in] some poly F
463                       const CFList& factors,   ///< [in] some list of
464                                                ///< factor candidates
465                       const CFList& evaluation
466                      );
467
468/// refine a bivariate factorization of A with l factors to one with
469/// minFactorsLength
470void
471refineBiFactors (const CanonicalForm& A,  ///< [in] some poly
472                 CFList& biFactors,       ///< [in,out] list of bivariate to be
473                                          ///< refined, returns refined factors
474                 CFList* const& factors,  ///< [in] list of bivariate
475                                          ///< factorizations of A wrt different
476                                          ///< second variables
477                 const CFList& evaluation,///< [in] the evaluation point
478                 int minFactorsLength     ///< [in] the minimal number of factors
479                );
480
481/// plug in evalPoint for y in a list of polys
482///
483/// @return returns a list of the evaluated polys, these evaluated polys are
484/// made monic
485CFList
486buildUniFactors (const CFList& biFactors,       ///< [in] a list of polys
487                 const CanonicalForm& evalPoint,///< [in] some evaluation point
488                 const Variable& y              ///< [in] some variable
489                );
490
491/// extract leading coefficients wrt Variable(1) from bivariate factors obtained
492/// from factorizations of A wrt different second variables
493void
494getLeadingCoeffs (const CanonicalForm& A,  ///< [in] some poly
495                  CFList*& Aeval,          ///< [in,out] array of bivariate
496                                           ///< factors, returns the leading
497                                           ///< coefficients of these factors
498                  const CFList& uniFactors,///< [in] univariate factors of A
499                  const CFList& evaluation ///< [in] evaluation point
500                 );
501
502/// normalize precomputed leading coefficients such that leading coefficients
503/// evaluated at 0 in K^(n-2) equal the leading coeffs wrt Variable(1) of
504/// bivariate factors
505void
506prepareLeadingCoeffs (CFList*& LCs,               ///<[in,out]
507                      int n,                      ///<[in] level of poly to be
508                                                  ///< factored
509                      const CFList& leadingCoeffs,///<[in] precomputed leading
510                                                  ///< coeffs
511                      const CFList& biFactors     ///<[in] bivariate factors
512                     );
513
514/// obtain factors of F by reconstructing their leading coeffs
515///
516/// @return returns the reconstructed factors
517/// @sa factorRecombination()
518CFList
519leadingCoeffReconstruction (const CanonicalForm& F,///<[in] poly to be factored
520                            const CFList& factors, ///<[in] factors of f monic
521                                                   ///< wrt Variable (1)
522                            const CFList& M        ///<[in] a list of powers of
523                                                   ///< Variables
524                           );
525
526/// distribute content
527///
528/// @return returns a list result of polys such that prod (result)= prod (L)
529/// but the first entry of L may be (partially) factorized and these factors
530/// are distributed onto other entries in L
531CFList
532distributeContent (
533          const CFList& L,                        ///<[in] list of polys, first
534                                                  ///< entry the content to be
535                                                  ///< distributed
536          const CFList* differentSecondVarFactors,///<[in] factorization wrt
537                                                  ///< different second vars
538          int length                              ///<[in] length of
539                                                  ///<differentSecondVarFactors
540                  );
541
542/// gcd free basis of two lists of factors
543void
544gcdFreeBasis (CFFList& factors1, ///< [in,out] list of factors, returns gcd free
545                                 ///< factors
546              CFFList& factors2  ///< [in,out] list of factors, returns gcd free
547                                 ///< factors
548             );
549
550#endif
551/* FAC_FQ_FACTORIZE_H */
552
Note: See TracBrowser for help on using the repository browser.