2
$\begingroup$

How can I add constraints to the Solve function?

For example, I tried:

Solve[x^2 == y && (2 < x < 3 || x > 5), x]

but it returns an empty set, which seems wrong. How can I include such inequality constraints correctly in Solve?

$\endgroup$
5
  • $\begingroup$ The solution is empty because $y$ is not guaranteed to be a positive real number. Solve[x^2 == y && (2 < x < 3 || x > 5) && y > 0, x] is what you want, isn't it? Or, tryReduce[x^2 == y && (2 < x < 3 || x > 5), x]. $\endgroup$ Commented Oct 27 at 5:11
  • $\begingroup$ @A.Kato That gives the same result with this Solve[x^2 == y && (2 < x < 3 || x > 5), x, Reals] but I don't want specify y>0 as that is still unknown. Just use Reals seems work well. $\endgroup$ Commented Oct 27 at 5:29
  • 1
    $\begingroup$ Ok. You solved the problem by yourself.... $\endgroup$ Commented Oct 27 at 7:18
  • $\begingroup$ Reduce[x^2 == y && (2 < x < 3 || x > 5), x] seems more appropriate for something like this. $\endgroup$ Commented Oct 27 at 15:32
  • $\begingroup$ @SjoerdSmit I should have mentioned that I want a result with rules so I can replace it with other expression. $\endgroup$ Commented Oct 27 at 17:53

1 Answer 1

7
$\begingroup$
  • Since in Solve, the default MaxExtraConditions is 0.
Solve[x^2 == y && (2 < x < 3 || x > 5), x, MaxExtraConditions -> All]

enter image description here

$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.