• No results found

The normalization process for any mathematical expression starts with a CEvaluationNode based expression tree as described above. libSBML which is used to load SBML files also has a node tree based format for mathematical expressions and all expressions from SBML model files are first converted to the COPASI tree representation. For this a number of methods have been written which are also used for the import of SBML model files into COPASI. Since many steps of the normalization process are easier to do on the tree like expression representation, a large part of the normalization process is done on the nodes of the tree while other steps of the normalization process are executed on the normal form representation (see chapter 5.1). The nor- malization process is an iterative process and in the course of a single normal- ization the expression is converted several times between these two formats. For the conversion from the CEvaluationNode based expression representa- tion to the CNormalBase representation and vice versa special methods have been written.

Function Call Expansion

COPASI as well as SBML model files can contain user defined function defi- nitions. So the first step when normalizing an expression is to eliminate calls to these user defined functions. For this, all calls to user defined functions are replaced by the expression of the function. All function variables in that expressions have to be replaced by the arguments to the function from the function call.

Since function definitions can call other function definitions, this process has to be repeated until there are no more calls to user defined functions in the expression (see figure 5.14).

This expansion of the expression is done on the CEvaluationNode based representation and the result of the expansion is again represented by a CEvaluationNode based expression tree.

NORMALIZATION ALGORITHM 143 Function definitions: f (x) = 3.0 ∗ x g(y) = f (y)2.0 4.0 ∗ g(a) + f (b) → 4.0 ∗ f (a)2.0+ 3.0 ∗ b → 4.0 ∗ (3.0 ∗ a)2.0+ 3.0 ∗ b

Figure 5.14: Example of a function call elimination. The expression calls contains two function calls, f and g. In the first elimination step both calls are replaced by the expressions of the corresponding function definitions and the function variables are replaced by the arguments to these function calls. Since the function g calls the function f , the expanded code still contains a function call, so the expression needs to be expanded a second time to finally get the fully expanded expression.

Only normal forms of expressions expanded in this way can be compared reliably.

Normalization Iteration

The expanded expression tree is then simplified and normalized repeatedly either until the infix (meaning the string representing the expression) has not changed between two iterations of the simplification and normalization process or until a certain iteration limit has been reached.

Since on the one hand mathematical expressions can be arbitrarily com- plex and on the other hand the algorithm is not guaranteed to converge for all possible mathematical expressions, the algorithm will not necessarily stop by itself for any given expressions. For this reason a limit for the number of iterations that are done has been added to the algorithm which guarantees that the algorithm will not spent infinite time on the normalization of any expression. The current iteration limit for this top level iteration is 20. This value seems to provide a good compromise between allowing the algorithm to converge for most expressions while making certain that it does stop within a reasonable time frame.

The algorithm starts out with the tree representation and simplifies this tree as much as possible. For the result of this simplification, the exponents of all power nodes are expanded again and the result is converted to the CNormalBase representation which is then again simplified.

Since the power node expansion is also done during the simplification of the tree based expression, the details of this function are explained in that context.

Those parts of the simplification process that are easier done on the tree are done on the tree and those the are easier to do on the normal form representation are done there.

The result of this process is an instance of the class CNormalFraction. repeat

- store infix

- simplify tree based expression

- expand power nodes on simplified tree

- convert tree based expression to CNormalFraction - simplify fraction

until (stored infix = infix from fraction ∨ number of iterations > iteration limit) Figure 5.15: Steps of the normalization of mathematical expressions.

In the following paragraphs, the four steps from figure 5.15 will be ex- plained in more detail. First we will have a look at the simplification of the tree based expression representation.

Simplification Of The Tree Based Expression

The overall algorithm for this step is similar to the iterative process described above. A number of simplification steps are executed on the nodes of the tree based expression representation and afterwards, the infix of the expression is compared to the infix as it was before these simplification steps. If the two string representations are identical, the algorithm assumes that the process of simplifying the expression is finished and stops, otherwise it continues with another round of the same simplification steps.

This either continues until no more changes to the tree have occurred within one iteration or if a certain iteration limit has been reached. Currently this iteration limit is the same as for the overall process which is 20 iterations.

NORMALIZATION ALGORITHM 145

repeat

- elimination of certain structures

- evaluation of operations on numerical nodes

- collecting identical elements in addition/subtraction and multiplication/division chains

- expansion of power bases - expansion of power nodes - expansion of products

until (stored infix = infix from fraction ∨ number of iterations > iteration limit)

Eliminations

The elimination process gets rid of several undesired structures again in an iterative way, meaning the process is repeated until there are no more changes to the expression between two iterations.

The first thing the method does is to eliminate some unnecessary elements like multiplications or divisions by the number 1 as well as additions and/or subtractions of the number 0.

The next thing it does it to eliminate nested powers. E.g. the term Axy

is converted to the term A(x∗y).

Another structure that is converted are powers of fractions. A fraction to a power is converted to a fraction where the numerator and the denominator are each taken to that power. E.g. BA5

is converted to AB55.

Another elimination is done on nested fractions. Nested fractions are converted to a single fractions. E.g. the term

A B

C is converted to the term

A B∗C.

And last but not least, the method collects identical elements in the result- ing expressions as explained below in the paragraph on "collecting identical elements".

Evaluation Of Operations On Number Nodes

In expressions one often finds operations that act only on numbers, e.g. some- thing like the term 2.0 + 3.0/6.0. The algorithm searches for such operations, evaluates them and replaces the complete subexpression by the resulting number (see figure 5.16).

Collecting Identical Elements

This methods tries to identify chains of additions/subtractions and/or chains of multiplications/divisions. It then tries to identify elements in these chains

A * 4.0 * (3.0 - 1.0) + A * 4.0 - 3.0 1.0 A + 8.0 + A 8.0

Figure 5.16: Example of the evaluation of operation on numbers. A complete subexpression of the tree is replaced by a single number after the expression has been evaluated.

that cancel each other out, either partially or completely. E.g. a multiplica- tion would be canceled by a division with the identical term, or an additions would be canceled out by a subtraction of the same term (see figure 5.17).

3.0 ∗ A ∗ C2/(B ∗ C) → 3.0 ∗ A ∗ C/B

2.4 − x + T + x → 2.4 + T

Figure 5.17: Example of a multiplication (left) and an addition (right) where terms cancel each other out. In the second addition example two terms cancel each other out completely and can therefore be eliminated.

For multiplication chains this method also considers the exponents of potential power nodes. E.g. if in a multiplication/division chain a factor A4

is found and in the same chain there is a divisor A3, these two nodes would be replaced by the term A.

Expansion Of Power Bases

This method expands products to some power to the corresponding products of the individual factors to the same power.

E.g. the expression (A ∗ B)x would be converted to the new expression

Ax∗ Bx

Expansion Of Power Nodes

This method converts nodes representing a power operation where the expo- nent is a sum into a product of two or more power nodes where the exponents

NORMALIZATION ALGORITHM 147

are no longer sums.

An example for this would be the term A(x+y) which would be converted

to Ax∗ Ay.

Expansion Of Products

This method expands products of sums into sums of products.

E.g. the term (A + B) ∗ (C + D) would be expanded to the new term (A ∗ C) + (A ∗ D) + (B ∗ C) + (B ∗ D).

Once the expression tree has been simplified this way power nodes are ex- panded again before the expression is converted to the CNormalBase based representation. This additional final expansion of the power nodes, simpli- fies the following conversion to the normal form. The resulting instance of CNormalFraction is now again subjected to a number of simplification steps that are supposed to lead to the final normalized form.

The steps undertaken for the simplification and normalization of this sec- ond representation greatly depends on the element that is being processed. Each class has a method called simplify which is used to further rear- range the mathematical representation to create the final final normal form. Usually each class will call the simplify method for all instances of other elements it contains. E.g. the fraction representation will call simplify on its numerator and its denominator.

In the following paragraphs the processing steps for the individual classes are described.

CNormalFraction

In the simplify method for CNormalFraction the corresponding methods for the numerator and the denominator are called which are both instances of CNormalSum.

If the instances of CNormalSum of the numerator and the denominator still contain fractions in addition to the products, the method expands these fractions and converts them to new instances of CNormalSum which are added to the numerator and the denominator accordingly.

Afterwards the method tries to identify common factors in the numerator and the denominator and cancels those.

CNormalSum

If the instance of CNormalSum still contains fractions, these fractions are simplified first. Next the algorithm traverses all instances of CNormalProduct and simplifies them as well.

The method also tries to eliminate nested fractions as might be present in items of type CNormalGeneralPower in the instances of CNormalProd- uct. By converting the CNormalGeneralPower to an instance of CNormal- Fraction, the fraction can be eliminated by the simplify method of the parent fraction instance in the following iteration (see figure 5.18).

· · · + Nb Db (Ne Be) !n + · · · → · · · + N (n∗NeDe) b D(n∗ Ne De) b + · · ·

Figure 5.18: Conversion of an instance of CNormalGeneralPower in a CNormalSum to a CNormalFraction, which can be eliminated by the simplify method of the fraction object containing the instance of CNormalSum.

CNormalProduct

The CNormalProduct class first calls simplify on all instances of CNormal- ItemPower. Next the method traverses all items and checks for items which are instances of type CNormalGeneralPower. If such an instance is found and that instance has a base of 1, is is eliminated otherwise it is combined with the other instances of CNormalGeneralPower in the product. This combination of CNormalGeneralPower instances again leads to a CNormalGeneralPower which might be simplified further in the next iteration.

CNormalItemPower

Instances of CNormalItemPower only simplify the item they contain. Since the item, can be an instance of one of several classes, the corresponding simplify method for that class is called.

NORMALIZATION ALGORITHM 149

CNormalItem

Instances of CNormalItem are not simplified.

CNormalFunction

Instances of CNormalFunction simplify their argument which is an instance of CNormalFraction.

CNormalCall

Instances of CNormalFunction simplify all their arguments which are in- stances of the CNormalFraction class.

CNormalGeneralPower

Instances of CNormalGeneralPower simplify the two CNormalFraction in- stances representing the base and the exponent.

CNormalChoice

Instances of the class CNormalChoice simplify the condition which is an instance of CNormalLogical and the two result branches which are both in- stances of CNormalFraction.

CNormalLogical

The simplification for instances of CNormalLogical is rather complex. Since intermediate results can contain instances of CNormalChoiceLogical those have to be eliminated first. This is done by replacing each choice element IF(COND, TRUE-term, FALSE-term) by the term (CON D ∧ T RU E − term)∨ (¬CON D ∧ F ALSE − term).

For the creation of the disjunctive normal form in the last step, it is also necessary to eliminate all negated elements, meaning all elements to which the logical not (¬) operation is applied.

Last but not least the sets of logical items in the instance of CNormal- Logical are converted to the canonical disjunctive normal form[182, 183] to make it comparable to other logical expressions.

This conversion to the canonical disjunctive normal form scales exponen- tially with the number of logical elements. For this reason, we limit the

number of elements that are allowed to 16. Due to this, expressions contain- ing more than 16 elements can not be normalized by the current version of this framework.

CNormalChoiceLogical

Instances of the class CNormalChoiceLogical simplify the condition which is an instance of CNormalLogical and the two result branches which are also both instances of CNormalLogical.

CNormalLogicalItem

For the normal form, instances of class CNormalLogicalItem which represent the greater (>) relation are converted to the less (<) relations and instances representing the "greater or equal" (≥) relation are converted to the "less or equal" (≤) relation. During this conversion the two arguments have to be switched.

If the instance of CNormalLogicalItem contains arguments, e.g. a relation, these arguments, which are instances of CNormalFraction, are simplified.