# Why is the solution I obtained from Solve not verified in the original equation?

I have this equation $$x^2 \left(\sqrt{1-y^2} \sin (x)-\sin (4 x)\right)+2 x y=0$$ I want to solve this equation and find $$y$$ in terms of $$x$$. I use Solve

Solve[ (Sqrt[1 - y^2] Sin[x] - Sin[4 x]) x^2 + 2 x  y == 0, y]


and I obtain two solutions

y -> (-Sqrt[2] Sqrt[
8 x^2 Sin[x]^2 - x^4 Cos[2 x] Sin[x]^2 + x^4 Cos[8 x] Sin[x]^2] +
4 x Sin[4 x])/(2 (4 + x^2 Sin[x]^2))


and

y -> (Sqrt[2] Sqrt[
8 x^2 Sin[x]^2 - x^4 Cos[2 x] Sin[x]^2 + x^4 Cos[8 x] Sin[x]^2] +
4 x Sin[4 x])/(2 (4 + x^2 Sin[x]^2))


Then, when I substitute these solutions in the original equation, they are not verified. Can someone please guide me where I am going wrong?

Solve yields a generic result, while Reduce provides complete description of the solution space. With the MaxExtraConditions -> All option in Solve one can get in various cases as much as Reduce can provide however this isn't always possible.
The fact that Solve provides a generic result sometimes apears to be convenient as is the case here, however that generic solution need not always to be an actual solution. More extensive discussion one can find in What is the difference between Reduce and Solve?

For an insight what kind of solution one might expect here we can sketch them with

ContourPlot[ (Sqrt[1 - y^2] Sin[x] - Sin[4 x]) x^2 + 2 x y == 0,
{x, -10, 10}, {y, -2, 2},
ContourStyle -> Thick, AspectRatio -> Automatic, ImageSize -> 600,
PlotPoints -> 90, MaxRecursion -> 3]


It is obvious thet there are solutions with -1 <= y <= 1 only. We can see that for certain real ranges of x thare is no solution, for others on can find one or two solutions. As we mentioned above Reduce is more powerful, nonetheless we can find solutions with Solve as well:

Solve[ (Sqrt[1 - y^2] Sin[x] - Sin[4x]) x^2 + 2 x y == 0 && -5 < x < 5, y, Reals]


Let's demonstrate that the "generic sollution" need not be an actual solution.

sol = Solve[ (Sqrt[1 - y^2] Sin[x] - Sin[4 x]) x^2 + 2 x  y == 0, y];
ex1 = (((Sqrt[1 - y^2] Sin[x] - Sin[4 x]) x^2 + 2 x  y)/. sol[[1]] // Simplify);
Plot[ ex1, {x, -5, 5}, PlotStyle -> Thick, WorkingPrecision -> 30]


y is a solution only when ex1 vanishes. Since it is hard demonstraiting with symbolic functionality we can reach satisfactory insight with plotting of the graph of ex1. One can easily observe that ex1 is not a solution e.g. for 3.5 < x < 4. Similar analysis for another "generic solution" ensures that we can get a specific solution only for appropriate ranges and simplifying the equation with a generic solution cannot yield zero in general. One can see how many different cases can be found with Reduce e.g.

Reduce[ (Sqrt[1 - y^2] Sin[x] - Sin[4 x]) x^2 + 2 x y == 0 && -10 < x < 10, y, Reals]


This output is very large and one realizes why there the system suppresses the output when no reasonable restriction for x is provided.

• Beat me to it! +1.
– ciao
Commented Aug 23, 2020 at 3:25
– user73597
Commented Aug 23, 2020 at 9:40
• @Artes Another problem. It seems that ContourPlot does not consider double roots of an equation. So, one should not only consider its solutions.
– user73597
Commented Aug 23, 2020 at 9:58
• @Mariya You are welcome. ContourPlot simply generates lines in the plane {x, y} where this equation (Sqrt[1 - y^2] Sin[x] - Sin[4 x]) x^2 + 2 x y == 0 is satisfied. It doesn't have anything to do with multiple roots. Nevertheless it appears to be helpful when analyzing possible solutions. There is an extensive discusion in the post I linked in the answer If you are not familiar with subtleties regarding symbolic equation solving functionality. Commented Aug 23, 2020 at 13:00

I don't think you are doing anything wrong, but the result is interesting. When you plug in numbers, you get the equation satisfied only sometimes.

eq[x_, y_] = (Sqrt[1 - y^2]*Sin[x] - Sin[4*x])*x^2 + 2*x*y


let Mathematica solve it.

sol = Solve[eq[x, y] == 0, y] // Flatten // Simplify


and look at some values. A few x,y values for the first solution:

tab1 = Table[{x, y /. sol[[1]]}, {x, 0, 5, .2}] // N


plug the values into the original equation:

result1 = Table[{tab1[[i, 1]], eq[tab1[[i, 1]], tab1[[i, 2]]]}, {i, 1, Length[tab1]}];


Looking at the result the equation is satisfied to machine precision up to about $$x=2.4$$ and for higher values, only occasionally. If you look at the second solution the same way, the lower values are wrong, while the higher values are right about half the time.

So I understand why Mathematica does not verify the solutions, but I do not understand why we are getting these answers in the first place.

As a check, M12 and M8 produce the same results, except for minor simplification differences.

• Thanks. You are right. It seems that Mathematica square the equation to find $y$, and in this way, it produces the extraneous solutions.
– user73597
Commented Aug 22, 2020 at 22:55

I cannot find an error in what you write but the issue lies with Solve which does not quite "solve" equations. Mathematica indeed finds two solutions:

e[x_, y_] := x^2 (Sqrt[1 - y^2]*Sin[x] - Sin[4*x]) + 2 x y;
sol = Solve[e[x, y] == 0, y];
TableForm[%]
f[x_] := e[x, y] /. First[sol];
g[x_] := e[x, y] /. Last[sol];


Neither solution can be reduced to 0 by Simplify or FullSimplify. Plotting may help; each solution may be OK in part of the domain for $$x$$ but not everywhere as shown here:

Plot[{f[x], g[x]}, {x, 0, 10}, PlotRange -> All]


However the documentation for Solve mentions that

Solve does not eliminate solutions that are neither generically correct nor generically incorrect

Have a look at @Artes ' comment for a link to a discussion.

• Thanks. It seems that Mathematica square the equation to find $y$, and in this way, it produces the extraneous solutions.
– user73597
Commented Aug 22, 2020 at 22:56
• @Mariya Please report at [email protected]
– Alan
Commented Aug 22, 2020 at 23:42
• @A.G. For what?
– user73597
Commented Aug 22, 2020 at 23:45
• This is not a bug. For a detailed discussion of various restrictions see What is the difference between Reduce and Solve?. Solve yields a genric solution and in certain ranges of x such a generic solution need not be a solution. Commented Aug 23, 2020 at 0:18
• For the first plot, specify a WorkingPrecision so that arbitrary-precision is used rather than machine precision. Commented Aug 23, 2020 at 1:49