4
$\begingroup$

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

enter image description here

$\endgroup$
4
  • 1
    $\begingroup$ Mathematica is right: complex solutions are produced by default. Use Solve[f == 0, x, Reals] in order to obtain conditional expressions. $\endgroup$
    – user64494
    Nov 30, 2018 at 9:49
  • $\begingroup$ Still if, a=1, b=0 this solution is wrong. $\endgroup$
    – kiara
    Nov 30, 2018 at 9:56
  • $\begingroup$ @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. $\endgroup$ Nov 30, 2018 at 11:01
  • 2
    $\begingroup$ I don't think this is a bug. Up to the help to Solve, Solve may make nonequivalent transforms. $\endgroup$
    – user64494
    Nov 30, 2018 at 15:57

2 Answers 2

5
$\begingroup$

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.

$\endgroup$
0
$\begingroup$

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}}

$\endgroup$
2
  • $\begingroup$ 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? $\endgroup$ Nov 30, 2018 at 13:03
  • 1
    $\begingroup$ 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]) $\endgroup$
    – user64494
    Nov 30, 2018 at 15:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.