(I suspect this question is a duplicate, but I didn't find a sufficiently similar question with an answer to it.)
I'm having trouble with comparisons of symbolic Reals
that are equal, but which Mathematica has trouble recognising them as equal, apparently because it uses N
to compare these (apparently after some simple symbolic manipulation). Typically these issues creep up in conditions like one (greatly simplified) below:
x > y /. {x -> Sqrt[(2 - Sqrt[3])^2 + (-3 + 2*Sqrt[3])^2], y -> 4 - 2*Sqrt[3]}
N::meprec: "Internal precision limit $MaxExtraPrecision = 50.` reached while evaluating -4+2\ Sqrt[3]+Sqrt[(2-Sqrt[3])^2+(-3+2 Sqrt[3])^2]."
Sqrt[(2 - Sqrt[3])^2 + (-3 + 2*Sqrt[3])^2] > 4 - 2*Sqrt[3]
This is in no way undocumented feature; it is discussed under Possible Issues section of $MaxExtraPrecision
.
What I really want is Mathematica to try a bit harder on solving these (in)equalities numerically in a block of code. How do I accomplish this? As a workaround for specific problem above, this does work (while Simplify
on inequality part doesn't):
x > y /. Simplify @ {x -> Sqrt[(2 - Sqrt[3])^2 + (-3 + 2*Sqrt[3])^2], y -> 4 - 2*Sqrt[3]}
False
I would be happy to see a solution that could wrap up around a block of code, and which could possibly work also on non-algebraics that FullSimplify
can handle.
EDIT:
To clarify my question: I want first example to evaluate like the expression below, and in general Greater
to evaluate for NumericQ
argument list similarly inside a code block where I want this feature to be used:
Simplify[Sqrt[(2 - Sqrt[3])^2 + (-3 + 2*Sqrt[3])^2]] > Simplify[4 - 2*Sqrt[3]]
False
N
appears only in the error message, not in my code. This is exactly the inconvenience I'm trying to get rid of. $\endgroup$MachinePrecision
only to be able to compare things with Matlab and Fortran when I want to. You can force all computation to be inMachinePrecision
by putting this at the top of the notebook or in your init.m$MinPrecision = $MachinePrecision; $MaxPrecision = $MachinePrecision;
Now your example runs with no warnings: !Mathematica graphics again, do not know if this is what you want, or this will work for what you are doing. $\endgroup$PossibleZeroQ
, withMethod -> "ExactAlgebraics"
. This post Most efficient way to determine conclusively whether an algebraic number is zero discusses the issue. $\endgroup$