# Separation of variables in a nonlinear PDE

Consider the equation

$$\left(\frac{\partial S}{\partial q}\right)^2 + q^2 = -\frac{\partial S}{\partial t}$$

where $$S$$ is a function of $$q$$ and $$t$$. The start of the solution to this problem in the book I'm reading is as follows:

Because the LHS is a function of $$S$$ not involving $$t$$, integrating both sides gives us a function $$S$$ having the form $$S(q,t)=W(q)+V(t)$$

Once we think $$S$$ is of this form, I can easily solve the PDE myself. However, this first step confuses this confuses both me and my math-y friends. The LHS involves $$(\partial_q S)^2$$, not $$\partial_q S$$, so I don't see how we can get anything meaningful by direct integration. Can someone explain what they did here?

(For those who care, this PDE is the Hamilton-Jacobi equation for the harmonic oscillator. The solution that's confusing me is from "A Student's Guide to Lagrangians and Hamiltonians" by Mark Hamill, though other solutions run along the same lines.)

Note that we have the Hamilton-Jacobi equation \begin{align} \frac{\partial S}{\partial t}=-H\left(q, \frac{\partial S}{\partial q}\right) \end{align} where $$H(q, p) = q^2+p^2$$.
In short, if we solve the equation using the method of characteristics then we see that \begin{align} S(t, q) -S(0, q) =&\ \int^t_0 \frac{\partial S}{\partial \tau}\ d\tau = \int^t_0 -H\left(q(\tau), \frac{\partial S}{\partial q}(\tau)\right)\ d\tau \\ =&\ -\int^t_0 H(q(\tau), p(\tau))\ d\tau = -Et \end{align} for some constant $$E$$.
Hence it follows \begin{align} S(t, q) = S(0, q) -E t =: W(q)+V(t). \end{align}