COPASI API  4.16.103
Public Types | Public Member Functions | Static Public Member Functions | Protected Attributes | Static Protected Attributes | List of all members
CNormalGeneralPower Class Reference

#include <CNormalGeneralPower.h>

Inheritance diagram for CNormalGeneralPower:
Inheritance graph
[legend]
Collaboration diagram for CNormalGeneralPower:
Collaboration graph
[legend]

Public Types

enum  Type { POWER = 0, MODULO, INVALID }
 

Public Member Functions

bool checkIsOne () const
 
 CNormalGeneralPower ()
 
 CNormalGeneralPower (const CNormalGeneralPower &src)
 
virtual CNormalBasecopy () const
 
CNormalFractiongetLeft ()
 
const CNormalFractiongetLeft () const
 
CNormalFractiongetRight ()
 
const CNormalFractiongetRight () const
 
Type getType () const
 
void multiply (const CNormalGeneralPower &generalPower)
 
bool operator< (const CNormalGeneralPower &rhs) const
 
CNormalGeneralPoweroperator= (const CNormalGeneralPower &src)
 
bool operator== (const CNormalGeneralPower &rhs) const
 
void setLeft (const CNormalFraction &left)
 
void setRight (const CNormalFraction &right)
 
void setType (Type type)
 
virtual bool simplify ()
 
virtual std::string toString () const
 
virtual ~CNormalGeneralPower ()
 
- Public Member Functions inherited from CNormalBase
virtual bool areEqual (const CNormalBase &rhs) const
 
virtual ~CNormalBase ()
 

Static Public Member Functions

static CNormalGeneralPowercreateUnitGeneralPower ()
 

Protected Attributes

CNormalFractionmpLeft
 
CNormalFractionmpRight
 
Type mType
 

Static Protected Attributes

static const char * SYMBOLS [] = {"^", "%"}
 

Detailed Description

Definition at line 28 of file CNormalGeneralPower.h.

Member Enumeration Documentation

Enumerator
POWER 
MODULO 
INVALID 

Definition at line 31 of file CNormalGeneralPower.h.

Constructor & Destructor Documentation

CNormalGeneralPower::CNormalGeneralPower ( )
CNormalGeneralPower::CNormalGeneralPower ( const CNormalGeneralPower src)

Definition at line 37 of file CNormalGeneralPower.cpp.

CNormalGeneralPower::~CNormalGeneralPower ( )
virtual

Definition at line 40 of file CNormalGeneralPower.cpp.

References mpLeft, and mpRight.

41 {
42  if (this->mpLeft != NULL) delete this->mpLeft;
43  if (this->mpRight != NULL) delete this->mpRight;
44 }
CNormalFraction * mpRight
CNormalFraction * mpLeft

Member Function Documentation

bool CNormalGeneralPower::checkIsOne ( ) const

Definition at line 265 of file CNormalGeneralPower.cpp.

References CNormalFraction::checkIsOne(), CNormalFraction::checkIsZero(), mpLeft, and mpRight.

Referenced by CNormalSum::checkIsOne(), multiply(), CNormalSum::simplify(), and CNormalProduct::simplify().

266  {
267  // the general power is one if either the exponent is 0.0
268  // or if the base is 1.0
269  return (this->mpLeft->checkIsOne() ||
270  this->mpRight->checkIsZero());
271  }
bool checkIsOne() const
bool checkIsZero() const
CNormalFraction * mpRight
CNormalFraction * mpLeft
CNormalBase * CNormalGeneralPower::copy ( ) const
virtual

Implements CNormalBase.

Definition at line 176 of file CNormalGeneralPower.cpp.

References CNormalGeneralPower().

177  {
178  return new CNormalGeneralPower(*this);
179  }
CNormalGeneralPower * CNormalGeneralPower::createUnitGeneralPower ( )
static

Returns a general power that is (1/1)^(1/1). It creates a new general power of type power and sets the left and right side to a unit fraction.

Definition at line 273 of file CNormalGeneralPower.cpp.

References CNormalGeneralPower(), CNormalFraction::createUnitFraction(), mpLeft, mpRight, POWER, and setType().

274 {
275  CNormalGeneralPower* pGeneralPower = new CNormalGeneralPower();
276  pGeneralPower->setType(CNormalGeneralPower::POWER);
277  delete pGeneralPower->mpLeft;
278  delete pGeneralPower->mpRight;
279  pGeneralPower->mpLeft = CNormalFraction::createUnitFraction();
280  pGeneralPower->mpRight = CNormalFraction::createUnitFraction();
281  return pGeneralPower;
282 }
static CNormalFraction * createUnitFraction()
CNormalFraction * mpRight
CNormalFraction * mpLeft
CNormalFraction & CNormalGeneralPower::getLeft ( )
const CNormalFraction & CNormalGeneralPower::getLeft ( ) const

Definition at line 97 of file CNormalGeneralPower.cpp.

References mpLeft.

98  {
99  return *this->mpLeft;
100  }
CNormalFraction * mpLeft
CNormalFraction & CNormalGeneralPower::getRight ( )

Definition at line 108 of file CNormalGeneralPower.cpp.

References mpRight.

Referenced by convertToCEvaluationNode(), normalize_variable_names(), operator=(), and CNormalSum::simplify().

109 {
110  return *this->mpRight;
111 }
CNormalFraction * mpRight
const CNormalFraction & CNormalGeneralPower::getRight ( ) const

Definition at line 113 of file CNormalGeneralPower.cpp.

References mpRight.

114  {
115  return *this->mpRight;
116  }
CNormalFraction * mpRight
CNormalGeneralPower::Type CNormalGeneralPower::getType ( ) const

Definition at line 124 of file CNormalGeneralPower.cpp.

References mType.

Referenced by convertToCEvaluationNode(), CNormalProduct::getDenominator(), operator=(), and CNormalProduct::setDenominatorsOne().

125  {
126  return this->mType;
127  }
void CNormalGeneralPower::multiply ( const CNormalGeneralPower generalPower)

Definition at line 181 of file CNormalGeneralPower.cpp.

References checkIsOne(), CNormalSum::checkIsOne(), CNormalGeneralPower(), CNormalFraction::createUnitFraction(), CNormalFraction::getDenominator(), CNormalFraction::getNumerator(), CNormalSum::getProducts(), mpLeft, mpRight, CNormalProduct::multiply(), POWER, setLeft(), CNormalFraction::setNumerator(), setRight(), and setType().

Referenced by CNormalProduct::getDenominator(), and CNormalProduct::simplify().

182 {
183  // make sure we don't multiply with a general power that is 1
184  // this would make the simplification process more complicated.
185  if (generalPower.checkIsOne()) return;
186  if (this->checkIsOne())
187  {
188  delete this->mpLeft;
189  delete this->mpRight;
190  this->mpLeft = new CNormalFraction(*generalPower.mpLeft);
191  this->mpRight = new CNormalFraction(*generalPower.mpRight);
192  }
193  else
194  {
195  // (A/B)^(C/D)*(E/F)^(G/H) -> // (A^(C/D)*E^(G/H))/(B^(C/D)*F^(G/H))
196  // new exponent is 1
198  // initialize the new base with 1
200  // the numerator of the new base is (A^(C/D)*E^(G/H))
201  CNormalProduct* pTmpProduct = (*pNewBase->getNumerator().getProducts().begin());
202  assert(pTmpProduct != NULL);
203  // A^(C/D)
204  if (!this->mpLeft->getNumerator().checkIsOne())
205  {
206  CNormalGeneralPower* pTmpPower = new CNormalGeneralPower();
208  CNormalFraction* pTmpFraction = new CNormalFraction(*pNewExponent);
209  pTmpFraction->setNumerator(this->mpLeft->getNumerator());
210  pTmpPower->setLeft(*pTmpFraction);
211  delete pTmpFraction;
212  pTmpPower->setRight(*this->mpRight);
213  pTmpProduct->multiply(*pTmpPower);
214  delete pTmpPower;
215  }
216  // E^(G/H)
217  if (!generalPower.mpLeft->getNumerator().checkIsOne())
218  {
219  CNormalGeneralPower* pTmpPower = new CNormalGeneralPower();
221  CNormalFraction* pTmpFraction = new CNormalFraction(*pNewExponent);
222  pTmpFraction->setNumerator(generalPower.mpLeft->getNumerator());
223  pTmpPower->setLeft(*pTmpFraction);
224  delete pTmpFraction;
225  pTmpPower->setRight(*generalPower.mpRight);
226  pTmpProduct->multiply(*pTmpPower);
227  delete pTmpPower;
228  }
229  // the denominator of the new base is (B^(C/D)*F^(G/H))
230  pTmpProduct = (*pNewBase->getDenominator().getProducts().begin());
231  assert(pTmpProduct != NULL);
232  // B^(C/D)
233  if (!this->mpLeft->getDenominator().checkIsOne())
234  {
235  CNormalGeneralPower* pTmpPower = new CNormalGeneralPower();
237  CNormalFraction* pTmpFraction = new CNormalFraction(*pNewExponent);
238  pTmpFraction->setNumerator(this->mpLeft->getDenominator());
239  pTmpPower->setLeft(*pTmpFraction);
240  delete pTmpFraction;
241  pTmpPower->setRight(*this->mpRight);
242  pTmpProduct->multiply(*pTmpPower);
243  delete pTmpPower;
244  }
245  // F^(G/H)
246  if (!generalPower.mpLeft->getDenominator().checkIsOne())
247  {
248  CNormalGeneralPower* pTmpPower = new CNormalGeneralPower();
250  CNormalFraction* pTmpFraction = new CNormalFraction(*pNewExponent);
251  pTmpFraction->setNumerator(generalPower.mpLeft->getDenominator());
252  pTmpPower->setLeft(*pTmpFraction);
253  delete pTmpFraction;
254  pTmpPower->setRight(*generalPower.mpRight);
255  pTmpProduct->multiply(*pTmpPower);
256  delete pTmpPower;
257  }
258  delete this->mpRight;
259  this->mpRight = pNewExponent;
260  delete this->mpLeft;
261  this->mpLeft = pNewBase;
262  }
263 }
CNormalSum & getNumerator()
static CNormalFraction * createUnitFraction()
CNormalSum & getDenominator()
void setRight(const CNormalFraction &right)
CNormalFraction * mpRight
bool setNumerator(const CNormalSum &numerator)
bool checkIsOne() const
Definition: CNormalSum.cpp:850
void setLeft(const CNormalFraction &left)
bool multiply(const C_FLOAT64 &number)
const std::set< CNormalProduct *, compareProducts > & getProducts() const
Definition: CNormalSum.cpp:416
CNormalFraction * mpLeft
bool CNormalGeneralPower::operator< ( const CNormalGeneralPower rhs) const

Definition at line 145 of file CNormalGeneralPower.cpp.

References mpLeft, mpRight, and mType.

146  {
147  bool result = false;
148  if (this->mType < rhs.mType)
149  {
150  result = true;
151  }
152  else if (this->mType == rhs.mType)
153  {
154  if ((*this->mpLeft) < (*rhs.mpLeft))
155  {
156  result = true;
157  }
158  else if ((*this->mpLeft) == (*rhs.mpLeft))
159  {
160  result = ((*this->mpRight) < (*rhs.mpRight));
161  }
162  }
163  return result;
164  }
CNormalFraction * mpRight
CNormalFraction * mpLeft
CNormalGeneralPower & CNormalGeneralPower::operator= ( const CNormalGeneralPower src)

Definition at line 46 of file CNormalGeneralPower.cpp.

References getLeft(), getRight(), getType(), mpLeft, mpRight, and mType.

47 {
48  if (this->mpLeft != NULL) delete this->mpLeft;
49  if (this->mpRight != NULL) delete this->mpRight;
50  this->mType = src.getType();
51  this->mpLeft = new CNormalFraction(src.getLeft());
52  this->mpRight = new CNormalFraction(src.getRight());
53  return *this;
54 }
CNormalFraction & getLeft()
CNormalFraction & getRight()
CNormalFraction * mpRight
CNormalFraction * mpLeft
bool CNormalGeneralPower::operator== ( const CNormalGeneralPower rhs) const

Definition at line 140 of file CNormalGeneralPower.cpp.

References mpLeft, mpRight, and mType.

141  {
142  return ((this->mType == rhs.mType) && (*this->mpLeft) == (*rhs.mpLeft) && (*this->mpRight) == (*rhs.mpRight));
143  }
CNormalFraction * mpRight
CNormalFraction * mpLeft
void CNormalGeneralPower::setLeft ( const CNormalFraction left)

Definition at line 102 of file CNormalGeneralPower.cpp.

References mpLeft.

Referenced by createGeneralPower(), CNormalProduct::getDenominator(), multiply(), CNormalSum::simplify(), and test_simplify::test_simplify_1().

103 {
104  if (this->mpLeft != NULL) delete this->mpLeft;
105  this->mpLeft = new CNormalFraction(left);
106 }
CNormalFraction * mpLeft
void CNormalGeneralPower::setRight ( const CNormalFraction right)

Definition at line 118 of file CNormalGeneralPower.cpp.

References mpRight.

Referenced by createGeneralPower(), CNormalProduct::getDenominator(), multiply(), and test_simplify::test_simplify_1().

119 {
120  if (this->mpRight != NULL) delete this->mpRight;
121  this->mpRight = new CNormalFraction(right);
122 }
CNormalFraction * mpRight
void CNormalGeneralPower::setType ( CNormalGeneralPower::Type  type)
bool CNormalGeneralPower::simplify ( )
virtual

Implements CNormalBase.

Definition at line 166 of file CNormalGeneralPower.cpp.

References mpLeft, mpRight, and CNormalFraction::simplify().

Referenced by test_simplify::test_simplify_1().

167 {
168  bool result = true;
169  if (this->mpLeft != NULL && this->mpRight != NULL)
170  {
171  result = (this->mpLeft->simplify() && this->mpRight->simplify());
172  }
173  return result;
174 }
virtual bool simplify()
CNormalFraction * mpRight
CNormalFraction * mpLeft
std::string CNormalGeneralPower::toString ( ) const
virtual

Implements CNormalBase.

Definition at line 56 of file CNormalGeneralPower.cpp.

References CNormalFraction::checkDenominatorOne(), CNormalSum::checkIsOne(), CNormalFraction::getDenominator(), CNormalFraction::getNumerator(), INVALID, mpLeft, mpRight, mType, and SYMBOLS.

Referenced by operator<<().

57  {
58  std::ostringstream s;
59  if (this->mType != INVALID)
60  {
61  // if the exponent is not 1, we have to add parentheses around the left
62  // side, otherwise we don't
63  // we check the numerator and the denominator separately because if they
64  // are both equal bot not 1, we want to display the actual fraction not the
65  // canceled fraction
66  if (!(this->mpRight->getNumerator().checkIsOne() && this->mpRight->getDenominator().checkIsOne()))
67  {
68  s << "(" << *this->mpLeft << ")";
69  s << CNormalGeneralPower::SYMBOLS[this->mType] << "(" << *this->mpRight << ")";
70  }
71  else
72  {
73  // we also have to addd parentesis if the denominator of the left
74  // side is 1
75  if (this->mpLeft->checkDenominatorOne())
76  {
77  s << "(" << *this->mpLeft << ")";
78  }
79  else
80  {
81  s << *this->mpLeft;
82  }
83  }
84  }
85  else
86  {
87  s << "(!!!INVALID GENERAL POWER!!!)";
88  }
89  return s.str();
90  }
static const char * SYMBOLS[]
CNormalSum & getNumerator()
CNormalSum & getDenominator()
CNormalFraction * mpRight
bool checkDenominatorOne() const
bool checkIsOne() const
Definition: CNormalSum.cpp:850
CNormalFraction * mpLeft

Member Data Documentation

CNormalFraction* CNormalGeneralPower::mpLeft
protected
CNormalFraction* CNormalGeneralPower::mpRight
protected
Type CNormalGeneralPower::mType
protected

Definition at line 39 of file CNormalGeneralPower.h.

Referenced by getType(), operator<(), operator=(), operator==(), setType(), and toString().

const char * CNormalGeneralPower::SYMBOLS = {"^", "%"}
staticprotected

Definition at line 43 of file CNormalGeneralPower.h.

Referenced by toString().


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