I understand that I can use Chop to force a very small number to be treated as 0 and can use PossibleZeroQ to as a way to test whether such a number might effectively be 0, but applying Chop every time a small number is close to zero in order to "make it be" zero is tedious and error prone; while PossibleZeroQ seems to have its own ideas about what constitutes 0.

Are there global settings that will let me

  • treat every number smaller than some specified value as 0, effectively applying Chop automatically to all results; and
  • specify how large a number PossibleZeroQ should recognize as 0?
  • $\begingroup$ There is a system option controlling the maximum difference when treating close inexact numbers as equal. But I can't find it now ... should be somewhere in SystemOptions $\endgroup$
    – Szabolcs
    Nov 13 '12 at 18:59
  • $\begingroup$ @Szabolcs and raxa: you're probably looking for Internal`$EqualTolerance. $\endgroup$
    – rm -rf
    Nov 13 '12 at 19:11
  • $\begingroup$ @rm-rf: That looks interesting. There's no help on it though, and its value (2.10721) is cryptic. $\endgroup$
    – orome
    Nov 13 '12 at 19:16
  • 4
    $\begingroup$ Regarding the first point: What about $Post=Chop? $\endgroup$
    – sebhofer
    Nov 13 '12 at 19:30
  • 2
    $\begingroup$ And note that Chop can tale a second argument specifying the tolerance. So you might want to use something like $Post = Chop[#, 10^-13]&. $\endgroup$
    – murray
    Nov 13 '12 at 22:04

As was pointed out in the comments, $Post is a way to go here. Take as an example:

FourierDCT[FourierDCT[{0, 0, 1, 0, 0}, 2], 3]

(*{0., -5.55112*10^-17, 1., 1.38778*10^-17, 1.38778*10^-17}*)

Now lets set $Post to Chop with tolerance 10^-13.

$Post = Chop[#, 10^-13] &;

This will apply the Chop function to every output thereafter.

FourierDCT[FourierDCT[{0, 0, 1, 0, 0}, 2], 3]

(*{0, 0, 1., 0, 0}*)

If you want to make this behavior semi-permanent, you can set $Post in any one of your init.m files. A good choice might be the one located at

$InstallationDirectory <> "\\SystemFiles\\Kernel\\Packages\\init.m"

If you do this and want to not Chop for a particular output you can always clear $Post or remove this from init.m and restart the kernel.

  • $\begingroup$ Andy Ross ,Does $Post = Chop[#, 10^-13] &; really take away the digits smaller than 10^-13? I find that those digits still exist by Print[MatrixForm[FourierDCT[FourierDCT[{0, 0, 1, 0, 0}, 2], 3]]]; $\endgroup$
    – novice
    May 7 '13 at 5:33
  • $\begingroup$ @novice this is a very good question that I don't immediately know the answer to. I suggest posting it as a question. $\endgroup$
    – Andy Ross
    May 7 '13 at 14:00

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.