Interior Extrema and the Vanishing Derivative

Suppose a smooth trail winds through the mountains. You stand at its highest point, not at either end. What must be true of the trail's slope exactly where you stand? Every hiker's intuition says the ground is momentarily flat there. This article turns that intuition into a theorem. The result is due to Pierre de Fermat. It is one of the shortest and most consequential proofs in calculus: at an interior point where a differentiable function attains a local maximum or minimum, its derivative must vanish. This fact is often mistaken for a triviality, a picture rather than a theorem. But its precision matters enormously. It requires the extremum to be interior (not at an endpoint). It also requires differentiability at that exact point. Drop either hypothesis and the conclusion collapses. The counterexamples below will show this concretely. Understanding exactly what Fermat's theorem does and does not say matters greatly. It separates a student who can locate critical points from one who can also justify the method. The big picture is that this innocuous-looking lemma is important. It is the hinge on which a huge share of single-variable calculus turns. It converts the geometric notion of "extremum" into the algebraic condition "derivative equals zero." This turns optimization problems into equation-solving problems. It is also the seed from which Rolle's Theorem grows. The Mean Value Theorem grows from it too. Ultimately, the entire theory of monotonicity and curve sketching grows from it as well. This article states Fermat's theorem with all hypotheses made explicit. It gives a complete one-sided-limits proof. The proof is built directly from the The Derivative: Definition via Difference Quotients. The article also stress-tests the statement with worked examples. It includes a counterexample showing why each hypothesis is load-bearing.

Key takeaways
  • Fermat's theorem: if ff has a local extremum at an interior point cc and f′(c)f'(c) exists, then f′(c)=0f'(c)=0.
  • The proof uses only the definition of the derivative as a two-sided limit of difference quotients, split into left and right sign estimates.
  • "Interior" is essential: endpoints of a domain routinely have extrema with nonzero one-sided derivatives.
  • "Differentiable at cc" is essential: a corner (non-differentiable point) can be an extremum without any derivative to vanish.
  • The converse is false: f′(c)=0f'(c)=0 does not imply an extremum at cc (inflection points like x3x^3).
  • Key idea: at an interior extremum, the difference quotient is forced to be ≥0\ge 0 from one side and ≤0\le 0 from the other, so if a single two-sided limit exists it must equal 00.

Where this lives today

Fermat's theorem is the computational engine behind every "take the derivative and set it to zero" optimization technique taught across science and engineering. In physics, finding equilibrium points of a potential energy function U(x)U(x) reduces to solving U′(x)=0U'(x)=0, precisely because stable and unstable equilibria are local extrema of UU. In economics, profit-maximizing quantities are found by setting marginal revenue equal to marginal cost — an instance of f′(x)=0f'(x)=0 at an interior maximum of profit. In statistics and machine learning, maximum-likelihood estimation and loss-minimization in gradient-based training both begin from the same principle in many-variable form: at an interior optimum of a differentiable objective, every partial derivative vanishes, giving the gradient equation ∇f=0\nabla f = 0 used throughout regression, neural network training, and convex optimization. In numerical analysis, root-finding methods for f′(x)=0f'(x)=0 (Newton's method applied to the derivative) are the standard computational route to locating extrema when no closed form exists. And within pure mathematics, Fermat's theorem is the base case from which Rolle's Theorem is proved (by applying Fermat's theorem to the interior point where a function returning to the same value attains its max or min), which in turn drives the Mean Value Theorem and the entire theory of monotonicity, convexity, and curve sketching.

:::quiz[Which hypothesis of Fermat's theorem fails for f(x)=xf(x)=x on the domain [0,1][0,1] at the point c=0c=0, even though ff is a perfectly differentiable, simple function?]

  • ff is not differentiable at 00
  • c=0c=0 is not an interior point of the domain [0,1][0,1] ✓
  • ff does not have a local extremum at 00
  • The limit defining f′(0)f'(0) does not exist

Ask the tutor: Can you show me step by step how Fermat's theorem is used inside the proof of Rolle's Theorem?

DefinitionLocal extremum, interior point, critical point

Let ff be a real-valued function defined on a set D⊆RD \subseteq \mathbb{R}, and let c∈Dc \in D.

Local maximum. ff has a local maximum at cc if there exists δ>0\delta > 0 such that

f(x)≤f(c)for all x∈D with ∣x−c∣<δ.f(x) \le f(c) \quad \text{for all } x \in D \text{ with } |x-c| < \delta.

Local minimum is defined by reversing the inequality. A point where either occurs is a local extremum.

Interior point. cc is an interior point of DD if there exists δ0>0\delta_0 > 0 such that the entire interval (c−δ0,c+δ0)(c-\delta_0, c+\delta_0) is contained in DD. Equivalently, ff is defined on both sides of cc, not merely up to cc.

Differentiability at cc. ff is differentiable at cc if the two-sided limit

f′(c)=lim⁡h→0f(c+h)−f(c)hf'(c) = \lim_{h \to 0} \frac{f(c+h) - f(c)}{h}

exists as a finite real number; this requires ff to be defined on an open interval containing cc.

Critical point. If f′(c)=0f'(c) = 0, cc is called a critical point of ff. (More broadly, points where f′f' fails to exist are also called critical points, but Fermat's theorem concerns only the differentiable case.)

Intuition

Picture the graph of ff near an interior local maximum at cc. Because ff is defined on both sides of cc and f(c)f(c) is at least as large as all nearby values, the secant line from (c,f(c))(c, f(c)) to a nearby point (c+h,f(c+h))(c+h, f(c+h)) with h>0h>0 must have slope ≤0\le 0 — you are looking rightward and downward or flat. The secant to a point on the left, h<0h<0, must have slope ≥0\ge 0 — reading the quotient f(c+h)−f(c)h\frac{f(c+h)-f(c)}{h} with a negative denominator flips the sign of a numerator that is still ≤0\le 0. So as h→0+h \to 0^+ the difference quotients are squeezed toward being ≤0\le 0, and as h→0−h \to 0^- they are squeezed toward being ≥0\ge 0. If ff is differentiable at cc, both one-sided limits must equal the same number f′(c)f'(c). A number that is simultaneously ≤0\le 0 (as a limit from the right) and ≥0\ge 0 (as a limit from the left) can only be 00. This is the entire proof, compressed into one sentence; the formal version below just makes each sign statement rigorous using the definition of limit. The picture also reveals immediately why "interior" matters: at a right endpoint of the domain, there is no room to test h>0h>0, so only one of the two sign constraints exists, and there is nothing to force the slope to zero.

Figure
At an interior local maximum, secants from the right have slope ≤ 0 and secants from the left have slope ≥ 0 — forcing the two-sided limit to be exactly 0.
x y c, local max h>0: slope ≤ 0 h<0: slope ≥ 0 c f'(c) = 0 forced
TheoremFermat's Theorem on Interior Extrema

Let ff be a real-valued function defined on an open interval I⊆RI \subseteq \mathbb{R} (or more generally on a set DD for which cc is an interior point). Suppose: 1. ff has a local extremum (a local maximum or a local minimum) at c∈Ic \in I; 2. cc is an interior point of the domain, so ff is defined on some full open interval (c−δ0,c+δ0)(c-\delta_0, c+\delta_0) around cc; 3. ff is differentiable at cc, i.e. f′(c)=lim⁡h→0f(c+h)−f(c)hf'(c) = \lim_{h\to 0} \dfrac{f(c+h)-f(c)}{h} exists. Then

f′(c)=0.f'(c) = 0.
Proof

We prove the case where ff has a local maximum at cc; the local minimum case follows by applying this result to −f-f, which has a local maximum at cc exactly when ff has a local minimum there, and (−f)′(c)=−f′(c)(-f)'(c) = -f'(c), so (−f)′(c)=0  ⟺  f′(c)=0(-f)'(c)=0 \iff f'(c)=0.

Step 1 (Set up the local inequality). Since ff has a local maximum at cc, by Definition: Local maximum there exists δ1>0\delta_1 > 0 such that

f(x)≤f(c)for all x with ∣x−c∣<δ1.f(x) \le f(c) \quad \text{for all } x \text{ with } |x - c| < \delta_1.

By hypothesis (2), cc is interior, so choose δ=min⁡(δ0,δ1)>0\delta = \min(\delta_0, \delta_1) > 0; then ff is defined and satisfies f(x)≤f(c)f(x)\le f(c) throughout (c−δ,c+δ)(c-\delta, c+\delta).

Step 2 (Sign of the difference quotient from the right). Let hh satisfy 0<h<δ0 < h < \delta. Then c+h∈(c−δ,c+δ)c + h \in (c-\delta, c+\delta), so f(c+h)≤f(c)f(c+h) \le f(c), i.e.

f(c+h)−f(c)≤0.f(c+h) - f(c) \le 0.

Dividing by h>0h > 0 preserves the inequality direction:

f(c+h)−f(c)h≤0for all 0<h<δ.(∗)\frac{f(c+h) - f(c)}{h} \le 0 \qquad \text{for all } 0 < h < \delta. \tag{$\ast$}

Step 3 (Sign of the difference quotient from the left). Let hh satisfy −δ<h<0-\delta < h < 0. Again c+h∈(c−δ,c+δ)c+h \in (c-\delta,c+\delta), so f(c+h)−f(c)≤0f(c+h) - f(c) \le 0 as before. Now dividing by h<0h < 0 reverses the inequality:

f(c+h)−f(c)h≥0for all −δ<h<0.(∗∗)\frac{f(c+h)-f(c)}{h} \ge 0 \qquad \text{for all } -\delta < h < 0. \tag{$\ast\ast$}

Step 4 (Pass to one-sided limits). By hypothesis (3), f′(c)=lim⁡h→0f(c+h)−f(c)hf'(c) = \lim_{h\to 0}\frac{f(c+h)-f(c)}{h} exists as a finite limit. Existence of a two-sided limit implies existence and equality of both one-sided limits (this is a basic property of limits, used here exactly as in the limit definition underlying The Derivative: Definition via Difference Quotients):

lim⁡h→0+f(c+h)−f(c)h=lim⁡h→0−f(c+h)−f(c)h=f′(c).\lim_{h \to 0^+} \frac{f(c+h)-f(c)}{h} = \lim_{h\to 0^-} \frac{f(c+h)-f(c)}{h} = f'(c).

We now invoke the order-preserving property of limits: if g(h)≤Mg(h) \le M for all hh in a punctured neighborhood of a limit point and lim⁡g(h)\lim g(h) exists, then lim⁡g(h)≤M\lim g(h) \le M (proved directly from the ε\varepsilon–NN/ε\varepsilon–δ\delta definition of limit: if the limit LL satisfied L>ML > M, taking ε=(L−M)/2>0\varepsilon = (L-M)/2 > 0 would force g(h)>Mg(h) > M for hh close enough to the limit point, contradicting g(h)≤Mg(h)\le M there). Applying this to (∗)(\ast) with the right-hand limit and M=0M = 0:

lim⁡h→0+f(c+h)−f(c)h≤0,sof′(c)≤0.\lim_{h\to 0^+} \frac{f(c+h)-f(c)}{h} \le 0, \quad \text{so} \quad f'(c) \le 0.

Applying the analogous (reverse-direction) fact to (∗∗)(\ast\ast) with the left-hand limit and M=0M=0:

lim⁡h→0−f(c+h)−f(c)h≥0,sof′(c)≥0.\lim_{h\to 0^-} \frac{f(c+h)-f(c)}{h} \ge 0, \quad \text{so} \quad f'(c) \ge 0.

Step 5 (Conclude). We have shown f′(c)≤0f'(c) \le 0 and f′(c)≥0f'(c) \ge 0 simultaneously for the same real number f′(c)f'(c). The only real number satisfying both inequalities is 00. Hence

f′(c)=0.f'(c) = 0.

This completes the proof for a local maximum; the local minimum case follows from the argument applied to −f-f as noted above. ■\blacksquare

∎

Proof technique used: direct construction of one-sided sign inequalities from the defining local inequality, combined with the order-preserving (squeeze-type) property of limits — no appeal to any theorem built on top of Fermat's theorem itself (such as the Mean Value Theorem), so the argument is non-circular.

CorollaryNecessary condition for optimization

If f:[a,b]→Rf: [a,b] \to \mathbb{R} is differentiable on (a,b)(a,b) and attains its global maximum or minimum on [a,b][a,b] at a point cc, then either c∈{a,b}c \in \{a,b\}, or c∈(a,b)c \in (a,b) and f′(c)=0f'(c) = 0. In particular, to locate the global extrema of a differentiable function on a closed interval, it suffices to check the two endpoints together with all interior critical points.

Proof

If the global extremum occurs at c∈(a,b)c \in (a,b), then cc is in particular a local extremum (the global condition on [a,b][a,b] implies the local condition on any smaller neighborhood contained in (a,b)(a,b)), cc is interior to the domain of differentiability (a,b)(a,b), and ff is differentiable at cc by hypothesis. All three hypotheses of Fermat's theorem hold, so f′(c)=0f'(c) = 0 by Fermat's Theorem on Interior Extrema. The only remaining possibility is that the extremum occurs at an endpoint. ■\blacksquare

∎

Worked examples

Example 1: A cubic with an asymmetric interior maximum. Let f(x)=−x3+3x2+9x−2f(x) = -x^3 + 3x^2 + 9x - 2 on the interval [−3,5][-3, 5]. We locate all candidates for global extrema. Since ff is a polynomial, it is differentiable everywhere, in particular on the open interval (−3,5)(-3,5), so Fermat's theorem applies to any interior local extremum. Compute

f′(x)=−3x2+6x+9=−3(x2−2x−3)=−3(x−3)(x+1).f'(x) = -3x^2 + 6x + 9 = -3(x^2 - 2x - 3) = -3(x-3)(x+1).

Setting f′(x)=0f'(x) = 0 gives x=3x = 3 and x=−1x = -1, both interior to [−3,5][-3,5], so both are candidates permitted by the corollary above. Evaluate:

f(−3)=−(−27)+3(9)+9(−3)−2=27+27−27−2=25,f(-3) = -(-27) + 3(9) + 9(-3) - 2 = 27 + 27 - 27 - 2 = 25,
f(−1)=−(−1)+3(1)+9(−1)−2=1+3−9−2=−7,f(-1) = -(-1) + 3(1) + 9(-1) - 2 = 1 + 3 - 9 - 2 = -7,
f(3)=−(27)+3(9)+9(3)−2=−27+27+27−2=25,f(3) = -(27) + 3(9) + 9(3) - 2 = -27+27+27-2 = 25,
f(5)=−(125)+3(25)+9(5)−2=−125+75+45−2=−7.f(5) = -(125) + 3(25) + 9(5) - 2 = -125+75+45-2 = -7.

Interesting asymmetry: the global maximum value 2525 is attained both at the interior critical point x=3x=3 and at the endpoint x=−3x=-3 — a tie between an interior critical point and a boundary point, which is exactly the scenario the corollary anticipates by requiring us to check both types of candidates. The global minimum value −7-7 is likewise attained both at interior critical point x=−1x=-1 and at endpoint x=5x=5. Fermat's theorem correctly predicted that if an extremum were strictly interior, it would show up among {−1,3}\{-1,3\} — and indeed both interior extrema (which are local, at least) occur exactly there. Direct sign analysis of f′f' confirms x=−1x=-1 is a local minimum (f′f' changes −→+- \to +... here f′(−2)=−3(4)+6(−2)+9=−12−12+9=−15<0f'(-2) = -3(4)+6(-2)+9=-12-12+9=-15<0 and f′(0)=9>0f'(0)=9>0, confirming a local min at −1-1) and x=3x=3 is a local maximum (f′(2)=−3(4)+12+9=9>0f'(2) = -3(4)+12+9 = 9 > 0, f′(4)=−48+24+9=−15<0f'(4) = -48+24+9=-15<0, confirming a local max at 33).

Example 2: A function differentiable at the extremum but not elsewhere — testing the hypotheses precisely. Let

f(x)={x2sin⁡(1/x)+x/2x≠00x=0f(x) = \begin{cases} x^2 \sin(1/x) + x/2 & x \neq 0 \\ 0 & x = 0\end{cases}

restricted to the interior point c=0c=0 of R\mathbb{R}. This is a genuinely delicate case because ff oscillates infinitely often near 00 yet is differentiable there. First confirm differentiability at 00 directly from the definition:

f′(0)=lim⁡h→0f(h)−f(0)h=lim⁡h→0(hsin⁡(1/h)+12)=12,f'(0) = \lim_{h\to 0} \frac{f(h) - f(0)}{h} = \lim_{h \to 0}\left( h\sin(1/h) + \tfrac12 \right) = \tfrac12,

since ∣hsin⁡(1/h)∣≤∣h∣→0|h \sin(1/h)| \le |h| \to 0. So f′(0)=1/2≠0f'(0) = 1/2 \ne 0. Does this contradict Fermat's theorem? No — because ff does not have a local extremum at 00. Indeed for small h>0h>0, f(h)≈h/2>0=f(0)f(h) \approx h/2 > 0 = f(0), and for small h<0h<0, f(h)≈h/2<0=f(0)f(h) \approx h/2 < 0 = f(0); more carefully, since ∣h2sin⁡(1/h)∣≤h2=o(h)|h^2\sin(1/h)| \le h^2 = o(h), the term h/2h/2 dominates the sign of f(h)−f(0)f(h)-f(0) for small h≠0h\ne0, so f(h)>f(0)f(h) > f(0) for small h>0h>0 and f(h)<f(0)f(h) < f(0) for small h<0h<0. Thus ff is strictly increasing through 00 in a suitable sense and has no local extremum at c=0c=0 at all — consistent with f′(0)≠0f'(0) \ne 0. This example is instructive precisely because it shows Fermat's theorem is a one-directional implication: differentiability plus interior-ness alone say nothing; the extremum hypothesis is what does the work, and here that hypothesis genuinely fails, so there is no contradiction.

CounterexampleDropping differentiability at cc: a corner extremum with no vanishing derivative

Consider f(x)=−∣x∣f(x) = -|x| on the interior point c=0c = 0 of R\mathbb{R} (domain R\mathbb{R}, so c=0c=0 is certainly interior). Here f(0)=0f(0) = 0 and f(x)=−∣x∣≤0=f(0)f(x) = -|x| \le 0 = f(0) for all xx, so ff has a (global, hence local) maximum at c=0c=0. The interior-point hypothesis holds. But ff is not differentiable at 00: the right-hand difference quotient is

lim⁡h→0+f(h)−f(0)h=lim⁡h→0+−hh=−1,\lim_{h\to 0^+} \frac{f(h)-f(0)}{h} = \lim_{h\to0^+}\frac{-h}{h} = -1,

while the left-hand difference quotient is

lim⁡h→0−f(h)−f(0)h=lim⁡h→0−hh=1.\lim_{h\to 0^-} \frac{f(h)-f(0)}{h} = \lim_{h\to0^-}\frac{h}{h} = 1.

These one-sided limits disagree (−1≠1-1 \ne 1), so the two-sided limit defining f′(0)f'(0) does not exist. There is no derivative to set equal to zero — the conclusion of Fermat's theorem simply has no object to assert. This shows precisely why differentiability at cc is not a technical nicety but a load-bearing hypothesis: the proof's Step 4 needed a single two-sided limit squeezed between ≤0\le 0 and ≥0\ge 0. Here the "limit from the right" (which the proof shows is ≤0\le 0) equals −1-1, and the "limit from the left" (which the proof shows is ≥0\ge 0) equals 11; both sign bounds are individually satisfied and consistent with the proof, but since they are unequal, there is no common value f′(0)f'(0) for them to pin down to 00. The corner is exactly the obstruction the differentiability hypothesis is designed to rule out.

Scope, edge cases & common traps

SituationDoes Fermat's theorem apply?What can happen
Interior point, ff differentiable there, local extremumYesf′(c)=0f'(c) = 0, guaranteed
Endpoint of a closed intervalNo (not interior)f′(c)f'(c) can be any nonzero value, e.g. f(x)=xf(x)=x on [0,1][0,1] at c=0c=0
Interior point, ff not differentiable there, extremum presentNof′(c)f'(c) may not exist at all, e.g. f(x)=−∣x∣f(x) = -\lvert x\rvert at 00
Interior point, f′(c)=0f'(c) = 0N/A (converse direction)Extremum may or may not occur, e.g. f(x)=x3f(x) = x^3 at 00 has f′(0)=0f'(0)=0 but no extremum
Interior point, ff differentiable, no extremumN/Af′(c)f'(c) can be any real number, as in Worked Example 2

The mathematician behind it

Origins · 1 minPierre de Fermat and how this was discovered
PD
Pierre de Fermat
1607–1665 · Toulouse, France — magistrate and mathematician

Fermat was a lawyer and government official in Toulouse who pursued mathematics as an intense private avocation, corresponding with contemporaries like Mersenne and Pascal rather than publishing formally. He is best known to the general public for Fermat's Last Theorem, but his method for finding maxima and minima — worked out in the 1630s in a manuscript titled Methodus ad disquirendam maximam et minimam — is arguably his most direct ancestor to modern calculus. Fermat's method, applied to polynomials, effectively computed what we now call the derivative and set it to zero, decades before Newton and Leibniz built the full differential and integral calculus around the same idea.

History
- 1629 — Fermat begins developing his method of adequality for finding tangents and extrema of curves, in correspondence and manuscripts circulating among French mathematicians.
- 1637 — Fermat's Methodus ad disquirendam maximam et minimam is composed, giving an algorithm equivalent to setting the derivative of a polynomial to zero at an extremum.
- 1660s–1670s — Newton and Leibniz independently formalize the derivative as a limit of difference quotients, subsuming Fermat's method as a special case of a general differential calculus.
- 1823 — Cauchy's Résumé des leçons gives a rigorous limit-based treatment of the derivative, allowing Fermat's extremum principle to be stated and proved with full modern precision.
- Present — Fermat's theorem is taught as the first-year gateway lemma from which Rolle's Theorem and the Mean Value Theorem are derived.
Does Fermat's theorem require ff to be continuous, in addition to differentiable?

No separate continuity hypothesis is needed, because differentiability at cc already implies continuity at cc — this is the content of Differentiability Implies Continuity. The proof of Fermat's theorem uses only the existence of the two-sided limit defining f′(c)f'(c), and continuity is automatically along for the ride. What is required, beyond differentiability at the single point cc, is that ff be defined on a full open interval around cc (the interior-point condition), so that both one-sided difference quotients in Steps 2–3 of the proof make sense.

Is Fermat's theorem true for functions of several variables?

Yes, in an analogous form: if f:Rn→Rf: \mathbb{R}^n \to \mathbb{R} has a local extremum at an interior point c\mathbf{c} of its domain and all partial derivatives of ff exist at c\mathbf{c}, then every partial derivative vanishes there, i.e. ∇f(c)=0\nabla f(\mathbf{c}) = \mathbf{0}. The proof reduces to the one-variable case: fix all but one coordinate and apply the single-variable theorem to the resulting function of one variable along each axis direction. This is exactly the gradient-vanishing condition used throughout multivariable optimization.

What exactly goes wrong in the proof if the extremum is at an endpoint instead of an interior point?

The proof needs both a right-hand inequality (f(x)≤f(c)f(x)\le f(c) for xx slightly greater than cc) and a left-hand inequality (f(x)≤f(c)f(x)\le f(c) for xx slightly less than cc) to derive the two opposite-sign bounds on the difference quotient. At a left endpoint, for instance, there are no domain points to the left of cc at all, so Step 3 of the proof (the left-hand sign bound) cannot even be formulated. Only one of the two sign constraints survives, and a single inequality like f′(c)≤0f'(c) \le 0 does not force f′(c)=0f'(c) = 0.

Can f′(c)=0f'(c) = 0 happen without cc being any kind of critical value of interest, i.e. is the converse ever "almost true"?

The converse fails outright as a biconditional, but a useful partial converse holds under extra hypotheses: if ff is twice differentiable at cc with f′(c)=0f'(c) = 0 and f′′(c)>0f''(c) > 0, then cc is a strict local minimum (and symmetrically for f′′(c)<0f''(c)<0, a strict local maximum). This is the second-derivative test, itself typically proved using a Taylor expansion or the Mean Value Theorem, both of which trace back to Fermat's theorem as their starting lemma. When f′′(c)=0f''(c) = 0 too, no conclusion follows from the second derivative alone, as x3x^3 and x4x^4 both illustrate.

Why is the interior-point hypothesis phrased in terms of an open interval rather than just saying "not an endpoint"?

Domains in analysis are not always intervals with two endpoints — they can be unions of intervals, or more exotic subsets of R\mathbb{R}. The precise requirement is that some full open interval (c−δ0,c+δ0)(c-\delta_0, c+\delta_0) around cc lies entirely in the domain, which is exactly what "interior point" means in a general topological sense. This phrasing correctly excludes not just the two endpoints of a closed interval [a,b][a,b], but also isolated points of the domain or points that are limits only from one side, all of which would break the proof's need for domain points on both sides of cc.

Does Fermat's theorem hold for functions from R\mathbb{R} to C\mathbb{C}, or only real-valued functions?

As stated, Fermat's theorem is inherently about real-valued functions, because "local maximum" and "local minimum" require an ordering on the codomain, and C\mathbb{C} is not ordered in a way compatible with its field structure. For complex-valued or complex-differentiable (holomorphic) functions, the relevant extremum results look completely different — for instance, the Maximum Modulus Principle governs where ∣f∣|f| can attain its maximum, and it has a very different proof and different hypotheses from Fermat's theorem.

How does Fermat's theorem foreshadow Rolle's Theorem?

Rolle's Theorem considers a function continuous on [a,b][a,b], differentiable on (a,b)(a,b), with f(a)=f(b)f(a) = f(b), and concludes some c∈(a,b)c \in (a,b) has f′(c)=0f'(c) = 0. Its proof works by locating a global extremum of ff on [a,b][a,b] (using the Extreme Value Theorem), then arguing that if this extremum is not at both endpoints, it must occur at some interior point cc — at which point Fermat's theorem immediately gives f′(c)=0f'(c) = 0. Fermat's theorem is thus the final algebraic step that Rolle's Theorem's existence argument is built to reach.

Before this

Where this leads