9 #if defined(WINNT) && ! defined(__GNUC__) 13 #include <strstream.h> 47 ASSERT( 0,
"ups, why do you initialize an empty poly" );
53 firstTerm =
new term( 0, c, e );
59 ASSERT( 0,
"ups there is something wrong in your code" );
83 cursor = cursor->
next;
159 if ( theCursor->
exp == i )
160 return theCursor->
coeff;
161 else if ( theCursor->
exp < i )
164 theCursor = theCursor->
next;
174 aStream << 0 << aString;
181 ostrstream theStream;
182 if ( theCursor->
exp == 0 )
187 if ( theCursor->
exp != 1 )
188 aStream <<
'^' << theCursor->
exp << aString;
194 aStream <<
'-' <<
var;
195 if ( theCursor->
exp != 1 )
196 aStream <<
'^' << theCursor->
exp << aString;
202 theStream <<
'*' <<
var;
203 if ( theCursor->
exp != 1 )
204 theStream <<
'^' << theCursor->
exp << aString << ends;
206 theStream << aString << ends;
207 theString = theStream.str();
211 theCursor = theCursor->
next;
212 if ( theCursor && ( theCursor->
coeff.
sign() >= 0 ) )
303 if ( first && first->
exp != 0 )
343 if ( first && first->
exp != 0 )
362 termList resultFirst = 0, resultLast = 0;
368 theCursor->
coeff, theCursor->
exp, resultLast,
false );
369 theCursor = theCursor->
next;
374 if ( resultFirst == 0 )
387 else if ( resultFirst->
exp == 0 )
425 termList resultFirst = 0, resultLast = 0;
431 theCursor->
coeff, theCursor->
exp, resultLast,
false );
432 theCursor = theCursor->
next;
437 if ( resultFirst == 0 )
450 else if ( resultFirst->
exp == 0 )
496 else dummy = dummy->
mulsame(
this );
509 termList dummy, first,
last, resultfirst = 0, resultlast = 0;
525 while (first && ( first->
exp >= exp ) )
528 newexp = first->
exp -
exp;
537 if ( resultfirst && resultfirst->
exp != 0 )
543 else if ( resultfirst )
554 ASSERT( 0,
"FATAL ERROR, PLEASE INFORM THE AUTHOR" );
562 if ( resultfirst && resultfirst->
exp != 0 )
564 else if ( resultfirst )
605 termList dummy, first,
last, resultfirst = 0, resultlast = 0;
621 while (first && ( first->
exp >= exp ) )
629 newcoeff=
reduce (newcoeff, M);
630 newexp = first->
exp -
exp;
640 if ( resultfirst && resultfirst->
exp != 0 )
646 else if ( resultfirst )
657 ASSERT( 0,
"FATAL ERROR, PLEASE INFORM THE AUTHOR" );
665 if ( resultfirst && resultfirst->
exp != 0 )
667 else if ( resultfirst )
709 while (first && ( first->
exp >= exp ) )
712 newexp = first->
exp -
exp;
719 if ( first && first->
exp != 0 )
742 if ( first && first->
exp != 0 )
768 termList dummy, first,
last, resultfirst = 0, resultlast = 0;
776 while (first && ( first->
exp >= exp ) )
779 newexp = first->
exp -
exp;
786 if ( resultfirst->
exp == 0 )
796 if ( first->
exp == 0 )
817 termList dummy, first,
last, resultfirst = 0, resultlast = 0;
820 bool divideok =
true;
829 while (first && ( first->
exp >= exp ) && divideok )
831 divideok =
divremt( first->
coeff, coeff, newcoeff, dummycoeff );
832 if ( divideok && dummycoeff.
isZero() )
834 newexp = first->
exp -
exp;
846 if ( resultfirst->
exp == 0 )
856 if ( first->
exp == 0 )
889 termList dummy, first,
last, resultfirst = 0, resultlast = 0;
892 bool divideok =
true;
898 while (first && ( first->
exp >= exp ) && divideok )
900 divideok =
tryDivremt( first->
coeff, coeff, newcoeff, dummycoeff, M, fail );
906 if ( divideok && dummycoeff.
isZero() )
908 newexp = first->
exp -
exp;
921 if ( resultfirst->
exp == 0 )
931 if ( first->
exp == 0 )
992 termList cursor2 = apoly->firstTerm;
993 for ( ; cursor1 && cursor2; cursor1 = cursor1->
next, cursor2 = cursor2->
next )
998 if ( (cursor1->
exp != cursor2->exp) || (cursor1->
coeff != cursor2->coeff) )
1000 if ( cursor1->
exp > cursor2->exp )
1002 else if ( cursor1->
exp < cursor2->exp )
1004 else if ( cursor1->
coeff > cursor2->coeff )
1010 if ( cursor1 == cursor2 )
1012 else if ( cursor1 != 0 )
1046 cursor = cursor->
next;
1063 if ( last->
exp == 0 )
1069 while ( cursor->
next != last )
1070 cursor = cursor->
next;
1120 cursor = cursor->
next;
1143 if ( last->
exp == 0 )
1152 while ( cursor->
next != last )
1153 cursor = cursor->
next;
1189 else if ( c.isOne() )
1226 else dummy = dummy->
mulcoeff( cc );
1277 if ( first && first->
exp != 0 )
1320 else dummy = dummy->
mulcoeff( cc );
1372 if ( first && first->
exp != 0 )
1449 if ( first && first->
exp != 0 )
1548 if ( first && first->
exp != 0 )
1574 ASSERT( ! c.isZero(),
"divide by zero!" );
1588 ASSERT( ! c.isZero(),
"divide by zero!" );
1626 if ( first && first->
exp != 0 )
1663 ASSERT( ! c.isZero(),
"divide by zero!" );
1667 if ( quotfirst->exp == 0 )
1700 ASSERT( ! c.isZero(),
"divide by zero!" );
1704 bool divideok =
true;
1707 quotcursor = quotfirst =
new term;
1709 while ( cursor && divideok )
1712 divideok = divideok && crem.
isZero();
1717 quotcursor->next =
new term( 0, cquot, cursor->
exp );
1718 quotcursor = quotcursor->next;
1720 cursor = cursor->
next;
1723 quotcursor->
next = 0;
1726 cursor = quotfirst; quotfirst = quotfirst->
next;
delete cursor;
1728 if ( quotfirst->exp == 0 )
1768 ASSERT( ! c.isZero(),
"divide by zero!" );
1772 bool divideok =
true;
1775 quotcursor = quotfirst =
new term;
1777 while ( cursor && divideok )
1785 divideok = divideok && crem.
isZero();
1790 quotcursor->next =
new term( 0, cquot, cursor->
exp );
1791 quotcursor = quotcursor->next;
1793 cursor = cursor->
next;
1796 quotcursor->
next = 0;
1799 cursor = quotfirst; quotfirst = quotfirst->
next;
delete cursor;
1801 if ( quotfirst->exp == 0 )
1824 if ( aTermList == 0 )
1832 while ( sourceCursor )
1834 targetCursor->
next =
new term( 0, -sourceCursor->
coeff, sourceCursor->
exp );
1835 targetCursor = targetCursor->
next;
1836 sourceCursor = sourceCursor->
next;
1838 targetCursor->
next = 0;
1839 theLastTerm = targetCursor;
1840 targetCursor = dummy->
next;
1842 return targetCursor;
1850 while ( sourceCursor )
1852 targetCursor->
next =
new term( 0, sourceCursor->
coeff, sourceCursor->
exp );
1853 targetCursor = targetCursor->
next;
1854 sourceCursor = sourceCursor->
next;
1856 targetCursor->
next = 0;
1857 theLastTerm = targetCursor;
1858 targetCursor = dummy->
next;
1860 return targetCursor;
1867 if ( aTermList == 0 )
1875 while ( sourceCursor )
1878 targetCursor = targetCursor->
next;
1879 sourceCursor = sourceCursor->
next;
1881 targetCursor->
next = 0;
1882 theLastTerm = targetCursor;
1883 targetCursor = dummy->
next;
1885 return targetCursor;
1896 cursor = cursor->
next;
1909 cursor = cursor->
next;
1920 while ( theCursor && aCursor )
1922 if ( theCursor->
exp == aCursor->
exp )
1932 predCursor->
next = theCursor->
next;
1934 theCursor = predCursor->
next;
1938 theList = theList->
next;
1940 theCursor = theList;
1945 predCursor = theCursor;
1946 theCursor = theCursor->
next;
1948 aCursor = aCursor->
next;
1950 else if ( theCursor->
exp < aCursor->
exp )
1956 predCursor = predCursor->
next;
1960 theList =
new term( theCursor, -aCursor->
coeff, aCursor->
exp );
1961 predCursor = theList;
1967 predCursor = predCursor->
next;
1971 theList =
new term( theCursor, aCursor->
coeff, aCursor->
exp );
1972 predCursor = theList;
1974 aCursor = aCursor->
next;
1978 predCursor = theCursor;
1979 theCursor = theCursor->
next;
1989 else if ( ! theCursor )
1990 lastTerm = predCursor;
2002 theCursor = theCursor->
next;
2018 if ( theCursor == firstTerm )
2019 firstTerm = theCursor->
next;
2023 theCursor = theCursor->
next;
2028 lastTerm = theCursor;
2029 theCursor = theCursor->
next;
2047 if ( theCursor == firstTerm )
2048 firstTerm = theCursor->
next;
2052 theCursor = theCursor->
next;
2057 lastTerm = theCursor;
2058 theCursor = theCursor->
next;
2078 if ( theCursor == firstTerm )
2079 firstTerm = theCursor->
next;
2083 theCursor = theCursor->
next;
2088 lastTerm = theCursor;
2089 theCursor = theCursor->
next;
2107 if ( theCursor == firstTerm )
2108 firstTerm = theCursor->
next;
2112 theCursor = theCursor->
next;
2117 lastTerm = theCursor;
2118 theCursor = theCursor->
next;
2129 last->
next =
new term( 0, coeff, exp );
2134 first =
new term( 0, coeff, exp );
2152 while ( theCursor && aCursor )
2154 if ( theCursor->
exp == aCursor->
exp + exp )
2161 predCursor->
next = theCursor->
next;
2163 theCursor = predCursor->
next;
2167 theList = theList->
next;
2169 theCursor = theList;
2174 predCursor = theCursor;
2175 theCursor = theCursor->
next;
2177 aCursor = aCursor->
next;
2179 else if ( theCursor->
exp < aCursor->
exp + exp )
2183 predCursor->
next =
new term( theCursor, aCursor->
coeff * coeff, aCursor->
exp + exp );
2184 predCursor = predCursor->
next;
2188 theList =
new term( theCursor, aCursor->
coeff * coeff, aCursor->
exp + exp );
2189 predCursor = theList;
2191 aCursor = aCursor->
next;
2195 predCursor = theCursor;
2196 theCursor = theCursor->
next;
2204 predCursor = predCursor->
next;
2209 predCursor = theList;
2211 while ( predCursor )
2215 predCursor = predCursor->
next;
2218 else if ( ! theCursor )
2219 lastTerm = predCursor;
2231 while ( first && ( first->
exp >= exp ) )
2234 newexp = first->
exp -
exp;
friend class InternalInteger
InternalCF * neg()
InternalCF * InternalPoly::neg ()
static void mulTermList(termList, const CanonicalForm &, const int)
int comparesame(InternalCF *)
comparesame(), comparecoeff() - compare with an InternalPoly.
InternalCF * mulsame(InternalCF *)
virtual bool isOne() const
bool InternalCF::isOne, isZero () const
void rem(unsigned long *a, unsigned long *q, unsigned long p, int °a, int degq)
static void negateTermList(termList)
static termList modTermList(termList, const CanonicalForm &, termList &)
InternalCF * tryDivsame(InternalCF *, const CanonicalForm &, bool &)
gmp_float exp(const gmp_float &a)
CanonicalForm extgcd(const CanonicalForm &f, const CanonicalForm &g, CanonicalForm &a, CanonicalForm &b)
CanonicalForm extgcd ( const CanonicalForm & f, const CanonicalForm & g, CanonicalForm & a...
InternalCF * dividecoeff(InternalCF *, bool)
int sign() const
int InternalPoly::sign () const
factory's class for variables
virtual InternalCF * tryInvert(const CanonicalForm &, bool &)
static void appendTermList(termList &, termList &, const CanonicalForm &, const int)
InternalCF * divsame(InternalCF *)
static termList divideTermList(termList, const CanonicalForm &, termList &)
void divremcoeff(InternalCF *, InternalCF *&, InternalCF *&, bool)
InternalCF * copyObject()
CanonicalForm tailcoeff()
CanonicalForm InternalPoly::tailcoeff (), int InternalPoly::taildegree ()
InternalCF * modulocoeff(InternalCF *, bool)
bool divremsamet(InternalCF *, InternalCF *&, InternalCF *&)
InternalCF * deepCopyObject() const
CanonicalForm getMipo(const Variable &alpha, const Variable &x)
static const omBin InternalPoly_bin
virtual class for internal CanonicalForm's
InternalCF * tryInvert(const CanonicalForm &, bool &)
InternalCF * subsame(InternalCF *)
virtual int level() const
bool isUnivariate() const
InternalCF * tryDividecoeff(InternalCF *, bool, const CanonicalForm &, bool &)
InternalCF * dividesame(InternalCF *)
CanonicalForm coeff(int i)
CanonicalForm InternalPoly::coeff ( int i )
static termList divTermList(termList, const CanonicalForm &, termList &)
static termList deepCopyTermList(termList, termList &)
univariate Gcd over finite fields and Z, extended GCD over finite fields and Q
bool divremcoefft(InternalCF *, InternalCF *&, InternalCF *&, bool)
InternalCF * tryDivcoeff(InternalCF *, bool, const CanonicalForm &, bool &)
InternalCF * tryMulsame(InternalCF *, const CanonicalForm &)
static termList addTermList(termList, termList, termList &, bool negate)
virtual CanonicalForm coeff(int i)
CanonicalForm InternalCF::coeff ( int i )
void setReduce(const Variable &alpha, bool reduce)
Interface to generate InternalCF's over various domains from intrinsic types or mpz_t's.
bool getReduce(const Variable &alpha)
void divremsame(InternalCF *, InternalCF *&, InternalCF *&)
factory's class for polynomials
virtual InternalCF * dividecoeff(InternalCF *, bool) PVIRT_INTCF("dividecoeff")
static InternalCF * basic(long value)
InternalCF * modulosame(InternalCF *)
InternalCF * modsame(InternalCF *)
virtual InternalCF * tryMulsame(InternalCF *, const CanonicalForm &)
static void freeTermList(termList)
void print(OSTREAM &, char *)
static termList tryDivTermList(termList, const CanonicalForm &, termList &, const CanonicalForm &, bool &)
InternalPoly * getInternalMipo(const Variable &alpha)
static termList mulAddTermList(termList theList, termList aList, const CanonicalForm &c, const int exp, termList &lastTerm, bool negate)
static const omBin term_bin
static long imm2int(const InternalCF *const imm)
#define omGetSpecBin(size)
Factory's internal polynomials.
const Variable & v
< [in] a sqrfree bivariate poly
virtual InternalCF * invert()
InternalCF * modcoeff(InternalCF *, bool)
static termList copyTermList(termList, termList &, bool negate=false)
InternalCF * divcoeff(InternalCF *, bool)
int degree()
int InternalPoly::degree ()
operations on immediates, that is elements of F_p, GF, Z, Q that fit into intrinsic int...
InternalCF * addsame(InternalCF *)
static termList reduceTermList(termList first, termList redterms, termList &last)
bool tryDivremsamet(InternalCF *, InternalCF *&, InternalCF *&, const CanonicalForm &, bool &)
Factory's internal CanonicalForm's.
virtual InternalCF * mulcoeff(InternalCF *) PVIRT_INTCF("mulcoeff")
#define ASSERT(expression, message)
virtual InternalCF * tryDividecoeff(InternalCF *, bool, const CanonicalForm &, bool &)
virtual InternalCF * mulsame(InternalCF *) PVIRT_INTCF("mulsame")
factory's class for integers
bool tryDivremcoefft(InternalCF *, InternalCF *&, InternalCF *&, bool, const CanonicalForm &, bool &)
InternalCF * mulcoeff(InternalCF *)
int comparecoeff(InternalCF *)
comparecoeff() always returns 1 since CO is defined to be larger than anything which is a coefficient...
Factory's internal integers.
InternalCF * addcoeff(InternalCF *)
InternalCF * subcoeff(InternalCF *, bool)