# Solve returns solution that isn't (always) one

I was asking Mathematica to find the roots of $$f(x) = a+\sqrt{x^2-b}$$ and it returns $$x = \pm \sqrt{a^2+b}$$. These are however solutions only if $$a\leq 0$$ (there are no roots if a is positive since principal square roots are by definition non-negative). Why is Solve not returning ConditionalExpression[$$\pm \sqrt{a^2+b}$$, $$a\leq 0$$]? Is it a bug?

Here's a numerical example:

numc = {a -> 2, b -> 5};
f = a + Sqrt[x^2 - b];
Plot[f /. numc, {x, -3.5, 3.5}, PlotRange -> {0, 5}]
Solve[f == 0, x]
% /. numc


• Mathematica is right: complex solutions are produced by default. Use Solve[f == 0, x, Reals] in order to obtain conditional expressions. – user64494 Nov 30 '18 at 9:49
• Still if, a=1, b=0 this solution is wrong. – kiara Nov 30 '18 at 9:56
• @user64494 Solve[f == 0, x, Reals] does indeed work! However, I don't see why Mathematica is right. If you take a=2, b=5, you get $x=\pm 3$ even though $f(\pm 3) = 4$. Correct me if I'm wrong but there is no real or complex solution in that example. – user2737248 Nov 30 '18 at 11:01
• I don't think this is a bug. Up to the help to Solve, Solve may make nonequivalent transforms. – user64494 Nov 30 '18 at 15:57

You can instruct Solve to generate all conditions using MaxExtraConditions, or you can use Reduce instead of Solve.

Solve[a + Sqrt[x^2 - b] == 0, x, MaxExtraConditions -> All]

During evaluation of Solve::useq: The answer found by Solve contains equational condition(s) {0==-a-Sqrt[a^2],0==-a-Sqrt[a^2]}. A likely reason for this is that the solution set depends on branch cuts of Wolfram Language functions.
(* {{x ->
ConditionalExpression[-Sqrt[a^2 + b], a + Sqrt[a^2] == 0]}, {x ->
ConditionalExpression[Sqrt[a^2 + b], a + Sqrt[a^2] == 0]}} *)

Reduce[a + Sqrt[x^2 - b] == 0, x]

During evaluation of Reduce::useq: The answer found by Reduce contains unsolved equation(s) {0==-a-Sqrt[a^2],0==-a-Sqrt[a^2]}. A likely reason for this is that the solution set depends on branch cuts of Wolfram Language functions.
(* (0 == -a - Sqrt[a^2] &&
x == -Sqrt[a^2 + b]) || (0 == -a - Sqrt[a^2] && x == Sqrt[a^2 + b]) *)


Quoting from the Solve documentation:

Solve gives generic solutions only. Solutions that are valid only when continuous parameters satisfy equations are removed. Additional solutions can be obtained by using nondefault settings for MaxExtraConditions.

If you want to obtain solutions over reals, try

numc = {a -> 2, b -> 5};f = a + Sqrt[x^2 - b];Solve[f == 0, x,Reals]


{{x->ConditionalExpression[-Sqrt[a^2+b],a<0&&a^2+b>0]},{x->ConditionalExpression[Sqrt[a^2+b],a<0&&a^2+b>0]}}

% /. numc


{{x->Undefined},{x->Undefined}}

• Indeed, but what if I am also interested in complex solutions? There are no real or complex solutions when a is positive so why isn't there a ConditionalExpression? – user2737248 Nov 30 '18 at 13:03
• Making use of sol = Reduce[f == 0, x, Complexes], one obtains Reduce::useq: The answer found by Reduce contains unsolved equation(s) {0==-a-Sqrt[a^2],0==-a-Sqrt[a^2]}. A likely reason for this is that the solution set depends on branch cuts of Wolfram Language functions. (0 == -a - Sqrt[a^2] && x == -Sqrt[a^2 + b]) || (0 == -a - Sqrt[a^2] && x == Sqrt[a^2 + b]) – user64494 Nov 30 '18 at 15:33