1 #ifndef UTIL_POLYNOMIAL_H 2 #define UTIL_POLYNOMIAL_H 11 #include <util/containers/GArray.h> 12 #include <util/containers/DArray.h> 13 #include <util/math/Rational.h> 14 #include <util/math/Binomial.h> 15 #include <util/containers/DArray.h> 29 template <
typename T = Rational>
262 template <
typename T>
270 template <
typename T>
281 template <
typename T>
287 for (
int i = 0; i < coeffs.
capacity(); ++i) {
296 template <
typename T>
301 if (other.
size() > 0) {
302 for (
int i = 0; i < other.
size(); ++i) {
311 template <
typename T>
312 template <
typename U>
317 if (other.
size() >= 0) {
322 for (
int i = 0; i < other.
size(); ++i) {
333 template <
typename T>
341 template <
typename T>
349 template <
typename T>
355 for (
int i = 0; i < min; ++i) {
361 for (
int i =
size(); i < a.
size(); ++i) {
372 template <
typename T>
386 template <
typename T>
392 for (
int i = 0; i < min; ++i) {
398 for (
int i =
size(); i < a.
size(); ++i) {
409 template <
typename T>
423 template <
typename T>
428 for (
int i = 0; i <
size(); ++i) {
438 template <
typename T>
443 for (
int i = 0; i <
size(); ++i) {
453 template <
typename T>
479 for (i = 0; i < n; ++i) {
485 for (i = 0; i < a.
size(); ++i) {
486 for (j = 0; j < b.
size(); ++j) {
489 (*this)[k] += a[i]*b[j];
501 template <
typename T>
513 for (
int i = 0; i <
size(); ++i) {
514 coeffs[i+1] = (*this)[i];
515 coeffs[i+1] /= T(i+1);
527 template <
typename T>
542 for (
int i = 1; i <
size(); ++i) {
543 coeffs[i-1] = (*this)[i];
556 template <
typename T>
563 for (
int i = 0; i < b.
size(); ++i) {
575 template <
typename T>
586 for (n = 1; n <=
degree; ++n) {
588 for (m = 1; m <= n; ++m) {
601 template <
typename T>
606 T value = (*this)[
degree];
608 for (
int i = degree-1; i >= 0; --i) {
622 template <
typename T>
627 double value = (double)(*
this)[
degree];
629 for (
int i = degree-1; i >= 0; --i) {
631 value += (double)(*
this)[i];
645 template <
typename T>
653 for (
int i = 0; i <= power; ++i) {
654 a.GArray<T>::append(zero);
675 template <
typename T>
678 if (a.
size() != b.
size())
return false;
680 for (
int i = 0; i < a.
size(); ++i) {
681 if (a[i] != b[i])
return false;
694 template <
typename T>
696 {
return !(a == b); }
704 template <
typename T>
710 for (
int i = 0; i < a.
size(); ++i) {
717 template <
typename T>
718 std::ostream& operator << (std::ostream& out, Polynomial<T>
const & p)
722 for (
int i = 0; i < p.size(); ++i) {
int capacity() const
Return physical capacity of array.
static int coeff(int n, int m)
Return coefficient "n choose m", or C(n, m) = n!/(m!(n-m)!).
Polynomial< T > & operator*=(T a)
Multiply this polynomial by a scalar.
An automatically growable array, analogous to a std::vector.
Polynomial< T > operator-(Polynomial< T > const &a)
Unary negation of polynomial.
void append(const Data &data)
Append an element to the end of the sequence.
void clear()
Reset to empty state.
void setToZero()
Assign this polynomial a value of zero.
void reserve(int capacity)
Reserve memory for specified number of elements.
int size() const
Return logical size of this array (i.e., current number of elements).
Array container class template.
File containing preprocessor macros for error handling.
Polynomial< T > & operator+=(const Polynomial< T > &a)
Add another polynomial to this one.
Polynomial< T > differentiate() const
Compute and return derivative of this polynomial.
bool operator==(const PointSymmetry &A, const PointSymmetry &B)
Are two PointSymmetry objects equivalent?
Polynomial< T > & operator/=(T a)
Divide this polynomial by a scalar.
T operator()(T x) const
Evaluate polynomial at specific argument of type T.
double evaluate(double x) const
Evaluate polynomial at specific floating point argument.
static void setup(int nMax)
Precompute all combinations C(n, m) up to n = nMax.
Utility classes for scientific computation.
int degree() const
Return degree of polynomial.
Dynamically allocatable contiguous array template.
static Polynomial< T > monomial(int n)
Return a monomial f(x) = x^{n}.
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
Polynomial< T > & operator-=(const Polynomial< T > &a)
Subtract another polynomial from this one.
Polynomial< T > shift(T a) const
Compute and return shifted polynomial f(x+a).
Polynomial(int capacity=10)
Construct a zero polynomial.
int capacity() const
Return allocated size.
void allocate(int capacity)
Allocate the underlying C array.
Polynomial< T > & operator=(Polynomial< U > const &other)
Assignment from another polynomial.
Polynomial< T > integrate() const
Compute and return indefinite integral of this polynomial.
Polynomial< T > reflect() const
Compute and return reflected polynomial f(-x).
#define UTIL_ASSERT(condition)
Assertion macro suitable for debugging serial or parallel code.
bool operator!=(const PointSymmetry &A, const PointSymmetry &B)
Are two PointSymmetry objects not equivalent?