Fractals/Mathematics/Derivative


 * Derivative of Iterated function (map)
 * of the function f with respect to variable ...
 * following the derivative
 * the rolling derivative
 * the derivative of order n: first, second, ...
 * Keep track of derivatives ...

=notation=
 * variable z
 * constant parameter c
 * function f
 * derivative d
 * iteration number p
 * wrt = with respect to

Notation types
 * Leibniz's notation
 * Euler's notation
 * Newton's notation ( dot notation)
 * Lagrange's notation ( prime mark notation)


 * $$\frac{d}{dz} f(z) = f'(z) = z' = d = D\,$$

=Informal description=

The derivative gives you what is called the gradient. For 2D, consider the terrain as a contour map. The gradient tells you the rate of change in x and y directions. The slope is the magnitude of the gradient, and the contours are closer together for higher slope. For 3D the gradient is the rate of change in x, y and z, and the slope is still the magnitude of the gradient. Technically, slope is only 1D, and the gradient also tells you the direction of the slope. When we talk about derivative giving you the slope we are being casual. ( xenodreambuie )

=Derivative of the iterated function =

"the derivative basically as it's calculated for anlytical DE using the implementation of the chain rule for the derivative of f(g(x)) where f(x) is say g(x)^p+c and the value of g(x) is current z. So f'(g(x)) is p*z^(p-1) and g'(x) is the derivative from the previous iteration,  so on each iteration the new derivative is:  dz = dz*p*z^(p-1)  and new z = z^p+c as normal" FractalDave

For Julia set: // initial values: c is const z = z0 ( z is a variable, read initial value from the pixel) dz = 1

// Recurrence steps: dz = f'(z)*dz  // calculating dz and multiply the previous d z = f(z)       // forward iteration

For Mandelbrot set:

// initial values: z = critical point ( critical pointis 0 for multibrot sets, z is variable) c = ( c is a variable, read initial value from the pixel) dc = 0

// Recurrence steps: dc = f'(z)*dc + 1 // calculating dc and multiply the previous dc z = f(z)       // forward iteration

It can be computed with Maxima CAS : display2d:false; f:1/(z^3+d*z); dz : diff(f,z,1); // first derivative of f wrt variable z dc : diff(f,c,1); // first derivative of f wrt parameter c

Rational function
$$f(x)=\frac{P(x)}{Q(x)}$$

$$f'(x)=\frac{P'(x)Q(x)-P(x)Q'(x)}{Q^2(x)}$$

degree 3
wrt z

// function f(z)= 1/(z^3 + c*z )

// first derivativwe wrt z d = f'(z) = -(3z^2 +c)/(z^3 + cz)^2

// iteration: z_(n+1) = f(z_n)

// initial values: z = z d = 1

// Recurrence steps: d = - d*(3z^2 +c)/(z^3 + cz)^2 z = 1/(z^3 + c*z)

degree 5
display2d:false; f: 1/(a*z^5+ z^3 + b*z); dz: diff(f,z,1);

in plain text: dz = -(5*a*z^4+3*z^2+b)/(a*z^5+z^3+b*z)^2

Example:
 * 1/((0.15*I+0.15)*z^5+(3*I-3)*z + z^3)

degree 5 by Buschmann
f(z):=z^5/(4*z+2)-z^2+c+1

(%i4) diff(f(z), z,1);

(%o4) (5*z^4)/(4*z+2)-(4*z^5)/(4*z+2)^2-2*z

Polynomials
C src code for making exterior DEM/M images of Multibrot sets: Mandelbrot sets for $$z^q + c$$ where q is a degree of unicritical monomial:

C src code for making exterior DEM/J images of Julia sets for $$z^q + c$$ where q is a degree of unicritical monomial:

First derivative wrt c
On parameter plane :
 * $$c$$ is a variable
 * $$z_0 = 0 $$ is constant


 * $$\frac{d}{dc} f^{(p)} _c (z_0) = z'_p \,$$

This derivative can be found by iteration starting with


 * $$z_0 = 0 \,$$
 * $$z'_0 = 1 \,$$

and then ( compute derivative before next z because it uses previous values of z):


 * $$z'_{p+1} = 2 \cdot z_p\cdot z'_p + 1 \,$$
 * $$z_{p+1} = z_p^2 + c \,$$

This can be verified by using the chain rule for the derivative.


 * $$\frac{dz_{n+1}}{dc} = \frac{d(z_n^2+ c)}{dc} = 2 z_n \frac{dz_n}{dc} + \frac{dc}{dc} = 2 z_n \frac{dz_n}{dc} + 1\,$$


 * Maxima CAS function :

dcfn(p, z, c) := if p=0 then 1 else 2*fn(p-1,z,c)*dcfn(p-1, z, c)+1;

Example values :
 * $$z_0 = 0 \qquad\qquad z'_0 = 1 \,$$
 * $$z_1 = c \qquad\qquad z'_1 = 1 \,$$
 * $$z_2 = c^2+c \qquad z'_2 = 2c+1 \,$$

It can be used for:
 * the distance estimation method for drawing a Mandelbrot set ( DEM/M )

First derivative wrt z
$$z'_n\,$$ is first derivative with respect to z.

This derivative can be found by iteration starting with
 * $$z_0 = z \,$$
 * $$z'_0 = 1 \,$$

and then :
 * $$z'_{n+1}= 2*z_n*z'_n\,$$
 * $$z_{n+1} = z_n^2 + c \,$$

Derivation of recurrence relation:

$$ A_0 \quad \xrightarrow{definition\ of\ A}\ f^0 (z, c) \quad \xrightarrow{definition\ of\ f}\ \quad z $$

$$A_{m+1} \quad \xrightarrow{definition of A} f^{m+1} (z, c)  \quad \xrightarrow{definition\ of\ f} f (f^m (z, c), c)  \quad \xrightarrow{definition\ of\ A} f (A_m, c)  \quad \xrightarrow{definition\ of\ f} A_m ^ 2 + c $$

$$B_0 \quad \xrightarrow{definition\ of\ B}\ \dfrac{\partial}{\partial z} f^0 (z, c) \xrightarrow{definition\ of\ f}\ \dfrac{\partial}{\partial z} z \xrightarrow{derivative}\ 1 $$

$$B_{m+1} \quad \xrightarrow{definition\ of\ B} \dfrac{\partial}{\partial z} A_{m+1}  \quad \xrightarrow{definition\ of\ A} \dfrac{\partial}{\partial z} (A_m ^ 2 + c)  \quad \xrightarrow{distributivity} \dfrac{\partial}{\partial z} A_m ^ 2 + \dfrac{\partial}{\partial z} c  \quad \xrightarrow{constant\ derivative} \dfrac{\partial}{\partial z} A_m ^ 2 + 0  \quad \xrightarrow{zero } \dfrac{\partial}{\partial z} A_m ^ 2   \quad \xrightarrow{chain\ rule} 2 A_m (\dfrac{\partial}{\partial z} A_m)  \quad \xrightarrow{definition\ of\ B} 2 A_m B_m $$

Following the derivative

"As we iterate z, we can look at the derivatives of P at z. In our case it is quite simple: P′(z)=2z. Multiplying all these numbers along an orbit yields the derivative at z of the composition Pn. This multiplication can be carried on iteratively as we iterate z " A Cheritat

der = 1 z = c # note that we start with c instead of 0, to avoid multiplying the derivative by 0 for n in range(0,N): new_z = z*z+c new_der = der*2*z z = new_z der = new_der

It can be used for :
 * computing the external distance to the Julia set (DEM/J)
 * detection of interior points of Mandelbrot set componnets

logistic map
Logistic map

complex cubic polynomial
wrt z

(%i2) display2d:false;

(%o2) false (%i3) f(z):= z^3 + c;

(%o3) f(z):=z^3+c (%i4) diff(f(z), z,1);

(%o4) 3*z^2 (%i5) diff(f(z), c,1);

(%o5) 1



// function f(z)= z^3 + c*z

// first derivativwe wrt z d = f'(z) = 3*z^2 + c

// iteration: z_(n+1) = f(z_n)

// initial values: z = z d = 1

// Recurrence steps: d = (3*z^2 + c)*d z = z^3 + c*z

quarctic
(%i1) display2d:false;

(%o1) false

(%o4) f(z):=z^4+c (%i5) diff(f(z), z,1);

(%o5) 4*z^3

=FAQ=
 * why new d must be computed before new z ?

=Aplications=
 * Vector field gradient
 * Newton method and recurrence relations
 * eDEM = Distance Estimation Method for exterior of the set
 * DEM/M- for Mandelbrot set
 * DEM/J for Julia set
 * iDEM = DEM for interior
 * stability of periodic point ( multiplier)
 * finding critical points
 * slope - an algorithm for converting 2D image to 3D

Keep track of derivatives of Z+z wrt. Z1+z1 (where Z0+z0  is at the critical point, usually 0 ). When the absolute value of the derivative drops below a threshold such as 0.001, classify it as interior and stop iterating. Keep track of derivatives of Z+z wrt. pixel coordinates k. As Z is constant for the whole image, you just need dzdk. An easy way to do this is with dual numbers for automatic numeric differentiation. Set up the pixel coordinates as dual numbers with dual part 1+0i, then transform them to the complex C+c plane of the fractal iterations. At the end you plug the complex derivative into the (directional) distance estimate formula, it is already prescaled by the pixel spacing (this also helps to avoid overflow during iteration). (	Claude Heiland-Allen)

finding equation of normal and tangent to the curve
to find the equation of the normal line to the curve at the given point by Krista King Math:
 * Take the derivative of the original curve, and evaluate it at the given point. This is the slope of the tangent line, called m.
 * Find the negative reciprocal of m. This is the slope of the normal line, which we’ll call n. So n = −1/m.
 * Plug n and the given point into the point-slope formula for the equation of the line, (y−y1)=n(x−x1)
 * Simplify the equation by solving for y

Interior distance estimation
The Interior distance estimation is given by :


 * $$distance(c,\sigma M) = d(c, z_0, p) = \frac{1-\mid{\frac{\partial}{\partial{z}}f_c^p(z_0)}\mid^2}

{\mid{\frac{\partial}{\partial{c}}\frac{\partial}{\partial{z}}f_c^p(z_0) + \frac{\partial}{\partial{z}}\frac{\partial}{\partial{z}}f_c^p(z_0) \frac{\frac{\partial}{\partial{c}}f_c^p(z_0)} {1-\frac{\partial}{\partial{z}}f_c^p(z_0)}}\mid}$$ where

$$p$$ is the period = length of the periodic orbit

$$c$$ is the point from parameter plane to be estimated

$$f_c(z)$$ is the complex quadratic polynomial $$f_c(z)=z^2 + c$$

$$f_c^p(z_0)$$ is the $$p$$-fold iteration of $$f_c(z) $$

$$z_0$$ is any of the $$p$$ points that make the periodic orbit ( limit cycle ) $$\{z_0, \dots, z_{p-1} \}$$

4 derivatives of $$f_c^p $$ evaluated at $$z_0, c, p$$ :

$$\frac{\partial}{\partial{c}}\frac{\partial}{\partial{z}}f_c^p(z_0)$$

$$\frac{\partial}{\partial{z}}\frac{\partial}{\partial{z}}f_c^p(z_0)$$

$$\frac{\partial}{\partial{c}}f_c^p(z_0)$$

$$\frac{\partial}{\partial{z}}f_c^p(z_0)$$

First partial derivative with respect to z

It must be computed recursively by applying the chain rule : Starting points : $$ \begin{cases} \frac{\partial}{\partial{z}}f_c^0(z_0) = 1 \\ f_c^0(z_0) = z_0 \end{cases} $$

First iteration : $$ \begin{cases} \frac{\partial}{\partial{z}}f_c^1(z_0) = 2*f_c^0(z_0)*\frac{\partial}{\partial{z}}f_c^0(z_0) = 2z_0 \\ f_c^1(z_0) = (f_c^0(z_0))^2 + c = z_0^2 + c \end{cases} $$

Second iteration : $$ \begin{cases} \frac{\partial}{\partial{z}}f_c^2(z_0) =2*f_c^1(z_0)*\frac{\partial}{\partial{z}}f_c^1(z_0)= 4z_0^3+4cz_0 \\ f_c^2(z_0) = (f_c^1(z_0))^2 + c = (z_0^2 + c)^2 + c = z_0^4 + 2*c*z_0^2 + c^2 + c \end{cases} $$

General rule for p iteration : $$ \begin{cases} \frac{\partial}{\partial{z}}f_c^p(z_0) = 2*f_c^{p-1}(z_0)*\frac{\partial}{\partial{z}}f_c^{p-1}(z_0) \\ f_c^p(z_0) = f_c^{p-1}(z_0)^2 + c \end{cases} $$

First partial derivative with respect to c

It must be computed recursively by applying the chain rule : Starting points : $$ \begin{cases} \frac{\partial}{\partial{c}}f_c^p(z_0) = 0 \\ f_c^0(z_0) = z_0 \end{cases} $$

First iteration : $$ \begin{cases} \frac{\partial}{\partial{c}}f_c^1(z_0) = 2*f_c^0(z_0)*\frac{\partial}{\partial{c}}f_c^0(z_0) + 1 = 1 \\ f_c^1(z_0) = (f_c^0(z_0))^2 + c = z_0^2 + c \end{cases} $$

Second iteration : $$ \begin{cases} \frac{\partial}{\partial{c}}f_c^2(z_0) =2*f_c^1(z_0)*\frac{\partial}{\partial{c}}f_c^1(z_0) + 1 = 2z_0^2 +2c + 1 \\ f_c^2(z_0) = (f_c^1(z_0))^2 + c = (z_0^2 + c)^2 + c = z_0^4 + 2*c*z_0^2 + c^2 + c \end{cases} $$

General rule for p iteration : $$ \begin{cases} \frac{\partial}{\partial{c}}f_c^p(z_0) = 2*f_c^{p-1}(z_0)*\frac{\partial}{\partial{c}}f_c^p(z_0) + 1 \\ f_c^p(z_0) = f_c^{p-1}(z_0)^2 + c \end{cases} $$

Second order partial derivative with respect to z

It must be computed : Starting points : $$ \begin{cases} \frac{\partial}{\partial{z}}f_c^0(z_0) = 1 \\ \frac{\partial}{\partial{z}}\frac{\partial}{\partial{z}}f_c^p(z_0) = 0 \\ f_c^0(z_0) = z_0 \end{cases} $$
 * together with :$$f_c^n $$ and $$\frac{\partial}{\partial{z}}f_c^p(z_0)$$
 * recursively by applying the chain rule

First iteration : $$ \begin{cases} \frac{\partial}{\partial{z}}f_c^1(z_0) = 2*f_c^0(z_0)*\frac{\partial}{\partial{z}}f_c^0(z_0) = 2z_0 \\ \frac{\partial}{\partial{z}}\frac{\partial}{\partial{z}}f_c^p(z_0) = 2\{ (\frac{\partial}{\partial{z}}f_c^0(z_0))^2 + f_c^0(z_0)*\frac{\partial}{\partial{z}}\frac{\partial}{\partial{z}}f_c^0(z_0)\} = 2\\ f_c^1(z_0) = (f_c^0(z_0))^2 + c = z_0^2 + c \end{cases} $$

Second iteration : $$ \begin{cases} \frac{\partial}{\partial{z}}f_c^2(z_0) =2*f_c^1(z_0)*\frac{\partial}{\partial{z}}f_c^1(z_0)= 4z_0^3+4cz_0 \\ \frac{\partial}{\partial{z}}\frac{\partial}{\partial{z}}f_c^p(z_0) = \\ f_c^2(z_0) = (f_c^1(z_0))^2 + c = (z_0^2 + c)^2 + c = z_0^4 + 2*c*z_0^2 + c^2 + c \end{cases} $$

General rule for p iteration : $$ \begin{cases} \frac{\partial}{\partial{z}}f_c^p(z_0) = 2*f_c^{p-1}(z_0)*\frac{\partial}{\partial{z}}f_c^{p-1}(z_0) \\ \frac{\partial}{\partial{z}}\frac{\partial}{\partial{z}}f_c^p(z_0) = 2\{ (\frac{\partial}{\partial{z}}f_c^{p-1}(z_0))^2 + f_c^{p-1}(z_0)*\frac{\partial}{\partial{z}}\frac{\partial}{\partial{z}}f_c^{p-1}(z_0)\}\\ f_c^p(z_0) = f_c^{p-1}(z_0)^2 + c \end{cases} $$

Second order mixed partial derivative

$$\frac{\partial}{\partial{c}}\frac{\partial}{\partial{z}}f_c^p(z_0) = 2(\frac{\partial}{\partial{c}} f_c^{p-1}(z_0)*\frac{\partial}{\partial{z}}f_c^{p-1}(z_0) + f_c^{p-1}(z_0)*\frac{\partial}{\partial{c}}\frac{\partial}{\partial{z}}f_c^{p-1}(z_0))$$

=How to compute derivative ?=
 * wolfram alpha
 * Maxima

=p-norm of the gradient =

The p-norm of the gradient is: $$||g||_p = ( g^p_x + g^p_y )^{(1/p)}$$

and set p=-2.

=See also =
 * automatic differentiation

derivatives w.r.t. pixel coordinates by Claude

 * Pixel = (x + i y); x in [0..w), y in [0..h) (may be fractional if using jitter)
 * C = r exp(i pi (Pixel - (w + i h) /2) / w) + C0
 * dc/dpixel = r i pi / w exp(i pi (Pixel - (w + i h) /2) / w)
 * for z <- z^2 + c:
 * dz/dpixel <- 2 z dz/dpixel + dc/dpixel
 * distance estimate in screen space : de = |z| log |z| / |dz/dpixel|

here:
 * pixel_size = |dc/dpixel| (just divide through by dc/dpixel to get dz/dpixel / dc/dpixel = dz/dc, etc)
 * dy = (2 * circle_period * Math.PI) / image_size;
 * dx = dy * height_ratio;
 * height_ratio is usually 1. Its just there to stretch the image on one direction.

derivatives wrt pixel are less likely to overflow, and give screen space de automatically.

Also, now that I checked again the e^(x*dx) term, is actually e^(x*dx + offset). I don't know if this changes the things alot.

C value = (e^(x*dx + offset)) * (cos(y * dy) + sin(y* dy)i) + C0

=References=