Regina Calculation Engine
|
Represents a single-variable Laurent polynomial with coefficients of type T. More...
#include <maths/laurent.h>
Public Types | |
typedef T | Coefficient |
The type of each coefficient of the polynomial. More... | |
Public Member Functions | |
Laurent () | |
Creates the zero polynomial. More... | |
Laurent (long exponent) | |
Creates the polynomial x^d for the given exponent d. More... | |
Laurent (const Laurent< T > &value) | |
Creates a new copy of the given polynomial. More... | |
template<typename U > | |
Laurent (const Laurent< U > &value) | |
Creates a new copy of the given polynomial. More... | |
Laurent (Laurent< T > &&value) noexcept | |
Moves the contents of the given polynomial to this new polynomial. More... | |
template<typename iterator > | |
Laurent (long minExp, iterator begin, iterator end) | |
Creates a new polynomial from the given sequence of coefficients. More... | |
Laurent (long minExp, std::initializer_list< T > coefficients) | |
Creates a new polynomial from a hard-coded sequence of coefficients. More... | |
~Laurent () | |
Destroys this polynomial. More... | |
void | init () |
Sets this to become the zero polynomial. More... | |
void | init (long exponent) |
Sets this to become the polynomial x^d for the given exponent d. More... | |
template<typename iterator > | |
void | init (long minExp, iterator begin, iterator end) |
Sets this to become the polynomial described by the given sequence of coefficients. More... | |
long | minExp () const |
Returns the smallest exponent that appears in this polynomial with a non-zero coefficient. More... | |
long | maxExp () const |
Returns the largest exponent that appears in this polynomial with a non-zero coefficient. More... | |
bool | isZero () const |
Returns whether this is the zero polynomial. More... | |
const T & | operator[] (long exp) const |
Returns the given coefficient of this polynomial. More... | |
void | set (long exp, const T &value) |
Changes the given coefficient of this polynomial. More... | |
bool | operator== (const Laurent< T > &rhs) const |
Tests whether this and the given polynomial are equal. More... | |
bool | operator!= (const Laurent< T > &rhs) const |
Tests whether this and the given polynomial are not equal. More... | |
Laurent & | operator= (const Laurent< T > &value) |
Sets this to be a copy of the given polynomial. More... | |
template<typename U > | |
Laurent & | operator= (const Laurent< U > &value) |
Sets this to be a copy of the given polynomial. More... | |
Laurent & | operator= (Laurent< T > &&value) noexcept |
Moves the contents of the given polynomial to this polynomial. More... | |
void | swap (Laurent< T > &other) |
Swaps the contents of this and the given polynomial. More... | |
void | shift (long s) |
Multiplies this polynomial by x^s for some integer s. More... | |
void | scaleUp (long k) |
Multiplies all exponents in this polynomial by k for some integer k. More... | |
void | scaleDown (long k) |
Divides all exponents in this polynomial by k for some integer k. More... | |
void | negate () |
Negates this polynomial. More... | |
Laurent & | operator*= (const T &scalar) |
Multiplies this polynomial by the given constant. More... | |
Laurent & | operator/= (const T &scalar) |
Divides this polynomial by the given constant. More... | |
Laurent & | operator+= (const Laurent< T > &other) |
Adds the given polynomial to this. More... | |
Laurent & | operator-= (const Laurent< T > &other) |
Subtracts the given polynomial from this. More... | |
Laurent & | operator*= (const Laurent< T > &other) |
Multiplies this by the given polynomial. More... | |
void | writeTextShort (std::ostream &out, bool utf8=false, const char *variable=nullptr) 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 > | |
Laurent< T > & | operator= (const Laurent< U > &other) |
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 > | |
Laurent< U > | operator+ (const Laurent< U > &, const Laurent< U > &) |
template<typename U > | |
Laurent< U > | operator+ (Laurent< U > &&, Laurent< U > &&) |
template<typename U > | |
Laurent< U > | operator- (const Laurent< U > &, const Laurent< U > &) |
template<typename U > | |
Laurent< U > | operator- (const Laurent< U > &, Laurent< U > &&) |
template<typename U > | |
Laurent< U > | operator- (Laurent< U > &&, Laurent< U > &&) |
template<typename U > | |
Laurent< U > | operator* (const Laurent< U > &, const Laurent< U > &) |
Represents a single-variable Laurent polynomial with coefficients of type T.
A Laurent polynomial differs from an ordinary polynomial in that it allows negative exponents (so, unlike the Polynomial class, you can represent both 2+3x
and 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).
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.
The underlying storage method for this class is dense (i.e., all coefficients are explicitly stored, including zero coefficients).
See also the class Laurent2, which describes Laurent polynomials in two variables.
|
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. |