Trigonometric Identities
An identity is an equation that holds for every value where both sides are defined. Trig identities let you rewrite an expression into a simpler or more useful form. This lesson collects the core identities, shows how to prove new ones by hand, and how to check them with code.
The core list
Everything here follows from the unit-circle definition and the sum formulas of the previous lesson.
| Family | Identities |
|---|---|
| Reciprocal | , , |
| Quotient | , |
| Pythagorean | , , |
| Even / odd | , , |
| Cofunction | , , |
| Periodicity | and have period , and have period |
| Double angle | , |
| Power reduction | , |
The other two Pythagorean identities come from the first: divide by to get , or by to get .
Product-to-sum and sum-to-product
Adding and subtracting the sum and difference formulas gives:
For example, , because the terms cancel. The second group is the first group read backwards with and . These formulas explain beats in sound: two close frequencies added together equal one fast wave times a slow envelope.
How to prove an identity
You prove an identity by transforming one side, step by step, until it becomes the other side. Do not start from the equation and do the same thing to both sides; that assumes what you want to prove.
Useful moves:
- Start with the more complicated side.
- Rewrite everything in and .
- Combine fractions over a common denominator.
- Look for , or a factoring pattern such as .
- Multiply by a "conjugate" such as .
Example 1. Prove .
Example 2. Prove .
Both are true wherever the expressions are defined (, in Example 1; in Example 2).
Checking identities with code
SymPy's simplify and trigsimp can often reduce to 0, which proves the identity symbolically. The same advice as by hand helps SymPy too: substitute and for , , and first. A numeric check at random points cannot prove anything, but it catches a false identity almost instantly, and it is how you would test a trig-heavy function in a real codebase:
import sympy as sp
t = sp.Symbol("theta")
to_sin_cos = {sp.tan(t): sp.sin(t) / sp.cos(t), sp.cot(t): sp.cos(t) / sp.sin(t),
sp.sec(t): 1 / sp.cos(t), sp.csc(t): 1 / sp.sin(t)}
checks = {
"tan + cot = sec·csc": sp.tan(t) + sp.cot(t) - sp.sec(t) * sp.csc(t),
"(1-cos)/sin = sin/(1+cos)": (1 - sp.cos(t)) / sp.sin(t) - sp.sin(t) / (1 + sp.cos(t)),
"sin^4 - cos^4 = -cos 2θ": sp.sin(t)**4 - sp.cos(t)**4 + sp.cos(2 * t),
}
for name, diff in checks.items():
print(f"{name:28} simplify(left - right) = {sp.simplify(diff.subs(to_sin_cos))}")tan + cot = sec·csc simplify(left - right) = 0
(1-cos)/sin = sin/(1+cos) simplify(left - right) = 0
sin^4 - cos^4 = -cos 2θ simplify(left - right) = 0
Now a numeric, property-based style test, run on one true identity and one tempting false one:
import math
import random
rng = random.Random(7)
def holds(f, g, trials=1000):
for _ in range(trials):
x = rng.uniform(-10, 10)
try:
if not math.isclose(f(x), g(x), rel_tol=1e-9, abs_tol=1e-9):
return f"fails at x = {x:.4f}: {f(x):.6f} vs {g(x):.6f}"
except ZeroDivisionError:
continue
return "passes 1000 random tests"
print("1 + tan² = sec² :", holds(lambda x: 1 + math.tan(x)**2, lambda x: 1 / math.cos(x)**2))
print("sin 2x = 2 sin x :", holds(lambda x: math.sin(2 * x), lambda x: 2 * math.sin(x)))1 + tan² = sec² : passes 1000 random tests
sin 2x = 2 sin x : fails at x = 9.0174: -0.727614 vs 0.792481
Note:
simplifyreturning something other than 0 does not mean the identity is false; SymPy may just not find the route. Trytrigsimp,expand_trig, or rewrite both sides with.rewrite(sp.cos). A numeric counterexample, on the other hand, really does disprove it.
In software
- Avoiding expensive calls. from a known is ; graphics code often needs only one trig call per angle.
- Numerical stability. loses all precision for tiny (it subtracts two nearly equal numbers). The identity gives the same value accurately. The haversine formula for map distances is built on exactly this rewrite (see Map Distances).
- Testing. Identities make great test oracles: a correct
rotate(v, a)must satisfyrotate(rotate(v, a), b) == rotate(v, a + b)up to rounding.
import math
theta = 1e-8
naive = 1 - math.cos(theta)
stable = 2 * math.sin(theta / 2) ** 2
print("1 - cos θ :", naive)
print("2 sin²(θ/2) :", stable)
print("true ≈ θ²/2 :", theta**2 / 2)1 - cos θ : 0.0
2 sin²(θ/2) : 5.0000000000000005e-17
true ≈ θ²/2 : 5.0000000000000005e-17
Exercises
Exercise 1: Simplify
Simplify .
Answer
.
Solution
Exercise 2: Prove
Prove that .
Answer
Expanding the left side gives .
Solution
Exercise 3: Prove with a conjugate
Prove .
Answer
Multiply the left side by .
Solution
import sympy as sp
t = sp.Symbol("t")
print(sp.simplify(sp.cos(t) / (1 - sp.sin(t)) - (1 + sp.sin(t)) / sp.cos(t)))0
Exercise 4: Product to sum
Write as a sum of sines, and check it at .
Answer
. At both sides are about 0.3295.
Solution
Use with , .
import math
x = 0.4
print(round(math.sin(5*x) * math.cos(3*x), 6), round(0.5 * (math.sin(8*x) + math.sin(2*x)), 6))0.329491 0.329491
Exercise 5: Find the false one
Use the holds approach (random tests) to decide which of these is not an identity: (a) , (b) , (c) .
Answer
(b) is false (the true identity is ).
Solution
import math, random
rng = random.Random(1)
def holds(f, g):
for _ in range(500):
x = rng.uniform(-5, 5)
if not math.isclose(f(x), g(x), abs_tol=1e-9):
return False
return True
print("a", holds(lambda x: math.cos(x)**4 - math.sin(x)**4, lambda x: math.cos(2*x)))
print("b", holds(lambda x: math.tan(x) + 1, lambda x: 1 / math.cos(x)))
print("c", holds(lambda x: math.sin(3*x), lambda x: 3*math.sin(x) - 4*math.sin(x)**3))a True
b False
c True
Test yourself
Which identity follows from dividing by ?
Your random test finds an x where the two sides differ by 0.3. What can you conclude?
- Nothing, numeric tests are unreliable
- The equation is not an identity
- The equation is an identity with a rounding error
- SymPy must be used instead
Why is better than in code for tiny ?
- It is faster
- It avoids subtracting two nearly equal numbers, so it keeps precision
- It works in degrees
- It is not better; they are the same in floating point