Solution (source code)

= Solution

The <Riemannian volume form> of an oriented $n$-dimensional <Riemannian manifold> is the unique positive $n$-form taking value one on every positively oriented orthonormal frame. In positive coordinates,
$$
\omega_g=\sqrt{\det(g_{ij})}\,dx^1\wedge\cdots\wedge dx^n.
$$
The metric induces an inner product on exterior powers of the <cotangent bundle>, with wedges of distinct orthonormal covectors forming an <orthonormal basis>. The <Hodge star> is the pointwise linear map $*:\Lambda^pT^*M\to\Lambda^{n-p}T^*M$ specified by
$$
\alpha\wedge*\beta=\langle\alpha,\beta\rangle_g\omega_g.
$$
It is an <isometry> and satisfies $**\alpha=(-1)^{p(n-p)}\alpha$. With the positive-sign convention, the <Hodge Laplacian> on <differential forms> is
$$
\Delta=d\delta+\delta d,\qquad
\delta|_{\Omega^p}=(-1)^{n(p-1)+1}*d*.
$$
Here $d$ is the <exterior derivative> and $\delta$ its <formal adjoint>; $\delta$ on functions is zero. On functions this is the <Laplace-Beltrami operator>
$$
\Delta f=-\operatorname{div}(\operatorname{grad}f)
=-\frac1{\sqrt{\det g}}\partial_i\bigl(\sqrt{\det g}\,g^{ij}\partial_jf\bigr).
$$
The convention $\operatorname{div}\operatorname{grad}$ gives the negative of this operator. All subsequent Laplacians use the nonnegative convention above.

On a compact oriented manifold without boundary, the <Hodge decomposition theorem> gives an orthogonal decomposition of smooth real forms,
$$
\Omega^p(M)=\mathcal H^p(M)\oplus d\Omega^{p-1}(M)\oplus\delta\Omega^{p+1}(M),\qquad
\mathcal H^p=\ker\Delta.
$$
The three component forms are uniquely determined, although the potentials in the last two summands need not be unique. The space $\mathcal H^p$ is finite-dimensional, and each <de Rham cohomology> class has a unique harmonic representative. <Integration by parts> gives $\langle\Delta\alpha,\alpha\rangle_{L^2}=\|d\alpha\|_{L^2}^2+\|\delta\alpha\|_{L^2}^2$, so <harmonic forms> are exactly the closed and coclosed forms. Set $\Omega^k=0$ outside $0\le k\le n$. Compactness without boundary is a hypothesis of this version of the theorem; orientation alone does not supply it.

A connection on $TM$ induces a <dual connection> on $T^*M$ and then connections on its tensor and exterior powers by the Leibniz rule. Explicitly, for a $p$-form $\alpha$,
$$
(\nabla_X\alpha)(Y_1,\ldots,Y_p)=X\bigl(\alpha(Y_1,\ldots,Y_p)\bigr)
-\sum_{j=1}^p\alpha(Y_1,\ldots,\nabla_XY_j,\ldots,Y_p).
$$
To prove the <parallelism of the Riemannian volume form>, use a local positively oriented orthonormal frame $E_i$, its dual coframe $\theta^i$, and write $\nabla_XE_j=\sum_i a_{ij}(X)E_i$. <Metric compatibility> makes the matrix $a(X)$ skew-symmetric. Since $\omega_g=\theta^1\wedge\cdots\wedge\theta^n$, differentiating the wedge yields
$$
\nabla_X\omega_g=-\sum_i a_{ii}(X)\omega_g=0.
$$
Off-diagonal terms vanish because they repeat a coframe factor. Thus \b[$\nabla\omega_g=0$]; equivalently <parallel transport> preserves both the metric and the continuously chosen orientation.

Now let $M$ be compact, oriented and without boundary. For <representing functionals on harmonic forms by wedge pairing>, choose an $L^2$-<orthonormal basis> $h_1,\ldots,h_b$ of $\mathcal H^p$ and define
$$
h_f=\sum_{a=1}^b f(h_a)h_a,\qquad \psi_0=*h_f.
$$
If $\varphi=\sum_a c_ah_a$, linearity gives
$$
\boxed{f(\varphi)=\langle\varphi,h_f\rangle_{L^2}=\int_M\varphi\wedge\psi_0}.
$$
This also works when $b=0$, using the empty sum. Since the <Hodge star> commutes with the <Hodge Laplacian>, $\psi_0$ is harmonic of degree $n-p$.

For the full <ambiguity of harmonic wedge-pairing representatives>, write another representative as $\psi_0+\chi$. Because the star is an <isometry>,
$$
\int_M\varphi\wedge\chi=\langle*\varphi,\chi\rangle_{L^2}.
$$
The forms $*\varphi$ range over all of $\mathcal H^{n-p}$. Hence $\chi$ gives zero functional exactly when its harmonic projection is zero. Hodge decomposition proves that the complete answer is
$$
\boxed{\psi=*h_f+d\alpha+\delta\beta,\qquad
\alpha\in\Omega^{n-p-1}(M),\quad\beta\in\Omega^{n-p+1}(M)}.
$$
Both summands in this ambiguity are permitted; it is not only an exact-form ambiguity. The exact and coexact component forms are orthogonal to every <harmonic form>, so every displayed choice works. Conversely a nonzero harmonic component would pair nontrivially with some $*\varphi$, and therefore cannot occur. \b[The harmonic representative $*h_f$ is unique; the arbitrary smooth representative generally is not.] The formula also covers the endpoint degrees and any exceptional case where the ambiguity space is zero.

For a concrete coexact ambiguity, take the <torus> $(\mathbb R/2\pi\mathbb Z)^2$ with metric $dx^2+dy^2$. The form $\chi=\delta(\sin y\,dx\wedge dy)=\cos y\,dx$ annihilates every harmonic one-form by orthogonality, yet $d\chi=\sin y\,dx\wedge dy$ is nonzero. Thus an annihilating representative need not even be closed, let alone exact.