Message Boards Message Boards

3 Replies
0 Total Likes
View groups...
Share this post:

Complement[] with tolerance on comparisons?

Posted 11 years ago
I have been setting up two parameter experimental designs using Table to create a grid of {x, y} values. Later, I add detail to my grid with a second Table command. To eliminate  duplicate points in my table I use Complement[]. Most of the time this works, but sometimes there is a very small difference in the x, y values.

{0.03`, 0.03`}
{0.030000000000000002`, 0.030000000000000002`}

I consider these equal.

Any suggestions on a way to do a “Complement[]” with a custom definition of equality?
POSTED BY: Jeff Burns
3 Replies
@Bill Simpson  In fact it is sufficient to use SameTest -> Equal or even SameTest -> SameQ, as I describe in the linked post, but this will make the complexity of Comlement O(n^2), significantly slowing it down.   The unexpected thing is precisely that the default SameTest is not equivalent to SameTest -> SameQ
POSTED BY: Szabolcs Horvát
Here's a very closely related problem:

I'd say this behaviour is a borderline-bug, though fixing it might noticeably reduce the performance of some functions.
POSTED BY: Szabolcs Horvát
Posted 11 years ago
In[1]:= Complement[{0.03`, 0.030000000000000002`}, {0.03`, 0.03`}, {0.030000000000000002`, 0.030000000000000002`}]

Out[1]= {}
Perhaps a specific example that fails might help track this down.

In the help system, hidden behind the Details and Options tab, that seems so often to be overlooked, it says

   Complement[Subscript[e, all],Subscript[e, 1],..,SameTest->test]

so you can craft your own specific test to be anything you want.

Unfortunately it doesn't seem to give a nice example showing the syntax of a SameTest.
POSTED BY: Bill Simpson
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract