My Project
Loading...
Searching...
No Matches
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...
 
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 InternalCFdeepCopyObject () const PVIRT_INTCF("deepCopyObject")
 
virtual const char * classname () const PVIRT_CHARCC("classname")
 
virtual InternalCFgenZero () PVIRT_INTCF("genZero")
 
virtual InternalCFgenOne () PVIRT_INTCF("genOne")
 
virtual int level () const
 
virtual int levelcoeff () const
 
virtual int type () const
 
virtual Variable variable () const
 
virtual void print (OSTREAM &, char *) PVIRT_VOID("print")
 
virtual bool inBaseDomain () const
 
virtual bool inExtension () const
 
virtual bool inCoeffDomain () const
 
virtual bool inPolyDomain () const
 
virtual bool inQuotDomain () const
 
virtual bool isZero () const
 
virtual bool isOne () const
 bool InternalCF::isOne, isZero () const More...
 
virtual bool isUnivariate () const
 
virtual long intval () const
 
virtual int intmod (int) const
 
virtual int sign () const PVIRT_INT("sign")
 
virtual InternalCFnum ()
 InternalCF * InternalCF::num (), den () More...
 
virtual InternalCFden ()
 
virtual InternalCFneg () PVIRT_INTCF("neg")
 
virtual InternalCFinvert ()
 
virtual InternalCFtryInvert (const CanonicalForm &, bool &)
 
virtual int comparesame (InternalCF *) PVIRT_INT("comparesame")
 
virtual int comparecoeff (InternalCF *) PVIRT_INT("comparecoeff")
 
virtual InternalCFaddsame (InternalCF *) PVIRT_INTCF("addsame")
 
virtual InternalCFsubsame (InternalCF *) PVIRT_INTCF("subsame")
 
virtual InternalCFmulsame (InternalCF *) PVIRT_INTCF("mulsame")
 
virtual InternalCFtryMulsame (InternalCF *, const CanonicalForm &)
 
virtual InternalCFdividesame (InternalCF *) PVIRT_INTCF("dividesame")
 
virtual InternalCFmodulosame (InternalCF *) PVIRT_INTCF("modulosame")
 
virtual InternalCFdivsame (InternalCF *) PVIRT_INTCF("divsame")
 
virtual InternalCFtryDivsame (InternalCF *, const CanonicalForm &, bool &)
 
virtual InternalCFmodsame (InternalCF *) PVIRT_INTCF("modsame")
 
virtual void divremsame (InternalCF *, InternalCF *&, InternalCF *&) PVIRT_VOID("divremsame")
 
virtual bool divremsamet (InternalCF *, InternalCF *&, InternalCF *&) PVIRT_BOOL("divremsamet")
 
virtual bool tryDivremsamet (InternalCF *, InternalCF *&, InternalCF *&, const CanonicalForm &, bool &)
 
virtual InternalCFaddcoeff (InternalCF *) PVIRT_INTCF("addcoeff")
 
virtual InternalCFsubcoeff (InternalCF *, bool) PVIRT_INTCF("subcoeff")
 
virtual InternalCFmulcoeff (InternalCF *) PVIRT_INTCF("mulcoeff")
 
virtual InternalCFdividecoeff (InternalCF *, bool) PVIRT_INTCF("dividecoeff")
 
virtual InternalCFtryDividecoeff (InternalCF *, bool, const CanonicalForm &, bool &)
 
virtual InternalCFmodulocoeff (InternalCF *, bool) PVIRT_INTCF("dividecoeff")
 
virtual InternalCFdivcoeff (InternalCF *, bool) PVIRT_INTCF("divcoeff")
 
virtual InternalCFtryDivcoeff (InternalCF *, bool, const CanonicalForm &, bool &)
 
virtual InternalCFmodcoeff (InternalCF *, bool) PVIRT_INTCF("modcoeff")
 
virtual void divremcoeff (InternalCF *, InternalCF *&, InternalCF *&, bool) PVIRT_VOID("divremcoeff")
 
virtual bool divremcoefft (InternalCF *, InternalCF *&, InternalCF *&, bool) PVIRT_BOOL("divremcoefft")
 
virtual bool tryDivremcoefft (InternalCF *, InternalCF *&, InternalCF *&, bool, const CanonicalForm &, bool &)
 
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...
 
virtual CanonicalForm lc ()
 CanonicalForm InternalCF::lc (), Lc (), LC () More...
 
virtual CanonicalForm Lc ()
 
virtual CanonicalForm LC ()
 
virtual CanonicalForm coeff (int i)
 CanonicalForm InternalCF::coeff ( int i ) More...
 
virtual int degree ()
 int InternalCF::degree () More...
 
virtual int taildegree ()
 
virtual CanonicalForm tailcoeff ()
 CanonicalForm InternalCF::tailcoeff (), int InternalCF::taildegree () 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 46 of file int_poly.cc.

47{
48 firstTerm = first;
49 lastTerm = last;
50 var = v;
51}
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:39
STATIC_VAR poly last
Definition: hdegree.cc:1173

◆ InternalPoly() [2/4]

InternalPoly::InternalPoly ( )

Definition at line 53 of file int_poly.cc.

54{
55 ASSERT( 0, "ups, why do you initialize an empty poly" );
56}
#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 58 of file int_poly.cc.

59{
60 var = v;
61 firstTerm = new term( 0, c, e );
63}
Definition: int_poly.h:33

◆ InternalPoly() [4/4]

InternalPoly::InternalPoly ( const InternalPoly )

Definition at line 65 of file int_poly.cc.

65 :InternalCF()
66{
67 ASSERT( 0, "ups there is something wrong in your code" );
68}
InternalCF()
Definition: int_cf.h:55

◆ ~InternalPoly()

InternalPoly::~InternalPoly ( )

Definition at line 70 of file int_poly.cc.

71{
73}
static void freeTermList(termList)
Definition: int_poly.cc:1898

Member Function Documentation

◆ addcoeff()

InternalCF * InternalPoly::addcoeff ( InternalCF cc)
virtual

Reimplemented from InternalCF.

Definition at line 1038 of file int_poly.cc.

1039{
1040 CanonicalForm c( is_imm(cc) ? cc : cc->copyObject() );
1041 if ( c.isZero() )
1042 return this;
1043 else
1044 {
1045 if ( getRefCount() <= 1 )
1046 {
1047 if ( lastTerm->exp == 0 )
1048 {
1049 lastTerm->coeff += c;
1050 if ( lastTerm->coeff.isZero() )
1051 {
1052 termList cursor = firstTerm;
1053 while ( cursor->next != lastTerm )
1054 cursor = cursor->next;
1055 delete lastTerm;
1056 cursor->next = 0;
1057 lastTerm = cursor;
1058 }
1059 }
1060 else
1061 {
1062 lastTerm->next = new term( 0, c, 0 );
1064 }
1065 return this;
1066 }
1067 else
1068 {
1069 decRefCount();
1070 termList last, first = copyTermList( firstTerm, last, false );
1071 if ( last->exp == 0 )
1072 {
1073 last->coeff += c;
1074 if ( last->coeff.isZero() )
1075 {
1076 termList cursor = first;
1077 while ( cursor->next != last )
1078 cursor = cursor->next;
1079 delete last;
1080 cursor->next = 0;
1081 last = cursor;
1082 }
1083 }
1084 else
1085 {
1086 last->next = new term( 0, c, 0L );
1087 last = last->next;
1088 }
1089 return new InternalPoly( first, last, var );
1090 }
1091 }
1092}
int is_imm(const InternalCF *const ptr)
Definition: canonicalform.h:65
factory's main class
Definition: canonicalform.h:86
CF_NO_INLINE bool isZero() const
InternalCF * copyObject()
Definition: int_cf.h:62
int getRefCount()
Definition: int_cf.h:51
int decRefCount()
Definition: int_cf.h:53
static termList copyTermList(termList, termList &, bool negate=false)
Definition: int_poly.cc:1830
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 286 of file int_poly.cc.

287{
288 InternalPoly * aPoly = (InternalPoly*)aCoeff;
289 if ( getRefCount() <= 1 )
290 {
291 firstTerm = addTermList( firstTerm, aPoly->firstTerm, lastTerm, false );
292 if ( firstTerm && firstTerm->exp != 0 )
293 return this;
294 else if ( firstTerm )
295 {
297 delete this;
298 return res;
299 }
300 else
301 {
302 delete this;
303 return CFFactory::basic( 0 );
304 }
305 }
306 else
307 {
308 decRefCount();
310 first = addTermList( first, aPoly->firstTerm, last, false );
311 if ( first && first->exp != 0 )
312 return new InternalPoly( first, last, var );
313 else if ( first )
314 {
315 InternalCF * res = first->coeff.getval();
316 delete first;
317 return res;
318 }
319 else
320 return CFFactory::basic( 0 );
321
322 }
323}
static InternalCF * basic(int value)
Definition: cf_factory.cc:61
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:1922
CanonicalForm res
Definition: facAbsFact.cc:60

◆ addTermList()

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

Definition at line 1922 of file int_poly.cc.

1923{
1924 termList theCursor = theList;
1925 termList aCursor = aList;
1926 termList predCursor = 0;
1927
1928 if (negate)
1929 while ( theCursor && aCursor )
1930 {
1931 if ( theCursor->exp == aCursor->exp )
1932 {
1933 theCursor->coeff -= aCursor->coeff;
1934 if ( theCursor->coeff.isZero() )
1935 {
1936 if ( predCursor )
1937 {
1938 predCursor->next = theCursor->next;
1939 delete theCursor;
1940 theCursor = predCursor->next;
1941 }
1942 else
1943 {
1944 theList = theList->next;
1945 delete theCursor;
1946 theCursor = theList;
1947 }
1948 }
1949 else
1950 {
1951 predCursor = theCursor;
1952 theCursor = theCursor->next;
1953 }
1954 aCursor = aCursor->next;
1955 }
1956 else if ( theCursor->exp < aCursor->exp )
1957 {
1958 if ( predCursor )
1959 {
1960 predCursor->next = new term( theCursor, -aCursor->coeff, aCursor->exp );
1961 predCursor = predCursor->next;
1962 }
1963 else
1964 {
1965 theList = new term( theCursor, -aCursor->coeff, aCursor->exp );
1966 predCursor = theList;
1967 }
1968 aCursor = aCursor->next;
1969 }
1970 else
1971 {
1972 predCursor = theCursor;
1973 theCursor = theCursor->next;
1974 }
1975 }
1976 else
1977 while ( theCursor && aCursor )
1978 {
1979 if ( theCursor->exp == aCursor->exp )
1980 {
1981 theCursor->coeff += aCursor->coeff;
1982 if ( theCursor->coeff.isZero() )
1983 {
1984 if ( predCursor )
1985 {
1986 predCursor->next = theCursor->next;
1987 delete theCursor;
1988 theCursor = predCursor->next;
1989 }
1990 else
1991 {
1992 theList = theList->next;
1993 delete theCursor;
1994 theCursor = theList;
1995 }
1996 }
1997 else
1998 {
1999 predCursor = theCursor;
2000 theCursor = theCursor->next;
2001 }
2002 aCursor = aCursor->next;
2003 }
2004 else if ( theCursor->exp < aCursor->exp )
2005 {
2006 if ( predCursor )
2007 {
2008 predCursor->next = new term( theCursor, aCursor->coeff, aCursor->exp );
2009 predCursor = predCursor->next;
2010 }
2011 else
2012 {
2013 theList = new term( theCursor, aCursor->coeff, aCursor->exp );
2014 predCursor = theList;
2015 }
2016 aCursor = aCursor->next;
2017 }
2018 else
2019 {
2020 predCursor = theCursor;
2021 theCursor = theCursor->next;
2022 }
2023 }
2024 if ( aCursor )
2025 {
2026 if ( predCursor )
2027 predCursor->next = copyTermList( aCursor, lastTerm, negate );
2028 else
2029 theList = copyTermList( aCursor, lastTerm, negate );
2030 }
2031 else if ( ! theCursor )
2032 lastTerm = predCursor;
2033
2034 return theList;
2035}

◆ appendTermList()

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

Definition at line 2167 of file int_poly.cc.

2168{
2169 if ( last )
2170 {
2171 last->next = new term( 0, coeff, exp );
2172 last = last->next;
2173 }
2174 else
2175 {
2176 first = new term( 0, coeff, exp );
2177 last = first;
2178 }
2179}
CanonicalForm coeff(int i)
CanonicalForm InternalPoly::coeff ( int i )
Definition: int_poly.cc:162
gmp_float exp(const gmp_float &a)
Definition: mpr_complex.cc:357

◆ 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 162 of file int_poly.cc.

163{
164 termList theCursor = firstTerm;
165 while ( theCursor )
166 {
167 if ( theCursor->exp == i )
168 return theCursor->coeff;
169 else if ( theCursor->exp < i )
170 return CanonicalForm( 0 );
171 else
172 theCursor = theCursor->next;
173 }
174 return CanonicalForm( 0 );
175}
int i
Definition: cfEzgcd.cc:132

◆ 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 1032 of file int_poly.cc.

1033{
1034 return 1;
1035}

◆ 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 990 of file int_poly.cc.

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

◆ copyTermList()

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

Definition at line 1830 of file int_poly.cc.

1831{
1832 if ( UNLIKELY(aTermList == 0) )
1833 return 0;
1834 else if ( negate )
1835 {
1836 termList sourceCursor = aTermList;
1837 termList dummy = new term;
1838 termList targetCursor = dummy;
1839
1840 while ( LIKELY(sourceCursor) )
1841 {
1842 targetCursor->next = new term( 0, -sourceCursor->coeff, sourceCursor->exp );
1843 targetCursor = targetCursor->next;
1844 sourceCursor = sourceCursor->next;
1845 }
1846 targetCursor->next = 0;
1847 theLastTerm = targetCursor;
1848 targetCursor = dummy->next;
1849 delete dummy;
1850 return targetCursor;
1851 }
1852 else
1853 {
1854 termList sourceCursor = aTermList;
1855 termList dummy = new term;
1856 termList targetCursor = dummy;
1857
1858 while ( LIKELY(sourceCursor) )
1859 {
1860 targetCursor->next = new term( 0, sourceCursor->coeff, sourceCursor->exp );
1861 targetCursor = targetCursor->next;
1862 sourceCursor = sourceCursor->next;
1863 }
1864 targetCursor->next = 0;
1865 theLastTerm = targetCursor;
1866 targetCursor = dummy->next;
1867 delete dummy;
1868 return targetCursor;
1869 }
1870}
#define UNLIKELY(X)
Definition: auxiliary.h:404
#define LIKELY(X)
Definition: auxiliary.h:403

◆ deepCopyObject()

InternalCF * InternalPoly::deepCopyObject ( ) const
virtual

Reimplemented from InternalCF.

Definition at line 76 of file int_poly.cc.

77{
78 termList first, last;
80 return new InternalPoly( first, last, var );
81}
static termList deepCopyTermList(termList, termList &)
Definition: int_poly.cc:1873

◆ deepCopyTermList()

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

Definition at line 1873 of file int_poly.cc.

1874{
1875 if ( aTermList == 0 )
1876 return 0;
1877 else
1878 {
1879 termList sourceCursor = aTermList;
1880 termList dummy = new term;
1881 termList targetCursor = dummy;
1882
1883 while ( sourceCursor )
1884 {
1885 targetCursor->next = new term( 0, sourceCursor->coeff.deepCopy(), sourceCursor->exp );
1886 targetCursor = targetCursor->next;
1887 sourceCursor = sourceCursor->next;
1888 }
1889 targetCursor->next = 0;
1890 theLastTerm = targetCursor;
1891 targetCursor = dummy->next;
1892 delete dummy;
1893 return targetCursor;
1894 }
1895}
CanonicalForm deepCopy() const

◆ degree()

int InternalPoly::degree ( )
virtual

int InternalPoly::degree ()

See also
CanonicalForm::sign ()

Reimplemented from InternalCF.

Definition at line 100 of file int_poly.cc.

101{
102 return firstTerm->exp;
103}

◆ divcoeff()

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

Reimplemented from InternalCF.

Definition at line 1399 of file int_poly.cc.

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

◆ dividecoeff()

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

Reimplemented from InternalCF.

Definition at line 1217 of file int_poly.cc.

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

◆ dividesame()

InternalCF * InternalPoly::dividesame ( InternalCF aCoeff)
virtual

Reimplemented from InternalCF.

Definition at line 491 of file int_poly.cc.

492{
493 return divsame( aCoeff );
494}
InternalCF * divsame(InternalCF *)
Definition: int_poly.cc:498

◆ divideTermList()

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

Definition at line 2049 of file int_poly.cc.

2050{
2051 termList theCursor = firstTerm;
2052 lastTerm = 0;
2053 termList dummy;
2054
2055 while ( LIKELY(theCursor) )
2056 {
2057 theCursor->coeff /= coeff;
2058 if ( theCursor->coeff.isZero() )
2059 {
2060 if ( theCursor == firstTerm )
2061 firstTerm = theCursor->next;
2062 else
2063 lastTerm->next = theCursor->next;
2064 dummy = theCursor;
2065 theCursor = theCursor->next;
2066 delete dummy;
2067 }
2068 else
2069 {
2070 lastTerm = theCursor;
2071 theCursor = theCursor->next;
2072 }
2073 }
2074 return firstTerm;
2075}

◆ divremcoeff()

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

Reimplemented from InternalCF.

Definition at line 1652 of file int_poly.cc.

1653{
1654 if ( inExtension() && getReduce( var ) )
1655 {
1656 quot = copyObject();
1657 quot = quot->dividecoeff( cc, invert );
1658 rem = CFFactory::basic( 0 );
1659 }
1660 else if ( invert )
1661 {
1662 if ( is_imm( cc ) )
1663 rem = cc;
1664 else
1665 rem = cc->copyObject();
1666 quot = CFFactory::basic( 0 );
1667 }
1668 else
1669 {
1670 CanonicalForm c( is_imm(cc) ? cc : cc->copyObject() );
1671 ASSERT( ! c.isZero(), "divide by zero!" );
1672 termList quotlast, quotfirst = copyTermList( firstTerm, quotlast );
1673 quotfirst = divideTermList( quotfirst, c, quotlast );
1674 if ( quotfirst )
1675 if ( quotfirst->exp == 0 )
1676 {
1677 quot = quotfirst->coeff.getval();
1678 delete quotfirst;
1679 }
1680 else
1681 quot = new InternalPoly( quotfirst, quotlast, var );
1682 else
1683 quot = CFFactory::basic( 0 );
1684 rem = CFFactory::basic( 0 );
1685 }
1686}
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 1689 of file int_poly.cc.

1690{
1691 if ( inExtension() && getReduce( var ) )
1692 {
1693 quot = copyObject();
1694 quot = quot->dividecoeff( cc, invert );
1695 rem = CFFactory::basic( 0 );
1696 return true;
1697 }
1698 else if ( invert )
1699 {
1700 if ( is_imm( cc ) )
1701 rem = cc;
1702 else
1703 rem = cc->copyObject();
1704 quot = CFFactory::basic( 0 );
1705 return true;
1706 }
1707 CanonicalForm c( is_imm(cc) ? cc : cc->copyObject() );
1708 ASSERT( ! c.isZero(), "divide by zero!" );
1709 termList quotfirst, quotcursor;
1710 termList cursor;
1711 CanonicalForm cquot, crem;
1712 bool divideok = true;
1713
1714 cursor = firstTerm;
1715 quotcursor = quotfirst = new term;
1716
1717 while ( cursor && divideok )
1718 {
1719 divideok = divremt( cursor->coeff, c, cquot, crem );
1720 divideok = divideok && crem.isZero();
1721 if ( divideok )
1722 {
1723 if ( ! cquot.isZero() )
1724 {
1725 quotcursor->next = new term( 0, cquot, cursor->exp );
1726 quotcursor = quotcursor->next;
1727 }
1728 cursor = cursor->next;
1729 }
1730 }
1731 quotcursor->next = 0;
1732 if ( divideok )
1733 {
1734 cursor = quotfirst; quotfirst = quotfirst->next; delete cursor;
1735 if ( quotfirst )
1736 if ( quotfirst->exp == 0 )
1737 {
1738 quot = quotfirst->coeff.getval();
1739 delete quotfirst;
1740 }
1741 else
1742 quot = new InternalPoly( quotfirst, quotcursor, var );
1743 else
1744 quot = CFFactory::basic( 0 );
1745 rem = CFFactory::basic( 0 );
1746 }
1747 else
1748 {
1749 freeTermList( quotfirst );
1750 }
1751 return divideok;
1752}
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 765 of file int_poly.cc.

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

◆ divremsamet()

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

Reimplemented from InternalCF.

Definition at line 817 of file int_poly.cc.

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

◆ divsame()

InternalCF * InternalPoly::divsame ( InternalCF aCoeff)
virtual

Reimplemented from InternalCF.

Definition at line 498 of file int_poly.cc.

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

◆ divTermList()

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

Definition at line 2078 of file int_poly.cc.

2079{
2080 termList theCursor = firstTerm;
2081 lastTerm = 0;
2082 termList dummy;
2083
2084 while ( LIKELY(theCursor) )
2085 {
2086 theCursor->coeff.div( coeff );
2087 if ( theCursor->coeff.isZero() )
2088 {
2089 if ( theCursor == firstTerm )
2090 firstTerm = theCursor->next;
2091 else
2092 lastTerm->next = theCursor->next;
2093 dummy = theCursor;
2094 theCursor = theCursor->next;
2095 delete dummy;
2096 }
2097 else
2098 {
2099 lastTerm = theCursor;
2100 theCursor = theCursor->next;
2101 }
2102 }
2103 return firstTerm;
2104}
CanonicalForm & div(const CanonicalForm &)

◆ freeTermList()

void InternalPoly::freeTermList ( termList  aTermList)
staticprivate

Definition at line 1898 of file int_poly.cc.

1899{
1900 termList cursor = aTermList;
1901
1902 while ( LIKELY(cursor) )
1903 {
1904 cursor = cursor->next;
1905 delete aTermList;
1906 aTermList = cursor;
1907 }
1908}

◆ 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
input/output

◆ 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: variable.h:49

◆ 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 247 of file int_poly.cc.

248{
249 if ( inExtension() && getReduce( var ) )
250 {
251 setReduce( var, false );
252 CanonicalForm a( this->copyObject() );
254 CanonicalForm u, v;
255 CanonicalForm g = extgcd( a, b, u, v );
256 setReduce( var, true );
257 return u.getval();
258 }
259 else
260 return CFFactory::basic( 0 );
261}
g
Definition: cfModGcd.cc:4090
CanonicalForm b
Definition: cfModGcd.cc:4103
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:174
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 84 of file int_poly.cc.

85{
86 termList cursor = firstTerm;
87 while ( cursor )
88 {
89 if ( ! cursor->coeff.inCoeffDomain() )
90 return false;
91 cursor = cursor->next;
92 }
93 return true;
94}
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 120 of file int_poly.cc.

121{
122 return firstTerm->coeff.lc();
123}
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 129 of file int_poly.cc.

130{
131 return firstTerm->coeff.Lc();
132}
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 138 of file int_poly.cc.

139{
140 return firstTerm->coeff;
141}

◆ 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 1588 of file int_poly.cc.

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

◆ modsame()

InternalCF * InternalPoly::modsame ( InternalCF aCoeff)
virtual

Reimplemented from InternalCF.

Definition at line 693 of file int_poly.cc.

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

◆ modTermList()

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

Definition at line 2138 of file int_poly.cc.

2139{
2140 termList theCursor = firstTerm;
2141 lastTerm = 0;
2142 termList dummy;
2143
2144 while ( theCursor )
2145 {
2146 theCursor->coeff.mod( coeff );
2147 if ( theCursor->coeff.isZero() )
2148 {
2149 if ( theCursor == firstTerm )
2150 firstTerm = theCursor->next;
2151 else
2152 lastTerm->next = theCursor->next;
2153 dummy = theCursor;
2154 theCursor = theCursor-> next;
2155 delete dummy;
2156 }
2157 else
2158 {
2159 lastTerm = theCursor;
2160 theCursor = theCursor->next;
2161 }
2162 }
2163 return firstTerm;
2164}
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 1574 of file int_poly.cc.

1575{
1576 CanonicalForm c( is_imm(cc) ? cc : cc->copyObject() );
1577 if ( invert )
1578 {
1579 if ( deleteObject() ) delete this;
1580 return c.getval();
1581 }
1582 ASSERT( ! c.isZero(), "divide by zero!" );
1583 if ( deleteObject() ) delete this;
1584 return CFFactory::basic( 0 );
1585}

◆ modulosame()

InternalCF * InternalPoly::modulosame ( InternalCF aCoeff)
virtual

Reimplemented from InternalCF.

Definition at line 687 of file int_poly.cc.

688{
689 return modsame( aCoeff );
690}
InternalCF * modsame(InternalCF *)
Definition: int_poly.cc:693

◆ mulAddTermList()

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

Definition at line 2182 of file int_poly.cc.

2183{
2184 termList theCursor = theList;
2185 termList aCursor = aList;
2186 termList predCursor = 0;
2188
2189 if ( negate )
2190 coeff = -c;
2191 else
2192 coeff = c;
2193
2194 while ( theCursor && aCursor )
2195 {
2196 if ( theCursor->exp == aCursor->exp + exp )
2197 {
2198 theCursor->coeff += aCursor->coeff * coeff;
2199 if(UNLIKELY(( theCursor->coeff.isZero() )))
2200 {
2201 if ( predCursor )
2202 {
2203 predCursor->next = theCursor->next;
2204 delete theCursor;
2205 theCursor = predCursor->next;
2206 }
2207 else
2208 {
2209 theList = theList->next;
2210 delete theCursor;
2211 theCursor = theList;
2212 }
2213 }
2214 else
2215 {
2216 predCursor = theCursor;
2217 theCursor = theCursor->next;
2218 }
2219 aCursor = aCursor->next;
2220 }
2221 else if ( theCursor->exp < aCursor->exp + exp )
2222 {
2223 if ( predCursor )
2224 {
2225 predCursor->next = new term( theCursor, aCursor->coeff * coeff, aCursor->exp + exp );
2226 predCursor = predCursor->next;
2227 }
2228 else
2229 {
2230 theList = new term( theCursor, aCursor->coeff * coeff, aCursor->exp + exp );
2231 predCursor = theList;
2232 }
2233 aCursor = aCursor->next;
2234 }
2235 else
2236 {
2237 predCursor = theCursor;
2238 theCursor = theCursor->next;
2239 }
2240 }
2241 if ( aCursor )
2242 {
2243 if ( predCursor )
2244 {
2245 predCursor->next = copyTermList( aCursor, lastTerm );
2246 predCursor = predCursor->next;
2247 }
2248 else
2249 {
2250 theList = copyTermList( aCursor, lastTerm );
2251 predCursor = theList;
2252 }
2253 while ( predCursor )
2254 {
2255 predCursor->exp += exp;
2256 predCursor->coeff *= coeff;
2257 predCursor = predCursor->next;
2258 }
2259 }
2260 else if ( ! theCursor )
2261 lastTerm = predCursor;
2262 return theList;
2263}

◆ mulcoeff()

InternalCF * InternalPoly::mulcoeff ( InternalCF cc)
virtual

Reimplemented from InternalCF.

Definition at line 1181 of file int_poly.cc.

1182{
1183 CanonicalForm c( is_imm(cc) ? cc : cc->copyObject() );
1184 if ( c.isZero() )
1185 {
1186 if ( getRefCount() <= 1 )
1187 {
1188 delete this;
1189 return CFFactory::basic( 0 );
1190 }
1191 else
1192 {
1193 decRefCount();
1194 return CFFactory::basic( 0 );
1195 }
1196 }
1197 else if ( c.isOne() )
1198 return this;
1199 else
1200 {
1201 if ( getRefCount() <= 1 )
1202 {
1203 mulTermList( firstTerm, c, 0 );
1204 return this;
1205 }
1206 else
1207 {
1208 decRefCount();
1210 mulTermList( first, c, 0 );
1211 return new InternalPoly( first, last, var );
1212 }
1213 }
1214}
static void mulTermList(termList, const CanonicalForm &, const int)
Definition: int_poly.cc:2038

◆ mulsame()

InternalCF * InternalPoly::mulsame ( InternalCF aCoeff)
virtual

Reimplemented from InternalCF.

Definition at line 366 of file int_poly.cc.

367{
368 if (is_imm(aCoeff)) return mulcoeff(aCoeff);
369 InternalPoly *aPoly = (InternalPoly*)aCoeff;
370 termList resultFirst = 0, resultLast = 0;
371 termList theCursor = firstTerm;
372
373 while ( theCursor )
374 {
375 resultFirst = mulAddTermList( resultFirst, aPoly->firstTerm,
376 theCursor->coeff, theCursor->exp, resultLast, false );
377 theCursor = theCursor->next;
378 }
379 if ( inExtension() && getReduce( var ) )
380 {
381 resultFirst = reduceTermList( resultFirst, (getInternalMipo( var ))->firstTerm, resultLast );
382 if ( resultFirst == 0 )
383 {
384 if ( getRefCount() <= 1 )
385 {
386 delete this;
387 return CFFactory::basic(0);
388 }
389 else
390 {
391 decRefCount();
392 return CFFactory::basic(0);
393 }
394 }
395 else if ( resultFirst->exp == 0 )
396 {
397 if ( getRefCount() <= 1 )
398 {
399 InternalCF * res = resultFirst->coeff.getval();
400 delete resultFirst;
401 delete this;
402 return res;
403 }
404 else
405 {
406 decRefCount();
407 InternalCF * res = resultFirst->coeff.getval();
408 delete resultFirst;
409 return res;
410 }
411 }
412 }
413 if ( getRefCount() <= 1 )
414 {
416 firstTerm = resultFirst;
417 lastTerm = resultLast;
418 return this;
419 }
420 else
421 {
422 decRefCount();
423 return new InternalPoly( resultFirst, resultLast, var );
424 }
425}
InternalCF * mulcoeff(InternalCF *)
Definition: int_poly.cc:1181
static termList reduceTermList(termList first, termList redterms, termList &last)
Definition: int_poly.cc:2266
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 2038 of file int_poly.cc.

2039{
2040 while ( LIKELY(theCursor) )
2041 {
2042 theCursor->coeff *= coeff;
2043 theCursor->exp += exp;
2044 theCursor = theCursor->next;
2045 }
2046}

◆ neg()

InternalCF * InternalPoly::neg ( )
virtual

InternalCF * InternalPoly::neg ()

See also
CanonicalForm::operator -()

Reimplemented from InternalCF.

Definition at line 231 of file int_poly.cc.

232{
233 if ( getRefCount() <= 1 )
234 {
236 return this;
237 }
238 else
239 {
240 decRefCount();
241 termList last, first = copyTermList( firstTerm, last, true );
242 return new InternalPoly( first, last, var );
243 }
244}
static void negateTermList(termList)
Definition: int_poly.cc:1911

◆ negateTermList()

void InternalPoly::negateTermList ( termList  terms)
staticprivate

Definition at line 1911 of file int_poly.cc.

1912{
1913 termList cursor = terms;
1914 while ( LIKELY(cursor) )
1915 {
1916 cursor->coeff = -cursor->coeff;
1917 cursor = cursor->next;
1918 }
1919}

◆ 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

◆ reduceTermList()

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

Definition at line 2266 of file int_poly.cc.

2267{
2268 CanonicalForm coeff = CanonicalForm (1)/redterms->coeff;
2269 CanonicalForm newcoeff;
2270 int newexp;
2271 int exp = redterms->exp;
2272 termList dummy;
2273 while ( first && ( first->exp >= exp ) )
2274 {
2275 newcoeff = first->coeff * coeff;
2276 newexp = first->exp - exp;
2277 dummy = first;
2278 first = mulAddTermList( first->next, redterms->next, newcoeff, newexp, last, true );
2279 delete dummy;
2280 }
2281 return first;
2282}

◆ sign()

int InternalPoly::sign ( ) const
virtual

int InternalPoly::sign () const

See also
CanonicalForm::sign()

Reimplemented from InternalCF.

Definition at line 110 of file int_poly.cc.

111{
112 return firstTerm->coeff.sign();
113}
int sign() const
int CanonicalForm::sign () const

◆ subcoeff()

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

Reimplemented from InternalCF.

Definition at line 1095 of file int_poly.cc.

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

◆ subsame()

InternalCF * InternalPoly::subsame ( InternalCF aCoeff)
virtual

Reimplemented from InternalCF.

Definition at line 326 of file int_poly.cc.

327{
328 InternalPoly * aPoly = (InternalPoly*)aCoeff;
329 if ( getRefCount() <= 1 )
330 {
332 if ( firstTerm && firstTerm->exp != 0 )
333 return this;
334 else if ( firstTerm )
335 {
337 delete this;
338 return res;
339 }
340 else
341 {
342 delete this;
343 return CFFactory::basic( 0 );
344 }
345 }
346 else
347 {
348 decRefCount();
350 first = addTermList( first, aPoly->firstTerm, last, true );
351 if ( first && first->exp != 0 )
352 return new InternalPoly( first, last, var );
353 else if ( first )
354 {
355 InternalCF * res = first->coeff.getval();
356 delete first;
357 return res;
358 }
359 else
360 return CFFactory::basic( 0 );
361
362 }
363}

◆ tailcoeff()

CanonicalForm InternalPoly::tailcoeff ( )
virtual

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

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

Reimplemented from InternalCF.

Definition at line 147 of file int_poly.cc.

148{
149 return lastTerm->coeff;
150}

◆ taildegree()

int InternalPoly::taildegree ( )
virtual

Reimplemented from InternalCF.

Definition at line 153 of file int_poly.cc.

154{
155 return lastTerm->exp;
156}

◆ tryDivcoeff()

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

Reimplemented from InternalCF.

Definition at line 1475 of file int_poly.cc.

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

◆ tryDividecoeff()

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

Reimplemented from InternalCF.

Definition at line 1303 of file int_poly.cc.

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

◆ tryDivremcoefft()

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

Reimplemented from InternalCF.

Definition at line 1755 of file int_poly.cc.

1756{
1757 if ( inExtension() && !getReduce( var ) )
1758 {
1759 quot = copyObject();
1760 quot = quot->tryDividecoeff( cc, invert, M, fail );
1761 if (fail)
1762 return false;
1763 rem = CFFactory::basic( 0 );
1764 return true;
1765 }
1766 else if ( invert )
1767 {
1768 if ( is_imm( cc ) )
1769 rem = cc;
1770 else
1771 rem = cc->copyObject();
1772 quot = CFFactory::basic( 0 );
1773 return true;
1774 }
1775 CanonicalForm c( is_imm(cc) ? cc : cc->copyObject() );
1776 ASSERT( ! c.isZero(), "divide by zero!" );
1777 termList quotfirst, quotcursor;
1778 termList cursor;
1779 CanonicalForm cquot, crem;
1780 bool divideok = true;
1781
1782 cursor = firstTerm;
1783 quotcursor = quotfirst = new term;
1784
1785 while ( cursor && divideok )
1786 {
1787 divideok = tryDivremt( cursor->coeff, c, cquot, crem, M, fail );
1788 if (fail)
1789 {
1790 freeTermList (quotfirst);
1791 return false;
1792 }
1793 divideok = divideok && crem.isZero();
1794 if ( divideok )
1795 {
1796 if ( ! cquot.isZero() )
1797 {
1798 quotcursor->next = new term( 0, cquot, cursor->exp );
1799 quotcursor = quotcursor->next;
1800 }
1801 cursor = cursor->next;
1802 }
1803 }
1804 quotcursor->next = 0;
1805 if ( divideok )
1806 {
1807 cursor = quotfirst; quotfirst = quotfirst->next; delete cursor;
1808 if ( quotfirst )
1809 if ( quotfirst->exp == 0 )
1810 {
1811 quot = quotfirst->coeff.getval();
1812 delete quotfirst;
1813 }
1814 else
1815 quot = new InternalPoly( quotfirst, quotcursor, var );
1816 else
1817 quot = CFFactory::basic( 0 );
1818 rem = CFFactory::basic( 0 );
1819 }
1820 else
1821 {
1822 freeTermList( quotfirst );
1823 }
1824 return divideok;
1825}
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 883 of file int_poly.cc.

884{
885 if (inExtension() && !getReduce (var))
886 {
887 InternalCF * dummy = acoeff->tryInvert(M, fail);
888 if (fail)
889 return false;
890 quot = dummy->tryMulsame( this, M);
891 rem = CFFactory::basic( 0 );
892 if (fail)
893 return false;
894 return true;
895 }
896 InternalPoly *aPoly = (InternalPoly*)acoeff;
897 termList dummy, first, last, resultfirst = 0, resultlast = 0;
898 CanonicalForm coeff, newcoeff, dummycoeff;
899 int exp, newexp;
900 bool divideok = true;
901
902 first = copyTermList( firstTerm, last );
903
904 coeff = aPoly->firstTerm->coeff;
905 exp = aPoly->firstTerm->exp;
906 while (first && ( first->exp >= exp ) && divideok )
907 {
908 divideok = tryDivremt( first->coeff, coeff, newcoeff, dummycoeff, M, fail );
909 if (fail)
910 {
911 freeTermList (first);
912 return false;
913 }
914 if ( divideok && dummycoeff.isZero() )
915 {
916 newexp = first->exp - exp;
917 dummy = first;
918 first = mulAddTermList( first->next, aPoly->firstTerm->next, newcoeff, newexp, last, true );
919 delete dummy;
920 if (!newcoeff.isZero())
921 appendTermList( resultfirst, resultlast, newcoeff, newexp );
922 }
923 else
924 divideok = false;
925 }
926 if ( divideok )
927 {
928 if ( resultfirst )
929 if ( resultfirst->exp == 0 )
930 {
931 quot = resultfirst->coeff.getval();
932 delete resultfirst;
933 }
934 else
935 quot = new InternalPoly( resultfirst, resultlast, var );
936 else
937 quot = CFFactory::basic( 0 );
938 if ( first )
939 if ( first->exp == 0 )
940 {
941 rem = first->coeff.getval();
942 delete first;
943 }
944 else
945 {
946 if (first->coeff.isZero())
947 {
949 delete first;
950 }
951 else
952 rem = new InternalPoly( first, last, var );
953 }
954 else
955 rem = CFFactory::basic( 0 );
956 }
957 else
958 {
959 freeTermList( resultfirst );
960 freeTermList( first );
961 }
962 return divideok;
963}
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 584 of file int_poly.cc.

585{
586 if ( inExtension() && !getReduce( var ) )
587 {
588 InternalCF * dummy = aCoeff->tryInvert(M, fail);
589 if (fail)
590 return CFFactory::basic( 0 );
591 if (is_imm(dummy)) dummy=this->tryMulsame(dummy, M);
592 else dummy = dummy->tryMulsame( this, M);
593 if (fail)
594 {
595 if (getRefCount() <= 1)
596 delete this;
597 else
598 decRefCount();
599 return dummy;
600 }
601 if ( getRefCount() <= 1 )
602 {
603 delete this;
604 return dummy;
605 }
606 else
607 {
608 decRefCount();
609 return dummy;
610 }
611 }
612 InternalPoly *aPoly = (InternalPoly*)aCoeff;
613 termList dummy, first, last, resultfirst = 0, resultlast = 0;
614 CanonicalForm coeff, newcoeff;
615 int exp, newexp;
616 bool singleObject;
617
618 if ( getRefCount() <= 1 )
619 {
620 first = firstTerm; last = lastTerm; singleObject = true;
621 }
622 else
623 {
624 first = copyTermList( firstTerm, last ); singleObject = false;
625 decRefCount();
626 }
627 coeff = aPoly->firstTerm->coeff;
628 exp = aPoly->firstTerm->exp;
629 while (first && ( first->exp >= exp ) )
630 {
631 newcoeff= first->coeff.tryDiv (coeff, M, fail);
632 if (fail)
633 {
634 freeTermList (first);
635 return CFFactory::basic (0);
636 }
637 newcoeff= reduce (newcoeff, M);
638 newexp = first->exp - exp;
639 dummy = first;
640 first = mulAddTermList( first->next, aPoly->firstTerm->next, newcoeff, newexp, last, true );
641 delete dummy;
642 if (!newcoeff.isZero())
643 appendTermList( resultfirst, resultlast, newcoeff, newexp );
644 }
645 freeTermList( first );
646 if ( singleObject )
647 {
648 if ( resultfirst && resultfirst->exp != 0 )
649 {
650 firstTerm = resultfirst;
651 lastTerm = resultlast;
652 return this;
653 }
654 else if ( resultfirst )
655 {
656 InternalCF * res = resultfirst->coeff.getval();
657 delete resultfirst;
658 firstTerm = 0;
659 delete this;
660 return res;
661 }
662 else
663 {
664 // this should not happen (evtl use assertion)
665 ASSERT( 0, "FATAL ERROR, PLEASE INFORM THE AUTHOR" );
666 firstTerm = 0;
667 delete this;
668 return CFFactory::basic( 0 );
669 }
670 }
671 else
672 {
673 if ( resultfirst && resultfirst->exp != 0 )
674 return new InternalPoly( resultfirst, resultlast, var );
675 else if ( resultfirst )
676 {
677 InternalCF * res = resultfirst->coeff.getval();
678 delete resultfirst;
679 return res;
680 }
681 else
682 return CFFactory::basic( 0 );
683 }
684}
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:660
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:428

◆ tryDivTermList()

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

Definition at line 2107 of file int_poly.cc.

2108{
2109 termList theCursor = firstTerm;
2110 lastTerm = 0;
2111 termList dummy;
2112
2113 while ( theCursor )
2114 {
2115 theCursor->coeff.tryDiv( coeff, M, fail );
2116 if (fail)
2117 return 0;
2118 if ( theCursor->coeff.isZero() )
2119 {
2120 if ( theCursor == firstTerm )
2121 firstTerm = theCursor->next;
2122 else
2123 lastTerm->next = theCursor->next;
2124 dummy = theCursor;
2125 theCursor = theCursor->next;
2126 delete dummy;
2127 }
2128 else
2129 {
2130 lastTerm = theCursor;
2131 theCursor = theCursor->next;
2132 }
2133 }
2134 return firstTerm;
2135}

◆ tryInvert()

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

Reimplemented from InternalCF.

Definition at line 264 of file int_poly.cc.

265{
266 if ( inExtension() && !getReduce ( var ) )
267 {
268 CanonicalForm b, inverse;
269 CanonicalForm F ( this ->copyObject() );
270 Variable a = M.mvar();
271 Variable x = Variable(1);
272 F= mod (F, M); //reduce mod M
273 CanonicalForm g= extgcd (replacevar( F, a, x ), replacevar( M, a, x ), inverse, b );
274 if(!g.isOne())
275 fail = true;
276 else
277 inverse = replacevar( inverse, x, a ); // change back to alg var
278 CanonicalForm test= mod (inverse*F, M);
279 return inverse.getval();
280 }
281 else
282 return CFFactory::basic( 0 );
283}
CanonicalForm FACTORY_PUBLIC replacevar(const CanonicalForm &, const Variable &, const Variable &)
CanonicalForm replacevar ( const CanonicalForm & f, const Variable & x1, const Variable & x2 )
Definition: cf_ops.cc:271
CF_NO_INLINE FACTORY_PUBLIC CanonicalForm mod(const CanonicalForm &, const CanonicalForm &)
Variable x
Definition: cfModGcd.cc:4082
CanonicalForm test
Definition: cfModGcd.cc:4096
factory's class for variables
Definition: variable.h:33

◆ tryMulsame()

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

Reimplemented from InternalCF.

Definition at line 428 of file int_poly.cc.

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

◆ 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: