User:Papaya25

This is my user page

=Fast programming techniques=

Fast integer powers of x
When calculating Taylor series powers of $$x$$ are overly used, this means that when calculating the function in any programming languaje a fast way of calculating powers of $$x$$ are needed. This can be expressed recursivelly as:

$$x^n = x^{n/2}\times x^{n/2}$$ if $$n$$ is even.

$$x^n = x\times x^{n-1}$$ if $$n$$ is odd.

Where $$x^{n/2}$$ does not need to be calculated twice, it can be calculated once and then cached.

Fast integer products of x
When calculating products, sometimes it's easier to do bitshifting that multiplying normaly.

They follow the simple sum:

$$\sum_{i = 0} (x << i) \times n_i$$

where $$n_i$$ is the $$i$$th binary digit of $$n$$

=Splines=

Bézier curves
Explicit definition of a $$n$$ elements for $$0 \leqslant t \leqslant 1$$ $$\begin{align} \mathbf{B}_n(t) &= \sum_{i=0}^{n - 1} {n \choose i}(1 - t)^{n - i}t^i\mathbf{P}_i \\ &= (1 - t)^{n - 1}\mathbf{P}_0 + {n - 1\choose 1}(1 - t)^{n - 2}t\mathbf{P}_1 + \cdots + {n - 1\choose n - 2}(1 - t)t^{n - 2}\mathbf{P}_{n - 2} + t^{n - 1}\mathbf{P}_{n - 1} \\ &= \sum_{i=0}^{n - 1} {n \choose i} \sum_{k=0}^{n - i} {n - i \choose k} \left(-1\right)^{k} t^{i + k}\mathbf{P}_i \\ &= \sum_{i=0}^{n - 1} \sum_{k=0}^{n - i} \frac{n!}{i! k! \left(n-i-k\right)!}\left(-1\right)^{k} t^{i + k}\mathbf{P}_i \\ \end{align}$$

Matrix form of the curve

$$\mathbf{B}_n(t) = \underbrace{\begin{bmatrix} 1 & t & t^2 & \cdots & t^{n-1} \end{bmatrix}}_{n\;elements} \begin{bmatrix} 1 & 0 & 0 & \cdots & 0 \\ -{n - 1\choose 1} & {n - 1\choose 1}^2 & 0 & \cdots & 0 \\ {n - 1\choose 2} & -{n - 1\choose 1}{n - 1\choose 2} & {n - 1\choose 2}^2 & \cdots & 0 \\ \vdots & \vdots & \vdots & \ddots & \vdots \\ (-1)^{n+1} & (-1)^{n}{n - 1\choose 1} & (-1)^{n + 1}{n - 1\choose 2} & \cdots & 1 \end{bmatrix} \begin{bmatrix} P_0 \\ P_1 \\ P_2 \\ \vdots \\ P_{n-1} \end{bmatrix} $$

Matrix form of multiple Béziers:

$$\mathbf{B}_2(t) = \begin{bmatrix} 1 & t \end{bmatrix} \begin{bmatrix} 1 & 0 \\ -1 & 1 \\ \end{bmatrix} \begin{bmatrix} {\color[RGB]{255,0,0} P_0} \\ {\color[RGB]{0,0,255} P_1} \\ \end{bmatrix} $$

$$\mathbf{B}_3(t) = \begin{bmatrix} 1 & t & t^2 \end{bmatrix} \begin{bmatrix} 1 & 0 & 0 \\ -2 & 2 & 0 \\ 1 & -2 & 1 \\ \end{bmatrix} \begin{bmatrix} {\color[RGB]{255,0,0} P_0} \\ {\color[RGB]{0,0,255} P_1} \\ {\color[RGB]{0,255,0} P_2} \end{bmatrix} $$

$$\mathbf{B}_4(t) = \begin{bmatrix} 1 & t & t^2 & t^3 \end{bmatrix} \begin{bmatrix} 1 & 0 & 0 & 0 \\ -3 & 3 & 0 & 0 \\ 3 & -6 & 3 & 0 \\ -1 & 3 & -3 & 1 \end{bmatrix} \begin{bmatrix} {\color[RGB]{255,0,0} P_0} \\ {\color[RGB]{0,0,255} P_1} \\ {\color[RGB]{0,255,0} P_2} \\ {\color[RGB]{255,0,255} P_3} \end{bmatrix} $$

$$\mathbf{B}_5(t) = \begin{bmatrix} 1 & t & t^2 & t^3 & t^4 \end{bmatrix} \begin{bmatrix} 1 & 0 & 0 & 0 & 0 \\ -4 & 4 & 0 & 0 & 0 \\ 6 & -12 & 6 & 0 & 0 \\ -4 & 12 & -12 & 4 & 0 \\ 1 & -4 & 6 & -4 & 1 \end{bmatrix} \begin{bmatrix} {\color[RGB]{255,0,0} P_0} \\ {\color[RGB]{0,0,255} P_1} \\ {\color[RGB]{0,255,0} P_2} \\ {\color[RGB]{255,0,255} P_3} \\ {\color[RGB]{0,255,255} P_4} \end{bmatrix} $$

Derivatives of B4(t)
Velocity in the curve at the point $$t$$

$$\mathbf{B}'_4(t) = \begin{bmatrix} 1 & t & t^2 & 0 \end{bmatrix} \begin{bmatrix} -3 & 3 & 0 & 0 \\ 6 & -12 & 6 & 0 \\ -3 & 9 & -9 & 3 \\ 0 & 0 & 0 & 0 \end{bmatrix} \begin{bmatrix} {\color[RGB]{255,0,0} P_0} \\ {\color[RGB]{0,0,255} P_1} \\ {\color[RGB]{0,255,0} P_2} \\ {\color[RGB]{255,0,255} P_3} \end{bmatrix} $$

Acceleration in the curve at the point $$t$$

$$\mathbf{B}''_4(t) = \begin{bmatrix} 1 & t & 0 & 0 \end{bmatrix} \begin{bmatrix} 6 & -12 & 6 & 0 \\ -6 & 18 & -18 & 6 \\ 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 \end{bmatrix} \begin{bmatrix} {\color[RGB]{255,0,0} P_0} \\ {\color[RGB]{0,0,255} P_1} \\ {\color[RGB]{0,255,0} P_2} \\ {\color[RGB]{255,0,255} P_3} \end{bmatrix} $$

Jolt in the curve at the point $$t$$

$$\mathbf{B}'''_4(t) = \begin{bmatrix} 1 & 0 & 0 & 0 \end{bmatrix} \begin{bmatrix} -6 & 18 & -18 & 6 \\ 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 \\ \end{bmatrix} \begin{bmatrix} {\color[RGB]{255,0,0} P_0} \\ {\color[RGB]{0,0,255} P_1} \\ {\color[RGB]{0,255,0} P_2} \\ {\color[RGB]{255,0,255} P_3} \end{bmatrix} $$

Hermite Spline
The Hermite Spline is given by an initial position $${\color[RGB]{255,0,0} P_0}$$, a final position $${\color[RGB]{0,255,0} P_1}$$, an initial velocity $${\color[RGB]{0,0,255} v_0}$$ and a final velocity $${\color[RGB]{255,0,255} v_1}$$. This spline is at least $$C^1$$ continuos.

Matrix form: $$\mathbf{P}(t) = \begin{bmatrix} 1 & t & t^2 & t^3 \end{bmatrix} \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ -3 & -2 & 3 & -1 \\ 2 & 1 & -2 & 1 \end{bmatrix} \begin{bmatrix} {\color[RGB]{255,0,0} P_0} \\ {\color[RGB]{0,0,255} v_0} \\ {\color[RGB]{0,255,0} P_1} \\ {\color[RGB]{255,0,255} v_1} \end{bmatrix} $$

Explicit equation organized by the vectors:

$$ \mathbf{P}(t) = {\color[RGB]{255,0,0} P_0} \left( 1 - 3 t^2 + 2 t^3 \right) + {\color[RGB]{0,0,255} v_0} \left( t - 2 t^2 + t^3 \right) + {\color[RGB]{0,255,0} P_1} \left( 3 t^2 - 2 t^3 \right) + {\color[RGB]{255,0,255} v_1} \left( - t^2 + t^3 \right) $$

Explicit equation organized by the powers of $$t$$:

$$ \mathbf{P}(t) = t^0 \left( {\color[RGB]{255,0,0} P_0} \right) + t^1 \left( {\color[RGB]{0,0,255} v_0} \right) + t^2 \left( - 3 {\color[RGB]{255,0,0} P_0} - 2 {\color[RGB]{0,0,255} v_0} + 3 {\color[RGB]{0,255,0} P_1} - {\color[RGB]{255,0,255} v_1} \right) + t^2 \left( 2 {\color[RGB]{255,0,0} P_0} + 1 {\color[RGB]{0,0,255} v_0} - 2 {\color[RGB]{0,255,0} P_1} + {\color[RGB]{255,0,255} v_1} \right) $$

The Hermite spline is related to the Bézier splines of the basis of:

$$\begin{align} {\color[RGB]{255,0,0} B_0} &= {\color[RGB]{255,0,0} P_0} \\ {\color[RGB]{0,0,255} B_1} &= {\color[RGB]{255,0,0} P_0} + \frac{ {\color[RGB]{0,0,255} v_0} }{3} \\ {\color[RGB]{0,255,0} B_2} &= {\color[RGB]{0,255,0} P_1} - \frac{ {\color[RGB]{255,0,255} v_1} }{3} \\ {\color[RGB]{255,0,255} B_3} &= {\color[RGB]{0,255,0} P_1} \end{align}$$

Cardinal Spline
The Cardinal Spline is given by an initial position $${\color[RGB]{255,0,0} P_0}$$, a control point $${\color[RGB]{0,255,0} P_1}$$, another control point $${\color[RGB]{0,0,255} P_2}$$, the final position $${\color[RGB]{255,0,255} P_3}$$ and a scale factor $${\color[RGB]{0,255,255} s}$$. This spline is at least $$C^1$$ continuos.

Matrix form: $$\mathbf{P}(t) = \begin{bmatrix} 1 & t & t^2 & t^3 \end{bmatrix} \begin{bmatrix} 0 & 1 & 0 & 0 \\ -{\color[RGB]{0,255,255} s} & 0 & {\color[RGB]{0,255,255} s} & 0 \\ 2{\color[RGB]{0,255,255} s} & {\color[RGB]{0,255,255} s}-3 & 3-2{\color[RGB]{0,255,255} s} & -{\color[RGB]{0,255,255} s} \\ -{\color[RGB]{0,255,255} s} & 2-{\color[RGB]{0,255,255} s} & {\color[RGB]{0,255,255} s}-2 & {\color[RGB]{0,255,255} s} \end{bmatrix} \begin{bmatrix} {\color[RGB]{255,0,0} P_0} \\ {\color[RGB]{0,0,255} P_1} \\ {\color[RGB]{0,255,0} P_2} \\ {\color[RGB]{255,0,255} P_3} \end{bmatrix} $$

Explicit equation organized by the vectors:

TBD
$$ \mathbf{P}(t) = {\color[RGB]{255,0,0} P_0} \left( 1 - 3 t^2 + 2 t^3 \right) + {\color[RGB]{0,0,255} v_0} \left( t - 2 t^2 + t^3 \right) + {\color[RGB]{0,255,0} P_1} \left( 3 t^2 - 2 t^3 \right) + {\color[RGB]{255,0,255} v_1} \left( - t^2 + t^3 \right) $$

Explicit equation organized by the powers of $$t$$:

$$ \mathbf{P}(t) = t^0 \left( {\color[RGB]{255,0,0} P_0} \right) + t^1 \left( {\color[RGB]{0,0,255} v_0} \right) + t^2 \left( - 3 {\color[RGB]{255,0,0} P_0} - 2 {\color[RGB]{0,0,255} v_0} + 3 {\color[RGB]{0,255,0} P_1} - {\color[RGB]{255,0,255} v_1} \right) + t^2 \left( 2 {\color[RGB]{255,0,0} P_0} + 1 {\color[RGB]{0,0,255} v_0} - 2 {\color[RGB]{0,255,0} P_1} + {\color[RGB]{255,0,255} v_1} \right) $$

The Hermite spline is related to the Bézier splines of the basis of:

$$\begin{align} {\color[RGB]{255,0,0} B_0} &= {\color[RGB]{255,0,0} P_0} \\ {\color[RGB]{0,0,255} B_1} &= {\color[RGB]{255,0,0} P_0} + \frac{ {\color[RGB]{0,0,255} v_0} }{3} \\ {\color[RGB]{0,255,0} B_2} &= {\color[RGB]{0,255,0} P_1} - \frac{ {\color[RGB]{255,0,255} v_1} }{3} \\ {\color[RGB]{255,0,255} B_3} &= {\color[RGB]{0,255,0} P_1} \end{align}$$

=Householder's method= The generalization of the Householder's method of order $$p$$ is:

$$y_{n+1} = y_n + p\; \frac{ \frac{ \operatorname{d}^{p-1} }{ \operatorname{d}^{p-1} y_n } \frac{ 1 }{ f\left(y_n\right) } }{ \frac{ \operatorname{d}^{p} }{ \operatorname{d}^{p} y_n } \frac{ 1 }{ f\left(y_n\right) } } $$

Householder's method of order 1 is just Newton's method:

$$y_{n+1} = y_n - \frac{ f\left(y_n\right) }{ f'\left(y_n\right) }$$

Householder's method of order 2 is just Halley's method:

$$y_{n+1} = y_n - \frac{ 2 f\left(y_n\right) f'\left(y_n\right)}{ 2\left(f'\left(y_n\right)\right)^2 - f\left(y_n\right) f''\left(y_n\right) }$$

Householder's method of order 3 is:

$$y_{n+1} = y_n - \frac{ 6 f\left(y_n\right) f'\left(y_n\right)^2 - 3 f\left(y_n\right)^2 f\left(y_n\right) }{ f\left(y_n\right)^2 f'\left(y_n\right) + 6 f'\left(y_n\right)^3 - 6 f\left(y_n\right) f'\left(y_n\right) f''\left(y_n\right) }$$

Lambert W
The $$\operatorname{W}_0\left(x\right)$$ has an inverse of $$y e^y - x = 0$$ which has intuitive derivatives of $$\left(y + n\right) e^y$$ for $$n \in \mathbb{N}$$. $$\operatorname{W}_0\left(x\right)$$ is equal to $$\lim_{n\rightarrow\infty}y_n$$

$$y_0 = \ln\left( \frac{2 x + 1}{ \ln\left( x + 1 \right) + 1 } \right)$$

Householder's method of order 1 is :

$$\begin{align}y_{n+1} &= y_n - \frac{ y_n e^{y_n} - x }{ \left(y_n + 1\right) e^{y_n} } \\ &=\frac{ y_n^2 }{ y_n + 1 } + \frac{ x }{ \left(y_n + 1\right) e^{y_n} } \end{align}$$

Householder's method of order 2 is just Halley's method:

$$\begin{align} y_{n+1} &= y_n - \frac{ 2 \left( y_n e^{y_n} - x \right) \left( y_n + 1 \right) e^{y_n}}{ 2\left(\left(y_n + 1\right) e^{y_n}\right)^2 - \left( y_n e^{y_n} - x \right) \left(y_n + 2\right) e^{y_n} } \\ &= y_n - \frac{ 1 }{ \frac{ \left(y_n + 1\right) e^{y_n} } { \left( y_n e^{y_n} - x \right) } - \frac{ 1 }{ 2 } \frac{ y_n + 2 }{ y_n + 1 } } \end{align}$$

Nth roots of x
The $$\sqrt[k]{x} = y$$ has an inverse of $$y^k - x = 0$$ which has intuitive derivatives of $$\frac{\left(k - n\right)!}{n!} y^{k - n} $$ for $$n \in \mathbb{N}$$. $$\sqrt[n]{x}$$ is equal to $$\lim_{n\rightarrow\infty}y_n$$

$$y_0 = 1$$

Householder's method of order 1 is:

$$\begin{align} y_{n+1} &= y_n - \frac{ y_n^k - x }{ k\times y_n^{k - 1} } \\ &= \frac{ \left(k - 1\right)\times y_n^k + x }{ k\times y_n^{k - 1} } \\ &= y_n - \frac{ y_n^{k - 1}\times y_n - x }{ y_n^{k - 1}\times k } \\ \end{align}$$

Householder's method of order 2 is:

$$\begin{align} y_{n+1} &= y_n - \frac{ 2 \left(y_n^k - x\right) k\times y_n^{k - 1} }{ 2\left(k\times y_n^{k - 1}\right)^2 - \left(y_n^k - x\right)\times k\times \left(k - 1\right)\times y_n^{k - 2} } \\ &= y_n - \frac{ 2 \left(y_n^k - x\right) y_n^{k - 1} }{ 2k\times y_n^{2k - 2} - \left(y_n^k - x\right)\times \left(k - 1\right)\times y_n^{k - 2} } \\ &= y_n - \frac{ 2 \left(y_n^k - x\right)\times y_n }{ 2k\times y_n^{k} - \left(y_n^k - x\right)\times \left(k - 1\right) } \end{align}$$

Householder's method of order 3 is:

$$\begin{align} y_{n+1} &= y_n - \frac{ 6 \left(y_n^k - x\right) \left(k\times y_n^{k-1}\right)^2 - 3 \left(y_n^k - x\right)^2 k\times \left(k-1\right)\times y_n^{k-2} }{ \left(y_n^k - x\right)^2 k\times \left(k-1\right)\times \left(k-2\right)\times y_n^{k-3} + 6 \left(k\times y_n^{k-1}\right)^3 - 6 \left(y_n^k - x\right)\times k\times y_n^{k-1}\times k\times \left(k-1\right)\times y_n^{k-2} } \\

&= y_n - \frac{ 6 \left(y_n^k - x\right) k\times y_n^{k-1}\times y_n^{k-1} - 3 \left(y_n^k - x\right)^2 \times \left(k-1\right)\times y_n^{k-2} }{ \left(y_n^k - x\right)^2 \times \left(k-1\right)\times \left(k-2\right)\times y_n^{k-3} + 6 k^2 \times y_n^{k-1}\times y_n^{k-1}\times y_n^{k-1} - 6 \left(y_n^k - x\right)\times y_n^{k-1}\times k\times \left(k-1\right)\times y_n^{k-2} } \\

&= y_n - \frac{ 6 \left(y_n^k - x\right) k\times y_n^{k}\times y_n - 3 \left(y_n^k - x\right)^2 \times \left(k-1\right)\times y_n }{ \left(y_n^k - x\right)^2 \times \left(k-1\right)\times \left(k-2\right) + 6 k^2 \times y_n^{k}\times y_n^{k} - 6 \left(y_n^k - x\right)\times k\times \left(k-1\right)\times y_n^{k} } \\ \end{align}$$

=Test=