1
$\begingroup$

Why do the following commands

$Assumptions = {Element[x, Reals], x > 0};
Solve[{x^2 == 1}, {x}]
Solve[{x^2 == -1}, {x}]

give

(*{{x -> -1}, {x -> 1}}*)
(*{{x -> -I}, {x -> I}}*)

Wouldn't I expect to get only

(*{x -> 1}*)

Furthermore, how can I implement global assumptions that hold for the entire session? I have quite a lot of Simplify[] and they all use the same variables which I want to be real and positive.

$\endgroup$
2
$\begingroup$

The appropriate command should be :

Solve[x^2 == 1 && x > 0, x, Reals]
Solve[x^2 == -1 && x > 0, x, Reals]

The third argument is the domain specification and the x>0 is an extra constraint you need to specify.

This gives the results {{x -> 1}} and {} respectively.

When Mathematica solves your equation it treats $x$ as a dummy variable and, hence, is ignoring the global assumptions on $x$.

| improve this answer | |
$\endgroup$
  • $\begingroup$ Thanks! So there is no way to declare x as real and positive for all calculations without having to write it as you wrote it above? $\endgroup$ – xabdax Aug 7 '19 at 21:00
  • 1
    $\begingroup$ @xabdax not while using Solve. You can use global assumptions to simplify other expressions where $x$ is not treated as a dummy variable -- $Assumptions = And[x>0,Element[x,Reals]] should work for those other cases. $\endgroup$ – TheTwistedSector Aug 7 '19 at 21:05
  • 2
    $\begingroup$ x>0 automatically implies x ∈ Reals, so it can be omitted in the assumptions $\endgroup$ – Lukas Lang Aug 7 '19 at 22:12
  • 3
    $\begingroup$ If you evaluate Options[Solve] you will see that the options do not include Assumptions and consequently Solve does not make use of $Assumptions. The assumptions must be included as constraints in the system provided to Solve. Subsequent use of Simplify or FullSimplify would make use of $Assumptions since their options include Assumptions ($Assumptions is the default value for Assumptions). $\endgroup$ – Bob Hanlon Aug 8 '19 at 4:51

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