let's consider a particle in a 2D-Box of length $L_x, L_y$.
Hamiltonian: $\hat{H}=-\frac{\hbar^2}{2m}(\partial_x^2 + \partial_y^2)$
Potential: $V(x,y)=\begin{cases} 0, & 0\leq x \leq L_x, \ 0\leq y \leq L_y\\ \infty ,& \text{else}\end{cases}$
Schrödinger-EQ: $\hat{H}\Psi(x,y)=E\Psi(x,y)$
We solve the Schrödinger-EQ using the ansatz $\Psi(x,y)=\psi_{n_x}(x)\psi_{n_y}(y)$
Inside of the box, we have:
$$ \frac{-\hbar^2}{2m}\big( \psi_{n_y}(y)\partial_x^2\psi_{n_x}(x) + \psi_{n_x}(x)\partial_y^2\psi_{n_y}(y) \big) = E\psi_{n_x}(x)\psi_{n_y}(y) \tag{1}$$
We divide by $\psi_{n_x}(x)\psi_{n_y}(y)$ and end up with
$$ \frac{-\hbar^2}{2m}\frac{1}{\psi_{n_x}(x)}\partial_x^2\psi_{n_x}(x) - \frac{-\hbar^2}{2m}\frac{1}{\psi_{n_y}(y)}\partial_y^2\psi_{n_y}(y) = E \tag{2}$$
Now apparently we can argue like this:
In (2) the first term on the LHS depends only on $x$ while the second term only depends on $y$. Becuase of that, both terms have to be constant and we can look at each other separately:
$$ \frac{-\hbar^2}{2m}\frac{1}{\psi_{n_x}(x)}\partial_x^2\psi_{n_x}(x)= E_{n_x} \tag{3}$$ $$ \frac{-\hbar^2}{2m}\frac{1}{\psi_{n_y}(y)}\partial_y^2\psi_{n_y}(y)= E_{n_y} \tag{4}$$
whereas $E_{n_x}+E_{n_y}=E$
Now my question is about the quote above. How exactly do we know that both terms are constant on their own? It's more a mathematical question. I'd like to prove this but I fail.
Here's my attempt:
Let
$f: \mathbb R^2 \to \mathbb R, \ \vec{v}\mapsto \vec{v}\cdot\begin{pmatrix}1\\ 0\end{pmatrix}$
$g: \mathbb R^2 \to \mathbb R, \ \vec{v}\mapsto \vec{v}\cdot\begin{pmatrix}0\\ 1\end{pmatrix}$
whereas $\vec{v}=(v_x, v_y)$
Claim: $f(\vec{v}) + g(\vec{v}) = E$ for a fixed $E\in\mathbb R \vec{5}$ implies $f,g$ are constant Proof: Choose $f,g$ as above. Then
$g(\vec{v})+f(\vec{v})=E \tag{5.1}$
$\vec{v}\cdot\begin{pmatrix}1\\ 0\end{pmatrix} + \vec{v}\cdot\begin{pmatrix}0\\ 1\end{pmatrix} = E \tag{5.2}$
Let's identify $g(\vec{v})$ with $\hat{g}(y)$ and $f(\vec{v})$ whereas obviusly $\hat{f}(x)$ whereas $\hat{g},\hat{f}: \mathbb R \to \mathbb R$
Now we can write
$$ \hat{f}(x) + \hat{g}(y) = E \tag{5.3} $$
so now we have the situation in the quote. (I did this, just so we have two one-dimensional functions and don't have to use vectrs. I'm pedantic.)
Now, what stops me from just saying:
Choose $\hat{f}(x)$ as a non-constant function and define $\hat{g}(y)=\hat{f}(y)+\text{const}$ with $\text{const}\in \mathbb R$
Now furthermore choose $\text{const}=E$ and we get $E=\hat{g}(y)-\hat{f}(y)$ whereas $\hat{g}, \hat{f}$ are both non-constant functions.
Of course, that only works because we now identified implicitly $x=y$. But I don't fully see how I can get the claim properly now.