# source:git/factory/facFactorize.h@f9b796e

spielwiese
Last change on this file since f9b796e was f9b796e, checked in by Martin Lee <martinlee84@…>, 12 years ago
chg: substitution in the top level routines
• Property mode set to 100644
File size: 3.8 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 * @internal @version \$Id$
11 *
12 **/
13/*****************************************************************************/
14
15#ifndef FAC_FACTORIZE_H
16#define FAC_FACTORIZE_H
17
18// #include "config.h"
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.
35#ifdef HAVE_NTL
36inline
37CFList
38ratSqrfFactorize (const CanonicalForm & G,       ///<[in] a multivariate poly
39                  const Variable& v              ///<[in] algebraic variable
40                 )
41{
42  if (getNumVars (G) == 2)
43    return ratBiSqrfFactorize (G, v);
44  CanonicalForm F= G;
45  if (isOn (SW_RATIONAL))
46    F *= bCommonDen (F);
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
61CFFList
62ratFactorize (const CanonicalForm& G,        ///<[in] a multivariate poly
63              const Variable& v,             ///<[in] algebraic variable
64              bool substCheck= true          ///<[in] enables substitute check
65             )
66{
67  if (getNumVars (G) == 2)
68  {
69    CFFList result= ratBiFactorize (G,v);
70    return result;
71  }
72  CanonicalForm F= G;
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
119  CanonicalForm LcF= Lc (F);
120  if (isOn (SW_RATIONAL))
121    F *= bCommonDen (F);
122
123  CFFList result;
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  }
134  if (isOn (SW_RATIONAL))
135  {
136    normalize (result);
137    result.insert (CFFactor (LcF, 1));
138  }
139  return result;
140}
141#endif
142
143#endif
144
Note: See TracBrowser for help on using the repository browser.