source: git/factory/facFactorize.h @ a8a93f

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