FURTHER STUDY
OF
DISCRETE FUNCTIONS

By: Mohamed Al-Dabbagh (B.Sc. Eng. Tech)
Email: dabbagh@maktoob.com

Abstract: An attempt was made to analytically describe some basic functions which are provided with the libraries of mathematical functions of programming languages. This study will rely on Mathematica in calculating all numerical results. This study provides global methods to calculate some discrete functions, which were previously calculated by using low-level language techniques to chop digits. Using these definitions we can simulate digital signals without the need for IF statements and conditions.

A comparison were made between the formulas provided by this study and some functions provided by Mathematica such as FractionalPart function that converges very slowly or does NOT converge at all to correct results. The formulas derived herein were applied to complex numbers and some interesting results were obtained, such as the integer part of a complex number equals the Floor of its real part, and will be without imaginary part, i.e. the integer part of a complex number is a real number!

Integer Part Function

Starting with the idea of taking the inverse of an argument that represent the inversed function, we can proceed as follows:

f(x) = tan^(-1)(tan(x))      ------------------------------------- (1)

fx = ArcTan[Tan[x]]

ArcTan[Tan[x]]

RowBox[{Plot, [, RowBox[{fx, ,, {x, -2 π, 2 π}, ,, RowBox[{PlotStyle, , RowB ... -π, -π/2, 0, π/2, π, (3 π)/2, 2 π}, {-π/2, 0, π/2}}}], ]}]

[Graphics:HTMLFiles/index_5.gif]

⁃Graphics⁃

figure (1)

It is obvious that graph in figure (1) above has discontinuities at  |x|= π/2, (3π)/2, ... .      We can notice from the graph in figure(1) that a duplication of line segment with a slope=1 occurs periodically, which reminds of using the definition of modulo function. It is not hard to put the graph in figure (1) in the other form (2) considering an appropriate shifting scheme:

1/2tan^(-1)(tan(2x - π/2)) = (x  mod  π/2) - π/4             ----------------------(2)

(2) above utilizes the definition of modulo function:

a  mod  b = a - b INT (a/b)        &nbs ... nbsp;             -------------- - (3)

Re-arranging formula (2) incorporating definition in formula (3) yields:

π/2 INT ((2x)/π) = x - 1/2 tan^(-1)(tan(2x - π/2)) - π/4  

Dividing (x) by 2/πand re-arranging again can yield the following important and basic formula which describes the integer part of any value (x):

INT(x) = x - 1/πtan^(-1)(tan(π(x - 1/2))) - 1/2

Or in Mathematica notation:

Int[x_] := x - 1/πArcTan[Tan[π (x - 1/2)]] - 1/2 ;

Using the magical FullSimplify in Mathematica:

fx = FullSimplify[Int[x]]

-1/2 + x + ArcTan[Cot[π x]]/π

Therefore, we eventually get the definition for the Int(x)as follows:

Int(x) = x + 1/πtan^(-1)(cot(π x)) - 1/2       ------------------(4)

And one can notice that Int(x) represents the Floor of x

x1 = -6 ; x2 = 6 ;

RowBox[{Plot, [, RowBox[{fx, ,, {x, x1 - .1, x2 + .1}, ,, RowBox[{PlotStyle, , RowBox[{{, RowBox[{RowBox[{Thickness, [, 0.01, ]}], ,, RowBox[{GrayLevel, [, 0.1, ]}]}], }}]}]}], ]}]

[Graphics:HTMLFiles/index_22.gif]

⁃Graphics⁃

To get the Ceiling or greatest integer of (x) we add 1 to the Floor, to get:

Gnt(x) = x + 1/πtan^(-1)(cot(π x)) + 1/2       ----------------------(5)

Gnt[x_] := x + ArcTan[Cot[π x]]/π + 1/2 ;

fx = Gnt[x] ;

x1 = -6 ; x2 = 6 ;

RowBox[{Plot, [, RowBox[{fx, ,, {x, x1 - .1, x2 + .1}, ,, RowBox[{PlotStyle, , RowBox[{{, RowBox[{RowBox[{Thickness, [, 0.01, ]}], ,, RowBox[{GrayLevel, [, 0.1, ]}]}], }}]}]}], ]}]

[Graphics:HTMLFiles/index_29.gif]

⁃Graphics⁃

Obviously, formulas (4) and (5) are not defined (discontinuous) when
| x | = 1, 2, 3, ... ... i . e . when   x   is an integer


Fractional Part Function

There are two types of fractional part function:

a- Mechanically isolated fractional part, which is the adopted definition of fractional part implimented by Mathematica, and high-level programming languages (such as the case with symbolic mathematics calculator HP-48SX) and maybe other machines, with the following definition:

FP(x) = SGN(x) ( x -⌊x | ⌋  )     ------------------------------ (6)

b- Natural fractional part

Fr(x) = x - ⌊x⌋     ---------------------------------------- (7)

Natural fractional part given in formula (7) will considered whenever a reference is made to fractional part in this study. Using definition in formula (4) and definition in formula (7):

Fr (x) = x - Int (x)             = x - (x ... - 1/2)   Fr(x) = 1/2 - 1/πtan^(-1)(cot(π x)) ---------------------- (8)

Obviously, the formula is not defined at | x | = 1, 2, 3, ... ... i . e . when   x   is an integer

In Mathematica notation:

Fr[x_] := x - Int[x] ;

eq = Fr[x] ;

FullSimplify[eq]

1/2 - ArcTan[Cot[π x]]/π

fx = 1/2 - ArcTan[Cot[π x]]/π ;

x1 = -π ; x2 = π ;

RowBox[{Plot, [, RowBox[{fx, ,, {x, x1 - .1, x2 + .1}, ,, RowBox[{PlotStyle, , RowBox[{{, RowBox[{RowBox[{Thickness, [, 0.001, ]}], ,, RowBox[{GrayLevel, [, 0.1, ]}]}], }}]}]}], ]}]

[Graphics:HTMLFiles/index_43.gif]

⁃Graphics⁃


Congruences Into Analytical Form

Using the above definitions of integer and fractional parts (formulas 4 and 8) we can put the congruence with the general form:

f(x) ≡0 (mod g(x))       -------------------------- (9)

Then recalling the definition of modulo in formula (3), and replacing (a) by f(x) and (b) by g(x), we can obtain another form of congruence (9) as follows:

f(x) mod g(x) = f(x) - g(x) Int(f(x)/g(x))       ------------------ (9)

Using definition in formula (4):

f (x) mod g (x) = f (x) - g (x) ((f (x))/(g (x)) + 1/πtan^(-1) (cot (π (f (x))/(g (x ... 2371;  f(x) mod g(x) = g(x) Fr(f(x)/g(x))     ----------------------- (10)

Therefore, formula (10) is nothing but the fractional part version of formula (3)

In Mathematica notation:

Modulo[x_, y_] := y Fr[x/y]

General :: spell1 : Possible spelling error: new symbol name \


Absolute Value Function

Absolute value function can also be derived starting with the idea of:

f(x) = sin^(-1)(sin(x))       -------------------------- (11)

In Mathematica notation:

fx = ArcSin[Sin[x]] ;

RowBox[{Plot, [, RowBox[{fx, ,, {x, -2 π, 2 π}, ,, RowBox[{PlotStyle, , RowB ... -π, -π/2, 0, π/2, π, (3 π)/2, 2 π}, {-π/2, 0, π/2}}}], ]}]

[Graphics:HTMLFiles/index_53.gif]

⁃Graphics⁃

We can remember the V-shaped absolute value curve. Shifting the curve to the right by π/2 and up by π/2 will result in the absolute value formula:

absol(x) = sin^(-1)(sin(x - π/2)) + π/2      -------------------------- (11)
        Where | x | < π

For formula (11) to be correct for  | x | <m, it is not hard to prove that the formula should take the following form:

absol(x) = m/π (sin^(-1)(sin(π(x/m - 1/2))) + π/2)       -- ------------------ (11 - 1)

In order for formula (11-1) be global and correct for  | x | <∞, we should use a value instead of (m) such that it should be greater than the absolute value of (x) and (m) should not divide (x). The simplest option that satisfies both conditions is  m = x^2 + 1 ;Therefore, formula (11-1) will be:

absol(x) = (x^2 + 1)/π (sin^(-1)(sin(π(x/(x^2 + 1) - 1/2))) + π/2)       -- ------------------ (11 - 2)

In Mathematica notation:

Absol[x_] := (x^2 + 1)/π (ArcSin[Sin[π (x/(x^2 + 1) - 1/2)]] + π/2) ;

fx = FullSimplify[Absol[x]]

((1 + x^2) ArcCos[Cos[(π x)/(1 + x^2)]])/π

x1 = -π ; x2 = π ;

RowBox[{Plot, [, RowBox[{fx, ,, {x, x1 - .1, x2 + .1}, ,, RowBox[{PlotStyle, , RowBox[{{, RowBox[{RowBox[{Thickness, [, 0.001, ]}], ,, RowBox[{GrayLevel, [, 0.1, ]}]}], }}]}]}], ]}]

[Graphics:HTMLFiles/index_69.gif]

⁃Graphics⁃

Therefore, absolute value function can be re-written in the form:

Absol(x) = (1 + x^2)/πcos^(-1)(cos((π x)/(1 + x^2)))       ---------------------- (12)

In Mathematica notation:


Sign Function

This function will return (positive 1) if the sign of the function is positive and will return (negative 1) when the function is negative; and, is thereby defined:

Sgn(x) = Absol(x)/x  

or

Sgn(x) = (1 + x^2)/(π x) cos^(-1)(cos((π x)/(1 + x^2)))       ---------------------- (13)

In Mathematica notation:

Sgn[x_] := ((1 + x^2) ArcCos[Cos[(π x)/(1 + x^2)]])/(π x) ;

fx = Sgn[x] ;

x1 = -π ; x2 = π ;

RowBox[{Plot, [, RowBox[{fx, ,, {x, x1 - .1, x2 + .1}, ,, RowBox[{PlotStyle, , RowBox[{{, RowBox[{RowBox[{Thickness, [, 0.001, ]}], ,, RowBox[{GrayLevel, [, 0.1, ]}]}], }}]}]}], ]}]

[Graphics:HTMLFiles/index_78.gif]

⁃Graphics⁃


Unit Step Function

Using the appropriate shifting scheme for the Sign Function we can end up with the general form of unit step function:


Ω(x) = 1/4 (Sgn(x) - 1)^2   --------------------------- (14)


or

Ω(x) = 1/4 ((1 + x^2)/(π x) cos^(-1)(cos((π x)/(1 + x^2))) - 1)^2      ------------------ (15)

In Mathematica notation:

Omeg[x_] := 1/4 (-1 + ((1 + x^2) ArcCos[Cos[(π x)/(1 + x^2)]])/(π x))^2

fx = Omeg[(x - 2) (x - 1) (x + 1) (x + 3)] ;

RowBox[{x1 = -4, ;, RowBox[{x2, =, 2.1}], ;}]

RowBox[{Plot, [, RowBox[{fx, ,, {x, x1 - .1, x2 + .1}, ,, RowBox[{PlotRange, , RowBox[ ... Box[{{, RowBox[{RowBox[{Thickness, [, 0.01, ]}], ,, RowBox[{GrayLevel, [, 0.1, ]}]}], }}]}]}], ]}]

[Graphics:HTMLFiles/index_86.gif]

⁃Graphics⁃

The possibilities are endless with custom unit steps, because such unit steps will provide the mean for constructing piecewise functions without the need for programming or using IF statements, for example, if we have the following function:

f(x) = {         x - 1          1<x<2               2         3 - x          -3<x<1

We construct two unit steps function, one Ω((x - 1) (x - 2))and multiply it times x - 1, and the other is Ω((x - 1) (x + 3)) and multiply it times 3 - x^2, and we add the two functions together, as follows in Mathematica notation:


In[1]:=

Omeg[x_] := 1/4 (-1 + ((1 + x^2) ArcCos[Cos[(π x)/(1 + x^2)]])/(π x))^2

In[2]:=

fx = Omeg[(x - 2) (x - 1)] (x - 1) ;

In[3]:=

fx = fx + Omeg[(x - 1) (x + 3)] (3 - x^2) ;

In[4]:=

x1 = -4 ; x2 = 3 ;

In[5]:=

RowBox[{Plot, [, RowBox[{fx, ,, {x, x1 - .1, x2 + .1}, ,, PlotRange {Automatic, {-6, 4 ... ox[{{, RowBox[{RowBox[{Thickness, [, 0.005, ]}], ,, RowBox[{GrayLevel, [, 0.1, ]}]}], }}]}]}], ]}]

[Graphics:HTMLFiles/index_98.gif]

Out[5]=

⁃Graphics⁃


Derivatives of Above Functions
Derivatives of Int(f(x)), Fr(f(x)) and Modulo(f(x),g(x))

Fortunately, all of the above formulas could be derived with respect to their variables, the matter that expands the scope of the useful functions such that methods that need derivatives like Newton-Raphson, and curve fitting could be applied in the intervals of continuity. Using traditional techniques, one can prove the following important formulas:


d/dx (Int(f(x))) = 0   --------------------------- (16)

d/dx (Fr(f(x))) = d/dx (f(x)) = f ' (x) ------------------(17)

The result in formula (17) is interesting as it states that the derivative of the fractional part of a function equals the derivative of the function, and this applies to higher order deriatives of the fractional part function.

d/dx (Modulo(f(x), g(x))) = f ' (x) - g ' (x) Int(f(x)/g(x))         ------ - (18)


Comparison
Between
Some results and
Mathematica Built-in Functions

Hereunder, some results produced by Mathematica's built-in FractionalPart and the results obtained by Fr[x] function derived in this study:

In Mathematica notation:

We have the following function:

In[1]:=

f[x_] := x^5 ;

In[2]:=

Fr[x_] := 1/2 - ArcTan[Cot[π x]]/π ;

gMath(x) will represent Mathematica's built-in FractionalPart

In[3]:=

gMath[x_] := FractionalPart[f[x]] ;

gPaper(x) will represent study's derived Fr(x)

In[4]:=

gPaper[x_] := Fr[f[x]]

The time needed to evaluate the second derivative at x=12.2 (correct to 400 places of decimals) provided that the final result is needed correct to 7 significant figures:

In[5]:=

RowBox[{Timing, [, RowBox[{N, [, RowBox[{RowBox[{gMath'', [, 12.200000000000000000000000000000 ... 000000000000000000000000000000000000000000000000000000000000000000000000000, ]}], ,, 7}], ]}], ]}]

Out[5]=

{70.08 Second,33582.83}

The above result needed 70.08 seconds to evaluate correct to 7 figures (as stated by Mathematica which produced no message indicating that this result is INCORRECT) (the correct result should be 36316.96)

Now the time needed to evaluate the same expression using this paper Fr(x) derivative, at x=12.2 (also correct to 400 places of decimals) provided that the final result is needed correct to 400 significant figures:

In[6]:=

RowBox[{Timing, [, RowBox[{N, [, RowBox[{RowBox[{gPaper'', [, 12.20000000000000000000000000000 ... 0000000000000000000000000000000000000000000000000000000000000000000000000, ]}], ,, 400}], ]}], ]}]

Out[6]=

{0.11 Second,36316.96000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000}

The above result is correct to 400 significant figures and took 1/637 the time taken by Mathematica.!!


Comparison
Between
Some results and
Mathematica Using
Complex Numbers

In[1]:=

f[x_] := Sin[x]

In[2]:=

Int[x_] := -1/2 + x + ArcTan[Cot[π x]]/π ;

In[3]:=

Fr[x_] := 1/2 - ArcTan[Cot[π x]]/π ;

In[4]:=

Modulo[x_, y_] := x - y Int[x/y]

General :: spell1 : Possible spelling error: new symbol name \

In[5]:=

Absol[x_] := ((1 + x^2) ArcCos[Cos[(π x)/(1 + x^2)]])/π ;

In[6]:=

Sgn[x_] := ((1 + x^2) ArcCos[Cos[(π x)/(1 + x^2)]])/(π x) ;

In[7]:=

Modulo1[x_, y_] := y Fr[x/y]

In[8]:=

RowBox[{RowBox[{x, =, RowBox[{110.100000000000000000000000000000000000000000000000000000000000 ... 0000000000000000000000000000000000000000000000000000000000000000000000000000, }]}]}], ;}]

In[10]:=

N[{Int[x], Int[y], Fr[x], Fr[y], Int[x] + Fr[x], Int[y] + Fr[y], Modulo[x, y], Modulo1[x, y], Absol[x], Absol[y], Sgn[x], Sgn[y]}, 20]

Out[10]=

RowBox[{{, RowBox[{RowBox[{110.000000000000000000, +, RowBox[{0.*10^-18,  , }]}], ,, R ... ,  , }]}], ,, RowBox[{1.00000000000000000000, +, RowBox[{0.*10^-20,  , }]}]}], }}]

In[1]:=

RowBox[{RowBox[{x, =, RowBox[{110.100000000000000000000000000000000000000000000000000000000000 ... 0000000000000000000000000000000000000000000000000000000000000000000000000000, }]}]}], ;}]

In[3]:=

N[{IntegerPart[x], IntegerPart[y], FractionalPart[x], FractionalPart[y], IntegerPart[x] + FractionalPart[x], IntegerPart[y] + FractionalPart[y], Mod[x, y], Sign[x]}, 20]

Out[3]=

RowBox[{{, RowBox[{RowBox[{110.000000000000000000, -, RowBox[{30.000000000000000000,  , ᢻ ... }]}], ,, RowBox[{0.96460189476651064794, -, RowBox[{0.26371041809692979567,  , }]}]}], }}]

In[4]:=

Quit


Download Mathematica  Notebook


(C) 2006 Mohamed Al-Dabbagh ----- All rights reserved  (May 27, 2006)


Created by Mathematica  (May 27, 2006)