6

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?
orome
  • 12,819
  • 3
  • 52
  • 100

1 Answers1

7

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.

Andy Ross
  • 19,320
  • 2
  • 61
  • 93
  • 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]]]; – novice May 07 '13 at 05:33
  • @novice this is a very good question that I don't immediately know the answer to. I suggest posting it as a question. – Andy Ross May 07 '13 at 14:00