Loss of precision when using Simplify

• To: mathgroup at smc.vnet.net
• Subject: [mg36925] Loss of precision when using Simplify
• From: "Carl K. Woll" <carlw at u.washington.edu>
• Date: Wed, 2 Oct 2002 03:32:09 -0400 (EDT)
• Organization: University of Washington
• Sender: owner-wri-mathgroup at wolfram.com

```To Technical Support and the Mathematica User community,

I'm writing to report what I consider to be a bug. First, I want to show a
simplified example of the problem. Consider the following expression:

expr=0.22 + x[0] + (3*(-0.16+ x[1]))/4 + (9*(0.546 + x[2]))/16;

When simplified I expected to get some real number plus
x[0]+3x[1]/4+9x[2]/16, but instead I get the following:

Simplify[expr]
0.407125 + x[0] + 0.75 x[1] + 0.5625 x[2]

As you can see, for some reason Mathematica converted the fractions 3/4 and
9/16 to real machine numbers. I consider this to be a bug.

Now, for an example more representative of the situation that I've been
coming across.

expr12 = 1.001`17 + Sum[(x[i] - 1.001`17)/2^i, {i, 12}];
expr13 = 1.001`17 + Sum[(x[i] - 1.001`17)/2^i, {i, 13}];
expr55 = 1.001`17 + Sum[(x[i] - 1.001`17)/2^i, {i, 55}];

As you can see, I have replaced the real numbers by extended precision
numbers. The simplified example above demonstrates that the problem exists
when using machine numbers. Now, we'll see what happens when we use
arbitrary precision numbers. First, let's simplify the expression with 12
terms.

Simplify[expr12]
(1.0010000000000 + 2048 x[1] + 1024 x[2] + 512 x[3] + 256 x[4] + 128 x[5] +

64 x[6] + 32 x[7] + 16 x[8] + 8 x[9] + 4 x[10] + 2 x[11] + x[12]) / 4096

As you can see, a sum with 12 terms upon simplification has coefficients
which are still integers as they should be. However, increasing the number
of terms to 13 yields

Simplify[expr13]
0.0001221923828125 + 0.500000000000 x[1] + 0.250000000000 x[2] +

0.1250000000000 x[3] + 0.0625000000000 x[4] + 0.0312500000000 x[5] +

0.01562500000000 x[6] + 0.00781250000000 x[7] + 0.00390625000000 x[8] +

0.001953125000000 x[9] + 0.000976562500000 x[10] + 0.000488281250000 x[11]
+

0.000244140625000 x[12] + 0.0001220703125000 x[13]

Now, all of the coefficients are converted to real numbers, replicating the
bug from the simplified example. Finally, let's see what happens when we
have 55 terms. Rather than putting the resulting expression here, I will
just leave it at the end of the post. The result though is somewhat
surprising. Each of the coefficients of the x[i] are again real numbers, but
now their precision is only 0! The proper result of course is the sum of
some real number (with a precision close to 0 due to numerical cancellation)
and an expression consisting of rational numbers multiplied by x[i]. The
loss of precision of the coefficients of the x[i] is precisely what occurred
to me. Of course, in this simple example, simply using Expand instead of
Simplify produces the expected result, and is my workaround. I hope you
agree with me that this is a bug, and one that Wolfram needs to correct.

Carl Woll
Physics Dept
U of Washington

Simplify[expr55]
-16                            -1             -1             -1
0. 10    + 0. x[1] + 0. x[2] + 0. 10   x[3] + 0. 10   x[4] + 0. 10   x[5] +

-2             -2             -2             -3             -3
0. 10   x[6] + 0. 10   x[7] + 0. 10   x[8] + 0. 10   x[9] + 0. 10   x[10]
+

-3              -3              -4              -4              -4
0. 10   x[11] + 0. 10   x[12] + 0. 10   x[13] + 0. 10   x[14] + 0. 10
x[15] +

-5              -5              -5              -6              -6
0. 10   x[16] + 0. 10   x[17] + 0. 10   x[18] + 0. 10   x[19] + 0. 10
x[20] +

-6              -6              -7              -7              -7
0. 10   x[21] + 0. 10   x[22] + 0. 10   x[23] + 0. 10   x[24] + 0. 10
x[25] +

-8              -8              -8              -9              -9
0. 10   x[26] + 0. 10   x[27] + 0. 10   x[28] + 0. 10   x[29] + 0. 10
x[30] +

-9              -9              -10              -10
0. 10   x[31] + 0. 10   x[32] + 0. 10    x[33] + 0. 10    x[34] +

-10              -11              -11              -11
0. 10    x[35] + 0. 10    x[36] + 0. 10    x[37] + 0. 10    x[38] +

-12              -12              -12              -12
0. 10    x[39] + 0. 10    x[40] + 0. 10    x[41] + 0. 10    x[42] +

-13              -13              -13              -14
0. 10    x[43] + 0. 10    x[44] + 0. 10    x[45] + 0. 10    x[46] +

-14              -14              -15              -15
0. 10    x[47] + 0. 10    x[48] + 0. 10    x[49] + 0. 10    x[50] +

-15              -15              -16              -16              -
16
0. 10    x[51] + 0. 10    x[52] + 0. 10    x[53] + 0. 10    x[54] + 0. 10
x[55]

```

• Prev by Date: Re: RE: Real Time Animation
• Next by Date: RE: Accuracy and Precision
• Previous by thread: Re: Choosing between Mathematica for Windows and Linux
• Next by thread: Re: Loss of precision when using Simplify