Three more derivatives found straight from the definition. The difference quotient of an exponential factors into the function times its slope at 0, and the base whose slope at 0 is 1 is e, so e^x is its own derivative. Angle addition and two small-angle limits turn the slope of the sine into the cosine.
Factor the difference quotient of a^x into a^x times its slope at 0, and explain why the slope of an exponential is proportional to its height.
Define e as the base whose exponential has slope 1 at 0, and deduce that e^x is its own derivative.
Derive the derivatives of sin x and cos x from the angle-addition formulas, including the limit of (cos h - 1)/h.
Explain why these derivatives need angles in radians, and check each one with a central difference.
In review. The maths and code on this page are checked by automated tests on every change, but an independent reader has not signed it off yet. Spot a mistake or a confusing step? Tell us.
The question
Logistic regression passes its score through \(e^z\), and a softmax layer does the same for every class, so training needs the slope of the exponential. Sines and cosines describe anything that repeats in cycles, from seasons in sales data to the position code of a transformer. What is the slope of \(e^x\) at \({x = 1}\), and of \(\sin x\) at \({x = \pi/3}\)? And why does the answer for the sine change if the angle is measured in degrees?
From the last lesson
1. State the power rule, and say for which exponents lesson M04.3.1 proves it.
Show answer
\({(x^n)' = n\,x^{n-1}}\), proved for \({n = 1, 2, 3, \dots}\) from the binomial expansion.
2. What is the derivative of the running loss, and where is it zero?
Show answer
\({L'(w) = 15w - 23.5}\), which is zero at \({w = 47/30 \approx 1.567}\).
Intuition
Two pictures carry this lesson. On the left below are three tangent lines to \(e^x\). Each one meets the horizontal axis exactly one unit to the left of the point it touches, so each tangent rises by the height of its point over a run of 1. The slope of \(e^x\) at any point is the height of the graph there.
On the right is the sine wave with its tangent line at five points. At a peak or a trough the tangent is flat, and where the wave crosses the axis it climbs or falls with slope 1 or \(-1\). Plot those five slopes as dots and they land on another wave, the same shape shifted a quarter turn to the left: the cosine.
M04.3.2-F1
Left: every tangent to \(e^x\) meets the axis one unit before its point, so slope = height. Right: the slopes of \(\sin x\), plotted as green dots, lie on the curve \(\cos x\).
Both facts come out of the definition of the derivative, with tools you already have: the rule \({a^{x+h} = a^x a^h}\) for powers (M01.4.1) and the angle-addition formula for the sine (lesson M01.5.4).
Build it up
Step 1. The difference quotient of an exponential factors. For a base \({a > 0}\), split \({a^{x+h}}\) into \({a^x a^h}\) and take \(a^x\) out as a common factor:
The second factor has no \(x\) in it. Since \({a^0 = 1}\), it is exactly the difference quotient of \(a^x\) at \({x = 0}\). So the slope at any \(x\) is \(a^x\) times the slope at 0. Write \(m_a\) for that slope at 0: then the slope of \(a^x\) is \({m_a\,a^x}\), proportional to the height.
Step 2. Measure the slope at 0. A table of the second factor for shrinking \(h\):
\(h\)
\({(2^h - 1)/h}\)
\({(3^h - 1)/h}\)
0.1
0.7177
1.1612
0.01
0.6956
1.1047
0.001
0.6934
1.0992
0.0001
0.6932
1.0987
The columns settle: \({m_2 \approx 0.693}\) and \({m_3 \approx 1.099}\). A table is evidence, not proof (M04.1.1), and the formal section says what is taken as given.
Step 3. One base has slope exactly 1. A bigger base climbs more steeply through \({(0, 1)}\): \(m_2\) is below 1 and \(m_3\) is above. Between 2 and 3 sits the base whose slope at 0 is exactly 1. It is called \(e\), and it is about 2.71828. For this base the factor is 1, and Step 1 says \({(e^x)' = e^x}\).
M04.3.2-F2
Left: every exponential passes through \({(0, 1)}\), each at its own slope. Right: that slope grows with the base, and it is exactly 1 for the base \(e\).
Step 4. The sine’s difference quotient splits in two. The angle-addition formula gives
\[
\begin{aligned}
&\sin(x + h) \\
&\quad= \sin x \cos h + \cos x \sin h .
\end{aligned}
\]
Subtract \(\sin x\), divide by \(h\) and group the terms by what they multiply:
\[
\begin{aligned}
&\frac{\sin(x+h) - \sin x}{h} \\
&\quad= \sin x \cdot \frac{\cos h - 1}{h} \\
&\qquad + \cos x \cdot \frac{\sin h}{h} .
\end{aligned}
\]
Step 5. Two small-angle limits. As \(h\) shrinks, the height \(\sin h\) becomes nearly the arc \(h\), so \({(\sin h)/h}\) tends to 1: the limit that lesson M04.1.2 proved by squeezing areas. The gap \({1 - \cos h}\) shrinks much faster than \(h\) itself, so \({(\cos h - 1)/h}\) tends to 0. The formal section proves this second limit.
M04.3.2-F3
For a small angle, the blue height \(\sin h\) is nearly the orange arc \(h\), while the purple gap \({1 - \cos h}\) shrinks about four times when \(h\) halves. So \({(\sin h)/h}\) tends to 1 and \({(1 - \cos h)/h}\) tends to 0.
Step 6. Put them together. In Step 4 the first piece fades to 0 and the second tends to \({\cos x \cdot 1}\). So the slope of \(\sin x\) is \(\cos x\). The same steps with the formula for \({\cos(x + h)}\) give the slope of \(\cos x\): it is \({-\sin x}\).
The formal statement
NoteDerivatives of the exponential, the sine and the cosine
For every base \({a > 0}\): \({(a^x)' = m_a\,a^x}\), where \(m_a\) is the slope of \(a^x\) at 0, the limit of \({(a^h - 1)/h}\) as \(h\) tends to 0.
The number \(e\) is the base with \({m_e = 1}\). So \({(e^x)' = e^x}\).
With \(x\) in radians: \({(\sin x)' = \cos x}\) and \({(\cos x)' = -\sin x}\).
What is taken as given. This lesson assumes, as the table suggests, that \(a^x\) has a slope at \({x = 0}\) for every base \({a > 0}\), and that exactly one base has slope 1 there. OpenStax makes the same assumption and defines \(e\) in the same way; proving it needs a definition of \(a^x\) for every real \(x\), which is beyond this course. Lesson M04.3.4 then shows that \({m_a = \ln a}\), which explains the table: \({\ln 2 \approx 0.693}\) and \({\ln 3 \approx 1.099}\).
The exponential. By Step 1, with the constant multiple law for limits (the factor \(a^x\) does not change as \(h\) shrinks):
The limit of \({(\cos h - 1)/h}\). Multiply the top and the bottom by \({\cos h + 1}\), which is close to 2 and so not 0 when \(h\) is small. Then use the difference of two squares and \({\cos^2 h + \sin^2 h = 1}\):
\[
\begin{aligned}
&\frac{\cos h - 1}{h} \\
&\quad= \frac{(\cos h - 1)(\cos h + 1)}{h\,(\cos h + 1)} \\
&\quad= \frac{\cos^2 h - 1}{h\,(\cos h + 1)} \\
&\quad= \frac{-\sin^2 h}{h\,(\cos h + 1)} \\
&\quad= -\frac{\sin h}{h} \cdot \frac{\sin h}{\cos h + 1} .
\end{aligned}
\]
As \(h\) tends to 0, the point \({(\cos h, \sin h)}\) slides to \({(1, 0)}\) on the unit circle, so \({\sin h \to 0}\) and \({\cos h + 1 \to 2}\), while \({(\sin h)/h \to 1}\). By the product and quotient laws the limit is \({-1 \cdot 0/2 = 0}\).
The sine. Expand with the angle-addition formula and collect the two terms that hold \(\sin x\):
\[
\begin{aligned}
&\sin(x+h) - \sin x \\
&\quad= \sin x \cos h + \cos x \sin h \\
&\qquad - \sin x \\
&\quad= \sin x\,(\cos h - 1) + \cos x \sin h .
\end{aligned}
\]
Divide by \(h\) and take the two limits:
\[
\begin{aligned}
&\frac{\sin(x+h) - \sin x}{h} \\
&\quad= \sin x \cdot \frac{\cos h - 1}{h} \\
&\qquad + \cos x \cdot \frac{\sin h}{h} \\
&\quad\to \sin x \cdot 0 + \cos x \cdot 1 \\
&\quad= \cos x .
\end{aligned}
\]
The cosine. The same steps, starting from the angle-addition formula for the cosine,
\[
\begin{aligned}
&\cos(x + h) \\
&\quad= \cos x \cos h - \sin x \sin h ,
\end{aligned}
\]
give
\[
\begin{aligned}
&\frac{\cos(x+h) - \cos x}{h} \\
&\quad= \cos x \cdot \frac{\cos h - 1}{h} \\
&\qquad - \sin x \cdot \frac{\sin h}{h} \\
&\quad\to \cos x \cdot 0 - \sin x \cdot 1 \\
&\quad= -\sin x .
\end{aligned}
\]
Where radians come in. The limit \({(\sin h)/h \to 1}\) holds because, in radians, an angle \(h\) cuts an arc of length \(h\) from the unit circle. In degrees the arc of \(h\) degrees has length \({\pi h / 180}\), so \({\sin(h^\circ)/h}\) tends to \({\pi/180}\), and every slope picks up that factor.
Go deeper: is this the same e as in lesson M01.4.2?
In lesson M01.4.2\(e\) was the value that \({(1 + \tfrac{1}{n})^n}\) settles towards. Here it is the base whose graph leaves \({(0, 1)}\) at slope 1. They are the same number. A quick reason, not yet a proof: slope 1 at 0 means \({e^h \approx 1 + h}\) for small \(h\), so \(e\) is close to \({(1 + h)^{1/h}}\), and with \({h = 1/n}\) that is \({(1 + \tfrac{1}{n})^n}\). Lesson M04.3.4 turns this into a proof, once the logarithm has a derivative.
Worked example
The exponential. At \({x = 1}\) the slope of \(e^x\) is \({e^1 \approx 2.718}\). The tangent line there is \({y = e + e(x - 1) = ex}\), which passes through the origin, one unit to the left of \({x = 1}\), as the picture promised. For the base 2 the slope at \({x = 3}\) is \({m_2 \cdot 2^3 \approx 0.6931 \times 8}\), about 5.545: the slope quoted at the end of the last lesson.
The sine at \({x = \pi/3}\), by hand. Use \({\sin(\pi/3) = \sqrt{3}/2 \approx 0.8660}\), \({\cos(\pi/3) = 0.5}\) and, for \({h = 0.1}\), \({\cos 0.1 \approx 0.995004}\) and \({\sin 0.1 \approx 0.099833}\). The two factors that depend on \(h\) are
and their sum, the secant slope, is about 0.4559. With \({h = 0.01}\) the pieces are about \(-0.0043\) and \(0.49999\), with sum 0.4957. The first piece fades and the second settles on \({\cos(\pi/3) = 0.5}\), the slope of the sine at \({\pi/3}\).
M04.3.2-F4
The trace of the worked example. As \(h\) shrinks, the purple piece fades to 0, the sky-blue piece settles on 0.5, and so does their sum, the secant slope.
A central difference (M04.2.4) gets there faster. With \({x = \pi/3}\) and \({h = 0.01}\) it gives
From scratch: measure the slope at 0 of \(2^x\) and \(3^x\) with a central difference, then find the base whose slope at 0 is 1 by bisection, the method of M04.1.4.
import mathdef slope_at_zero(a, h=1e-6):"""The slope of a**x at x = 0, by a central difference (M04.2.4)."""return (a ** h - a **-h) / (2* h)for a in (2, 3):print(f"base {a}: slope at 0 is about {slope_at_zero(a):.6f}")lo, hi =2.0, 3.0# slope below 1 at 2, above 1 at 3for _ inrange(40): mid = (lo + hi) /2if slope_at_zero(mid) <1: lo = midelse: hi = midprint("the base with slope 1 at 0:", round((lo + hi) /2, 6), " math.e:", round(math.e, 6))
base 2: slope at 0 is about 0.693147
base 3: slope at 0 is about 1.098612
the base with slope 1 at 0: 2.718282 math.e: 2.718282
Now each rule against a central difference at thirteen points, and the sine once more with its angle in degrees:
import numpy as npx = np.linspace(-3, 3, 13)h =1e-5rules = (("exp", np.exp, np.exp), ("sin", np.sin, np.cos), ("cos", np.cos, lambda x: -np.sin(x)))for name, f, slope in rules: central = (f(x + h) - f(x - h)) / (2* h)print(f"{name}: largest gap to the rule {np.max(np.abs(central - slope(x))):.1e}")def sin_degrees(x):return np.sin(np.radians(x))at_zero = (sin_degrees(h) - sin_degrees(-h)) / (2* h)print("slope of the sine at 0, angle in degrees:", round(float(at_zero), 6), " pi/180:", round(math.pi /180, 6))
exp: largest gap to the rule 4.4e-10
sin: largest gap to the rule 1.8e-11
cos: largest gap to the rule 1.1e-11
slope of the sine at 0, angle in degrees: 0.017453 pi/180: 0.017453
SciPy’s scipy.differentiate.derivative does the same job with a more careful choice of steps. It takes a function that works on whole arrays and returns an object whose df holds the slopes:
from scipy.differentiate import derivativeresult = derivative(np.sin, x)print(f"largest gap between scipy's slope of sin and cos: {np.max(np.abs(result.df - np.cos(x))):.1e}")print("every estimate converged:", bool(np.all(result.success)))print("slope of exp at 1:", float(derivative(np.exp, 1.0).df), " e:", math.e)
largest gap between scipy's slope of sin and cos: 1.4e-14
every estimate converged: True
slope of exp at 1: 2.7182818284590127 e: 2.718281828459045
Explore
The module’s interactive, the chain-rule gears, is in lesson M04.3.4. Two of its outer functions come from this lesson. With \({y = e^u}\), its gear ratio \({dy/du}\) always equals the value \(y\) on its dial, the fact proved here. With \({y = \sin u}\), the ratio is \(\cos u\), and it drops to 0 when the sine dial reaches its highest value.
Pitfalls
M04.3.2-F5
Wrong beside right. With the angle in degrees, a slope of 1 at 0 would climb one unit per degree. The true slope is \({\pi/180 \approx 0.0175}\) per degree.
“The derivative of \(\sin x\) is \(\cos x\), whatever the unit of the angle.”
Only in radians. With \(x\) in degrees the slope is \({(\pi/180)\cos x}\), because the limit \({(\sin h)/h \to 1}\) needs the arc of the angle to equal the angle. NumPy, SciPy and every deep learning library measure angles in radians, so convert degrees with np.radians first.
“The derivative of \(e^x\) is \({x\,e^{x-1}}\), by the power rule.”
The power rule is for a moving base and a fixed exponent. Here the exponent moves. At \({x = 1}\) the false rule gives \({1 \cdot e^0 = 1}\), but the slope is \({e \approx 2.718}\).
“The derivative of \(\cos x\) is \(\sin x\).”
Check the sign against the graph. Just after \({x = 0}\) the cosine falls from its peak, so its slope must be negative there. The rule \({(\cos x)' = -\sin x}\) gives \({-\sin(\pi/2) = -1}\) at \({x = \pi/2}\), where the cosine crosses the axis on its way down.
Check yourself
Recall
1. Why is the slope of \(a^x\) at any \(x\) equal to \(a^x\) times its slope at 0?
Show answer
Because the difference quotient factors as \({a^x \cdot (a^h - 1)/h}\), and the second factor is the difference quotient at 0, which does not depend on \(x\).
2. What makes \(e\) special among the bases?
Show answer
Its exponential has slope exactly 1 at \({x = 0}\), so \({(e^x)' = e^x}\): the slope equals the height everywhere.
3. State the derivatives of \(\sin x\) and \(\cos x\), with the condition they need.
Show answer
\({(\sin x)' = \cos x}\) and \({(\cos x)' = -\sin x}\), with \(x\) in radians.
4. Which two limits does the derivation of \({(\sin x)'}\) use?
Show answer
\({(\sin h)/h \to 1}\) (lesson M04.1.2) and \({(\cos h - 1)/h \to 0}\) (derived in this lesson).
5. What is the slope of the sine at 0 when the angle is measured in degrees?
Show answer
\({\pi/180 \approx 0.01745}\) per degree.
Exercises
1.★ Differentiate \({f(x) = 5e^x - 4\cos x + x^3}\) and find \(f'(0)\).
Show solution
With the sum and constant multiple rules of M04.3.1: \({f'(x) = 5e^x - 4(-\sin x) + 3x^2}\), that is \({5e^x + 4\sin x + 3x^2}\). At 0: \({f'(0) = 5 \cdot 1 + 0 + 0 = 5}\).
2.★★ Show that the tangent line to \(e^x\) at \({x = a}\) crosses the horizontal axis at \({x = a - 1}\), as the anchor picture shows. Write down the tangent line at \({a = 1}\).
Show solution
The tangent at \(a\) has slope \(e^a\) and passes through \({(a, e^a)}\), so it is
\[
\begin{aligned}
y &= e^a + e^a(x - a) \\
&= e^a(1 + x - a) .
\end{aligned}
\]
Since \({e^a > 0}\), this is zero exactly when \({1 + x - a = 0}\), at \({x = a - 1}\). At \({a = 1}\) the tangent is \({y = e(1 + x - 1) = ex}\).
3.★★★ Use \({4^h - 1 = (2^h - 1)(2^h + 1)}\) to show that \({m_4 = 2\,m_2}\), and check it with \({m_2 \approx 0.693}\) and the slope of \(4^x\) at 0 measured with \({h = 0.0001}\). What kind of function of the base does \(m_a\) behave like?
As \(h\) tends to 0 the first factor tends to \(m_2\) and the second to \({2^0 + 1 = 2}\), because the graph of \(2^x\) has no break at 0. By the product law, \({m_4 = 2\,m_2 \approx 1.386}\), and indeed \({(4^{0.0001} - 1)/0.0001 \approx 1.3864}\). Squaring the base doubles \(m_a\), just as \({\ln(a^2) = 2\ln a}\): \(m_a\) behaves like a logarithm, and lesson M04.3.4 proves that \({m_a = \ln a}\).
Summary card
An exponential’s slope is proportional to its height; the sine’s slope is the cosine.
M04.3.2-F1
Slope = height; slopes of sine trace cosine.
\({(a^x)' = m_a\,a^x}\), with \(m_a\) the slope at 0: \({m_2 \approx 0.693}\), \({m_3 \approx 1.099}\).
\(e\) is the base with slope 1 at 0, so \({(e^x)' = e^x}\).
\({(\sin x)' = \cos x}\) and \({(\cos x)' = -\sin x}\), in radians.
On the way: \({(\sin h)/h \to 1}\) and \({(\cos h - 1)/h \to 0}\).
Sources and next steps
Sources. Each was opened and checked against this lesson on 12 November 2026.
Gilbert Strang and Edwin Herman, Calculus Volume 1, OpenStax: Section 3.9 assumes that the slope of \(b^x\) at 0 exists, writes it as the limit of \({(b^h - 1)/h}\) (equation 3.28) and defines \(e\) as the base for which it is 1, giving Theorem 3.14; Section 3.5 derives Theorem 3.8, the derivatives of \(\sin x\) and \(\cos x\), from the angle-addition formula and the limits of \({(\sin h)/h}\) and \({(\cos h - 1)/h}\).
Matthew Boelkins, Active Calculus: Section 2.2 finds the derivatives of sine and cosine first by reading tangent slopes off their graphs, the picture used here; Section 2.1, Exercise 2.1.6.11, estimates \({(a^h - 1)/h}\) for \({a = 2}\) and \({a = 3}\) and searches between them for the base that gives 1.
SciPy, scipy.differentiate.derivative, SciPy 1.18 reference: an elementwise function in, an object with df, error and success out.
Next.M04.3.3 Products and quotients finds the slope of a product from a growing rectangle, and with it the slope of the sigmoid.