source: git/factory/facFqFactorize.h @ fd5b3a

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