Regina Calculation Engine
|
Represents a single-variable polynomial with coefficients of type T. More...
#include <maths/polynomial.h>
Public Types | |
typedef T | Coefficient |
The type of each coefficient of the polynomial. More... | |
Public Member Functions | |
Polynomial () | |
Creates the zero polynomial. More... | |
Polynomial (size_t degree) | |
Creates the polynomial x^d for the given degree d. More... | |
Polynomial (const Polynomial< T > &value) | |
Creates a new copy of the given polynomial. More... | |
template<typename U > | |
Polynomial (const Polynomial< U > &value) | |
Creates a new copy of the given polynomial. More... | |
Polynomial (Polynomial< T > &&value) noexcept | |
Moves the contents of the given polynomial to this new polynomial. More... | |
template<typename iterator > | |
Polynomial (iterator begin, iterator end) | |
Creates a new polynomial from the given sequence of coefficients. More... | |
~Polynomial () | |
Destroys this polynomial. More... | |
void | init () |
Sets this to become the zero polynomial. More... | |
void | init (size_t degree) |
Sets this to become the polynomial x^d for the given degree d. More... | |
template<typename iterator > | |
void | init (iterator begin, iterator end) |
Sets this to become the polynomial described by the given sequence of coefficients. More... | |
size_t | degree () const |
Returns the degree of this polynomial. More... | |
bool | isZero () const |
Returns whether this is the zero polynomial. More... | |
bool | isMonic () const |
Returns whether this polynomial is monic. More... | |
const T & | leading () const |
Returns the leading coefficient of this polynomial. More... | |
const T & | operator[] (size_t exp) const |
Returns the given coefficient of this polynomial. More... | |
void | set (size_t exp, const T &value) |
Changes the given coefficient of this polynomial. More... | |
bool | operator== (const Polynomial< T > &rhs) const |
Tests whether this and the given polynomial are equal. More... | |
bool | operator!= (const Polynomial< T > &rhs) const |
Tests whether this and the given polynomial are not equal. More... | |
Polynomial & | operator= (const Polynomial< T > &value) |
Sets this to be a copy of the given polynomial. More... | |
template<typename U > | |
Polynomial & | operator= (const Polynomial< U > &value) |
Sets this to be a copy of the given polynomial. More... | |
Polynomial & | operator= (Polynomial< T > &&value) noexcept |
Moves the contents of the given polynomial to this polynomial. More... | |
void | swap (Polynomial< T > &other) |
Swaps the contents of this and the given polynomial. More... | |
void | negate () |
Negates this polynomial. More... | |
Polynomial & | operator*= (const T &scalar) |
Multiplies this polynomial by the given constant. More... | |
Polynomial & | operator/= (const T &scalar) |
Divides this polynomial by the given constant. More... | |
Polynomial & | operator+= (const Polynomial< T > &other) |
Adds the given polynomial to this. More... | |
Polynomial & | operator-= (const Polynomial< T > &other) |
Subtracts the given polynomial from this. More... | |
Polynomial & | operator*= (const Polynomial< T > &other) |
Multiplies this by the given polynomial. More... | |
Polynomial & | operator/= (const Polynomial< T > &other) |
Divides this by the given polynomial. More... | |
void | divisionAlg (const Polynomial< T > &divisor, Polynomial< T > "ient, Polynomial< T > &remainder) const |
Divides this by the given divisor, and extracts both the quotient and the remainder. More... | |
template<typename U > | |
void | gcdWithCoeffs (const Polynomial< U > &other, Polynomial< T > &gcd, Polynomial< T > &u, Polynomial< T > &v) const |
Calculates the greatest common divisor of this and the given polynomial, and finds a linear combination of these polynomials that gives this gcd. More... | |
void | writeTextShort (std::ostream &out, bool utf8=false, const char *variable=0) const |
Writes this polynomial to the given output stream, using the given variable name instead of x . More... | |
std::string | str (const char *variable) const |
Returns this polynomial as a human-readable string, using the given variable name instead of x . More... | |
std::string | utf8 (const char *variable) const |
Returns this polynomial as a human-readable string using unicode characters, using the given variable name instead of x . More... | |
template<typename U > | |
Polynomial< T > & | operator= (const Polynomial< U > &value) |
void | writeTextLong (std::ostream &out) const |
A default implementation for detailed output. More... | |
std::string | str () const |
Returns a short text representation of this object. More... | |
std::string | utf8 () const |
Returns a short text representation of this object using unicode characters. More... | |
std::string | detail () const |
Returns a detailed text representation of this object. More... | |
Friends | |
template<typename U > | |
Polynomial< U > | operator+ (const Polynomial< U > &, const Polynomial< U > &) |
template<typename U > | |
Polynomial< U > | operator* (const Polynomial< U > &, const Polynomial< U > &) |
Represents a single-variable polynomial with coefficients of type T.
All exponents in the polynomial must be non-negative (so you can represent 2+3x
but not 1+1/x
).
The type T must represent a ring with no zero divisors. In particular, it must:
x = int
and tests of the form x == int
and x < int
;This means that Regina's numerical types such as Integer and Rational are supported, but native data types such as int and long are not (since they have no zero-initialising default constructor).
The underlying storage method for this class is dense (i.e., all coefficients are explicitly stored, including zero coefficients).
This class is designed to avoid deep copies wherever possible. In particular, it supports C++11 move constructors and move assignment. Functions that take or return objects by value are designed to be just as efficient as working with references or pointers (any variations to this are noted in the method documentation), and long chains of operators such as a = b * c + d
do not make unwanted deep copies.
|
inherited |
Returns a detailed text representation of this object.
This text may span many lines, and should provide the user with all the information they could want. It should be human-readable, should not contain extremely long lines (which cause problems for users reading the output in a terminal), and should end with a final newline. There are no restrictions on the underlying character set.
|
inherited |
Returns a short text representation of this object.
This text should be human-readable, should fit on a single line, and should not end with a newline. Where possible, it should use plain ASCII characters.
__str__()
.
|
inherited |
Returns a short text representation of this object using unicode characters.
Like str(), this text should be human-readable, should fit on a single line, and should not end with a newline. In addition, it may use unicode characters to make the output more pleasant to read. This string will be encoded in UTF-8.
|
inlineinherited |
A default implementation for detailed output.
This routine simply calls T::writeTextShort() and appends a final newline.
out | the output stream to which to write. |