Maximilian Kreuter | 1 May 01:14 2009

Optimization of Mandelbrot calculation

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 [

(Continue reading)

Maximilian Kreuter | 1 May 01:50 2009

Re: Optimization of Mandelbrot calculation

No doubt... these are very impressive and there are many programs out 
there, that can do this better than Maxima (e.g. XAOS).

But my approach is not to show stunning images and animations to the 
pupils but rather show them how the calculation is done.

Cheers

Maxx

Billinghurst, David (RTATECH) wrote:
> Have you seen these images?  http://pauillac.inria.fr/~ddr/mlbrot/
>
> David Billinghurst
>
>   
>> -----Original Message-----
>> From: maxima-bounces <at> math.utexas.edu 
>> [mailto:maxima-bounces <at> math.utexas.edu] On Behalf Of 
>> Maximilian Kreuter
>> Sent: Friday, 1 May 2009 09:15
>> To: maxima <at> math.utexas.edu
>> Subject: [Maxima] Optimization of Mandelbrot calculation
>>
>> 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.
>>
(Continue reading)

Mario Rodriguez | 1 May 02:22 2009
Picon

Re: Optimization of Mandelbrot calculation

El vie, 01-05-2009 a las 01:50 +0200, Maximilian Kreuter escribió:
> No doubt... these are very impressive and there are many programs out 
> there, that can do this better than Maxima (e.g. XAOS).
> 
> But my approach is not to show stunning images and animations to the 
> pupils but rather show them how the calculation is done.
> 
> Cheers
> 
> Maxx

Look at package fractals.mac:

http://maxima.cvs.sourceforge.net/viewvc/maxima/maxima/share/contrib/fractals/

Some graphics based on this package are at

http://www.telefonica.net/web2/biomates/maxima/gpdraw/image

--

-- 
Mario

_______________________________________________
Maxima mailing list
Maxima <at> math.utexas.edu
http://www.math.utexas.edu/mailman/listinfo/maxima
Adam Majewski | 1 May 09:50 2009
Picon

Re: Optimization of Mandelbrot calculation

Hi,

I'm not sure but maybe :
- writing procedure in Lisp is faster then Maxima
- compiling procodure makes it faster

About optimisation :
http://www.mrob.com/pub/muency/speedimprovements.html

also look at :
http://fisica.fe.up.pt/maxima/dynamicalsystems/index.html

Some images in Maxima :
http://apps.sourceforge.net/mediawiki/maxima/index.php?title=Gallery
http://commons.wikimedia.org/wiki/File:Mandelbrot_Components.svg
http://commons.wikimedia.org/w/index.php?title=File:ComponentNewton.png
http://commons.wikimedia.org/w/index.php?title=File:Jung200.png
http://commons.wikimedia.org/w/index.php?title=File:Jung50e.png

Adam
fraktal.republika.pl

Maximilian Kreuter pisze:
> 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 
(Continue reading)

Stavros Macrakis | 1 May 15:59 2009
Picon

Re: 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

_______________________________________________
Maxima mailing list
Maxima <at> math.utexas.edu
http://www.math.utexas.edu/mailman/listinfo/maxima
Pol | 1 May 15:40 2009
Picon

5.18.1-MacOS for mac tiger, 10.4.11

The last maxima package, 5.18.1-MacOS, does not work for Mac 10.4.11

Launching wxmaxima from terminal returns:

  pol$ /Applications/wx*/Co*/*OS/wxmaxima
dyld: Library not loaded: /usr/local/lib/libiconv.2.dylib
   Referenced from: /Applications/wxMaxima.app/Contents/MacOS/wxmaxima
   Reason: Incompatible library version: wxmaxima requires version 7.0.0 
or later, but libiconv.2.dylib provides version 5.0.0

Would it be possible to get a package for libiconv 5.0.0?

Thank you

----p
Robert Dodier | 1 May 16:52 2009
Picon

Re: Optimization of Mandelbrot calculation

On 4/30/09, Maximilian Kreuter <maxx <at> 2097.com> wrote:

>             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
>             ],

Enclosing the loop body in [ ] is valid Maxima syntax,
although the effect might be a little different than you expected.
block(a, b, c) or (a, b, c) group together expressions to be
evaluated sequentially, while [a, b, c] constructs a list.
Maxima evaluates list elements in order, so in this case
for ... do [a, b, c] has the same effect (fortuitously) as
for ... do (a, b, c). My advice is to write (a, b, c) unless you
really mean to construct a list.

best

Robert Dodier
Žiga Lenarčič | 1 May 20:22 2009
Picon

5.18.1-MacOS for mac tiger, 10.4.11

Hi!

Please try downloading it from wxMaxima's page:
http://downloads.sourceforge.net/wxmaxima/wxMaxima-0.8.2- 
Maxima-5.18.1.dmg?use_mirror=

This version shouldn't require 7.0.0. Please report if it works! If  
it works, I will upload it to Maxima's sourceforge too.

Regards,
Ziga
Dieter Kaiser | 1 May 20:53 2009
Picon

Bug with the global absflag

Alexey Beshenov has given an equation with roots which are real, but
seems to be complex. With the help of trigsimp and rectform we get the
expected real roots:

(%i83) sol : map ('rhs, solve (3*x^3  - 3*x + 1))$
(%i84) trigsimp(rectform(sol));
(%o84) [(sqrt(3)*sin(5*%pi/18)-cos(5*%pi/18))/sqrt(3),
        -(sqrt(3)*sin(5*%pi/18)+cos(5*%pi/18))/sqrt(3),
        2*cos(5*%pi/18)/sqrt(3)]

I have observed that the absolute values of the roots are not calculated
correctly. The correct absolute values can be obtained by doing an
additional rectform:

These values are not correct:

(%i88) abs(sol);
(%o88) [1/sqrt(3),1/sqrt(3),2/sqrt(3)]

Now the correct values:

(%i89) abs(rectform(sol));
(%o89) [sin(5*%pi/18)-cos(5*%pi/18)/sqrt(3),
        sin(5*%pi/18)+cos(5*%pi/18)/sqrt(3),2*cos(5*%pi/18)/sqrt(3)]

I think the problem is the global ABSFLAG. The function abs calls cabs
which sets ABSFLAG to TRUE. Later in the routine absarg the function
trisplit is called with the global ABSFLAG set to TRUE. This causes
wrong results for the real and imaginary part of the expression. We can
see it more directly:

We pick up the first solution:

(%i14) a:sol[1];
(%o14) (sqrt(3)*%i/2-1/2)/(3*(3^-(3/2)*%i/2-1/6)^(1/3))
        +(3^-(3/2)*%i/2-1/6)^(1/3)*(-sqrt(3)*%i/2-1/2)

That is the result of rectform:

(%i15) rectform(a);
(%o15) %i*((sqrt(3)*sin((%pi-atan(3*3^-(3/2)))/3)/2
          +3*cos((%pi-atan(3*3^-(3/2)))/3)/2)
          /3
          -sin((%pi-atan(3*3^-(3/2)))/3)/(2*sqrt(3))
          -cos((%pi-atan(3*3^-(3/2)))/3)/2)
        +(3*sin((%pi-atan(3*3^-(3/2)))/3)/2
         -sqrt(3)*cos((%pi-atan(3*3^-(3/2)))/3)/2)
         /3+sin((%pi-atan(3*3^-(3/2)))/3)/2
        -cos((%pi-atan(3*3^-(3/2)))/3)/(2*sqrt(3))

These are the simplified real and imaginary parts:

(%i16) trigsimp(realpart(a));
(%o16) (sqrt(3)*sin(5*%pi/18)-cos(5*%pi/18))/sqrt(3)
(%i17) trigsimp(imagpartpart(a));
(%o17) imagpartpart(-((%i-sqrt(3))^(2/3)*(3*sqrt(3)*%i+3)
                     -3^(5/6)*6^(2/3)*%i+3^(1/3)*6^(2/3))
                     /(6*3^(1/6)*6^(1/3)*(%i-sqrt(3))^(1/3)))
(%i18) trigsimp(imagpart(a));
(%o18) 0

Now, we set the global flag ABSFLAG and we get the wrong results which
are returned by absarg too:

(%i19) :lisp (setq absflag t)
T
(%i19) trigsimp(realpart(a));
(%o19) -1/sqrt(3)
(%i20) trigsimp(imagpart(a));
(%o20) 0
(%i21) rectform(a);
(%o21) -1/sqrt(3)

A solution would be to cut off the global flag completely. (See also the
corrected bug for powers with complex numbers. Here absflag causes the
problem too.)

Dieter Kaiser
Oliver Kullmann | 1 May 21:12 2009
Picon
Picon

Re: can't build Maxima 5.18.1 with Ecl 9.4.1

On Wed, Apr 22, 2009 at 04:12:12PM -0600, Robert Dodier wrote:
> On Wed, Apr 22, 2009 at 12:36 PM, Oliver Kullmann
> <O.Kullmann <at> swansea.ac.uk> wrote:
> 
> > when building Maxima 5.18.1 with Ecl version 9.4.1
> > I get right at the start the following error:
> 
> Hmm. I have just built Maxima 5.18.1 + ECL 9.4.1 on Linux.
> Are you using the standard incantation
> 
> sh bootstrap && ./configure --enable-ecl && make
> 
> ?
> 
> Sorry I can 't be more helpful.
> 
> Robert Dodier

It seems the above error was related to some gcc/ld problems;
solved now!

thanks!

Oliver

Gmane