bug-apl
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Standard way to compute a Mandelbrot fractal in APL


From: Dr . Jürgen Sauermann
Subject: Re: Standard way to compute a Mandelbrot fractal in APL
Date: Tue, 22 Sep 2020 15:16:08 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0

Hi Kacper,

thanks, fixed missing DOMAIN ERROR in SVN 1348.

Best Regards,
Jürgen


On 9/22/20 10:44 AM, Kacper Gutowski wrote:
On Mon, Sep 21, 2020 at 01:17:18PM +0800, Elias Mårtenson wrote:
What is the neatest way to compute a Mandelbrot fractal in APL? The fact
that you have to break out of the loop as soon as the absolute value of Z
is >2 makes it a bit ugly. Is there a neater way to do this?

This is what I came up with that works in GNU APL:

" #"[⌊0.5+50÷⍨ { (n ⊣ {(x+⍵×⍵) ⊣ n←n+1}⍣{(2<|⍺) ∨ n≥50} n←0) ⊣ x←⍵ }¨
(0J1×r) ∘.+ r←¯2+25÷⍨⍳100]


If you wanted to use different colors for different number of iterations before it escapes 2≥| disc, my only suggestion would be to get rid of each which makes it slow.  But since you only need one fixed threshold, I would do it like that:

      rr←(0J1×r) ∘.+ r←¯2+25÷⍨⍳100
      " #"[⎕IO+ 2≥| {⍺+×⍨⍵⊣((2<|,⍵)/,⍵)←2}⍣23⍨ rr]

(⍣23 instead of 25 because I start from ⍺ rather than from 0.)
Notably, if you use ⋆ with real right argument instead of ×, GNU APL has a bug where it returns infinity instead of a domain error, so you don't need to check for it ;)

      " #"[⎕IO+ 2≥| {⍺+⍵⋆2}⍣23⍨ rr]


/cc Jürgen:

      x←2⋆999
      x⋆2    ⍝ should be a domain error

      x⋆2J0  ⍝ like it is here
DOMAIN ERROR
      x⋆2
      ^^

-k



reply via email to

[Prev in Thread] Current Thread [Next in Thread]