source: git/factory/facFactorize.h @ 72bfc8

jengelh-datetimespielwiese
Last change on this file since 72bfc8 was 72bfc8, checked in by Martin Lee <martinlee84@…>, 11 years ago
chg: deleted @internal
  • Property mode set to 100644
File size: 4.1 KB
Line 
1/*****************************************************************************\
2 * Computer Algebra System SINGULAR
3\*****************************************************************************/
4/** @file facFactorize.h
5 *
6 * multivariate factorization over Q(a)
7 *
8 * @author Martin Lee
9 *
10 **/
11/*****************************************************************************/
12
13#ifndef FAC_FACTORIZE_H
14#define FAC_FACTORIZE_H
15
16// #include "config.h"
17
18#include "facBivar.h"
19#include "facFqBivarUtil.h"
20
21/// Factorization over Q (a)
22///
23/// @return @a multiFactorize returns a factorization of F
24CFList
25multiFactorize (const CanonicalForm& F,     ///< [in] poly to be factored
26                const Variable& v           ///< [in] some algebraic variable
27               );
28
29/// factorize a squarefree multivariate polynomial over \f$ Q(\alpha) \f$
30///
31/// @return @a ratSqrfFactorize returns a list of monic factors, the first
32///         element is the leading coefficient.
33#ifdef HAVE_NTL
34inline
35CFList
36ratSqrfFactorize (const CanonicalForm & G,        ///<[in] a multivariate poly
37                  const Variable& v= Variable (1) ///<[in] algebraic variable
38                 )
39{
40  if (getNumVars (G) == 2)
41    return ratBiSqrfFactorize (G, v);
42  CanonicalForm F= G;
43  if (isOn (SW_RATIONAL))
44    F *= bCommonDen (F);
45  CFList result= multiFactorize (F, v);
46  if (isOn (SW_RATIONAL))
47  {
48    normalize (result);
49    result.insert (Lc(F));
50  }
51  return result;
52}
53
54/// factorize a multivariate polynomial over \f$ Q(\alpha) \f$
55///
56/// @return @a ratFactorize returns a list of monic factors with
57///         multiplicity, the first element is the leading coefficient.
58inline
59CFFList
60ratFactorize (const CanonicalForm& G,          ///<[in] a multivariate poly
61              const Variable& v= Variable (1), ///<[in] algebraic variable
62              bool substCheck= true            ///<[in] enables substitute check
63             )
64{
65  if (getNumVars (G) == 2)
66  {
67    CFFList result= ratBiFactorize (G,v);
68    return result;
69  }
70  CanonicalForm F= G;
71
72  if (substCheck)
73  {
74    bool foundOne= false;
75    int * substDegree= new int [F.level()];
76    for (int i= 1; i <= F.level(); i++)
77    {
78      if (degree (F, i) > 0)
79      {
80        substDegree[i-1]= substituteCheck (F, Variable (i));
81        if (substDegree [i-1] > 1)
82        {
83          foundOne= true;
84          subst (F, F, substDegree[i-1], Variable (i));
85        }
86      }
87      else
88        substDegree[i-1]= -1;
89    }
90    if (foundOne)
91    {
92      CFFList result= ratFactorize (F, v, false);
93      CFFList newResult, tmp;
94      CanonicalForm tmp2;
95      newResult.insert (result.getFirst());
96      result.removeFirst();
97      for (CFFListIterator i= result; i.hasItem(); i++)
98      {
99        tmp2= i.getItem().factor();
100        for (int j= 1; j <= G.level(); j++)
101        {
102          if (substDegree[j-1] > 1)
103            tmp2= reverseSubst (tmp2, substDegree[j-1], Variable (j));
104        }
105        tmp= ratFactorize (tmp2, v, false);
106        tmp.removeFirst();
107        for (CFFListIterator j= tmp; j.hasItem(); j++)
108          newResult.append (CFFactor (j.getItem().factor(),
109                                      j.getItem().exp()*i.getItem().exp()));
110      }
111      delete [] substDegree;
112      return newResult;
113    }
114    delete [] substDegree;
115  }
116
117  CanonicalForm LcF= Lc (F);
118  if (isOn (SW_RATIONAL))
119    F *= bCommonDen (F);
120
121  CFFList result;
122  CFFList sqrfFactors= sqrFree (F);
123  for (CFFListIterator i= sqrfFactors; i.hasItem(); i++)
124  {
125    CFList tmp= ratSqrfFactorize (i.getItem().factor(), v);
126    for (CFListIterator j= tmp; j.hasItem(); j++)
127    {
128      if (j.getItem().inCoeffDomain()) continue;
129      result.append (CFFactor (j.getItem(), i.getItem().exp()));
130    }
131  }
132  if (isOn (SW_RATIONAL))
133  {
134    normalize (result);
135    if (v.level() == 1)
136    {
137      for (CFFListIterator i= result; i.hasItem(); i++)
138      {
139        LcF /= power (bCommonDen (i.getItem().factor()), i.getItem().exp());
140        i.getItem()= CFFactor (i.getItem().factor()*
141                     bCommonDen(i.getItem().factor()), i.getItem().exp());
142      }
143    }
144    result.insert (CFFactor (LcF, 1));
145  }
146  return result;
147}
148#endif
149
150#endif
151
Note: See TracBrowser for help on using the repository browser.