Chop and smoothing

by Rolf Sulanke

August 16, 2006

Summary

This notebook discusses the relation between Chop and smoothing and indicates an error met applying Chop. I used Mathematica v.3 and v.4 .

Address:

Rolf.Sulanke@mathematik.hu-berlin.de
Homepage:
http://www2.mathematik.hu-berlin.de/~sulanke/

For comments, hints,  and corrections the author will be very thankful.

1. Definition of smoothing

The following function has been defined in my package euvec.m, see MathSource, item Spheres; it makes an almost zero  number to be zero; the sensibility can be regulated by the optional second argument, whose default value is (10^(-10)):

smoothing[a_,b_:10^(-10)]:=Module[{c=a},If[b== 1,Return[c],If[Abs[c]<b,c=0]];c];Attributes[smoothing]=Listable;

smoothing::usage="smoothing[a, b] is a listable function setting small (a<b: 10^-10) arguments a to zero; for b = 1 the argument a is returned: smoothing[a, 1] = a."

2. Chop and smoothing

??Chop

In spite of the fact that the attribute Listable is not reported, Chop seems to have this attribute. Therefore instead of smoothing we could have used Chop[a, b]. The behavior of smoothing differs from that of Chop; for our purposes smoothing is more appropriate, since it evaluates more expressions.

Chop[N[Exp[-40]]]

Chop[{N[Exp[-40]], N[Exp[-35]]}]

Chop[{N[Exp[-40]], Exp[-35]}]

Chop[{N[I*Exp[-40]], Exp[-35]}]

Chop[{N[Exp[-40]],I*Exp[-35]}]

In the next example Chop produces a false result; since t may be complex, the argument should have been returned:

Chop[N[Pi*10^(-19)]*Cos[t]]

N[Pi*10^(-19)]*Cos[I*100.]

In difference to Chop smoothing evaluates the inserted expressions correctly:

smoothing[{N[Exp[-40]], Exp[-35]}]

smoothing[{N[I*Exp[-40]], Exp[-35]}]

smoothing[{N[Exp[-40]],I*Exp[-35]}]

smoothing[N[Pi*10^(-19)]*Cos[t]]

smoothing[N[Pi*10^(-19)]*I]

Wolfram's answer

The examples from Wolfram's answer:

Chop[1.7+0.0 I]

smoothing[1.7+0.0 I]

Abs[%]< 10^(-10)

Abs[1.7+0.0 I]

expr=1+0.0t+t^2+0.0t^3+t^4;
Chop[expr]

smoothing[expr]

0.`< 10^(-10)

The "smoothing" function ]is a qualitatively different function than Chop,and so would not be a viable replacement for Chop. These examples show the intended behavior of Chop. If there is enough interest,we may consider adding a function like "smoothing" for some future version of Mathematica.
Dave Withoff
Wolfram Research

Final remark

Indeed, Chop seems to act on any floating point numbers contained in expr, while smoothing acts on the value of Abs[expr] :

Exp[N[2 Pi I]]

Re[%]

Im[%%]

smoothing[Exp[N[2 Pi I]]]

Chop[Exp[N[2 Pi I]]]

Dave seems not to consider the fact that

Chop[N[Pi*10^(-19)]*Cos[t]]

leads to the error  e.g. N[Pi*10^(-19)]*Cos[I*100.] = 0, while

N[Pi*10^(-19)]*Cos[I*100.]

Thus, we are justified to the following

WARNING: Applying Chop may cause serious errors!