# Julia set

In complex dynamics, the Julia set and the Fatou set are two complementary sets (Julia "laces" and Fatou "dusts") defined from a function. Informally, the Fatou set of the function consists of values with the property that all nearby values behave similarly under repeated iteration of the function, and the Julia set consists of values such that an arbitrarily small perturbation can cause drastic changes in the sequence of iterated function values. Thus the behavior of the function on the Fatou set is "regular", while on the Julia set its behavior is "chaotic".
The Julia set of a function  f  is commonly denoted $\operatorname {J} (f),$ and the Fatou set is denoted $\operatorname {F} (f).$ These sets are named after the French mathematicians Gaston Julia and Pierre Fatou whose work began the study of complex dynamics during the early 20th century.

## Formal definition

Let $f(z)$ be a non-constant meromorphic function from the Riemann sphere onto itself. Such functions $f(z)$ are precisely the non-constant complex rational functions, that is, $f(z)=p(z)/q(z)$ where $p(z)$ and $q(z)$ are complex polynomials. Assume that p and q have no common roots, and at least one has degree larger than 1. Then there is a finite number of open sets $F_{1},...,F_{r}$ that are left invariant by $f(z)$ and are such that:
* The union of the sets $F_{i}$ is dense in the plane and
* $f(z)$ behaves in a regular and equal way on each of the sets $F_{i}$.
The last statement means that the termini of the sequences of iterations generated by the points of $F_{i}$ are either precisely the same set, which is then a finite cycle, or they are finite cycles of circular or annular shaped sets that are lying concentrically. In the first case the cycle is attracting, in the second case it is neutral.
These sets $F_{i}$ are the Fatou domains of $f(z)$, and their union is the Fatou set $\operatorname {F} (f)$ of $f(z)$. Each of the Fatou domains contains at least one critical point of $f(z)$, that is, a (finite) point z satisfying $f'(z)=0$, or $f(z)=\infty$ if the degree of the numerator $p(z)$ is at least two larger than the degree of the denominator $q(z)$, or if $f(z)=1/g(z)+c$ for some c and a rational function $g(z)$ satisfying this condition.
The complement of $\operatorname {F} (f)$ is the Julia set $\operatorname {J} (f)$ of $f(z)$. If all the critical points are preperiodic, that is they are not periodic but eventually land on a periodic cycle, then $\operatorname {J} (f)$ is all the sphere. Otherwise, $\operatorname {J} (f)$ is a nowhere dense set (it is without interior points) and an uncountable set (of the same cardinality as the real numbers). Like $\operatorname {F} (f)$, $\operatorname {J} (f)$ is left invariant by $f(z)$, and on this set the iteration is repelling, meaning that $|f(z)-f(w)|>|z-w|$ for all w in a neighbourhood of z (within $\operatorname {J} (f)$). This means that $f(z)$ behaves chaotically on the Julia set. Although there are points in the Julia set whose sequence of iterations is finite, there are only a countable number of such points (and they make up an infinitesimal part of the Julia set). The sequences generated by points outside this set behave chaotically, a phenomenon called deterministic chaos.
There has been extensive research on the Fatou set and Julia set of iterated rational functions, known as rational maps. For example, it is known that the Fatou set of a rational map has either 0, 1, 2 or infinitely many components. Each component of the Fatou set of a rational map can be classified into one of four different classes.

## Equivalent descriptions of the Julia set

* $\operatorname {J} (f)$ is the smallest closed set containing at least three points which is completely invariant under f.
* $\operatorname {J} (f)$ is the closure of the set of repelling periodic points.
* For all but at most two points $\;z\in X\;,$ the Julia set is the set of limit points of the full backwards orbit $\bigcup _{n}f^{-n}(z).$ (This suggests a simple algorithm for plotting Julia sets, see below.)
* If f is an entire function, then $\operatorname {J} (f)$ is the boundary of the set of points which converge to infinity under iteration.
* If f is a polynomial, then $\operatorname {J} (f)$ is the boundary of the filled Julia set; that is, those points whose orbits under iterations of f remain bounded.

## Properties of the Julia set and Fatou set

The Julia set and the Fatou set of f are both completely invariant under iterations of the holomorphic function f:
    $f^{-1}(\operatorname {J} (f))=f(\operatorname {J} (f))=\operatorname {J} (f),$
    $f^{-1}(\operatorname {F} (f))=f(\operatorname {F} (f))=\operatorname {F} (f).$

## Examples

For $f(z)=z^{2}$ the Julia set is the unit circle and on this the iteration is given by doubling of angles (an operation that is chaotic on the points whose argument is not a rational fraction of $2\pi$). There are two Fatou domains: the interior and the exterior of the circle, with iteration towards 0 and ∞, respectively.
For $g(z)=z^{2}-2$ the Julia set is the line segment between −2 and 2. There is one Fatou domain: the points not on the line segment iterate towards ∞. (Apart from a shift and scaling of the domain, this iteration is equivalent to $x\to 4(x-{\tfrac {1}{2}})^{2}$ on the unit interval, which is commonly used as an example of chaotic system.)
The functions f and g are of the form $z^{2}+c$, where c is a complex number. For such an iteration the Julia set is not in general a simple curve, but is a fractal, and for some values of c it can take surprising shapes. See the pictures below.
For some functions f(z) we can say beforehand that the Julia set is a fractal and not a simple curve. This is because of the following result on the iterations of a rational function:
Theorem — Each of the Fatou domains has the same boundary, which consequently is the Julia set.
This means that each point of the Julia set is a point of accumulation for each of the Fatou domains. Therefore, if there are more than two Fatou domains, each point of the Julia set must have points of more than two different open sets infinitely close, and this means that the Julia set cannot be a simple curve. This phenomenon happens, for instance, when f(z) is the Newton iteration for solving the equation $\;P(z):=z^{n}-1=0~:~n>2\;$:
    $f(z)=z-{\frac {P(z)}{P'(z)}}={\frac {\;1+(n-1)z^{n}\;}{nz^{n-1}}}~.$
The image on the right shows the case n = 3.

## Quadratic polynomials

A very popular complex dynamical system is given by the family of complex quadratic polynomials, a special case of rational maps. Such quadratic polynomials can be expressed as
    $f_{c}(z)=z^{2}+c~,$
where c is a complex parameter. Fix some $R>0$ large enough that $R^{2}-R\geq |c|.$ (For example, if c is in the Mandelbrot set, then $|c|\leq 2,$ so we may simply let $R=2~.$) Then the filled Julia set for this system is the subset of the complex plane given by
    $K(f_{c})=\left\{z\in \mathbb {C} :\forall n\in \mathbb {N} ,|f_{c}^{n}(z)|\leq R\right\}~,$
where $f_{c}^{n}(z)$ is the nth iterate of $f_{c}(z).$ The Julia set $J(f_{c})$ of this function is the boundary of $K(f_{c})$.
* Julia sets for $z^{2}+0.7885\,e^{ia},$ where a ranges from 0 to $2\pi$
* A video of the Julia sets as left
* Filled Julia set for f$_c$, c = 1 − φ, where φ is the golden ratio
* Julia set for f$_c$, c = (φ − 2) + (φ − 1)i = −0.4 + 0.6i
* Julia set for f$_c$, c = 0.285 + 0i
* Julia set for f$_c$, c = 0.285 + 0.0–01i
* Julia set for f$_c$, c = 0.45 + 0.1428i
* Julia set for f$_c$, c = −0.70176 − 0.3842i
* Julia set for f$_c$, c = −0.835 − 0.2321i
* Julia set for f$_c$, c = −0.8 + 0.156i
* Julia set for f$_c$, vc = −0.7269 + 0.1889i
* Julia set for f$_c$, c = 0.8i
* Julia set for f$_c$, c = 0.35 + 0.35i
* Julia set for f$_c$, c = 0.4 + 0.4i
* Collection of Julia sets laid out in a 100 × 100 grid such that the center of each image corresponds to the same position in the complex plane as the value of the set. When laid out like this, the overall image resembles a Photographic mosaic depicting a Mandelbrot set.
The parameter plane of quadratic polynomials – that is, the plane of possible c values – gives rise to the famous Mandelbrot set. Indeed, the Mandelbrot set is defined as the set of all c such that $J(f_{c})$ is connected. For parameters outside the Mandelbrot set, the Julia set is a Cantor space: in this case it is sometimes referred to as Fatou dust.
In many cases, the Julia set of c looks like the Mandelbrot set in sufficiently small neighborhoods of c. This is true, in particular, for so-called Misiurewicz parameters, i.e. parameters c for which the critical point is pre-periodic. For instance:
* At c = i, the shorter, front toe of the forefoot, the Julia set looks like a branched lightning bolt.
* At c = −2, the tip of the long spiky tail, the Julia set is a straight line segment.
In other words, the Julia sets $J(f_{c})$ are locally similar around Misiurewicz points.

## Generalizations

The definition of Julia and Fatou sets easily carries over to the case of certain maps whose image contains their domain; most notably transcendental meromorphic functions and Adam Epstein's finite-type maps.
Julia sets are also commonly defined in the study of dynamics in several complex variables.

## Pseudocode

The below pseudocode implementations hard code the functions for each fractal. Consider implementing complex number operations to allow for more dynamic and reusable code.

### Pseudocode for normal Julia sets

    $f(z)=z^{2}+c$

### Pseudocode for multi-Julia sets

    $f(z)=z^{n}+c$
Another recommended option is to reduce color banding between iterations by using a renormalization formula for the iteration.
Such formula is given to be,
    $mu=k+1-{\frac {\log {\log {|z_{k}|}}}{\log {n}}}$
    $\forall f_{c,n}(z)=z^{n}+{\text{lower power terms}}+c$
where $k$ is the escaping iteration, bounded by some $K$ such that $0\leq k<K$ and $K\in \mathbb {N}$, and $|z_{k}|$ is the magnitude of the last iterate before escaping.
This can be implemented, very simply, like so:
The difference is shown below with a Julia set defined as $f_{c,2}(z)$ where $c=-0.835-0.321i$.
* With color banding
* Without color banding

## The potential function and the real iteration number

The Julia set for $f(z)=z^{2}$ is the unit circle, and on the outer Fatou domain, the potential function φ(z) is defined by φ(z) = log|z|. The equipotential lines for this function are concentric circles. As $|f(z)|=|z|^{2}$ we have
    $\varphi (z)=\lim _{k\to \infty }{\frac {\log |z_{k}|}{2^{k}}},$
where $z_{k}$ is the sequence of iteration generated by z. For the more general iteration $f(z)=z^{2}+c$, it has been proved that if the Julia set is connected (that is, if c belongs to the (usual) Mandelbrot set), then there exist a biholomorphic map ψ between the outer Fatou domain and the outer of the unit circle such that $|\psi (f(z))|=|\psi (z)|^{2}$. This means that the potential function on the outer Fatou domain defined by this correspondence is given by:
    $\varphi (z)=\lim _{k\to \infty }{\frac {\log |z_{k}|}{2^{k}}}.$
This formula has meaning also if the Julia set is not connected, so that we for all c can define the potential function on the Fatou domain containing ∞ by this formula. For a general rational function f(z) such that ∞ is a critical point and a fixed point, that is, such that the degree m of the numerator is at least two larger than the degree n of the denominator, we define the potential function on the Fatou domain containing ∞ by:
    $\varphi (z)=\lim _{k\to \infty }{\frac {\log |z_{k}|}{d^{k}}},$
where d = m − n is the degree of the rational function.
If N is a very large number (e.g. 10$^{100}$), and if k is the first iteration number such that $|z_{k}|>N$, we have that
    ${\frac {\log |z_{k}|}{d^{k}}}={\frac {\log(N)}{d^{\nu (z)}}},$
for some real number $\nu (z)$, which should be regarded as the real iteration number, and we have that:
    $\nu (z)=k-{\frac {\log(\log |z_{k}|/\log(N))}{\log(d)}},$
where the last number is in the interval [0, 1).
For iteration towards a finite attracting cycle of order r, we have that if $z^{*}$ is a point of the cycle, then $f(f(...f(z^{*})))=z^{*}$ (the r-fold composition), and the number
    $\alpha ={\frac {1}{\left|(d(f(f(\cdots f(z))))/dz)_{z=z^{*}}\right|}}\qquad (>1)$
is the attraction of the cycle. If w is a point very near $z^{*}$ and w′ is w iterated r times, we have that
    $\alpha =\lim _{k\to \infty }{\frac {|w-z^{*}|}{|w'-z^{*}|}}.$
Therefore, the number $|z_{kr}-z^{*}|\alpha ^{k}$ is almost independent of k. We define the potential function on the Fatou domain by:
    $\varphi (z)=\lim _{k\to \infty }{\frac {1}{(|z_{kr}-z^{*}|\alpha ^{k})}}.$
If ε is a very small number and k is the first iteration number such that $|z_{k}-z^{*}|<\epsilon$, we have that
    $\varphi (z)={\frac {1}{(\varepsilon \alpha ^{\nu (z)})}}$
for some real number $\nu (z)$, which should be regarded as the real iteration number, and we have that:
    $\nu (z)=k-{\frac {\log(\varepsilon /|z_{k}-z^{*}|)}{\log(\alpha )}}.$
If the attraction is ∞, meaning that the cycle is super-attracting, meaning again that one of the points of the cycle is a critical point, we must replace α by
    $\alpha =\lim _{k\to \infty }{\frac {\log |w'-z^{*}|}{\log |w-z^{*}|}},$
where w′ is w iterated r times and the formula for φ(z) by:
    $\varphi (z)=\lim _{k\to \infty }{\frac {\log(1/|z_{kr}-z^{*}|)}{\alpha ^{k}}}.$
And now the real iteration number is given by:
    $\nu (z)=k-{\frac {\log(\log |z_{k}-z^{*}|/\log(\varepsilon ))}{\log(\alpha )}}.$
For the colouring we must have a cyclic scale of colours (constructed mathematically, for instance) and containing H colours numbered from 0 to H−1 (H = 500, for instance). We multiply the real number $\nu (z)$ by a fixed real number determining the density of the colours in the picture, and take the integral part of this number modulo H.
The definition of the potential function and our way of colouring presuppose that the cycle is attracting, that is, not neutral. If the cycle is neutral, we cannot colour the Fatou domain in a natural way. As the terminus of the iteration is a revolving movement, we can, for instance, colour by the minimum distance from the cycle left fixed by the iteration.

## Field lines

In each Fatou domain (that is not neutral) there are two systems of lines orthogonal to each other: the equipotential lines (for the potential function or the real iteration number) and the field lines.
If we colour the Fatou domain according to the iteration number (and not the real iteration number $\nu (z)$, as defined in the previous section), the bands of iteration show the course of the equipotential lines. If the iteration is towards ∞ (as is the case with the outer Fatou domain for the usual iteration $z^{2}+c$), we can easily show the course of the field lines, namely by altering the colour according as the last point in the sequence of iteration is above or below the x-axis (first picture), but in this case (more precisely: when the Fatou domain is super-attracting) we cannot draw the field lines coherently - at least not by the method we describe here. In this case a field line is also called an external ray.
Let z be a point in the attracting Fatou domain. If we iterate z a large number of times, the terminus of the sequence of iteration is a finite cycle C, and the Fatou domain is (by definition) the set of points whose sequence of iteration converges towards C. The field lines issue from the points of C and from the (infinite number of) points that iterate into a point of C. And they end on the Julia set in points that are non-chaotic (that is, generating a finite cycle). Let r be the order of the cycle C (its number of points) and let $z^{*}$ be a point in C. We have $f(f(\dots f(z^{*})))=z^{*}$ (the r-fold composition), and we define the complex number α by
    $\alpha =(d(f(f(\dots f(z))))/dz)_{z=z^{*}}.$
If the points of C are $z_{i},i=1,\dots ,r(z_{1}=z^{*})$, α is the product of the r numbers $f'(z_{i})$. The real number 1/|α| is the attraction of the cycle, and our assumption that the cycle is neither neutral nor super-attracting, means that 1 < ⁠1/|α|⁠ < ∞. The point $z^{*}$ is a fixed point for $f(f(\dots f(z)))$, and near this point the map $f(f(\dots f(z)))$ has (in connection with field lines) character of a rotation with the argument β of α (that is, $\alpha =|\alpha |e^{\beta i}$).
In order to colour the Fatou domain, we have chosen a small number ε and set the sequences of iteration $z_{k}(k=0,1,2,\dots ,z_{0}=z)$ to stop when $|z_{k}-z^{*}|<\epsilon$, and we colour the point z according to the number k (or the real iteration number, if we prefer a smooth colouring). If we choose a direction from $z^{*}$ given by an angle θ, the field line issuing from $z^{*}$ in this direction consists of the points z such that the argument ψ of the number $z_{k}-z^{*}$ satisfies the condition that
    $\psi -k\beta =\theta \mod \pi .\,$
For if we pass an iteration band in the direction of the field lines (and away from the cycle), the iteration number k is increased by 1 and the number ψ is increased by β, therefore the number $\psi -k\beta \mod \pi$ is constant along the field line.
A colouring of the field lines of the Fatou domain means that we colour the spaces between pairs of field lines: we choose a number of regularly situated directions issuing from $z^{*}$, and in each of these directions we choose two directions around this direction. As it can happen that the two field lines of a pair do not end in the same point of the Julia set, our coloured field lines can ramify (endlessly) in their way towards the Julia set. We can colour on the basis of the distance to the center line of the field line, and we can mix this colouring with the usual colouring. Such pictures can be very decorative (second picture).
A coloured field line (the domain between two field lines) is divided up by the iteration bands, and such a part can be put into a one-to-one correspondence with the unit square: the one coordinate is (calculated from) the distance from one of the bounding field lines, the other is (calculated from) the distance from the inner of the bounding iteration bands (this number is the non-integral part of the real iteration number). Therefore, we can put pictures into the field lines (third picture).

## Plotting the Julia set

Methods :
* Distance Estimation Method for Julia set (DEM/J)
* Inverse Iteration Method (IIM)

### Using backwards (inverse) iteration (IIM)

As mentioned above, the Julia set can be found as the set of limit points of the set of pre-images of (essentially) any given point. So we can try to plot the Julia set of a given function as follows. Start with any point z we know to be in the Julia set, such as a repelling periodic point, and compute all pre-images of z under some high iterate $f^{n}$ of f.
Unfortunately, as the number of iterated pre-images grows exponentially, this is not feasible computationally. However, we can adjust this method, in a similar way as the "random game" method for iterated function systems. That is, in each step, we choose at random one of the inverse images of f.
For example, for the quadratic polynomial f$_c$, the backwards iteration is described by
    $z_{n-1}={\sqrt {z_{n}-c}}.$
At each step, one of the two square roots is selected at random.
Note that certain parts of the Julia set are quite difficult to access with the reverse Julia algorithm. For this reason, one must modify IIM/J ( it is called MIIM/J) or use other methods to produce better images.

### Using DEM/J

* Images of Julia sets for ⁠$f_{c}(z)=z^{2}+c$⁠
* ⁠$c=-0.74543+0.11301*i$⁠
* ⁠$c=-0.75+0.11*i$⁠
* ⁠$c=-0.1+0.651*i$⁠
* Julia set drawn by distance estimation, the iteration is of the form ⁠$1-z^{2}+z^{5}/(2+4z)+c$⁠
* Three-dimensional rendering of Julia set using distance estimation
As a Julia set is infinitely thin we cannot draw it effectively by backwards iteration from the pixels. It will appear fragmented because of the impracticality of examining infinitely many startpoints. Since the iteration count changes vigorously near the Julia set, a partial solution is to imply the outline of the set from the nearest color contours, but the set will tend to look muddy.
A better way to draw the Julia set in black and white is to estimate the distance of pixels (DEM) from the set and to color every pixel whose center is close to the set. The formula for the distance estimation is derived from the formula for the potential function φ(z). When the equipotential lines for φ(z) lie close, the number $|\varphi '(z)|$ is large, and conversely, therefore the equipotential lines for the function $\delta (z)=\varphi (z)/|\varphi '(z)|$ should lie approximately regularly. It has been proven that the value found by this formula (up to a constant factor) converges towards the true distance for z converging towards the Julia set.
We assume that f(z) is rational, that is, $f(z)=p(z)/q(z)$ where p(z) and q(z) are complex polynomials of degrees m and n, respectively, and we have to find the derivative of the above expressions for φ(z). And as it is only $z_{k}$ that varies, we must calculate the derivative $z'_{k}$ of $z_{k}$ with respect to z. But as $z_{k}=f(f(\cdots f(z)))$ (the k-fold composition), $z'_{k}$ is the product of the numbers $f'(z_{k})$, and this sequence can be calculated recursively by $z'_{k+1}=f'(z_{k})z'_{k}$, starting with $z'_{0}=1$ (before the calculation of the next iteration $z_{k+1}=f(z_{k})$).
For iteration towards ∞ (more precisely when m ≥ n + 2, so that ∞ is a super-attracting fixed point), we have
    $|\varphi '(z)|=\lim _{k\to \infty }{\frac {|z'_{k}|}{|z_{k}|d^{k}}},$
(d = m − n) and consequently:
    $\delta (z)=\varphi (z)/|\varphi '(z)|=\lim _{k\to \infty }\log |z_{k}||z_{k}|/|z'_{k}|.\,$
For iteration towards a finite attracting cycle (that is not super-attracting) containing the point ⁠$z^{*}$⁠ and having order r, we have
    $|\varphi '(z)|=\lim _{k\to \infty }|z'_{kr}|/(|z_{kr}-z^{*}|^{2}\alpha ^{k}),\,$
and consequently:
    $\delta (z)=\varphi (z)/|\varphi '(z)|=\lim _{k\to \infty }|z_{kr}-z^{*}|/|z'_{kr}|.\,$
For a super-attracting cycle, the formula is:
    $\delta (z)=\lim _{k\to \infty }\log |z_{kr}-z^{*}|^{2}/|z'_{kr}|.\,$
We calculate this number when the iteration stops. Note that the distance estimation is independent of the attraction of the cycle. This means that it has meaning for transcendental functions of "degree infinity" (e.g. sin(z) and tan(z)).
Besides drawing of the boundary, the distance function can be introduced as a 3rd dimension to create a solid fractal landscape.