[proofplan]
We compute the residue of the logarithmic derivative $f'/f$ at each zero and pole. Near a zero of order $m$, writing $f(z) = (z - a)^m g(z)$ with $g(a) \neq 0$ gives $f'/f = m/(z-a) + g'/g$, so $\operatorname{Res}(f'/f, a) = m$. The analogous computation at a pole of order $p$ gives residue $-p$. The [Residue Theorem](/theorems/352) then yields the formula. The geometric interpretation as $I(f \circ \gamma, 0)$ follows from the chain rule.
[/proofplan]
[step:Compute $\operatorname{Res}(f'/f, z_j) = m_j$ at a zero of order $m_j$]
At a zero $z_j$ of order $m_j$, write $f(z) = (z - z_j)^{m_j} g(z)$ where $g$ is holomorphic near $z_j$ with $g(z_j) \neq 0$. Differentiating via the product rule:
\begin{align*}
f'(z) = m_j (z - z_j)^{m_j - 1} g(z) + (z - z_j)^{m_j} g'(z).
\end{align*}
Dividing by $f(z) = (z - z_j)^{m_j} g(z)$:
\begin{align*}
\frac{f'(z)}{f(z)} = \frac{m_j}{z - z_j} + \frac{g'(z)}{g(z)}.
\end{align*}
Since $g(z_j) \neq 0$, the function $g'/g$ is holomorphic in a neighbourhood of $z_j$. Therefore $f'/f$ has a simple pole at $z_j$ with $\operatorname{Res}(f'/f, z_j) = m_j$.
[/step]
[step:Compute $\operatorname{Res}(f'/f, w_j) = -p_j$ at a pole of order $p_j$]
At a pole $w_j$ of order $p_j$, write $f(z) = (z - w_j)^{-p_j} h(z)$ where $h$ is holomorphic near $w_j$ with $h(w_j) \neq 0$. Differentiating:
\begin{align*}
f'(z) = -p_j (z - w_j)^{-p_j - 1} h(z) + (z - w_j)^{-p_j} h'(z).
\end{align*}
Dividing by $f(z) = (z - w_j)^{-p_j} h(z)$:
\begin{align*}
\frac{f'(z)}{f(z)} = \frac{-p_j}{z - w_j} + \frac{h'(z)}{h(z)}.
\end{align*}
Since $h(w_j) \neq 0$, $h'/h$ is holomorphic near $w_j$, and $\operatorname{Res}(f'/f, w_j) = -p_j$.
[/step]
[step:Apply the Residue Theorem to obtain the counting formula]
The logarithmic derivative $f'/f$ is holomorphic on $U \setminus (\{z_1, \ldots, z_k\} \cup \{w_1, \ldots, w_\ell\})$ with simple poles at each $z_j$ and $w_j$. By [Cauchy's Residue Theorem](/theorems/352):
\begin{align*}
\frac{1}{2\pi i} \int_\gamma \frac{f'(z)}{f(z)} \, dz &= \sum_{j=1}^k I(\gamma, z_j) \, \operatorname{Res}(f'/f, z_j) + \sum_{j=1}^\ell I(\gamma, w_j) \, \operatorname{Res}(f'/f, w_j) \\
&= \sum_{j=1}^k m_j \, I(\gamma, z_j) - \sum_{j=1}^\ell p_j \, I(\gamma, w_j).
\end{align*}
[/step]
[step:Identify the integral as the winding number $I(f \circ \gamma, 0)$]
For the geometric interpretation, note that the chain rule gives
\begin{align*}
\frac{d}{dt}\bigl[f(\gamma(t))\bigr] = f'(\gamma(t)) \, \gamma'(t),
\end{align*}
so
\begin{align*}
\int_\gamma \frac{f'(z)}{f(z)} \, dz = \int_a^b \frac{f'(\gamma(t))}{f(\gamma(t))} \, \gamma'(t) \, dt = \int_{f \circ \gamma} \frac{dw}{w}.
\end{align*}
By the [Winding Number Integral Formula](/theorems/351) applied to the closed curve $f \circ \gamma$ and the point $w = 0$:
\begin{align*}
\frac{1}{2\pi i} \int_\gamma \frac{f'(z)}{f(z)} \, dz = \frac{1}{2\pi i} \int_{f \circ \gamma} \frac{dw}{w} = I(f \circ \gamma, 0).
\end{align*}
This is the net number of times $f(\gamma(t))$ winds around the origin as $t$ traverses $[a, b]$, which equals the total change in $\arg f(\gamma(t))$ divided by $2\pi$.
[guided]
The substitution $w = f(z)$, $dw = f'(z) \, dz$ transforms $\int_\gamma \frac{f'(z)}{f(z)} \, dz$ into $\int_{f \circ \gamma} \frac{dw}{w}$.
This is valid because $f$ has no zeros or poles on $\gamma^*$ (by hypothesis), so $f \circ \gamma$ is a closed curve in $\mathbb{C} \setminus \{0\}$.
The [Winding Number Integral Formula](/theorems/351) applied to the curve $f \circ \gamma$ about the point $w = 0$ gives:
\begin{align*}
\frac{1}{2\pi i} \int_{f \circ \gamma} \frac{dw}{w} = I(f \circ \gamma, 0).
\end{align*}
The winding number $I(f \circ \gamma, 0)$ counts the net number of times $f(z)$ encircles the origin as $z$ traverses $\gamma$.
Each zero of order $m_j$ inside $\gamma$ contributes $+m_j$ to this count (the value $f(z)$ circles the origin $m_j$ times near $z_j$).
Each pole of order $p_j$ contributes $-p_j$ (the value $f(z)$ passes through $\infty$, reversing the winding direction).
This gives the formula:
$I(f \circ \gamma, 0) = \sum m_j I(\gamma, z_j) - \sum p_j I(\gamma, w_j)$.
[/guided]
[/step]