piranha
0.10
|
Kronecker monomial class. More...
#include <piranha/kronecker_monomial.hpp>
Public Types | |
using | value_type = T |
Alias for T . | |
using | size_type = typename ka::size_type |
Size type. More... | |
using | v_type = static_vector< T, 255u > |
Vector type used for temporary packing/unpacking. | |
Public Member Functions | |
kronecker_monomial () | |
Default constructor. More... | |
kronecker_monomial (const kronecker_monomial &)=default | |
Defaulted copy constructor. | |
kronecker_monomial (kronecker_monomial &&)=default | |
Defaulted move constructor. | |
template<typename U , container_ctor_enabler< U > = 0> | |
kronecker_monomial (const U &c) | |
Constructor from container. More... | |
template<typename U , init_list_ctor_enabler< U > = 0> | |
kronecker_monomial (std::initializer_list< U > list) | |
Constructor from initializer list. More... | |
template<typename Iterator , it_ctor_enabler< Iterator > = 0> | |
kronecker_monomial (Iterator begin, Iterator end) | |
Constructor from range. More... | |
template<typename Iterator , it_ctor_enabler< Iterator > = 0> | |
kronecker_monomial (Iterator begin, Iterator end, const symbol_fset &s) | |
Constructor from range and symbol set. More... | |
kronecker_monomial (const symbol_fset &) | |
Constructor from set of symbols. More... | |
kronecker_monomial (const kronecker_monomial &other, const symbol_fset &) | |
Converting constructor. More... | |
kronecker_monomial (const T &n) | |
Constructor from T . More... | |
~kronecker_monomial () | |
Destructor. | |
kronecker_monomial & | operator= (const kronecker_monomial &other)=default |
Copy assignment operator. More... | |
kronecker_monomial & | operator= (kronecker_monomial &&other)=default |
Defaulted move assignment operator. More... | |
void | set_int (const T &n) |
Set the internal integer instance. More... | |
T | get_int () const |
Get internal instance. More... | |
bool | is_compatible (const symbol_fset &args) const noexcept |
Compatibility check. More... | |
bool | is_zero (const symbol_fset &) const noexcept |
Zero check. More... | |
kronecker_monomial | merge_symbols (const symbol_idx_fmap< symbol_fset > &ins_map, const symbol_fset &args) const |
Merge symbols. More... | |
bool | is_unitary (const symbol_fset &) const |
Check if monomial is unitary. More... | |
degree_type | degree (const symbol_fset &args) const |
Degree. More... | |
degree_type | ldegree (const symbol_fset &args) const |
Low degree (equivalent to the degree). More... | |
degree_type | degree (const symbol_idx_fset &p, const symbol_fset &args) const |
Partial degree. More... | |
degree_type | ldegree (const symbol_idx_fset &p, const symbol_fset &args) const |
Partial low degree (equivalent to the partial degree). More... | |
std::size_t | hash () const |
Hash value. More... | |
bool | operator== (const kronecker_monomial &other) const |
Equality operator. More... | |
bool | operator!= (const kronecker_monomial &other) const |
Inequality operator. More... | |
std::pair< bool, symbol_idx > | is_linear (const symbol_fset &args) const |
Detect linear monomial. More... | |
template<typename U , pow_enabler< U > = 0> | |
kronecker_monomial | pow (const U &x, const symbol_fset &args) const |
Exponentiation. More... | |
v_type | unpack (const symbol_fset &args) const |
Unpack internal integer instance. 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... | |
std::pair< T, kronecker_monomial > | partial (const symbol_idx &p, const symbol_fset &args) const |
Partial derivative. More... | |
std::pair< T, kronecker_monomial > | integrate (const std::string &s, const symbol_fset &args) const |
Integration. 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 >, kronecker_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 >, kronecker_monomial > > | ipow_subs (const symbol_idx &p, const integer &n, const U &x, const symbol_fset &args) const |
Substitution of integral power. More... | |
void | trim_identify (std::vector< char > &trim_mask, const symbol_fset &args) const |
Identify symbols that can be trimmed. More... | |
kronecker_monomial | trim (const std::vector< char > &trim_mask, const symbol_fset &args) const |
Trim. More... | |
bool | operator< (const kronecker_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 = kronecker_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... | |
Static Public Member Functions | |
template<typename Cf , multiply_enabler< Cf > = 0> | |
static void | multiply (std::array< term< Cf, kronecker_monomial >, multiply_arity > &res, const term< Cf, kronecker_monomial > &t1, const term< Cf, kronecker_monomial > &t2, const symbol_fset &) |
Multiply terms with a Kronecker monomial key. More... | |
Static Public Attributes | |
static const std::size_t | multiply_arity = 1u |
Arity of the multiply() method. | |
Kronecker monomial class.
This class represents a multivariate monomial with integral exponents. The values of the exponents are packed in a signed integer using Kronecker substitution, using the facilities provided by piranha::kronecker_array.
This class satisfies the piranha::is_key, piranha::key_has_degree, piranha::key_has_ldegree and piranha::key_is_differentiable type traits.
T
must be suitable for use in piranha::kronecker_array. The default type for T
is the signed counterpart of std::size_t
.
Unless otherwise specified, this class provides the strong exception safety guarantee for all operations.
The move semantics of this class are equivalent to the move semantics of C++ signed integral types.
Definition at line 119 of file kronecker_monomial.hpp.
using piranha::kronecker_monomial< T >::size_type = typename ka::size_type |
Size type.
Used to represent the number of variables in the monomial. Equivalent to the size type of piranha::kronecker_array.
Definition at line 134 of file kronecker_monomial.hpp.
|
inline |
Default constructor.
After construction all exponents in the monomial will be zero.
Definition at line 147 of file kronecker_monomial.hpp.
|
inlineexplicit |
Constructor from container.
U
satisfies piranha::has_input_begin_end, and the value type of the iterator type of U
can be safely cast to T
.This constructor will build internally a vector of values from the input container c
, encode it and assign the result to the internal integer instance. The value type of the container is converted to T
using piranha::safe_cast().
c | the input container. |
unspecified | any exception thrown by kronecker_monomial::kronecker_monomial(Iterator, Iterator). |
Definition at line 188 of file kronecker_monomial.hpp.
|
inlineexplicit |
Constructor from initializer list.
U
can be safely cast to T
.list | the input initializer list. |
unspecified | any exception thrown by kronecker_monomial::kronecker_monomial(Iterator, Iterator). |
Definition at line 207 of file kronecker_monomial.hpp.
|
inlineexplicit |
Constructor from range.
Iterator
is an input iterator whose value type is safely convertible to T
.This constructor will build internally a vector of values from the input iterators, encode it and assign the result to the internal integer instance. The value type of the iterator is converted to T
using piranha::safe_cast().
begin | the beginning of the range. |
end | the end of the range. |
unspecified | any exception thrown by:
|
Definition at line 239 of file kronecker_monomial.hpp.
|
inlineexplicit |
Constructor from range and symbol set.
Iterator
is an input iterator whose value type is safely convertible to T
.This constructor is identical to the constructor from range. In addition, after construction it will also check that the distance between begin
and end
is equal to the size of s
.
begin | the beginning of the range. |
end | the end of the range. |
s | the reference piranha::symbol_fset. |
std::invalid_argument | if the distance between begin and end is different from the size of s . |
unspecified | any exception thrown by kronecker_monomial::kronecker_monomial(Iterator, Iterator) |
Definition at line 261 of file kronecker_monomial.hpp.
|
inlineexplicit |
Constructor from set of symbols.
After construction all exponents in the monomial will be zero.
Definition at line 276 of file kronecker_monomial.hpp.
|
inlineexplicit |
Converting constructor.
This constructor is for use when converting from one term type to another in piranha::series. It will set the internal integer instance to the same value of other
.
other | the construction argument. |
Definition at line 284 of file kronecker_monomial.hpp.
|
inlineexplicit |
Constructor from T
.
This constructor will initialise the internal integer instance to n
.
n | the value that will be used to construct the internal integer instance. |
Definition at line 292 of file kronecker_monomial.hpp.
|
inline |
Degree.
The type returned by this method is the type resulting from the addition of two instances of T
.
args | the reference piranha::symbol_fset. |
std::overflow_error | if the computation of the degree overflows. |
unspecified | any exception thrown by unpack(). |
Definition at line 432 of file kronecker_monomial.hpp.
|
inline |
Partial degree.
Partial degree of the monomial: only the symbols at the positions specified by p
are considered. The type returned by this method is the type resulting from the addition of two instances of T
.
p | the positions of the symbols to be considered in the calculation of the degree. |
args | the reference piranha::symbol_fset. |
p
.std::invalid_argument | if the last element of p , if existing, is not less than the size of args . |
std::overflow_error | if the computation of the degree overflows. |
unspecified | any exception thrown by unpack(). |
Definition at line 473 of file kronecker_monomial.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. |
unspecified | any exception thrown by:
|
Definition at line 858 of file kronecker_monomial.hpp.
|
inline |
Get internal instance.
Definition at line 327 of file kronecker_monomial.hpp.
|
inline |
Hash value.
std::size_t
. Definition at line 543 of file kronecker_monomial.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.
s | the symbol with respect to which the integration will be calculated. |
args | the reference piranha::symbol_fset. |
std::invalid_argument | if the exponent associated to s is -1. |
std::overflow_error | if the integration leads to integer overflow. |
unspecified | any exception thrown by: |
Definition at line 780 of file kronecker_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. |
unspecified | any exception thrown by:
|
Definition at line 1003 of file kronecker_monomial.hpp.
|
inlinenoexcept |
Compatibility check.
A monomial is considered incompatible with a piranha::symbol_fset if any of these conditions holds:
args
is zero and the internal integer is not zero,args
is equal to or larger than the size of the output of piranha::kronecker_array::get_limits(),Otherwise, the monomial is considered to be incompatible.
args | the reference piranha::symbol_fset. |
Definition at line 346 of file kronecker_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. |
unspecified | any exception thrown by unpack(). |
Definition at line 581 of file kronecker_monomial.hpp.
|
inline |
Check if monomial is unitary.
true
if all the exponents are zero, false
otherwise. Definition at line 409 of file kronecker_monomial.hpp.
|
inlinenoexcept |
Zero check.
A monomial is never zero.
false
. Definition at line 371 of file kronecker_monomial.hpp.
|
inline |
Low degree (equivalent to the degree).
args | the reference piranha::symbol_fset. |
unspecified | any exception thrown by degree(const symbol_fset &) const. |
Definition at line 453 of file kronecker_monomial.hpp.
|
inline |
Partial low degree (equivalent to the partial degree).
p | the positions of the symbols to be considered in the calculation of the degree. |
args | the reference piranha::symbol_fset. |
unspecified | any exception thrown by degree(const symbol_idx_fset &, const symbol_fset &) const. |
Definition at line 499 of file kronecker_monomial.hpp.
|
inline |
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::kronecker_monomial 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 . |
this
zeroes at the positions specified by ins_map
.std::invalid_argument | in the following cases:
|
unspecified | any exception thrown by: |
Definition at line 401 of file kronecker_monomial.hpp.
|
inline |
Deserialize from msgpack object.
T
and piranha::kronecker_monomial::v_type satisfy piranha::has_msgpack_convert.This method will deserialize o
into this
. In binary mode, no check is performed on the content of o
, and calling this method will result in undefined behaviour if o
does not contain a monomial serialized via msgpack_pack().
o | msgpack object that will be deserialized. |
f | serialization format. |
s | 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:
|
Definition at line 1151 of file kronecker_monomial.hpp.
|
inline |
Serialize in msgpack format.
Stream
satisfies piranha::is_msgpack_stream and both T
and piranha::kronecker_monomial::v_type satisfy piranha::has_msgpack_pack.This method will pack this
into packer
. The packed object is the internal integral instance in binary format, an array of exponents in portable format.
packer | the target packer. |
f | the serialization format. |
s | reference piranha::symbol_fset. |
unspecified | any exception thrown by unpack() or piranha::msgpack_pack(). |
Definition at line 1122 of file kronecker_monomial.hpp.
|
inlinestatic |
Multiply terms with a Kronecker monomial key.
Cf
satisfies piranha::has_mul3.Multiply t1
by t2
, storing the result in the only element of res
. This method offers the basic exception safety guarantee. If Cf
is an instance of piranha::mp_rational, then only the numerators of the coefficients will be multiplied.
Note that the key of the return value is generated directly from the addition of the values of the input keys. No check is performed for overflow of either the limits of the integral type or the limits of the Kronecker codification.
res | the return value. |
t1 | the first argument. |
t2 | the second argument. |
unspecified | any exception thrown by piranha::math::mul3(). |
Definition at line 530 of file kronecker_monomial.hpp.
|
inline |
Inequality operator.
other | the comparison argument. |
Definition at line 564 of file kronecker_monomial.hpp.
|
inline |
Comparison operator.
other | comparison argument. |
true
if the internal integral value of this
is less than the internal integral value of other
, false
otherwise. Definition at line 1089 of file kronecker_monomial.hpp.
|
default |
Copy assignment operator.
other | the assignment argument. |
this
.
|
default |
Defaulted move assignment operator.
other | the assignment argument. |
this
.
|
inline |
Equality operator.
other | the comparison argument. |
true
if the internal integral instance of this
is equal to the integral instance of other
, false
otherwise. Definition at line 554 of file kronecker_monomial.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,kronecker_monomial{args})
.
p | the position of the symbol with respect to which the differentiation will be calculated. |
args | the reference piranha::symbol_fset. |
std::overflow_error | if the computation of the derivative causes a negative overflow. |
unspecified | any exception thrown by: |
Definition at line 740 of file kronecker_monomial.hpp.
|
inline |
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
:
U
is a C++ integral type, then the multiplication is checked for overflow; 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 (e.g., because the multiplication of T
by U
is not available, or T2
does not support piranha::safe_cast()), then the method will be disabled.
x | the exponent. |
args | the reference piranha::symbol_fset. |
this
to the power of x
.std::overflow_error | if U is an integral type and the exponentiation causes overflow. |
unspecified | any exception thrown by:
|
Definition at line 635 of file kronecker_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. |
unspecified | any exception thrown by unpack() or by streaming instances of T . |
Definition at line 669 of file kronecker_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. |
unspecified | any exception thrown by unpack() or by streaming instances of T . |
Definition at line 697 of file kronecker_monomial.hpp.
|
inline |
Set the internal integer instance.
n | the value to which the internal integer instance will be set. |
Definition at line 319 of file kronecker_monomial.hpp.
|
inline |
Substitution.
U
satisfies the following requirements:subs_type
,subs_type
is constructible from int
,subs_type
is multipliable in place,subs_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 args . |
unspecified | any exception thrown by:
|
Definition at line 923 of file kronecker_monomial.hpp.
|
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) 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 element will be removed. |
args | the reference piranha::symbol_fset. |
this
.std::invalid_argument | if the size of trim_mask differs from the size of args . |
unspecified | any exception thrown by unpack() or piranha::static_vector::push_back(). |
Definition at line 1078 of file kronecker_monomial.hpp.
|
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 (i.e., a zero value means that the symbol at the corresponding position in args
is not a candidate for trimming, while a nonzero value means that the symbol is 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 must not be trimmed).
trim_mask | a mask signalling candidate elements for trimming. |
args | the reference piranha::symbol_fset. |
std::invalid_argument | if the size of trim_mask differs from the size of args . |
unspecified | any exception thrown by unpack(). |
Definition at line 1054 of file kronecker_monomial.hpp.
|
inline |
Unpack internal integer instance.
This method will decode the internal integral instance into a piranha::static_vector of size equal to the size of args
.
args | the reference piranha::symbol_fset. |
std::invalid_argument | if the size of args is larger than the maximum size of piranha::static_vector. |
unspecified | any exception thrown by piranha::kronecker_array::decode(). |
Definition at line 656 of file kronecker_monomial.hpp.