36 #if defined(MPolynomial_RECURSES)
37 #error Recursive header files inclusion detected in MPolynomial.h
38 #else // defined(MPolynomial_RECURSES)
40 #define MPolynomial_RECURSES
42 #if !defined MPolynomial_h
50 #include "DGtal/base/Common.h"
56 template <
int n,
typename TRing,
57 typename TAlloc = std::allocator<TRing> >
59 template <
int N,
int n,
typename TRing,
60 typename TAlloc = std::allocator<TRing> >
62 template <
int n,
typename TRing,
63 typename TAlloc = std::allocator<TRing>,
67 template <
int n,
typename TRing,
typename TOwner,
68 typename TAlloc,
typename TX >
74 template <
typename TRing,
typename TAlloc >
88 template <
typename TRing,
typename TOwner,
89 typename TAlloc,
typename TX >
98 template <
int nn,
class TT,
class AA,
class SS>
101 template <
int nn,
class TT,
class HLHL,
class AA,
class SS>
149 inline operator X()
const
152 myOwner.evaluate( res, EvalFun( *
this ) );
180 template <
int n,
typename TRing,
typename TOwner,
181 typename TAlloc,
typename TX >
199 typename Alloc::template rebind<X>::other >
MPolyNM1;
201 template<
int nn,
class TT,
class AA,
class SS>
204 template<
int nn,
class TT,
class HLHL,
class AA,
class SS>
221 template <
typename XX,
typename Fun >
259 template <
typename XX,
typename Fun >
261 void evaluate( XX & res,
const Fun & evalfun )
const
265 myOwner.evaluate( res, EvalFun< XX, Fun >( *
this, evalfun ) );
314 myOwner.evaluate( res, EvalFun2( *
this ) );
322 template <
typename XX >
331 Alloc, XX >( *
this, x );
343 template <
typename TRing,
typename TAlloc,
typename TX >
398 template <
int n,
typename TRing,
typename TAlloc,
typename TX >
403 template<
int nn,
class TT,
class HLHL,
class AA,
class SS>
412 typename Alloc::template rebind<X>::other >
MPolyNM1;
428 template <
typename XX,
typename Fun >
430 void evaluate( XX & res,
const Fun & evalfun )
const
460 template <
typename XX>
493 template <
typename TRing,
typename TAlloc >
514 : myAllocator(allocator),
myValue(v)
540 inline operator const Ring & ()
const
719 template <
typename T,
typename TAlloc = std::allocator<T>,
720 bool usePo
inters = false>
725 typedef typename std::vector<T, Alloc>::size_type
Size;
735 :
myVec( aSize, T(), allocator )
739 :
myVec(aSize, entry, allocator)
749 myVec.resize(aSize, entry);
779 return myVec.get_allocator();
784 return myVec.get_allocator();
792 template <
typename T,
typename TAlloc>
798 typedef unsigned long int Size;
802 std::vector<typename Alloc::pointer, typename Alloc::template rebind<typename Alloc::pointer>::other>
myVec;
804 void create(
Size begin,
Size end,
typename Alloc::const_reference entry)
806 for (
Size i = begin; i < end; ++i)
808 myVec[i] = myAllocator.allocate(
sizeof(T));
809 myAllocator.construct(
myVec[i], entry);
815 for (
Size i = begin; i < end; ++i)
817 myAllocator.destroy(
myVec[i]);
818 myAllocator.deallocate(
myVec[i],
sizeof(T));
823 void copy_from(
const std::vector<typename Alloc::pointer, A> & source)
827 myVec[i] = myAllocator.allocate(
sizeof(T));
828 myAllocator.construct(
myVec[i], *source[i]);
834 : myAllocator(allocator),
myVec(allocator)
838 : myAllocator(allocator),
myVec(aSize, 0, allocator)
840 create(0, aSize, T());
844 : myAllocator(allocator),
myVec(aSize, 0, allocator)
846 create(0, aSize, entry);
880 free(aSize, oldsize);
883 create(oldsize, aSize, entry);
898 return *
myVec.back();
903 return *
myVec.back();
913 return myVec.get_allocator();
918 return myVec.get_allocator();
954 template <
int n,
typename TRing,
class TAlloc >
959 template<
int NN,
int nn,
typename TT,
typename AA>
962 friend void euclidDiv<TRing, TAlloc>
968 template<
int nn,
typename TT,
typename AA,
typename SS>
971 template<
int nn,
typename TT,
typename HLHL,
typename AA,
typename SS>
985 typename Alloc::template rebind<MPolyNM1 >::other, (n>1) >
1060 template <
typename Ring2,
typename Alloc2 >
1074 template <
typename Ring2,
typename Alloc2 >
1172 template <
typename Ring2>
1215 return *
this = *
this * p;
1468 r[i] +=
myValue[j] * p[i - j];
1498 return !(*
this == q);
1522 return !(*
this == v);
1546 if (nonzero > 1) s <<
"(";
1551 if (first) first =
false;
1558 if (i > 1) s <<
"^" << i;
1588 template <
int N,
typename TRing,
class TAlloc>
1605 template <
int n,
typename Ring,
typename Alloc>
1612 get(
unsigned int k,
unsigned int e )
1626 template <
typename Ring,
typename Alloc>
1633 get(
unsigned int ,
unsigned int )
1649 template <
int n,
typename Ring,
typename Alloc>
1652 Xe_k(
unsigned int k,
unsigned int e )
1665 template <
int n,
typename Ring>
1668 Xe_k(
unsigned int k,
unsigned int e )
1681 template <
typename Ring,
typename Alloc>
1699 template <
typename Ring,
typename Alloc>
1718 template <
typename Ring,
typename Alloc>
1737 template <
typename Ring,
typename Alloc>
1740 mmonomial(
unsigned int e,
unsigned int f,
unsigned int g,
unsigned int h)
1753 template <
typename Ring>
1770 template <
typename Ring>
1788 template <
typename Ring>
1807 template <
typename Ring>
1811 (
unsigned int e,
unsigned int f,
unsigned int g,
unsigned int h)
1839 template <
int n,
typename Ring,
class Alloc>
1857 for (
int i = 1; i <= src.
degree(); ++i )
1858 dest[i - 1] = src[i] * (Ring)i;
1884 template <
int N,
int n,
typename Ring,
typename Alloc>
1902 for (
int i = 0; i <= src.
degree(); ++i )
1912 template<
typename Ring,
class Alloc>
1916 class ERROR_N_must_be_strictly_less_than_n_in_derivative_template;
1922 ERROR_N_must_be_strictly_less_than_n_in_derivative_template();
1929 template<
int N,
typename Ring,
class Alloc>
1933 class ERROR_N_must_be_strictly_less_than_n_in_derivative_template;
1939 ERROR_N_must_be_strictly_less_than_n_in_derivative_template();
1961 template <
int N,
int n,
typename Ring,
typename Alloc>
1984 template<
int N,
int n,
typename Ring>
1992 ::computeDerivative( p, res );
1999 template<
typename Ring,
typename Alloc>
2016 for (
int i = q.
degree(); i >= 0; --i)
2019 for (
int j = g.
degree(); j >= 0; --j)
2020 r[i + j] -= q[i] * g[j];
2029 template <
typename Ring>
2032 const MPolynomial<1, Ring, std::allocator<Ring> > & g,
2036 euclidDiv<Ring, std::allocator<Ring> >(f, g, q, r);
2043 template<
typename Ring,
typename Alloc>
2050 if (g.
isZero())
return f;
2058 while (!d2.isZero())
2072 template<
typename Ring>
2075 const MPolynomial<1, Ring, std::allocator<Ring> > & g )
2077 return gcd<Ring, std::allocator<Ring> >(f, g);
2085 #include "DGtal/math/MPolynomial.ih"
2090 #endif // !defined MPolynomial_h
2092 #undef MPolynomial_RECURSES
2093 #endif // else defined(MPolynomial_RECURSES)