3
$\begingroup$

I need a "clean" way to find the smallest solution to some (in)equalities given by Reduce and containing only one variable x. For example, such an expression could be 1 ≤ x ≤ 2, x == 9 or -1 ≤ x ≤ 4 || 7 ≤ x ≤ 11 || x == 5. I know that FindInstance finds some instance, but I don't know how to restrict the search to the smallest one (it outputs {{x -> 43/34}}, {{x -> 9}} and {{x -> 2/7}} for the previous examples).

In principle, this could be done by using patterns to extract the endpoints of the intervals and choosing the smallest one, but I think there should be a cleaner way.

$\endgroup$

1 Answer 1

3
$\begingroup$

This is very easily done, using Minimize. Make a list of your examples

conditions = {1 <= x <= 2, 
  x == 9, -1 <= x <= 4 || 7 <= x <= 11 || x == 5}
(* {1 <= x <= 2, x == 9, -1 <= x <= 4 || 7 <= x <= 11 || x == 5} *)

and solve each of them

Minimize[{x, #}, x] & /@ %
(* {{1, {x -> 1}}, {9, {x -> 9}}, {-1, {x -> -1}}} *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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