Optimization of Mandelbrot calculation



If you don't do anything special, Maxima will a) run interpretively and b)
assume that all variables are general symbolic expressions, not numbers.

You should be able to speed up the calculation by one or more orders of
magnitude by declaring all numeric variables (? mode_declare) and compiling
the function (? compile), something like this:

/* slow-converging series demo */
pisq(n) := 6*block( [x:0.0, i:float(n)], mode_declare([x,i],float), while
i>0.0 do (x : x + 1/(i*i), i: i - 1.0 ), x )$

pisq(1000000)$
Evaluation took 11.8600 seconds (11.8600 elapsed)

compile(pisq)$
WARNING-> Assigning variable n, whose mode is float,a value of mode any.
Compiling C:/DOCUME~1/SMACRA~1/LOCALS~1/Temp/gazonk_3324_0.lsp.
End of Pass 1.
End of Pass 2.
OPTIMIZE levels: Safety=2, Space=3, Speed=3
Finished compiling C:/DOCUME~1/SMACRA~1/LOCALS~1/Temp/gazonk_3324_0.lsp.
Evaluation took 1.2100 seconds (1.2100 elapsed)

pisq(1000000);
Evaluation took 0.2900 seconds (0.2900 elapsed)

40x improvement.

You might be able to get an additional small improvement by coding in Lisp
yourself, but it is unlikely to be worth it, and doesn't add anything to
your pedagogical goals....

            -s

On Thu, Apr 30, 2009 at 7:14 PM, Maximilian Kreuter <maxx at 2097.com> wrote:

> Hi,
>
> Im using Maxima at my school and I like to use it teaching complex
> numbers and chaos theory. Therefore I like to show how to calculate and
> display the Mandelbrot-Set.
>
> I already got it working so far (you can look at it below). The only
> problem i have is that the execution gets very slow (and sometimes takes
> forever), when I choose a lower value for the parameter "resolution"
> (e.g. 0.01 instead of 0.02).
>
> Is there anything I could do to optimize this, or any setting i could
> change to run this faster?
>
> BTW... Im using wxMaxima on Windows.
>
> Any suggestions welcome;)
>
> Cheers
>
> Maxx
>
>
>
>
> mandel(reMin, reMax, imMin, imMax, resolution, iterations):=block(
>    [reZ, imZ, absZ, i, pixels, reTemp],
>
>    pixels:[[0,0]],
>
>    for x:reMin step resolution thru reMax do [
>        for y:imMin step resolution thru imMax do [
>
>            reZ:0,
>            imZ:0,
>            absZ:0,
>
>            for i:1 step 1 thru iterations while absZ < 4 do [
>                reTemp:reZ^2 - imZ^2 + x,
>                imZ:2*reZ*imZ + y,
>                reZ:reTemp,
>                absZ:reZ^2+imZ^2
>            ],
>
>            if absZ < 4 then pixels:append(pixels,[[x,y]])
>
>        ]
>    ],
>
>    return(pixels)
> )$
>
> plot2d([discrete, mandel(-2,0.5,-1,1, 0.02, 16)],[style,
> [points,0.2,1,1]]);
>
>
>
>
>
>
>
>
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>