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

Divisor class. More...

#include <piranha/divisor.hpp>

Public Types

using value_type = T
 Alias for T.
 
using container_type = hash_set< p_type, p_type_hasher >
 Underlying container type.
 
using size_type = typename container_type::size_type
 Size type. More...
 

Public Member Functions

 divisor ()=default
 Defaulted default constructor. More...
 
 divisor (const divisor &)=default
 Defaulted copy constructor.
 
 divisor (divisor &&)=default
 Defaulted move constructor.
 
 divisor (const divisor &other, const symbol_fset &args)
 Converting constructor. More...
 
 divisor (const symbol_fset &)
 Constructor from piranha::symbol_fset. More...
 
 ~divisor ()
 Trivial destructor.
 
divisoroperator= (const divisor &other)=default
 Copy assignment operator. More...
 
divisoroperator= (divisor &&other)=default
 Move assignment operator. More...
 
template<typename It , typename Exponent , insert_enabler< It, Exponent > = 0>
void insert (It begin, It end, const Exponent &e)
 Create and insert a term from range and exponent. More...
 
size_type size () const
 Size. More...
 
const container_type_container () const
 Const access to the internal container. More...
 
container_type_container ()
 Mutable access to the internal container. More...
 
void clear ()
 Clear. More...
 
bool operator== (const divisor &other) const
 Equality operator. More...
 
bool operator!= (const divisor &other) const
 Inequality operator. More...
 
std::size_t hash () const
 Hash value. 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 &) const
 Check if divisor is unitary. More...
 
divisor merge_symbols (const symbol_idx_fmap< symbol_fset > &ins_map, const symbol_fset &args) const
 Merge symbols. More...
 
void print (std::ostream &os, const symbol_fset &args) const
 Print to stream. More...
 
void print_tex (std::ostream &os, const symbol_fset &args) const
 Print to stream in TeX mode. More...
 
template<typename U >
eval_type< U > evaluate (const std::vector< U > &values, const symbol_fset &args) const
 Evaluation. More...
 
void trim_identify (std::vector< char > &trim_mask, const symbol_fset &args) const
 Identify symbols that can be trimmed. More...
 
divisor trim (const std::vector< char > &trim_mask, const symbol_fset &args) const
 Trim. More...
 
std::pair< divisor, divisorsplit (const symbol_idx &p, const symbol_fset &args) const
 Split divisor. More...
 
template<typename Stream , msgpack_pack_enabler< Stream > = 0>
void msgpack_pack (msgpack::packer< Stream > &p, msgpack_format f, const symbol_fset &args) const
 Pack in msgpack format. More...
 
template<typename U = divisor, msgpack_convert_enabler< U > = 0>
void msgpack_convert (const msgpack::object &o, msgpack_format f, const symbol_fset &args)
 Convert from msgpack object. More...
 

Static Public Member Functions

template<typename Cf , multiply_enabler< Cf > = 0>
static void multiply (std::array< term< Cf, divisor >, multiply_arity > &res, const term< Cf, divisor > &t1, const term< Cf, divisor > &t2, const symbol_fset &args)
 Multiply terms with a divisor key. More...
 

Static Public Attributes

static const std::size_t multiply_arity = 1u
 Arity of the multiply() method.
 

Detailed Description

template<typename T>
class piranha::divisor< T >

Divisor class.

This class is used to represent keys of the form

\[ \prod_j\frac{1}{\left(a_{0,j}x_0+a_{1,j}x_1+\ldots+a_{n,j}x_n\right)^{e_j}}, \]

where \( a_{i,j} \) are integers, \( x_i \) are symbols, and \( e_j \) are positive integers. The type of \( a_{i,j} \) and \( e_j \) is T. The terms of the product are stored in a piranha::hash_set and they are guaranteed to be in a canonical form defined by the following properties:

Type requirements

T must be either a C++ signed integral type or an instance of piranha::mp_integer.

Exception safety guarantee

Unless otherwise specified, this class provides the strong exception safety guarantee for all operations.

Move semantics

Move semantics is equivalent to the move semantics of piranha::hash_set.

Definition at line 182 of file divisor.hpp.

Member Typedef Documentation

◆ size_type

template<typename T >
using piranha::divisor< T >::size_type = typename container_type::size_type

Size type.

It corresponds to the size type of the internal container.

Definition at line 334 of file divisor.hpp.

Constructor & Destructor Documentation

◆ divisor() [1/3]

template<typename T >
piranha::divisor< T >::divisor ( )
default

Defaulted default constructor.

This constructor will initialise an empty divisor.

◆ divisor() [2/3]

template<typename T >
piranha::divisor< T >::divisor ( const divisor< T > &  other,
const symbol_fset args 
)
inlineexplicit

Converting constructor.

This constructor is used in the generic constructor of piranha::series. It is equivalent to a copy constructor with extra checking.

Parameters
otherthe construction argument.
argsthe reference piranha::symbol_fset.
Exceptions
std::invalid_argumentif other is not compatible with args.
unspecifiedany exception thrown by the copy constructor.

Definition at line 355 of file divisor.hpp.

◆ divisor() [3/3]

template<typename T >
piranha::divisor< T >::divisor ( const symbol_fset )
inlineexplicit

Constructor from piranha::symbol_fset.

Equivalent to the default constructor.

Definition at line 366 of file divisor.hpp.

Member Function Documentation

◆ _container() [1/2]

template<typename T >
const container_type& piranha::divisor< T >::_container ( ) const
inline

Const access to the internal container.

Returns
a const reference to the internal container.

Definition at line 455 of file divisor.hpp.

◆ _container() [2/2]

template<typename T >
container_type& piranha::divisor< T >::_container ( )
inline

Mutable access to the internal container.

Returns
a reference to the internal container.

Definition at line 463 of file divisor.hpp.

◆ clear()

template<typename T >
void piranha::divisor< T >::clear ( )
inline

Clear.

This method will remove all terms from the divisor.

Definition at line 471 of file divisor.hpp.

◆ evaluate()

template<typename T >
template<typename U >
eval_type<U> piranha::divisor< T >::evaluate ( const std::vector< U > &  values,
const symbol_fset args 
) const
inline

Evaluation.

Note
This method is available only if U supports the arithmetic operations necessary to construct the return type.

The return value will be built via multiplications of the \( a_{i,j} \) by the input values, additions, divisions and exponentiations via piranha::math::pow(). If the divisor has no terms, 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 there exist an incompatibility between this, args or pmap.
unspecifiedany exception thrown by the construction of the return type.

Definition at line 761 of file divisor.hpp.

◆ hash()

template<typename T >
std::size_t piranha::divisor< T >::hash ( ) const
inline

Hash value.

The hash value is computed by combining the hash values of all terms. An empty divisor has a hash value of 0. Two equal divisors have the same hash value.

Returns
a hash value for the divisor.

Definition at line 517 of file divisor.hpp.

◆ insert()

template<typename T >
template<typename It , typename Exponent , insert_enabler< It, Exponent > = 0>
void piranha::divisor< T >::insert ( It  begin,
It  end,
const Exponent &  e 
)
inline

Create and insert a term from range and exponent.

Note
This method is enabled only if:

This method will construct and insert a term into the divisor. The elements in the range [begin,end) will be used to construct the \( a_{i,j} \) of the term, while e will be used to construct the exponent (after a call to piranha::safe_cast()). If no term with the same set of \( a_{i,j} \) exists, then a new term will be inserted; otherwise, e will be added to the exponent of the existing term.

This method provides the basic exception safety guarantee.

Parameters
beginstart of the range of \( a_{i,j} \).
endend of the range of \( a_{i,j} \).
eexponent.
Exceptions
std::invalid_argumentif the term to be inserted is not in canonical form, or if the insertion leads to an overflow in the value of an exponent.
std::overflow_errorif the insertion results in the container to be resized over an implementation-defined limit.
unspecifiedany exception thrown by:

Definition at line 420 of file divisor.hpp.

◆ is_compatible()

template<typename T >
bool piranha::divisor< T >::is_compatible ( const symbol_fset args) const
inlinenoexcept

Compatibility check.

An empty divisor is considered compatible with any set of symbols. Otherwise, a non-empty divisor is compatible if the number of variables in the terms is the same as the number of symbols in args.

Parameters
argsthe reference piranha::symbol_fset.
Returns
true if this is compatible with args, false otherwise.

Definition at line 546 of file divisor.hpp.

◆ is_unitary()

template<typename T >
bool piranha::divisor< T >::is_unitary ( const symbol_fset ) const
inline

Check if divisor is unitary.

Only an empty divisor is considered unitary.

Returns
true if this is empty, false otherwise.

Definition at line 566 of file divisor.hpp.

◆ is_zero()

template<typename T >
bool piranha::divisor< T >::is_zero ( const symbol_fset ) const
inlinenoexcept

Zero check.

A divisor can never be zero.

Returns
false.

Definition at line 556 of file divisor.hpp.

◆ merge_symbols()

template<typename T >
divisor piranha::divisor< T >::merge_symbols ( const symbol_idx_fmap< symbol_fset > &  ins_map,
const symbol_fset args 
) const
inline

Merge symbols.

This method will return a copy of this in which, for every factor of the divisor, 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.

Parameters
ins_mapthe insertion map.
argsthe reference symbol set for this.
Returns
a piranha::divisor resulting from inserting into this zeroes at the positions specified by ins_map.
Exceptions
std::invalid_argumentin the following cases:
  • the size of the factors 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 the factors of this.
unspecifiedany exception thrown by:

Definition at line 592 of file divisor.hpp.

◆ msgpack_convert()

template<typename T >
template<typename U = divisor, msgpack_convert_enabler< U > = 0>
void piranha::divisor< T >::msgpack_convert ( const msgpack::object &  o,
msgpack_format  f,
const symbol_fset args 
)
inline

Convert from msgpack object.

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

This method will convert the input msgpack object o into this, using the format f. The method provides the basic exception safety guarantee.

Parameters
othe input msgpack::object.
fthe desired piranha::msgpack_format.
argsthe reference piranha::symbol_fset.
Exceptions
std::invalid_argumentif the deserialized divisor fails internal consistency checks, or if it is not compatible with args.
unspecifiedany exception thrown by piranha::msgpack_convert().

Definition at line 1025 of file divisor.hpp.

◆ msgpack_pack()

template<typename T >
template<typename Stream , msgpack_pack_enabler< Stream > = 0>
void piranha::divisor< T >::msgpack_pack ( msgpack::packer< Stream > &  p,
msgpack_format  f,
const symbol_fset args 
) const
inline

Pack 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 in to p using the format f.

Parameters
pthe target msgpack::packer.
fthe desired piranha::msgpack_format.
argsthe reference piranha::symbol_fset.
Exceptions
std::invalid_argumentif args is not compatible with this.
unspecifiedany exception thrown by piranha::msgpack_pack().

Definition at line 1000 of file divisor.hpp.

◆ multiply()

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

Multiply terms with a divisor key.

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

Parameters
resthe return value.
t1the first argument.
t2the second argument.
argsthe reference piranha::symbol_fset.
Exceptions
std::invalid_argumentif the key of t1 and/or the key of t2 are incompatible with args, or if the multiplication of the keys results in an exponent exceeding the allowed range.
std::overflow_errorif the multiplication of the keys results in the container of the result key to be resized over an implementation-defined limit.
unspecifiedany exception thrown by:

Definition at line 826 of file divisor.hpp.

◆ operator!=()

template<typename T >
bool piranha::divisor< T >::operator!= ( const divisor< T > &  other) const
inline

Inequality operator.

Parameters
othercomparison argument.
Returns
the opposite of operator==().

Definition at line 506 of file divisor.hpp.

◆ operator=() [1/2]

template<typename T >
divisor& piranha::divisor< T >::operator= ( const divisor< T > &  other)
default

Copy assignment operator.

Parameters
otherthe assignment argument.
Returns
a reference to this.
Exceptions
unspecifiedany exception thrown by the assignment operator of piranha::hash_set.

◆ operator=() [2/2]

template<typename T >
divisor& piranha::divisor< T >::operator= ( divisor< T > &&  other)
default

Move assignment operator.

Parameters
otherthe assignment argument.
Returns
a reference to this.

◆ operator==()

template<typename T >
bool piranha::divisor< T >::operator== ( const divisor< T > &  other) const
inline

Equality operator.

Two divisors are considered equal if:

  • they have the same number of terms, and
  • for each term in the first divisor there exist an identical term in the second divisor.
Parameters
othercomparison argument.
Returns
true if this is equal to other, false otherwise.

Definition at line 486 of file divisor.hpp.

◆ print()

template<typename T >
void piranha::divisor< T >::print ( std::ostream &  os,
const symbol_fset args 
) const
inline

Print to stream.

This method will print to the stream os a text representation of this.

Parameters
osthe target stream.
argsthe reference symbol set for this.
Exceptions
std::invalid_argumentif the number of variables in the terms of this is different from the size of args.
unspecifiedany exception thrown by printing to os piranha::divisor::value_type, strings or characters.

Definition at line 619 of file divisor.hpp.

◆ print_tex()

template<typename T >
void piranha::divisor< T >::print_tex ( std::ostream &  os,
const symbol_fset args 
) const
inline

Print to stream in TeX mode.

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

Parameters
osthe target stream.
argsthe reference symbol set for this.
Exceptions
std::invalid_argumentif the number of variables in the terms of this is different from the size of args.
unspecifiedany exception thrown by printing to os piranha::divisor::value_type, strings or characters.

Definition at line 681 of file divisor.hpp.

◆ size()

template<typename T >
size_type piranha::divisor< T >::size ( ) const
inline

Size.

Returns
the size of the internal container - that is, the number of terms in the product.

Definition at line 447 of file divisor.hpp.

◆ split()

template<typename T >
std::pair<divisor, divisor> piranha::divisor< T >::split ( const symbol_idx p,
const symbol_fset args 
) const
inline

Split divisor.

This method will split this into two parts: the first one will contain the terms of the divisor whose \( a_{i,j} \) values at the position p are not zero, the second one the remaining terms.

Parameters
pthe position of the splitting symbol.
argsthe reference piranha::symbol_fset.
Returns
the original divisor split into two parts.
Exceptions
std::invalid_argumentif args is not compatible with this or p, or p is not less than the size of args.
unspecifiedany exception thrown by:

Definition at line 940 of file divisor.hpp.

◆ trim()

template<typename T >
divisor piranha::divisor< T >::trim ( const std::vector< char > &  trim_mask,
const symbol_fset args 
) const
inline

Trim.

This method is used in piranha::series::trim(). The input mask trim_mask is a vector of boolean flags signalling (with nonzero values) symbols to be removed. The method will return a copy of this in which the specified elements have been removed from each term of the divisor.

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 this is not compatible with args or if the sizes of args and trim_mask differ.
unspecifiedany exception thrown by piranha::small_vector::push_back() or piranha::divisor::insert().

Definition at line 900 of file divisor.hpp.

◆ trim_identify()

template<typename T >
void piranha::divisor< T >::trim_identify ( std::vector< char > &  trim_mask,
const symbol_fset args 
) const
inline

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. The method will set to zero in trim_mask those symbols whose \( a_{i,j} \) in this are not all zeroes.

Parameters
trim_maska mask signalling candidate elements for trimming.
argsthe reference piranha::symbol_fset.
Exceptions
std::invalid_argumentif this is not compatible with args, or if the sizes of trim_mask and args differ.
unspecifiedany exception thrown by piranha::math::is_zero().

Definition at line 863 of file divisor.hpp.


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