Next Previous Contents

13. Outlining - Simplifying complex expressions

Matlab enables the use of rather complex formula. These expressions are unwieldy. ADiMat may break up complex active expressions into many smaller expressions, this process is called 'outlining' in contrast to the inlining process performed by many compilers. The 'outlined' subexpressions are assigned to uniquely generated temporary variables. The temporary variables are inserted into the complex expression where the subexpression was removed. This process has some advantages:

  1. during the computation of the derivatives the differentiated expressions are shorter,
  2. the differentiated code is easier to check, and
  3. the time to compute the derivative of an expression is reduced, because instead of differentiating an expression a variable is used.
The decision where to take a subexpression out of the whole expression is made by rating each item (variable, operator, ...) of the expression using a cost function. If the costs of a subexpression exceed a user-defineable limit, the subexpression is outlined. The costs of a subexpression are defined by the table given below. The costs of each item where choosen with respect to the expected complexity of the derivative expression. The costs do not reflect a meassured execution time or likewise. The symbols used in the table are:
c

for constant expressions, like numbers or operations that do not contain an active variable,

x

for an active variable,

u,v,w

for subexpressions that may contain active variables,

f()

for calls to user-defined functions,

bui()

for calls to functions that are defined to be built into Matlab,

uc,vc,wc

for the costs of the corresponding subexpression,

infinity

telling that the coresponding expression is outlined where ever it occurs (See below for more information), and

SUM(i=1..n,expr)

for the sum of n summands of the expressions expr using i for indexing.


operation cost
v = cvc = 0
v = xvc = 1
v = u ± wvc = uc + wc
v = u * wvc = 2 * ( uc + wc)
vc = 4 * ( uc + wc )
v = ucvc = 3 * uc
v = u \ wvc = infinity
v= f(u1, ..., un)vc = infinity
v = bui(u1, ..., un)vc = SUM(i=1..n,uc,i)/n

Two expressions are rated to have infinite costs, because they have to be outlined whereever they occur. The backslash operator has to be outlined whereever it occurs, because the derivative expression uses the result of the original expression y=A\d. The computation of y is expensive, because the backslash-operator solves the linear equation A*y=d. Reusing the result is recommended therefore. The second expression that has to outlined whereever it occurs is the call of a user-defined function. The differentiated version of a user-defined function returns the double number of active results. A function that returns only one result in the original version, returns the original result and a derivative object in the differentiated version. To get both results of the differentiated version the function has to be called using an expression like [g y, y]= g f(...).


Next Previous Contents