source: git/factory/facFactorize.h

spielwiese
Last change on this file was 91bc52, checked in by Daniel Schultz <tthsqe12@…>, 3 years ago
add flint code for diophantineQa and fix convertFacCF2Fq_t
  • Property mode set to 100644
File size: 5.4 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 **/
11/*****************************************************************************/
12
13#ifndef FAC_FACTORIZE_H
14#define FAC_FACTORIZE_H
15
[3c702a]16// #include "config.h"
[0851b0]17#include "timing.h"
[ab547e2]18
19#include "facBivar.h"
20#include "facFqBivarUtil.h"
21
[0851b0]22TIMING_DEFINE_PRINT (fac_squarefree)
23TIMING_DEFINE_PRINT (fac_factor_squarefree)
24
[091b250]25/// Factorization of A wrt. to different second vars
26void
27factorizationWRTDifferentSecondVars (
28                          const CanonicalForm& A, ///<[in] poly
29                          CFList*& Aeval,         ///<[in,out] A evaluated wrt.
30                                                  ///< different second vars
31                                                  ///< returns bivariate factors
32                          int& minFactorsLength,  ///<[in,out] minimal length of
33                                                  ///< bivariate factors
34                          bool& irred,            ///<[in,out] Is A irreducible?
35                          const Variable& w       ///<[in] alg. variable
36                                    );
37
[ab547e2]38/// Factorization over Q (a)
39///
40/// @return @a multiFactorize returns a factorization of F
41CFList
[d46cb6]42multiFactorize (const CanonicalForm& F,     ///< [in] sqrfree poly
[ab547e2]43                const Variable& v           ///< [in] some algebraic variable
44               );
[91bc52]45
46#if defined(HAVE_NTL) || defined(HAVE_FLINT) // ratBiSqrfFactorize
[ab547e2]47/// factorize a squarefree multivariate polynomial over \f$ Q(\alpha) \f$
48///
49/// @return @a ratSqrfFactorize returns a list of monic factors, the first
50///         element is the leading coefficient.
51inline
[f9b796e]52CFList
[530295]53ratSqrfFactorize (const CanonicalForm & G,        ///<[in] a multivariate poly
54                  const Variable& v= Variable (1) ///<[in] algebraic variable
[f9b796e]55                 )
[ab547e2]56{
[5f9b47]57  if (getNumVars (G) == 2)
58    return ratBiSqrfFactorize (G, v);
59  CanonicalForm F= G;
60  if (isOn (SW_RATIONAL))
61    F *= bCommonDen (F);
[ab547e2]62  CFList result= multiFactorize (F, v);
63  if (isOn (SW_RATIONAL))
64  {
65    normalize (result);
66    result.insert (Lc(F));
67  }
68  return result;
69}
[a0efc8]70#endif
[ab547e2]71
[91bc52]72#if defined(HAVE_NTL) || defined(HAVE_FLINT) // multiFactorize, henselLiftAndEarly, nonMonicHenselLift
[ab547e2]73/// factorize a multivariate polynomial over \f$ Q(\alpha) \f$
74///
75/// @return @a ratFactorize returns a list of monic factors with
76///         multiplicity, the first element is the leading coefficient.
77inline
[f9b796e]78CFFList
[530295]79ratFactorize (const CanonicalForm& G,          ///<[in] a multivariate poly
80              const Variable& v= Variable (1), ///<[in] algebraic variable
81              bool substCheck= true            ///<[in] enables substitute check
[f9b796e]82             )
[ab547e2]83{
[5f9b47]84  if (getNumVars (G) == 2)
[ab547e2]85  {
[5f9b47]86    CFFList result= ratBiFactorize (G,v);
[ab547e2]87    return result;
88  }
[5f9b47]89  CanonicalForm F= G;
[f9b796e]90
91  if (substCheck)
92  {
93    bool foundOne= false;
94    int * substDegree= new int [F.level()];
95    for (int i= 1; i <= F.level(); i++)
96    {
97      if (degree (F, i) > 0)
98      {
99        substDegree[i-1]= substituteCheck (F, Variable (i));
100        if (substDegree [i-1] > 1)
101        {
102          foundOne= true;
103          subst (F, F, substDegree[i-1], Variable (i));
104        }
105      }
106      else
107        substDegree[i-1]= -1;
108    }
109    if (foundOne)
110    {
111      CFFList result= ratFactorize (F, v, false);
112      CFFList newResult, tmp;
113      CanonicalForm tmp2;
114      newResult.insert (result.getFirst());
115      result.removeFirst();
116      for (CFFListIterator i= result; i.hasItem(); i++)
117      {
118        tmp2= i.getItem().factor();
119        for (int j= 1; j <= G.level(); j++)
120        {
121          if (substDegree[j-1] > 1)
122            tmp2= reverseSubst (tmp2, substDegree[j-1], Variable (j));
123        }
124        tmp= ratFactorize (tmp2, v, false);
125        tmp.removeFirst();
126        for (CFFListIterator j= tmp; j.hasItem(); j++)
127          newResult.append (CFFactor (j.getItem().factor(),
128                                      j.getItem().exp()*i.getItem().exp()));
129      }
130      delete [] substDegree;
131      return newResult;
132    }
133    delete [] substDegree;
134  }
135
[ab547e2]136  CanonicalForm LcF= Lc (F);
[5f9b47]137  if (isOn (SW_RATIONAL))
138    F *= bCommonDen (F);
[ab547e2]139
140  CFFList result;
[0851b0]141  TIMING_START (fac_squarefree);
[5f9b47]142  CFFList sqrfFactors= sqrFree (F);
[0851b0]143  TIMING_END_AND_PRINT (fac_squarefree,
144                        "time for squarefree factorization over Q: ");
145
146  CFList tmp;
[5f9b47]147  for (CFFListIterator i= sqrfFactors; i.hasItem(); i++)
148  {
[0851b0]149    TIMING_START (fac_factor_squarefree);
150    tmp= ratSqrfFactorize (i.getItem().factor(), v);
151    TIMING_END_AND_PRINT (fac_factor_squarefree,
152                          "time to factorize sqrfree factor over Q: ");
[5f9b47]153    for (CFListIterator j= tmp; j.hasItem(); j++)
154    {
155      if (j.getItem().inCoeffDomain()) continue;
156      result.append (CFFactor (j.getItem(), i.getItem().exp()));
157    }
158  }
[ab547e2]159  if (isOn (SW_RATIONAL))
160  {
161    normalize (result);
[a8a93f]162    if (v.level() == 1)
163    {
164      for (CFFListIterator i= result; i.hasItem(); i++)
165      {
[ed66770]166        LcF /= power (bCommonDen (i.getItem().factor()), i.getItem().exp());
[a8a93f]167        i.getItem()= CFFactor (i.getItem().factor()*
168                     bCommonDen(i.getItem().factor()), i.getItem().exp());
169      }
170    }
[ab547e2]171    result.insert (CFFactor (LcF, 1));
172  }
173  return result;
174}
[d990001]175#endif
[815e70]176#endif
[ab547e2]177
Note: See TracBrowser for help on using the repository browser.