       Re: Complement replacement

• To: mathgroup at smc.vnet.net
• Subject: [mg58617] Re: [mg58608] Complement replacement
• From: Andrzej Kozlowski <akozlowski at gmail.com>
• Date: Sun, 10 Jul 2005 16:51:35 -0400 (EDT)
• References: <200507100912.FAA06500@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```On 10 Jul 2005, at 18:12, konstantpi at mail15.com wrote:

> hi
> in the list:
> pp=Table[Random[Integer, {1, 1000}], {i, 1000}];
> how could i know which numbers from 1 to 1000 does not exist in the
> pp List.
> but without using:
> Complement[Table[i,{i,1000}],pp]
> regards
>
>

Perhaps you should explain why you do not want to use Complement as
it will be very hard if not impossible to match its performance.
Indeed, on ny machine I get:

In:=
pp=Table[Random[Integer, {1, 1000}], {i, 1000}];

In:=
a=Complement[Range,pp];//Timing

Out=
{0.001657 Second,Null}

while using the most obvious alternative:

In:=
b=Select[Range,Not[MemberQ[pp,#]]&];//Timing

Out=
{0.408538 Second,Null}

In:=
Union[b]==a

Out=
True

The difference in performance is huge. There are a number of ways
that give a better performance but I can't find any that beets
Complement. Here s one that is at least better than the most obvious
way above. First define a function f:

SetAttributes[f, Listable]

Scan[(f[#]=Sequence[])&,pp];//Timing

{0.020849 Second,Null}

f[x_] := x

(note that evaluating this defintion itself takes more time than
running Complement)

now:

In:=
c=f[Range];//Timing

Out=
{0.008274 Second,Null}

In:=
Union[c]==a

Out=
True

Andrzej Kozlowski

Chiba, Japan

```

• Prev by Date: Re: Complement replacement
• Next by Date: Re: SeedRandom and \$SessionID
• Previous by thread: Re: Complement replacement
• Next by thread: Re: Complement replacement