3

I'm working on some code which utilizes Newton's method, and I would like to take advantage of dual numbers to simplify taking the derivative. I've worked out a class definition Dual which works great for polynomials, pow (where either base or exponent is real) exp, and log.

However, I am a bit stymied at raising a dual number to the power of another dual number, e.g.

$(a+b\varepsilon)^{(c+d\varepsilon)}$

I used the general form derived from the Taylor series $f(a+b\varepsilon) = f(a) + bf'(a)\varepsilon$ to derive the rules for $x^n$ and $n^x$ where $n$ is real and $x$ is dual. For those, I got:

$x^n = a^n + bna^{n-1}$ , where $ x = a+b\varepsilon$

$n^y = n^c + d\ln(n)n^{c}$ , where $ y = c+d\varepsilon$

Substituting and simplifying, I end up with:

$x^y = a^c + (d\ln(a)a^c + bca^{c-1})\varepsilon$

This seems to work right in my code, but I do not know if this is actually correct. The implementations of exp and pow work properly with this more general code, and $\varepsilon^\varepsilon = 1 + NaN\varepsilon$, which is a good-ish sign (if I got something well-formed, that would be more troubling).

Is this formula valid?

The Art Of Repetition
  • 2,428
  • 1
  • 7
  • 34

4 Answers4

8

$\def\e{\varepsilon}$\begin{align*} (a+b\e)^{c+d\e} &= \exp((c+d\e)\ln(a+b\e)) & x=e^{\ln x} \\ &=\exp((c+d\e)(\ln a+\ln(1+b\e/a))) \\ &=\exp((c+d\e)(\ln a+b\e/a)) & \ln(1+x)=x+\mathrm{h.o.} \\ &=\exp(c\ln a+\e(d\ln a+bc/a))\\ &=a^c e^{\e(d\ln a+bc/a)} \\ &=a^c (1+\e(d\ln a+bc/a)). & e^x=1+x+\mathrm{h.o.} \end{align*}

user26872
  • 20,221
  • 1
    That is really crafty, especially using the Euler form of dual numbers (I just learned about that this morning)! What does h.o. stand for though? – DeusXMachina Sep 05 '16 at 21:06
  • @DeusXMachina: Glad to help. "h.o." stands for "higher order," in this case $O(x^2)$. For dual numbers this contribution vanishes. – user26872 Sep 05 '16 at 21:27
  • 1
    Thanks! So is that like, $\varepsilon^n$ for $n > 1$ for example? – DeusXMachina Sep 05 '16 at 21:29
  • Exactly. The Taylor series for dual numbers is just the linear approximation. – user26872 Sep 05 '16 at 21:47
  • 1
    even if this topic is over 3-years, but i would like to ask, where i can find a good and understandble literature about dual-numbers. Specially i would like to know where i can find @user26872 derivation of the power rule using exp-func? thanks – arash javan Jun 14 '19 at 08:39
  • @arashjavan: I do not have a good reference for you. Having a physics background I encountered the Grassmann numbers first. The dual numbers are a simple example of Grassmann numbers. The wikipedia page for dual numbers is not a bad place to start. In my answer I just perform a Taylor expansion in small $\varepsilon$, neglecting terms of order $\varepsilon^2$ and higher. This requires knowledge of Taylor series. – user26872 Jun 14 '19 at 13:55
  • 1
    How do you deal with dual number with negative real part (a<0), since the result makes use of ln(a) ? – mocquin May 20 '24 at 15:44
  • @mocquin: Since the dual number $a+b\varepsilon$ is defined only for real $a,b$, this operation is undefined for $a\le 0$. – user26872 May 21 '24 at 01:16
4

The accepted answer is the correct one. The derivation is cool but there is an easier way to get to this result. Notice that the result is just the real function + $\epsilon$ times the sum of the results you got for $x^n$ and $n^y$. You already know $$f(a+b\epsilon) = f(a) + f'(a)b\epsilon.$$ In $x^y$ you have a function with two arguments, and this works in a similar way: $$f(a+b\epsilon,c+d\epsilon) = f(a,c) + \frac{\partial}{\partial a}f(a,c)b\epsilon + \frac{\partial}{\partial c}f(a,c)d\epsilon. $$ Applying this to $x^y$ you get your result: $$\left(a+b\epsilon\right)^{c+d\epsilon} = a^c + ca^{c-1}b\epsilon +\ln(a)a^cd\epsilon.$$

Anixx
  • 10,161
Dick
  • 41
  • 2
0

The other answer is not very consistent with the set of Dual Numbers. You don't need any approximation to prove this. First suppose that $a\neq 0\\$. The second step is to prove that for a generic Dual Number $z=a+\epsilon b\,\,\text{with } a\neq 0$, holds : \begin{align} z=e^{\log(z)} \end{align} and holds since for the Dual Numbers set we have the following: \begin{align*} \log(z)= \log(a+\epsilon b)=\log(a)+\frac{b}{a}\epsilon \end{align*} \begin{align*} e^{z}= e^{a+\epsilon b}=e^a+e^ab\epsilon \end{align*} Combining them we have \begin{align*} e^{\log(z)}= e^{\log(a)+\epsilon \frac{b}{a} }=e^{\log(a)}+e^{\log(a)}\frac{b}{a}\epsilon=a+\epsilon b=z \end{align*} Coming back to the original problem we have: \begin{align*} (a+b\epsilon)^{c+d\epsilon} &= e^{ (c+d\epsilon)\log(a+b\epsilon) } & z=e^{\log z} \\ &=e^{ (c+d\epsilon)(\log a+b\epsilon/a) } & \log(a+\epsilon b)=\log(a)+\frac{b}{a}\epsilon\\ &=e^{ c\log a+\epsilon(d\log a+b c/a) }& \epsilon^2=0 \\ &=e^{c\log a}\,e^{ \epsilon\,d\log a }\,e^{ \epsilon \frac{b\,c}{a} }\\ &=a^{c+\epsilon d}\,e^{\epsilon \frac{b\,c}{a}} \end{align*} or, if you prefer \begin{align*} (a+b\epsilon)^{c+d\epsilon} &=a^{c+\epsilon d}\,e^{\epsilon \frac{b\,c}{a}}=a^{c+\epsilon d}\,(1+\epsilon \frac{b\,c}{a}) \end{align*}

Nicola
  • 29
  • All dual numbers may be written in the form $A+B\epsilon$ for some $A,B\in\mathbb{R}$. Notice that your result is not in this form. – user26872 Jan 17 '18 at 14:31
0

In Mathematica use this code:

$Pre = MatrixFunction[
      Function[ε, #], {{0, 0}, {1, 0}}] /. {{a_, 
        b_}, {0, a_}} -> a + ε b /. {{a_, 0}, {b_, a_}} -> a + ε b &;

(a + b ε)^(c + d ε)

The result:

a^c + a^(-1 + c) (b c + a d Log[a]) ε
Anixx
  • 10,161