source: git/factory/facFqFactorize.h @ f09105

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