RE: Chop? Programming Challenge!!

• To: mathgroup at smc.vnet.net
• Subject: [mg23046] RE: [mg23007] Chop? Programming Challenge!!
• From: Russell Towle <rustybel at foothill.net>
• Date: Thu, 13 Apr 2000 02:43:30 -0400 (EDT)
• References: <200004120318.XAA04724@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```Hi David,

>the tolerance for Chop is 10^-10.
>
>So why don't you use Chop[expression, 10^-6]?

Many thanks to those who promptly informed me of how to use Chop. I didn't
posted to the Group.

I routinely use Chop to look at lists of numbers and vectors. Perhaps it is
a coincidence, but only after going to version 4.01 did I see Chop return a
list with numbers in scientific notation. The very same notebooks in which
no problem arose under version 4.00 are now failing under version 4.01.

All my numbers are machine precision. Perhaps there is some setting in the
Options Inspector which allows machine precision numbers to bleed into
spurious higher precision and fool plain old Chop-with-one-argument.

As an example of a function which worked perfectly under version 4.00, but
now sometimes fails under version 4.01, I offer this, called 'vunion', for
'vector union'. It finds the Union of a list of n-dimensional vectors. I
offer as a programming challenge, to construct a faster vector union
function, which is as unfailingly accurate as this one was, and now is
again, once Chop has been given its second argument. Let the function
operate upon machine-precision n-vectors. It is important to devise lists
for testing, in which two vectors, actually the same, appear to differ,
with changes in sign for numbers which Chop to 0. Let the lists contain
1000 vectors, which after Union reduce to 350 or so.

(*****)
(* 2.2 to 4.0 version of vunion*)

vunion::usage = "vunion[v] returns the union of a list of n-vectors.";

vunion[v_]:=
Union[Chop[v],
SameTest->((Sign[#1]==Sign[#2]) &&
( Chop[#1-#2]==Table[0,{Length[ v[[1]] ]}] ) &)]

(*****)
(* 4.01 version of vunion*)

vunion::usage = "vunion[v] returns the union of a list of n-vectors.";

vunion[v_]:=
Union[Chop[v, .000001],
SameTest->((Sign[#1]==Sign[#2]) &&
( Chop[#1-#2, .000001]==Table[0,{Length[ v[[1]] ]}] ) &)]

Russell Towle
Box 141
Dutch Flat, CA 95714
(530) 389-2872

```

• References:
• Chop?
• From: Russell Towle <rustybel@foothill.net>
• Prev by Date: RE: Mesh
• Next by Date: Re: Chop?