Often I need to generate some data using some symmetry operations and I usually keep them as exact expressions (for example, consider the points on a triangular grid {{-(1/2), Sqrt[3]/2}, {-(1/2), -(Sqrt[3]/2)}, {1, 0}, ...}) and I need to compare different points, something like if a1+b==a2. I am trying to find an efficient way to do that.
Consider this
a=-2/Sqrt[3] + Sqrt[3]
b=Sqrt[1/4 + (2/Sqrt[3] - Sqrt[3]/2)^2]
{N[a],N[b]}
{0.57735,0.57735}
Now, a==b does not do anything.
N[a] == N[b]
N[a]-N[b] == 0
N[a - b] == 0
True
False
False
Because N[a-b]=-3.33067*10^-16. So the way out is
Chop@N[a - b] == 0
True
However,
RepeatedTiming[N[a] == N[b]]
RepeatedTiming[Chop@N[a - b] == 0]
{5.4*10^-6, True}
{9.07*10^-6, True}
On the other hand,
a1 = N[a]; b1 = N[b];
RepeatedTiming[a1 == b1]
{2.7*10^-7, True}
So my questions are
Is it better to use real numbers if I have to do such comparisons?
What would be the best (least time consuming when dealing with a large number of inputs) way to compare exact expressions if I have to use exact expressions?
N[Sin[2017 2^(1/5)]] - N[-1]– J. M.'s missing motivation Mar 08 '19 at 10:29PossibleZeroQcould help. – Roman Mar 08 '19 at 10:48