My Project  UNKNOWN_GIT_VERSION
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 
SW_RATIONAL
static const int SW_RATIONAL
set to 1 for computations over Q
Definition: cf_defs.h:28
isOn
bool isOn(int sw)
switches
Definition: canonicalform.cc:1912
isZero
bool isZero(const CFArray &A)
checks if entries of A are zero
Definition: facSparseHensel.h:468
f
FILE * f
Definition: checklibs.c:9
canonicalform.h
icontent
CanonicalForm icontent(const CanonicalForm &f)
CanonicalForm icontent ( const CanonicalForm & f )
Definition: cf_gcd.cc:71
y
const CanonicalForm int const CFList const Variable & y
Definition: facAbsFact.cc:57
result
return result
Definition: facAbsBiFact.cc:76
CFMap
class CFMap
Definition: cf_map.h:85
g
g
Definition: cfModGcd.cc:4031
sign
static int sign(int x)
Definition: ring.cc:3346
deriv
CanonicalForm deriv(const CanonicalForm &f, const Variable &x)
Definition: canonicalform.h:339
w
const CanonicalForm & w
Definition: facAbsFact.cc:55
b
CanonicalForm b
Definition: cfModGcd.cc:4044
sqrFreeZ
CFFList sqrFreeZ(const CanonicalForm &a)
Definition: fac_sqrfree.cc:45
CanonicalForm
factory's main class
Definition: canonicalform.h:83
sqrfPart
CanonicalForm sqrfPart(const CanonicalForm &F)
squarefree part of a poly
Definition: fac_sqrfree.cc:111
CanonicalForm::isOne
CF_NO_INLINE bool isOne() const
CF_INLINE bool CanonicalForm::isOne, isZero () const.
Definition: cf_inline.cc:354
i
int i
Definition: cfEzgcd.cc:125
Lc
CanonicalForm Lc(const CanonicalForm &f)
Definition: canonicalform.h:300
M
#define M
Definition: sirandom.c:24
buf
int status int void * buf
Definition: si_signals.h:59
content
CanonicalForm content(const CanonicalForm &)
CanonicalForm content ( const CanonicalForm & f )
Definition: cf_gcd.cc:175
lc
CanonicalForm lc(const CanonicalForm &f)
Definition: canonicalform.h:297
cf_defs.h
CanonicalForm::deriv
CanonicalForm deriv() const
deriv() - return the formal derivation of CO.
Definition: canonicalform.cc:1235
compress
CanonicalForm compress(const CanonicalForm &f, CFMap &m)
CanonicalForm compress ( const CanonicalForm & f, CFMap & m )
Definition: cf_map.cc:210
cf_algorithm.h
sortCFFList
CFFList sortCFFList(CFFList &F)
Definition: fac_sqrfree.cc:21
ListIterator::hasItem
int hasItem()
Definition: ftmpl_list.cc:439
exp
gmp_float exp(const gmp_float &a)
Definition: mpr_complex.cc:358
Factor
Definition: ftmpl_factor.h:18
cf_map.h
bCommonDen
CanonicalForm bCommonDen(const CanonicalForm &f)
CanonicalForm bCommonDen ( const CanonicalForm & f )
Definition: cf_algorithm.cc:293
CanonicalForm::inCoeffDomain
bool inCoeffDomain() const
Definition: canonicalform.cc:119
compareFactors
static int compareFactors(const CFFactor &f, const CFFactor &g)
Definition: fac_sqrfree.cc:15
Variable
factory's class for variables
Definition: factory.h:118
ListIterator::getItem
T & getItem() const
Definition: ftmpl_list.cc:431
CanonicalForm::mvar
Variable mvar() const
mvar() returns the main variable of CO or Variable() if CO is in a base domain.
Definition: canonicalform.cc:560
cf_assert.h
Union
template List< Variable > Union(const List< Variable > &, const List< Variable > &)
gcd
int gcd(int a, int b)
Definition: walkSupport.cc:836
v
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:37
List
Definition: ftmpl_list.h:20
CFFactor
Factor< CanonicalForm > CFFactor
Definition: canonicalform.h:385
List::append
void append(const T &)
Definition: ftmpl_list.cc:256
A
#define A
Definition: sirandom.c:23
degree
int degree(const CanonicalForm &f)
Definition: canonicalform.h:309
List::insert
void insert(const T &)
Definition: ftmpl_list.cc:193
List::sort
void sort(int(*)(const T &, const T &))
Definition: ftmpl_list.cc:339
ListIterator
Definition: ftmpl_list.h:17