If $(X,\langle\cdot,\cdot\rangle)$ is an and the set (of non zero vectors) $S = \{e_i \mid i ∈ N\} $ Assume that $S$ is orthonormal. Let $n \in \mathbb N$ and let $x \in X$. The following vector are defined
$$ y := \sum_{i=1}^n \langle x,e_i\rangle e_i.$$
How can i prove this $(x − y) \perp y$?
You can note that the application $$\begin{align}p: &X \rightarrow X \\ &x \mapsto \sum_{i=1}^n \langle x,e_i\rangle e_i \end{align}$$
is linear by construction ($\forall (\lambda, \mu) \in \mathbb R^2, \forall (x, y) \in X^2, p(\lambda x + \mu y) = \lambda p(x) + \mu p(x)$), and that $p^2=p$. It is the definition of the orthonormal projection of X on the sub vector space built from S.
Now for the direct proof:
$\langle x, y \rangle = \langle x, \sum_{i=1}^n \langle x,e_i\rangle e_i\rangle = \sum_{i=1}^n \langle x,e_i\rangle \langle x,e_i\rangle$
$\langle y, y \rangle = \langle \sum_{j=1}^n \langle x,e_j\rangle e_j\rangle, \sum_{i=1}^n \langle x,e_i\rangle e_i\rangle = \sum_{i=1}^n \langle x,e_i\rangle \langle x,e_i\rangle$ because $\langle e_i, e_j \rangle$ is 1 when $i = j$ else $0$ by orthonormality of S
It immediately gives $\langle x -y, y\rangle = 0$ which proves $(x − y) \perp y$