Loading...
Searching...
No Matches
SymEngine::SimplifyVisitor Class Reference
+ Inheritance diagram for SymEngine::SimplifyVisitor:
+ Collaboration diagram for SymEngine::SimplifyVisitor:

Public Member Functions

 SimplifyVisitor (const Assumptions *assumptions)
 
void bvisit (const Mul &x)
 
void bvisit (const Pow &x)
 
void bvisit (const OneArgFunction &x)
 
void bvisit (const Basic &x)
 
void bvisit (const Add &x)
 
void bvisit (const Mul &x)
 
void bvisit (const Pow &x)
 
void bvisit (const OneArgFunction &x)
 
template<class T >
void bvisit (const TwoArgBasic< T > &x)
 
void bvisit (const MultiArgFunction &x)
 
- Public Member Functions inherited from SymEngine::TransformVisitor
virtual RCP< const Basicapply (const RCP< const Basic > &x)
 
void bvisit (const Basic &x)
 
void bvisit (const Add &x)
 
void bvisit (const Mul &x)
 
void bvisit (const Pow &x)
 
void bvisit (const OneArgFunction &x)
 
template<class T >
void bvisit (const TwoArgBasic< T > &x)
 
void bvisit (const MultiArgFunction &x)
 

Private Member Functions

std::pair< RCP< const Basic >, RCP< const Basic > > simplify_pow (const RCP< const Basic > &e, const RCP< const Basic > &b)
 

Private Attributes

const Assumptionsassumptions_
 

Additional Inherited Members

- Protected Attributes inherited from SymEngine::TransformVisitor
RCP< const Basicresult_
 

Detailed Description

Definition at line 11 of file simplify.h.

Constructor & Destructor Documentation

◆ SimplifyVisitor()

SymEngine::SimplifyVisitor::SimplifyVisitor ( const Assumptions assumptions)
inline

Definition at line 22 of file simplify.h.

23 : BaseVisitor<SimplifyVisitor, TransformVisitor>(),
24 assumptions_(assumptions)
25 {
26 }

Member Function Documentation

◆ bvisit() [1/10]

void SymEngine::TransformVisitor::bvisit ( const Add x)

Definition at line 246 of file visitor.cpp.

154{
155 vec_basic newargs;
156 for (const auto &a : x.get_args()) {
157 newargs.push_back(apply(a));
158 }
159 result_ = add(newargs);
160}
RCP< const Basic > add(const RCP< const Basic > &a, const RCP< const Basic > &b)
Adds two objects (safely).
Definition: add.cpp:425
T push_back(T... args)

◆ bvisit() [2/10]

void SymEngine::TransformVisitor::bvisit ( const Basic x)

Definition at line 245 of file visitor.cpp.

149{
150 result_ = x.rcp_from_this();
151}

◆ bvisit() [3/10]

void SymEngine::TransformVisitor::bvisit ( const Mul x)

Definition at line 247 of file visitor.cpp.

163{
164 vec_basic newargs;
165 for (const auto &a : x.get_args()) {
166 newargs.push_back(apply(a));
167 }
168 result_ = mul(newargs);
169}
RCP< const Basic > mul(const RCP< const Basic > &a, const RCP< const Basic > &b)
Multiplication.
Definition: mul.cpp:352

◆ bvisit() [4/10]

void SymEngine::SimplifyVisitor::bvisit ( const Mul x)

Definition at line 43 of file simplify.cpp.

44{
45 map_basic_basic map;
46 for (const auto &p : x.get_dict()) {
47 auto base = apply(p.first);
48 auto newpair = simplify_pow(p.second, base);
49 Mul::dict_add_term(map, newpair.first, newpair.second);
50 }
51 result_ = Mul::from_dict(x.get_coef(), std::move(map));
52}
static void dict_add_term(map_basic_basic &d, const RCP< const Basic > &exp, const RCP< const Basic > &t)
Add terms to dict.
Definition: mul.cpp:150
static RCP< const Basic > from_dict(const RCP< const Number > &coef, map_basic_basic &&d)
Create a Mul from a dict.
Definition: mul.cpp:115
T move(T... args)

◆ bvisit() [5/10]

void SymEngine::TransformVisitor::bvisit ( const MultiArgFunction x)

Definition at line 263 of file visitor.cpp.

194{
195 auto fargs = x.get_args();
196 vec_basic newargs;
197 for (const auto &a : fargs) {
198 newargs.push_back(apply(a));
199 }
200 auto nbarg = x.create(newargs);
201 result_ = nbarg;
202}

◆ bvisit() [6/10]

void SymEngine::TransformVisitor::bvisit ( const OneArgFunction x)

Definition at line 249 of file visitor.cpp.

183{
184 auto farg = x.get_arg();
185 auto newarg = apply(farg);
186 if (eq(*newarg, *farg)) {
187 result_ = x.rcp_from_this();
188 } else {
189 result_ = x.create(newarg);
190 }
191}
bool eq(const Basic &a, const Basic &b)
Checks equality for a and b
Definition: basic-inl.h:21

◆ bvisit() [7/10]

void SymEngine::SimplifyVisitor::bvisit ( const OneArgFunction x)

Definition at line 7 of file simplify.cpp.

8{
9 auto farg = x.get_arg();
10 auto newarg = apply(farg);
11 result_ = x.create(newarg);
12}

◆ bvisit() [8/10]

void SymEngine::TransformVisitor::bvisit ( const Pow x)

Definition at line 248 of file visitor.cpp.

172{
173 auto base_ = x.get_base(), exp_ = x.get_exp();
174 auto newarg1 = apply(base_), newarg2 = apply(exp_);
175 if (base_ != newarg1 or exp_ != newarg2) {
176 result_ = pow(newarg1, newarg2);
177 } else {
178 result_ = x.rcp_from_this();
179 }
180}
T pow(T... args)

◆ bvisit() [9/10]

void SymEngine::SimplifyVisitor::bvisit ( const Pow x)

Definition at line 14 of file simplify.cpp.

15{
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);
20}

◆ bvisit() [10/10]

template<class T >
void SymEngine::TransformVisitor::bvisit ( const TwoArgBasic< T > &  x)
inline

Definition at line 252 of file visitor.h.

253 {
254 auto farg1 = x.get_arg1(), farg2 = x.get_arg2();
255 auto newarg1 = apply(farg1), newarg2 = apply(farg2);
256 if (farg1 != newarg1 or farg2 != newarg2) {
257 result_ = x.create(newarg1, newarg2);
258 } else {
259 result_ = x.rcp_from_this();
260 }
261 }

◆ simplify_pow()

std::pair< RCP< const Basic >, RCP< const Basic > > SymEngine::SimplifyVisitor::simplify_pow ( const RCP< const Basic > &  e,
const RCP< const Basic > &  b 
)
private

Definition at line 23 of file simplify.cpp.

25{
26 if (is_a<Csc>(*b) and eq(*e, *minus_one)) {
27 // csc(expr) ** -1 = sin(expr)
28 return std::make_pair(
29 one, sin(down_cast<const OneArgFunction &>(*b).get_arg()));
30 } else if (is_a<Sec>(*b) and eq(*e, *minus_one)) {
31 // sec(expr) ** -1 = cos(expr)
32 return std::make_pair(
33 one, cos(down_cast<const OneArgFunction &>(*b).get_arg()));
34 } else if (is_a<Cot>(*b) and eq(*e, *minus_one)) {
35 // cot(expr) ** -1 = tan(expr)
36 return std::make_pair(
37 one, tan(down_cast<const OneArgFunction &>(*b).get_arg()));
38 } else {
39 return std::make_pair(e, b);
40 }
41}
T make_pair(T... args)
RCP< const Basic > tan(const RCP< const Basic > &arg)
Canonicalize Tan:
Definition: functions.cpp:1007
RCP< const Basic > cos(const RCP< const Basic > &arg)
Canonicalize Cos:
Definition: functions.cpp:942
RCP< const Basic > sin(const RCP< const Basic > &arg)
Canonicalize Sin:
Definition: functions.cpp:874

Field Documentation

◆ assumptions_

const Assumptions* SymEngine::SimplifyVisitor::assumptions_
private

Definition at line 14 of file simplify.h.


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