[proofplan]
We integrate the logarithmic derivative
\begin{align*}
\frac{f'(z)}{f(z)}
\end{align*}
around a truncated standard fundamental domain for $SL_2(\mathbb{Z})$. [The argument principle](/theorems/356) converts this boundary integral into a weighted count of zeros in the quotient; the weights $1/2$ and $1/3$ come from the local angles at the elliptic points $i$ and $\rho$. The horizontal boundary near the cusp contributes $-v_\infty(f)$, the vertical sides cancel by $T$-invariance, and the circular arc contributes $k/12$ by the $S$-transformation law. Combining these contributions gives the claimed identity.
[/proofplan]
[step:Choose the logarithmic derivative and the standard fundamental domain]
Let $F \subset \mathbb{H}$ denote the closed standard fundamental domain
\begin{align*}
F
=
\{z \in \mathbb{H} : |z| \geq 1,\ -1/2 \leq \operatorname{Re}(z) \leq 1/2\}.
\end{align*}
Its lower circular boundary is the arc of the unit circle from $\rho = e^{2\pi i/3}$ to $\rho + 1 = e^{\pi i/3}$, oriented clockwise in the positive boundary orientation of $F$.
Let $\mathcal{L}^1$ denote one-dimensional Lebesgue measure on $\mathbb{R}$.
Let $Z(f) \subset \mathbb{H}$ be the zero set of $f$. Since $f$ is holomorphic and nonzero, $Z(f)$ is discrete. Define the logarithmic derivative
\begin{align*}
g: \mathbb{H} \setminus Z(f) &\to \mathbb{C} \\
z &\mapsto \frac{f'(z)}{f(z)}.
\end{align*}
At every zero $z_0 \in Z(f)$ of order $v_{z_0}(f)$, the function $g$ has a simple pole with residue $v_{z_0}(f)$.
For $T > 1$, define the truncated fundamental region
\begin{align*}
F_T = F \cap \{z \in \mathbb{H} : \operatorname{Im}(z) \leq T\}.
\end{align*}
Choose $T$ so that $f$ has no zero on the horizontal segment
\begin{align*}
H_T = \{x+iT : -1/2 \leq x \leq 1/2\}.
\end{align*}
This is possible because the zeros of $f$ are discrete.
[/step]
[step:Use the argument principle on a regularized boundary and record the angular weights]
Let $\mathcal{Z}_T$ denote the finite set of zeros of $f$ in $F_T$. For each $z_0 \in \mathcal{Z}_T$, let $\alpha_T(z_0) \in (0,2\pi]$ be the interior angle of $F_T$ at $z_0$, counting both identified corner representatives when they represent the same point of $SL_2(\mathbb{Z})\backslash\mathbb{H}$. Choose $\varepsilon>0$ so small that the closed disks $\overline{B}(z_0,\varepsilon)$, for $z_0 \in \mathcal{Z}_T$, are pairwise disjoint and contain no zeros of $f$ other than their centres.
Define $\Gamma_{T,\varepsilon}$ to be the positively oriented boundary of
\begin{align*}
F_{T,\varepsilon}
=
F_T \setminus \bigcup_{z_0 \in \mathcal{Z}_T} \bigl(B(z_0,\varepsilon)\cap F_T\bigr),
\end{align*}
where each circular indentation is oriented as part of the boundary of $F_{T,\varepsilon}$. The function $g$ is holomorphic on a neighbourhood of $F_{T,\varepsilon}$, so the residue theorem applied to $g$ on $F_{T,\varepsilon}$ gives zero total integral. Moving the indentation integrals to the other side gives
\begin{align*}
\frac{1}{2\pi i}\int_{\Gamma_{T,\varepsilon,\mathrm{out}}}g(z)\,dz
=
\sum_{z_0\in \mathcal{Z}_T}\frac{\alpha_T(z_0)}{2\pi}v_{z_0}(f),
\end{align*}
where $\Gamma_{T,\varepsilon,\mathrm{out}}$ denotes the outer boundary pieces of $F_T$ with the small deleted arcs removed. Indeed, near a zero $z_0$ of order $r=v_{z_0}(f)$, write $f(z)=(z-z_0)^r h(z)$ with $h$ holomorphic and $h(z_0)\neq0$; then $g(z)=r/(z-z_0)+h'(z)/h(z)$. The indentation arc has clockwise orientation around $z_0$ and angular size $\alpha_T(z_0)$, so its contribution tends to $-i\alpha_T(z_0)r$ as $\varepsilon\to0$, while the holomorphic term contributes $0$ in the limit.
Let $\operatorname{ht}_F(p)$ denote the imaginary part of the representative of the orbit $p\in SL_2(\mathbb{Z})\backslash\mathbb{H}$ lying in $F$. Passing to the limit $\varepsilon\to0$ therefore yields
\begin{align*}
\frac{1}{2\pi i}\int_{\Gamma_{T,\mathrm{reg}}} g(z)\,dz
=
\sum_{\substack{p \in SL_2(\mathbb{Z})\backslash \mathbb{H} \\ p \neq [i],\, [\rho] \\ \operatorname{ht}_F(p) \leq T}}
v_p(f)
+
\frac{1}{2}v_i(f)
+
\frac{1}{3}v_\rho(f).
\end{align*}
Here $\int_{\Gamma_{T,\mathrm{reg}}}$ means the limit of the integrals over the regularized outer boundary. The factor $1/2$ at $i$ is the ratio of the angle $\pi$ of $F$ at $i$ to the full angle $2\pi$. At the orbit of $\rho$, the two boundary representatives $\rho$ and $\rho+1$ each contribute angle $\pi/3$, so their total contribution is
\begin{align*}
\frac{\pi/3+\pi/3}{2\pi}v_\rho(f)=\frac{1}{3}v_\rho(f).
\end{align*}
For non-elliptic boundary points, the side-pairing transformations identify two representatives with complementary angular fractions; their total angular coefficient is $1$, so the quotient zero is counted once.
[guided]
The purpose of the regularized contour is to avoid a mismatch between two operations: zeros may lie on the boundary of the standard fundamental domain, but the later side computations use the boundary identifications. We therefore remove small sectors around every zero on or inside $F_T$ and keep track of exactly what each removed sector contributes.
Let $\mathcal{Z}_T$ be the finite set of zeros of $f$ in $F_T$. For each $z_0\in\mathcal{Z}_T$, let $\alpha_T(z_0)$ be the angle of the part of $F_T$ at $z_0$, with identified representatives combined when they represent the same quotient point. Choose $\varepsilon>0$ small enough that the disks $\overline{B}(z_0,\varepsilon)$ are pairwise disjoint and contain no other zeros. Define
\begin{align*}
F_{T,\varepsilon}
=
F_T \setminus \bigcup_{z_0 \in \mathcal{Z}_T} \bigl(B(z_0,\varepsilon)\cap F_T\bigr).
\end{align*}
The logarithmic derivative $g=f'/f$ is holomorphic on a neighbourhood of $F_{T,\varepsilon}$, because all zeros have been removed. Hence the residue theorem gives zero total integral around the boundary of $F_{T,\varepsilon}$.
Now compute the contribution of a removed sector. If $z_0$ is a zero of order $r$, then there is a [holomorphic function](/page/Holomorphic%20Function) $h$ with $h(z_0)\neq0$ such that
\begin{align*}
f(z)=(z-z_0)^r h(z).
\end{align*}
Therefore
\begin{align*}
g(z)=\frac{f'(z)}{f(z)}=\frac{r}{z-z_0}+\frac{h'(z)}{h(z)}.
\end{align*}
The holomorphic term $h'/h$ has integral tending to $0$ over the small indentation as $\varepsilon\to0$. The pole term contributes the angular fraction of the full residue. Since the indentation is clockwise as a boundary component of the punctured region, its contribution tends to $-i\alpha_T(z_0)r$. Moving this indentation contribution to the outer boundary side gives the positive contribution
\begin{align*}
\frac{\alpha_T(z_0)}{2\pi}v_{z_0}(f).
\end{align*}
Thus the regularized outer boundary integral satisfies
\begin{align*}
\frac{1}{2\pi i}\int_{\Gamma_{T,\mathrm{reg}}} g(z)\,dz
=
\sum_{z_0\in \mathcal{Z}_T}\frac{\alpha_T(z_0)}{2\pi}v_{z_0}(f).
\end{align*}
We now translate the angular coefficients into quotient weights. At $i$, the domain angle is $\pi$, so the coefficient is $\pi/(2\pi)=1/2$. At $\rho$, the two identified corner representatives $\rho$ and $\rho+1$ each have angle $\pi/3$, and both represent the same quotient point, so the total coefficient is
\begin{align*}
\frac{\pi/3+\pi/3}{2\pi}=\frac{1}{3}.
\end{align*}
At every non-elliptic boundary zero, the two identified representatives have complementary angles under the side-pairing map, and their angular coefficients add to $1$. If $\operatorname{ht}_F(p)$ denotes the imaginary part of the representative of $p$ lying in $F$, the regularized [argument principle](/page/Argument%20Principle) becomes
\begin{align*}
\frac{1}{2\pi i}\int_{\Gamma_{T,\mathrm{reg}}} g(z)\,dz
=
\sum_{\substack{p \in SL_2(\mathbb{Z})\backslash \mathbb{H} \\ p \neq [i],\, [\rho] \\ \operatorname{ht}_F(p) \leq T}}
v_p(f)
+
\frac{1}{2}v_i(f)
+
\frac{1}{3}v_\rho(f).
\end{align*}
This is the precise form of the argument principle used in the proof.
[/guided]
[/step]
[step:Compute the cusp contribution from the first nonzero $q$-coefficient]
Let $m = v_\infty(f)$. By definition of $v_\infty(f)$, there is a holomorphic function
\begin{align*}
h: \{q \in \mathbb{C} : |q| < 1\} &\to \mathbb{C}
\end{align*}
with $h(0)=a_m\neq 0$ such that
\begin{align*}
f(z)=q^m h(q), \qquad q=e^{2\pi i z},
\end{align*}
for $\operatorname{Im}(z)$ sufficiently large. Differentiating gives
\begin{align*}
\frac{f'(z)}{f(z)}
=
2\pi i m
+
2\pi i q \frac{h'(q)}{h(q)}.
\end{align*}
As $T \to \infty$, the second term converges uniformly to $0$ on the horizontal segment $H_T$, because $q=e^{2\pi i(x+iT)}$ satisfies $|q|=e^{-2\pi T}$.
In the positive orientation of $\partial F_T$, the top segment is traversed from $1/2+iT$ to $-1/2+iT$. Therefore
\begin{align*}
\lim_{T\to\infty}
\frac{1}{2\pi i}
\int_{1/2+iT}^{-1/2+iT}
\frac{f'(z)}{f(z)}\,dz
=
\frac{1}{2\pi i}
\int_{1/2}^{-1/2}
2\pi i m\,d\mathcal{L}^1(x)
=
-m.
\end{align*}
Thus the cusp contribution is $-v_\infty(f)$.
[/step]
[step:Cancel the two vertical boundary integrals by translation invariance]
Let
\begin{align*}
T_0: \mathbb{H} &\to \mathbb{H} \\
z &\mapsto z+1
\end{align*}
be the translation corresponding to the matrix $\begin{pmatrix}1&1\\0&1\end{pmatrix} \in SL_2(\mathbb{Z})$. Since $f$ has weight $k$ for $SL_2(\mathbb{Z})$, the transformation law for $T_0$ gives
\begin{align*}
f(z+1)=f(z).
\end{align*}
Differentiating with respect to $z$ gives
\begin{align*}
f'(z+1)=f'(z),
\end{align*}
and hence
\begin{align*}
g(z+1)=g(z).
\end{align*}
The right vertical side is parametrized by
\begin{align*}
\gamma_R: [\sqrt{3}/2,T] &\to \mathbb{H} \\
y &\mapsto 1/2+iy,
\end{align*}
and the left vertical side is parametrized in the positive boundary orientation by
\begin{align*}
\gamma_L: [\sqrt{3}/2,T] &\to \mathbb{H} \\
y &\mapsto -1/2+i(T+\sqrt{3}/2-y),
\end{align*}
equivalently from $-1/2+iT$ down to $-1/2+i\sqrt{3}/2$. Since $\gamma_R(y)=\gamma_{L,*}(y)+1$ for the corresponding point $\gamma_{L,*}(y)=-1/2+iy$, and since the orientations are opposite, the two regularized vertical integrals cancel after matching deleted arcs by translation:
\begin{align*}
\int_{\text{right side},\mathrm{reg}} g(z)\,dz
+
\int_{\text{left side},\mathrm{reg}} g(z)\,dz
=
0.
\end{align*}
The small omitted arcs around paired non-elliptic boundary zeros are matched by $T_0$, and the equality $g(z+1)=g(z)$ preserves their limiting contributions with opposite orientations.
[/step]
[step:Pair the circular arcs using the $S$-transformation law]
Let
\begin{align*}
S: \mathbb{H} &\to \mathbb{H} \\
z &\mapsto -\frac{1}{z}
\end{align*}
be the transformation corresponding to the matrix $\begin{pmatrix}0&-1\\1&0\end{pmatrix} \in SL_2(\mathbb{Z})$. The modular transformation law gives
\begin{align*}
f(Sz)=f\left(-\frac{1}{z}\right)=z^k f(z).
\end{align*}
Differentiating this identity with respect to $z$ yields
\begin{align*}
\frac{1}{z^2}f'(Sz)
=
kz^{k-1}f(z)+z^k f'(z).
\end{align*}
Dividing by $f(Sz)=z^k f(z)$ gives
\begin{align*}
\frac{1}{z^2}g(Sz)=g(z)+\frac{k}{z}.
\end{align*}
Let $C_L$ be the unit-circle arc from $\rho$ to $i$, and let $C_R$ be the unit-circle arc from $i$ to $\rho+1$, both with the positive boundary orientation of $F$. The map $S$ sends the arc from $i$ to $\rho$ onto $C_R$. Therefore, using the substitution
\begin{align*}
w=S z=-\frac{1}{z}, \qquad dw=z^{-2}\,dz,
\end{align*}
we obtain
\begin{align*}
\int_{C_R} g(w)\,dw
&=
\int_i^\rho g(Sz)\frac{1}{z^2}\,dz \\
&=
\int_i^\rho \left(g(z)+\frac{k}{z}\right)\,dz.
\end{align*}
Since
\begin{align*}
\int_{C_L}g(z)\,dz=\int_\rho^i g(z)\,dz,
\end{align*}
the $g$-terms cancel after adding the two regularized circular arc integrals:
\begin{align*}
\int_{C_{L,\mathrm{reg}}}g(z)\,dz+\int_{C_{R,\mathrm{reg}}}g(z)\,dz
=
k\int_i^\rho \frac{1}{z}\,dz.
\end{align*}
The regularization is compatible with the substitution $w=Sz$: deleted arcs around paired non-elliptic boundary zeros correspond under $S$, while the elliptic corner contributions at $i$, $\rho$, and $\rho+1$ have already been isolated in the weighted argument-principle computation.
Along the unit circle from $i=e^{\pi i/2}$ to $\rho=e^{2\pi i/3}$, the argument increases from $\pi/2$ to $2\pi/3$. Hence
\begin{align*}
\int_i^\rho \frac{1}{z}\,dz
=
i\left(\frac{2\pi}{3}-\frac{\pi}{2}\right)
=
\frac{\pi i}{6}.
\end{align*}
Thus
\begin{align*}
\frac{1}{2\pi i}
\left(
\int_{C_L}g(z)\,dz+\int_{C_R}g(z)\,dz
\right)
=
\frac{k}{12}.
\end{align*}
[guided]
The circular side is the only boundary piece where the weight $k$ appears. The reason is that the two circular arcs are identified by the matrix
\begin{align*}
S=\begin{pmatrix}0&-1\\1&0\end{pmatrix},
\end{align*}
whose action on $\mathbb{H}$ is $z\mapsto -1/z$. Since $f$ has weight $k$, the defining transformation law says
\begin{align*}
f\left(-\frac{1}{z}\right)=z^k f(z).
\end{align*}
We differentiate this identity because the contour integral involves $f'/f$. Differentiating the left side requires the chain rule:
\begin{align*}
\frac{d}{dz}f\left(-\frac{1}{z}\right)=\frac{1}{z^2}f'\left(-\frac{1}{z}\right).
\end{align*}
Differentiating the right side gives
\begin{align*}
\frac{d}{dz}\left(z^k f(z)\right)=kz^{k-1}f(z)+z^k f'(z).
\end{align*}
Dividing the resulting identity by $z^k f(z)=f(-1/z)$ gives
\begin{align*}
\frac{1}{z^2}\frac{f'(-1/z)}{f(-1/z)}
=
\frac{f'(z)}{f(z)}+\frac{k}{z}.
\end{align*}
In the notation
\begin{align*}
g=\frac{f'}{f},
\end{align*}
this is
\begin{align*}
\frac{1}{z^2}g(Sz)=g(z)+\frac{k}{z}.
\end{align*}
Now pair the two halves of the circular boundary. The substitution
\begin{align*}
w=Sz=-\frac{1}{z}, \qquad dw=z^{-2}\,dz,
\end{align*}
has differential $dw=z^{-2}\,dz$ and sends the arc from $i$ to $\rho$ onto the arc from $i$ to $\rho+1$. We apply this substitution to the regularized arcs, deleting corresponding small arcs around paired boundary zeros. Therefore
\begin{align*}
\int_{C_{R,\mathrm{reg}}}g(w)\,dw
=
\int_{[i,\rho]_{\mathrm{reg}}} g(Sz)\frac{1}{z^2}\,dz
=
\int_{[i,\rho]_{\mathrm{reg}}} \left(g(z)+\frac{k}{z}\right)\,dz.
\end{align*}
The left arc contributes
\begin{align*}
\int_{C_{L,\mathrm{reg}}}g(z)\,dz=\int_{[\rho,i]_{\mathrm{reg}}} g(z)\,dz.
\end{align*}
Adding these two expressions cancels the regularized integrals of $g$:
\begin{align*}
\int_{[\rho,i]_{\mathrm{reg}}} g(z)\,dz+\int_{[i,\rho]_{\mathrm{reg}}} g(z)\,dz=0.
\end{align*}
The only term left is the weight term:
\begin{align*}
\int_{C_L}g(z)\,dz+\int_{C_R}g(z)\,dz
=
k\int_i^\rho \frac{1}{z}\,dz.
\end{align*}
Along the unit circle, write $z=e^{i\theta}$ with $\theta$ increasing from $\pi/2$ to $2\pi/3$. Then $dz/z=i\,d\mathcal{L}^1(\theta)$, so
\begin{align*}
\int_i^\rho \frac{1}{z}\,dz
=
\int_{\pi/2}^{2\pi/3} i\,d\mathcal{L}^1(\theta)
=
\frac{\pi i}{6}.
\end{align*}
Dividing by $2\pi i$ gives the circular contribution $k/12$.
[/guided]
[/step]
[step:Let the truncation height tend to infinity and obtain the valence formula]
Combining the boundary computations gives
\begin{align*}
\lim_{T\to\infty}
\frac{1}{2\pi i}\int_{\Gamma_{T,\mathrm{reg}}} g(z)\,dz
=
\frac{k}{12}-v_\infty(f).
\end{align*}
Here $\int_{\Gamma_{T,\mathrm{reg}}}$ is the regularized boundary integral defined above as the limit after deleting small arcs around zeros on the boundary. On the other hand, the argument-principle computation gives
\begin{align*}
\frac{1}{2\pi i}\int_{\Gamma_{T,\mathrm{reg}}} g(z)\,dz
=
\sum_{\substack{p \in SL_2(\mathbb{Z})\backslash \mathbb{H} \\ p \neq [i],\, [\rho] \\ \operatorname{ht}_F(p) \leq T}}
v_p(f)
+
\frac{1}{2}v_i(f)
+
\frac{1}{3}v_\rho(f).
\end{align*}
For sufficiently large $T$, the finite set of zeros of $f$ in the compact quotient away from the cusp is contained below height $T$, except for the cusp contribution already measured by $v_\infty(f)$. Therefore
\begin{align*}
\sum_{\substack{p \in SL_2(\mathbb{Z})\backslash \mathbb{H} \\ p \neq [i],\, [\rho]}}
v_p(f)
+
\frac{1}{2}v_i(f)
+
\frac{1}{3}v_\rho(f)
=
\frac{k}{12}-v_\infty(f).
\end{align*}
Rearranging yields
\begin{align*}
v_\infty(f)
+
\frac{1}{2}v_i(f)
+
\frac{1}{3}v_\rho(f)
+
\sum_{\substack{p \in SL_2(\mathbb{Z})\backslash \mathbb{H} \\ p \neq [i],\, [\rho]}}
v_p(f)
=
\frac{k}{12}.
\end{align*}
This is the valence formula for level one modular forms.
[/step]