Recall that a Hilbert space $\mathcal{H}$ is a reproducing kernel Hilbert space (RKHS) if the elements of $\mathcal{H}$ are functions on a certain set $X$ and for any $a\in X$, the linear functional $f\mapsto f(a)$ is bounded on $\mathcal{H}$. By Riesz Representation Theorem, there exists an element $K_a\in\mathcal{H}$ such that $$f(a) = \langle f, K_a\rangle\ \text{ for all } \ f\in\mathcal{H}.$$ The function $K(x,y) = K_y(x) = \langle K_y, K_x\rangle$ defined on $X\times X$ is called the reproducing kernel function of $\mathcal{H}$.

It is well known and easy to show that for any orthonormal basis $\{e_m\}_{m=1}^{\infty}$ for $\mathcal{H}$, we have the formula $$K(x,y) = \sum_{m=1}^{\infty}e_m(x)\overline{e_m(y)},\tag{Eqn 1}$$ where the convergence is pointwise on $X\times X$.

My question concerns the converse of the above statement.

**Question:** if $\{g_m\}_{m=1}^{\infty}$ is a sequence of functions in $\mathcal{H}$ such that $$K(x,y) = \sum_{m=1}^{\infty}g_m(x)\overline{g_m(y)}\tag{Eqn 2}$$ for all $x,y\in X$. Is the sequence $\{g_m\}_{m=1}^{\infty}$ an orthonormal basis for $\mathcal{H}$?

The answer to this question is clearly negative since equation (Eqn 1) can be re-written as
$$K(x,y) = \frac{e_1(x)}{\sqrt{2}}\overline{\frac{e_1(y)}{\sqrt{2}}}+\frac{e_1(x)}{\sqrt{2}}\overline{\frac{e_1(y)}{\sqrt{2}}}+\sum_{m=2}^{\infty}e_m(x)\overline{e_m(y)}$$
and clearly $\{e_1/\sqrt{2}, e_1/\sqrt{2}, e_2, \ldots\}$ is **not** an orthonormal basis for $\mathcal{H}$. So the following additional condition should be added: the sequence $\{g_m\}_{m=1}^{\infty}$ is **linearly independent**.

The following proof suggests that the answer is affirmative. (For those who are familiar with the proof of the Moore-Aronszajn's Theorem in the theory of RKHS, the proof here looks similar.)
Assume that we have (Eqn 2) and the sequence $\{g_m\}_{m=1}^{\infty}$ is linearly independent. Let $\mathcal M$ be the linear space spanned by the functions $\{g_m\}_{m=1}^{\infty}$. Define a sesquilinear form on $\mathcal M$ as
\begin{align*}
\left\langle\sum_{\text{finite sum}}a_jg_j, \sum_{\text{finite sum}}b_kg_k\right\rangle_{\mathcal M} = \sum_{\text{finite sum}} a_j\overline{b}_j.
\end{align*}
Since $\{g_m\}_{m=1}^{\infty}$ is a linearly independent set, the above definition is **well-defined**. Note that $\{g_m\}_{m=1}^{\infty}$ is an orthonormal set in $\langle,\rangle_{\mathcal M}$. For any $f\in\mathcal M$ and $x\in X$, we have
\begin{align*}
f(x) = \sum_{\text{finite sum}}\langle f,g_m\rangle_{\mathcal M}\,g_m(x).
\end{align*}
Cauchy-Schwarz's inequality gives
\begin{align*}
|f(x)| & \leq \Big(\sum_{\text{finite sum}}|\langle f,g_m\rangle_{\mathcal M}|^2\Big)^{1/2}\Big(\sum_{\text{finite sum}}|g_m(x)|^2\Big)^{1/2} \leq \|f\|_{\mathcal M}\sqrt{K(x,x)}.
\end{align*}
Let $\widetilde{\mathcal M}$ be the Hilbert space completion of $\mathcal M$. The standard argument shows that $\widetilde{\mathcal M}$ is a RKHS of functions on $X$. What is the kernel of $\widetilde{\mathcal M}$? Since $\{g_m\}_{m=1}^{\infty}$ is an orthonormal set and its span is dense in $\widetilde{\mathcal M}$, it is an orthonormal basis for $\widetilde{\mathcal M}$. The kernel of $\widetilde{\mathcal M}$ then can be computed as $$\sum_{m=1}^{\infty}g_m(x)\bar{g}_m(y),$$ which is the same as $K(x,y)$. Therefore, $\widetilde{\mathcal M}$ is the same as $\mathcal H$ (they consist of the same functions and the inner products on the two spaces are equal). Consequently, $\{g_m\}_{m=1}^{\infty}$ is an orthonormal basis for $\mathcal{H}$. This completes the proof.

**Counterexample:** On the other hand, there are counterexamples that provide a negative answer to the question in the infinite dimensional case.

What part of the above proof is incorrect? I have checked but could not figure out what went wrong.

Thank you.