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

Public Member Functions

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

Private Member Functions

void error ()
 

Private Attributes

tribool is_positive_
 
const Assumptionsassumptions_
 

Detailed Description

Definition at line 35 of file test_visitors.h.

Constructor & Destructor Documentation

◆ PositiveVisitor()

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

Definition at line 44 of file test_visitors.h.

45 : assumptions_(assumptions){};

Member Function Documentation

◆ apply()

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

Definition at line 189 of file test_visitors.cpp.

190{
191 b.accept(*this);
192 return is_positive_;
193}

◆ bvisit() [1/8]

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

Definition at line 144 of file test_visitors.cpp.

145{
146 // True if all are positive
147 // False if all are negative
148 auto coef = x.get_coef();
149 auto dict = x.get_dict();
150
151 bool can_be_true = true;
152 bool can_be_false = true;
153 if (coef->is_positive()) {
154 can_be_false = false;
155 } else if (coef->is_negative()) {
156 can_be_true = false;
157 }
158 NegativeVisitor neg_visitor(assumptions_);
159 for (const auto &p : dict) {
160 if (not can_be_true and not can_be_false) {
161 is_positive_ = tribool::indeterminate;
162 return;
163 }
164 p.first->accept(*this);
165 if ((p.second->is_positive() and is_true(is_positive_))
166 or (p.second->is_negative()
167 and is_true(neg_visitor.apply(*p.first)))) {
168 // key * value is positive
169 can_be_false = false;
170 } else if ((p.second->is_negative() and is_true(is_positive_))
171 or (p.second->is_positive()
172 and is_true(neg_visitor.apply(*p.first)))) {
173 // key * value is negative
174 can_be_true = false;
175 } else {
176 can_be_true = false;
177 can_be_false = false;
178 }
179 }
180 if (can_be_true) {
181 is_positive_ = tribool::tritrue;
182 } else if (can_be_false) {
183 is_positive_ = tribool::trifalse;
184 } else {
185 is_positive_ = tribool::indeterminate;
186 }
187}

◆ bvisit() [2/8]

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

Definition at line 104 of file test_visitors.cpp.

105{
106 is_positive_ = tribool::indeterminate;
107}

◆ bvisit() [3/8]

void SymEngine::PositiveVisitor::bvisit ( const Boolean x)

Definition at line 119 of file test_visitors.cpp.

120{
121 error();
122}

◆ bvisit() [4/8]

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

Definition at line 99 of file test_visitors.cpp.

100{
101 is_positive_ = tribool::tritrue;
102}

◆ bvisit() [5/8]

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

Definition at line 133 of file test_visitors.cpp.

134{
135 if (is_a_Complex(x)) {
136 is_positive_ = tribool::trifalse;
137 } else if (bool(x.is_positive())) {
138 is_positive_ = tribool::tritrue;
139 } else {
140 is_positive_ = tribool::trifalse;
141 }
142}
bool is_a_Complex(const Basic &b)
Definition: complex.h:24

◆ bvisit() [6/8]

void SymEngine::PositiveVisitor::bvisit ( const Relational x)

Definition at line 114 of file test_visitors.cpp.

115{
116 error();
117}

◆ bvisit() [7/8]

void SymEngine::PositiveVisitor::bvisit ( const Set x)

Definition at line 109 of file test_visitors.cpp.

110{
111 error();
112}

◆ bvisit() [8/8]

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

Definition at line 124 of file test_visitors.cpp.

125{
126 if (assumptions_) {
127 is_positive_ = assumptions_->is_positive(x.rcp_from_this());
128 } else {
129 is_positive_ = tribool::indeterminate;
130 }
131}

◆ error()

void SymEngine::PositiveVisitor::error ( )
private

Definition at line 94 of file test_visitors.cpp.

95{
96 throw SymEngineException("Only numeric types allowed for is_positive");
97}

Field Documentation

◆ assumptions_

const Assumptions* SymEngine::PositiveVisitor::assumptions_
private

Definition at line 39 of file test_visitors.h.

◆ is_positive_

tribool SymEngine::PositiveVisitor::is_positive_
private

Definition at line 38 of file test_visitors.h.


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