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

Public Member Functions

 RealVisitor (const Assumptions *assumptions)
 
void bvisit (const Basic &x)
 
void bvisit (const Symbol &x)
 
void bvisit (const Number &x)
 
void bvisit (const Set &x)
 
void bvisit (const Relational &x)
 
void bvisit (const Boolean &x)
 
void bvisit (const Constant &x)
 
void bvisit (const Add &x)
 
void bvisit (const Mul &x)
 
void bvisit (const Pow &x)
 
tribool apply (const Basic &b)
 

Private Member Functions

void check_power (const RCP< const Basic > &base, const RCP< const Basic > &exp)
 

Private Attributes

tribool is_real_
 
const Assumptionsassumptions_
 

Detailed Description

Definition at line 173 of file test_visitors.h.

Constructor & Destructor Documentation

◆ RealVisitor()

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

Definition at line 182 of file test_visitors.h.

182: assumptions_(assumptions){};

Member Function Documentation

◆ apply()

tribool SymEngine::RealVisitor::apply ( const Basic b)

Definition at line 546 of file test_visitors.cpp.

547{
548 b.accept(*this);
549 return is_real_;
550}

◆ bvisit() [1/10]

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

Definition at line 468 of file test_visitors.cpp.

469{
470 tribool b = tribool::tritrue;
471 for (const auto &arg : x.get_args()) {
472 arg->accept(*this);
473 b = andwk_tribool(b, is_real_);
474 if (is_indeterminate(b)) {
475 break;
476 }
477 }
478 is_real_ = b;
479}

◆ bvisit() [2/10]

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

Definition at line 183 of file test_visitors.h.

184 {
185 is_real_ = tribool::indeterminate;
186 };

◆ bvisit() [3/10]

void SymEngine::RealVisitor::bvisit ( const Boolean x)
inline

Definition at line 197 of file test_visitors.h.

198 {
199 is_real_ = tribool::trifalse;
200 };

◆ bvisit() [4/10]

void SymEngine::RealVisitor::bvisit ( const Constant x)

Definition at line 458 of file test_visitors.cpp.

459{
460 if (eq(x, *pi) or eq(x, *E) or eq(x, *EulerGamma) or eq(x, *Catalan)
461 or eq(x, *GoldenRatio)) {
462 is_real_ = tribool::tritrue;
463 } else {
464 is_real_ = tribool::indeterminate;
465 }
466}
bool eq(const Basic &a, const Basic &b)
Checks equality for a and b
Definition: basic-inl.h:21

◆ bvisit() [5/10]

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

Definition at line 512 of file test_visitors.cpp.

513{
514 unsigned non_real = 0;
515 tribool b = tribool_from_bool(!x.get_coef()->is_complex());
516 if (is_false(b)) {
517 non_real++;
518 }
519 for (const auto &p : x.get_dict()) {
520 this->check_power(p.first, p.second);
521 if (is_false(is_real_)) {
522 non_real++;
523 if (non_real > 1) {
524 is_real_ = tribool::indeterminate;
525 return;
526 }
527 }
528 b = andwk_tribool(b, is_real_);
529 if (is_indeterminate(b)) {
530 is_real_ = tribool::indeterminate;
531 return;
532 }
533 }
534 if (non_real == 1) {
535 is_real_ = tribool::trifalse;
536 } else {
537 is_real_ = b;
538 }
539}

◆ bvisit() [6/10]

void SymEngine::RealVisitor::bvisit ( const Number x)

Definition at line 449 of file test_visitors.cpp.

450{
451 if (is_a_Complex(x) or is_a<Infty>(x) or is_a<NaN>(x)) {
452 is_real_ = tribool::trifalse;
453 } else {
454 is_real_ = tribool::tritrue;
455 }
456}
bool is_a_Complex(const Basic &b)
Definition: complex.h:24

◆ bvisit() [7/10]

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

Definition at line 541 of file test_visitors.cpp.

542{
543 this->check_power(x.get_base(), x.get_exp());
544}

◆ bvisit() [8/10]

void SymEngine::RealVisitor::bvisit ( const Relational x)
inline

Definition at line 193 of file test_visitors.h.

194 {
195 is_real_ = tribool::trifalse;
196 };

◆ bvisit() [9/10]

void SymEngine::RealVisitor::bvisit ( const Set x)
inline

Definition at line 189 of file test_visitors.h.

190 {
191 is_real_ = tribool::trifalse;
192 };

◆ bvisit() [10/10]

void SymEngine::RealVisitor::bvisit ( const Symbol x)

Definition at line 440 of file test_visitors.cpp.

441{
442 if (assumptions_) {
443 is_real_ = assumptions_->is_real(x.rcp_from_this());
444 } else {
445 is_real_ = tribool::indeterminate;
446 }
447}

◆ check_power()

void SymEngine::RealVisitor::check_power ( const RCP< const Basic > &  base,
const RCP< const Basic > &  exp 
)
private

Definition at line 481 of file test_visitors.cpp.

483{
484 if (is_true(is_zero(*exp, assumptions_))) {
485 // exp == 0 => true
486 is_real_ = tribool::tritrue;
487 return;
488 }
489 base->accept(*this);
490 if (is_true(is_real_)) {
491 if (is_true(is_integer(*exp, assumptions_))) {
492 // base is real and exp is integer => true
493 is_real_ = tribool::tritrue;
494 } else if (is_true(is_nonnegative(*base, assumptions_))) {
495 // base >= 0 and exp is real => true
496 exp->accept(*this);
497 if (is_false(is_real_)) {
498 is_real_ = tribool::indeterminate;
499 }
500 } else {
501 is_real_ = tribool::indeterminate;
502 }
503 } else if (is_false(is_real_) && is_true(is_complex(*base, assumptions_))
504 && is_true(is_zero(*sub(exp, integer(1)), assumptions_))) {
505 // base is not real but complex and exp = 1 => false
506 is_real_ = tribool::trifalse;
507 } else {
508 is_real_ = tribool::indeterminate;
509 }
510}
RCP< const Basic > sub(const RCP< const Basic > &a, const RCP< const Basic > &b)
Substracts b from a.
Definition: add.cpp:495
RCP< const Basic > exp(const RCP< const Basic > &x)
Returns the natural exponential function E**x = pow(E, x)
Definition: pow.cpp:271
std::enable_if< std::is_integral< T >::value, RCP< constInteger > >::type integer(T i)
Definition: integer.h:197

Field Documentation

◆ assumptions_

const Assumptions* SymEngine::RealVisitor::assumptions_
private

Definition at line 177 of file test_visitors.h.

◆ is_real_

tribool SymEngine::RealVisitor::is_real_
private

Definition at line 176 of file test_visitors.h.


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