36#if defined(MPolynomial_RECURSES)
37#error Recursive header files inclusion detected in MPolynomial.h
40#define MPolynomial_RECURSES
42#if !defined MPolynomial_h
49#pragma GCC diagnostic push
50#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
51#pragma clang diagnostic push
52#pragma clang diagnostic ignored "-Wdeprecated-declarations"
60#include "DGtal/base/Common.h"
66 template <
int n,
typename TRing,
67 typename TAlloc = std::allocator<TRing> >
69 template <
int N,
int n,
typename TRing,
70 typename TAlloc = std::allocator<TRing> >
71 class MPolynomialDerivativeComputer;
72 template <
int n,
typename TRing,
73 typename TAlloc = std::allocator<TRing>,
75 class MPolynomialEvaluator;
77 template <
int n,
typename TRing,
typename TOwner,
78 typename TAlloc,
typename TX >
79 class MPolynomialEvaluatorImpl;
84 template <
typename TRing,
typename TAlloc >
98 template <
typename TRing,
typename TOwner,
99 typename TAlloc,
typename TX >
108 template <
int nn,
class TT,
class AA,
class SS>
111 template <
int nn,
class TT,
class HLHL,
class AA,
class SS>
146 for (
int i = 0; i < (int) p.myValue.size(); ++i )
148 res += (
X)(
Ring) p.myValue[i] * xx;
159 inline operator X()
const
190 template <
int n,
typename TRing,
typename TOwner,
191 typename TAlloc,
typename TX >
209 typename Alloc::template rebind<X>::other >
MPolyNM1;
211 template<
int nn,
class TT,
class AA,
class SS>
214 template<
int nn,
class TT,
class HLHL,
class AA,
class SS>
231 template <
typename XX,
typename Fun >
254 for (
int i = 0; i < (int) p.myValue.size(); ++i )
256 res +=
myEvalFun(p.myValue[i]) * (XX) xx;
269 template <
typename XX,
typename Fun >
271 void evaluate( XX & res,
const Fun & evalfun )
const
305 for (
int i = 0; i < (int) p.myValue.size(); ++i )
307 res += ( (
MPolyNM1) p.myValue[i] ) * xx;
333 template <
typename XX >
342 Alloc, XX >( *
this, x );
354 template <
typename TRing,
typename TAlloc,
typename TX >
409 template <
int n,
typename TRing,
typename TAlloc,
typename TX >
414 template<
int nn,
class TT,
class HLHL,
class AA,
class SS>
423 typename Alloc::template rebind<X>::other >
MPolyNM1;
439 template <
typename XX,
typename Fun >
441 void evaluate( XX & res,
const Fun & evalfun )
const
471 template <
typename XX>
504 template <
typename TRing,
typename TAlloc >
525 : myAllocator(allocator),
myValue(v)
551 inline operator const Ring & ()
const
729 template <
typename T,
typename TAlloc = std::allocator<T>,
730 bool usePo
inters = false>
735 typedef typename std::vector<T, Alloc>::size_type
Size;
745 :
myVec( aSize, T(), allocator )
749 :
myVec(aSize, entry, allocator)
759 myVec.resize(aSize, entry);
784 myVec.swap( v.myVec );
789 return myVec.get_allocator();
794 return myVec.get_allocator();
802 template <
typename T,
typename TAlloc>
807 typedef typename std::vector<typename Alloc::pointer, typename Alloc::template rebind<typename Alloc::pointer>::other>::size_type
Size;
811 std::vector<typename Alloc::pointer, typename Alloc::template rebind<typename Alloc::pointer>::other>
myVec;
815 for (
Size i = begin; i < end; ++i)
817 myVec[i] = myAllocator.allocate(
sizeof(T));
818 myAllocator.construct(
myVec[i], entry);
824 for (
Size i = begin; i < end; ++i)
826 myAllocator.destroy(
myVec[i]);
827 myAllocator.deallocate(
myVec[i],
sizeof(T));
832 void copy_from(
const std::vector<typename Alloc::pointer, A> & source)
836 myVec[i] = myAllocator.allocate(
sizeof(T));
837 myAllocator.construct(
myVec[i], *source[i]);
843 : myAllocator(allocator),
myVec(allocator)
847 : myAllocator(allocator),
myVec(aSize, 0, allocator)
849 create(0, aSize, T());
853 : myAllocator(allocator),
myVec(aSize, 0, allocator)
855 create(0, aSize, entry);
874 myVec.resize(v.size());
889 free(aSize, oldsize);
892 create(oldsize, aSize, entry);
907 return *
myVec.back();
912 return *
myVec.back();
922 return myVec.get_allocator();
927 return myVec.get_allocator();
963 template <
int n,
typename TRing,
class TAlloc >
968 template<
int NN,
int nn,
typename TT,
typename AA>
977 template<
int nn,
typename TT,
typename AA,
typename SS>
980 template<
int nn,
typename TT,
typename HLHL,
typename AA,
typename SS>
994 typename Alloc::template rebind<MPolyNM1 >::other, (n>1) >
1069 template <
typename Ring2,
typename Alloc2 >
1083 template <
typename Ring2,
typename Alloc2 >
1181 template <
typename Ring2>
1224 return *
this = *
this * p;
1262 for (
Size i = 0; i < p.myValue.size(); ++i )
1286 if (r.myValue.size() < q.myValue.size())
1287 r.myValue.resize(q.myValue.size());
1288 for (
Size i = 0; i < q.myValue.size(); ++i )
1302 if (r.myValue.size() < q.myValue.size())
1303 r.myValue.resize(q.myValue.size());
1304 for (
Size i = 0; i < q.myValue.size(); ++i )
1319 for (
Size i = 0; i < q.myValue.size(); ++i )
1334 for (
Size i = 0; i < q.myValue.size(); ++i )
1349 if (r.myValue.size() < 1)
1350 r.myValue.resize(1);
1365 if (r.myValue.size() < 1)
1366 r.myValue.resize(1);
1380 if (r.myValue.size() < 1)
1381 r.myValue.resize(1);
1395 if (r.myValue.size() < 1)
1396 r.myValue.resize(1);
1473 if (!
isZero() && !p.isZero())
1474 for (
Size i = 0; i < r.myValue.size(); ++i )
1476 if (i < j + p.myValue.size())
1477 r[i] +=
myValue[j] * p[i - j];
1507 return !(*
this == q);
1531 return !(*
this == v);
1556 if (nonzero > 1) s <<
"(";
1561 if (first) first =
false;
1568 if (i > 1) s <<
"^" << i;
1598 template <
int N,
typename TRing,
class TAlloc>
1612 template <
int n,
typename Ring,
typename Alloc>
1624 get(
unsigned int k,
unsigned int e )
1638 template <
typename Ring,
typename Alloc>
1645 get(
unsigned int ,
unsigned int )
1661 template <
int n,
typename Ring,
typename Alloc>
1663 MPolynomial<n, Ring, Alloc>
1664 Xe_k(
unsigned int k,
unsigned int e )
1677 template <
int n,
typename Ring>
1679 MPolynomial<n, Ring, std::allocator<Ring> >
1680 Xe_k(
unsigned int k,
unsigned int e )
1693 template <
typename Ring,
typename Alloc>
1695 MPolynomial<1, Ring, Alloc>
1711 template <
typename Ring,
typename Alloc>
1713 MPolynomial<2, Ring, Alloc>
1730 template <
typename Ring,
typename Alloc>
1731 inline MPolynomial<3, Ring, Alloc>
1749 template <
typename Ring,
typename Alloc>
1751 MPolynomial<4, Ring, Alloc>
1752 mmonomial(
unsigned int e,
unsigned int f,
unsigned int g,
unsigned int h)
1765 template <
typename Ring>
1767 MPolynomial<1, Ring, std::allocator<Ring> >
1782 template <
typename Ring>
1784 MPolynomial<2, Ring, std::allocator<Ring> >
1800 template <
typename Ring>
1802 MPolynomial<3, Ring, std::allocator<Ring> >
1819 template <
typename Ring>
1821 MPolynomial<4, Ring, std::allocator<Ring> >
1823 (
unsigned int e,
unsigned int f,
unsigned int g,
unsigned int h)
1851 template <
int n,
typename Ring,
class Alloc>
1869 for (
int i = 1; i <= src.degree(); ++i )
1870 dest[i - 1] = src[i] * (Ring)i;
1896 template <
int N,
int n,
typename Ring,
typename Alloc>
1914 for (
int i = 0; i <= src.degree(); ++i )
1924 template<
typename Ring,
class Alloc>
1928 class ERROR_N_must_be_strictly_less_than_n_in_derivative_template;
1934 ERROR_N_must_be_strictly_less_than_n_in_derivative_template();
1941 template<
int N,
typename Ring,
class Alloc>
1945 class ERROR_N_must_be_strictly_less_than_n_in_derivative_template;
1951 ERROR_N_must_be_strictly_less_than_n_in_derivative_template();
1973 template <
int N,
int n,
typename Ring,
typename Alloc>
1975 MPolynomial<n, Ring, Alloc>
1996 template<
int N,
int n,
typename Ring>
1998 MPolynomial<n, Ring, std::allocator<Ring> >
2000 (
const MPolynomial<n,Ring,std::allocator<Ring> > & p)
2004 ::computeDerivative( p, res );
2011 template<
typename Ring,
typename Alloc>
2018 if (f.degree() < g.degree())
2028 for (
int i = q.degree(); i >= 0; --i)
2030 q[i] = r[i + g.degree()] / g.leading();
2031 for (
int j = g.degree(); j >= 0; --j)
2032 r[i + j] -= q[i] * g[j];
2041 template <
typename Ring>
2044 const MPolynomial<1, Ring, std::allocator<Ring> > & g,
2055 template<
typename Ring,
typename Alloc>
2056 MPolynomial<1, Ring, Alloc>
2062 if (g.isZero())
return f;
2063 else return g / g.leading();
2066 d1(f / f.leading()),
2067 d2(g / g.leading()),
2068 q(f.getAllocator()),
2069 r(f.getAllocator());
2070 while (!d2.isZero())
2084 template<
typename Ring>
2085 MPolynomial<1, Ring, std::allocator<Ring> >
2087 const MPolynomial<1, Ring, std::allocator<Ring> > & g )
2097#include "DGtal/math/MPolynomial.ih"
2099#pragma GCC diagnostic pop
2100#pragma clang diagnostic pop
2108#undef MPolynomial_RECURSES
IVector(Size aSize, const Alloc &allocator=Alloc())
Alloc getAllocator() const
IVector(Size aSize, const T &entry, const Alloc &allocator=Alloc())
void copy_from(const std::vector< typename Alloc::pointer, A > &source)
IVector(const Alloc &allocator=Alloc())
void create(Size begin, Size end, typename Alloc::const_reference entry)
void resize(Size aSize, const T &entry=T())
std::vector< typenameAlloc::pointer, typenameAlloc::templaterebind< typenameAlloc::pointer >::other >::size_type Size
Alloc get_allocator() const
std::vector< typename Alloc::pointer, typename Alloc::template rebind< typename Alloc::pointer >::other > myVec
IVector(const IVector &v)
void free(Size begin, Size end)
std::vector< T, Alloc >::size_type Size
IVector(const Alloc &allocator=Alloc())
IVector(Size aSize, const Alloc &allocator=Alloc())
Alloc get_allocator() const
std::vector< T, Alloc > myVec
const T & operator[](Size i) const
IVector(Size aSize, const T &entry, const Alloc &allocator=Alloc())
Alloc getAllocator() const
void resize(Size aSize, const T &entry=T())
MPolynomial< 0, Ring, Alloc > MPoly0
static void computeDerivative(const MPoly0 &, MPoly0 &)
static void computeDerivative(const MPolyN &src, MPolyN &dest)
MPolynomial< n, Ring, Alloc > MPolyN
Type for polynomial with n variable in the ring Ring.
static void computeDerivative(const MPoly0 &, MPoly0 &)
MPolynomial< 0, Ring, Alloc > MPoly0
MPolynomial< n, Ring, Alloc > MPolyN
Type for polynomial with n variable in the ring Ring.
static void computeDerivative(const MPolyN &src, MPolyN &dest)
const MPolynomialEvaluatorImpl< n, Ring, Owner, Alloc, X > & myOwner
MPolyNM1 operator()(const MPolyN &p) const
EvalFun2(const MPolynomialEvaluatorImpl< n, Ring, Owner, Alloc, X > &owner)
const MPolynomialEvaluatorImpl< n, Ring, Owner, Alloc, X > & myOwner
XX operator()(const MPolynomial< n, Ring, Alloc > &p) const
EvalFun(const MPolynomialEvaluatorImpl< n, Ring, Owner, Alloc, X > &owner, const Fun &evalfun)
const MPolynomialEvaluatorImpl< 1, Ring, Owner, Alloc, X > & myOwner
EvalFun(const MPolynomialEvaluatorImpl< 1, Ring, Owner, Alloc, X > &owner)
const Owner & myOwner
The "owner".
MPolynomialEvaluatorImpl(const Owner &owner, const X &evalpoint)
const X & myEvalPoint
The evaluation point on this level.
void evaluate(XX &res, const Fun &evalfun) const
MPolynomial< n - 1, X, typename Alloc::template rebind< X >::other > MPolyNM1
MPolynomialEvaluatorImpl< n - 1, Ring, MPolynomialEvaluatorImpl< n, Ring, Owner, Alloc, X >, Alloc, XX > operator()(const XX &x) const
MPolynomial< n, Ring, Alloc > MPolyN
Type for the multivariate polynomial.
MPolynomialEvaluatorImpl(const Owner &owner, const X &evalpoint)
MPolynomial< 1, Ring, Alloc > MPoly1
const X & myEvalPoint
The evaluation point.
const MPoly1 & myPoly
The polynomial in question.
MPolynomialEvaluator(const MPoly1 &poly, const X &evalpoint)
MPolynomial< n, Ring, Alloc > MPolyN
const X & myEvalPoint
the evaluation point
MPolynomial< n - 1, X, typename Alloc::template rebind< X >::other > MPolyNM1
MPolynomialEvaluator(const MPolyN &poly, const X &evalpoint)
MPolynomialEvaluatorImpl< n - 1, Ring, MPolynomialEvaluator< n, Ring, Alloc, X >, Alloc, XX > operator()(const XX &x) const
void evaluate(XX &res, const Fun &evalfun) const
const MPolyN & myPoly
The polynomial in question.
MPolynomial(const Alloc &allocator)
MPolynomial(const Ring &v=0, const Alloc &allocator=Alloc())
void selfDisplay(std::ostream &s, int) const
Alloc getAllocator() const
void swap(MPolynomial &p)
Aim: Represents a multivariate polynomial, i.e. an element of , where K is some ring or field.
MPolynomial(const Ring &v, const Alloc &allocator=Alloc())
bool operator==(const MPolynomial &q) const
static MPolyNM1 myZeroPolynomial
The zero polynomial of n-1 variables for a n-multivariate polynomial.
MPolynomialEvaluator< n, Ring, Alloc, Ring > operator()(const Ring &x) const
friend void euclidDiv(const MPolynomial< 1, TRing, TAlloc > &, const MPolynomial< 1, TRing, TAlloc > &, MPolynomial< 1, TRing, TAlloc > &, MPolynomial< 1, TRing, TAlloc > &)
void selfDisplay(std::ostream &s, int N=n) const
MPolynomial(const Alloc &allocator=Alloc())
friend MPolynomial operator*(const Ring &v, const MPolynomial &p)
MPolynomial & operator-=(const MPolynomial &q)
MPolynomial operator/(const Ring &v) const
MPolynomial & operator/=(const Ring &v)
MPolynomial< n - 1, Ring, Alloc > MPolyNM1
MPolynomial operator-() const
MPolynomial & operator+=(const MPolynomial &q)
MPolynomial(const MPolyNM1 &pdm1, const Alloc &)
MPolyNM1 & operator[](Size i)
MPolynomial & operator*=(const MPolynomial &p)
Alloc getAllocator() const
bool operator!=(const MPolynomial &q) const
void swap(MPolynomial &p)
friend class MPolynomialEvaluator
const MPolyNM1 & leading() const
MPolynomial(bool, Size s, const Alloc &)
MPolynomial(const MPolynomial< n, Ring2, Alloc2 > &p, const Alloc &allocator=Alloc())
MPolynomial & operator=(const MPolynomial< n, Ring2, Alloc2 > &p)
MPolynomial operator+(const MPolynomial &q) const
MPolynomial< 0, Ring, Alloc > get(unsigned int, unsigned int)
MPolynomial< n, Ring, Alloc > get(unsigned int k, unsigned int e)
DGtal is the top-level namespace which contains all DGtal functions and types.
void euclidDiv(const MPolynomial< 1, TRing, TAlloc > &f, const MPolynomial< 1, TRing, TAlloc > &g, MPolynomial< 1, TRing, TAlloc > &q, MPolynomial< 1, TRing, TAlloc > &r)
MPolynomial< 1, Ring, Alloc > mmonomial(unsigned int e)
MPolynomial< n, Ring, Alloc > Xe_k(unsigned int k, unsigned int e)
std::ostream & operator<<(std::ostream &out, const ClosedIntegerHalfPlane< TSpace > &object)
MPolynomial< 1, Ring, Alloc > gcd(const MPolynomial< 1, Ring, Alloc > &f, const MPolynomial< 1, Ring, Alloc > &g)
MPolynomial< n, Ring, Alloc > derivative(const MPolynomial< n, Ring, Alloc > &p)