9#if defined(WINNT) && ! defined(__GNUC__)
34#define LIKELY(X) (__builtin_expect(!!(X), 1))
35#define UNLIKELY(X) (__builtin_expect(!!(X), 0))
38#define UNLIKELY(X) (X)
55 ASSERT( 0,
"ups, why do you initialize an empty poly" );
67 ASSERT( 0,
"ups there is something wrong in your code" );
91 cursor = cursor->
next;
167 if ( theCursor->
exp ==
i )
168 return theCursor->
coeff;
169 else if ( theCursor->
exp <
i )
172 theCursor = theCursor->
next;
182 aStream << 0 << aString;
189 ostrstream theStream;
190 if ( theCursor->
exp == 0 )
195 if ( theCursor->
exp != 1 )
196 aStream <<
'^' << theCursor->
exp << aString;
200 else if ( theCursor->
coeff.
sign() < 0 && (-theCursor->
coeff).isOne() )
202 aStream <<
'-' <<
var;
203 if ( theCursor->
exp != 1 )
204 aStream <<
'^' << theCursor->
exp << aString;
210 theStream <<
'*' <<
var;
211 if ( theCursor->
exp != 1 )
212 theStream <<
'^' << theCursor->
exp << aString << ends;
214 theStream << aString << ends;
215 theString = theStream.str();
219 theCursor = theCursor->
next;
220 if ( theCursor && ( theCursor->
coeff.
sign() >= 0 ) )
311 if ( first && first->
exp != 0 )
351 if ( first && first->
exp != 0 )
370 termList resultFirst = 0, resultLast = 0;
376 theCursor->
coeff, theCursor->
exp, resultLast,
false );
377 theCursor = theCursor->
next;
382 if ( resultFirst == 0 )
395 else if ( resultFirst->
exp == 0 )
433 termList resultFirst = 0, resultLast = 0;
439 theCursor->
coeff, theCursor->
exp, resultLast,
false );
440 theCursor = theCursor->
next;
445 if ( resultFirst == 0 )
458 else if ( resultFirst->
exp == 0 )
504 else dummy = dummy->
mulsame(
this );
517 termList dummy, first,
last, resultfirst = 0, resultlast = 0;
533 while (first && ( first->
exp >=
exp ) )
536 newexp = first->
exp -
exp;
545 if ( resultfirst && resultfirst->
exp != 0 )
551 else if ( resultfirst )
562 ASSERT( 0,
"FATAL ERROR, PLEASE INFORM THE AUTHOR" );
570 if ( resultfirst && resultfirst->
exp != 0 )
572 else if ( resultfirst )
613 termList dummy, first,
last, resultfirst = 0, resultlast = 0;
629 while (first && ( first->
exp >=
exp ) )
637 newcoeff=
reduce (newcoeff,
M);
638 newexp = first->
exp -
exp;
648 if ( resultfirst && resultfirst->
exp != 0 )
654 else if ( resultfirst )
665 ASSERT( 0,
"FATAL ERROR, PLEASE INFORM THE AUTHOR" );
673 if ( resultfirst && resultfirst->
exp != 0 )
675 else if ( resultfirst )
717 while (first && ( first->
exp >=
exp ) )
720 newexp = first->
exp -
exp;
727 if ( first && first->
exp != 0 )
750 if ( first && first->
exp != 0 )
776 termList dummy, first,
last, resultfirst = 0, resultlast = 0;
784 while (first && ( first->
exp >=
exp ) )
787 newexp = first->
exp -
exp;
794 if ( resultfirst->
exp == 0 )
804 if ( first->
exp == 0 )
825 termList dummy, first,
last, resultfirst = 0, resultlast = 0;
828 bool divideok =
true;
837 while (first && ( first->
exp >=
exp ) && divideok )
840 if ( divideok && dummycoeff.
isZero() )
842 newexp = first->
exp -
exp;
854 if ( resultfirst->
exp == 0 )
864 if ( first->
exp == 0 )
897 termList dummy, first,
last, resultfirst = 0, resultlast = 0;
900 bool divideok =
true;
906 while (first && ( first->
exp >=
exp ) && divideok )
914 if ( divideok && dummycoeff.
isZero() )
916 newexp = first->
exp -
exp;
929 if ( resultfirst->
exp == 0 )
939 if ( first->
exp == 0 )
1001 for ( ; cursor1 && cursor2; cursor1 = cursor1->
next, cursor2 = cursor2->
next )
1007 if ( cursor1->
exp > cursor2->
exp )
1009 else if ( cursor1->
exp < cursor2->
exp )
1020 if ( cursor1 == cursor2 )
1022 else if ( cursor1 != 0 )
1056 cursor = cursor->
next;
1073 if (
last->exp == 0 )
1076 if (
last->coeff.isZero() )
1080 cursor = cursor->
next;
1130 cursor = cursor->
next;
1153 if (
last->exp == 0 )
1159 if (
last->coeff.isZero() )
1163 cursor = cursor->
next;
1199 else if ( c.
isOne() )
1236 else dummy = dummy->
mulcoeff( cc );
1287 if ( first && first->
exp != 0 )
1330 else dummy = dummy->
mulcoeff( cc );
1382 if ( first && first->
exp != 0 )
1459 if ( first && first->
exp != 0 )
1558 if ( first && first->
exp != 0 )
1636 if ( first && first->
exp != 0 )
1677 if ( quotfirst->
exp == 0 )
1714 bool divideok =
true;
1717 quotcursor = quotfirst =
new term;
1719 while ( cursor && divideok )
1722 divideok = divideok && crem.
isZero();
1727 quotcursor->
next =
new term( 0, cquot, cursor->
exp );
1728 quotcursor = quotcursor->
next;
1730 cursor = cursor->
next;
1733 quotcursor->
next = 0;
1736 cursor = quotfirst; quotfirst = quotfirst->
next;
delete cursor;
1738 if ( quotfirst->
exp == 0 )
1782 bool divideok =
true;
1785 quotcursor = quotfirst =
new term;
1787 while ( cursor && divideok )
1795 divideok = divideok && crem.
isZero();
1800 quotcursor->
next =
new term( 0, cquot, cursor->
exp );
1801 quotcursor = quotcursor->
next;
1803 cursor = cursor->
next;
1806 quotcursor->
next = 0;
1809 cursor = quotfirst; quotfirst = quotfirst->
next;
delete cursor;
1811 if ( quotfirst->
exp == 0 )
1842 while (
LIKELY(sourceCursor) )
1844 targetCursor->
next =
new term( 0, -sourceCursor->
coeff, sourceCursor->
exp );
1845 targetCursor = targetCursor->
next;
1846 sourceCursor = sourceCursor->
next;
1848 targetCursor->
next = 0;
1849 theLastTerm = targetCursor;
1850 targetCursor = dummy->
next;
1852 return targetCursor;
1860 while (
LIKELY(sourceCursor) )
1862 targetCursor->
next =
new term( 0, sourceCursor->
coeff, sourceCursor->
exp );
1863 targetCursor = targetCursor->
next;
1864 sourceCursor = sourceCursor->
next;
1866 targetCursor->
next = 0;
1867 theLastTerm = targetCursor;
1868 targetCursor = dummy->
next;
1870 return targetCursor;
1877 if ( aTermList == 0 )
1885 while ( sourceCursor )
1888 targetCursor = targetCursor->
next;
1889 sourceCursor = sourceCursor->
next;
1891 targetCursor->
next = 0;
1892 theLastTerm = targetCursor;
1893 targetCursor = dummy->
next;
1895 return targetCursor;
1906 cursor = cursor->
next;
1919 cursor = cursor->
next;
1931 while ( theCursor && aCursor )
1933 if ( theCursor->
exp == aCursor->
exp )
1940 predCursor->
next = theCursor->
next;
1942 theCursor = predCursor->
next;
1946 theList = theList->
next;
1948 theCursor = theList;
1953 predCursor = theCursor;
1954 theCursor = theCursor->
next;
1956 aCursor = aCursor->
next;
1958 else if ( theCursor->
exp < aCursor->
exp )
1963 predCursor = predCursor->
next;
1967 theList =
new term( theCursor, -aCursor->
coeff, aCursor->
exp );
1968 predCursor = theList;
1970 aCursor = aCursor->
next;
1974 predCursor = theCursor;
1975 theCursor = theCursor->
next;
1979 while ( theCursor && aCursor )
1981 if ( theCursor->
exp == aCursor->
exp )
1988 predCursor->
next = theCursor->
next;
1990 theCursor = predCursor->
next;
1994 theList = theList->
next;
1996 theCursor = theList;
2001 predCursor = theCursor;
2002 theCursor = theCursor->
next;
2004 aCursor = aCursor->
next;
2006 else if ( theCursor->
exp < aCursor->
exp )
2011 predCursor = predCursor->
next;
2015 theList =
new term( theCursor, aCursor->
coeff, aCursor->
exp );
2016 predCursor = theList;
2018 aCursor = aCursor->
next;
2022 predCursor = theCursor;
2023 theCursor = theCursor->
next;
2033 else if ( ! theCursor )
2042 while (
LIKELY(theCursor) )
2046 theCursor = theCursor->
next;
2057 while (
LIKELY(theCursor) )
2067 theCursor = theCursor->
next;
2073 theCursor = theCursor->
next;
2086 while (
LIKELY(theCursor) )
2096 theCursor = theCursor->
next;
2102 theCursor = theCursor->
next;
2127 theCursor = theCursor->
next;
2133 theCursor = theCursor->
next;
2156 theCursor = theCursor->
next;
2162 theCursor = theCursor->
next;
2196 while ( theCursor && aCursor )
2198 if ( theCursor->
exp == aCursor->
exp +
exp )
2205 predCursor->
next = theCursor->
next;
2207 theCursor = predCursor->
next;
2211 theList = theList->
next;
2213 theCursor = theList;
2218 predCursor = theCursor;
2219 theCursor = theCursor->
next;
2221 aCursor = aCursor->
next;
2223 else if ( theCursor->
exp < aCursor->
exp +
exp )
2228 predCursor = predCursor->
next;
2233 predCursor = theList;
2235 aCursor = aCursor->
next;
2239 predCursor = theCursor;
2240 theCursor = theCursor->
next;
2248 predCursor = predCursor->
next;
2253 predCursor = theList;
2255 while ( predCursor )
2259 predCursor = predCursor->
next;
2262 else if ( ! theCursor )
2275 while ( first && ( first->
exp >=
exp ) )
2278 newexp = first->
exp -
exp;
CanonicalForm extgcd(const CanonicalForm &f, const CanonicalForm &g, CanonicalForm &a, CanonicalForm &b)
CanonicalForm extgcd ( const CanonicalForm & f, const CanonicalForm & g, CanonicalForm & a,...
univariate Gcd over finite fields and Z, extended GCD over finite fields and Q
#define ASSERT(expression, message)
Interface to generate InternalCF's over various domains from intrinsic types or mpz_t's.
static InternalCF * basic(int value)
virtual class for internal CanonicalForm's
virtual InternalCF * tryMulsame(InternalCF *, const CanonicalForm &)
InternalCF * copyObject()
virtual InternalCF * mulcoeff(InternalCF *) PVIRT_INTCF("mulcoeff")
virtual InternalCF * tryDividecoeff(InternalCF *, bool, const CanonicalForm &, bool &)
virtual InternalCF * dividecoeff(InternalCF *, bool) PVIRT_INTCF("dividecoeff")
virtual InternalCF * tryInvert(const CanonicalForm &, bool &)
virtual InternalCF * invert()
virtual int level() const
virtual InternalCF * mulsame(InternalCF *) PVIRT_INTCF("mulsame")
factory's class for integers
factory's class for polynomials
InternalCF * addsame(InternalCF *)
static termList divideTermList(termList, const CanonicalForm &, termList &)
static termList addTermList(termList, termList, termList &, bool negate)
InternalCF * mulcoeff(InternalCF *)
void print(OSTREAM &, char *)
static termList reduceTermList(termList first, termList redterms, termList &last)
InternalCF * modsame(InternalCF *)
int degree()
int InternalPoly::degree ()
static void freeTermList(termList)
InternalCF * deepCopyObject() const
bool divremsamet(InternalCF *, InternalCF *&, InternalCF *&)
InternalCF * neg()
InternalCF * InternalPoly::neg ()
InternalCF * tryDivcoeff(InternalCF *, bool, const CanonicalForm &, bool &)
static const omBin InternalPoly_bin
static void mulTermList(termList, const CanonicalForm &, const int)
bool isUnivariate() const
void divremcoeff(InternalCF *, InternalCF *&, InternalCF *&, bool)
int comparesame(InternalCF *)
comparesame(), comparecoeff() - compare with an InternalPoly.
InternalCF * tryDividecoeff(InternalCF *, bool, const CanonicalForm &, bool &)
InternalCF * modulocoeff(InternalCF *, bool)
InternalCF * subsame(InternalCF *)
InternalCF * divcoeff(InternalCF *, bool)
InternalCF * modcoeff(InternalCF *, bool)
InternalCF * modulosame(InternalCF *)
static void negateTermList(termList)
static termList tryDivTermList(termList, const CanonicalForm &, termList &, const CanonicalForm &, bool &)
static termList mulAddTermList(termList theList, termList aList, const CanonicalForm &c, const int exp, termList &lastTerm, bool negate)
bool tryDivremcoefft(InternalCF *, InternalCF *&, InternalCF *&, bool, const CanonicalForm &, bool &)
void divremsame(InternalCF *, InternalCF *&, InternalCF *&)
InternalCF * dividesame(InternalCF *)
bool divremcoefft(InternalCF *, InternalCF *&, InternalCF *&, bool)
CanonicalForm coeff(int i)
CanonicalForm InternalPoly::coeff ( int i )
InternalCF * dividecoeff(InternalCF *, bool)
int comparecoeff(InternalCF *)
comparecoeff() always returns 1 since CO is defined to be larger than anything which is a coefficient...
CanonicalForm tailcoeff()
CanonicalForm InternalPoly::tailcoeff (), int InternalPoly::taildegree ()
static termList deepCopyTermList(termList, termList &)
InternalCF * divsame(InternalCF *)
InternalCF * addcoeff(InternalCF *)
InternalCF * subcoeff(InternalCF *, bool)
InternalPoly(termList, termList, const Variable &)
bool tryDivremsamet(InternalCF *, InternalCF *&, InternalCF *&, const CanonicalForm &, bool &)
static termList modTermList(termList, const CanonicalForm &, termList &)
static termList copyTermList(termList, termList &, bool negate=false)
static void appendTermList(termList &, termList &, const CanonicalForm &, const int)
static termList divTermList(termList, const CanonicalForm &, termList &)
InternalCF * mulsame(InternalCF *)
InternalCF * tryInvert(const CanonicalForm &, bool &)
InternalCF * tryMulsame(InternalCF *, const CanonicalForm &)
int sign() const
int InternalPoly::sign () const
InternalCF * tryDivsame(InternalCF *, const CanonicalForm &, bool &)
factory's class for variables
static const omBin term_bin
const Variable & v
< [in] a sqrfree bivariate poly
void setReduce(const Variable &alpha, bool reduce)
CanonicalForm getMipo(const Variable &alpha, const Variable &x)
operations on immediates, that is elements of F_p, GF, Z, Q that fit into intrinsic int,...
static long imm2int(const InternalCF *const imm)
Factory's internal CanonicalForm's.
Factory's internal integers.
Factory's internal polynomials.
void rem(unsigned long *a, unsigned long *q, unsigned long p, int °a, int degq)
gmp_float exp(const gmp_float &a)
#define omGetSpecBin(size)
bool getReduce(const Variable &alpha)
InternalPoly * getInternalMipo(const Variable &alpha)