source: git/factory/facFqFactorize.h @ e558c41

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