# Implementing trig functions for dual numbers

I'm curious, how do common trig functions get implemented for dual numbers? One way would be to use the power series definition, but that seems inefficient

• You mean the numbers of the form $a + b \varepsilon$, with $\varepsilon^2 = 0$? I never saw anything about it. Good question. Aug 16, 2014 at 22:49

Suppose $x=u+v\varepsilon$ where $u,v\in\mathbb C$ and $\varepsilon\ne0=\varepsilon^2$. \begin{align} \sin x & = x - \frac{x^3} 6 + \frac{x^5}{120} - \frac{x^7}{5040} + \cdots \\[8pt] & = (u+v\varepsilon) - \frac{u^3 + 3u^2 v\varepsilon}6 + \frac{u^5 + 5u^4 v\varepsilon}{120} - \frac{u^7+7u^6 v\varepsilon}{5040} + \cdots \tag 1 \\[8pt] & = \sin u + v\varepsilon\left(1 - \frac{u^2}{2} + \frac{u^4}{24} - \frac{u^6}{720} +\cdots\right) \\[8pt] & = \sin u + v\varepsilon\cos u. \end{align} In $(1)$, I am simply applying the binomial theorem, and most of the terms vanish.

And so on $\ldots\ldots$

Power series are used here not for computing, but for establishing the trigonometric identity $$\sin(u + v\varepsilon) = \sin u + v\varepsilon\cos u$$ whenever $\varepsilon$ is a non-zero object whose square is $0$ and there's enough commutativity. For example, when you multiply matrices, they don't commute with each other but when you multiply a matrix by a scalar, those do.

• It's rather beautiful what you've shown here. Intuitively, $\varepsilon$ is "small". In view of that intuition, note that $\cos(v \varepsilon) = 1$ and $\sin (v \varepsilon)=v \varepsilon$ therefore, the result you derive follows from the standard adding angles formula for sine. Aug 17, 2014 at 2:27
• That $\cos(v\varepsilon)=1$ and $\sin(v\varepsilon)=v\varepsilon$ follows from the power series as above, and then we can say $\sin(u+v\varepsilon)=\sin u\cos(v\varepsilon)+\cos u\sin(v\varepsilon)$ $=\sin u + v\varepsilon\cos u$. To make everything rigorous, maybe we'd want to use power series to show that the identity for the sine of a sum applies to dual numbers. Aug 17, 2014 at 17:14

Given that $$\epsilon^2 = 0$$ with $$\epsilon \neq 0$$, one can use Taylor expansion:

$$f(a + b\epsilon) = f(a) + b\epsilon f'(a)$$

For trigonometric functions:

$$\cos\left({a+b\epsilon}\right) = \cos{a} - b\epsilon\sin{a} \\ \sin\left({a+b\epsilon}\right) = \sin{a} + b\epsilon\cos{a} \\ \tan\left({a+b\epsilon}\right) = \tan{a} + b\epsilon\sec^2{a} \\ ...\text{etc}.$$

You can also start from the argument addition formulas and proceed by evaluating only $\sin (\epsilon) , \cos (\epsilon), \tan (\epsilon), \cot(\epsilon)$. Then you can evaluate the functions from their Taylor expansions. That is $\cos (\epsilon) = 1$, $\sin (\epsilon)= \epsilon$, $\tan (\epsilon)= \epsilon$ but $\cot (\epsilon)$ is undefined because $\epsilon$ does not have an inverse.