next up previous contents
Next: Generating code Up: Interval evaluation in ALIAS-Maple Previous: Interval valuation and the   Contents


Interval evaluation of an expression in Maple

Maple provides the package evalr that calculate the interval evaluation of an expression. An example follows:

 
readlib(evalr):
X:=INTERVAL(0..1):
evalr(sin(X)*cos(X)+X);
But this package does not evaluate correctly some expressions (for example X-X will be evaluated to 0 whatever is the interval for X). ALIAS-Maple provides the procedure Interval that allows for the interval evaluation of an expression as shown in the following example:
 
Interval([x*cos(y)+sin(x*y),x^2-cosh(y)],[x,y],[[-2,2],[-2,2]]);
               [[[-3, 3]], [[-7.3890560989307,3.8646647167634]]]
The first argument is a list of expression, the second argument is the name of the variables and the third a list of intervals for the variables. The procedure generates a C++ program and hence may take some seconds. But as soon as the executable has been created it is possible to re-use it with other intervals using the Restart procedure
 
Restart("Interval",[[-0.5,0.5],[-0.5,0.5]]);
Note however that as soon as you have defined the `ALIAS/ID` string before generating an executable it is necessary to reset this string to the same name before using the Restart procedure to re-run the same executable

An optional 4th argument allows to control the evaluation. Indeed by default the expression will be transformed into a compact form (as provided by the procedure MinimalCout) that may lead to a better evaluation. The fourth argument may be:

Here is an example:
 
Interval([x*sin(x)+cos(x)],[x],[[0,1]]);
          [[[.54030230586814, 1.8414709848079]]]

Interval([x*sin(x)+cos(x)],[x],[[0,1]],"Gradient");
                  [[[1, 1.381773290676]]]
in which the use of the "Gradient" option allows to get the exact interval evaluation. It must be reminded that the interval evaluation of an expression is very sensitive to the manner with which the expression is written. For example the expression $x^2+2x+1$ for $x$ in the interval [-1,1] is evaluated as:
 
Interval([x^2+2*x+1],[x],[[-1,1]],"AsIt");
                        [[[-1, 4]]]
If the option AsIt is not used ALIAS will convert the expression into the Horner form $x(x+2)+1$:
 
Interval([x^2+2*x+1],[x],[[-1,1]]);       
                        [[[-2, 4]]]
Here it may be noticed that the Horner form leads to a worst interval evaluation. But we may factor this expression as $(x+1)^2$:
 
Interval([(x+1)^2],[x],[[-1,1]],"AsIt");  
                        [[[0, 4]]]


next up previous contents
Next: Generating code Up: Interval evaluation in ALIAS-Maple Previous: Interval valuation and the   Contents
Jean-Pierre Merlet 2012-12-20