If Reduce
returns an Or
expression, you can apply Sort
to get the lowest, something like this:
With[{A = 3/10, B = 1},
Block[{s},
s = Reduce[1/(16 (1 - x)^7) + (4.5 (1 - x) (-1 + 3 x))/
(-B - 0.5 A + 4.5 (1 - x)^2 x)^3 == 0 &&
0 < x < 1, x,
Reals];
If[Head[s] === Or, First[Sort[s]], s]
]
]
(* x == 0.349826 *)
Try it with {A,B}={-1,0} for the single solution case, and {A,B}={-1,2} for the no solution case.
Sanity Check:
The following code will perform a quick sanity check to confirm that Sort
will give us the right answers:
nTest = 20;
testCases = Thread[x == RandomReal[{0, 1}, nTest]]
Sort[testCases]
Exercising the above code over various ranges like {0,1}, {-1,1} and {-100,100} indicates Sort
is doing its job, as long as the expressions are all of the assumed form. To get the least of the expressions, we apply First
to the sorted list. To get the greatest of the expressions, we apply Last
.
Why Greater
did not work: A comment mentioned that Sort[s,Greater]
did not work to return the highest answer.
So, why didn't Greater
work? The documentation for Greater
says it returns True or False for real numbers. We are trying to sort expressions. Since Greater[x==1, x==2]
does not return True or False, we are not really comparing the expressions.
How to use Greater
Since Greater
works with real numbers, we can simply point to the real numbers in our expressions, like this:
Sort[testCases, Greater[Last[#1], Last[#2]] &]
Here, we are applying Last
to expressions like x == 3.14159
, so Last
returns just the real number. We pass 2 real numbers to Greater
, and voilà, Greater
makes the comparison.