My Project  debian-1:4.1.1-p2+ds-4build4
Public Member Functions | Static Public Attributes | Private Member Functions | Static Private Member Functions | Private Attributes | Friends
InternalPoly Class Reference

factory's class for polynomials More...

#include <int_poly.h>

Public Member Functions

 InternalPoly ()
 
 InternalPoly (const Variable &v, const int e, const CanonicalForm &c)
 
 InternalPoly (const InternalPoly &)
 
 ~InternalPoly ()
 
InternalCFdeepCopyObject () const
 
const char * classname () const
 
int level () const
 
Variable variable () const
 
int degree ()
 int InternalPoly::degree () More...
 
CanonicalForm lc ()
 
CanonicalForm Lc ()
 
CanonicalForm LC ()
 
int taildegree ()
 
CanonicalForm tailcoeff ()
 CanonicalForm InternalPoly::tailcoeff (), int InternalPoly::taildegree () More...
 
CanonicalForm coeff (int i)
 CanonicalForm InternalPoly::coeff ( int i ) More...
 
void print (OSTREAM &, char *)
 
bool inBaseDomain () const
 
bool inExtension () const
 
bool inCoeffDomain () const
 
bool inPolyDomain () const
 
bool inQuotDomain () const
 
InternalCFgenZero ()
 
InternalCFgenOne ()
 
bool isUnivariate () const
 
InternalCFneg ()
 InternalCF * InternalPoly::neg () More...
 
InternalCFinvert ()
 
InternalCFtryInvert (const CanonicalForm &, bool &)
 
int comparesame (InternalCF *)
 comparesame(), comparecoeff() - compare with an InternalPoly. More...
 
InternalCFaddsame (InternalCF *)
 
InternalCFsubsame (InternalCF *)
 
InternalCFmulsame (InternalCF *)
 
InternalCFtryMulsame (InternalCF *, const CanonicalForm &)
 
InternalCFdividesame (InternalCF *)
 
InternalCFmodulosame (InternalCF *)
 
InternalCFdivsame (InternalCF *)
 
InternalCFtryDivsame (InternalCF *, const CanonicalForm &, bool &)
 
InternalCFmodsame (InternalCF *)
 
void divremsame (InternalCF *, InternalCF *&, InternalCF *&)
 
bool divremsamet (InternalCF *, InternalCF *&, InternalCF *&)
 
bool tryDivremsamet (InternalCF *, InternalCF *&, InternalCF *&, const CanonicalForm &, bool &)
 
int comparecoeff (InternalCF *)
 comparecoeff() always returns 1 since CO is defined to be larger than anything which is a coefficient w.r.t. More...
 
InternalCFaddcoeff (InternalCF *)
 
InternalCFsubcoeff (InternalCF *, bool)
 
InternalCFmulcoeff (InternalCF *)
 
InternalCFdividecoeff (InternalCF *, bool)
 
InternalCFtryDividecoeff (InternalCF *, bool, const CanonicalForm &, bool &)
 
InternalCFmodulocoeff (InternalCF *, bool)
 
InternalCFdivcoeff (InternalCF *, bool)
 
InternalCFtryDivcoeff (InternalCF *, bool, const CanonicalForm &, bool &)
 
InternalCFmodcoeff (InternalCF *, bool)
 
void divremcoeff (InternalCF *, InternalCF *&, InternalCF *&, bool)
 
bool divremcoefft (InternalCF *, InternalCF *&, InternalCF *&, bool)
 
bool tryDivremcoefft (InternalCF *, InternalCF *&, InternalCF *&, bool, const CanonicalForm &, bool &)
 
int sign () const
 int InternalPoly::sign () const More...
 
void * operator new (size_t)
 
void operator delete (void *addr, size_t)
 
- Public Member Functions inherited from InternalCF
 InternalCF ()
 
 InternalCF (const InternalCF &)
 
virtual ~InternalCF ()
 
int deleteObject ()
 
InternalCFcopyObject ()
 
virtual int levelcoeff () const
 
virtual int type () const
 
virtual bool isZero () const
 
virtual bool isOne () const
 bool InternalCF::isOne, isZero () const More...
 
virtual long intval () const
 
virtual int intmod (int) const
 
virtual InternalCFnum ()
 InternalCF * InternalCF::num (), den () More...
 
virtual InternalCFden ()
 
virtual InternalCFbgcdsame (const InternalCF *const) const
 InternalCF * InternalCF::bgcdsame, bgcdcoeff ( const InternalCF * const ) More...
 
virtual InternalCFbgcdcoeff (const InternalCF *const)
 
virtual InternalCFbextgcdsame (InternalCF *, CanonicalForm &, CanonicalForm &)
 InternalCF * InternalCF::bextgcdsame ( InternalCF *, CanonicalForm & a, CanonicalForm & b ) More...
 
virtual InternalCFbextgcdcoeff (InternalCF *, CanonicalForm &, CanonicalForm &)
 
virtual InternalCFsqrt ()
 InternalCF * InternalCF::sqrt () More...
 
virtual int ilog2 ()
 int InternalCF::ilog2 () More...
 
- Public Member Functions inherited from omallocClass
void * operator new (size_t size) throw (std::bad_alloc)
 
void operator delete (void *block) throw ()
 
void * operator new[] (size_t size) throw (std::bad_alloc)
 
void operator delete[] (void *block) throw ()
 
void * operator new (size_t size, const std::nothrow_t &) throw ()
 
void * operator new[] (size_t size, const std::nothrow_t &) throw ()
 

Static Public Attributes

static const omBin InternalPoly_bin = omGetSpecBin(sizeof(InternalPoly))
 

Private Member Functions

 InternalPoly (termList, termList, const Variable &)
 

Static Private Member Functions

static termList copyTermList (termList, termList &, bool negate=false)
 
static termList deepCopyTermList (termList, termList &)
 
static void freeTermList (termList)
 
static void negateTermList (termList)
 
static termList addTermList (termList, termList, termList &, bool negate)
 
static void mulTermList (termList, const CanonicalForm &, const int)
 
static termList divideTermList (termList, const CanonicalForm &, termList &)
 
static termList divTermList (termList, const CanonicalForm &, termList &)
 
static termList tryDivTermList (termList, const CanonicalForm &, termList &, const CanonicalForm &, bool &)
 
static termList modTermList (termList, const CanonicalForm &, termList &)
 
static void appendTermList (termList &, termList &, const CanonicalForm &, const int)
 
static termList mulAddTermList (termList theList, termList aList, const CanonicalForm &c, const int exp, termList &lastTerm, bool negate)
 
static termList reduceTermList (termList first, termList redterms, termList &last)
 

Private Attributes

termList firstTerm
 
termList lastTerm
 
Variable var
 

Friends

class CFIterator
 

Additional Inherited Members

- Protected Member Functions inherited from InternalCF
int getRefCount ()
 
void incRefCount ()
 
int decRefCount ()
 

Detailed Description

factory's class for polynomials

polynomials are represented as a linked list termList, factory uses a sparse distributive representation of polynomials, i.e. each poly is viewed as a univariate poly in its main variable CanonicalForm::mvar() over a (polynomial) ring

Definition at line 71 of file int_poly.h.

Constructor & Destructor Documentation

◆ InternalPoly() [1/4]

InternalPoly::InternalPoly ( termList  first,
termList  last,
const Variable v 
)
private

Definition at line 38 of file int_poly.cc.

39 {
40  firstTerm = first;
41  lastTerm = last;
42  var = v;
43 }
Variable var
Definition: int_poly.h:74
termList firstTerm
Definition: int_poly.h:73
termList lastTerm
Definition: int_poly.h:73
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:37
static poly last
Definition: hdegree.cc:1077

◆ InternalPoly() [2/4]

InternalPoly::InternalPoly ( )

Definition at line 45 of file int_poly.cc.

46 {
47  ASSERT( 0, "ups, why do you initialize an empty poly" );
48 }
#define ASSERT(expression, message)
Definition: cf_assert.h:99

◆ InternalPoly() [3/4]

InternalPoly::InternalPoly ( const Variable v,
const int  e,
const CanonicalForm c 
)

Definition at line 50 of file int_poly.cc.

51 {
52  var = v;
53  firstTerm = new term( 0, c, e );
55 }
Definition: int_poly.h:33

◆ InternalPoly() [4/4]

InternalPoly::InternalPoly ( const InternalPoly )

Definition at line 57 of file int_poly.cc.

57  :InternalCF()
58 {
59  ASSERT( 0, "ups there is something wrong in your code" );
60 }
InternalCF()
Definition: int_cf.h:55

◆ ~InternalPoly()

InternalPoly::~InternalPoly ( )

Definition at line 62 of file int_poly.cc.

63 {
65 }
static void freeTermList(termList)
Definition: int_poly.cc:1890

Member Function Documentation

◆ addcoeff()

InternalCF * InternalPoly::addcoeff ( InternalCF cc)
virtual

Reimplemented from InternalCF.

Definition at line 1030 of file int_poly.cc.

1031 {
1032  CanonicalForm c( is_imm(cc) ? cc : cc->copyObject() );
1033  if ( c.isZero() )
1034  return this;
1035  else
1036  {
1037  if ( getRefCount() <= 1 )
1038  {
1039  if ( lastTerm->exp == 0 )
1040  {
1041  lastTerm->coeff += c;
1042  if ( lastTerm->coeff.isZero() )
1043  {
1044  termList cursor = firstTerm;
1045  while ( cursor->next != lastTerm )
1046  cursor = cursor->next;
1047  delete lastTerm;
1048  cursor->next = 0;
1049  lastTerm = cursor;
1050  }
1051  }
1052  else
1053  {
1054  lastTerm->next = new term( 0, c, 0 );
1055  lastTerm = lastTerm->next;
1056  }
1057  return this;
1058  }
1059  else
1060  {
1061  decRefCount();
1062  termList last, first = copyTermList( firstTerm, last, false );
1063  if ( last->exp == 0 )
1064  {
1065  last->coeff += c;
1066  if ( last->coeff.isZero() )
1067  {
1068  termList cursor = first;
1069  while ( cursor->next != last )
1070  cursor = cursor->next;
1071  delete last;
1072  cursor->next = 0;
1073  last = cursor;
1074  }
1075  }
1076  else
1077  {
1078  last->next = new term( 0, c, 0L );
1079  last = last->next;
1080  }
1081  return new InternalPoly( first, last, var );
1082  }
1083  }
1084 }
int is_imm(const InternalCF *const ptr)
Definition: canonicalform.h:62
factory's main class
Definition: canonicalform.h:83
CF_NO_INLINE bool isZero() const
Definition: cf_inline.cc:372
int getRefCount()
Definition: int_cf.h:51
int decRefCount()
Definition: int_cf.h:53
InternalCF * copyObject()
Definition: int_cf.h:62
static termList copyTermList(termList, termList &, bool negate=false)
Definition: int_poly.cc:1822
term * next
Definition: int_poly.h:35
CanonicalForm coeff
Definition: int_poly.h:36
int exp
Definition: int_poly.h:37

◆ addsame()

InternalCF * InternalPoly::addsame ( InternalCF aCoeff)
virtual

Reimplemented from InternalCF.

Definition at line 278 of file int_poly.cc.

279 {
280  InternalPoly * aPoly = (InternalPoly*)aCoeff;
281  if ( getRefCount() <= 1 )
282  {
283  firstTerm = addTermList( firstTerm, aPoly->firstTerm, lastTerm, false );
284  if ( firstTerm && firstTerm->exp != 0 )
285  return this;
286  else if ( firstTerm )
287  {
289  delete this;
290  return res;
291  }
292  else
293  {
294  delete this;
295  return CFFactory::basic( 0L );
296  }
297  }
298  else
299  {
300  decRefCount();
301  termList last, first = copyTermList( firstTerm, last );
302  first = addTermList( first, aPoly->firstTerm, last, false );
303  if ( first && first->exp != 0 )
304  return new InternalPoly( first, last, var );
305  else if ( first )
306  {
307  InternalCF * res = first->coeff.getval();
308  delete first;
309  return res;
310  }
311  else
312  return CFFactory::basic( 0L );
313 
314  }
315 }
static InternalCF * basic(long value)
Definition: cf_factory.cc:30
InternalCF * getval() const
virtual class for internal CanonicalForm's
Definition: int_cf.h:47
factory's class for polynomials
Definition: int_poly.h:71
static termList addTermList(termList, termList, termList &, bool negate)
Definition: int_poly.cc:1914
CanonicalForm res
Definition: facAbsFact.cc:64

◆ addTermList()

termList InternalPoly::addTermList ( termList  theList,
termList  aList,
termList lastTerm,
bool  negate 
)
staticprivate

Definition at line 1914 of file int_poly.cc.

1915 {
1916  termList theCursor = theList;
1917  termList aCursor = aList;
1918  termList predCursor = 0;
1919 
1920  while ( theCursor && aCursor )
1921  {
1922  if ( theCursor->exp == aCursor->exp )
1923  {
1924  if ( negate )
1925  theCursor->coeff -= aCursor->coeff;
1926  else
1927  theCursor->coeff += aCursor->coeff;
1928  if ( theCursor->coeff.isZero() )
1929  {
1930  if ( predCursor )
1931  {
1932  predCursor->next = theCursor->next;
1933  delete theCursor;
1934  theCursor = predCursor->next;
1935  }
1936  else
1937  {
1938  theList = theList->next;
1939  delete theCursor;
1940  theCursor = theList;
1941  }
1942  }
1943  else
1944  {
1945  predCursor = theCursor;
1946  theCursor = theCursor->next;
1947  }
1948  aCursor = aCursor->next;
1949  }
1950  else if ( theCursor->exp < aCursor->exp )
1951  {
1952  if ( negate )
1953  if ( predCursor )
1954  {
1955  predCursor->next = new term( theCursor, -aCursor->coeff, aCursor->exp );
1956  predCursor = predCursor->next;
1957  }
1958  else
1959  {
1960  theList = new term( theCursor, -aCursor->coeff, aCursor->exp );
1961  predCursor = theList;
1962  }
1963  else
1964  if ( predCursor )
1965  {
1966  predCursor->next = new term( theCursor, aCursor->coeff, aCursor->exp );
1967  predCursor = predCursor->next;
1968  }
1969  else
1970  {
1971  theList = new term( theCursor, aCursor->coeff, aCursor->exp );
1972  predCursor = theList;
1973  }
1974  aCursor = aCursor->next;
1975  }
1976  else
1977  {
1978  predCursor = theCursor;
1979  theCursor = theCursor->next;
1980  }
1981  }
1982  if ( aCursor )
1983  {
1984  if ( predCursor )
1985  predCursor->next = copyTermList( aCursor, lastTerm, negate );
1986  else
1987  theList = copyTermList( aCursor, lastTerm, negate );
1988  }
1989  else if ( ! theCursor )
1990  lastTerm = predCursor;
1991 
1992  return theList;
1993 }

◆ appendTermList()

void InternalPoly::appendTermList ( termList first,
termList last,
const CanonicalForm coeff,
const int  exp 
)
staticprivate

Definition at line 2125 of file int_poly.cc.

2126 {
2127  if ( last )
2128  {
2129  last->next = new term( 0, coeff, exp );
2130  last = last->next;
2131  }
2132  else
2133  {
2134  first = new term( 0, coeff, exp );
2135  last = first;
2136  }
2137 }
CanonicalForm coeff(int i)
CanonicalForm InternalPoly::coeff ( int i )
Definition: int_poly.cc:154
gmp_float exp(const gmp_float &a)
Definition: mpr_complex.cc:358

◆ classname()

const char* InternalPoly::classname ( ) const
inlinevirtual

Reimplemented from InternalCF.

Definition at line 96 of file int_poly.h.

96 { return "InternalPoly"; }

◆ coeff()

CanonicalForm InternalPoly::coeff ( int  i)
virtual

CanonicalForm InternalPoly::coeff ( int i )

See also
CanonicalForm::operator []()

Reimplemented from InternalCF.

Definition at line 154 of file int_poly.cc.

155 {
156  termList theCursor = firstTerm;
157  while ( theCursor )
158  {
159  if ( theCursor->exp == i )
160  return theCursor->coeff;
161  else if ( theCursor->exp < i )
162  return CanonicalForm( 0 );
163  else
164  theCursor = theCursor->next;
165  }
166  return CanonicalForm( 0 );
167 }
int i
Definition: cfEzgcd.cc:125

◆ comparecoeff()

int InternalPoly::comparecoeff ( InternalCF )
virtual

comparecoeff() always returns 1 since CO is defined to be larger than anything which is a coefficient w.r.t.

CO.

Reimplemented from InternalCF.

Definition at line 1024 of file int_poly.cc.

1025 {
1026  return 1;
1027 }

◆ comparesame()

int InternalPoly::comparesame ( InternalCF acoeff)
virtual

comparesame(), comparecoeff() - compare with an InternalPoly.

comparesame() compares the coefficient vectors of f=CO and g=acoeff w.r.t to a lexicographic order in the following way: f < g iff there exists an 0 <= i <= max(deg(f),deg(g)) s.t. i) f[j] = g[j] for all i < j <= max(deg(f),deg(g)) and ii) g[i] occurs in g (i.e. is not equal to zero) and f[i] does not occur in f or f[i] < g[i] if f[i] occurs where f[i] denotes the coefficient to the power x^i of f.

As usual, comparesame() returns 1 if CO is larger than c, 0 if CO equals c, and -1 if CO is less than c. However, this function is optimized to test on equality since this is its most important and frequent usage.

See the respective ‘CanonicalForm’-methods for an explanation why we define such a strange (but total) ordering on polynomials.

See also
CanonicalForm::operator <(), CanonicalForm::operator ==()

Reimplemented from InternalCF.

Definition at line 982 of file int_poly.cc.

983 {
984  ASSERT( ! ::is_imm( acoeff ) && acoeff->level() > LEVELBASE, "incompatible base coefficients" );
985  InternalPoly* apoly = (InternalPoly*)acoeff;
986  // check on triviality
987  if ( this == apoly )
988  return 0;
989  else
990  {
991  termList cursor1 = firstTerm;
992  termList cursor2 = apoly->firstTerm;
993  for ( ; cursor1 && cursor2; cursor1 = cursor1->next, cursor2 = cursor2->next )
994  // we test on inequality of coefficients at this
995  // point instead of testing on "less than" at the
996  // last `else' in the enclosed `if' statement since a
997  // test on inequaltiy in general is cheaper
998  if ( (cursor1->exp != cursor2->exp) || (cursor1->coeff != cursor2->coeff) )
999  {
1000  if ( cursor1->exp > cursor2->exp )
1001  return 1;
1002  else if ( cursor1->exp < cursor2->exp )
1003  return -1;
1004  else if ( cursor1->coeff > cursor2->coeff )
1005  return 1;
1006  else
1007  return -1;
1008  }
1009  // check trailing terms
1010  if ( cursor1 == cursor2 )
1011  return 0;
1012  else if ( cursor1 != 0 )
1013  return 1;
1014  else
1015  return -1;
1016  }
1017 }
#define LEVELBASE
Definition: cf_defs.h:16
virtual int level() const
Definition: int_cf.h:67

◆ copyTermList()

termList InternalPoly::copyTermList ( termList  aTermList,
termList theLastTerm,
bool  negate = false 
)
staticprivate

Definition at line 1822 of file int_poly.cc.

1823 {
1824  if ( aTermList == 0 )
1825  return 0;
1826  else if ( negate )
1827  {
1828  termList sourceCursor = aTermList;
1829  termList dummy = new term;
1830  termList targetCursor = dummy;
1831 
1832  while ( sourceCursor )
1833  {
1834  targetCursor->next = new term( 0, -sourceCursor->coeff, sourceCursor->exp );
1835  targetCursor = targetCursor->next;
1836  sourceCursor = sourceCursor->next;
1837  }
1838  targetCursor->next = 0;
1839  theLastTerm = targetCursor;
1840  targetCursor = dummy->next;
1841  delete dummy;
1842  return targetCursor;
1843  }
1844  else
1845  {
1846  termList sourceCursor = aTermList;
1847  termList dummy = new term;
1848  termList targetCursor = dummy;
1849 
1850  while ( sourceCursor )
1851  {
1852  targetCursor->next = new term( 0, sourceCursor->coeff, sourceCursor->exp );
1853  targetCursor = targetCursor->next;
1854  sourceCursor = sourceCursor->next;
1855  }
1856  targetCursor->next = 0;
1857  theLastTerm = targetCursor;
1858  targetCursor = dummy->next;
1859  delete dummy;
1860  return targetCursor;
1861  }
1862 }

◆ deepCopyObject()

InternalCF * InternalPoly::deepCopyObject ( ) const
virtual

Reimplemented from InternalCF.

Definition at line 68 of file int_poly.cc.

69 {
70  termList first, last;
71  first = deepCopyTermList( firstTerm, last );
72  return new InternalPoly( first, last, var );
73 }
static termList deepCopyTermList(termList, termList &)
Definition: int_poly.cc:1865

◆ deepCopyTermList()

termList InternalPoly::deepCopyTermList ( termList  aTermList,
termList theLastTerm 
)
staticprivate

Definition at line 1865 of file int_poly.cc.

1866 {
1867  if ( aTermList == 0 )
1868  return 0;
1869  else
1870  {
1871  termList sourceCursor = aTermList;
1872  termList dummy = new term;
1873  termList targetCursor = dummy;
1874 
1875  while ( sourceCursor )
1876  {
1877  targetCursor->next = new term( 0, sourceCursor->coeff.deepCopy(), sourceCursor->exp );
1878  targetCursor = targetCursor->next;
1879  sourceCursor = sourceCursor->next;
1880  }
1881  targetCursor->next = 0;
1882  theLastTerm = targetCursor;
1883  targetCursor = dummy->next;
1884  delete dummy;
1885  return targetCursor;
1886  }
1887 }
CanonicalForm deepCopy() const

◆ degree()

int InternalPoly::degree ( )
virtual

int InternalPoly::degree ()

See also
CanonicalForm::sign ()

Reimplemented from InternalCF.

Definition at line 92 of file int_poly.cc.

93 {
94  return firstTerm->exp;
95 }

◆ divcoeff()

InternalCF * InternalPoly::divcoeff ( InternalCF cc,
bool  invert 
)
virtual

Reimplemented from InternalCF.

Definition at line 1391 of file int_poly.cc.

1392 {
1393  CanonicalForm c( is_imm(cc) ? cc : cc->copyObject() );
1394  if ( inExtension() && getReduce( var ) && invert )
1395  {
1396  InternalCF * dummy;
1397  dummy = this->invert();
1398  dummy = dummy->mulcoeff( cc );
1399  if ( getRefCount() <= 1 )
1400  {
1401  delete this;
1402  return dummy;
1403  }
1404  else
1405  {
1406  decRefCount();
1407  return dummy;
1408  }
1409  }
1410  if ( invert )
1411  {
1412  if ( getRefCount() <= 1 )
1413  {
1414  delete this;
1415  return CFFactory::basic( 0L );
1416  }
1417  else
1418  {
1419  decRefCount();
1420  return CFFactory::basic( 0L );
1421  }
1422  }
1423  if ( c.isOne() )
1424  return this;
1425  else
1426  {
1427  if ( getRefCount() <= 1 )
1428  {
1430  if ( firstTerm && firstTerm->exp != 0 )
1431  return this;
1432  else if ( firstTerm )
1433  {
1435  delete this;
1436  return res;
1437  }
1438  else
1439  {
1440  delete this;
1441  return CFFactory::basic( 0L );
1442  }
1443  }
1444  else
1445  {
1446  decRefCount();
1447  termList last, first = copyTermList( firstTerm, last );
1448  first = divTermList( first, c, last );
1449  if ( first && first->exp != 0 )
1450  return new InternalPoly( first, last, var );
1451  else if ( first )
1452  {
1453  InternalCF * res = first->coeff.getval();
1454  delete first;
1455  return res;
1456  }
1457  else
1458  {
1459  delete first;
1460  return CFFactory::basic( 0L );
1461  }
1462  }
1463  }
1464 }
virtual InternalCF * mulcoeff(InternalCF *) PVIRT_INTCF("mulcoeff")
InternalCF * invert()
Definition: int_poly.cc:239
bool inExtension() const
Definition: int_poly.h:110
static termList divTermList(termList, const CanonicalForm &, termList &)
Definition: int_poly.cc:2036
bool getReduce(const Variable &alpha)
Definition: variable.cc:232

◆ dividecoeff()

InternalCF * InternalPoly::dividecoeff ( InternalCF cc,
bool  invert 
)
virtual

Reimplemented from InternalCF.

Definition at line 1209 of file int_poly.cc.

1210 {
1211  CanonicalForm c( is_imm(cc) ? cc : cc->copyObject() );
1212  if ( inExtension() && getReduce( var ) && invert )
1213  {
1214  InternalCF * dummy;
1215  dummy = this->invert();
1216  if (is_imm(dummy))
1217  {
1218  if (is_imm(cc))
1219  {
1220  InternalInteger *d=new InternalInteger(imm2int(dummy)*imm2int(cc));
1221  dummy=d;
1222  }
1223  else
1224  dummy=cc->mulcoeff(dummy);
1225  }
1226  else dummy = dummy->mulcoeff( cc );
1227  if ( getRefCount() <= 1 )
1228  {
1229  delete this;
1230  return dummy;
1231  }
1232  else
1233  {
1234  decRefCount();
1235  return dummy;
1236  }
1237  }
1238  if ( invert )
1239  {
1240  if ( getRefCount() <= 1 )
1241  {
1242  delete this;
1243  return CFFactory::basic( 0L );
1244  }
1245  else
1246  {
1247  decRefCount();
1248  return CFFactory::basic( 0L );
1249  }
1250  }
1251  if ( c.isOne() )
1252  return this;
1253  else
1254  {
1255  if ( getRefCount() <= 1 )
1256  {
1258  if ( firstTerm && firstTerm->exp != 0 )
1259  return this;
1260  else if ( firstTerm )
1261  {
1263  delete this;
1264  return res;
1265  }
1266  else
1267  {
1268  delete this;
1269  return CFFactory::basic( 0L );
1270  }
1271  }
1272  else
1273  {
1274  decRefCount();
1275  termList last, first = copyTermList( firstTerm, last );
1276  first = divideTermList( first, c, last );
1277  if ( first && first->exp != 0 )
1278  return new InternalPoly( first, last, var );
1279  else if ( first )
1280  {
1281  InternalCF * res = first->coeff.getval();
1282  delete first;
1283  return res;
1284  }
1285  else
1286  {
1287  delete first;
1288  return CFFactory::basic( 0L );
1289  }
1290  }
1291  }
1292 }
factory's class for integers
Definition: int_int.h:41
static termList divideTermList(termList, const CanonicalForm &, termList &)
Definition: int_poly.cc:2007
static long imm2int(const InternalCF *const imm)
Definition: imm.h:70

◆ dividesame()

InternalCF * InternalPoly::dividesame ( InternalCF aCoeff)
virtual

Reimplemented from InternalCF.

Definition at line 483 of file int_poly.cc.

484 {
485  return divsame( aCoeff );
486 }
InternalCF * divsame(InternalCF *)
Definition: int_poly.cc:490

◆ divideTermList()

termList InternalPoly::divideTermList ( termList  firstTerm,
const CanonicalForm coeff,
termList lastTerm 
)
staticprivate

Definition at line 2007 of file int_poly.cc.

2008 {
2009  termList theCursor = firstTerm;
2010  lastTerm = 0;
2011  termList dummy;
2012 
2013  while ( theCursor )
2014  {
2015  theCursor->coeff /= coeff;
2016  if ( theCursor->coeff.isZero() )
2017  {
2018  if ( theCursor == firstTerm )
2019  firstTerm = theCursor->next;
2020  else
2021  lastTerm->next = theCursor->next;
2022  dummy = theCursor;
2023  theCursor = theCursor->next;
2024  delete dummy;
2025  }
2026  else
2027  {
2028  lastTerm = theCursor;
2029  theCursor = theCursor->next;
2030  }
2031  }
2032  return firstTerm;
2033 }

◆ divremcoeff()

void InternalPoly::divremcoeff ( InternalCF cc,
InternalCF *&  quot,
InternalCF *&  rem,
bool  invert 
)
virtual

Reimplemented from InternalCF.

Definition at line 1644 of file int_poly.cc.

1645 {
1646  if ( inExtension() && getReduce( var ) )
1647  {
1648  quot = copyObject();
1649  quot = quot->dividecoeff( cc, invert );
1650  rem = CFFactory::basic( 0L );
1651  }
1652  else if ( invert )
1653  {
1654  if ( is_imm( cc ) )
1655  rem = cc;
1656  else
1657  rem = cc->copyObject();
1658  quot = CFFactory::basic( 0L );
1659  }
1660  else
1661  {
1662  CanonicalForm c( is_imm(cc) ? cc : cc->copyObject() );
1663  ASSERT( ! c.isZero(), "divide by zero!" );
1664  termList quotlast, quotfirst = copyTermList( firstTerm, quotlast );
1665  quotfirst = divideTermList( quotfirst, c, quotlast );
1666  if ( quotfirst )
1667  if ( quotfirst->exp == 0 )
1668  {
1669  quot = quotfirst->coeff.getval();
1670  delete quotfirst;
1671  }
1672  else
1673  quot = new InternalPoly( quotfirst, quotlast, var );
1674  else
1675  quot = CFFactory::basic( 0L );
1676  rem = CFFactory::basic( 0L );
1677  }
1678 }
virtual InternalCF * dividecoeff(InternalCF *, bool) PVIRT_INTCF("dividecoeff")
void rem(unsigned long *a, unsigned long *q, unsigned long p, int &dega, int degq)
Definition: minpoly.cc:572

◆ divremcoefft()

bool InternalPoly::divremcoefft ( InternalCF cc,
InternalCF *&  quot,
InternalCF *&  rem,
bool  invert 
)
virtual

Reimplemented from InternalCF.

Definition at line 1681 of file int_poly.cc.

1682 {
1683  if ( inExtension() && getReduce( var ) )
1684  {
1685  quot = copyObject();
1686  quot = quot->dividecoeff( cc, invert );
1687  rem = CFFactory::basic( 0L );
1688  return true;
1689  }
1690  else if ( invert )
1691  {
1692  if ( is_imm( cc ) )
1693  rem = cc;
1694  else
1695  rem = cc->copyObject();
1696  quot = CFFactory::basic( 0L );
1697  return true;
1698  }
1699  CanonicalForm c( is_imm(cc) ? cc : cc->copyObject() );
1700  ASSERT( ! c.isZero(), "divide by zero!" );
1701  termList quotfirst, quotcursor;
1702  termList cursor;
1703  CanonicalForm cquot, crem;
1704  bool divideok = true;
1705 
1706  cursor = firstTerm;
1707  quotcursor = quotfirst = new term;
1708 
1709  while ( cursor && divideok )
1710  {
1711  divideok = divremt( cursor->coeff, c, cquot, crem );
1712  divideok = divideok && crem.isZero();
1713  if ( divideok )
1714  {
1715  if ( ! cquot.isZero() )
1716  {
1717  quotcursor->next = new term( 0, cquot, cursor->exp );
1718  quotcursor = quotcursor->next;
1719  }
1720  cursor = cursor->next;
1721  }
1722  }
1723  quotcursor->next = 0;
1724  if ( divideok )
1725  {
1726  cursor = quotfirst; quotfirst = quotfirst->next; delete cursor;
1727  if ( quotfirst )
1728  if ( quotfirst->exp == 0 )
1729  {
1730  quot = quotfirst->coeff.getval();
1731  delete quotfirst;
1732  }
1733  else
1734  quot = new InternalPoly( quotfirst, quotcursor, var );
1735  else
1736  quot = CFFactory::basic( 0L );
1737  rem = CFFactory::basic( 0L );
1738  }
1739  else
1740  {
1741  freeTermList( quotfirst );
1742  }
1743  return divideok;
1744 }
bool divremt(const CanonicalForm &f, const CanonicalForm &g, CanonicalForm &q, CanonicalForm &r)

◆ divremsame()

void InternalPoly::divremsame ( InternalCF acoeff,
InternalCF *&  quot,
InternalCF *&  rem 
)
virtual

Reimplemented from InternalCF.

Definition at line 757 of file int_poly.cc.

758 {
759  if ( inExtension() && getReduce( var ) )
760  {
761  InternalCF * dummy = acoeff->invert();
762  quot = dummy->mulsame( this );
763  rem = CFFactory::basic( 0L );
764  }
765  else
766  {
767  InternalPoly *aPoly = (InternalPoly*)acoeff;
768  termList dummy, first, last, resultfirst = 0, resultlast = 0;
769  CanonicalForm coeff, newcoeff;
770  int exp, newexp;
771 
772  first = copyTermList( firstTerm, last );
773 
774  coeff = aPoly->firstTerm->coeff;
775  exp = aPoly->firstTerm->exp;
776  while (first && ( first->exp >= exp ) )
777  {
778  newcoeff = first->coeff / coeff;
779  newexp = first->exp - exp;
780  dummy = first;
781  first = mulAddTermList( first->next, aPoly->firstTerm->next, newcoeff, newexp, last, true );
782  delete dummy;
783  appendTermList( resultfirst, resultlast, newcoeff, newexp );
784  }
785  if ( resultfirst )
786  if ( resultfirst->exp == 0 )
787  {
788  quot = resultfirst->coeff.getval();
789  delete resultfirst;
790  }
791  else
792  quot = new InternalPoly( resultfirst, resultlast, var );
793  else
794  quot = CFFactory::basic( 0L );
795  if ( first )
796  if ( first->exp == 0 )
797  {
798  rem = first->coeff.getval();
799  delete first;
800  }
801  else
802  rem = new InternalPoly( first, last, var );
803  else
804  rem = CFFactory::basic( 0L );
805  }
806 }
virtual InternalCF * mulsame(InternalCF *) PVIRT_INTCF("mulsame")
virtual InternalCF * invert()
Definition: int_cf.cc:172
static termList mulAddTermList(termList theList, termList aList, const CanonicalForm &c, const int exp, termList &lastTerm, bool negate)
Definition: int_poly.cc:2140
static void appendTermList(termList &, termList &, const CanonicalForm &, const int)
Definition: int_poly.cc:2125

◆ divremsamet()

bool InternalPoly::divremsamet ( InternalCF acoeff,
InternalCF *&  quot,
InternalCF *&  rem 
)
virtual

Reimplemented from InternalCF.

Definition at line 809 of file int_poly.cc.

810 {
811  if ( inExtension() && getReduce( var ) )
812  {
813  divremsame( acoeff, quot, rem );
814  return true;
815  }
816  InternalPoly *aPoly = (InternalPoly*)acoeff;
817  termList dummy, first, last, resultfirst = 0, resultlast = 0;
818  CanonicalForm coeff, newcoeff, dummycoeff;
819  int exp, newexp;
820  bool divideok = true;
821 
822 // if ( ! ::divremt( lastTerm->coeff, aPoly->lastTerm->coeff, newcoeff, dummycoeff ) )
823 // return false;
824 
825  first = copyTermList( firstTerm, last );
826 
827  coeff = aPoly->firstTerm->coeff;
828  exp = aPoly->firstTerm->exp;
829  while (first && ( first->exp >= exp ) && divideok )
830  {
831  divideok = divremt( first->coeff, coeff, newcoeff, dummycoeff );
832  if ( divideok && dummycoeff.isZero() )
833  {
834  newexp = first->exp - exp;
835  dummy = first;
836  first = mulAddTermList( first->next, aPoly->firstTerm->next, newcoeff, newexp, last, true );
837  delete dummy;
838  appendTermList( resultfirst, resultlast, newcoeff, newexp );
839  }
840  else
841  divideok = false;
842  }
843  if ( divideok )
844  {
845  if ( resultfirst )
846  if ( resultfirst->exp == 0 )
847  {
848  quot = resultfirst->coeff.getval();
849  delete resultfirst;
850  }
851  else
852  quot = new InternalPoly( resultfirst, resultlast, var );
853  else
854  quot = CFFactory::basic( 0L );
855  if ( first )
856  if ( first->exp == 0 )
857  {
858  rem = first->coeff.getval();
859  delete first;
860  }
861  else
862  rem = new InternalPoly( first, last, var );
863  else
864  rem = CFFactory::basic( 0L );
865  }
866  else
867  {
868  freeTermList( resultfirst );
869  freeTermList( first );
870  }
871  return divideok;
872 }
void divremsame(InternalCF *, InternalCF *&, InternalCF *&)
Definition: int_poly.cc:757

◆ divsame()

InternalCF * InternalPoly::divsame ( InternalCF aCoeff)
virtual

Reimplemented from InternalCF.

Definition at line 490 of file int_poly.cc.

491 {
492  if ( inExtension() && getReduce( var ) )
493  {
494  InternalCF * dummy = aCoeff->invert();
495  if (is_imm(dummy)) dummy=this->mulsame(dummy);
496  else dummy = dummy->mulsame( this );
497  if ( getRefCount() <= 1 )
498  {
499  delete this;
500  return dummy;
501  }
502  else
503  {
504  decRefCount();
505  return dummy;
506  }
507  }
508  InternalPoly *aPoly = (InternalPoly*)aCoeff;
509  termList dummy, first, last, resultfirst = 0, resultlast = 0;
510  CanonicalForm coeff, newcoeff;
511  int exp, newexp;
512  bool singleObject;
513 
514  if ( getRefCount() <= 1 )
515  {
516  first = firstTerm; last = lastTerm; singleObject = true;
517  }
518  else
519  {
520  first = copyTermList( firstTerm, last ); singleObject = false;
521  decRefCount();
522  }
523  coeff = aPoly->firstTerm->coeff;
524  exp = aPoly->firstTerm->exp;
525  while (first && ( first->exp >= exp ) )
526  {
527  newcoeff = first->coeff / coeff;
528  newexp = first->exp - exp;
529  dummy = first;
530  first = mulAddTermList( first->next, aPoly->firstTerm->next, newcoeff, newexp, last, true );
531  delete dummy;
532  appendTermList( resultfirst, resultlast, newcoeff, newexp );
533  }
534  freeTermList( first );
535  if ( singleObject )
536  {
537  if ( resultfirst && resultfirst->exp != 0 )
538  {
539  firstTerm = resultfirst;
540  lastTerm = resultlast;
541  return this;
542  }
543  else if ( resultfirst )
544  {
545  InternalCF * res = resultfirst->coeff.getval();
546  delete resultfirst;
547  firstTerm = 0;
548  delete this;
549  return res;
550  }
551  else
552  {
553  // this should not happen (evtl use assertion)
554  ASSERT( 0, "FATAL ERROR, PLEASE INFORM THE AUTHOR" );
555  firstTerm = 0;
556  delete this;
557  return CFFactory::basic( 0L );
558  }
559  }
560  else
561  {
562  if ( resultfirst && resultfirst->exp != 0 )
563  return new InternalPoly( resultfirst, resultlast, var );
564  else if ( resultfirst )
565  {
566  InternalCF * res = resultfirst->coeff.getval();
567  delete resultfirst;
568  return res;
569  }
570  else
571  return CFFactory::basic( 0L );
572  }
573 }
InternalCF * mulsame(InternalCF *)
Definition: int_poly.cc:358

◆ divTermList()

termList InternalPoly::divTermList ( termList  firstTerm,
const CanonicalForm coeff,
termList lastTerm 
)
staticprivate

Definition at line 2036 of file int_poly.cc.

2037 {
2038  termList theCursor = firstTerm;
2039  lastTerm = 0;
2040  termList dummy;
2041 
2042  while ( theCursor )
2043  {
2044  theCursor->coeff.div( coeff );
2045  if ( theCursor->coeff.isZero() )
2046  {
2047  if ( theCursor == firstTerm )
2048  firstTerm = theCursor->next;
2049  else
2050  lastTerm->next = theCursor->next;
2051  dummy = theCursor;
2052  theCursor = theCursor->next;
2053  delete dummy;
2054  }
2055  else
2056  {
2057  lastTerm = theCursor;
2058  theCursor = theCursor->next;
2059  }
2060  }
2061  return firstTerm;
2062 }
CanonicalForm & div(const CanonicalForm &)

◆ freeTermList()

void InternalPoly::freeTermList ( termList  aTermList)
staticprivate

Definition at line 1890 of file int_poly.cc.

1891 {
1892  termList cursor = aTermList;
1893 
1894  while ( cursor )
1895  {
1896  cursor = cursor->next;
1897  delete aTermList;
1898  aTermList = cursor;
1899  }
1900 }

◆ genOne()

InternalCF* InternalPoly::genOne ( )
inlinevirtual

Reimplemented from InternalCF.

Definition at line 118 of file int_poly.h.

119  { return firstTerm->coeff.genOne().getval(); }
CanonicalForm genOne() const

◆ genZero()

InternalCF* InternalPoly::genZero ( )
inlinevirtual

Reimplemented from InternalCF.

Definition at line 115 of file int_poly.h.

116  { return firstTerm->coeff.genZero().getval(); }
CanonicalForm genZero() const
genOne(), genZero()

◆ inBaseDomain()

bool InternalPoly::inBaseDomain ( ) const
inlinevirtual

Reimplemented from InternalCF.

Definition at line 109 of file int_poly.h.

109 { return false; }

◆ inCoeffDomain()

bool InternalPoly::inCoeffDomain ( ) const
inlinevirtual

Reimplemented from InternalCF.

Definition at line 111 of file int_poly.h.

111 { return var.level() < 0; }
int level() const
Definition: factory.h:134

◆ inExtension()

bool InternalPoly::inExtension ( ) const
inlinevirtual

Reimplemented from InternalCF.

Definition at line 110 of file int_poly.h.

110 { return var.level() < 0; }

◆ inPolyDomain()

bool InternalPoly::inPolyDomain ( ) const
inlinevirtual

Reimplemented from InternalCF.

Definition at line 112 of file int_poly.h.

112 { return var.level() > 0; }

◆ inQuotDomain()

bool InternalPoly::inQuotDomain ( ) const
inlinevirtual

Reimplemented from InternalCF.

Definition at line 113 of file int_poly.h.

113 { return false; }

◆ invert()

InternalCF * InternalPoly::invert ( )
virtual

Reimplemented from InternalCF.

Definition at line 239 of file int_poly.cc.

240 {
241  if ( inExtension() && getReduce( var ) )
242  {
243  setReduce( var, false );
244  CanonicalForm a( this->copyObject() );
245  CanonicalForm b = getMipo( var );
246  CanonicalForm u, v;
247  CanonicalForm g = extgcd( a, b, u, v );
248  setReduce( var, true );
249  return u.getval();
250  }
251  else
252  return CFFactory::basic( 0L );
253 }
g
Definition: cfModGcd.cc:4031
CanonicalForm b
Definition: cfModGcd.cc:4044
CanonicalForm extgcd(const CanonicalForm &f, const CanonicalForm &g, CanonicalForm &a, CanonicalForm &b)
CanonicalForm extgcd ( const CanonicalForm & f, const CanonicalForm & g, CanonicalForm & a,...
Definition: cfUnivarGcd.cc:173
void setReduce(const Variable &alpha, bool reduce)
Definition: variable.cc:238
CanonicalForm getMipo(const Variable &alpha, const Variable &x)
Definition: variable.cc:207

◆ isUnivariate()

bool InternalPoly::isUnivariate ( ) const
virtual

Reimplemented from InternalCF.

Definition at line 76 of file int_poly.cc.

77 {
78  termList cursor = firstTerm;
79  while ( cursor )
80  {
81  if ( ! cursor->coeff.inCoeffDomain() )
82  return false;
83  cursor = cursor->next;
84  }
85  return true;
86 }
bool inCoeffDomain() const

◆ lc()

CanonicalForm InternalPoly::lc ( )
virtual
See also
CanonicalForm::lc(), CanonicalForm::Lc(), CanonicalForm::LC(), InternalPoly::Lc (), InternalPoly::LC ()

Reimplemented from InternalCF.

Definition at line 112 of file int_poly.cc.

113 {
114  return firstTerm->coeff.lc();
115 }
CanonicalForm lc() const
CanonicalForm CanonicalForm::lc (), Lc (), LC (), LC ( v ) const.

◆ Lc()

CanonicalForm InternalPoly::Lc ( )
virtual
See also
CanonicalForm::lc(), CanonicalForm::Lc(), CanonicalForm::LC(), InternalPoly::lc (), InternalPoly::LC ()

Reimplemented from InternalCF.

Definition at line 121 of file int_poly.cc.

122 {
123  return firstTerm->coeff.Lc();
124 }
CanonicalForm Lc() const

◆ LC()

CanonicalForm InternalPoly::LC ( )
virtual
See also
CanonicalForm::lc(), CanonicalForm::Lc(), CanonicalForm::LC(), InternalPoly::lc (), InternalPoly::Lc ()

Reimplemented from InternalCF.

Definition at line 130 of file int_poly.cc.

131 {
132  return firstTerm->coeff;
133 }

◆ level()

int InternalPoly::level ( ) const
inlinevirtual

Reimplemented from InternalCF.

Definition at line 97 of file int_poly.h.

97 { return var.level(); }

◆ modcoeff()

InternalCF * InternalPoly::modcoeff ( InternalCF cc,
bool  invert 
)
virtual

Reimplemented from InternalCF.

Definition at line 1580 of file int_poly.cc.

1581 {
1582  CanonicalForm c( is_imm(cc) ? cc : cc->copyObject() );
1583  if ( invert )
1584  {
1585  if ( deleteObject() ) delete this;
1586  return c.getval();
1587  }
1588  ASSERT( ! c.isZero(), "divide by zero!" );
1589  if ( c.isOne() )
1590  {
1591  if ( getRefCount() <= 1 )
1592  {
1593  delete this;
1594  return CFFactory::basic( 0L );
1595  }
1596  else
1597  {
1598  decRefCount();
1599  return CFFactory::basic( 0L );
1600  }
1601  }
1602  else
1603  {
1604  if ( getRefCount() <= 1 )
1605  {
1607  if ( firstTerm && firstTerm->exp != 0 )
1608  return this;
1609  else if ( firstTerm )
1610  {
1612  delete this;
1613  return res;
1614  }
1615  else
1616  {
1617  delete this;
1618  return CFFactory::basic( 0L );
1619  }
1620  }
1621  else
1622  {
1623  decRefCount();
1624  termList last, first = copyTermList( firstTerm, last );
1625  first = modTermList( first, c, last );
1626  if ( first && first->exp != 0 )
1627  return new InternalPoly( first, last, var );
1628  else if ( first )
1629  {
1630  InternalCF * res = first->coeff.getval();
1631  delete first;
1632  return res;
1633  }
1634  else
1635  {
1636  delete first;
1637  return CFFactory::basic( 0L );
1638  }
1639  }
1640  }
1641 }
int deleteObject()
Definition: int_cf.h:61
static termList modTermList(termList, const CanonicalForm &, termList &)
Definition: int_poly.cc:2096

◆ modsame()

InternalCF * InternalPoly::modsame ( InternalCF aCoeff)
virtual

Reimplemented from InternalCF.

Definition at line 685 of file int_poly.cc.

686 {
687  if ( inExtension() && getReduce( var ) )
688  {
689  if ( deleteObject() ) delete this;
690  return CFFactory::basic( 0L );
691  }
692  InternalPoly *aPoly = (InternalPoly*)aCoeff;
693  termList dummy, first, last;
694  CanonicalForm coeff, newcoeff;
695  int exp, newexp;
696  bool singleObject;
697 
698  if ( getRefCount() <= 1 )
699  {
700  first = firstTerm; last = lastTerm; singleObject = true;
701  }
702  else
703  {
704  first = copyTermList( firstTerm, last ); singleObject = false;
705  decRefCount();
706  }
707  coeff = aPoly->firstTerm->coeff;
708  exp = aPoly->firstTerm->exp;
709  while (first && ( first->exp >= exp ) )
710  {
711  newcoeff = first->coeff / coeff;
712  newexp = first->exp - exp;
713  dummy = first;
714  first = mulAddTermList( first->next, aPoly->firstTerm->next, newcoeff, newexp, last, true );
715  delete dummy;
716  }
717  if ( singleObject )
718  {
719  if ( first && first->exp != 0 )
720  {
721  firstTerm = first;
722  lastTerm = last;
723  return this;
724  }
725  else if ( first )
726  {
727  InternalCF * res = first->coeff.getval();
728  delete first;
729  firstTerm = 0;
730  delete this;
731  return res;
732  }
733  else
734  {
735  firstTerm = 0;
736  delete this;
737  return CFFactory::basic( 0L );
738  }
739  }
740  else
741  {
742  if ( first && first->exp != 0 )
743  return new InternalPoly( first, last, var );
744  else if ( first )
745  {
746  InternalCF * res = first->coeff.getval();
747  delete first;
748  return res;
749  }
750  else
751  return CFFactory::basic( 0L );
752  }
753 }

◆ modTermList()

termList InternalPoly::modTermList ( termList  firstTerm,
const CanonicalForm coeff,
termList lastTerm 
)
staticprivate

Definition at line 2096 of file int_poly.cc.

2097 {
2098  termList theCursor = firstTerm;
2099  lastTerm = 0;
2100  termList dummy;
2101 
2102  while ( theCursor )
2103  {
2104  theCursor->coeff.mod( coeff );
2105  if ( theCursor->coeff.isZero() )
2106  {
2107  if ( theCursor == firstTerm )
2108  firstTerm = theCursor->next;
2109  else
2110  lastTerm->next = theCursor->next;
2111  dummy = theCursor;
2112  theCursor = theCursor-> next;
2113  delete dummy;
2114  }
2115  else
2116  {
2117  lastTerm = theCursor;
2118  theCursor = theCursor->next;
2119  }
2120  }
2121  return firstTerm;
2122 }
CanonicalForm & mod(const CanonicalForm &)
ListNode * next
Definition: janet.h:31

◆ modulocoeff()

InternalCF * InternalPoly::modulocoeff ( InternalCF cc,
bool  invert 
)
virtual

Reimplemented from InternalCF.

Definition at line 1566 of file int_poly.cc.

1567 {
1568  CanonicalForm c( is_imm(cc) ? cc : cc->copyObject() );
1569  if ( invert )
1570  {
1571  if ( deleteObject() ) delete this;
1572  return c.getval();
1573  }
1574  ASSERT( ! c.isZero(), "divide by zero!" );
1575  if ( deleteObject() ) delete this;
1576  return CFFactory::basic( 0L );
1577 }

◆ modulosame()

InternalCF * InternalPoly::modulosame ( InternalCF aCoeff)
virtual

Reimplemented from InternalCF.

Definition at line 679 of file int_poly.cc.

680 {
681  return modsame( aCoeff );
682 }
InternalCF * modsame(InternalCF *)
Definition: int_poly.cc:685

◆ mulAddTermList()

termList InternalPoly::mulAddTermList ( termList  theList,
termList  aList,
const CanonicalForm c,
const int  exp,
termList lastTerm,
bool  negate 
)
staticprivate

Definition at line 2140 of file int_poly.cc.

2141 {
2142  termList theCursor = theList;
2143  termList aCursor = aList;
2144  termList predCursor = 0;
2146 
2147  if ( negate )
2148  coeff = -c;
2149  else
2150  coeff = c;
2151 
2152  while ( theCursor && aCursor )
2153  {
2154  if ( theCursor->exp == aCursor->exp + exp )
2155  {
2156  theCursor->coeff += aCursor->coeff * coeff;
2157  if ( theCursor->coeff.isZero() )
2158  {
2159  if ( predCursor )
2160  {
2161  predCursor->next = theCursor->next;
2162  delete theCursor;
2163  theCursor = predCursor->next;
2164  }
2165  else
2166  {
2167  theList = theList->next;
2168  delete theCursor;
2169  theCursor = theList;
2170  }
2171  }
2172  else
2173  {
2174  predCursor = theCursor;
2175  theCursor = theCursor->next;
2176  }
2177  aCursor = aCursor->next;
2178  }
2179  else if ( theCursor->exp < aCursor->exp + exp )
2180  {
2181  if ( predCursor )
2182  {
2183  predCursor->next = new term( theCursor, aCursor->coeff * coeff, aCursor->exp + exp );
2184  predCursor = predCursor->next;
2185  }
2186  else
2187  {
2188  theList = new term( theCursor, aCursor->coeff * coeff, aCursor->exp + exp );
2189  predCursor = theList;
2190  }
2191  aCursor = aCursor->next;
2192  }
2193  else
2194  {
2195  predCursor = theCursor;
2196  theCursor = theCursor->next;
2197  }
2198  }
2199  if ( aCursor )
2200  {
2201  if ( predCursor )
2202  {
2203  predCursor->next = copyTermList( aCursor, lastTerm );
2204  predCursor = predCursor->next;
2205  }
2206  else
2207  {
2208  theList = copyTermList( aCursor, lastTerm );
2209  predCursor = theList;
2210  }
2211  while ( predCursor )
2212  {
2213  predCursor->exp += exp;
2214  predCursor->coeff *= coeff;
2215  predCursor = predCursor->next;
2216  }
2217  }
2218  else if ( ! theCursor )
2219  lastTerm = predCursor;
2220  return theList;
2221 }

◆ mulcoeff()

InternalCF * InternalPoly::mulcoeff ( InternalCF cc)
virtual

Reimplemented from InternalCF.

Definition at line 1173 of file int_poly.cc.

1174 {
1175  CanonicalForm c( is_imm(cc) ? cc : cc->copyObject() );
1176  if ( c.isZero() )
1177  {
1178  if ( getRefCount() <= 1 )
1179  {
1180  delete this;
1181  return CFFactory::basic( 0L );
1182  }
1183  else
1184  {
1185  decRefCount();
1186  return CFFactory::basic( 0L );
1187  }
1188  }
1189  else if ( c.isOne() )
1190  return this;
1191  else
1192  {
1193  if ( getRefCount() <= 1 )
1194  {
1195  mulTermList( firstTerm, c, 0L );
1196  return this;
1197  }
1198  else
1199  {
1200  decRefCount();
1201  termList last, first = copyTermList( firstTerm, last );
1202  mulTermList( first, c, 0 );
1203  return new InternalPoly( first, last, var );
1204  }
1205  }
1206 }
static void mulTermList(termList, const CanonicalForm &, const int)
Definition: int_poly.cc:1996

◆ mulsame()

InternalCF * InternalPoly::mulsame ( InternalCF aCoeff)
virtual

Reimplemented from InternalCF.

Definition at line 358 of file int_poly.cc.

359 {
360  if (is_imm(aCoeff)) return mulcoeff(aCoeff);
361  InternalPoly *aPoly = (InternalPoly*)aCoeff;
362  termList resultFirst = 0, resultLast = 0;
363  termList theCursor = firstTerm;
364 
365  while ( theCursor )
366  {
367  resultFirst = mulAddTermList( resultFirst, aPoly->firstTerm,
368  theCursor->coeff, theCursor->exp, resultLast, false );
369  theCursor = theCursor->next;
370  }
371  if ( inExtension() && getReduce( var ) )
372  {
373  resultFirst = reduceTermList( resultFirst, (getInternalMipo( var ))->firstTerm, resultLast );
374  if ( resultFirst == 0 )
375  {
376  if ( getRefCount() <= 1 )
377  {
378  delete this;
379  return CFFactory::basic(0L);
380  }
381  else
382  {
383  decRefCount();
384  return CFFactory::basic(0L);
385  }
386  }
387  else if ( resultFirst->exp == 0 )
388  {
389  if ( getRefCount() <= 1 )
390  {
391  InternalCF * res = resultFirst->coeff.getval();
392  delete resultFirst;
393  delete this;
394  return res;
395  }
396  else
397  {
398  decRefCount();
399  InternalCF * res = resultFirst->coeff.getval();
400  delete resultFirst;
401  return res;
402  }
403  }
404  }
405  if ( getRefCount() <= 1 )
406  {
408  firstTerm = resultFirst;
409  lastTerm = resultLast;
410  return this;
411  }
412  else
413  {
414  decRefCount();
415  return new InternalPoly( resultFirst, resultLast, var );
416  }
417 }
InternalCF * mulcoeff(InternalCF *)
Definition: int_poly.cc:1173
static termList reduceTermList(termList first, termList redterms, termList &last)
Definition: int_poly.cc:2224
InternalPoly * getInternalMipo(const Variable &alpha)
Definition: variable.cc:201

◆ mulTermList()

void InternalPoly::mulTermList ( termList  theCursor,
const CanonicalForm coeff,
const int  exp 
)
staticprivate

Definition at line 1996 of file int_poly.cc.

1997 {
1998  while ( theCursor )
1999  {
2000  theCursor->coeff *= coeff;
2001  theCursor->exp += exp;
2002  theCursor = theCursor->next;
2003  }
2004 }

◆ neg()

InternalCF * InternalPoly::neg ( )
virtual

InternalCF * InternalPoly::neg ()

See also
CanonicalForm::operator -()

Reimplemented from InternalCF.

Definition at line 223 of file int_poly.cc.

224 {
225  if ( getRefCount() <= 1 )
226  {
228  return this;
229  }
230  else
231  {
232  decRefCount();
233  termList last, first = copyTermList( firstTerm, last, true );
234  return new InternalPoly( first, last, var );
235  }
236 }
static void negateTermList(termList)
Definition: int_poly.cc:1903

◆ negateTermList()

void InternalPoly::negateTermList ( termList  terms)
staticprivate

Definition at line 1903 of file int_poly.cc.

1904 {
1905  termList cursor = terms;
1906  while ( cursor )
1907  {
1908  cursor->coeff = -cursor->coeff;
1909  cursor = cursor->next;
1910  }
1911 }

◆ operator delete()

void InternalPoly::operator delete ( void *  addr,
size_t   
)
inline

Definition at line 166 of file int_poly.h.

167  {
169  }
static const omBin InternalPoly_bin
Definition: int_poly.h:159
#define omFreeBin(addr, bin)
Definition: omAllocDecl.h:259

◆ operator new()

void* InternalPoly::operator new ( size_t  )
inline

Definition at line 160 of file int_poly.h.

161  {
162  void* addr;
163  omTypeAllocBin(void*, addr, InternalPoly_bin);
164  return addr;
165  }
#define omTypeAllocBin(type, addr, bin)
Definition: omAllocDecl.h:203

◆ print()

void InternalPoly::print ( OSTREAM aStream,
char *  aString 
)
virtual

Reimplemented from InternalCF.

Definition at line 171 of file int_poly.cc.

172 {
173  if ( ! firstTerm )
174  aStream << 0 << aString;
175  else
176  {
177  char * theString;
178  termList theCursor = firstTerm;
179  while ( theCursor )
180  {
181  ostrstream theStream;
182  if ( theCursor->exp == 0 )
183  theCursor->coeff.print( aStream, aString );
184  else if ( theCursor->coeff.isOne() )
185  {
186  aStream << var;
187  if ( theCursor->exp != 1 )
188  aStream << '^' << theCursor->exp << aString;
189  else
190  aStream << aString;
191  }
192  else if ( theCursor->coeff.sign() < 0 && (-theCursor->coeff).isOne() )
193  {
194  aStream << '-' << var;
195  if ( theCursor->exp != 1 )
196  aStream << '^' << theCursor->exp << aString;
197  else
198  aStream << aString;
199  }
200  else
201  {
202  theStream << '*' << var;
203  if ( theCursor->exp != 1 )
204  theStream << '^' << theCursor->exp << aString << ends;
205  else
206  theStream << aString << ends; // results from error in GNU strstream
207  theString = theStream.str();
208  theCursor->coeff.print( aStream, theString );
209  theStream.freeze(0);//delete [] theString;
210  }
211  theCursor = theCursor->next;
212  if ( theCursor && ( theCursor->coeff.sign() >= 0 ) )
213  aStream << '+';
214  }
215  }
216 }
int sign() const
int CanonicalForm::sign () const
CF_NO_INLINE bool isOne() const
CF_INLINE bool CanonicalForm::isOne, isZero () const.
Definition: cf_inline.cc:354
void print(OSTREAM &, char *) const
input/output

◆ reduceTermList()

termList InternalPoly::reduceTermList ( termList  first,
termList  redterms,
termList last 
)
staticprivate

Definition at line 2224 of file int_poly.cc.

2225 {
2226  CanonicalForm coeff = CanonicalForm (1)/redterms->coeff;
2227  CanonicalForm newcoeff;
2228  int newexp;
2229  int exp = redterms->exp;
2230  termList dummy;
2231  while ( first && ( first->exp >= exp ) )
2232  {
2233  newcoeff = first->coeff * coeff;
2234  newexp = first->exp - exp;
2235  dummy = first;
2236  first = mulAddTermList( first->next, redterms->next, newcoeff, newexp, last, true );
2237  delete dummy;
2238  }
2239  return first;
2240 }

◆ sign()

int InternalPoly::sign ( ) const
virtual

int InternalPoly::sign () const

See also
CanonicalForm::sign()

Reimplemented from InternalCF.

Definition at line 102 of file int_poly.cc.

103 {
104  return firstTerm->coeff.sign();
105 }

◆ subcoeff()

InternalCF * InternalPoly::subcoeff ( InternalCF cc,
bool  negate 
)
virtual

Reimplemented from InternalCF.

Definition at line 1087 of file int_poly.cc.

1088 {
1089  CanonicalForm c( is_imm(cc) ? cc : cc->copyObject() );
1090  if ( c.isZero() )
1091  if ( getRefCount() > 1 )
1092  {
1093  decRefCount();
1094  termList last, first = copyTermList( firstTerm, last, negate );
1095  return new InternalPoly( first, last, var );
1096  }
1097  else
1098  {
1099  if ( negate )
1101  return this;
1102  }
1103  else
1104  {
1105  if ( getRefCount() <= 1 )
1106  {
1107  if ( lastTerm->exp == 0 )
1108  {
1109  if ( negate )
1110  {
1112  lastTerm->coeff += c;
1113  }
1114  else
1115  lastTerm->coeff -= c;
1116  if ( lastTerm->coeff.isZero() )
1117  {
1118  termList cursor = firstTerm;
1119  while ( cursor->next != lastTerm )
1120  cursor = cursor->next;
1121  delete lastTerm;
1122  cursor->next = 0;
1123  lastTerm = cursor;
1124  }
1125  }
1126  else
1127  {
1128  if ( negate )
1129  {
1131  lastTerm->next = new term( 0, c, 0 );
1132  }
1133  else
1134  lastTerm->next = new term( 0, -c, 0 );
1135  lastTerm = lastTerm->next;
1136  }
1137  return this;
1138  }
1139  else
1140  {
1141  decRefCount();
1142  termList last, first = copyTermList( firstTerm, last, negate );
1143  if ( last->exp == 0 )
1144  {
1145  if ( negate )
1146  last->coeff += c;
1147  else
1148  last->coeff -= c;
1149  if ( last->coeff.isZero() )
1150  {
1151  termList cursor = first;
1152  while ( cursor->next != last )
1153  cursor = cursor->next;
1154  delete last;
1155  cursor->next = 0;
1156  last = cursor;
1157  }
1158  }
1159  else
1160  {
1161  if ( negate )
1162  last->next = new term( 0, c, 0 );
1163  else
1164  last->next = new term( 0, -c, 0 );
1165  last = last->next;
1166  }
1167  return new InternalPoly( first, last, var );
1168  }
1169  }
1170 }

◆ subsame()

InternalCF * InternalPoly::subsame ( InternalCF aCoeff)
virtual

Reimplemented from InternalCF.

Definition at line 318 of file int_poly.cc.

319 {
320  InternalPoly * aPoly = (InternalPoly*)aCoeff;
321  if ( getRefCount() <= 1 )
322  {
323  firstTerm = addTermList( firstTerm, aPoly->firstTerm, lastTerm, true );
324  if ( firstTerm && firstTerm->exp != 0 )
325  return this;
326  else if ( firstTerm )
327  {
329  delete this;
330  return res;
331  }
332  else
333  {
334  delete this;
335  return CFFactory::basic( 0L );
336  }
337  }
338  else
339  {
340  decRefCount();
341  termList last, first = copyTermList( firstTerm, last );
342  first = addTermList( first, aPoly->firstTerm, last, true );
343  if ( first && first->exp != 0 )
344  return new InternalPoly( first, last, var );
345  else if ( first )
346  {
347  InternalCF * res = first->coeff.getval();
348  delete first;
349  return res;
350  }
351  else
352  return CFFactory::basic( 0L );
353 
354  }
355 }

◆ tailcoeff()

CanonicalForm InternalPoly::tailcoeff ( )
virtual

CanonicalForm InternalPoly::tailcoeff (), int InternalPoly::taildegree ()

See also
CanonicalForm::tailcoeff(), taildegree()

Reimplemented from InternalCF.

Definition at line 139 of file int_poly.cc.

140 {
141  return lastTerm->coeff;
142 }

◆ taildegree()

int InternalPoly::taildegree ( )
virtual

Reimplemented from InternalCF.

Definition at line 145 of file int_poly.cc.

146 {
147  return lastTerm->exp;
148 }

◆ tryDivcoeff()

InternalCF * InternalPoly::tryDivcoeff ( InternalCF cc,
bool  invert,
const CanonicalForm M,
bool &  fail 
)
virtual

Reimplemented from InternalCF.

Definition at line 1467 of file int_poly.cc.

1468 {
1469  CanonicalForm c( is_imm(cc) ? cc : cc->copyObject() );
1470  if ( inExtension() && !getReduce( var ) && invert )
1471  {
1472  InternalCF * dummy;
1473  dummy = this->tryInvert(M, fail);
1474  if (fail)
1475  {
1476  if (getRefCount() <= 1)
1477  delete this;
1478  else
1479  decRefCount();
1480  return dummy;
1481  }
1482  dummy = dummy->mulcoeff( cc );
1483  if ( getRefCount() <= 1 )
1484  {
1485  delete this;
1486  return dummy;
1487  }
1488  else
1489  {
1490  decRefCount();
1491  return dummy;
1492  }
1493  }
1494  if ( invert )
1495  {
1496  if ( getRefCount() <= 1 )
1497  {
1498  delete this;
1499  return CFFactory::basic( 0L );
1500  }
1501  else
1502  {
1503  decRefCount();
1504  return CFFactory::basic( 0L );
1505  }
1506  }
1507  if ( c.isOne() )
1508  return this;
1509  else
1510  {
1511  if ( getRefCount() <= 1 )
1512  {
1513  firstTerm = tryDivTermList( firstTerm, c, lastTerm, M, fail );
1514  if (fail)
1515  {
1516  delete this;
1517  return CFFactory::basic (0L);
1518  }
1519  if ( firstTerm && firstTerm->exp != 0 )
1520  return this;
1521  else if ( firstTerm )
1522  {
1524  delete this;
1525  return res;
1526  }
1527  else
1528  {
1529  delete this;
1530  return CFFactory::basic( 0L );
1531  }
1532  }
1533  else
1534  {
1535  decRefCount();
1536  termList last, first = copyTermList( firstTerm, last );
1537  first = tryDivTermList( first, c, last, M, fail );
1538  if (fail)
1539  {
1540  delete this;
1541  return CFFactory::basic (0L);
1542  }
1543  if (fail)
1544  {
1545  delete first;
1546  return CFFactory::basic (0L);
1547  }
1548  if ( first && first->exp != 0 )
1549  return new InternalPoly( first, last, var );
1550  else if ( first )
1551  {
1552  InternalCF * res = first->coeff.getval();
1553  delete first;
1554  return res;
1555  }
1556  else
1557  {
1558  delete first;
1559  return CFFactory::basic( 0L );
1560  }
1561  }
1562  }
1563 }
static termList tryDivTermList(termList, const CanonicalForm &, termList &, const CanonicalForm &, bool &)
Definition: int_poly.cc:2065
InternalCF * tryInvert(const CanonicalForm &, bool &)
Definition: int_poly.cc:256
#define M
Definition: sirandom.c:24

◆ tryDividecoeff()

InternalCF * InternalPoly::tryDividecoeff ( InternalCF cc,
bool  invert,
const CanonicalForm M,
bool &  fail 
)
virtual

Reimplemented from InternalCF.

Definition at line 1295 of file int_poly.cc.

1296 {
1297  CanonicalForm c( is_imm(cc) ? cc : cc->copyObject() );
1298  if ( inExtension() && !getReduce( var ) && invert )
1299  {
1300  InternalCF * dummy;
1301  dummy = this->tryInvert(M, fail);
1302  if (fail)
1303  {
1304  if (getRefCount() <= 1)
1305  delete this;
1306  else
1307  decRefCount();
1308  return dummy; //is equal to CFFactory::basic ( 0L ) in this case
1309  }
1310  if (is_imm(dummy))
1311  {
1312  if (is_imm(cc))
1313  {
1314  InternalInteger *d=new InternalInteger(imm2int(dummy)*imm2int(cc));
1315  dummy=d;
1316  }
1317  else
1318  dummy=cc->mulcoeff(dummy);
1319  }
1320  else dummy = dummy->mulcoeff( cc );
1321  if ( getRefCount() <= 1 )
1322  {
1323  delete this;
1324  return dummy;
1325  }
1326  else
1327  {
1328  decRefCount();
1329  return dummy;
1330  }
1331  }
1332  if ( invert )
1333  {
1334  if ( getRefCount() <= 1 )
1335  {
1336  delete this;
1337  return CFFactory::basic( 0L );
1338  }
1339  else
1340  {
1341  decRefCount();
1342  return CFFactory::basic( 0L );
1343  }
1344  }
1345  if ( c.isOne() )
1346  return this;
1347  //one should never get here
1348  else
1349  {
1350  if ( getRefCount() <= 1 )
1351  {
1353  if ( firstTerm && firstTerm->exp != 0 )
1354  return this;
1355  else if ( firstTerm )
1356  {
1358  delete this;
1359  return res;
1360  }
1361  else
1362  {
1363  delete this;
1364  return CFFactory::basic( 0L );
1365  }
1366  }
1367  else
1368  {
1369  decRefCount();
1370  termList last, first = copyTermList( firstTerm, last );
1371  first = divideTermList( first, c, last );
1372  if ( first && first->exp != 0 )
1373  return new InternalPoly( first, last, var );
1374  else if ( first )
1375  {
1376  InternalCF * res = first->coeff.getval();
1377  delete first;
1378  return res;
1379  }
1380  else
1381  {
1382  delete first;
1383  return CFFactory::basic( 0L );
1384  }
1385  }
1386  }
1387 }

◆ tryDivremcoefft()

bool InternalPoly::tryDivremcoefft ( InternalCF cc,
InternalCF *&  quot,
InternalCF *&  rem,
bool  invert,
const CanonicalForm M,
bool &  fail 
)
virtual

Reimplemented from InternalCF.

Definition at line 1747 of file int_poly.cc.

1748 {
1749  if ( inExtension() && !getReduce( var ) )
1750  {
1751  quot = copyObject();
1752  quot = quot->tryDividecoeff( cc, invert, M, fail );
1753  if (fail)
1754  return false;
1755  rem = CFFactory::basic( 0L );
1756  return true;
1757  }
1758  else if ( invert )
1759  {
1760  if ( is_imm( cc ) )
1761  rem = cc;
1762  else
1763  rem = cc->copyObject();
1764  quot = CFFactory::basic( 0L );
1765  return true;
1766  }
1767  CanonicalForm c( is_imm(cc) ? cc : cc->copyObject() );
1768  ASSERT( ! c.isZero(), "divide by zero!" );
1769  termList quotfirst, quotcursor;
1770  termList cursor;
1771  CanonicalForm cquot, crem;
1772  bool divideok = true;
1773 
1774  cursor = firstTerm;
1775  quotcursor = quotfirst = new term;
1776 
1777  while ( cursor && divideok )
1778  {
1779  divideok = tryDivremt( cursor->coeff, c, cquot, crem, M, fail );
1780  if (fail)
1781  {
1782  freeTermList (quotfirst);
1783  return false;
1784  }
1785  divideok = divideok && crem.isZero();
1786  if ( divideok )
1787  {
1788  if ( ! cquot.isZero() )
1789  {
1790  quotcursor->next = new term( 0, cquot, cursor->exp );
1791  quotcursor = quotcursor->next;
1792  }
1793  cursor = cursor->next;
1794  }
1795  }
1796  quotcursor->next = 0;
1797  if ( divideok )
1798  {
1799  cursor = quotfirst; quotfirst = quotfirst->next; delete cursor;
1800  if ( quotfirst )
1801  if ( quotfirst->exp == 0 )
1802  {
1803  quot = quotfirst->coeff.getval();
1804  delete quotfirst;
1805  }
1806  else
1807  quot = new InternalPoly( quotfirst, quotcursor, var );
1808  else
1809  quot = CFFactory::basic( 0L );
1810  rem = CFFactory::basic( 0L );
1811  }
1812  else
1813  {
1814  freeTermList( quotfirst );
1815  }
1816  return divideok;
1817 }
bool tryDivremt(const CanonicalForm &f, const CanonicalForm &g, CanonicalForm &q, CanonicalForm &r, const CanonicalForm &M, bool &fail)
same as divremt but handles zero divisors in case we are in Z_p[x]/(f) where f is not irreducible
virtual InternalCF * tryDividecoeff(InternalCF *, bool, const CanonicalForm &, bool &)
Definition: int_cf.cc:221

◆ tryDivremsamet()

bool InternalPoly::tryDivremsamet ( InternalCF acoeff,
InternalCF *&  quot,
InternalCF *&  rem,
const CanonicalForm M,
bool &  fail 
)
virtual

Reimplemented from InternalCF.

Definition at line 875 of file int_poly.cc.

876 {
877  if (inExtension() && !getReduce (var))
878  {
879  InternalCF * dummy = acoeff->tryInvert(M, fail);
880  if (fail)
881  return false;
882  quot = dummy->tryMulsame( this, M);
883  rem = CFFactory::basic( 0L );
884  if (fail)
885  return false;
886  return true;
887  }
888  InternalPoly *aPoly = (InternalPoly*)acoeff;
889  termList dummy, first, last, resultfirst = 0, resultlast = 0;
890  CanonicalForm coeff, newcoeff, dummycoeff;
891  int exp, newexp;
892  bool divideok = true;
893 
894  first = copyTermList( firstTerm, last );
895 
896  coeff = aPoly->firstTerm->coeff;
897  exp = aPoly->firstTerm->exp;
898  while (first && ( first->exp >= exp ) && divideok )
899  {
900  divideok = tryDivremt( first->coeff, coeff, newcoeff, dummycoeff, M, fail );
901  if (fail)
902  {
903  freeTermList (first);
904  return false;
905  }
906  if ( divideok && dummycoeff.isZero() )
907  {
908  newexp = first->exp - exp;
909  dummy = first;
910  first = mulAddTermList( first->next, aPoly->firstTerm->next, newcoeff, newexp, last, true );
911  delete dummy;
912  if (!newcoeff.isZero())
913  appendTermList( resultfirst, resultlast, newcoeff, newexp );
914  }
915  else
916  divideok = false;
917  }
918  if ( divideok )
919  {
920  if ( resultfirst )
921  if ( resultfirst->exp == 0 )
922  {
923  quot = resultfirst->coeff.getval();
924  delete resultfirst;
925  }
926  else
927  quot = new InternalPoly( resultfirst, resultlast, var );
928  else
929  quot = CFFactory::basic( 0L );
930  if ( first )
931  if ( first->exp == 0 )
932  {
933  rem = first->coeff.getval();
934  delete first;
935  }
936  else
937  {
938  if (first->coeff.isZero())
939  {
940  rem= CFFactory::basic (0L);
941  delete first;
942  }
943  else
944  rem = new InternalPoly( first, last, var );
945  }
946  else
947  rem = CFFactory::basic( 0L );
948  }
949  else
950  {
951  freeTermList( resultfirst );
952  freeTermList( first );
953  }
954  return divideok;
955 }
virtual InternalCF * tryMulsame(InternalCF *, const CanonicalForm &)
Definition: int_cf.cc:179
virtual InternalCF * tryInvert(const CanonicalForm &, bool &)
Definition: int_cf.cc:186

◆ tryDivsame()

InternalCF * InternalPoly::tryDivsame ( InternalCF aCoeff,
const CanonicalForm M,
bool &  fail 
)
virtual

Reimplemented from InternalCF.

Definition at line 576 of file int_poly.cc.

577 {
578  if ( inExtension() && !getReduce( var ) )
579  {
580  InternalCF * dummy = aCoeff->tryInvert(M, fail);
581  if (fail)
582  return CFFactory::basic( 0L );
583  if (is_imm(dummy)) dummy=this->tryMulsame(dummy, M);
584  else dummy = dummy->tryMulsame( this, M);
585  if (fail)
586  {
587  if (getRefCount() <= 1)
588  delete this;
589  else
590  decRefCount();
591  return dummy;
592  }
593  if ( getRefCount() <= 1 )
594  {
595  delete this;
596  return dummy;
597  }
598  else
599  {
600  decRefCount();
601  return dummy;
602  }
603  }
604  InternalPoly *aPoly = (InternalPoly*)aCoeff;
605  termList dummy, first, last, resultfirst = 0, resultlast = 0;
606  CanonicalForm coeff, newcoeff;
607  int exp, newexp;
608  bool singleObject;
609 
610  if ( getRefCount() <= 1 )
611  {
612  first = firstTerm; last = lastTerm; singleObject = true;
613  }
614  else
615  {
616  first = copyTermList( firstTerm, last ); singleObject = false;
617  decRefCount();
618  }
619  coeff = aPoly->firstTerm->coeff;
620  exp = aPoly->firstTerm->exp;
621  while (first && ( first->exp >= exp ) )
622  {
623  newcoeff= first->coeff.tryDiv (coeff, M, fail);
624  if (fail)
625  {
626  freeTermList (first);
627  return CFFactory::basic (0L);
628  }
629  newcoeff= reduce (newcoeff, M);
630  newexp = first->exp - exp;
631  dummy = first;
632  first = mulAddTermList( first->next, aPoly->firstTerm->next, newcoeff, newexp, last, true );
633  delete dummy;
634  if (!newcoeff.isZero())
635  appendTermList( resultfirst, resultlast, newcoeff, newexp );
636  }
637  freeTermList( first );
638  if ( singleObject )
639  {
640  if ( resultfirst && resultfirst->exp != 0 )
641  {
642  firstTerm = resultfirst;
643  lastTerm = resultlast;
644  return this;
645  }
646  else if ( resultfirst )
647  {
648  InternalCF * res = resultfirst->coeff.getval();
649  delete resultfirst;
650  firstTerm = 0;
651  delete this;
652  return res;
653  }
654  else
655  {
656  // this should not happen (evtl use assertion)
657  ASSERT( 0, "FATAL ERROR, PLEASE INFORM THE AUTHOR" );
658  firstTerm = 0;
659  delete this;
660  return CFFactory::basic( 0L );
661  }
662  }
663  else
664  {
665  if ( resultfirst && resultfirst->exp != 0 )
666  return new InternalPoly( resultfirst, resultlast, var );
667  else if ( resultfirst )
668  {
669  InternalCF * res = resultfirst->coeff.getval();
670  delete resultfirst;
671  return res;
672  }
673  else
674  return CFFactory::basic( 0L );
675  }
676 }
CanonicalForm reduce(const CanonicalForm &f, const CanonicalForm &M)
polynomials in M.mvar() are considered coefficients M univariate monic polynomial the coefficients of...
Definition: cf_ops.cc:646
CanonicalForm & tryDiv(const CanonicalForm &, const CanonicalForm &, bool &)
same as divremt but handles zero divisors in case we are in Z_p[x]/(f) where f is not irreducible
InternalCF * tryMulsame(InternalCF *, const CanonicalForm &)
Definition: int_poly.cc:420

◆ tryDivTermList()

termList InternalPoly::tryDivTermList ( termList  firstTerm,
const CanonicalForm coeff,
termList lastTerm,
const CanonicalForm M,
bool &  fail 
)
staticprivate

Definition at line 2065 of file int_poly.cc.

2066 {
2067  termList theCursor = firstTerm;
2068  lastTerm = 0;
2069  termList dummy;
2070 
2071  while ( theCursor )
2072  {
2073  theCursor->coeff.tryDiv( coeff, M, fail );
2074  if (fail)
2075  return 0;
2076  if ( theCursor->coeff.isZero() )
2077  {
2078  if ( theCursor == firstTerm )
2079  firstTerm = theCursor->next;
2080  else
2081  lastTerm->next = theCursor->next;
2082  dummy = theCursor;
2083  theCursor = theCursor->next;
2084  delete dummy;
2085  }
2086  else
2087  {
2088  lastTerm = theCursor;
2089  theCursor = theCursor->next;
2090  }
2091  }
2092  return firstTerm;
2093 }

◆ tryInvert()

InternalCF * InternalPoly::tryInvert ( const CanonicalForm M,
bool &  fail 
)
virtual

Reimplemented from InternalCF.

Definition at line 256 of file int_poly.cc.

257 {
258  if ( inExtension() && !getReduce ( var ) )
259  {
260  CanonicalForm b, inverse;
261  CanonicalForm F ( this ->copyObject() );
262  Variable a = M.mvar();
263  Variable x = Variable(1);
264  F= mod (F, M); //reduce mod M
265  CanonicalForm g= extgcd (replacevar( F, a, x ), replacevar( M, a, x ), inverse, b );
266  if(!g.isOne())
267  fail = true;
268  else
269  inverse = replacevar( inverse, x, a ); // change back to alg var
270  CanonicalForm test= mod (inverse*F, M);
271  return inverse.getval();
272  }
273  else
274  return CFFactory::basic( 0L );
275 }
CF_NO_INLINE CanonicalForm mod(const CanonicalForm &, const CanonicalForm &)
Definition: cf_inline.cc:564
CanonicalForm replacevar(const CanonicalForm &, const Variable &, const Variable &)
CanonicalForm replacevar ( const CanonicalForm & f, const Variable & x1, const Variable & x2 )
Definition: cf_ops.cc:271
Variable x
Definition: cfModGcd.cc:4023
CanonicalForm test
Definition: cfModGcd.cc:4037
factory's class for variables
Definition: factory.h:118

◆ tryMulsame()

InternalCF * InternalPoly::tryMulsame ( InternalCF aCoeff,
const CanonicalForm M 
)
virtual

Reimplemented from InternalCF.

Definition at line 420 of file int_poly.cc.

421 {
422  if (is_imm(aCoeff))
423  return mulcoeff(aCoeff);
424  InternalPoly *aPoly = (InternalPoly*)aCoeff;
425  termList resultFirst = 0, resultLast = 0;
426  termList theCursor = firstTerm;
427 
428  while ( theCursor )
429  {
430  resultFirst = mulAddTermList( resultFirst, aPoly->firstTerm,
431  theCursor->coeff, theCursor->exp, resultLast, false );
432  theCursor = theCursor->next;
433  }
434  if ( inExtension() && !getReduce( var ) )
435  {
436  resultFirst= reduceTermList (resultFirst, ((InternalPoly*) M.getval())->firstTerm, resultLast);
437  if ( resultFirst == 0 )
438  {
439  if ( getRefCount() <= 1 )
440  {
441  delete this;
442  return CFFactory::basic(0L);
443  }
444  else
445  {
446  decRefCount();
447  return CFFactory::basic(0L);
448  }
449  }
450  else if ( resultFirst->exp == 0 )
451  {
452  if ( getRefCount() <= 1 )
453  {
454  InternalCF * res = resultFirst->coeff.getval();
455  delete resultFirst;
456  delete this;
457  return res;
458  }
459  else
460  {
461  decRefCount();
462  InternalCF * res = resultFirst->coeff.getval();
463  delete resultFirst;
464  return res;
465  }
466  }
467  }
468  if ( getRefCount() <= 1 )
469  {
471  firstTerm = resultFirst;
472  lastTerm = resultLast;
473  return this;
474  }
475  else
476  {
477  decRefCount();
478  return new InternalPoly( resultFirst, resultLast, var );
479  }
480 }

◆ variable()

Variable InternalPoly::variable ( ) const
inlinevirtual

Reimplemented from InternalCF.

Definition at line 98 of file int_poly.h.

98 { return var; }

Friends And Related Function Documentation

◆ CFIterator

friend class CFIterator
friend

Definition at line 171 of file int_poly.h.

Field Documentation

◆ firstTerm

termList InternalPoly::firstTerm
private

Definition at line 73 of file int_poly.h.

◆ InternalPoly_bin

const omBin InternalPoly::InternalPoly_bin = omGetSpecBin(sizeof(InternalPoly))
static

Definition at line 159 of file int_poly.h.

◆ lastTerm

termList InternalPoly::lastTerm
private

Definition at line 73 of file int_poly.h.

◆ var

Variable InternalPoly::var
private

Definition at line 74 of file int_poly.h.


The documentation for this class was generated from the following files: