piranha
0.10
|
Monomial class. More...
#include <piranha/monomial.hpp>
Public Types | |
using | container_type = small_vector< T, S > |
The internal container type. | |
using | value_type = typename container_type::value_type |
Value type. | |
using | iterator = typename container_type::iterator |
Iterator type. | |
using | const_iterator = typename container_type::const_iterator |
Const iterator type. | |
using | size_type = typename container_type::size_type |
Size type. | |
Public Member Functions | |
monomial ()=default | |
Defaulted default constructor. | |
monomial (const monomial &)=default | |
Defaulted copy constructor. | |
monomial (monomial &&)=default | |
Defaulted move constructor. | |
template<typename U , init_list_enabler< U > = 0> | |
monomial (std::initializer_list< U > list) | |
Constructor from initializer list. More... | |
template<typename Iterator , it_ctor_enabler< Iterator > = 0> | |
monomial (Iterator begin, Iterator end) | |
Constructor from range. More... | |
template<typename Iterator , it_ctor_enabler< Iterator > = 0> | |
monomial (Iterator begin, Iterator end, const symbol_fset &s) | |
Constructor from range and symbol set. More... | |
~monomial () | |
Destructor. | |
monomial & | operator= (const monomial &other)=default |
Copy assignment operator. More... | |
monomial & | operator= (monomial &&other)=default |
Defaulted move assignment operator. More... | |
bool | is_compatible (const symbol_fset &args) const noexcept |
Compatibility check. More... | |
bool | is_zero (const symbol_fset &) const noexcept |
Zero check. More... | |
bool | is_unitary (const symbol_fset &args) const |
Check if the monomial is unitary. More... | |
template<typename U = T> | |
degree_type< U > | degree (const symbol_fset &args) const |
Degree. More... | |
template<typename U = T> | |
degree_type< U > | degree (const symbol_idx_fset &p, const symbol_fset &args) const |
Partial degree. More... | |
template<typename U = T> | |
degree_type< U > | ldegree (const symbol_fset &args) const |
Low degree (equivalent to the degree). More... | |
template<typename U = T> | |
degree_type< U > | ldegree (const symbol_idx_fset &p, const symbol_fset &args) const |
Partial low degree (equivalent to the partial degree). More... | |
std::pair< bool, symbol_idx > | is_linear (const symbol_fset &args) const |
Detect linear monomial. More... | |
template<typename U , pow_enabler< U > = 0> | |
monomial | pow (const U &x, const symbol_fset &args) const |
Monomial exponentiation. More... | |
template<typename U = T, partial_enabler< U > = 0> | |
std::pair< T, monomial > | partial (const symbol_idx &p, const symbol_fset &args) const |
Partial derivative. More... | |
template<typename U = T, integrate_enabler< U > = 0> | |
std::pair< T, monomial > | integrate (const std::string &s, const symbol_fset &args) const |
Integration. More... | |
void | print (std::ostream &os, const symbol_fset &args) const |
Print. More... | |
void | print_tex (std::ostream &os, const symbol_fset &args) const |
Print in TeX mode. More... | |
template<typename U > | |
eval_type< U > | evaluate (const std::vector< U > &values, const symbol_fset &args) const |
Evaluation. More... | |
template<typename U > | |
std::vector< std::pair< subs_type< U >, monomial > > | subs (const symbol_idx_fmap< U > &smap, const symbol_fset &args) const |
Substitution. More... | |
template<typename U > | |
std::vector< std::pair< ipow_subs_type< U >, monomial > > | ipow_subs (const symbol_idx &p, const integer &n, const U &x, const symbol_fset &args) const |
Substitution of integral power. More... | |
bool | operator< (const monomial &other) const |
Comparison operator. More... | |
template<typename Stream , msgpack_pack_enabler< Stream > = 0> | |
void | msgpack_pack (msgpack::packer< Stream > &packer, msgpack_format f, const symbol_fset &s) const |
Serialize in msgpack format. More... | |
template<typename U = monomial, msgpack_convert_enabler< U > = 0> | |
void | msgpack_convert (const msgpack::object &o, msgpack_format f, const symbol_fset &s) |
Deserialize from msgpack object. More... | |
iterator | begin () |
Begin iterator. More... | |
const_iterator | begin () const |
Begin const iterator. More... | |
iterator | end () |
End iterator. More... | |
const_iterator | end () const |
End const iterator. More... | |
size_type | size () const |
Size. More... | |
void | resize (const size_type &new_size) |
Resize the internal array container. More... | |
value_type & | operator[] (const size_type &i) |
Element access. More... | |
const value_type & | operator[] (const size_type &i) const |
Const element access. More... | |
std::size_t | hash () const |
Hash value. More... | |
void | push_back (value_type &&x) |
Move-add element at the end. More... | |
void | push_back (const value_type &x) |
Copy-add element at the end. More... | |
bool | operator== (const array_key &other) const |
Equality operator. More... | |
bool | operator!= (const array_key &other) const |
Inequality operator. More... | |
void | trim_identify (std::vector< char > &trim_mask, const symbol_fset &args) const |
Identify symbols that can be trimmed. More... | |
monomial< T, S > | trim (const std::vector< char > &trim_mask, const symbol_fset &args) const |
Trim. More... | |
void | vector_add (array_key &retval, const array_key &other) const |
Vector add. More... | |
void | vector_sub (array_key &retval, const array_key &other) const |
Vector sub. More... | |
monomial< T, S > | merge_symbols (const symbol_idx_fmap< symbol_fset > &ins_map, const symbol_fset &args) const |
Merge symbols. More... | |
auto | size_begin_end () const -> decltype(m_container.size_begin_end()) |
Get size, begin and end iterator (const version). More... | |
auto | size_begin_end () -> decltype(m_container.size_begin_end()) |
Get size, begin and end iterator. More... | |
Static Public Member Functions | |
template<typename Cf , multiply_enabler< Cf > = 0> | |
static void | multiply (std::array< term< Cf, monomial >, multiply_arity > &res, const term< Cf, monomial > &t1, const term< Cf, monomial > &t2, const symbol_fset &args) |
Multiply terms with a monomial key. More... | |
Static Public Attributes | |
static const std::size_t | multiply_arity = 1u |
Arity of the multiply() method. | |
Protected Attributes | |
container_type | m_container |
Internal container. | |
Monomial class.
This class extends piranha::array_key to define a series key type representing monomials, that is, objects of the form:
\[ x_0^{y_0} \cdot x_1^{y_1} \cdot \ldots \cdot x_n^{y_n}. \]
The type T
represents the type of the exponents \( y_i \), which are stored in a flat array.
This class satisfies the piranha::is_key type trait.
T
and S
must be suitable for use as first and third template arguments in piranha::array_key. Additionally, T
must be copy-assignable and it must satisfy the following type-traits:
Unless noted otherwise, this class provides the same exception safety guarantee as piranha::array_key.
Move semantics is equivalent to piranha::array_key's move semantics.
Definition at line 100 of file monomial.hpp.
|
inlineexplicit |
Constructor from initializer list.
list | initializer list. |
Definition at line 137 of file monomial.hpp.
|
inlineexplicit |
Constructor from range.
Iterator
is an input iterator whose value type can be cast safely to T
.This constructor will copy the elements from the range defined by begin
and end
into this
, using piranha::safe_cast() for any necessary type conversion.
begin | beginning of the range. |
end | end of the range. |
unspecified | any exception thrown by: |
Definition at line 167 of file monomial.hpp.
|
inlineexplicit |
Constructor from range and symbol set.
Iterator
is an input iterator whose value type can be cast safely to T
.This constructor will copy the elements from the range defined by begin
and end
into this
, using piranha::safe_cast() for any necessary type conversion. If the final size of this
is different from the size of s
, a runtime error will be produced. This constructor is used by piranha::polynomial::find_cf().
begin | beginning of the range. |
end | end of the range. |
s | reference symbol set. |
std::invalid_argument | if the final size of this and the size of s differ. |
unspecified | any exception thrown by: |
Definition at line 194 of file monomial.hpp.
|
inlineinherited |
Begin iterator.
Definition at line 222 of file array_key.hpp.
|
inlineinherited |
Begin const iterator.
Definition at line 238 of file array_key.hpp.
|
inline |
Degree.
T
is addable, yielding a type degree_type
,degree_type
is constructible from int
,degree_type
,degree_type
satisfies piranha::is_returnable.This method will return the degree of the monomial, computed via the summation of the exponents of the monomial. If T
is a C++ integral type, the addition of the exponents will be checked for overflow.
args | reference piranha::symbol_fset. |
std::invalid_argument | if the sizes of args and this differ. |
std::overflow_error | if the exponent type is a C++ integral type and the computation of the degree overflows. |
unspecified | any exception thrown by the invoked constructor or arithmetic operators. |
Definition at line 313 of file monomial.hpp.
|
inline |
Partial degree.
T
is addable, yielding a type degree_type
,degree_type
is constructible from int
,degree_type
,degree_type
satisfies piranha::is_returnable.This method will return the partial degree of the monomial, computed via the summation of the exponents of the monomial. If T
is a C++ integral type, the addition of the exponents will be checked for overflow.
The p
argument is used to indicate the positions of the exponents to be taken into account when computing the partial degree. Exponents at positions not present in p
will be discarded during the computation of the partial degree.
p | positions of the symbols to be considered. |
args | reference piranha::symbol_fset. |
std::invalid_argument | if the sizes of args and this differ, or if the largest value in p is not less than the size of the monomial. |
std::overflow_error | if the exponent type is a C++ integral type and the computation of the degree overflows. |
unspecified | any exception thrown by the invoked constructor or arithmetic operators. |
Definition at line 357 of file monomial.hpp.
|
inlineinherited |
End iterator.
Definition at line 230 of file array_key.hpp.
|
inlineinherited |
End const iterator.
Definition at line 246 of file array_key.hpp.
|
inline |
Evaluation.
U
satisfies the following requirements:eval_type
,eval_type
is constructible from int
,eval_type
is multipliable in place,eval_type
satisfies piranha::is_returnable.The return value will be built by iteratively applying piranha::math::pow() using the values provided by values
as bases and the values in the monomial as exponents. If the size of the monomial is zero, 1 will be returned.
values | the values will be used for the evaluation. |
args | the reference piranha::symbol_fset. |
this
with the values provided in values
.std::invalid_argument | if the sizes of values and args differ, or if the sizes of this and args differ. |
unspecified | any exception thrown by:
|
Definition at line 846 of file monomial.hpp.
|
inlineinherited |
Hash value.
unspecified | any exception thrown by piranha::small_vector::hash(). |
Definition at line 296 of file array_key.hpp.
|
inline |
Integration.
This method will return the antiderivative of this
with respect to the symbol s
. The result is a pair consisting of the exponent associated to s
increased by one and the monomial itself after integration. If s
is not in args
, the returned monomial will have an extra exponent set to 1 in the same position s
would have if it were added to args
. If the exponent corresponding to s
is -1, an error will be produced.
If the exponent type is an integral type, then the increment-by-one operation on the affected exponent is checked for negative overflow.
s | the symbol with respect to which the integration will be calculated. |
args | the reference piranha::symbol_fset. |
std::invalid_argument | if the sizes of args and this differ, or if the exponent associated to s is -1. |
std::overflow_error | if T is a C++ integral type and the integration leads to integer overflow. |
unspecified | any exception thrown by:
|
Definition at line 654 of file monomial.hpp.
|
inline |
Substitution of integral power.
U
can be raised to a piranha::integer power, yielding a type subs_type
,subs_type
is constructible from int
,subs_type
satisfies piranha::is_returnable,This method will substitute the n
-th power of the symbol at the position p
with the quantity x
. The return value is a vector containing a single pair in which the first element is the result of the substitution, and the second element the monomial after the substitution has been performed. If p
is not less than the size of args
, the return value will be (1,this)
(i.e., the monomial is unchanged and the substitution yields 1).
The method will substitute also powers higher than n
in absolute value. For instance, the substitution of y**2
with a
in the monomial y**7
will produce a**3 * y
, and the substitution of y**-2
with a
in the monomial y**-7
will produce a**3 * y**-1
.
p | the position of the symbol that will be substituted. |
n | the integral power that will be substituted. |
x | the quantity that will be substituted. |
args | the reference piranha::symbol_fset. |
x
for the n
-th power of the symbol at the position p
.std::invalid_argument | is n is zero, or if the sizes of args and this differ. |
unspecified | any exception thrown by:
|
Definition at line 1044 of file monomial.hpp.
|
inlinenoexcept |
Compatibility check.
A monomial and a set of arguments are compatible if their sizes coincide.
args | reference piranha::symbol_fset. |
true
if the size of this
is equal to the size of args
, false
otherwise. Definition at line 235 of file monomial.hpp.
|
inline |
Detect linear monomial.
If the monomial is linear in a variable (i.e., all exponents are zero apart from a single unitary exponent), then this method will return a pair formed by the true
value and the position, in args
, of the linear variable. Otherwise, the returned value will be a pair formed by the false
value and an unspecified position value.
args | the reference piranha::symbol_fset. |
std::invalid_argument | if the sizes of this and args differ. |
unspecified | any exception thrown by piranha::math::is_zero() or piranha::math::is_unitary(). |
Definition at line 421 of file monomial.hpp.
|
inline |
Check if the monomial is unitary.
A monomial is unitary if, for all its elements, piranha::math::is_zero() returns true
.
args | reference piranha::symbol_fset. |
true
if the monomial is unitary, false
otherwise.std::invalid_argument | if the sizes of args and this differ. |
unspecified | any exception thrown by piranha::math::is_zero(). |
Definition at line 260 of file monomial.hpp.
|
inlinenoexcept |
|
inline |
Low degree (equivalent to the degree).
args | reference piranha::symbol_fset. |
unspecified | any exception thrown by degree(const symbol_fset &args) const. |
Definition at line 389 of file monomial.hpp.
|
inline |
Partial low degree (equivalent to the partial degree).
p | positions of the symbols to be considered. |
args | reference piranha::symbol_fset. |
unspecified | any exception thrown by degree(const symbol_idx_fset &, const symbol_fset &) const. |
Definition at line 403 of file monomial.hpp.
|
inlineinherited |
Merge symbols.
This method will return a copy of this
in which the value 0 has been inserted at the positions specified by ins_map
. Specifically, before each index appearing in ins_map
a number of zeroes equal to the size of the mapped piranha::symbol_fset will be inserted.
For instance, given a piranha::array_key containing the values [1,2,3,4]
, a symbol set args
containing ["c","e","g","h"]
and an insertion map ins_map
containing the pairs [(0,["a","b"]),(1,["d"]),(2,["f"]),(4,["i"])]
, the output of this method will be [0,0,1,0,2,0,3,4,0]
. That is, the symbols appearing in ins_map
are merged into this
with a value of zero at the specified positions.
ins_map | the insertion map. |
args | the reference symbol set for this . |
Derived
instance resulting from inserting into this
zeroes at the positions specified by ins_map
.std::invalid_argument | in the following cases:
|
unspecified | any exception thrown by:
|
Definition at line 508 of file array_key.hpp.
|
inline |
Deserialize from msgpack object.
This method will deserialize o
into this
using the format f
. This method provides the basic exception safety guarantee.
o | msgpack object that will be deserialized. |
f | serialization format. |
s | the reference piranha::symbol_fset. |
std::invalid_argument | if the size of the deserialized array differs from the size of s . |
unspecified | any exception thrown by piranha::msgpack_convert(). |
Definition at line 1219 of file monomial.hpp.
|
inline |
Serialize in msgpack format.
Stream
satisfies piranha::is_msgpack_stream and the internal container type satisfies piranha::has_msgpack_pack.This method will pack this
into packer
using the format f
.
packer | the target packer. |
f | the serialization format. |
s | the reference piranha::symbol_fset. |
std::invalid_argument | if the sizes of s and this differ. |
unspecified | any exception thrown by piranha::msgpack_pack(). |
Definition at line 1192 of file monomial.hpp.
|
inlinestatic |
Multiply terms with a monomial key.
T
satisfies piranha::has_add3,Cf
satisfies piranha::has_mul3.Multiply t1
by t2
, storing the result in the only element of res
. If Cf
is an instance of piranha::mp_rational, then only the numerators of the coefficients will be multiplied.
This method offers the basic exception safety guarantee.
res | the return value. |
t1 | the first argument. |
t2 | the second argument. |
args | the reference piranha::symbol_fset. |
std::invalid_argument | if the size of t1 differs from the size of args . |
unspecified | any exception thrown by piranha::array_key::vector_add(), or by piranha::math::mul3(). |
Definition at line 1116 of file monomial.hpp.
|
inlineinherited |
Inequality operator.
other | the comparison argument. |
unspecified | any exception thrown by the equality operator. |
Definition at line 344 of file array_key.hpp.
|
inline |
Comparison operator.
The two monomials will be compared lexicographically.
other | comparison argument. |
true
if this
is lexicographically less than other
, false
otherwise.std::invalid_argument | if the sizes of this and other differ. |
unspecified | any exception thrown by std::lexicographical_compare() . |
Definition at line 1143 of file monomial.hpp.
|
default |
Copy assignment operator.
other | the assignment argument. |
this
.unspecified | any exception thrown by the assignment operator of the base class. |
|
default |
Defaulted move assignment operator.
other | the assignment argument. |
this
.
|
inlineinherited |
Equality operator.
other | the comparison argument. |
unspecified | any exception thrown by piranha::small_vector::operator==(). |
Definition at line 332 of file array_key.hpp.
|
inlineinherited |
Element access.
i | the index of the element to be accessed. |
i
. Definition at line 276 of file array_key.hpp.
|
inlineinherited |
Const element access.
i | the index of the element to be accessed. |
i
. Definition at line 286 of file array_key.hpp.
|
inline |
Partial derivative.
This method will return the partial derivative of this
with respect to the symbol at the position indicated by p
. The result is a pair consisting of the exponent associated to p
before differentiation and the monomial itself after differentiation. If p
is not smaller than the size of args
or if its corresponding exponent is zero, the returned pair will be (0,monomial{args})
.
If the exponent type is an integral type, then the decrement-by-one operation on the affected exponent is checked for negative overflow.
p | the position of the symbol with respect to which the differentiation will be calculated. |
args | the reference piranha::symbol_fset. |
std::invalid_argument | if the sizes of args and this differ. |
std::overflow_error | if the decrement of the affected exponent results in overflow. |
unspecified | any exception thrown by:
|
Definition at line 566 of file monomial.hpp.
|
inline |
Monomial exponentiation.
This method will return a monomial corresponding to this
raised to the x
-th power. The exponentiation is computed via the multiplication of the exponents by x
. The multiplication is performed in different ways, depending on the type U
:
T
and U
are C++ integral types, then the multiplication is checked for overflow; otherwise,T
and U
are the same type, and they support math::mul3(), then math::mul3() is used to compute the product; otherwise,T
by U
produces a result of type T
, then the binary multiplication operator is used to compute the product; otherwise,T
by U
results in another type T2
, then the multiplication is performed via the binary multiplication operator and the result is cast back to T
via piranha::safe_cast().If the type U
cannot be used as indicated above, then the method will be disabled.
x | the exponent. |
args | the reference piranha::symbol_fset. |
this
to the power of x
.std::invalid_argument | if the sizes of args and this differ. |
std::overflow_error | if both T and U are integral types and the exponentiation results in overflow. |
unspecified | any exception thrown by:
|
Definition at line 489 of file monomial.hpp.
|
inline |
Print.
This method will print to stream a human-readable representation of the monomial.
os | the target stream. |
args | the reference piranha::symbol_fset. |
std::invalid_argument | if the sizes of args and this differ. |
unspecified | any exception resulting from:
|
Definition at line 732 of file monomial.hpp.
|
inline |
Print in TeX mode.
This method will print to stream a TeX representation of the monomial.
os | the target stream. |
args | the reference piranha::symbol_fset. |
std::invalid_argument | if the sizes of args and this differ. |
unspecified | any exception resulting from:
|
Definition at line 771 of file monomial.hpp.
|
inlineinherited |
Move-add element at the end.
Move-add x
at the end of the internal container.
x | the element to be added to the internal container. |
unspecified | any exception thrown by piranha::small_vector::push_back(). |
Definition at line 308 of file array_key.hpp.
|
inlineinherited |
Copy-add element at the end.
Copy-add x
at the end of the internal container.
x | the element to be added to the internal container. |
unspecified | any exception thrown by piranha::small_vector::push_back(). |
Definition at line 320 of file array_key.hpp.
|
inlineinherited |
Resize the internal array container.
Equivalent to piranha::small_vector::resize().
new_size | the desired new size for the internal container. |
unspecified | any exception thrown by piranha::small_vector::resize(). |
Definition at line 266 of file array_key.hpp.
|
inlineinherited |
Size.
Definition at line 254 of file array_key.hpp.
|
inlineinherited |
Get size, begin and end iterator (const version).
Definition at line 525 of file array_key.hpp.
|
inlineinherited |
Get size, begin and end iterator.
Definition at line 534 of file array_key.hpp.
|
inline |
Substitution.
U
satisfies the following requirements:eval_type
,eval_type
is constructible from int
,eval_type
is multipliable in place,eval_type
satisfies piranha::is_returnable.This method will substitute the symbols at the positions specified in the keys of smap
with the mapped values. The return value is a vector containing one pair in which the first element is the result of the substitution (i.e., the product of the values of smap
raised to the corresponding exponents in the monomial), and the second element is the monomial after the substitution has been performed (i.e., with the exponents at the positions specified by the keys of smap
set to zero). If smap
is empty, the return value will be (1,this)
(i.e., the monomial is unchanged and the substitution yields 1).
For instance, given the monomial [2,3,4]
, the reference piranha::symbol_fset ["x","y","z"]
and the substitution map [(0,1),(2,-3)]
, then the return value will be a vector containing the single pair (81,[0,3,0])
.
smap | the map relating the positions of the symbols to be substituted to the values they will be substituted with. |
args | the reference piranha::symbol_fset. |
std::invalid_argument | if the last element of the substitution map is not smaller than the size of this , or if the sizes of this and args differ. |
unspecified | any exception thrown by:
|
Definition at line 915 of file monomial.hpp.
|
inlineinherited |
Trim.
This method is used in piranha::series::trim(). The input mask trim_mask
is a vector of boolean flags signalling (with nonzero values) elements of this
to be removed. The method will return a copy of this
in which the specified elements have been removed.
For instance, if this
contains the values [0,5,3,0,4]
and trim_mask
contains the values [false,false,false,true,false]
, then the output of this method will be the array of values [0,5,3,4]
(that is, the fourth element has been removed as indicated by a true
value in trim_mask
's fourth element).
trim_mask | a mask indicating which elements will be removed. |
args | the reference piranha::symbol_fset. |
this
.std::invalid_argument | if the sizes of this or trim_mask differ from the size of args . |
unspecified | any exception thrown by push_back(). |
Definition at line 409 of file array_key.hpp.
|
inlineinherited |
Identify symbols that can be trimmed.
This method is used in piranha::series::trim(). The input parameter trim_mask
is a vector of boolean flags (i.e., a mask) which signals which elements in args
are candidates for trimming: a nonzero value means that the symbol at the corresponding position is a candidate for trimming, while a zero value means that the symbol is not a candidate for trimming. This method will set to zero those values in trim_mask
for which the corresponding element in this
is nonzero.
For instance, if this
contains the values [0,5,3,0,4]
and trim_mask
originally contains the values [1,1,0,1,0]
, after a call to this method trim_mask
will contain [1,0,0,1,0]
(that is, the second element was set from 1 to 0 as the corresponding element in this
has a value of 5 and thus it must not be trimmed).
trim_mask | a mask signalling candidate elements for trimming. |
args | the reference piranha::symbol_fset. |
std::invalid_argument | if the sizes of this or trim_mask differ from the size of args . |
unspecified | any exception thrown by piranha::math::is_zero(). |
Definition at line 367 of file array_key.hpp.
|
inlineinherited |
Vector add.
Equivalent to calling piranha::small_vector::add() on the internal containers of this
and of the arguments.
retval | the piranha::array_key that will hold the result of the addition. |
other | the piranha::array_key that will be added to this . |
unspecified | any exception thrown by piranha::small_vector::add(). |
Definition at line 459 of file array_key.hpp.
|
inlineinherited |
Vector sub.
Equivalent to calling piranha::small_vector::sub() on the internal containers of this
and of the arguments.
retval | the piranha::array_key that will hold the result of the subtraction. |
other | the piranha::array_key that will be subtracted from this . |
unspecified | any exception thrown by piranha::small_vector::sub(). |
Definition at line 478 of file array_key.hpp.