COPASI API  4.16.103
Public Member Functions | Static Public Member Functions | Private Attributes | Friends | List of all members
CNormalProduct Class Reference

#include <CNormalProduct.h>

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

Public Member Functions

bool checkSamePowerList (const CNormalProduct &rhs) const
 
 CNormalProduct ()
 
 CNormalProduct (const CNormalProduct &src)
 
virtual CNormalBasecopy () const
 
CNormalGeneralPowergetDenominator () const
 
const C_FLOAT64getFactor () const
 
const std::set
< CNormalItemPower
*, compareItemPowers > & 
getItemPowers () const
 
bool multiply (const C_FLOAT64 &number)
 
bool multiply (const CNormalItem &item)
 
bool multiply (const CNormalFunction &fun)
 
bool multiply (const CNormalChoice &choice)
 
bool multiply (const CNormalGeneralPower &pow)
 
bool multiply (const CNormalItemPower &itemPower)
 
bool multiply (const std::set< CNormalItemPower *, compareItemPowers > &itemPowers)
 
bool multiply (const CNormalProduct &product)
 
CNormalSummultiply (const CNormalSum &sum)
 
const CNormalSummultiply (const CNormalLcm &lcm)
 
bool operator< (const CNormalProduct &rhs) const
 
CNormalProductoperator= (const CNormalProduct &src)
 
bool operator== (const CNormalProduct &rhs) const
 
bool remove (std::set< CNormalItemPower *, compareItemPowers >::iterator it)
 
bool remove (const CNormalItemPower &itemPower)
 
void setDenominatorsOne ()
 
bool setFactor (const C_FLOAT64 &number)
 
void setItemPowers (const std::set< CNormalItemPower *, compareItemPowers > &set)
 
virtual bool simplify ()
 
virtual std::string toString () const
 
virtual ~CNormalProduct ()
 
- Public Member Functions inherited from CNormalBase
virtual bool areEqual (const CNormalBase &rhs) const
 
virtual ~CNormalBase ()
 

Static Public Member Functions

static CNormalProductcreateUnitProduct ()
 

Private Attributes

C_FLOAT64 mFactor
 
std::set< CNormalItemPower
*, compareItemPowers
mItemPowers
 

Friends

std::ostream & operator<< (std::ostream &os, const CNormalProduct &d)
 

Detailed Description

The class for products used in CNormal

Definition at line 43 of file CNormalProduct.h.

Constructor & Destructor Documentation

CNormalProduct::CNormalProduct ( )

Default constructor

Definition at line 54 of file CNormalProduct.cpp.

Referenced by copy(), createUnitProduct(), getDenominator(), and setDenominatorsOne().

54  : CNormalBase(), mFactor(1.0)
55 {}
C_FLOAT64 mFactor
CNormalProduct::CNormalProduct ( const CNormalProduct src)

Copy contructor

Definition at line 60 of file CNormalProduct.cpp.

References mItemPowers.

60  : CNormalBase(src), mFactor(src.mFactor)
61 {
62  std::set<CNormalItemPower*, compareItemPowers >::const_iterator it;
63  std::set<CNormalItemPower*, compareItemPowers >::const_iterator itEnd = src.mItemPowers.end();
64  const CNormalItemPower* pSrcItemPower = NULL;
65  CNormalItemPower* pDestItemPower = NULL;
66 
67  for (it = src.mItemPowers.begin(); it != itEnd; ++it)
68  {
69  pSrcItemPower = *it;
70  pDestItemPower = new CNormalItemPower(*pSrcItemPower);
71  bool result = this->mItemPowers.insert(pDestItemPower).second;
72  assert(result == true);
73  }
74 }
C_FLOAT64 mFactor
std::set< CNormalItemPower *, compareItemPowers > mItemPowers
CNormalProduct::~CNormalProduct ( )
virtual

Destructor

Definition at line 94 of file CNormalProduct.cpp.

References mItemPowers.

95 {
96  std::set<CNormalItemPower*, compareItemPowers >::const_iterator it;
97  std::set<CNormalItemPower*, compareItemPowers >::const_iterator itEnd = mItemPowers.end();
98 
99  for (it = mItemPowers.begin(); it != itEnd; ++it)
100  delete *it;
101 }
std::set< CNormalItemPower *, compareItemPowers > mItemPowers

Member Function Documentation

bool CNormalProduct::checkSamePowerList ( const CNormalProduct rhs) const

Definition at line 438 of file CNormalProduct.cpp.

References mItemPowers.

Referenced by operator==().

439 {
440  if (mItemPowers.size() != rhs.mItemPowers.size())
441  return false;
442 
443  std::set< CNormalItemPower*, compareItemPowers >::const_iterator it;
444  std::set< CNormalItemPower*, compareItemPowers >::const_iterator itEnd = mItemPowers.end();
445  std::set< CNormalItemPower*, compareItemPowers >::const_iterator it2;
446  //std::set< CNormalItemPower*, compareItemPowers >::const_iterator it2End = rhs.mItemPowers.end();
447 
448  for (it = mItemPowers.begin(), it2 = rhs.mItemPowers.begin(); it != itEnd; ++it, ++it2)
449  {
450  if (!(**it == **it2))
451  return false;
452  }
453 
454  return true;
455 }
std::set< CNormalItemPower *, compareItemPowers > mItemPowers
CNormalBase * CNormalProduct::copy ( ) const
virtual

Implements CNormalBase.

Definition at line 507 of file CNormalProduct.cpp.

References CNormalProduct().

508 {
509  return new CNormalProduct(*this);
510 }
CNormalProduct * CNormalProduct::createUnitProduct ( )
static

Returns a product that is 1. In this case it only creates a new product instance with new.

Definition at line 746 of file CNormalProduct.cpp.

References CNormalProduct().

Referenced by CNormalSum::createUnitSum(), and CNormalSum::simplify().

747 {
748  return new CNormalProduct();
749 }
CNormalGeneralPower * CNormalProduct::getDenominator ( ) const

Definition at line 669 of file CNormalProduct.cpp.

References CNormalSum::add(), CNormalFraction::checkDenominatorOne(), CNormalProduct(), CNormalGeneralPower::getLeft(), CNormalGeneralPower::getType(), mItemPowers, CNormalGeneralPower::multiply(), CNormalGeneralPower::POWER, CNormalItemPower::POWER, pResult, CNormalFraction::setDenominator(), CNormalGeneralPower::setLeft(), CNormalFraction::setNumerator(), CNormalGeneralPower::setRight(), and CNormalGeneralPower::setType().

Referenced by CNormalSum::simplify().

670 {
671  // go though all items that are general powers and check for general items
672  // of type power that have denominators in their base that differ from 1
673  // from all those denominators create a common denoninator and return it
674 
675  // first we generate a general power that is 1
678  CNormalSum* pTmpSum = new CNormalSum();
679  CNormalFraction* pTmpFrac = new CNormalFraction();
680  CNormalProduct* pTmpProduct = new CNormalProduct();
681  pTmpSum->add(*pTmpProduct);
682  delete pTmpProduct;
683  pTmpFrac->setNumerator(*pTmpSum);
684  pTmpFrac->setDenominator(*pTmpSum);
685  pResult->setLeft(*pTmpFrac);
686  pResult->setRight(*pTmpFrac);
687  delete pTmpFrac;
688  std::set<CNormalItemPower*, compareItemPowers>::const_iterator it = this->mItemPowers.begin(), endit = this->mItemPowers.end();
689 
690  while (it != endit)
691  {
692  if ((*it)->getItemType() == CNormalItemPower::POWER)
693  {
694  CNormalGeneralPower* pTmpPow = dynamic_cast<CNormalGeneralPower*>(&(*it)->getItem());
695  assert(pTmpPow != NULL);
696 
697  // only set the numerator to 1 if it is a power item and the
698  // denominator is not 1
699  if (pTmpPow->getType() == CNormalGeneralPower::POWER && !pTmpPow->getLeft().checkDenominatorOne())
700  {
701  // set the numerator to 1
702  pTmpPow = new CNormalGeneralPower(*pTmpPow);
703  pTmpPow->getLeft().setNumerator(*pTmpSum);
704  pResult->multiply(*pTmpPow);
705  delete pTmpPow;
706  }
707  }
708 
709  ++it;
710  }
711 
712  delete pTmpSum;
713  return pResult;
714 }
CNormalFraction & getLeft()
void multiply(const CNormalGeneralPower &generalPower)
std::set< CNormalItemPower *, compareItemPowers > mItemPowers
bool add(const CNormalProduct &product)
Definition: CNormalSum.cpp:156
bool setDenominator(const CNormalSum &denominator)
void setRight(const CNormalFraction &right)
const CArrayAnnotation * pResult
bool checkDenominatorOne() const
bool setNumerator(const CNormalSum &numerator)
void setLeft(const CNormalFraction &left)
const C_FLOAT64 & CNormalProduct::getFactor ( ) const
const std::set< CNormalItemPower *, compareItemPowers > & CNormalProduct::getItemPowers ( ) const
bool CNormalProduct::multiply ( const C_FLOAT64 number)

Multiply this product with a number.

Returns
true.

Definition at line 132 of file CNormalProduct.cpp.

References mFactor, and mItemPowers.

Referenced by createProduct(), CNormalGeneralPower::multiply(), multiply(), CNormalSum::simplify(), simplify(), and test_simplify::test_simplify_1().

133 {
134  mFactor = mFactor * number;
135 
136  if (fabs(mFactor) < 1.0E-100)
137  {
138  std::set<CNormalItemPower*, compareItemPowers>::iterator it = mItemPowers.begin(), endit = mItemPowers.end();
139 
140  while (it != endit)
141  {
142  delete *it;
143  ++it;
144  }
145 
146  mItemPowers.clear();
147  //mPowers.clear();
148  }
149 
150  return true;
151 }
C_FLOAT64 mFactor
std::set< CNormalItemPower *, compareItemPowers > mItemPowers
bool CNormalProduct::multiply ( const CNormalItem item)

Multiply an item to this product.

Returns
true.

Definition at line 235 of file CNormalProduct.cpp.

References mFactor, and mItemPowers.

236 {
237  if (fabs(mFactor) < 1.0E-100)
238  return true;
239 
240  std::set <CNormalItemPower*, compareItemPowers >::const_iterator it;
241  std::set <CNormalItemPower*, compareItemPowers >::const_iterator itEnd = mItemPowers.end();
242 
243  for (it = mItemPowers.begin(); it != itEnd; ++it)
244  {
245  if ((*it)->getItem().areEqual(item) == true)
246  {
247  (*it)->setExp((*it)->getExp() + 1.0);
248  return true;
249  }
250  }
251 
252  CNormalItemPower* tmp = new CNormalItemPower(item, 1.0);
253  mItemPowers.insert(tmp);
254  return true;
255 }
C_FLOAT64 mFactor
std::set< CNormalItemPower *, compareItemPowers > mItemPowers
bool CNormalProduct::multiply ( const CNormalFunction fun)

Multiply a function to this product.

Returns
true.

Multiply an item to this product.

Returns
true.

Definition at line 209 of file CNormalProduct.cpp.

References mFactor, and mItemPowers.

210 {
211  if (fabs(mFactor) < 1.0E-100)
212  return true;
213 
214  std::set <CNormalItemPower*, compareItemPowers >::const_iterator it;
215  std::set <CNormalItemPower*, compareItemPowers >::const_iterator itEnd = mItemPowers.end();
216 
217  for (it = mItemPowers.begin(); it != itEnd; ++it)
218  {
219  if ((*it)->getItem().areEqual(fun) == true)
220  {
221  (*it)->setExp((*it)->getExp() + 1.0);
222  return true;
223  }
224  }
225 
226  CNormalItemPower* tmp = new CNormalItemPower(fun, 1.0);
227  mItemPowers.insert(tmp);
228  return true;
229 }
C_FLOAT64 mFactor
std::set< CNormalItemPower *, compareItemPowers > mItemPowers
bool CNormalProduct::multiply ( const CNormalChoice choice)

Multiply a function to this product.

Returns
true.

Multiply an choice to this product.

Returns
true.

Definition at line 157 of file CNormalProduct.cpp.

References mFactor, and mItemPowers.

158 {
159  if (fabs(mFactor) < 1.0E-100)
160  return true;
161 
162  std::set <CNormalItemPower*, compareItemPowers >::const_iterator it;
163  std::set <CNormalItemPower*, compareItemPowers >::const_iterator itEnd = mItemPowers.end();
164 
165  for (it = mItemPowers.begin(); it != itEnd; ++it)
166  {
167  if ((*it)->getItem().areEqual(choice) == true)
168  {
169  (*it)->setExp((*it)->getExp() + 1.0);
170  return true;
171  }
172  }
173 
174  CNormalItemPower* tmp = new CNormalItemPower(choice, 1.0);
175  mItemPowers.insert(tmp);
176  return true;
177 }
C_FLOAT64 mFactor
std::set< CNormalItemPower *, compareItemPowers > mItemPowers
bool CNormalProduct::multiply ( const CNormalGeneralPower pow)

Multiply a general power to this product.

Returns
true.

Multiply an item to this product.

Returns
true.

Definition at line 183 of file CNormalProduct.cpp.

References mFactor, and mItemPowers.

184 {
185  if (fabs(mFactor) < 1.0E-100)
186  return true;
187 
188  std::set <CNormalItemPower*, compareItemPowers >::const_iterator it;
189  std::set <CNormalItemPower*, compareItemPowers >::const_iterator itEnd = mItemPowers.end();
190 
191  for (it = mItemPowers.begin(); it != itEnd; ++it)
192  {
193  if ((*it)->getItem().areEqual(pow) == true)
194  {
195  (*it)->setExp((*it)->getExp() + 1.0);
196  return true;
197  }
198  }
199 
200  CNormalItemPower* tmp = new CNormalItemPower(pow, 1.0);
201  mItemPowers.insert(tmp);
202  return true;
203 }
C_FLOAT64 mFactor
std::set< CNormalItemPower *, compareItemPowers > mItemPowers
bool CNormalProduct::multiply ( const CNormalItemPower itemPower)

Multiply an itempower to this product.

Returns
true.

Definition at line 261 of file CNormalProduct.cpp.

References CNormalItemPower::getExp(), CNormalItemPower::getItem(), mFactor, and mItemPowers.

262 {
263  if (fabs(mFactor) < 1.0E-100)
264  return true;
265 
266  std::set <CNormalItemPower*, compareItemPowers >::const_iterator it;
267  std::set <CNormalItemPower*, compareItemPowers >::const_iterator itEnd = mItemPowers.end();
268 
269  for (it = mItemPowers.begin(); it != itEnd; ++it)
270  {
271  if ((*it)->getItem().areEqual(itemPower.getItem()))
272  {
273  (*it)->setExp((*it)->getExp() + itemPower.getExp());
274  return true;
275  }
276  }
277 
278  CNormalItemPower* tmp = new CNormalItemPower(itemPower);
279  mItemPowers.insert(tmp);
280  return true;
281 }
C_FLOAT64 mFactor
std::set< CNormalItemPower *, compareItemPowers > mItemPowers
const C_FLOAT64 & getExp() const
CNormalBase & getItem()
bool CNormalProduct::multiply ( const std::set< CNormalItemPower *, compareItemPowers > &  itemPowers)

Multiply a list of itempowers to this product.

Returns
true.

Definition at line 287 of file CNormalProduct.cpp.

References mFactor, and multiply().

288 {
289  if (fabs(mFactor) < 1.0E-100)
290  return true;
291 
292  std::set <CNormalItemPower*, compareItemPowers >::const_iterator it;
293  std::set <CNormalItemPower*, compareItemPowers >::const_iterator itEnd = itemPowers.end();
294 
295  for (it = itemPowers.begin(); it != itEnd; ++it)
296  multiply(**it);
297 
298  return true;
299 }
C_FLOAT64 mFactor
bool multiply(const C_FLOAT64 &number)
bool CNormalProduct::multiply ( const CNormalProduct product)

Multiply this product with another product.

Returns
true

Definition at line 352 of file CNormalProduct.cpp.

References getFactor(), getItemPowers(), mFactor, and multiply().

353 {
354  multiply(product.getFactor());
355 
356  if (fabs(mFactor) < 1.0E-100)
357  return true;
358 
359  multiply(product.getItemPowers());
360  return true;
361 }
C_FLOAT64 mFactor
const std::set< CNormalItemPower *, compareItemPowers > & getItemPowers() const
const C_FLOAT64 & getFactor() const
bool multiply(const C_FLOAT64 &number)
CNormalSum * CNormalProduct::multiply ( const CNormalSum sum)

Multiply this product with a sum NOT CONTAINING FRACTIONS!.

Returns
sum.

Definition at line 367 of file CNormalProduct.cpp.

References CNormalSum::add(), CNormalSum::getProducts(), and mFactor.

368 {
369  if (fabs(mFactor) < 1.0E-100)
370  {
371  CNormalSum* zeroSum = new CNormalSum();
372  zeroSum->add(*this);
373  return zeroSum;
374  }
375 
376  CNormalSum* tmp = new CNormalSum(sum);
377  CNormalSum* newsum = new CNormalSum();
378  std::set<CNormalProduct*, compareProducts>::const_iterator it;
379  std::set<CNormalProduct*, compareProducts>::const_iterator itEnd = tmp->getProducts().end();
380 
381  for (it = tmp->getProducts().begin(); it != itEnd; ++it)
382  {
383  (*it)->multiply(*this);
384  newsum->add(**it);
385  }
386 
387  delete tmp;
388  return newsum;
389 }
C_FLOAT64 mFactor
bool add(const CNormalProduct &product)
Definition: CNormalSum.cpp:156
const std::set< CNormalProduct *, compareProducts > & getProducts() const
Definition: CNormalSum.cpp:416
const CNormalSum * CNormalProduct::multiply ( const CNormalLcm lcm)

Multiply this product with a lcm.

Returns
true

Definition at line 395 of file CNormalProduct.cpp.

References CNormalSum::add(), CNormalLcm::getItemPowers(), CNormalLcm::getSums(), mFactor, and multiply().

396 {
397  if (fabs(mFactor) < 1.0E-100)
398  {
399  CNormalSum* zeroSum = new CNormalSum();
400  zeroSum->add(*this);
401  return zeroSum;
402  }
403 
404  CNormalLcm* tmp = new CNormalLcm(lcm);
405  multiply(tmp->getItemPowers());
406  CNormalSum* sum = new CNormalSum();
407  sum->add(*this);
408  std::vector<CNormalSum*>::const_iterator it;
409  std::vector<CNormalSum*>::const_iterator itEnd = tmp->getSums().end();
410 
411  for (it = tmp->getSums().begin(); it != itEnd; ++it)
412  {
413  sum->multiply(**it);
414  }
415 
416  delete tmp;
417  return sum;
418 }
C_FLOAT64 mFactor
const std::vector< CNormalSum * > & getSums() const
Definition: CNormalLcm.cpp:275
bool add(const CNormalProduct &product)
Definition: CNormalSum.cpp:156
bool multiply(const C_FLOAT64 &number)
const std::set< CNormalItemPower *, compareItemPowers > & getItemPowers() const
Definition: CNormalLcm.cpp:266
bool CNormalProduct::operator< ( const CNormalProduct rhs) const

Smaller operator

Definition at line 512 of file CNormalProduct.cpp.

References mFactor, and mItemPowers.

513 {
514  bool result = false;
515 
516  if (this->mFactor < rhs.mFactor)
517  {
518  result = true;
519  }
520  else if (this->mFactor == rhs.mFactor)
521  {
522  if (this->mItemPowers.size() < rhs.mItemPowers.size())
523  {
524  result = true;
525  }
526  else if (this->mItemPowers.size() == rhs.mItemPowers.size())
527  {
528  std::set<CNormalItemPower*, compareItemPowers >::const_iterator it = this->mItemPowers.begin(), endit = this->mItemPowers.end();
529  std::set<CNormalItemPower*, compareItemPowers >::const_iterator it2 = rhs.mItemPowers.begin();
530  compareItemPowers comp;
531 
532  while (result == false && it != endit)
533  {
534  if (comp(*it, *it2))
535  {
536  result = true;
537  }
538 
539  if (comp(*it2, *it))
540  {
541  break;
542  }
543 
544  ++it;
545  ++it2;
546  }
547  }
548  }
549 
550  return result;
551 }
C_FLOAT64 mFactor
std::set< CNormalItemPower *, compareItemPowers > mItemPowers
CNormalProduct & CNormalProduct::operator= ( const CNormalProduct src)

Assignment operator

Definition at line 79 of file CNormalProduct.cpp.

References mFactor, and mItemPowers.

80 {
81  mFactor = src.mFactor;
82  std::set<CNormalItemPower*, compareItemPowers >::const_iterator it;
83  std::set<CNormalItemPower*, compareItemPowers >::const_iterator itEnd = src.mItemPowers.end();
84 
85  for (it = src.mItemPowers.begin(); it != itEnd; ++it)
86  mItemPowers.insert(new CNormalItemPower(**it));
87 
88  return *this;
89 }
C_FLOAT64 mFactor
std::set< CNormalItemPower *, compareItemPowers > mItemPowers
bool CNormalProduct::operator== ( const CNormalProduct rhs) const

Definition at line 457 of file CNormalProduct.cpp.

References checkSamePowerList(), and mFactor.

458 {
459  if (mFactor != rhs.mFactor)
460  return false;
461 
462  if (checkSamePowerList(rhs))
463  return true;
464 
465  return false;
466 }
C_FLOAT64 mFactor
bool checkSamePowerList(const CNormalProduct &rhs) const
bool CNormalProduct::remove ( std::set< CNormalItemPower *, compareItemPowers >::iterator  it)

Remove an itempower from this product, provided it is a factor of it.

Returns
true.

Definition at line 305 of file CNormalProduct.cpp.

References mItemPowers.

306 {
307  delete(*it);
308  mItemPowers.erase(it);
309  return true;
310 }
std::set< CNormalItemPower *, compareItemPowers > mItemPowers
bool CNormalProduct::remove ( const CNormalItemPower itemPower)

Remove an itempower from this product, provided it is a factor of it. -used in multiplication with lcm-

Returns
true.

Definition at line 317 of file CNormalProduct.cpp.

References C_FLOAT64, CNormalItemPower::getExp(), CNormalItemPower::getItem(), and mItemPowers.

318 {
319  std::set <CNormalItemPower*, compareItemPowers >::iterator it;
320  std::set <CNormalItemPower*, compareItemPowers >::iterator itEnd = mItemPowers.end();
321 
322  for (it = mItemPowers.begin(); it != itEnd; ++it)
323  {
324  if ((*it)->getItem().areEqual(itemPower.getItem()))
325  {
326  C_FLOAT64 dif = (*it)->getExp() - itemPower.getExp();
327 
328  if (dif >= 1.0E-100)
329  {
330  (*it)->setExp(dif);
331  return true;
332  }
333 
334  if (fabs(dif) < 1.0E-100)
335  {
336  delete(*it);
337  mItemPowers.erase(it);
338  return true;
339  }
340 
341  return false;
342  }
343  }
344 
345  return false;
346 }
std::set< CNormalItemPower *, compareItemPowers > mItemPowers
const C_FLOAT64 & getExp() const
#define C_FLOAT64
Definition: copasi.h:92
CNormalBase & getItem()
void CNormalProduct::setDenominatorsOne ( )

Definition at line 716 of file CNormalProduct.cpp.

References CNormalSum::add(), CNormalProduct(), CNormalGeneralPower::getLeft(), CNormalGeneralPower::getType(), mItemPowers, CNormalGeneralPower::POWER, CNormalItemPower::POWER, and CNormalFraction::setDenominator().

Referenced by CNormalSum::simplify().

717 {
718  // goes through all items and sets the denominators of the bases of all
719  // general power items of type power to one
720  CNormalSum* pTmpSum = new CNormalSum();
721  CNormalProduct* pTmpProduct = new CNormalProduct();
722  pTmpSum->add(*pTmpProduct);
723  delete pTmpProduct;
724  std::set<CNormalItemPower*, compareItemPowers>::iterator it = this->mItemPowers.begin(), endit = this->mItemPowers.end();
725 
726  while (it != endit)
727  {
728  if ((*it)->getItemType() == CNormalItemPower::POWER)
729  {
730  CNormalGeneralPower* pGenPow = dynamic_cast<CNormalGeneralPower*>(&(*it)->getItem());
731  assert(pGenPow != NULL);
732 
733  // only set the denominator to 1 if it is a power item
734  if (pGenPow->getType() == CNormalGeneralPower::POWER)
735  {
736  pGenPow->getLeft().setDenominator(*pTmpSum);
737  }
738  }
739 
740  ++it;
741  }
742 
743  delete pTmpSum;
744 }
CNormalFraction & getLeft()
std::set< CNormalItemPower *, compareItemPowers > mItemPowers
bool add(const CNormalProduct &product)
Definition: CNormalSum.cpp:156
bool setDenominator(const CNormalSum &denominator)
bool CNormalProduct::setFactor ( const C_FLOAT64 number)

Set the factor for this product.

Returns
true.

Definition at line 107 of file CNormalProduct.cpp.

References mFactor, and mItemPowers.

Referenced by createProduct(), and createSum().

108 {
109  mFactor = number;
110 
111  if (fabs(mFactor) < 1.0E-100)
112  {
113  std::set<CNormalItemPower*, compareItemPowers>::iterator it = mItemPowers.begin(), endit = mItemPowers.end();
114 
115  while (it != endit)
116  {
117  delete *it;
118  ++it;
119  }
120 
121  mItemPowers.clear();
122  //mPowers.clear();
123  }
124 
125  return true;
126 }
C_FLOAT64 mFactor
std::set< CNormalItemPower *, compareItemPowers > mItemPowers
void CNormalProduct::setItemPowers ( const std::set< CNormalItemPower *, compareItemPowers > &  set)

Sets the item powers of this product.

Definition at line 553 of file CNormalProduct.cpp.

References mItemPowers.

Referenced by normalize_variable_names().

554 {
555  std::set<CNormalItemPower*, compareItemPowers>::const_iterator it = this->mItemPowers.begin(), endit = this->mItemPowers.end();
556 
557  while (it != endit)
558  {
559  delete *it;
560  ++it;
561  }
562 
563  it = set.begin(), endit = set.end();
564  this->mItemPowers.clear();
565 
566  while (it != endit)
567  {
568  this->mItemPowers.insert(new CNormalItemPower(**it));
569  ++it;
570  }
571 }
std::set< CNormalItemPower *, compareItemPowers > mItemPowers
bool CNormalProduct::simplify ( )
virtual

Implements CNormalBase.

Definition at line 573 of file CNormalProduct.cpp.

References CNormalGeneralPower::checkIsOne(), mItemPowers, CNormalGeneralPower::multiply(), multiply(), CNormalGeneralPower::POWER, CNormalItemPower::POWER, CNormalItemPower::setExp(), CNormalItemPower::setItem(), and CNormalItemPower::simplify().

Referenced by CNormalSum::simplify(), and test_simplify::test_simplify_1().

574 {
575  bool result = true;
576  // don't work on the items in the set directly
577  // make a copy, otherwise the set will be messed up
578  std::set<CNormalItemPower*, compareItemPowers> itemPowersCopy(this->mItemPowers);
579  std::set<CNormalItemPower*, compareItemPowers>::iterator it = itemPowersCopy.begin(), endit = itemPowersCopy.end();
580  CNormalItemPower* pTmpItemPower = NULL;
581  this->mItemPowers.clear();
582 
583  while (it != endit && result == true)
584  {
585  pTmpItemPower = *it;
586  result = pTmpItemPower->simplify();
587 
588  if (result)
589  {
590  this->multiply(*pTmpItemPower);
591  }
592 
593  delete pTmpItemPower;
594  ++it;
595  }
596 
597  // we should combine all general power items of type power into
598  // one large general power item which is again simplified
599  // this we only do if the CNormalItemPower parent has an exponent of 1
600  it = this->mItemPowers.begin();
601  endit = this->mItemPowers.end();
602  std::vector<CNormalItemPower*> tmpV;
603  // create a unit CNormalItemPower with one unit CNormalGeneralPower
604  // and an exponent of 1
605  CNormalGeneralPower* pGeneralPower = NULL; //CNormalGeneralPower::createUnitGeneralPower();
606 
607  while (it != endit)
608  {
609  if ((*it)->getExp() == 1.0 && (*it)->getItemType() == CNormalItemPower::POWER &&
610  dynamic_cast<CNormalGeneralPower*>(&(*it)->getItem())->getType() == CNormalGeneralPower::POWER
611  &&
612  dynamic_cast<CNormalGeneralPower*>(&(*it)->getItem())->getRight().checkIsOne()
613  )
614  {
615  if (pGeneralPower)
616  {
617  pGeneralPower->multiply(*static_cast<CNormalGeneralPower*>(&(*it)->getItem()));
618  }
619  else
620  {
621  pGeneralPower = static_cast<CNormalGeneralPower*>(&(*it)->getItem());
622  pGeneralPower = new CNormalGeneralPower(*pGeneralPower);
623  }
624 
625  delete *it;
626  }
627  else
628  {
629  if ((*it)->getItemType() == CNormalItemPower::POWER &&
630  dynamic_cast<CNormalGeneralPower*>(&(*it)->getItem())->getType() == CNormalGeneralPower::POWER &&
631  dynamic_cast<CNormalGeneralPower*>(&(*it)->getItem())->getLeft().checkIsOne()
632  )
633  {
634  delete *it;
635  }
636  else
637  {
638  tmpV.push_back(*it);
639  }
640  }
641 
642  ++ it;
643  }
644 
645  if (pGeneralPower && !pGeneralPower->checkIsOne())
646  {
647  CNormalItemPower* pTmpItemPower = new CNormalItemPower();
648  pTmpItemPower->setExp(1.0);
649  pTmpItemPower->setItem(*pGeneralPower);
650  tmpV.push_back(pTmpItemPower);
651  }
652 
653  delete pGeneralPower;
654  // clear the current set of items and add all the item in tmpV
655  this->mItemPowers.clear();
656  std::vector<CNormalItemPower*>::iterator vIt = tmpV.begin();
657  std::vector<CNormalItemPower*>::iterator vEndIt = tmpV.end();
658 
659  while (vIt != vEndIt)
660  {
661  this->multiply(**vIt);
662  delete *vIt;
663  ++vIt;
664  }
665 
666  return result;
667 }
virtual bool simplify()
void multiply(const CNormalGeneralPower &generalPower)
std::set< CNormalItemPower *, compareItemPowers > mItemPowers
bool setItem(const CNormalBase &item)
bool multiply(const C_FLOAT64 &number)
bool setExp(const C_FLOAT64 &number)
std::string CNormalProduct::toString ( ) const
virtual

Implements CNormalBase.

Definition at line 474 of file CNormalProduct.cpp.

References mFactor, and mItemPowers.

Referenced by operator<<().

475 {
476  std::ostringstream os;
477  bool firstFactor = true;
478 
479  if ((fabs(this->mFactor - 1.0) >= 1.0E-100) || (this->mItemPowers.size() == 0))
480  {
481  if (this->mFactor < 0.0)
482  os << "(" << this->mFactor << ")";
483  else
484  {
485  os.precision(18);
486  os << this->mFactor;
487  }
488 
489  firstFactor = false;
490  }
491 
492  std::set <CNormalItemPower*, compareItemPowers >::const_iterator it;
493  std::set <CNormalItemPower*, compareItemPowers >::const_iterator itEnd = this->mItemPowers.end();
494 
495  for (it = this->mItemPowers.begin(); it != itEnd; ++it)
496  {
497  if (firstFactor == false)
498  os << " * ";
499 
500  os << **it;
501  firstFactor = false;
502  }
503 
504  return os.str();
505 }
C_FLOAT64 mFactor
std::set< CNormalItemPower *, compareItemPowers > mItemPowers

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  os,
const CNormalProduct d 
)
friend

Definition at line 468 of file CNormalProduct.cpp.

469 {
470  os << d.toString();
471  return os;
472 }
virtual std::string toString() const

Member Data Documentation

C_FLOAT64 CNormalProduct::mFactor
private

Enumeration of members

Definition at line 49 of file CNormalProduct.h.

Referenced by getFactor(), multiply(), operator<(), operator=(), operator==(), setFactor(), and toString().

std::set<CNormalItemPower*, compareItemPowers > CNormalProduct::mItemPowers
private

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