# 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\,$

# Derivative of the iterated function

For Julia set:
For Mandelbrot set:
It can be computed with Maxima CAS :

## Rational function
### degree 3

wrt z

### degree 5

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

### Polynomials

First derivative wrt z :
| degree | Function f(z) | derivative wrt z |
| 2 | $z^{2}+c$ | $2*z$ |
| 3 | $z^{3}+c$ | $3*z^{2}$ |
| 4 | $z^{4}+c$ | $4*z^{3}$ |
| d | $z^{d}+c$ | $d*z^{d-1}$ |
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:

#### Complex quadratic polynomial
##### z^2+c
###### First derivative wrt c

On parameter plane :
* $c$ is a variable
* $z_{0}=0$ is constant
    ${\frac {d}{dc}}f_{c}^{(p)}(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}}=2z_{n}{\frac {dz_{n}}{dc}}+{\frac {dc}{dc}}=2z_{n}{\frac {dz_{n}}{dc}}+1\,$
* Maxima CAS function :
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 )
* Mandelbrot set boundary = 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\,$
| description | arbitrary name | formula | Initial conditions | Recurrence step | common names |
| iterated complex quadratic polynomial | $A_{m}$ | $f^{m}$ | $A_{0}=z$ | $A_{m+1}=A_{m}^{2}+c$ | z or f |
| first derivative with respect to z | $B_{m}$ | ${\dfrac {\partial }{\partial z}}f^{m}$ | $B_{0}=1$ | $B_{m+1}=2A_{m}B_{m}$ | dz, d (from derivative) or p ( from prime) of f' |
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 {definitionofA}}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}}2A_{m}({\dfrac {\partial }{\partial z}}A_{m})\quad {\xrightarrow {definition\ of\ B}}2A_{m}B_{m}$
Following the derivative
It can be used for :
* computing the external distance to the Julia set (DEM/J)
* detection of interior points of Mandelbrot set componnets
* Julia set boundary = DEM/J

##### logistic map

Logistic map

#### complex cubic polynomial

wrt z

#### quarctic
# 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

## 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})$
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 :
* together with :$f_{c}^{n}$ and ${\frac {\partial }{\partial {z}}}f_{c}^{p}(z_{0})$
* recursively by applying the chain rule
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}}$
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:
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.

# References

* ↑ mathoverflow question : whats-a-natural-candidate-for-an-analytic-function-that-interpolates-the-tower/43003
* ↑ Faa di Bruno and derivatives of an iterated function ON MAY 20, 2017 BY DCHOYLE
* ↑ fractalforums.org : some-questions-about-the-mandelbrot-derivative
* ↑ A Cheritat wiki : Mandelbrot_set - Following_the_derivative
* ↑ fractalforums.org: period-detection
* ↑ Notation_for_differentiation in wikipedia
* ↑ fractalforums.org : some-questions-about-the-mandelbrot-derivative
* ↑ fractalforums.org : all-periodic-bulbs-as-point-attractors
* ↑ A Cheritat wiki : Mandelbrot_set - Interior_detection_methods
* ↑ Fractalforums.org : exterior-distance-estimation-for-logistic-map
* ↑ Following_the_derivative by Arnaud Cheritat
* ↑ Finding The Equation Of The Normal Line To The Curve by Krista King Math
* ↑ Point–slope form or Point-gradient form of line equation
* ↑ fractalforums.org : m-brot-distance-estimation-versus-claudes-fake-de
* ↑ Automatic_differentiation in wikipedia
* ↑ fractalforums.org: ultrafractal exponential-map-transform