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

Public Member Functions

 PolynomialVisitor (const set_basic &variables)
 
void bvisit (const Basic &x)
 
void bvisit (const Number &x)
 
void bvisit (const Constant &x)
 
void bvisit (const Symbol &x)
 
void bvisit (const Add &x)
 
void bvisit (const Mul &x)
 
void bvisit (const Pow &x)
 
void bvisit (const Set &x)
 
void bvisit (const Relational &x)
 
bool apply (const Basic &b)
 

Private Member Functions

void check_power (const Basic &base, const Basic &exp)
 

Private Attributes

bool is_polynomial_ = true
 
bool variables_allowed_ = true
 
const set_basicvariables_
 

Detailed Description

Definition at line 320 of file test_visitors.h.

Constructor & Destructor Documentation

◆ PolynomialVisitor()

SymEngine::PolynomialVisitor::PolynomialVisitor ( const set_basic variables)
inline

Definition at line 330 of file test_visitors.h.

330: variables_(variables) {}

Member Function Documentation

◆ apply()

bool SymEngine::PolynomialVisitor::apply ( const Basic b)

Definition at line 806 of file test_visitors.cpp.

807{
808 b.accept(*this);
809 return is_polynomial_;
810}

◆ bvisit() [1/9]

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

Definition at line 741 of file test_visitors.cpp.

742{
743 for (const auto &arg : x.get_args()) {
744 arg->accept(*this);
745 if (!is_polynomial_)
746 return;
747 }
748}

◆ bvisit() [2/9]

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

Definition at line 727 of file test_visitors.cpp.

728{
729 auto old_allowed = variables_allowed_;
730 variables_allowed_ = false;
731 for (const auto &p : x.get_args()) {
732 p->accept(*this);
733 if (!is_polynomial_) {
734 variables_allowed_ = old_allowed;
735 return;
736 }
737 }
738 variables_allowed_ = old_allowed;
739}

◆ bvisit() [3/9]

void SymEngine::PolynomialVisitor::bvisit ( const Constant x)
inline

Definition at line 333 of file test_visitors.h.

333{};

◆ bvisit() [4/9]

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

Definition at line 750 of file test_visitors.cpp.

751{
752 for (const auto &p : x.get_dict()) {
753 this->check_power(*p.first, *p.second);
754 if (!is_polynomial_)
755 return;
756 }
757}

◆ bvisit() [5/9]

void SymEngine::PolynomialVisitor::bvisit ( const Number x)
inline

Definition at line 332 of file test_visitors.h.

332{};

◆ bvisit() [6/9]

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

Definition at line 784 of file test_visitors.cpp.

785{
786 check_power(*x.get_base(), *x.get_exp());
787}

◆ bvisit() [7/9]

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

Definition at line 342 of file test_visitors.h.

343 {
344 is_polynomial_ = false;
345 };

◆ bvisit() [8/9]

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

Definition at line 338 of file test_visitors.h.

339 {
340 is_polynomial_ = false;
341 };

◆ bvisit() [9/9]

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

Definition at line 789 of file test_visitors.cpp.

790{
791 if (variables_allowed_)
792 return;
793
794 if (variables_.empty()) { // All symbols are variables
795 is_polynomial_ = false;
796 } else {
797 for (const auto &elem : variables_) {
798 if (x.__eq__(*elem)) {
799 is_polynomial_ = false;
800 return;
801 }
802 }
803 }
804}
T empty(T... args)

◆ check_power()

void SymEngine::PolynomialVisitor::check_power ( const Basic base,
const Basic exp 
)
private

Definition at line 759 of file test_visitors.cpp.

760{
761 if (variables_allowed_) {
762 variables_allowed_ = false;
763 exp.accept(*this);
764 if (!is_polynomial_) {
765 variables_allowed_ = true;
766 return;
767 }
768 base.accept(*this);
769 variables_allowed_ = true;
770 if (!is_polynomial_) {
771 is_polynomial_ = true;
772 base.accept(*this);
773 is_polynomial_ = is_polynomial_ and is_a<Integer>(exp)
774 and down_cast<const Integer &>(exp).is_positive();
775 }
776 } else {
777 base.accept(*this);
778 if (!is_polynomial_)
779 return;
780 exp.accept(*this);
781 }
782}
RCP< const Basic > exp(const RCP< const Basic > &x)
Returns the natural exponential function E**x = pow(E, x)
Definition: pow.cpp:271

Field Documentation

◆ is_polynomial_

bool SymEngine::PolynomialVisitor::is_polynomial_ = true
private

Definition at line 323 of file test_visitors.h.

◆ variables_

const set_basic& SymEngine::PolynomialVisitor::variables_
private

Definition at line 325 of file test_visitors.h.

◆ variables_allowed_

bool SymEngine::PolynomialVisitor::variables_allowed_ = true
private

Definition at line 324 of file test_visitors.h.


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