Category Archives: Computer Algebra

Introducing Operator Delta

The r^{th} order finite difference of functionf(x) is defined by

\Delta^r f(x) = \begin{cases} f(x+1)-f(x), r=1\\ \Delta(\Delta^{r-1}f(x)), r > 1\end{cases}

From this definition, we have

\Delta f(x) = \Delta^1 f(x) = f(x+1)-f(x)

and,

\Delta^2 f(x) = \Delta (\Delta^{2-1} f(x))

= \Delta (\Delta f(x))

= \Delta( f(x+1)-f(x))

= (f(x+2)-f(x+1)) - (f(x+1)-f(x))

= f(x+2)-2f(x)+f(x+1)

as well as

\Delta^3 f(x) = \Delta (\Delta^2 f(x))

= \Delta (f(x+2)-2f(x)+f(x+1))

= (f(x+3)-2f(x+1)+f(x+2)) - (f(x+2)-2f(x)+f(x+1))

= f(x+3)-3f(x+2)+3f(x+1)-f(x)

The function shown below generates \Delta^r f(x), r:1\rightarrow 5 (see Fig. 1).

delta_(g, n) := block(
    local(f),
    
    define(f[1](x), 
           g(x+1)-g(x)),

    for i : 2 thru n do (
        define(f[i](x), 
               f[i-1](x+1)-f[i-1](x))
    ),

    return(f[n])
);

Fig. 1

Compare to the result of expanding (f(x)-1)^r=\sum\limits_{i=0}^r(-1)^i \binom{r}{i} f(x)^{r-i}, r:1\rightarrow 5 (see Fig. 2)

Fig. 2

It seems that

\Delta^r f(x) = \sum\limits_{i=0}^r(-1)^i \binom{r}{i} f(x+r-i)\quad\quad\quad(1)

Lets prove it!

We have already shown that (1) is true for r= 1, 2, 3.

Assuming (1) is true when r=k-1 \ge 4:

\Delta^{k-1} f(x) = \sum\limits_{i=0}^{k-1}(-1)^i \binom{r}{i} f(x+k-1-i)\quad\quad\quad(2)

When r=k,

\Delta^k f(x) = \Delta(\Delta^{k-1} f(x))

\overset{(2)}{=}\Delta (\sum\limits_{i=0}^{k-1}(-1)^i \binom{k-1}{i}f(x+k-1-i))

=\sum\limits_{i=0}^{k-1}(-1)^i \binom{k-1}{i}f(x+1+k-1-i)-\sum\limits_{i=0}^{k-1}(-1)^i \binom{k-1}{i}f(x+k-1-i)

=(-1)^0 \binom{k-1}{0}f(x+k-0)

+\sum\limits_{i=1}^{k-1}(-1)^i \binom{k-1}{i}f(x+k-i)-\sum\limits_{i=0}^{k-2}(-1)^i \binom{k-1}{i}f(x+k-1-i)

-(-1)^{k-1}\binom{k-1}{k-1}f(x+k-1-(k-1))

\overset{\binom{k-1}{0} = \binom{k-1}{k-1}=1}{=}

f(x+k)+ \sum\limits_{i=1}^{k-1}(-1)^i \binom{k-1}{i}f(x+k-i)-\sum\limits_{i=0}^{k-2}(-1)^i \binom{k-1}{i}f(x+k-1-i) -(-1)^{k-1}f(x)

=f(x+k)+ \sum\limits_{i=1}^{k-1}(-1)^i \binom{k-1}{i}f(x+k-i)+\sum\limits_{i=0}^{k-2}(-1)^{i+1}\binom{k-1}{i}f(x+k-1-i) -(-1)^{k-1}f(x)

\overset{j=i+1, i:0 \rightarrow k-2\implies j:1 \rightarrow k-1}{=}

f(x+k)+ \sum\limits_{i=1}^{k-1}(-1)^i\binom{k-1}{i}f(x+k-i) + \sum\limits_{j=1}^{k-1}(-1)^j \binom{k-1}{j-1}f(x+k-j)-(-1)^{k-1}f(x)

= f(x+k)+ \sum\limits_{i=1}^{k-1}(-1)^i\binom{k-1}{i}f(x+k-i) + \sum\limits_{i=1}^{k-1}(-1)^i\binom{k-1}{i-1}f(x+k-i)+(-1)^k f(x)

= f(x+k) + \sum\limits_{i=1}^{k-1}(-1)^i f(x+k-i) (\binom{k-1}{i} + \binom{k-1}{i-1})+(-1)^k f(x)

\overset{\binom{k-1}{i} + \binom{k-1}{i-1}=\binom{k}{i}}{=}

f(x+k)+ \sum\limits_{i=1}^{k-1}(-1)^i \binom{k}{i} f(x+k-i)+(-1)^k f(x)

= (-1)^0 \binom{k}{0}f(x+k-0)+\sum\limits_{i=1}^{k-1}(-1)^i \binom{k}{i} f(x+k-i)+(-1)^k \binom{k}{k} f(x+k-k)

= \sum\limits_{i=0}^{k}(-1)^i \binom{k}{i} f(x+k-i)

Advertisements

A pair of non-identical twins

A complex number x + i y can be plotted in a complex plain where the x coordinate is the real axis and the y coordinate the imaginary.

Let’s consider the following iteration:

z_{n+1} = z_{n}^2 + c\quad\quad\quad(1)

where z, c are complex numbers.

If (1) are started at z_0 = 0 for various values of c and plotted in c-space, we have the Mandelbrot set:

When c is held fixed and points generated by (1) are plotted in z-space, the result is the Julia set:

Constructing the tangent line of circle without calculus

The tangent line of a circle can be defined as a line that intersects the circle at one point only.

Put a circle in the rectangular coordinate system.

Let (x_0, y_0) be a point on a circle. The tangent line at (x_0, y_0) is a line intersects the circle at (x_0, y_0) only.

Let’s first find a function y=kx+m that represents the line.

From circle’s equation x^2+y^2=r^2, we have

y^2=r^2-x^2

Since the line intersects the circle at (x_0, y_0) only,

r^2-x^2=(kx+m)^2

has only one solution.

That means

k^2x^2+x^2+2kmx+m^2-r^2 =0

has only one solution. i.e., its discriminant

(2km)^2-4(k^2+1)(m^2-r^2)=0\quad\quad\quad(1)

By the definition of slope,

kx+m-y_0 = k(x-x_0).

It follows that

m =y_0-kx_0\quad\quad\quad(2)

Substitute (2) into (1) and solve for k gives

k = \frac{-x_0}{y_0}\quad\quad\quad(3)

The slope of line connecting (0, 0) and (x_0, y_0) where x_0 \neq 0 is \frac{y_0}{x_0}.

Since \frac{-x_0}{y_0}\cdot \frac{y_0}{x_0} = -1, the tangent line is perpendicular to the line connecting (0, 0) and (x_0, y_0).

Substitute (3) into y = k x +m, we have

y=-\frac{x_0}{y_0} x + m\quad\quad\quad(4).

The fact that the line intersects the circle at (x_0, y_0) means

y_0 = -\frac{x_0^2}{y_0} + m

or

y_0^2=-x_0^2+ my_0.

Hence,

m =\frac{x_0^2+y_0^2}{y_0} =  \frac{r^2}{y_0}.

It follows that by (4),

x_0 x +y_0 y = r^2\quad\quad\quad(5)

(5) is derived under the assumption that y_0 \neq 0. However, by letting y_0 =0 in (5), we obtain two tangent lines that can not be expressed in the form of y=kx+m:

x=-r, x=r

Constructing the tangent line of quadratic without calculus

The tangent line of a quadratic function at (x_0, y_0)is a line y=kx+m that intersects y=ax^2+bx+c at (x_0, y_0=ax_0^2+bx_0+c) only.

The presence of function y=kx+m immediately excludes the vertical line x=x_0 which also intersects y=ax^2+bx+c at (x_0, ax_0^2+bx_0+c) only (see Fig. 1).

Fig. 1

Let’s find k.

Line y = kx+m intersects y=ax^2+bx+c at (x_0, ax_0^2+bx_0+c) only means quadratic equation

ax^2+bx +c =kx +m

has only one solution. That is, the discriminant of ax^2+bx+c-kx-m =0 is zero:

(b-k)^2-4a(c-m) = 0\quad\quad\quad(1)

Fig. 2

And, by the definition of slope (see Fig. 2),

(x-x_0)k = (kx+m)-(ax_0^2+bx_0+c).

It follows that

m = (ax_0^2+b_0+c)-x_0 k\quad\quad\quad(2)

Substituting (2) into (1), we have

(b-k)^2-4a(c-((a_0 x^2+b x_0 + c)-x_0 k)=0.

Solve it for k gives

k = 2 a x_0 +b.

Fig. 3

A Proof without Calculus

Now, solve \sin(x)=x.

By inspection, x=0.

Is this the only solution?

Visually, it is difficult to tell (see Fig. 1 and Fig. 2)

Fig. 1

Fig. 2

However, we can prove that 0 is the only solution:

Fig. 3

If 0 < x \leq 1 < \frac{\pi}{2} then from Fig. 3, we have

Area of triangle OAB < Area of circular sector OAB.

That is,

\frac{1}{2}\cdot 1 \cdot \sin(x)< \frac{1}{2}\cdot 1 \cdot x.

Hence,

\forall 0< x \leq 1, \sin(x) < x\quad\quad\quad(1)

If x>1 then

\sin(x) \leq 1 \overset{x>1}{\implies} \sin(x) \leq 1< x \implies \forall x>1, \sin(x) <x\quad\quad\quad(2)

Put (1) and (2) together, we have

\forall x > 0, \sin(x) < x\quad\quad\quad(3)

If x < 0 then

-x > 0 \overset{(3)}\implies \sin(-x) < -x \overset{\sin(-x)=-\sin(x)}\implies -\sin(x) < -x \implies \sin(x) > x

i.e.,

\forall x < 0, \sin(x) > x\quad\quad\quad(4)

Therefore by (3) and (4), we conclude that

only when x = 0, \sin(x)=x.

From proof to simpler proof

Solve \sin(x)=2x for x.

By mere inspection, we have x=0.

Visually, it appears that 0 is the only solution (see Fig.1 or Fig. 2)

Fig. 1

Fig. 2

To show that 0 is the only solution of \sin(x)=2x analytically, let

f(x) = \sin(x)-2x

0 is a solution of \sin(x)=2x means

f(0) = 0\quad\quad\quad(1)

Suppose there is a solution

x^* \neq 0\quad\quad\quad(2)

then,

f(x^*)=\sin(x^*)-2x^*=0\quad\quad\quad(3)

Since f(x) is an function continuous and differentiable on (-\infty, +\infty),

by Lagrange’s Mean-Value Theorem (see “A Sprint to FTC“), there \exists c \in (0, x^*) such that

f(x^*)-f(0)=f'(c)(x^*-0)

\overset{(1), (3)}{\implies} 0 = f'(c) x^*\quad\quad\quad(4)

\overset{(2)}{\implies} f'(c)=0\quad\quad\quad(5).

We know

f'(x) = \cos(x)-2.

From (5), we have

\cos(c)-2=0.

i.e.,

\cos(c)=2.

This is not possible since \forall x \in R, -1 \le \cos(x) \le 1.

A simpler alternative without direct applying Lagrange’s Mean-Value Theorem is:

f(x) = \sin(x)-2x \implies f'(x) = \cos(x) - 2 \overset{-1 \le \cos(x) \le 1}{\implies} f'(x) < 0\implies

f(x) =\sin(x)-2x is a strictly decreasing function.

Since f(0) = 0, \forall x<0, f(x) > 0 and \forall x>0, f(x) < 0.

Therefore, 0 is the only solution of f(x)=0. i.e.,

0 is the only solution of \sin(x) = 2x.