piranha  0.10
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Attributes | List of all members
piranha::monomial< T, S > Class Template Reference

Monomial class. More...

#include <piranha/monomial.hpp>

Inheritance diagram for piranha::monomial< T, S >:
Inheritance graph
[legend]
Collaboration diagram for piranha::monomial< T, S >:
Collaboration graph
[legend]

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.
 
monomialoperator= (const monomial &other)=default
 Copy assignment operator. More...
 
monomialoperator= (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_idxis_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, monomialpartial (const symbol_idx &p, const symbol_fset &args) const
 Partial derivative. More...
 
template<typename U = T, integrate_enabler< U > = 0>
std::pair< T, monomialintegrate (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_typeoperator[] (const size_type &i)
 Element access. More...
 
const value_typeoperator[] (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.
 

Detailed Description

template<typename T, typename S = std::integral_constant<std::size_t, 0u>>
class piranha::monomial< T, S >

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.

Type requirements

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:

Exception safety guarantee

Unless noted otherwise, this class provides the same exception safety guarantee as piranha::array_key.

Move semantics

Move semantics is equivalent to piranha::array_key's move semantics.

Definition at line 100 of file monomial.hpp.

Constructor & Destructor Documentation

◆ monomial() [1/3]

template<typename T , typename S = std::integral_constant<std::size_t, 0u>>
template<typename U , init_list_enabler< U > = 0>
piranha::monomial< T, S >::monomial ( std::initializer_list< U >  list)
inlineexplicit

Constructor from initializer list.

Note
This constructor is enabled only if the corresponding constructor in piranha::array_key is enabled.
Parameters
listinitializer list.
See also
piranha::array_key's constructor from initializer list.

Definition at line 137 of file monomial.hpp.

◆ monomial() [2/3]

template<typename T , typename S = std::integral_constant<std::size_t, 0u>>
template<typename Iterator , it_ctor_enabler< Iterator > = 0>
piranha::monomial< T, S >::monomial ( Iterator  begin,
Iterator  end 
)
inlineexplicit

Constructor from range.

Note
This constructor is enabled only if 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.

Parameters
beginbeginning of the range.
endend of the range.
Exceptions
unspecifiedany exception thrown by:

Definition at line 167 of file monomial.hpp.

◆ monomial() [3/3]

template<typename T , typename S = std::integral_constant<std::size_t, 0u>>
template<typename Iterator , it_ctor_enabler< Iterator > = 0>
piranha::monomial< T, S >::monomial ( Iterator  begin,
Iterator  end,
const symbol_fset s 
)
inlineexplicit

Constructor from range and symbol set.

Note
This constructor is enabled only if 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().

Parameters
beginbeginning of the range.
endend of the range.
sreference symbol set.
Exceptions
std::invalid_argumentif the final size of this and the size of s differ.
unspecifiedany exception thrown by:

Definition at line 194 of file monomial.hpp.

Member Function Documentation

◆ begin() [1/2]

iterator piranha::array_key< T, monomial< T, S > , S >::begin ( )
inlineinherited

Begin iterator.

Returns
iterator to the first element of the internal container.

Definition at line 222 of file array_key.hpp.

◆ begin() [2/2]

const_iterator piranha::array_key< T, monomial< T, S > , S >::begin ( ) const
inlineinherited

Begin const iterator.

Returns
const iterator to the first element of the internal container.

Definition at line 238 of file array_key.hpp.

◆ degree() [1/2]

template<typename T , typename S = std::integral_constant<std::size_t, 0u>>
template<typename U = T>
degree_type<U> piranha::monomial< T, S >::degree ( const symbol_fset args) const
inline

Degree.

Note
This method is enabled only if:

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.

Parameters
argsreference piranha::symbol_fset.
Returns
the degree of the monomial.
Exceptions
std::invalid_argumentif the sizes of args and this differ.
std::overflow_errorif the exponent type is a C++ integral type and the computation of the degree overflows.
unspecifiedany exception thrown by the invoked constructor or arithmetic operators.

Definition at line 313 of file monomial.hpp.

◆ degree() [2/2]

template<typename T , typename S = std::integral_constant<std::size_t, 0u>>
template<typename U = T>
degree_type<U> piranha::monomial< T, S >::degree ( const symbol_idx_fset p,
const symbol_fset args 
) const
inline

Partial degree.

Note
This method is enabled only if:

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.

Parameters
ppositions of the symbols to be considered.
argsreference piranha::symbol_fset.
Returns
the partial degree of the monomial.
Exceptions
std::invalid_argumentif 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_errorif the exponent type is a C++ integral type and the computation of the degree overflows.
unspecifiedany exception thrown by the invoked constructor or arithmetic operators.

Definition at line 357 of file monomial.hpp.

◆ end() [1/2]

iterator piranha::array_key< T, monomial< T, S > , S >::end ( )
inlineinherited

End iterator.

Returns
iterator one past the last element of the internal container.

Definition at line 230 of file array_key.hpp.

◆ end() [2/2]

const_iterator piranha::array_key< T, monomial< T, S > , S >::end ( ) const
inlineinherited

End const iterator.

Returns
const iterator one past the last element of the internal container.

Definition at line 246 of file array_key.hpp.

◆ evaluate()

template<typename T , typename S = std::integral_constant<std::size_t, 0u>>
template<typename U >
eval_type<U> piranha::monomial< T, S >::evaluate ( const std::vector< U > &  values,
const symbol_fset args 
) const
inline

Evaluation.

Note
This method is available only if U satisfies the following requirements:
  • it can be used in piranha::math::pow() with the monomial exponents as powers, yielding a type 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.

Parameters
valuesthe values will be used for the evaluation.
argsthe reference piranha::symbol_fset.
Returns
the result of evaluating this with the values provided in values.
Exceptions
std::invalid_argumentif the sizes of values and args differ, or if the sizes of this and args differ.
unspecifiedany exception thrown by:
  • the construction of the return type,
  • math::pow() or the in-place multiplication operator of the return type.

Definition at line 846 of file monomial.hpp.

◆ hash()

std::size_t piranha::array_key< T, monomial< T, S > , S >::hash ( ) const
inlineinherited

Hash value.

Returns
hash value of the key, computed via piranha::small_vector::hash().
Exceptions
unspecifiedany exception thrown by piranha::small_vector::hash().

Definition at line 296 of file array_key.hpp.

◆ integrate()

template<typename T , typename S = std::integral_constant<std::size_t, 0u>>
template<typename U = T, integrate_enabler< U > = 0>
std::pair<T, monomial> piranha::monomial< T, S >::integrate ( const std::string &  s,
const symbol_fset args 
) const
inline

Integration.

Note
This method is enabled only if the exponent type supports the pre-increment operator.

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.

Parameters
sthe symbol with respect to which the integration will be calculated.
argsthe reference piranha::symbol_fset.
Returns
the result of the integration.
Exceptions
std::invalid_argumentif the sizes of args and this differ, or if the exponent associated to s is -1.
std::overflow_errorif T is a C++ integral type and the integration leads to integer overflow.
unspecifiedany exception thrown by:

Definition at line 654 of file monomial.hpp.

◆ ipow_subs()

template<typename T , typename S = std::integral_constant<std::size_t, 0u>>
template<typename U >
std::vector<std::pair<ipow_subs_type<U>, monomial> > piranha::monomial< T, S >::ipow_subs ( const symbol_idx p,
const integer n,
const U &  x,
const symbol_fset args 
) const
inline

Substitution of integral power.

Note
This method is enabled only if:

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.

Parameters
pthe position of the symbol that will be substituted.
nthe integral power that will be substituted.
xthe quantity that will be substituted.
argsthe reference piranha::symbol_fset.
Returns
the result of substituting x for the n-th power of the symbol at the position p.
Exceptions
std::invalid_argumentis n is zero, or if the sizes of args and this differ.
unspecifiedany exception thrown by:

Definition at line 1044 of file monomial.hpp.

◆ is_compatible()

template<typename T , typename S = std::integral_constant<std::size_t, 0u>>
bool piranha::monomial< T, S >::is_compatible ( const symbol_fset args) const
inlinenoexcept

Compatibility check.

A monomial and a set of arguments are compatible if their sizes coincide.

Parameters
argsreference piranha::symbol_fset.
Returns
true if the size of this is equal to the size of args, false otherwise.

Definition at line 235 of file monomial.hpp.

◆ is_linear()

template<typename T , typename S = std::integral_constant<std::size_t, 0u>>
std::pair<bool, symbol_idx> piranha::monomial< T, S >::is_linear ( const symbol_fset args) const
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.

Parameters
argsthe reference piranha::symbol_fset.
Returns
a pair indicating if the monomial is linear.
Exceptions
std::invalid_argumentif the sizes of this and args differ.
unspecifiedany exception thrown by piranha::math::is_zero() or piranha::math::is_unitary().

Definition at line 421 of file monomial.hpp.

◆ is_unitary()

template<typename T , typename S = std::integral_constant<std::size_t, 0u>>
bool piranha::monomial< T, S >::is_unitary ( const symbol_fset args) const
inline

Check if the monomial is unitary.

A monomial is unitary if, for all its elements, piranha::math::is_zero() returns true.

Parameters
argsreference piranha::symbol_fset.
Returns
true if the monomial is unitary, false otherwise.
Exceptions
std::invalid_argumentif the sizes of args and this differ.
unspecifiedany exception thrown by piranha::math::is_zero().

Definition at line 260 of file monomial.hpp.

◆ is_zero()

template<typename T , typename S = std::integral_constant<std::size_t, 0u>>
bool piranha::monomial< T, S >::is_zero ( const symbol_fset ) const
inlinenoexcept

Zero check.

A monomial is never zero.

Returns
false.

Definition at line 245 of file monomial.hpp.

◆ ldegree() [1/2]

template<typename T , typename S = std::integral_constant<std::size_t, 0u>>
template<typename U = T>
degree_type<U> piranha::monomial< T, S >::ldegree ( const symbol_fset args) const
inline

Low degree (equivalent to the degree).

Parameters
argsreference piranha::symbol_fset.
Returns
the output of degree(const symbol_fset &args) const.
Exceptions
unspecifiedany exception thrown by degree(const symbol_fset &args) const.

Definition at line 389 of file monomial.hpp.

◆ ldegree() [2/2]

template<typename T , typename S = std::integral_constant<std::size_t, 0u>>
template<typename U = T>
degree_type<U> piranha::monomial< T, S >::ldegree ( const symbol_idx_fset p,
const symbol_fset args 
) const
inline

Partial low degree (equivalent to the partial degree).

Parameters
ppositions of the symbols to be considered.
argsreference piranha::symbol_fset.
Returns
the output of degree(const symbol_idx_fset &, const symbol_fset &) const.
Exceptions
unspecifiedany exception thrown by degree(const symbol_idx_fset &, const symbol_fset &) const.

Definition at line 403 of file monomial.hpp.

◆ merge_symbols()

monomial< T, S > piranha::array_key< T, monomial< T, S > , S >::merge_symbols ( const symbol_idx_fmap< symbol_fset > &  ins_map,
const symbol_fset args 
) const
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.

Parameters
ins_mapthe insertion map.
argsthe reference symbol set for this.
Returns
a Derived instance resulting from inserting into this zeroes at the positions specified by ins_map.
Exceptions
std::invalid_argumentin the following cases:
  • the size of this is different from the size of args,
  • the size of ins_map is zero,
  • the last index in ins_map is greater than the size of this.
unspecifiedany exception thrown by:

Definition at line 508 of file array_key.hpp.

◆ msgpack_convert()

template<typename T , typename S = std::integral_constant<std::size_t, 0u>>
template<typename U = monomial, msgpack_convert_enabler< U > = 0>
void piranha::monomial< T, S >::msgpack_convert ( const msgpack::object &  o,
msgpack_format  f,
const symbol_fset s 
)
inline

Deserialize from msgpack object.

Note
This method is activated only if the internal container type satisfies piranha::has_msgpack_convert.

This method will deserialize o into this using the format f. This method provides the basic exception safety guarantee.

Parameters
omsgpack object that will be deserialized.
fserialization format.
sthe reference piranha::symbol_fset.
Exceptions
std::invalid_argumentif the size of the deserialized array differs from the size of s.
unspecifiedany exception thrown by piranha::msgpack_convert().

Definition at line 1219 of file monomial.hpp.

◆ msgpack_pack()

template<typename T , typename S = std::integral_constant<std::size_t, 0u>>
template<typename Stream , msgpack_pack_enabler< Stream > = 0>
void piranha::monomial< T, S >::msgpack_pack ( msgpack::packer< Stream > &  packer,
msgpack_format  f,
const symbol_fset s 
) const
inline

Serialize in msgpack format.

Note
This method is enabled only if 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.

Parameters
packerthe target packer.
fthe serialization format.
sthe reference piranha::symbol_fset.
Exceptions
std::invalid_argumentif the sizes of s and this differ.
unspecifiedany exception thrown by piranha::msgpack_pack().

Definition at line 1192 of file monomial.hpp.

◆ multiply()

template<typename T , typename S = std::integral_constant<std::size_t, 0u>>
template<typename Cf , multiply_enabler< Cf > = 0>
static void piranha::monomial< T, S >::multiply ( std::array< term< Cf, monomial< T, S > >, multiply_arity > &  res,
const term< Cf, monomial< T, S > > &  t1,
const term< Cf, monomial< T, S > > &  t2,
const symbol_fset args 
)
inlinestatic

Multiply terms with a monomial key.

Note
This method is enabled only if the following conditions hold:

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.

Parameters
resthe return value.
t1the first argument.
t2the second argument.
argsthe reference piranha::symbol_fset.
Exceptions
std::invalid_argumentif the size of t1 differs from the size of args.
unspecifiedany exception thrown by piranha::array_key::vector_add(), or by piranha::math::mul3().

Definition at line 1116 of file monomial.hpp.

◆ operator!=()

bool piranha::array_key< T, monomial< T, S > , S >::operator!= ( const array_key< T, monomial< T, S >, S > &  other) const
inlineinherited

Inequality operator.

Parameters
otherthe comparison argument.
Returns
the negation of operator==().
Exceptions
unspecifiedany exception thrown by the equality operator.

Definition at line 344 of file array_key.hpp.

◆ operator<()

template<typename T , typename S = std::integral_constant<std::size_t, 0u>>
bool piranha::monomial< T, S >::operator< ( const monomial< T, S > &  other) const
inline

Comparison operator.

The two monomials will be compared lexicographically.

Parameters
othercomparison argument.
Returns
true if this is lexicographically less than other, false otherwise.
Exceptions
std::invalid_argumentif the sizes of this and other differ.
unspecifiedany exception thrown by std::lexicographical_compare().

Definition at line 1143 of file monomial.hpp.

◆ operator=() [1/2]

template<typename T , typename S = std::integral_constant<std::size_t, 0u>>
monomial& piranha::monomial< T, S >::operator= ( const monomial< T, S > &  other)
default

Copy assignment operator.

Parameters
otherthe assignment argument.
Returns
a reference to this.
Exceptions
unspecifiedany exception thrown by the assignment operator of the base class.

◆ operator=() [2/2]

template<typename T , typename S = std::integral_constant<std::size_t, 0u>>
monomial& piranha::monomial< T, S >::operator= ( monomial< T, S > &&  other)
default

Defaulted move assignment operator.

Parameters
otherthe assignment argument.
Returns
a reference to this.

◆ operator==()

bool piranha::array_key< T, monomial< T, S > , S >::operator== ( const array_key< T, monomial< T, S >, S > &  other) const
inlineinherited

Equality operator.

Parameters
otherthe comparison argument.
Returns
the result of piranha::small_vector::operator==().
Exceptions
unspecifiedany exception thrown by piranha::small_vector::operator==().

Definition at line 332 of file array_key.hpp.

◆ operator[]() [1/2]

value_type& piranha::array_key< T, monomial< T, S > , S >::operator[] ( const size_type i)
inlineinherited

Element access.

Parameters
ithe index of the element to be accessed.
Returns
reference to the element of the container at index i.

Definition at line 276 of file array_key.hpp.

◆ operator[]() [2/2]

const value_type& piranha::array_key< T, monomial< T, S > , S >::operator[] ( const size_type i) const
inlineinherited

Const element access.

Parameters
ithe index of the element to be accessed.
Returns
const reference to the element of the container at index i.

Definition at line 286 of file array_key.hpp.

◆ partial()

template<typename T , typename S = std::integral_constant<std::size_t, 0u>>
template<typename U = T, partial_enabler< U > = 0>
std::pair<T, monomial> piranha::monomial< T, S >::partial ( const symbol_idx p,
const symbol_fset args 
) const
inline

Partial derivative.

Note
This method is enabled only if the exponent type supports the pre-decrement operator.

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.

Parameters
pthe position of the symbol with respect to which the differentiation will be calculated.
argsthe reference piranha::symbol_fset.
Returns
the result of the differentiation.
Exceptions
std::invalid_argumentif the sizes of args and this differ.
std::overflow_errorif the decrement of the affected exponent results in overflow.
unspecifiedany exception thrown by:

Definition at line 566 of file monomial.hpp.

◆ pow()

template<typename T , typename S = std::integral_constant<std::size_t, 0u>>
template<typename U , pow_enabler< U > = 0>
monomial piranha::monomial< T, S >::pow ( const U &  x,
const symbol_fset args 
) const
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:

  • if T and U are C++ integral types, then the multiplication is checked for overflow; otherwise,
  • if T and U are the same type, and they support math::mul3(), then math::mul3() is used to compute the product; otherwise,
  • if the multiplication of T by U produces a result of type T, then the binary multiplication operator is used to compute the product; otherwise,
  • if the multiplication of 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.

Parameters
xthe exponent.
argsthe reference piranha::symbol_fset.
Returns
this to the power of x.
Exceptions
std::invalid_argumentif the sizes of args and this differ.
std::overflow_errorif both T and U are integral types and the exponentiation results in overflow.
unspecifiedany exception thrown by:

Definition at line 489 of file monomial.hpp.

◆ print()

template<typename T , typename S = std::integral_constant<std::size_t, 0u>>
void piranha::monomial< T, S >::print ( std::ostream &  os,
const symbol_fset args 
) const
inline

Print.

This method will print to stream a human-readable representation of the monomial.

Parameters
osthe target stream.
argsthe reference piranha::symbol_fset.
Exceptions
std::invalid_argumentif the sizes of args and this differ.
unspecifiedany exception resulting from:

Definition at line 732 of file monomial.hpp.

◆ print_tex()

template<typename T , typename S = std::integral_constant<std::size_t, 0u>>
void piranha::monomial< T, S >::print_tex ( std::ostream &  os,
const symbol_fset args 
) const
inline

Print in TeX mode.

This method will print to stream a TeX representation of the monomial.

Parameters
osthe target stream.
argsthe reference piranha::symbol_fset.
Exceptions
std::invalid_argumentif the sizes of args and this differ.
unspecifiedany exception resulting from:

Definition at line 771 of file monomial.hpp.

◆ push_back() [1/2]

void piranha::array_key< T, monomial< T, S > , S >::push_back ( value_type &&  x)
inlineinherited

Move-add element at the end.

Move-add x at the end of the internal container.

Parameters
xthe element to be added to the internal container.
Exceptions
unspecifiedany exception thrown by piranha::small_vector::push_back().

Definition at line 308 of file array_key.hpp.

◆ push_back() [2/2]

void piranha::array_key< T, monomial< T, S > , S >::push_back ( const value_type x)
inlineinherited

Copy-add element at the end.

Copy-add x at the end of the internal container.

Parameters
xthe element to be added to the internal container.
Exceptions
unspecifiedany exception thrown by piranha::small_vector::push_back().

Definition at line 320 of file array_key.hpp.

◆ resize()

void piranha::array_key< T, monomial< T, S > , S >::resize ( const size_type new_size)
inlineinherited

Resize the internal array container.

Equivalent to piranha::small_vector::resize().

Parameters
new_sizethe desired new size for the internal container.
Exceptions
unspecifiedany exception thrown by piranha::small_vector::resize().

Definition at line 266 of file array_key.hpp.

◆ size()

size_type piranha::array_key< T, monomial< T, S > , S >::size ( ) const
inlineinherited

Size.

Returns
number of elements stored within the container.

Definition at line 254 of file array_key.hpp.

◆ size_begin_end() [1/2]

auto piranha::array_key< T, monomial< T, S > , S >::size_begin_end ( ) const-> decltype(m_container.size_begin_end())
inlineinherited

Get size, begin and end iterator (const version).

Returns
the output of the piranha::small_vector::size_begin_end() method called on the internal piranha::small_vector container.

Definition at line 525 of file array_key.hpp.

◆ size_begin_end() [2/2]

auto piranha::array_key< T, monomial< T, S > , S >::size_begin_end ( ) -> decltype(m_container.size_begin_end())
inlineinherited

Get size, begin and end iterator.

Returns
the output of the piranha::small_vector::size_begin_end() method called on the internal piranha::small_vector container.

Definition at line 534 of file array_key.hpp.

◆ subs()

template<typename T , typename S = std::integral_constant<std::size_t, 0u>>
template<typename U >
std::vector<std::pair<subs_type<U>, monomial> > piranha::monomial< T, S >::subs ( const symbol_idx_fmap< U > &  smap,
const symbol_fset args 
) const
inline

Substitution.

Note
This method is available only if U satisfies the following requirements:
  • it can be used in piranha::math::pow() with the monomial exponents as powers, yielding a type 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]).

Parameters
smapthe map relating the positions of the symbols to be substituted to the values they will be substituted with.
argsthe reference piranha::symbol_fset.
Returns
the result of the substitution.
Exceptions
std::invalid_argumentif the last element of the substitution map is not smaller than the size of this, or if the sizes of this and args differ.
unspecifiedany exception thrown by:
  • the construction of the return value,
  • the construction of an exponent from zero,
  • the copy assignment of the exponent type,
  • piranha::math::pow() or the in-place multiplication operator of the return type,
  • memory errors in standard containers.

Definition at line 915 of file monomial.hpp.

◆ trim()

monomial< T, S > piranha::array_key< T, monomial< T, S > , S >::trim ( const std::vector< char > &  trim_mask,
const symbol_fset args 
) const
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).

Parameters
trim_maska mask indicating which elements will be removed.
argsthe reference piranha::symbol_fset.
Returns
a trimmed copy of this.
Exceptions
std::invalid_argumentif the sizes of this or trim_mask differ from the size of args.
unspecifiedany exception thrown by push_back().

Definition at line 409 of file array_key.hpp.

◆ trim_identify()

void piranha::array_key< T, monomial< T, S > , S >::trim_identify ( std::vector< char > &  trim_mask,
const symbol_fset args 
) const
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).

Parameters
trim_maska mask signalling candidate elements for trimming.
argsthe reference piranha::symbol_fset.
Exceptions
std::invalid_argumentif the sizes of this or trim_mask differ from the size of args.
unspecifiedany exception thrown by piranha::math::is_zero().

Definition at line 367 of file array_key.hpp.

◆ vector_add()

void piranha::array_key< T, monomial< T, S > , S >::vector_add ( array_key< T, monomial< T, S >, S > &  retval,
const array_key< T, monomial< T, S >, S > &  other 
) const
inlineinherited

Vector add.

Note
This method is enabled only if the call to piranha::small_vector::add() is well-formed.

Equivalent to calling piranha::small_vector::add() on the internal containers of this and of the arguments.

Parameters
retvalthe piranha::array_key that will hold the result of the addition.
otherthe piranha::array_key that will be added to this.
Exceptions
unspecifiedany exception thrown by piranha::small_vector::add().

Definition at line 459 of file array_key.hpp.

◆ vector_sub()

void piranha::array_key< T, monomial< T, S > , S >::vector_sub ( array_key< T, monomial< T, S >, S > &  retval,
const array_key< T, monomial< T, S >, S > &  other 
) const
inlineinherited

Vector sub.

Note
This method is enabled only if the call to piranha::small_vector::sub() is well-formed.

Equivalent to calling piranha::small_vector::sub() on the internal containers of this and of the arguments.

Parameters
retvalthe piranha::array_key that will hold the result of the subtraction.
otherthe piranha::array_key that will be subtracted from this.
Exceptions
unspecifiedany exception thrown by piranha::small_vector::sub().

Definition at line 478 of file array_key.hpp.


The documentation for this class was generated from the following file: