[Date Index] [Thread Index] [Author Index]
Re: Why does Mathematica change the precision of an expression to check equality?
Hi Jean-Marc, the Help says: "For exact numeric quantities, Equal internally uses numerical approximations to establish inequality. This process can be affected by the setting of the global variable $MaxExtraPrecision. " Obviously the numerical approximation is only done on the expression on the LHS, not on the number 1. If 1 is changed into 1. only machine precision is used and the test succeed. Daniel Jean-Marc Gulliet wrote: > These thoughts come after answering a similar question in a forum > dedicated to anther CAS. Having ran the following code, I am a little > perplexed by the behavior of Mathematica. > > y = (Sqrt - 2)*(Sqrt + 2); > y == 1 > > --> N::"meprec" : "Internal precision limit $MaxExtraPrecision = > (49.99999999999999) reached while evaluating -1 + (-2 + Sqrt)*(2 + > Sqrt). More... > > --> (-2 + Sqrt)*(2 + Sqrt) == 1 > > At least Mathematica returns a warning message in addition to the > unevaluated expression > > I used to thought that Mathematica was not attempting to do any > algebraic simplifications when testing, say, equality, and that one have > to request explicitly such transformations. > > However, it is pretty clear that Mathematica transforms the expression > in some way, in this case changing infinite precision -- that is exact > numbers -- into arbitrary precision -- that is better precision that > hardware but still not exact. > > So the question is, "Why, when an expression is only written with exact > numbers, Mathematica would "downgrade" the precision to a lower and > inexact one before attempting to answer a boolean question?" > > I do not see the rational behind this design choice... > > Best regards, > Jean-Marc > > P.S. I know that one can get the correct answer by using Simplify. >