1 #include <symengine/simplify.h>
2 #include <symengine/refine.h>
7 void SimplifyVisitor::bvisit(
const OneArgFunction &x)
9 auto farg = x.get_arg();
10 auto newarg = apply(farg);
11 result_ = x.create(newarg);
14 void SimplifyVisitor::bvisit(
const Pow &x)
16 auto e = apply(x.get_exp());
17 auto base = apply(x.get_base());
18 auto pair = simplify_pow(e, base);
19 result_ =
pow(pair.second, pair.first);
23 SimplifyVisitor::simplify_pow(
const RCP<const Basic> &e,
24 const RCP<const Basic> &b)
26 if (is_a<Csc>(*b) and
eq(*e, *minus_one)) {
29 one,
sin(down_cast<const OneArgFunction &>(*b).get_arg()));
30 }
else if (is_a<Sec>(*b) and
eq(*e, *minus_one)) {
33 one,
cos(down_cast<const OneArgFunction &>(*b).get_arg()));
34 }
else if (is_a<Cot>(*b) and
eq(*e, *minus_one)) {
37 one,
tan(down_cast<const OneArgFunction &>(*b).get_arg()));
43 void SimplifyVisitor::bvisit(
const Mul &x)
46 for (
const auto &p : x.get_dict()) {
47 auto base = apply(p.first);
48 auto newpair = simplify_pow(p.second, base);
54 RCP<const Basic> simplify(
const RCP<const Basic> &x,
55 const Assumptions *assumptions)
57 auto expr = refine(x, assumptions);
static void dict_add_term(map_basic_basic &d, const RCP< const Basic > &exp, const RCP< const Basic > &t)
Add terms to dict.
static RCP< const Basic > from_dict(const RCP< const Number > &coef, map_basic_basic &&d)
Create a Mul from a dict.
Main namespace for SymEngine package.
bool eq(const Basic &a, const Basic &b)
Checks equality for a and b
RCP< const Basic > tan(const RCP< const Basic > &arg)
Canonicalize Tan:
RCP< const Basic > cos(const RCP< const Basic > &arg)
Canonicalize Cos:
RCP< const Basic > sin(const RCP< const Basic > &arg)
Canonicalize Sin: