2 #include <symengine/polys/basic_conversions.h>
7 umap_basic_num _find_gens_poly_pow(
const RCP<const Basic> &x,
8 const RCP<const Basic> &base);
26 void add_to_gen_set(
const RCP<const Basic> &base,
27 const RCP<const Number> &
exp)
29 auto it = gen_set.
find(base);
30 if (it == gen_set.
end()) {
35 if (is_a<const Rational>(*
exp)) {
36 RCP<const Integer> den
37 = down_cast<const Rational &>(*exp).get_den();
38 if (is_a<const Rational>(*it->second))
42 *down_cast<const Rational &>(*it->second).get_den()));
44 gen_set[base] =
divnum(one, den);
48 void bvisit(
const Pow &x)
50 if (is_a<const Integer>(*x.
get_exp())) {
51 if (down_cast<const Integer &>(*x.
get_exp()).is_positive()) {
54 add_to_gen_set(pow(x.
get_base(), minus_one), one);
57 }
else if (is_a<const Rational>(*x.
get_exp())) {
59 RCP<const Basic> base = x.
get_base();
61 = rcp_static_cast<const Rational>(x.
get_exp());
63 base = pow(base, minus_one);
64 add_to_gen_set(base,
divnum(one, r->get_den()));
69 for (
auto it : pow_pairs)
70 add_to_gen_set(pow(x.
get_base(), it.first), it.second);
74 void bvisit(
const Add &x)
76 for (
auto it : x.get_dict())
77 it.first->accept(*
this);
80 void bvisit(
const Mul &x)
82 for (
auto it : x.get_dict())
83 it.first->accept(*
this);
86 void bvisit(
const Number &x)
91 void bvisit(
const Basic &x)
104 RCP<const Basic> the_base;
114 void bvisit(
const Add &x)
119 for (
auto it : x.get_dict()) {
120 RCP<const Number> mulx = one, divx = one;
122 if (it.second->is_negative())
125 if (is_a<const Rational>(*it.second))
126 divx = down_cast<const Rational &>(*it.second).get_den();
128 gen_set[
mul(mulx, it.first)] =
divnum(one, divx);
132 void bvisit(
const Mul &x)
136 RCP<const Number> mulx = one, divx = one;
138 if (x.get_coef()->is_negative())
141 if (is_a<const Rational>(*x.get_coef()))
142 divx = down_cast<const Rational &>(*x.get_coef()).get_den();
144 auto dict = x.get_dict();
148 void bvisit(
const Number &x)
159 void bvisit(
const Basic &x)
171 umap_basic_num _find_gens_poly_pow(
const RCP<const Basic> &x,
172 const RCP<const Basic> &base)
174 PolyGeneratorVisitorPow v;
175 return v.apply(*x, base);
The base class for representing addition in symbolic expressions.
const RCP< const Number > & get_coef() const
The lowest unit of symbolic representation.
RCP< const T2 > rcp_from_this_cast() const
Get RCP<T2> pointer to self (it will cast the pointer to T2)
RCP< T > rcp_from_this()
Get RCP<T> pointer to self (it will cast the pointer to T)
static RCP< const Basic > from_dict(const RCP< const Number > &coef, map_basic_basic &&d)
Create a Mul from a dict.
virtual bool is_positive() const =0
RCP< const Basic > get_exp() const
RCP< const Basic > get_base() const
Main namespace for SymEngine package.
bool is_a_Number(const Basic &b)
RCP< const Number > mulnum(const RCP< const Number > &self, const RCP< const Number > &other)
Multiply self and other
RCP< const Number > divnum(const RCP< const Number > &self, const RCP< const Number > &other)
Divide self and other
RCP< const Basic > exp(const RCP< const Basic > &x)
Returns the natural exponential function E**x = pow(E, x)
RCP< const Integer > lcm(const Integer &a, const Integer &b)
Least Common Multiple.
RCP< const Basic > mul(const RCP< const Basic > &a, const RCP< const Basic > &b)
Multiplication.