# The Structure Behind Trigonometric Functions

This entry is dedicated to my friend Bud in Milwaukee.

Sine, cosine, tangent, etc. are actually abbreviations for combinations of complex exponential functions:

$\text{sin}(\theta) = \frac{1}{2i} (e^{i\theta} - e^{-i\theta})$

$\text{cos}(\theta) = \frac{1}{2} (e^{i\theta} + e^{-i\theta})$

$\text{tan}(\theta) = \frac{ e^{i\theta} - e^{-i\theta} }{ i (e^{i\theta} + e^{-i\theta}) }$

It’s just easier to write out something like “cos”, instead of the complex exponential form. However, it is handy to know the complex exponential forms to derive trig identities on the fly. So how exactly are trig functions made of complex exponential functions?

In a previous entry, I briefly discuss how the exponential function relates angle to Cartesian coordinates. When you put an imaginary number in the exponential function it results in a complex number (a number with a real and an imaginary component). If you treat the real component like an $x$ coordinate, and the imaginary component like a $y$ coordinate, then any complex number can represent a point  on a 2-D plane.

To visualize what’s actually going on in terms of geometry, see the figure below. Imagine a point (pictured in red) that can travel along a unit circle (a circle with radius 1). You can track the point’s angular position $\varphi$ along the circle, and you can also track its position in terms of $x$ and $y$. There is a relationship between the two ways to track position, and this relationship can be expressed as:
$e^{i\varphi} = x + iy$

At this point, you may see that $x = \text{cos}(\varphi)$ and $y = \text{sin}(\varphi)$.
By definition, cosine is adjacent over hypotenuse $h$
$\text{cos}(\varphi) = x/h$
and sine is opposite over hypotenuse
$\text{sin}(\varphi) = y/h$
and since radius $= h = 1$, you get:
$x = \text{cos}(\varphi)$ and $y = \text{sin}(\varphi)$

So $e^{i\varphi} = x + iy$ is really:
$e^{i\varphi} = \text{cos}(\varphi) + i \text{sin}(\varphi)$

From this equation, you can get the equations listed at the beginning by adding or subtracting complex conjugates. For example:
Take the complex conjugate (which just means to change all the $i$ to $-i$).
$e^{-i\varphi} = \text{cos}(\varphi) - i \text{sin}(\varphi)$
Now add it to the original to get:
$e^{i\varphi} + e^{-i\varphi} = \text{cos}(\varphi) + i \text{sin}(\varphi) + \text{cos}(\varphi) - i \text{sin}(\varphi)$
$e^{i\varphi} + e^{-i\varphi} = 2 \text{cos}(\varphi)$
Now divide by $2$ and you have the identity of cosine shown at the beginning!
$\text{cos}(\varphi) = \frac{1}{2} (e^{i\varphi} + e^{-i\varphi})$

So how do we know that something like $e^{i\varphi}$ breaks up into a complex number like $x + iy$? One way is through Taylor expansions. I won’t get into how Taylor expansions are derived, since it requires calculus. The only thing you need to know here is that a function can be expressed as an infinitely long polynomial. In the case of the exponential function:
$e^{z} = 1 + z + \frac{1}{2}z^2 + \frac{1}{6}z^3 + \frac{1}{24}z^4 + ...$
or to be complete, we can write it as a summation:
$e^{z} = \sum\limits_{n=0}^{\infty} \frac{1}{n!} z^n$

So if we replace the variable $z$ with $i \varphi$ we get:
$e^{i\varphi} = 1 + i\varphi + \frac{1}{2}(i\varphi)^2 + \frac{1}{6}(i\varphi)^3 + \frac{1}{24}(i\varphi)^4 + ...$
The terms in the polynomial with odd exponents will be imaginary, and the terms with even exponents will be real. Recall that:
$i^0 = 1$
$i^1 = i$
$i^2 = -1$
$i^3 = -i$
$i^4 = 1$
So then we get:
$e^{i\varphi} = 1 + i\varphi - \frac{1}{2}\varphi^2 - \frac{1}{6}i\varphi^3 + \frac{1}{24}\varphi^4 + ...$
We can then group all the real terms together and all the imaginary terms together:
$e^{i\varphi} = \left(1 - \frac{1}{2}\varphi^2 + \frac{1}{24}\varphi^4 -... \right) + i \left( \varphi - \frac{1}{6} \varphi^3 + ... \right)$
or to be complete:
$e^{i\varphi} = \sum\limits_{n=0}^{\infty} \frac{(-1)^n}{(2n)!} \varphi^{2n} + i \sum\limits_{n=0}^{\infty} \frac{(-1)^n}{(2n+1)!} \varphi^{2n+1}$
So you can see that $e^{i\varphi}$ indeed breaks up into a complex number. By definition, this is equivalent to:
$e^{i\varphi} = \text{cos}(\varphi) + i \text{sin}(\varphi)$

It is also worth noting that this gives us the Taylor series for sine and cosine:
$\text{sin}(\varphi) = \sum\limits_{n=0}^{\infty} \frac{(-1)^n}{(2n+1)!} \varphi^{2n+1}$

$\text{cos}(\varphi) = \sum\limits_{n=0}^{\infty} \frac{(-1)^n}{(2n)!} \varphi^{2n}$

For an example, let’s derive a trig identity using the complex exponential forms.
Let’s show that:
$\text{sin}(\theta) \text{cos}(\theta) = \frac{1}{2} \text{sin}(2 \theta)$

First write the complex exponential forms:
$\text{sin}(\theta) = \frac{1}{2i} (e^{i\theta} - e^{-i\theta})$

$\text{cos}(\theta) = \frac{1}{2} (e^{i\theta} + e^{-i\theta})$
Then multiply them:
$\frac{1}{2i} (e^{i\theta} - e^{-i\theta}) \cdot \frac{1}{2} (e^{i\theta} + e^{-i\theta})$
$= \frac{1}{2} \cdot \frac{1}{2i} (e^{2 i \theta} + 1 - 1 - e^{-2 i \theta})$
$= \frac{1}{2} \cdot \frac{1}{2i} (e^{2 i \theta} - e^{-2 i \theta})$
This is the same exponential form as the sine function with a couple adjustments (a factor of $1/2$ out front and a factor of $2$ inside the function):
$= \frac{1}{2} \text{sin} (2 \theta)$

Look up some other trig identities and try to derive them using complex exponentials.

# Imaginary Powers

Imaginary numbers ($i = \sqrt{-1}$) are used to relate Cartesian coordinates to polar coordinates as shown in the figure below. The argument $\varphi$ is the angle from the real axis along the unit circle, and can be expressed as two terms: a real and an imaginary, giving the Cartesian (x,y) position.
$e^{i\varphi} = \text{cos}(\varphi) + i \text{sin}(\varphi) = x + i y$
(If you want to expand beyond the unit circle just multiply by the desired radius: $e^{i\varphi} \rightarrow re^{i\varphi}$)

This is known as the Euler relation, and it gives us some neat results, like:
$e^{i\pi} = -1$
$e^{i \pi /2} = i$
But what happens when you exponentiate $i$ with itself? $i^i$.

From the Euler relation we know that $i=e^{i \pi /2}$, so it’s really a matter of substitution:
$i^i = e^{i \pi / 2 i} = e^{-\pi / 2} = 0.20788...$
So $i^i$ is a real number!

But wait a second, this isn’t the whole answer. We can add or subtract $2\pi$ from any angle and wind up in the same place on the circle. So $i = e^{i \pi /2 + i 2 \pi n}$, where $n$ is any integer. So we end up with a set of values:
$i^i = e^{- \pi /2 - 2 \pi n}$
which are all real!

The curve above goes through the set of values for $i^i$, where $n$ is an integer.
$i^i = \{...,111.32,0.20788,0.00038820,...\}$
But 0.20788… will be looked at as the primary value for now since it is the result when $n=0$, and having one value keeps things simple.

So what happens when we repeat this exponentiation? $i^{i^i}$
First, this can be written in a simpler way:
$^3i = i^{i^i}$
This operation is called “tetration” or “power tower”.
You start from the top and work your way down. So $^3i = i^{i^i} = i^{0.20788}$
Now use the Euler relation again (ignoring $2 \pi n$ terms in the exponential):
$i^{0.20788} = e^{i \pi/2 \times 0.20788} = e^{i 0.32653}$
So the result is complex:
$^3i = 0.94715+0.32076i$

We can keep going using results from the last iteration:
$^4i = i^{0.94715+0.32076 i} = 0.05009+0.60211 i$

Eventually you find that with $^mi$ as $m$ increases, the results start to converge on one number. This implies there’s a value for $^\infty i$. After plugging and chugging we can eventually conclude that:
$^\infty i = 0.43828 + 0.36059 i$
Convergence can be seen in both the real and imaginary components, around $m \approx 70$ if we require the difference between iterations to be less than 0.1%. (See figures below).

Each result has a different radius associated with it, since the imaginary component of the previous result puts a real term in the exponential of the next. This real term can be expressed as a factor $r$:
$e^{i\varphi} = a + bi \rightarrow i^{a+bi} = e^{i \pi/2 (a + bi)} = e^{-b\pi/2}e^{i a \pi/2} = r e^{i a \pi/2}$
The radius can be found by multiplying the result by its complex conjugate and then find the square root (i.e. the Pythagorean theorem).

We can then plot radius of $^mi$ as a function of $m$ (see plot below).

The python code for making these plots is:

import os
import sys
import math
import numpy
import pylab

REAL = []
IMAG = []
ITERA = []

pp = 1j
for n in range(100):
ppL = pp #save previous value for cut off
pp = (1j)**pp #interate power tower
RA = 0.001 #ratio for cut off
if (abs(pp.real - ppL.real)/(ppL.real + 0.00001) < RA) and (abs(pp.imag - ppL.imag)/(ppL.imag + 0.00001) < RA): #establish a cut off
print n
print pp
break
else:

REAL.append(pp.real) #save real component
IMAG.append(pp.imag) #save imaginary component
ITERA.append(n+2) #save iteration "m"

ITERA = [1]+ITERA
REAL = [0]+REAL
IMAG = [1]+IMAG

pylab.figure(1)
pylab.xlabel("m")

# pylab.show()

pylab.figure(2)
pylab.xlabel("m")
pylab.ylabel("imaginary component")
pylab.plot(ITERA,IMAG,'k')

pylab.savefig('Imfig.png')

pylab.figure(3)
pylab.xlabel("m")
pylab.ylabel("real component")
pylab.plot(ITERA,REAL,'k')

pylab.savefig('Refig.png')