32
$\begingroup$

Bug introduced in 9.0 and fixed in 10.0.0


It is not surprising that DeleteDuplicates[{5,5.}] returns {5,5.} because DeleteDuplicates uses SameQ by default, and SameQ[5,5.] is False.

However, Equal[5,5.] is True, but DeleteDuplicates[{5,5.},Equal] still returns {5,5.}.

It is interesting to note that Union works properly, in that Union[{5,5.},SameTest->Equal] returns {5}, as expected.

Is this a bug, or am I missing something? I'm using version 9.

Update:

I realize that using the function #1==#2& will get it working, thanks for pointing this out.

However, my question really is "Is this a bug, or am I missing something?".

To illustrate this further, consider the following:

f[x__]:=Equal[x]
DeleteDuplicates[{5,5.},f]
(* {5} *)

In what capacity are f and Equal different? Or what is leading DeleteDuplicates to treat them differently? They both take an arbitrary number of inputs, which is what I originally thought was the problem.

$\endgroup$
15
  • 6
    $\begingroup$ I'm reporting this as a bug. $\endgroup$ Jan 23, 2013 at 17:24
  • 5
    $\begingroup$ But @Albert Retey, are you saying that you won't believe me in a comment, but you will in an answer? $\endgroup$ Jan 23, 2013 at 17:40
  • 6
    $\begingroup$ ... it might also be of interest that this behavior is new to version 9, version 7 and 8 give the "expected" result... $\endgroup$ Jan 23, 2013 at 17:41
  • 2
    $\begingroup$ (Sigh) @Albert Retey, I forgot your country of origin... $\endgroup$ Jan 23, 2013 at 17:44
  • 14
    $\begingroup$ Meta question: If this question ever gets a duplicate, will we be able to delete it? $\endgroup$ Jan 23, 2013 at 18:27

2 Answers 2

19
$\begingroup$

As @Albert Retey remarked in a comment, a second argument of (just) Equal leads to a special case handler that, to me, seems overly ambitious. I reported it as a bug.

$\endgroup$
3
  • $\begingroup$ +1 but... raking in rep for confirming bugs may be the wrong incentive, WRI-wise? :-P $\endgroup$
    – Yves Klett
    Jan 24, 2013 at 9:58
  • 2
    $\begingroup$ My strategy has been to fix bugs/implement features, remain silent for weeks/months, and then miss the rep uptick when the new version ships because sleep started to look better than beating out intrepid explorers for reputation. Maybe I should rethink that... :) $\endgroup$
    – John Fultz
    Jan 24, 2013 at 11:37
  • 1
    $\begingroup$ @Yves Klett I'm as confused as you. Meanwhile other responses take real work and get maybe 2 upvotes. $\endgroup$ Jan 24, 2013 at 15:13
9
$\begingroup$

You need to use :

DeleteDuplicates[{5, 5.}, Equal[#1, #2] &]
(* {5} *)
$\endgroup$
1
  • 1
    $\begingroup$ Something like Unevaluated@Identity@Equal will work a bit faster I think $\endgroup$
    – Rojo
    Jan 23, 2013 at 22:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.