Separation of variables in the nonlinear wave equation