fac_sqrfree.cc
Go to the documentation of this file.
1 /* emacs edit mode for this file is -*- C++ -*- */
2 
3 
4 #include "config.h"
5 
6 
7 #include "cf_assert.h"
8 
9 #include "cf_defs.h"
10 #include "canonicalform.h"
11 #include "cf_map.h"
12 #include "cf_algorithm.h"
13 
14 static int
15 compareFactors( const CFFactor & f, const CFFactor & g )
16 {
17  return f.exp() > g.exp();
18 }
19 
20 CFFList
22 {
23  F.sort( compareFactors );
24 
25  int exp;
27  CFFListIterator I = F;
29 
30  // join elements with the same degree
31  while ( I.hasItem() ) {
32  f = I.getItem().factor();
33  exp = I.getItem().exp();
34  I++;
35  while ( I.hasItem() && I.getItem().exp() == exp ) {
36  f *= I.getItem().factor();
37  I++;
38  }
39  result.append( CFFactor( f, exp ) );
40  }
41 
42  return result;
43 }
44 
46 {
47  if ( a.inCoeffDomain() )
48  return CFFactor( a, 1 );
49  CanonicalForm aa, LcA;
50  if (isOn (SW_RATIONAL))
51  {
52  LcA= bCommonDen (a);
53  aa= a*LcA;
54  }
55  else
56  {
57  LcA= icontent (a);
58  if (lc (a).sign() < 0)
59  LcA= -LcA;
60  aa= a/LcA;
61  }
62  CanonicalForm cont = content( aa );
63  aa /= cont;
64  CanonicalForm b = aa.deriv(), c = gcd( aa, b );
65  CanonicalForm y, z, w = aa / c;
66  int i = 1;
67  CFFList F;
68  Variable v = aa.mvar();
69  CanonicalForm lcinv;
70  while ( c.degree(v) != 0 )
71  {
72  y = gcd( w, c ); z = w / y;
73  if ( degree( z, v ) > 0 )
74  {
75  if (isOn (SW_RATIONAL))
76  {
77  lcinv= 1/Lc (z);
78  z *= lcinv;
79  z *= bCommonDen (z);
80  }
81  if (lc (z).sign() < 0)
82  z= -z;
83  F.append( CFFactor( z, i ) );
84  }
85  i++;
86  w = y; c = c / y;
87  }
88  if ( degree( w,v ) > 0 )
89  {
90  if (isOn (SW_RATIONAL))
91  {
92  lcinv= 1/Lc (w);
93  w *= lcinv;
94  w *= bCommonDen (w);
95  }
96  if (lc (w).sign() < 0)
97  w= -w;
98  F.append( CFFactor( w, i ) );
99  }
100  if ( ! cont.isOne() )
101  {
102  CFFList buf= sqrFreeZ (cont);
103  buf.removeFirst();
104  F = Union( F, buf );
105  }
106  F.insert (CFFactor (LcA, 1));
107  return F;
108 }
109 
112 {
113  if (F.inCoeffDomain())
114  return F;
115  CFMap M;
116  CanonicalForm A= compress (F, M);
117  CanonicalForm w, v, b;
119  int i= 1;
120  for (; i <= A.level(); i++)
121  {
122  if (!deriv (A, Variable (i)).isZero())
123  break;
124  }
125 
126  w= gcd (A, deriv (A, Variable (i)));
127  b= A/w;
128  result= b;
129  if (degree (w) < 1)
130  return M (result);
131  i++;
132  for (; i <= A.level(); i++)
133  {
134  if (!deriv (w, Variable (i)).isZero())
135  {
136  b= w;
137  w= gcd (w, deriv (w, Variable (i)));
138  b /= w;
139  if (degree (b) < 1)
140  break;
141  CanonicalForm g= gcd (b, result);
142  if (degree (g) > 0)
143  result *= b/g;
144  if (degree (g) <= 0)
145  result *= b;
146  }
147  }
148  result= M (result);
149  return result;
150 }
151 
const CanonicalForm int const CFList const Variable & y
Definition: facAbsFact.cc:57
CanonicalForm icontent(const CanonicalForm &f)
CanonicalForm icontent ( const CanonicalForm & f )
Definition: cf_gcd.cc:71
int exp() const
Definition: ftmpl_factor.h:33
Variable mvar() const
mvar() returns the main variable of CO or Variable() if CO is in a base domain.
const poly a
Definition: syzextra.cc:212
bool inCoeffDomain() const
CanonicalForm deriv(const CanonicalForm &f, const Variable &x)
CFFList sqrFreeZ(const CanonicalForm &a)
Definition: fac_sqrfree.cc:45
factory's class for variables
Definition: variable.h:32
factory's main class
Definition: canonicalform.h:75
assertions for Factory
g
Definition: cfModGcd.cc:4031
CanonicalForm sqrfPart(const CanonicalForm &F)
squarefree part of a poly
Definition: fac_sqrfree.cc:111
CF_NO_INLINE bool isZero() const
Definition: cf_inline.cc:372
void insert(const T &)
Definition: ftmpl_list.cc:193
CanonicalForm deriv() const
deriv() - return the formal derivation of CO.
CanonicalForm Lc(const CanonicalForm &f)
CanonicalForm compress(const CanonicalForm &f, CFMap &m)
CanonicalForm compress ( const CanonicalForm & f, CFMap & m )
Definition: cf_map.cc:210
void removeFirst()
Definition: ftmpl_list.cc:287
map polynomials
CF_NO_INLINE bool isOne() const
CF_INLINE bool CanonicalForm::isOne, isZero () const.
Definition: cf_inline.cc:354
CanonicalForm content(const CanonicalForm &)
CanonicalForm content ( const CanonicalForm & f )
Definition: cf_gcd.cc:180
int level() const
level() returns the level of CO.
CanonicalForm lc(const CanonicalForm &f)
template List< Variable > Union(const List< Variable > &, const List< Variable > &)
#define M
Definition: sirandom.c:24
int status int void * buf
Definition: si_signals.h:59
#define A
Definition: sirandom.c:23
static const int SW_RATIONAL
set to 1 for computations over Q
Definition: cf_defs.h:28
bool isOn(int sw)
switches
FILE * f
Definition: checklibs.c:7
int i
Definition: cfEzgcd.cc:123
factory switches.
declarations of higher level algorithms.
CanonicalForm bCommonDen(const CanonicalForm &f)
CanonicalForm bCommonDen ( const CanonicalForm & f )
static int compareFactors(const CFFactor &f, const CFFactor &g)
Definition: fac_sqrfree.cc:15
class CFMap
Definition: cf_map.h:84
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:37
T & getItem() const
Definition: ftmpl_list.cc:431
Factor< CanonicalForm > CFFactor
int gcd(int a, int b)
Definition: walkSupport.cc:839
CFFList sortCFFList(CFFList &F)
Definition: fac_sqrfree.cc:21
const CanonicalForm & w
Definition: facAbsFact.cc:55
p exp[i]
Definition: DebugPrint.cc:39
void append(const T &)
Definition: ftmpl_list.cc:256
int degree(const CanonicalForm &f)
const poly b
Definition: syzextra.cc:213
return result
Definition: facAbsBiFact.cc:76
int sign(const CanonicalForm &a)
Header for factory's main class CanonicalForm.
void sort(int(*)(const T &, const T &))
Definition: ftmpl_list.cc:339