# Trig identities from complex exponentials

There’s tons of useful trig identities. You could spend the time to learn them by heart, or just look them up on Wikipedia when necessary. But I’ve always had problems remembering where the signs and such go when trying to memorize this directly. At least for me, what worked way better is this: spend a few hours familiarizing yourself with complex numbers if you haven’t done so already; after that, most identities that you need in practice are easy to derive from Euler’s formula:

Let’s do the basic addition formulas first. Euler’s formula gives:

and once we apply the identity again we get:

multiplying out:

The terms in parentheses are all real numbers; equating them with our original expression yields the result

Both addition formulas for the price of one. (In fact, this exploits that the addition formulas for trigonometric functions and the addition formula for exponents are really the same thing). The main point being that if you know complex multiplication, you never have to remember what the grouping of factors and the signs are, something I used to have trouble remembering.

Plugging in x=y into the above also immediately gives the double-angle formulas:

so if you know the addition formulas there’s really no reason to learn these separately.

Then there’s the well-known

but it’s really just the Pythagorean theorem in disguise (since cos(x) and sin(x) are the side lengths of a right-angled triangle). So not really a new formula either!

Moving either the cosine or sine terms to the right-hand side gives the two *immensely* useful equations:

In particular, that second one is perfect if you need the sine squared of an angle that you only have the cosine of (usually because you’ve determined it using a dot product). Judicious application of these two tends to be a great way to simplify superfluous math in shaders (and elsewhere), one of my pet peeves.

For practice, let’s apply these two identities to the cosine double-angle formula:

why, it’s the half-angle formulas! Fancy meeting you here!

Can we do something with the sine double-angle formula too? Well, it’s not too fancy, but we can get this:

Now, let’s go back to the original addition formulas and let’s see what happens when we plug in negative values for y. Using and , we get:

Hey look, flipped signs! This means that we can now add these to (or subtract them from) the original formulas to get *even more* identities!

It’s the product-to-sum identities this time. I got one more! We’ve deliberately flipped signs and then added/subtracted the addition formulas to get the above set. What if we do the same trick in reverse to get rid of those x+y and x-y terms? Let’s set and and plug that into the identities above and we get:

Ta-dah, it’s the sum-to-product identities. Now, admittedly, we’ve taken quite a few steps to get here, and looking these up when you need them is going to be faster than walking through the derivation (if you ever need them in the first place – I don’t think I’ve ever used the product/sum identities in practice). But still, working these out is a good exercise, and a lot less likely to go wrong (at least for me) than memorizing lots of similar formulas. (I never can get the signs right that way)

Bonus exercise: work out general expressions for and . Hint:

.

And I think that’s enough for now. (At some later point, I might do an extra post about one of the sneakier trig techniques: the Weierstrass substitution).

Same basis, but it seems like it’d be easier to just remember the axiom for complex numbers and the conjugate, then you can get the angle addition and subtraction and proceed as you have.

Nice post, but your notation is outrageous. For example, cos(x)^2 means cos(x^2), and not (cos(x))^2, as you intended. Please fix these, in order not to confuse the students. Thanks for the tutorial!

I’ve had, variously, professors that used “cos^k(x)”, “(cos(x))^k”, “(cos x)^k” and “cos(x)^k”. All of them would object to some of the other forms.

The non-parenthesized notation for trig functions is a historical artifact, (arguably) an abuse of notation, and riddled with special cases; the cos^k notation is one example, another would be that some authors will write “cos 2a” while some require “cos(2a)” in this case, and there’s some ambiguity whether writing “cos(a)b” means “(cos(a))*b” or “cos(a*b)”. I have seen both interpretations in the wild, which to me is solid evidence that the conventional notation is problematic and should be avoided.

At this point, I just write the trig functions like I write all other function, namely, parentheses (or brackets, or braces, …) around the arguments required on function evaluations. This is consistent, always unambiguous, and matches the behavior of most programming languages in existence (and remember, the audience for this blog is programmers) as well as all symbolic algebra packages I’m familiar with. You’re free to disagree with my choice of course.