Fractals/Iterations in the complex plane/MandelbrotSetExterior

Colouring of exterior of Mandelbrot set can be :
 * non-smooth = Escape Time = dwell
 * Boolean/binary Escape Time Method  ( bETM/M )
 * discrete = Level Set Method = LSM/M = integer ETM = iETM/M
 * Smooth :
 * radial measures
 * Real Escape Time Method( rETM/M )
 * Distance Estimation Method( DEM/M )
 * radius of complex potential = Complex Potential Method ( CPM/M )
 * angular measures
 * argument of complex potential
 * SAC = stripe average coloring
 * other
 * "triangle inequality"
 * Orbit trap

One can also draw curves :
 * external rays
 * equipotential lines ( closed curves - quasi circles)

Similar projects:
 * Mandelbrot Notebook by Claude Heiland-Allen
 * mandelbrot-book
 * mandelbrot-book/book : one file c programs, images and description
 * fork of the mandelbrot-book and book in pdf format
 * different drawing techniques and algorithms by Arnaud Cheritat
 * Mandelbrot set and example C programs ( not by A Cheritat)
 * Linas Vepstas' Art Gallery:
 * original site
 * fork at gitlab

Escape time or dwell
Here for given point c on parameter plane one checks how critical point $$ z = 0.0 $$ behaves on dynamical plane under forward iteration. If you change initial point you will get different result

To draw given plane one needs to check/scan (all) its points. See here for more details ( optimisation) Read definitions first.

How to find the number of iterations required to escape the mandelbrot set ?

 * math.stackexchange question: is-there-an-equation-for-the-number-of-iterations-required-to-escape-the-mandelb
 * math.stackexchange question: a-way-to-determine-the-ideal-number-of-maximum-iterations-for-an-arbitrary-zoom?

Boolean escape time
This algorithm answers the question: “For which values of c will the Julia fractal, J(c), be line-like and for which dust-like?”

Here complex plane consists of 2 sets : Mandelbrot set $$M\,$$ and its complement $$M^c\,$$ :

$$\mathbb{C}= M \cup M^c$$

ASCI graphic ( on screen)


Comparison programs in various languages

Graphic file ( PPM )
Here are various programs for creating pbm file
 * GLSL using shadertoy
 * short c programs by ed Burke

C
This is complete code of C one file program. For each point of screen (iX,iY) it's complex value is computed c=cx+cy*i.
 * It makes a ppm file which consists an image. To see the file (image) use external application ( graphic viewer).
 * Program consists of 3 loops:
 * iY and iX, which are used to scan rectangle area of parameter plane
 * iterations.

For each point c is computed iterations of critical point $$z_0 = z_{cr} = 0 \,$$

It uses some speed_improvement. Instead of checking :

sqrt(Zx2+Zy2)<ER

it checks :

(Zx2+Zy2)<ER2 // ER2 = ER*ER

It gives the same result but is faster.

Integer escape time = LSM/M = dwell bands
Here color is proportional to last iteration ( of final_n, final iteration).

This is also called Level Set Method ( LSM )

$$L_n= \{ c : z_n \in T \mbox{and} z_k \notin T \mbox{where} k<n \}\,$$

C


Difference between Mandelbrot algorithm and LSM/M is in only in part instruction, which computes pixel color of exterior of Mandelbrot set. In LSM/M is :

Here is C function whithout explicit complex numbers, only doubles:

here a short code with complex numbers:

C++
Here is C++ function which can be used to draw LSM/M :

I think that it can't be coded simpler (it looks better than pseudocode), but it can be coded in other way which can  be executed faster.

Here is faster code : A touch more optimised :

See also :
 * Rendering The Mandelbrot Set In C++: Part 1 - Saving Images, Video by Superdavo0001

GLSL

 * shadertoy

Java Script
Here is JavaScript function which does not give last iteration but LastIteration modulo maxCol. It makes colour cycling ( if maxCol < maxIt ).

Above functions do not use explicit definition of complex number.

Khan Academy

 * khan academy mandelbrot-set

Lisp program
Whole Lisp program making ASCII graphic based on code by Frank Buss

MathMap plugin for Gimp
filter mandelbrot (gradient coloration) c=ri:(xy/xy:[X,X]*1.5-xy:[0.5,0]); z=ri:[0,0]; # initial value z0 = 0 # iteration of z   iter=0; while abs(z)<2 && iter<31 do       z=z*z+c;  # z(n+1) = fc(zn) iter=iter+1 end; coloration(iter/32) # color of pixel end

Pov-Ray
Pov-Ray has a built-in function mandel

Wolfram Mathematica
Here is code by Paul Nylander

Level Curves of escape time Method = LCM/M


Lemniscates are boundaries of Level Sets of escape time ( LSM/M ). They can be drawn using :
 * edge detection of Level sets.
 * Algorithm described in paper by M. Romera et al. This method is fast and allows looking for high iterations.
 * boundary trace
 * drawing curves $$L_n(T)=\{c: abs(z_n)=ER \}\,$$, see  explanation and source code. This method is very complicated for iterations > 5.

Decomposition of target set for Mandelbrot set drawing
Decomposition is modification of escape time algorithm.

The target set is divided into parts (2 or more). Very large escape radius is used, for example ER = 12.

Binary decomposition of LSM/M


Here target set $$T\,$$ on dynamic plane is divided into 2 parts (binary decomposition = 2-decomposition ):


 * upper half ( white) $$T_u = \{ z : |z| > ER \mbox{and} Im (z) > 0\}\,$$
 * lower half (black) $$T_l = \{ z : |z| > ER \mbox{and} Im (z) \le 0 \}\,$$

Division of target set induces decomposition of level sets $$L_n\,$$ into $$2^{n+1}\,$$ parts ( cells, subsets):


 * $$L_{n,u} =\{ c:  |z_n| > ER \mbox{and} Im (z_n) > 0 \}\,$$ which is colored white,
 * $$L_{n,l} = \{ c : |z_n| > ER \mbox{and} Im (z_n) \le 0 \}\,$$ which is colored black.

"The Level Sets and Field Lines are superimposed, creating a sort of grid, and the "squares" of the grid are filled with N-digit binary numbers giving the first N binary digits of the external angles of field lines passing through the square. (Alternately, only the Nth binary digit is used.) Each level set is divided into 2n squares. It is easy to "read" the external arguments of points in the boundary of the Mandelbrot Set using a binary decomposition." Robert P. Munafo

For binary decomposition use exp(pi) as escape radius, so that the boxes appear square (a tip from mrob).

External rays of angles (measured in turns):

$$angle = (k / 2^n ) \mbox{mod }~1\,$$

can be seen as borders of subsets.

Difference between binary decomposition algorithm and Mandel or LSM/M is in only in part of instruction, which computes pixel color of exterior of Mandelbrot set. In binary decomposition is :

also GLSL code from Fragmentarium :

Point c is plotting white or black if imaginary value of last iteration ( Zy) is positive or negative.

nth-decomposition
This method is extension of binary decomposition.

The target set T = { z : |zn| > R } with a very large escape radius ( for example R = 12 ) is divided into more then 2 parts ( for example 8).

Real Escape Time
Other names of this method/algorithm are :
 * the fully-renormalized fractional iteration count ( by Linas Vepstas in 1997)
 * smooth iteration count for generalized Mandelbrot sets ( by Inigo Quilez in 2016)
 * continuous iteration count for the Mandelbrot set
 * Normalized Iteration Count Algorithm
 * Continuous coloring
 * smooth colour gradient
 * fractional iterations
 * fractional escape time

Here color of exterior of Mandelbrot set is proportional not to Last Iteration ( which is integer number) but to real number :


 * $$\nu(z) = \lim_{i \to \infty} (i - \log_2 \log_2 |z_i|)\,$$

Other methods and speedups

Colouring formula in Ultrafractal : smooth iter = iter + 1 + ( log(log(bailout)-log(log(cabs(z))) )/log(2)

where :
 * log(log(bailout) can be precalculated

theory
Description by Claude :

First description :

If R is large, the first z to escape satisfies (approximately)

$$R < |z| < R^p$$ so taking logs

$$\log(R) < \log(|z|) < p \log(R)$$

so taking logs again

$$\log(\log(R)) < \log(\log(|z|)) < \log(p) + \log(\log(R))$$

so by algebra

$$0 < \frac{\log(\log(|z|)) - \log(\log(R))}{\log(p)} < 1$$

when $$|z|$$ at escape is bigger, the smooth iteration count should be smaller, so this value needs to be subtracted from the integer iteration count

Alternatively this fraction can be used for interpolation, or used with arg(z) for exterior tiling / binary decomposition.

Second description

pick a radius R > 2, then |Z| > R implies that |Z^2 + C| > |Z| and more generally that |Z| -> infinity, this gives R the name escape radius. proof is on math.stackexchange.com somewhere

now suppose R is large, and n is the first iteration where |Z_n| > R.

consider what happens when |Z_n| increases as you move the point C a bit further from the Mandelbrot set boundary.

eventually |Z_n| > R^2, but then |Z_{n-1}| > R, so the iteration count should be n - 1.

for smoothing, we want a value to add to n that is 0 when |Z_n| = R and -1 when |Z_n| = R^2.

taking logs, get log |Z| is between log(R) and 2 log(R)

taking logs again, get log log |Z| is between log log R and log log R + log 2

dividing by log 2, get log_2 log |Z| is between log_2 log R and log_2 log R + 1

subtracting log_2 log R gives (log_2 log |Z| - log_2 log R) is between 0 and 1

negating it gives a value between 0 and -1, as desired

so the smooth iteration count is

$$n - (log_2 log |Z| - log_2 log R)$$

(replace 2 by P if you do Z^P + C)

see also http://linas.org/art-gallery/escape/escape.html which makes a value independent of R, but that is not so useful for some colouring algorithms (e.g. smooth part of escape count doesn't align with angle of final iterate)

C
To use log2 function add :


 * 1) include 

at the beginning of program.

where :
 * Zx2 = Zx*Zx
 * Zy2 = Zy*Zy

Here is another version by Tony Finch

based on equation
 * $$\nu(z) = n - \log_2 \log (z_n)\,$$

Matemathica
Here is code by Paul Nylander. It uses different formula :

$$cet = n + log_2ln(R) - log_2ln|z|$$

Python
Python code using mpmath library

Distance estimation DEM/M
Variants :
 * exterior DEM/M
 * interior DEM/M

Description

Complex potential
Description

=See also=
 * https://web.archive.org/web/20071008112609/http://rgba.scenesp.org/iq/trastero/fieldlines/
 * http://fraktal.republika.pl/mset_bottcher.html

=References=