Coprocessor

As stated in the chapter on the MandelbrotFast routine, the computation time for generating fractals can be significantly cut short by using the evalhf command, which uses the build-in coprocessor of your machine for a much more faster generation of the images. However you first have to transform the complex computation to the corresponding real arithmetics. This is being done by evalc.

If you have a complex formula such as 'z:=z^2+c' you have to proceed as follows:

evalc accepts only real-valued quantities for complex unknowns. So express z as 'z:=x+I*y' and c as 'c:=a+I*b':


> restart: interface(prettyprint=0);

> z:=x+I*y;
z := x+I*y

> c:=a+I*b;
c := a+I*b

Now apply evalc for both real and imaginary parts of z:

> real_part:=evalc(Re(z^2+c));
real_part := x^2-y^2+a

> imaginary_part:=evalc(Im(z^2+c));
imaginary_part := 2*x*y+b

R3> interface(prettyprint=2);

It is possible to conduct this transformation within the routine, however this slows it down. So to avoid the unnecessary call of functions each time a new point is evaluated build the formulas into the iteration part of the procedure by copying the results of evalc to it (hence you have to set the prettyprint environment variable of Maple V to zero; this, however, is not necessary in Release 4.).

This is the complex version of the Mandelbrot procedure:


> mandelbrot:=proc(x, y)
>    local z, c, m;
>    c:=evalf(x+y*I);
>    z:=evalf(x+y*I);
>    for m from 0 to 30 while abs(z)<2 do
>       z:=z^2+c
>    od;
>    m
> end:

Make changes so that afterwards the procedure looks something like this:

> mandelbrotfast:=proc(x, y)
>    local xn, xnold, yn, m;
>    xn:=x;  
>    yn:=y; 
>    # do not assign new values to the parameters x and y 
>    # of the procedure but store them in temporary variable xn, yn
>    # instead
>    for m from 0 to 100 while sqrt(evalhf(xn^2+yn^2)) < 2 do
>       xnold:=xn;   
>       # necessary for the parallel calculation of both xn and yn 
>       # independent of the prior assignment on xn in the same 
>       # iteration
>       xn:=evalhf(xn^2-yn^2+x); # here x is the real part of c
>       yn:=evalhf(2*xnold*yn+y); # replace all variables xn with 
>       # xnold, y is the imaginary part of c
>    od;
>    m
> end:

As stated above evalhf uses the build-in coprocessor (FPU - Floating Point Unit) of the computer and thus speeds up the computation. If your computer does not feature a FPU, Maple V automatically uses evalf with evalhf(Digits) digits. (evalhf(Digits) returns 14 on an Intel PC.) Please make sure that Digits <= evalhf(Digits), in order to benefit of the higher speed of evalhf.

Attention: If your FPU has one or more bugs like the built-in co-processor of the early Pentium 60 and 66 MHz versions, the result of the evalhf computation may in some cases be incorrect. Use evalf instead since this command relies on internal integer software routines which do not use the FPU. However concerning fractal images there should be no serious deviations from the correct results - if there are any.


last back next

MAPLE V FRACTALS Coprocessor #1.02 current as of July 27, 1997
Author: Alexander F. Walz, alexander.f.walz@t-online.de
Original file location: http://www.math.utsa.edu/mirrors/maple/mfrcopro.htm