Draft:Dual numbers for first order sensitivity analysis

Dual numbers, like complex, are a subset of hypercomplex numbers. Dual numbers consist of a real and imaginary part (aka a “dual” part), like complex, but follow different algebraic rules. In summary, whereas for complex numbers the imaginary unit satisfies , for dual numbers the imaginary unit satisfies , with . However, for sensitivity analysis, the same numerical procedures are applied using dual numbers as performed when using CTSE. Identical numerical results will be obtained for both methods assuming that a sufficiently small step size is used for CTSE; whereas any step size can be used with dual numbers. There is an advantage and a disadvantage to using dual numbers in place of complex numbers. As an advantage, the method using dual numbers to compute sensitivities is step size independent; therefore, a typical step size is . This is in contrast to CTSE where a step size of is required. A second advantage is that dual numbers can also be used to symbolically obtain derivatives for languages that support symbolic computations, whereas CTSE can only compute numerical results unless a “Limit” operator is available and employed. A disadvantage of dual numbers is that they are not intrinsic to today’s programming languages and a support library must be provided. As a result, using dual numbers may be significantly slower than using complex numbers. A second disadvantage for dual numbers is that most engineers and scientists are not familiar with dual numbers. Therefore, a short introduction is provided.

Dual numbers are a subset of hypercomplex numbers, as shown in Figure . They consist of a real part and an imaginary part of the form where and are real numbers, and denotes the imaginary number. Here is analogous to for complex numbers but it is more traditional to use . However, contrary to complex numbers, , with . The real and imaginary parts of a dual number can be extracted as , and . Consider the Taylor series expansion of a dual number expanded about ,

where denotes the first derivative of with respect to , the second derivative, and the nth derivative. Utilizing the fact that , for , the dual Taylor series is truncated as

As we will see, we can use dual numbers to compute first order derivatives analogous to CTSE if we consider a perturbation by step size h along the imaginary axis. In this case, the Taylor series becomes

Writing this result in terms of the generic evaluation point , the first order derivative is obtained as

If we use a step size of , the derivative is obtained as

Notice here that the derivative is an equal sign, not approximately equal, as is true for CTSE. As a result, the dual-step method is independent of step size; therefore, a step size of is often used.

As shown in Section 4, Dual numbers can also be defined in terms of a Cauchy-Riemann matrix of all real numbers. Hence, operations with dual numbers can be accomplished using matrices of all real numbers.

A comparison of using complex and dual numbers for differentiation is shown in Table 1. Note that both methods use the identical formula for differentiation with the sole difference being that the step size must be small for complex numbers but it can be arbitrary for dual numbers.

1 Overview of dual numbers

edit

The definitions of addition, subtraction, multiplication, and division of dual numbers are straightforward. Functions of dual numbers are also straightforward

to compute using the Taylor series definition, see equation 1. Many of these properties are self-evident. Consider the following cases with the definitions   and  , where   are real numbers.

1.1 Notation

edit

The standard notation for dual numbers is  ; however, it is convenient to also represent dual number as  . This longer form is especially useful in computer programs. Both formats will be used here.

1.2 Addition and subtraction

edit

 . Similarly,  . In addition, the addition or subtraction of a real number with a dual number only affects the real portion of the dual number, e.g.,  .

1.3 Multiplication

edit

 . However, since  . In addition, the multiplication of a real number with a dual number affects both the real and imaginary portions of the dual number, e.g.,  . That is, one can always consider a real number as a special case of a dual number with a zero imaginary part.

1.4 Negation of a dual number

edit

Negation of a dual number is a special case of a real multiplication,  .

1.5 Conjugate of a dual number

edit

The conjugate of a dual number is analogous to that of a complex number, in particular,  .

1.1.6 Division of a dual number by a dual number

edit

The division of two dual numbers is facilitated through the use of the dual conjugate,   . In this case  .

Division is defined as follows:  . Note, division by a dual number of the form   is not defined.

1.1.7 Division of a dual number by a real number

edit

The division of a dual number by a real number can be defined as a subset of a dual number divided by a dual number with  . Therefore,  .

 

 

2 Functions of dual numbers

edit

Functions of dual numbers can be determined in a straightforward manner using the Taylor series definition of a dual number. This definition is,   . Notice the the function   and its derivative are only evaluated at the real number  . Several examples are shown in Table 3. Construction of functions of dual numbers is straightforward given the function and its derivative, both evaluated at the real variable. For example, to develop a dual log function, one needs the log and its derivative evaluated at the parameter  . This procedure gives the function   .

Note, it may be convenient to provide a numerical derivative instead of an analytical function. For example, one could use CTSE to compute the derivative of the gamma function, that is,   . In this way, a formal symbolic derivative is not required.

 

 

2.1 Dual raised to a dual power

edit

A dual number raised to a dual power can be determined using the exponential and logarithm functions of dual numbers. Consider  . This situation can be addressed using the formula analogous to real numbers,  . The end result is  . Substituting for   , we obtain  .

2.2 Dual raised to a real power

edit

A dual number raised to a real power can be determined as a special case of a dual number raised to a dual power. If we use the notation   then   and  . The result is   . For example   .

2.3 Real raised to a dual number

edit

This case can be considers as a subset of a dual raised to a dual power with  . The result is   .

3 Symbolic derivative examples using elementary functions

edit

An attractive feature of using dual numbers is that they can be used to compute symbolic and numerical derivatives. While their primary application is within numerical algorithms and programs, symbolic derivatives are often useful for learning and exploratory purposes. This is especially true when using dual numbers with computer algebra systems. In addition, as shown in Section XXX ( what section did you want to reference here Reference a section), symbolic derivatives allow one to compute mixed and higher order derivates using dual numbers. However, of course, there are already sophisticated computer algebra systems for computing arbitrary symbolic derivatives of arbitrary order.

The use of dual numbers to compute first order derivatives can be easily demonstrated using simple functions. For computing derivatives, the imaginary component of the dual function is the step size  . In this case, unlike CTSE, we do not need to have the step size approach zero, that is, we do not need  . In fact, we will see that it is convenient to use  . In the examples below, we use   and  . That is, in order to compute the derivative of the function  , we use replace   with    and  .

Example:  

Consider the function  . Then,   , and  .

Example: f(x)=x^{3}

Consider the function f(x)=x^{3}. Then f(x+\epsilon)=(x+\epsilon)^{3}=(x^{2}+2x\epsilon)(x+\epsilon)=x^{3}+(2x^{2}+x)\epsilon=x^{3}+3x^{2}\epsilon. Then f'(x)=Im(f(x+\epsilon))=3x^{2}.

Example: f(x)=e^{x}

Consider the function f(x)=e^{x}. This case is a subset of a dual raised to a dual power. In particular, we have (a+b\epsilon)^{c+d\epsilon}=a^{c}+a^{c-1}(ad\ln(a)+cb)\epsilon  with a=e, b=0,c=x, and d=1. The result is

f(x+\epsilon)=e^{x+\epsilon}=e^{x}+e^{x}(1)ln(e)\epsilon=e^{x}+e^{x}\epsilon  Then f'(x)=Im(f(x+\epsilon))=e^{x}.

Example: f(x)=\sin(x)

Consider the function f(x)=\sin(x). Using the definition as shown in Table [tab:dual functions] with a=x, and h=1, it is clear f'(x)=\cos(x).

Example: f(x)=\cos(x)

Consider the function f(x)=\cos(x). Using the definition as shown in Table [tab:dual functions] with a=x, and h=1, it is clear f'(x)=-\sin(x).

Example: f(x)=\tan(x)

Consider the function f(x)=\tan(x).

f(x+\epsilon) =tan(x+\epsilon)

= \frac{\sin(x+\epsilon)}{\cos(x+\epsilon)}=\frac{\sin(x)+\cos(x)\epsilon}{\cos(x)-\sin(x)\epsilon}=\frac{\sin(x)+\cos(x)\epsilon}{\cos(x)-\sin(x)\epsilon}\cdot\frac{\cos(x)+\sin(x)\epsilon}{\cos(x)+\sin(x)\epsilon}

= \frac{\sin(x)\cos(x)+\sin^{2}(x)\epsilon+\cos^{2}(x)\epsilon+\cos(x)\epsilon^{2}}{\cos^{2}(x)}

= \frac{\sin(x)\cos(x)+(\sin^{2}(x)+\cos^{2}(x))\epsilon}{\cos^{2}(x)}=\frac{\sin(x)}{\cos(x)}+\frac{1}{\cos^{2}(x)}\epsilon

Hence, f'(x)=\frac{1}{\cos^{2}(x)}=\csc^{2}(x).

Example: f(x)=\sinh(x)

Consider the function f(x)=\sinh(x)=\frac{1}{2}(e^{x}-e^{-x}).

f(x+\epsilon) =\sinh(x+\epsilon)=\frac{1}{2}(e^{x+\epsilon}-e^{-(x+\epsilon)})=\frac{1}{2}((e^{x}+e^{x}\epsilon)-(e^{-x}-e^{-x}\epsilon))

= \frac{1}{2}(e^{x}-e^{-x})+\frac{1}{2}(e^{x}+e^{-x})\epsilon

= \sinh(x)+\cosh(x)\epsilon

Hence, f'(x)=\cosh(x).

Example: f(x)=\cosh(x)

Consider the function f(x)=\cosh(x)=\frac{1}{2}(e^{x}+e^{-x}).

f(x+\epsilon) =\cosh(x+\epsilon)=\frac{1}{2}(e^{x+\epsilon}+e^{-(x+\epsilon)})=\frac{1}{2}((e^{x}+e^{x}\epsilon)+(e^{-x}-e^{-x}\epsilon))

= \frac{1}{2}(e^{x}+e^{-x})+\frac{1}{2}(e^{x}-e^{-x})\epsilon

= \cosh(x)+\sinh(x)\epsilon

Hence, f'(x)=\sinh(x).

Example: f(x)=xe^{x}

Consider the function f(x)=xe^{x}.

f(x+\epsilon) =(x+\epsilon)e^{x+\epsilon}=(x+\epsilon)(e^{x}+e^{x}\epsilon)

= xe^{x}+(xe^{x}+e^{x})\epsilon+e^{x}\epsilon^{2}

= xe^{x}+(xe^{x}+e^{x})\epsilon

Hence, f'(x)=(x+1)e^{x}.

Example: f(x)=\frac{1}{x}

Consider the function f(x)=\frac{1}{x}.

f(x+\epsilon) =\frac{1}{x+\epsilon}=\frac{1}{x+\epsilon}\cdot\frac{x-\epsilon}{x-\epsilon}

= \frac{x-\epsilon}{x^{2}}=\frac{1}{x}-\frac{1}{x^{2}}\epsilon

Hence, f'(x)=-\frac{1}{x^{2}}.

Example: f(x)=\sin(2x^{2})

Consider the function f(x)=\sin(2x^{2}).

f(x+\epsilon) =\sin(2(x+\epsilon)^{2})=\sin(2(x^{2}+2x\epsilon+\epsilon^{2}))=\sin(2x^{2}+4x\epsilon)

Using the fact that \sin(a+b\epsilon)=\sin(a)+b\cos(a), with a=2x^{2}, and b=4x, this yields f(x+\epsilon)=\sin(2x^{2})+4x\cos(2x^{2})\epsilon . Hence, f'(x)=4x\cos(2x^{2}).

Example: f(x)=\sin(x)/x

Consider the function f(x)=\sin(x)/x.

f(x+\epsilon) =\frac{\sin(x+\epsilon)}{x+\epsilon}=\frac{\sin(x+\epsilon)}{x+\epsilon}\cdot\frac{x-\epsilon}{x-\epsilon}=

= \frac{(\sin(x)+\cos(x)\epsilon)(x-\epsilon)}{x^{2}}=\frac{1}{x^{2}}(x\sin(x)+(-\sin(x)+xcos(x))\epsilon-\cos(x)\epsilon^{2})

= \frac{1}{x^{2}}(x\sin(x)+(-\sin(x)+xcos(x))\epsilon)

= \frac{\sin(x)}{x}+\frac{-\sin(x)+x\cos(x)}{x^{2}}\epsilon=\frac{\sin(x)}{x}+\left(-\frac{\sin(x)}{x^{2}}+\frac{\cos(x)}{x}\right)\epsilon

Hence, f'(x)=-\frac{\sin(x)}{x^{2}}+\frac{\cos(x)}{x}.

Example: f(x)=\sqrt{x}

Consider the function f(x)=\sqrt{x}. This function is a subset of a dual number raised to a real power. We can use the relationship (a+b\epsilon)^{c}=a^{c}+cba^{c-1}\epsilon , with a=x,b=1, and c=1/2 to yield

f(x+\epsilon) =(x+\epsilon)^{1/2}=x^{1/2}+1/2x^{-1/2}\epsilon=\sqrt{x}+\frac{1}{2\sqrt{x}}\epsilon

Hence, f'(x)=\frac{1}{2\sqrt{x}}.