Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.



RE: [mg23007] Chop? Programming Challenge!!
Posted:
Apr 13, 2000 3:08 AM


Hi David,
>Did I miss something in your posting? If you check Help you will see that >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 realize that Chop had a second argument until about one minute after I had 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 Chopwithoneargument.
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 ndimensional 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 machineprecision nvectors. 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 nvectors.";
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 nvectors.";
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) 3892872



