COPASI API  4.16.103
Public Types | Public Member Functions | Protected Member Functions | Static Protected Member Functions | Private Attributes | Friends | List of all members
CFunctionAnalyzer::CValue Class Reference

#include <CFunctionAnalyzer.h>

Public Types

enum  Status {
  novalue = 0, negative = 1, zero = 2, positive = 4,
  invalid = 8, known = 16, unknown = 7
}
 

Public Member Functions

bool containsInvalid () const
 
bool containsNegative () const
 
bool containsPositive () const
 
bool containsZero () const
 
 CValue ()
 
 CValue (Status status)
 
 CValue (const double &d)
 
const StatusgetStatus () const
 
const double & getValue () const
 
CValue invert () const
 
bool isInvalid () const
 
bool isNegative () const
 
bool isPositive () const
 
bool isZero () const
 
CValue operator* (const CValue &rhs) const
 
CValue operator+ (const CValue &rhs) const
 
CValue operator- (const CValue &rhs) const
 
CValue operator/ (const CValue &rhs) const
 
bool operator== (const CValue &rhs) const
 
CValue operator^ (const CValue &rhs) const
 
void setStatus (const Status &status)
 
void setValue (const double &value)
 

Protected Member Functions

void Or (int s)
 
void Or (const CValue &v)
 
void orValue (const double &value)
 

Static Protected Member Functions

static CValue generalize (const double &d)
 

Private Attributes

double mDouble
 
Status mStatus
 

Friends

std::ostream & operator<< (std::ostream &os, const CValue &v)
 

Detailed Description

This is the base class of the arithmetics of the function analyzer. It describes possibilities for values. It basically consists of some flags that tell whether the value can be positive, can be negative, can be zero, or invalid, or if an actual exact numerical value is known. The usual arithmetic operators are defined for this class, the most important functions need to be implemented still. The missing functions are not critical since there is a save fallback: If you do not know how to perform a specific operation on CValues, the result should be (unknown|invalid).

Definition at line 55 of file CFunctionAnalyzer.h.

Member Enumeration Documentation

Constructor & Destructor Documentation

CFunctionAnalyzer::CValue::CValue ( )
inline
CFunctionAnalyzer::CValue::CValue ( Status  status)
inline

Definition at line 72 of file CFunctionAnalyzer.h.

CFunctionAnalyzer::CValue::CValue ( const double &  d)
inline

Member Function Documentation

bool CFunctionAnalyzer::CValue::containsInvalid ( ) const

Definition at line 385 of file CFunctionAnalyzer.cpp.

386 {
387  if (mStatus & invalid) return true;
388 
389  return false;
390 }
bool CFunctionAnalyzer::CValue::containsNegative ( ) const

Definition at line 369 of file CFunctionAnalyzer.cpp.

370 {
371  if (mStatus & negative) return true;
372 
373  if ((mStatus & known) && (mDouble < 0.0)) return true;
374 
375  return false;
376 }
bool CFunctionAnalyzer::CValue::containsPositive ( ) const

Definition at line 333 of file CFunctionAnalyzer.cpp.

334 {
335  if (mStatus & positive) return true;
336 
337  if ((mStatus & known) && (mDouble > 0.0)) return true;
338 
339  return false;
340 }
bool CFunctionAnalyzer::CValue::containsZero ( ) const

Definition at line 351 of file CFunctionAnalyzer.cpp.

352 {
353  if (mStatus & zero) return true;
354 
355  if ((mStatus & known) && (mDouble == 0.0)) return true;
356 
357  return false;
358 }
CFunctionAnalyzer::CValue CFunctionAnalyzer::CValue::generalize ( const double &  d)
staticprotected

convert a CValue with status "known" to a more general status.

Definition at line 300 of file CFunctionAnalyzer.cpp.

Referenced by operator*().

301 {
302  if (d == 0.0) return zero;
303  else if (d > 0.0) return positive;
304  else if (d < 0.0) return negative;
305  else return invalid;
306 }
const Status& CFunctionAnalyzer::CValue::getStatus ( ) const
inline

Definition at line 85 of file CFunctionAnalyzer.h.

References mStatus.

Referenced by operator*(), operator+(), operator/(), and operator^().

85 {return mStatus;};
const double& CFunctionAnalyzer::CValue::getValue ( ) const
inline

Definition at line 78 of file CFunctionAnalyzer.h.

References mDouble.

78 {return mDouble;};
CFunctionAnalyzer::CValue CFunctionAnalyzer::CValue::invert ( ) const

Definition at line 187 of file CFunctionAnalyzer.cpp.

References mDouble, mStatus, and Or().

Referenced by operator-().

bool CFunctionAnalyzer::CValue::isInvalid ( ) const

Definition at line 378 of file CFunctionAnalyzer.cpp.

379 {
380  if (mStatus == invalid) return true;
381 
382  return false;
383 }
bool CFunctionAnalyzer::CValue::isNegative ( ) const

Definition at line 360 of file CFunctionAnalyzer.cpp.

361 {
362  if (mStatus == negative) return true;
363 
364  if ((mStatus == known) && (mDouble < 0.0)) return true;
365 
366  return false;
367 }
bool CFunctionAnalyzer::CValue::isPositive ( ) const

Definition at line 324 of file CFunctionAnalyzer.cpp.

Referenced by CEvaluationNode::findTopMinus().

325 {
326  if (mStatus == positive) return true;
327 
328  if ((mStatus == known) && (mDouble > 0.0)) return true;
329 
330  return false;
331 }
bool CFunctionAnalyzer::CValue::isZero ( ) const

Definition at line 342 of file CFunctionAnalyzer.cpp.

343 {
344  if (mStatus == zero) return true;
345 
346  if ((mStatus == known) && (mDouble == 0.0)) return true;
347 
348  return false;
349 }
CFunctionAnalyzer::CValue CFunctionAnalyzer::CValue::operator* ( const CValue rhs) const

Definition at line 57 of file CFunctionAnalyzer.cpp.

References generalize(), getStatus(), invalid, known, mDouble, mStatus, negative, Or(), orValue(), positive, and zero.

58 {
59  CValue ret;
60 
61  //invalid
62  if ((this->getStatus() & invalid) || (rhs.getStatus() & invalid))
63  ret.Or(invalid);
64 
65  const CValue* v1, *v2;
66  v1 = this; v2 = &rhs;
67 
68  if ((v1->mStatus & negative) && (v2->mStatus & negative)) ret.Or(positive);
69 
70  if ((v1->mStatus & negative) && (v2->mStatus & zero)) ret.Or(zero);
71 
72  if ((v1->mStatus & negative) && (v2->mStatus & positive)) ret.Or(negative);
73 
74  if ((v1->mStatus & zero) && (v2->mStatus & negative)) ret.Or(zero);
75 
76  if ((v1->mStatus & zero) && (v2->mStatus & zero)) ret.Or(zero);
77 
78  if ((v1->mStatus & zero) && (v2->mStatus & positive)) ret.Or(zero);
79 
80  if ((v1->mStatus & positive) && (v2->mStatus & negative)) ret.Or(negative);
81 
82  if ((v1->mStatus & positive) && (v2->mStatus & zero)) ret.Or(zero);
83 
84  if ((v1->mStatus & positive) && (v2->mStatus & positive)) ret.Or(positive);
85 
86  //known values
87  if ((this->mStatus & known) && (rhs.mStatus & known))
88  ret.orValue(this->mDouble * rhs.mDouble);
89  else if (this->mStatus & known)
90  ret.Or(generalize(this->mDouble) * rhs);
91  else if (rhs.mStatus & known)
92  ret.Or(*this * generalize(rhs.mDouble));
93 
94 #ifdef C_DBG_FA
95  std::cout << " *: " << *this << " * " << rhs << " = " << ret << std::endl;
96 #endif
97 
98  return ret;
99 }
static CValue generalize(const double &d)
const Status & getStatus() const
CFunctionAnalyzer::CValue CFunctionAnalyzer::CValue::operator+ ( const CValue rhs) const

Definition at line 142 of file CFunctionAnalyzer.cpp.

References getStatus(), mDouble, mStatus, Or(), and orValue().

143 {
144  CValue ret;
145 
146  //invalid
147  if ((this->getStatus() & invalid) || (rhs.getStatus() & invalid))
148  ret.Or(invalid);
149 
150  //zero
151  if (this->getStatus() & zero)
152  ret.Or(rhs);
153 
154  if (rhs.getStatus() & zero)
155  ret.Or(*this);
156 
157  //symmetry
158  const CValue* v1, *v2;
159  v1 = this; v2 = &rhs;
160 
161  if ((v1->mStatus & negative) && (v2->mStatus & negative)) ret.Or(negative);
162 
163  if ((v1->mStatus & negative) && (v2->mStatus & positive)) ret.Or(negative | zero | positive);
164 
165  if ((v1->mStatus & positive) && (v2->mStatus & negative)) ret.Or(negative | zero | positive);
166 
167  if ((v1->mStatus & positive) && (v2->mStatus & positive)) ret.Or(positive);
168 
169  //known values
170  if ((this->mStatus & known) && (rhs.mStatus & known)) ret.orValue(this->mDouble + rhs.mDouble);
171 
172  if ((this->mStatus & negative) && (rhs.mStatus & known)) ret.Or(*this + generalize(rhs.mDouble));
173 
174  if ((this->mStatus & positive) && (rhs.mStatus & known)) ret.Or(*this + generalize(rhs.mDouble));
175 
176  if ((this->mStatus & known) && (rhs.mStatus & negative)) ret.Or(generalize(this->mDouble) + rhs);
177 
178  if ((this->mStatus & known) && (rhs.mStatus & positive)) ret.Or(generalize(this->mDouble) + rhs);
179 
180 #ifdef C_DBG_FA
181  std::cout << " +: " << *this << " + " << rhs << " = " << ret << std::endl;
182 #endif
183 
184  return ret;
185 }
static CValue generalize(const double &d)
const Status & getStatus() const
CFunctionAnalyzer::CValue CFunctionAnalyzer::CValue::operator- ( const CValue rhs) const

Definition at line 201 of file CFunctionAnalyzer.cpp.

References invert().

202 {
203  return *this + rhs.invert();
204 }
CFunctionAnalyzer::CValue CFunctionAnalyzer::CValue::operator/ ( const CValue rhs) const

Definition at line 101 of file CFunctionAnalyzer.cpp.

References getStatus(), mDouble, mStatus, Or(), and orValue().

102 {
103  CValue ret;
104 
105  //invalid
106  if ((this->getStatus() & invalid) || (rhs.getStatus() & invalid))
107  ret.Or(invalid);
108 
109  if (rhs.getStatus() & zero)
110  ret.Or(invalid);
111 
112  const CValue* v1, *v2;
113  v1 = this; v2 = &rhs;
114 
115  if ((v1->mStatus & negative) && (v2->mStatus & negative)) ret.Or(positive);
116 
117  if ((v1->mStatus & negative) && (v2->mStatus & positive)) ret.Or(negative);
118 
119  if ((v1->mStatus & zero) && (v2->mStatus & negative)) ret.Or(zero);
120 
121  if ((v1->mStatus & zero) && (v2->mStatus & positive)) ret.Or(zero);
122 
123  if ((v1->mStatus & positive) && (v2->mStatus & negative)) ret.Or(negative);
124 
125  if ((v1->mStatus & positive) && (v2->mStatus & positive)) ret.Or(positive);
126 
127  //known values
128  if ((this->mStatus & known) && (rhs.mStatus & known))
129  ret.orValue(this->mDouble / rhs.mDouble);
130  else if (this->mStatus & known)
131  ret.Or(generalize(this->mDouble) / rhs);
132  else if (rhs.mStatus & known)
133  ret.Or(*this / generalize(rhs.mDouble));
134 
135 #ifdef C_DBG_FA
136  std::cout << " /: " << *this << " / " << rhs << " = " << ret << std::endl;
137 #endif
138 
139  return ret;
140 }
static CValue generalize(const double &d)
const Status & getStatus() const
bool CFunctionAnalyzer::CValue::operator== ( const CValue rhs) const

Definition at line 392 of file CFunctionAnalyzer.cpp.

References mDouble, and mStatus.

393 {
394  if (mStatus != rhs.mStatus) return false;
395 
396  if ((mStatus & known) && (mDouble != rhs.mDouble)) return false;
397 
398  return true;
399 }
CFunctionAnalyzer::CValue CFunctionAnalyzer::CValue::operator^ ( const CValue rhs) const

Definition at line 206 of file CFunctionAnalyzer.cpp.

References getStatus(), mDouble, mStatus, Or(), and orValue().

207 {
208  CValue ret;
209 
210  //invalid
211  if ((this->getStatus() & invalid) || (rhs.getStatus() & invalid))
212  ret.Or(invalid);
213 
214  const CValue* v1, *v2;
215  v1 = this; v2 = &rhs;
216 
217  if ((v1->mStatus & negative) && (v2->mStatus & negative)) ret.Or(negative | positive | invalid);
218 
219  if ((v1->mStatus & negative) && (v2->mStatus & zero)) ret.orValue(1.0);
220 
221  if ((v1->mStatus & negative) && (v2->mStatus & positive)) ret.Or(negative | positive | invalid);
222 
223  if ((v1->mStatus & zero) && (v2->mStatus & negative)) ret.Or(invalid);
224 
225  if ((v1->mStatus & zero) && (v2->mStatus & zero)) ret.Or(invalid);
226 
227  if ((v1->mStatus & zero) && (v2->mStatus & positive)) ret.Or(zero);
228 
229  if ((v1->mStatus & positive) && (v2->mStatus & negative)) ret.Or(positive);
230 
231  if ((v1->mStatus & positive) && (v2->mStatus & zero)) ret.orValue(1.0);
232 
233  if ((v1->mStatus & positive) && (v2->mStatus & positive)) ret.Or(positive);
234 
235  //known values
236 
237  //base and exponent are known
238  if ((this->mStatus & known) && (rhs.mStatus & known)) ret.orValue(pow(this->mDouble, rhs.mDouble));
239 
240  //base is known
241  if ((this->mStatus & known) && ((rhs.mStatus & negative)
242  || (rhs.mStatus & zero)
243  || (rhs.mStatus & positive)))
244  {
245  if (this->mDouble == 1.0) // base is 1
246  ret.orValue(1.0);
247  else
248  ret.Or(generalize(this->mDouble) ^ rhs);
249  }
250 
251  //exponent is known
252  if (((this->mStatus & negative)
253  || (this->mStatus & zero)
254  || (this->mStatus & positive)) && (rhs.mStatus & known))
255  {
256  if ((rhs.mDouble == trunc(rhs.mDouble)) && (rhs.mDouble != 0.0)) //exponent is integer but not 0
257  {
258  if (rhs.mDouble / 2.0 == trunc(rhs.mDouble / 2.0)) //exponent is even
259  {
260  if (this->mStatus & negative) ret.Or(positive);
261 
262  if (this->mStatus & zero) ret.Or(zero);
263 
264  if (this->mStatus & positive) ret.Or(positive);
265  }
266  else //uneven
267  {
268  if (this->mStatus & negative) ret.Or(negative);
269 
270  if (this->mStatus & zero) ret.Or(zero);
271 
272  if (this->mStatus & positive) ret.Or(positive);
273  }
274  }
275  else
276  ret.Or(*this ^ generalize(rhs.mDouble));
277  }
278 
279 #ifdef C_DBG_FA
280  std::cout << " ^: " << *this << " ^ " << rhs << " = " << ret << std::endl;
281 #endif
282 
283  return ret;
284 }
static CValue generalize(const double &d)
const Status & getStatus() const
void CFunctionAnalyzer::CValue::Or ( int  s)
inlineprotected
void CFunctionAnalyzer::CValue::Or ( const CValue v)
protected

Definition at line 308 of file CFunctionAnalyzer.cpp.

References mDouble, mStatus, and Or().

309 {
310  if ((this->mStatus & known) && (v.mStatus & known) && (this->mDouble != v.mDouble))
311  {
312  //the two CValues have different known values
313  CValue tmp = generalize(this->mDouble);
314  tmp.Or(generalize(v.mDouble));
315  *this = tmp;
316  return;
317  }
318 
319  Or(v.mStatus);
320 
321  if (v.mStatus & known) this->mDouble = v.mDouble;
322 }
static CValue generalize(const double &d)
void CFunctionAnalyzer::CValue::orValue ( const double &  value)
inlineprotected

add the value to the set off possible values

Definition at line 125 of file CFunctionAnalyzer.h.

References CValue(), and Or().

Referenced by operator*(), operator+(), operator/(), and operator^().

125 {Or(CValue(value)); /* mDouble = value; Or(known);*/};
void CFunctionAnalyzer::CValue::setStatus ( const Status status)
inline

Definition at line 87 of file CFunctionAnalyzer.h.

References mStatus.

87 {mStatus = status;};
void CFunctionAnalyzer::CValue::setValue ( const double &  value)
inline

set value to be the only possible value

Definition at line 83 of file CFunctionAnalyzer.h.

References known, mDouble, and mStatus.

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  os,
const CValue v 
)
friend

insert operator

Definition at line 38 of file CFunctionAnalyzer.cpp.

39 {
40  os << "{";
41 
42  if (v.mStatus & CFunctionAnalyzer::CValue::negative) os << "- ";
43 
44  if (v.mStatus & CFunctionAnalyzer::CValue::zero) os << "0 ";
45 
46  if (v.mStatus & CFunctionAnalyzer::CValue::positive) os << "+ ";
47 
48  if (v.mStatus & CFunctionAnalyzer::CValue::invalid) os << "E ";
49 
50  if (v.mStatus & CFunctionAnalyzer::CValue::known) os << "v" << v.mDouble << " ";
51 
52  os << "}";
53 
54  return os;
55 }

Member Data Documentation

double CFunctionAnalyzer::CValue::mDouble
private
Status CFunctionAnalyzer::CValue::mStatus
private

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