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

Public Member Functions

 OptsCSEVisitor (umap_basic_basic &opt_subs_)
 
bool is_seen (const Basic &expr)
 
void bvisit (const Derivative &x)
 
void bvisit (const Subs &x)
 
void bvisit (const Add &x)
 
void bvisit (const Pow &x)
 
void bvisit (const Mul &x)
 
void bvisit (const Basic &x)
 

Data Fields

umap_basic_basicopt_subs
 
set_basic adds
 
set_basic muls
 
set_basic seen_subexp
 

Detailed Description

Definition at line 311 of file cse.cpp.

Constructor & Destructor Documentation

◆ OptsCSEVisitor()

SymEngine::OptsCSEVisitor::OptsCSEVisitor ( umap_basic_basic opt_subs_)
inline

Definition at line 318 of file cse.cpp.

318: opt_subs(opt_subs_) {}

Member Function Documentation

◆ bvisit() [1/6]

void SymEngine::OptsCSEVisitor::bvisit ( const Add x)
inline

Definition at line 331 of file cse.cpp.

332 {
333 if (not is_seen(x)) {
334 seen_subexp.insert(x.rcp_from_this());
335 for (const auto &p : x.get_args()) {
336 p->accept(*this);
337 }
338 adds.insert(x.rcp_from_this());
339 }
340 }
T insert(T... args)

◆ bvisit() [2/6]

void SymEngine::OptsCSEVisitor::bvisit ( const Basic x)
inline

Definition at line 382 of file cse.cpp.

383 {
384 auto v = x.get_args();
385 if (v.size() > 0 and not is_seen(x)) {
386 auto expr = x.rcp_from_this();
387 seen_subexp.insert(expr);
388 for (const auto &p : v) {
389 p->accept(*this);
390 }
391 }
392 }

◆ bvisit() [3/6]

void SymEngine::OptsCSEVisitor::bvisit ( const Derivative x)
inline

Definition at line 323 of file cse.cpp.

324 {
325 return;
326 }

◆ bvisit() [4/6]

void SymEngine::OptsCSEVisitor::bvisit ( const Mul x)
inline

Definition at line 360 of file cse.cpp.

361 {
362 if (not is_seen(x)) {
363 auto expr = x.rcp_from_this();
364 seen_subexp.insert(expr);
365 for (const auto &p : x.get_args()) {
366 p->accept(*this);
367 }
368 if (x.get_coef()->is_negative()) {
369 auto neg_expr = neg(x.rcp_from_this());
370 if (not is_a<Symbol>(*neg_expr)) {
371 opt_subs[expr]
372 = function_symbol("mul", {integer(-1), neg_expr});
373 seen_subexp.insert(neg_expr);
374 expr = neg_expr;
375 }
376 }
377 if (is_a<Mul>(*expr)) {
378 muls.insert(expr);
379 }
380 }
381 }
std::enable_if< std::is_integral< T >::value, RCP< constInteger > >::type integer(T i)
Definition: integer.h:200
RCP< const Basic > neg(const RCP< const Basic > &a)
Negation.
Definition: mul.cpp:443

◆ bvisit() [5/6]

void SymEngine::OptsCSEVisitor::bvisit ( const Pow x)
inline

Definition at line 341 of file cse.cpp.

342 {
343 if (not is_seen(x)) {
344 auto expr = x.rcp_from_this();
345 seen_subexp.insert(expr);
346 for (const auto &p : x.get_args()) {
347 p->accept(*this);
348 }
349 auto ex = x.get_exp();
350 if (is_a<Mul>(*ex)) {
351 ex = static_cast<const Mul &>(*ex).get_coef();
352 }
353 if (is_a_Number(*ex)
354 and static_cast<const Number &>(*ex).is_negative()) {
355 vec_basic v({pow(x.get_base(), neg(x.get_exp())), integer(-1)});
356 opt_subs[expr] = function_symbol("pow", v);
357 }
358 }
359 }
bool is_a_Number(const Basic &b)
Definition: number.h:130
T pow(T... args)

◆ bvisit() [6/6]

void SymEngine::OptsCSEVisitor::bvisit ( const Subs x)
inline

Definition at line 327 of file cse.cpp.

328 {
329 return;
330 }

◆ is_seen()

bool SymEngine::OptsCSEVisitor::is_seen ( const Basic expr)
inline

Definition at line 319 of file cse.cpp.

320 {
321 return (seen_subexp.find(expr.rcp_from_this()) != seen_subexp.end());
322 }
T end(T... args)
T find(T... args)

Field Documentation

◆ adds

set_basic SymEngine::OptsCSEVisitor::adds

Definition at line 315 of file cse.cpp.

◆ muls

set_basic SymEngine::OptsCSEVisitor::muls

Definition at line 316 of file cse.cpp.

◆ opt_subs

umap_basic_basic& SymEngine::OptsCSEVisitor::opt_subs

Definition at line 314 of file cse.cpp.

◆ seen_subexp

set_basic SymEngine::OptsCSEVisitor::seen_subexp

Definition at line 317 of file cse.cpp.


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