# Fractals/color julia

## Visualising complex functions

Suppose we want to visualise a complex valued function like

{\displaystyle {\begin{aligned}f:\mathbb {C} &\;\to \mathbb {C} \\z&\;\mapsto w=f(z)\\\end{aligned}}}

In order to color ${\displaystyle w}$ we decompose it into its absolute value ${\displaystyle |w|}$ and its argument ${\displaystyle \arg(w)}$.

Then, we assign the color

${\displaystyle \mathrm {HSV} \left({\tfrac {1}{2\pi }}\arg(w),\;1-g_{a_{s},b_{s}}(|w|),\;g_{a_{v},b_{v}}(|w|)\right)}$

to the point representing ${\displaystyle z}$. In this HSV color space, all values are in the range from 0 to  1. The first component (hue) of the HSV color depends only on the argument of ${\displaystyle w}$ and the second and third component (saturation and value) depend only on the absolute value of ${\displaystyle w}$. We use a transformation ${\displaystyle g_{a,b}}$ on ${\displaystyle w}$ to map it into the interval ${\displaystyle [0,1]}$. For ${\displaystyle g}$ see section helper functions.

### Examples

The values indexed s (saturation) control the transition saturated colors→white (resp. gray scale), i.e. intermediate values → infinity. The values indexed h (value/valenz) control the transition black→bright, i.e. zero→nonzero. Parameter a controls where the transition takes place: a is just the radius of the circle dividing the two regions (dark/bright, saturated/gray, etc.) Parameter b controls how sharp the transition is: b small = soft, b large = sharp.

The following images all show the range [-10,10]×[-10,10]${\displaystyle i}$ and use ${\displaystyle a_{s}=5}$ (radius of rainbow) and ${\displaystyle a_{v}=1}$ (radius of black disc).

In the image with swapped meanings of S and V zero is printed in white and infinity in black.

## Visualising Julia sets

Julia sets and Fatou sets can be nice. Their computergraphical generation can be hard.

In the remainder of this page, we work out a method which can be used to visualise the Julia set of a complex function ƒ. The advantage is that you don't need to know attractors of the iteration

${\displaystyle z\mapsto f(z)}$

The generated images will be smooth in the Fatou part.

### Overview: Imaging methods

Note that there exist other approaches to color complex dynamical systems like

#### Inverse Iteration Method (IIM)

Compute the preimages of ƒ, i.e. compute the reverse orbit. Because the stability of the fixed points turns from attractive to repelling and vice versa, one just choses a complex number and looks where it goes under the invers iteration. The trouble is that the results will not uniformly distributet in ${\displaystyle J}$ and that you have to compute the inverse of ƒ.

#### Coloring by speed of attraction (CSA)

Taking a value from the lattice of points to color, perform iterations until the iterative is close to an attractor. Color the point according to the number of iterations needed to bring it close enough to the attractor.

This method is commonly used to visualize Julia sets of polynomials and Julia sets that are attached to Newton's famous method for finding the zeros of a function. Polynomials or degree > 1 always have infinity as a super-attractive fixed point. The rational function that occurs in Newton's method has always the function's roots as attractive fixed points. However, in both cases there may be other attractors, which – moreover – need not to consist of just one point.

#### Escape Time Algorithm (ETA)

If ∞ is an attractor, i.e. a fixed point of the process, then color the point according to the number of iterations – the time – it takes until one sees the point escapes towards ∞. If the point does not escape during the maximum number of iterations, the point is colored as belonging to the Julia set or to the basin of some other attractor. This method works for polynomials. The most prominent Julia sets are the ones for zz2+c where c is an element of the Mandelbrot set or not far away from the mandelbrot set. If you see a picture of such a Julia set, it is likely that ETA had been used to get the picture.

#### Cauchy Convergence Algorithm (CCA)

In the remainder of this page, I will present a different approach whose idea as basically the same es that of Escape Time Algorithm. However, no basin of attraction must be known in advance and the different basins of attraction can be separated and be colored differently. The approch uses the notion of Cauchys convergence. Instead of observing the orbit of a point, this method observes how the distance of two nearby points z and z+ε evolves as these two values are iterated. If the difference tends to 0, then the point heads for an attractor. If the difference does not approach 0, then the point is close to (or a part of) the Julia set.

##### The Metric

Let ${\displaystyle \varrho }$ be a canonical projection of the compactified complex plane onto the Riemann sphere S2:

${\displaystyle \varrho :{\overline {\mathbb {C} }}=\mathbb {C} \cup \{\infty \}\rightarrow S_{2}}$

This gives us a metric d: As distance between two points in the complex plane we take their distance on the sphere, i.e. the length of the orthodrome. This means that the metric is bounded by π and even the distance to ∞ (which is now the north pole) is finite.

In order to compute the distance between two points z and w we rotate the sphere S2 in such a way that

1. w maps to 0
2. z maps to the positive real axis

After these transformations the distance can be computed quite easily. The rotation can be accomplished by a squence of isometric Möbius transformations. All an all, we get

${\displaystyle t_{w}:z\mapsto {\begin{cases}|z|\;,&{\text{ if }}w=0\\{\textstyle {\frac {1}{|z|}}}\;,&{\text{ if }}w=\infty \\{\textstyle {\frac {1}{|w|}}}\;,&{\text{ if }}z=\infty \\&\\{\textstyle {\frac {1}{|w|}}}\cdot \left|{\frac {z{\overline {w}}-|w|^{2}}{z{\overline {w}}+1}}\right|\;,&{\text{ else}}\end{cases}}}$

which is left as an exercise to the reader. The bar denotes complex conjugation. The metric is then

${\displaystyle d(z,w)=\,\!2\arctan(t_{w}(z))}$

The nice feature that is introduced by d is that sequences that formerly diverged against infinity now converge towards infinity, i.e. towards the north pole of S2.

##### Stability of Orbits

Recall the definition of the Julia set for a contraction mapping ƒ. The definition implies some facts on the stability of the iteration

${\displaystyle z\mapsto f(z)\mapsto f^{2}(z)\mapsto f^{3}(z)\mapsto \cdots }$

where ƒn denotes the n-th iterative of ƒ:

${\displaystyle f^{\,n}=f\circ f\circ \cdots \circ f}$

The set

${\displaystyle \{f^{\,n}(z)\}_{n\in \mathbb {N} _{0}}}$

is called Orbit of z (under ƒ).

The orbits of two points z and w behave similar − in some sense − if z and w lie close together and belong to the Fatou set Fƒ which is the complement of the Julia set Jƒ of ƒ. If z is an element of Jƒ then z and w will behave quite different, even if w itself is an element of Jƒ.

To get a notion of the stability of an orbit, we set

${\displaystyle \Sigma _{n}(z)=\Sigma _{n}(z,\varepsilon )=\sum _{k\leqslant n}d\,(f^{k}(z),f^{k}(z+\varepsilon ))}$

for a small ε and with the metric d from above. This means that we take two points which are close together, and then we summarize their distances as ƒ makes them jump around on the Riemann sphere. Note that for any fixed ε the sum can diverge for large n even if z is a Fatou point.

However, we can use Σn to measure how close a point is to Jƒ: the larger the sum is, the more instable is the iteration and the closer is the point to the Julia set of ƒ.

To destinguish points of (or close to) the Julia set from points in the Fatou set, we need a creterion. To get it, we compute all the Σ-values for the points that we want to color, i.e. for all points in a lattice Γ. After computing these values, we do a little bit of statistics to get the expected value E and the standard deviation σ for the set of Σ-values: Let

{\displaystyle {\begin{aligned}E_{n}&=E_{n}(\Gamma ,\varepsilon )=E\left\{\log(\delta +\Sigma _{n}(z,\varepsilon ))\right\}_{\!z\,\in \,\Gamma }\\\sigma _{n}&={\sqrt {D_{n}}}\\\end{aligned}}}

Remind that

{\displaystyle {\begin{aligned}EX&={\textstyle {\frac {1}{|X|}}}\sum \limits _{x\in X}x\\D\!X&=EX^{2}-(EX)^{2}\\\end{aligned}}}

It turns out that the values Σ are widely spread over several scales. Therefore, we do not use Σ directly. Instead, we use the logarithm of Σ. The value δ is just a small constant to avoid the logarithm's input to be zero.

##### Coloring

Now, we have all we need to color a point:

1. choose
1. a lattice ${\displaystyle \Gamma }$ of points ${\displaystyle z}$ to color
2. the number ${\displaystyle n}$ of iterations to perform
3. a small ${\displaystyle \varepsilon }$
2. for all points, compute ${\displaystyle \Sigma _{n}(z,\varepsilon )}$
3. compute ${\displaystyle E_{n}}$ and ${\displaystyle \sigma _{n}}$
4. compute
${\displaystyle J(z)=\,\ln(\delta +\Sigma _{n}(z))-K}$

for some constant ${\displaystyle K}$. Because ${\displaystyle K}$ will be used to separate points that belong to the Julia set (${\displaystyle J(z)>0}$) from points that to not (${\displaystyle J<0}$), reasonable values for ${\displaystyle K}$ are greater than ${\displaystyle E_{n}}$. Try settings like ${\displaystyle K=E_{n}+2\sigma _{n}}$ or ${\displaystyle E_{n}+\sigma _{n}}$ or the like. If ${\displaystyle J(z)>0}$ then we color ${\displaystyle z}$ as belonging to the Julia set. If ${\displaystyle J(z)<0}$ we can use that value to shade the Fatou set. If we know some attractor, we can check if ƒ${\displaystyle n}$${\displaystyle (z)}$ is close to it and use that information, too.

To map values to the valid ranges for saturation and brightness we use the function ${\displaystyle h}$ from section helper function h.

##### Modifications

The computation of ${\displaystyle E_{n}}$ takes a lot of time. The visualisation process needs two passes:

1. compute ${\displaystyle E_{n}}$ from all ${\displaystyle \Sigma _{n}(z)}$
2. color the points using ${\displaystyle E_{n}}$ and recomputed ${\displaystyle \Sigma _{n}(z)}$

Alternatively

1. compute and store all ${\displaystyle \Sigma _{n}(z)}$
2. compute ${\displaystyle E_{n}}$ and color the points

An other approach looks like that:

Find the smallest ${\displaystyle n}$ so that ${\displaystyle d_{k}(z,z+\varepsilon )}$ is below a given bound for all ${\displaystyle k\geq n}$. If no such ${\displaystyle n}$ can be found, then assume ${\displaystyle z}$ to be an element of the Julia set. Otherwise, use ${\displaystyle n}$ to color the Fatou set.

This algorithm is a variant of the escape time algorithm (ETA). Note that in ETA the point does not really escape (at least if we are on the sphere), it just converges to ∞. This approach is similar. However, we don't need to know an attractive fixed point of ƒ.

Up to now, I didn't try the modified version. One disadvantage may be that the Fatou set will no more appear smooth colored. Then I am not sure if this modification is really an advantage, because the iteration must be done until a given maximum number of iterations is reached. Note that even if ${\displaystyle d_{n}}$ is under the bound for some ${\displaystyle n}$ the distance ${\displaystyle d_{k}}$ can rise again. I cannot say if this effect is crucial or can be neglected...

${\displaystyle N}$ denotes the Newton operator

${\displaystyle N:f\mapsto {\mathit {id}}-{\frac {f}{f'}}}$

#### Using Critical Points Absorption (CPA)

The previous method yeilds neat, smooth colorings and requires least knowledge about the dynamics of the process. However, it is quite time consuming. Teh following approach is an extension of escape time algorithm (ETA) for polynomials.

Let ƒ be a polynomial of degree d > 1 over C. Such a polynomial has at most d critical points: infinity and the at most d–1 zeroes of ƒ′. It is well known that each attractor of the process z→ƒ(z) absorbs at least one critical point. Suppose zK is a critical value, then ƒn(zK) comes arbitrarirly close to one of the attractive cycles of ƒ.

A process for a quadratic polynomial ƒ(z) = z2 + c is the simplest case: The critical values are 0 and  ∞. As ∞ absorbs itself, only 0 is left, and we have the following cases. M denotes the Mandelbrot set.

${\displaystyle c\notin M}$
Easy case. 0 is absorbed by ∞, and J(ƒ) consists just of Cantor dust. Escape time to ∞ can be used to color all points.
${\displaystyle c\in M\setminus \partial M}$
If c is an element of the interior of M, then 0 will be absorbed by a (super) attractive cycle. Compute
${\displaystyle w=w(c,n)=f^{n}(0)}$
for a sufficiently large n. As w (basically) only depends on c, it can be precomputed before starting the visualization of J(ƒ). Notice that w is the element of a cycle that might have more than one element, i.e. w is only unique modulo that cycle.
Coloring for a point z in C is then as easy as ETA:
• If z is absorbed by ∞, use escape time to color z.
• If ƒn(z) comes close to w, i.e if |ƒn(z) – w| < ε for the first time, use that n to color z.
• If ƒn(z) neither comes close to ∞ nor comes close to w, then color z as part of J(ƒ). Only few z will fall into this category.

## Helper functions

### Helper function t

is a smooth, monotone sigmoidal transition from −1 to 1 that satisfies ${\displaystyle t'(0)=1}$ and ${\displaystyle t(x)=-t(-x)}$. There are many choices for it. Some of them are

{\displaystyle {\begin{aligned}t:\mathbb {R} &\to (-1,1)\\x&\mapsto \tanh \,x\\&\mapsto {\tfrac {2}{\pi }}\arctan \left({\tfrac {\pi }{2}}x\right)\\&\mapsto {\tfrac {2}{\pi }}\operatorname {gd} \left({\tfrac {\pi }{2}}x\right)\\&\mapsto {\frac {x}{\sqrt {1+x^{2}}}}\\&\mapsto {\frac {x}{1+|x|}}\\\end{aligned}}}

with gd denoting the gudermannian function.

### Helper function h

Helper function ${\displaystyle h_{a}}$ is almost the same like ${\displaystyle t}$ but it maps to ${\displaystyle (0,1)}$ and we can adjust the speed of transition by parameter ${\displaystyle a}$.

{\displaystyle {\begin{aligned}h_{a}:\mathbb {R} &\to (0,1)\\x\;&\mapsto {\tfrac {1}{2}}+{\tfrac {1}{2}}t(2ax)\end{aligned}}}

with ${\displaystyle a>0}$. Then ${\displaystyle h_{a}}$ is symmetric to the point (0, 1/2) and

{\displaystyle {\begin{alignedat}{2}h_{a}&(0)&&={\tfrac {1}{2}}\\h'_{a}&(0)&&=a\\h_{a}&(-\infty )&&=0^{+}\\h_{a}&(\infty )&&=1^{-}\\\end{alignedat}}}

Negative values are mapped to values between 0 and 1/2. Positive values are mapped to values between 1/2 and 1. The parameter ${\displaystyle a}$ controls how fast the transition will be.

If we want a falling function, we can use the symmetry

${\displaystyle h_{a}(x)\,=1-h_{a}(-x)=1-h_{-a}(x)}$

i.e. we negate ${\displaystyle x}$ or ${\displaystyle a}$.

### Helper function g

This function maps the positive numbers to the interval ${\displaystyle [0,1)}$.

{\displaystyle {\begin{aligned}g_{a,b}:\mathbb {R} ^{\geqslant \,0}&\to (0,1)\\x\;&\mapsto {\tfrac {1}{2}}+{\tfrac {1}{2}}\,t(2b\cdot a\cdot u(x/a))\end{aligned}}}

for some function ${\displaystyle u}$ that is defined below. If ${\displaystyle u}$ is appropriately chosen then for ${\displaystyle g}$ the following holds

${\displaystyle {\begin{array}{lll}g_{a,b}(0)&=&0\\g_{a,b}(\infty )&=&1\\g_{a,b}(a)&=&1/2\\g'_{a,b}(a)&=&b\\g'_{a,b}(x)&>&0{\text{ for }}x>0\end{array}}}$

This means that ${\displaystyle g_{a,b}}$

• grows continuously from 0 to 1 as ${\displaystyle x}$ grows from ${\displaystyle 0}$ to ${\displaystyle \infty }$
• we can control where ${\displaystyle g}$ crosses the middle between 0 and 1 by specifying parameter ${\displaystyle a}$
• we can control how fast ${\displaystyle g}$ passes the point ${\displaystyle (a,1/2)}$ by specifying parameter ${\displaystyle b}$

We are left with determining the finction ${\displaystyle u}$ on ${\displaystyle \mathbb {R} ^{>0}}$ with

${\displaystyle u}$ must satisty

${\displaystyle {\begin{array}{lll}u(0^{+})&=&-\infty \\u(\infty )&=&\infty \\u(1)&=&0\\u'(1)&=&1\end{array}}}$

For ${\displaystyle u}$ we set

${\displaystyle u(x)={\tfrac {1}{2}}\left(x-{\tfrac {1}{x}}\right)}$

### Helper function w

This function maps the positive numbers to the interval ${\displaystyle [0,1)}$.

{\displaystyle {\begin{aligned}w_{a}:\mathbb {R} ^{\geqslant \,0}&\to [0,1)\\x\;&\mapsto t(ax)\end{aligned}}}

By ${\displaystyle a}$ we can control its slope in the origin:

${\displaystyle w'(0)=\,a}$

### Circular arc through (0,0) and (1,1)

A circular arc through (0,0) and (1,1) that has given slope of ${\displaystyle a}$ in (0,0) and ${\displaystyle -1/a}$ in (1,1):

${\displaystyle \operatorname {arc} (x)={\begin{cases}x&;{\text{ if }}a=1\\y_{0}+\operatorname {sign} (\ln a){\sqrt {r^{2}-(x-x_{0})^{2}}}&;{\text{ if }}a\neq 1\\\end{cases}}}$

where

{\displaystyle {\begin{aligned}x_{0}&={\frac {a}{a-1}}\\y_{0}&=1-x_{0}\\r&={\sqrt {x_{0}^{2}+y_{0}^{2}}}\\\end{aligned}}}

The center of the circle is incident on the line ${\displaystyle y=1-x}$.