COPASI API  4.16.103
Static Public Member Functions | List of all members
CDerive Class Reference

#include <CDerive.h>

Static Public Member Functions

static void compileTree (CEvaluationNode *node, const CEvaluationTree *pTree)
 
static CEvaluationNodederiveBranch (const CEvaluationNode *node, unsigned C_INT32 variableIndex, const CCopasiObject *pObject=NULL)
 

Detailed Description

Definition at line 22 of file CDerive.h.

Member Function Documentation

void CDerive::compileTree ( CEvaluationNode node,
const CEvaluationTree pTree 
)
static

Definition at line 204 of file CDerive.cpp.

References CEvaluationNode::compile(), CCopasiNode< _Data >::getChild(), and CCopasiNode< _Data >::getSibling().

205 {
206  if (!node) return;
207 
208  node->compile(pTree);
209 
210  CEvaluationNode* child = dynamic_cast<CEvaluationNode*>(node->getChild());
211 
212  while (child != NULL)
213  {
214  compileTree(child, pTree);
215  child = dynamic_cast<CEvaluationNode*>(child->getSibling());
216  }
217 }
CCopasiNode< Data > * getSibling()
Definition: CCopasiNode.h:353
static void compileTree(CEvaluationNode *node, const CEvaluationTree *pTree)
Definition: CDerive.cpp:204
virtual bool compile(const CEvaluationTree *pTree)
CCopasiNode< Data > * getChild()
Definition: CCopasiNode.h:210
CEvaluationNode * CDerive::deriveBranch ( const CEvaluationNode node,
unsigned C_INT32  variableIndex,
const CCopasiObject pObject = NULL 
)
static

Definition at line 22 of file CDerive.cpp.

References CCopasiNode< _Data >::addChild(), CEvaluationNodeOperator::compile(), CEvaluationNode::copyBranch(), CEvaluationNodeOperator::DIVIDE, CEvaluationNodeVariable::getIndex(), CEvaluationNodeOperator::getLeft(), CEvaluationNodeOperator::getRight(), CEvaluationNode::getType(), CEvaluationNodeNumber::INTEGER, CEvaluationNodeFunction::LOG, CEvaluationNodeOperator::MINUS, CEvaluationNodeOperator::MULTIPLY, CEvaluationNodeOperator::PLUS, CEvaluationNodeOperator::POWER, and CEvaluationNode::subType().

23 {
24  CEvaluationNode * newNode = NULL;
25 
26  const CEvaluationNodeOperator * pENO = dynamic_cast<const CEvaluationNodeOperator*>(node);
27 
28  if (pENO)
29  {
30  if (!pENO->getLeft() || !pENO->getRight()) return NULL;
31 
32  CEvaluationNode * pLeftDeriv = deriveBranch(pENO->getLeft(), variableIndex, pObject);
33 
34  if (!pLeftDeriv) return NULL;
35 
36  CEvaluationNode * pRightDeriv = deriveBranch(pENO->getRight(), variableIndex, pObject);
37 
38  if (!pRightDeriv) {delete pLeftDeriv; return NULL;}
39 
40  // we now know that derivations of the left and right branch exist
41 
43  {
45  {
46  CEvaluationNode * pLeftCopy = pENO->getLeft()->copyBranch();
47  CEvaluationNode * pRightCopy = pENO->getRight()->copyBranch();
48 
50 
51  CEvaluationNodeOperator * tmpNode;
53  tmpNode->addChild(pRightCopy);
54  tmpNode->addChild(pLeftDeriv);
55  //tmpNode->compile(NULL);
56  newNode->addChild(tmpNode);
57 
59  tmpNode->addChild(pRightDeriv);
60  tmpNode->addChild(pLeftCopy);
61  //tmpNode->compile(NULL);
62  newNode->addChild(tmpNode);
63 
64  //if (newNode) newNode->compile(NULL);
65  return newNode;
66  }
67  break;
68 
70  {
71  CEvaluationNode * pLeftCopy = pENO->getLeft()->copyBranch();
72  CEvaluationNode * pRightCopy = pENO->getRight()->copyBranch();
73 
74  //numerator
76 
77  CEvaluationNodeOperator * tmpNode;
79  tmpNode->addChild(pRightCopy);
80  tmpNode->addChild(pLeftDeriv);
81  //tmpNode->compile(NULL);
82  minusNode->addChild(tmpNode);
83 
85  tmpNode->addChild(pRightDeriv);
86  tmpNode->addChild(pLeftCopy);
87  //tmpNode->compile(NULL);
88  minusNode->addChild(tmpNode);
89 
90  minusNode->compile(NULL);
91 
92  //denominator
94  pRightCopy = pENO->getRight()->copyBranch(); //new copy
95  powerNode->addChild(pRightCopy);
97  //powerNode->compile(NULL);
98 
100  newNode->addChild(minusNode);
101  newNode->addChild(powerNode);
102  //if (newNode) newNode->compile(NULL);
103  return newNode;
104  }
105  break;
106 
109  newNode->addChild(pLeftDeriv);
110  newNode->addChild(pRightDeriv);
111  //TODO check for zeros
112 
113  //if (newNode) newNode->compile(NULL);
114  return newNode;
115  break;
116 
119  newNode->addChild(pLeftDeriv);
120  newNode->addChild(pRightDeriv);
121  //TODO check for zeros
122 
123  //if (newNode) newNode->compile(NULL);
124  return newNode;
125  break;
126 
128  {
129  CEvaluationNode * pLeftCopy = pENO->getLeft()->copyBranch();
130  CEvaluationNode * pRightCopy = pENO->getRight()->copyBranch();
131 
132  // a^(b-1)
134  powerNode->addChild(pLeftCopy); // add a
135 
136  CEvaluationNodeOperator * tmpNode;
138  tmpNode->addChild(pRightCopy); // add b
140  powerNode->addChild(tmpNode); // add b-1
141 
142  // b*a´ + a*b´* ln a
144 
146  pRightCopy = pENO->getRight()->copyBranch(); //new copy of b
147  tmpNode->addChild(pRightCopy); // add b
148  tmpNode->addChild(pLeftDeriv); // add a´
149  plusNode->addChild(tmpNode); // add b*a´
150 
152  pLeftCopy = pENO->getLeft()->copyBranch(); //new copy of a
153  tmpNode->addChild(pLeftCopy); // add a
154 
156  tmptmpNode->addChild(pRightDeriv); // add b´
158  pLeftCopy = pENO->getLeft()->copyBranch(); //new copy of a
159  funcNode->addChild(pLeftCopy); // add a
160  tmptmpNode->addChild(funcNode); // add ln a
161 
162  tmpNode->addChild(tmptmpNode); // add b´ * ln a
163  plusNode->addChild(tmpNode); // add a * b´ * ln a
164 
165  // a^(b-1)*(b*a´ + a*b´ * ln a)
167  newNode->addChild(powerNode);
168  newNode->addChild(plusNode);
169  return newNode;
170  }
171  break;
172 
173  default:
174  break;
175  }
176  }
177 
178  const CEvaluationNodeVariable * pENV = dynamic_cast<const CEvaluationNodeVariable*>(node);
179 
180  if (pENV)
181  {
182  if (pObject) return NULL; // if a variable node occurs, we are differentiating a function
183 
184  if (variableIndex == pENV->getIndex())
186  else
188 
189  return newNode;
190  }
191 
192  const CEvaluationNodeNumber * pENN = dynamic_cast<const CEvaluationNodeNumber*>(node);
193 
194  if (pENN)
195  {
197  return newNode;
198  }
199 
200  return newNode;
201 }
CEvaluationNode * copyBranch() const
virtual bool compile(const CEvaluationTree *pTree)
const Type & getType() const
static CEvaluationNode * deriveBranch(const CEvaluationNode *node, unsigned C_INT32 variableIndex, const CCopasiObject *pObject=NULL)
Definition: CDerive.cpp:22
virtual bool addChild(CCopasiNode< Data > *pChild, CCopasiNode< Data > *pAfter=NULL)
Definition: CCopasiNode.h:156
static Type subType(const Type &type)

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