MathGroup Archive 1997

[Date Index] [Thread Index] [Author Index]

Search the Archive

UnsameQ implementation

  • To: mathgroup at smc.vnet.net
  • Subject: [mg8129] UnsameQ implementation
  • From: "C. Woll" <carlw at u.washington.edu>
  • Date: Tue, 12 Aug 1997 00:55:09 -0400
  • Sender: owner-wri-mathgroup at wolfram.com

Hi,

The function UnsameQ gives true if all of its arguments are pairwise
distinct. The following function also gives true if all of its arguments
are pairwise distinct

DistinctQ[a__]:=Length[Union[{a}]]===Length[{a}]

Now, let's consider a test of these two functions.

test = Table[i[Random[Integer,10000]],{10000}];
utest= Union[test];

Applying the above functions yields

UnsameQ@@test//Timing
DistinctQ@@test//Timing

{0. Second, False}
{0.06 Second, False}

UnsameQ@@utest//Timing
DistinctQ@@utest//Timing

{0.4 Second, True}
{0.02 Second, True}

Notice that for utest, DistinctQ is much faster than the built in
function UnsameQ.

For a list which contains duplicates, it's not surprising that UnsameQ is
much faster, since it terminates as soon as a duplicate is found. But why
is UnsameQ so slow when given a list with no duplicates? 

Although this isn't a bug, it seems to me that UnsameQ should be
implemented so that it's at least as fast as DistinctQ above. Will this be
looked at in future versions of Mathematica?

Carl Woll
Physics Dept
U of Washington

License L2514-7296




  • Prev by Date: Net Confiruation on NT
  • Next by Date: Threading objects of unequal length
  • Previous by thread: Net Confiruation on NT
  • Next by thread: Re: UnsameQ implementation