RE: Re: Loss of precision when using Simplify
- To: mathgroup at smc.vnet.net
- Subject: [mg36995] RE: [mg36958] Re: [mg36925] Loss of precision when using Simplify
- From: "DrBob" <drbob at bigfoot.com>
- Date: Fri, 4 Oct 2002 05:01:45 -0400 (EDT)
- Reply-to: <drbob at bigfoot.com>
- Sender: owner-wri-mathgroup at wolfram.com
I get a somewhat different answer with the same function: CW[n_] := Coefficient[Simplify[1.001`17 + Sum[(x[i] - 1.001`17)/2^i, {i, \ n}]], x[1]] Split[CW /@ Range[100]] {{1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2}, {0.5`12.3085, 0.5`12.0074, 0.5`11.7064, 0.5`11.4054, 0.5`11.1043, 0.5`10.8033, 0.5`10.5023, 0.5`10.2012, 0.5`9.9002, 0.5`9.5992, 0.5`9.2982, 0.5`8.9971, 0.5`8.6961, 0.5`8.3951, 0.5`8.094, 0.5`7.793, 0.5`7.492, 0.5`7.1909, 0.5`6.8899, 0.5`6.5889, 0.5`6.2879, 0.5`5.9868, 0.5`5.6858, 0.5`5.3848, 0.5`5.0837, 0.5`4.7827, 0.5`4.4817, 0.5`4.1806, 0.5`3.8796, 0.5`3.5786, 0.5`3.2776, 0.5`2.9765, 0.5`2.6755, 0.5`2.3745, 0.5`2.3745, 0.5`1.7724, 0.5`1.7724, 0.5`1.1703, 0.5`1.1703, 0.5`0.5683, 0.5`0.2673, 0.5`0.2673}, {0.125`0.2673}, {1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2}} Notice the split was different than yours. Bobby -----Original Message----- From: Andrzej Kozlowski [mailto:andrzej at platon.c.u-tokyo.ac.jp] To: mathgroup at smc.vnet.net Subject: [mg36995] [mg36958] Re: [mg36925] Loss of precision when using Simplify Dear Carl You have discovered what is perhaps a bug but maybe something even mor einteresting . However, I think you stopped your investigation a little prematurely. Here is a function that just computes the coefficient of x[1] in your Simplified expression for various values of n: CW[n_] := Coefficient[Simplify[1.001`17 + Sum[(x[i] - 1.001`17)/2^i, {i, \ n}]], x[1]] Now lets try CW for the first 100 values of n: In[30]:= Table[CW[n], {n, 100}] Out[30]= {1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 0.5`12.3085, 0.5`12.0074, 0.5`11.7064, 0.5`11.4054, 0.5`11.1043, 0.5`10.8033, 0.5`10.5023, 0.5`10.2012, 0.5`9.9002, 0.5`9.5992, 0.5`9.2982, 0.5`8.9971, 0.5`8.6961, 0.5`8.3951, 0.5`8.094, 0.5`7.793, 0.5`7.492, 0.5`7.1909, 0.5`6.8899, 0.5`6.5889, 0.5`6.2879, 0.5`5.9868, 0.5`5.6858, 0.5`5.3848, 0.5`5.0837, 0.5`4.7827, 0.5`4.4817, 0.5`4.1806, 0.5`3.8796, 0.5`3.5786, 0.5`3.2776, 0.5`2.9765, 0.5`2.6755, 0.5`2.3745, 0.5`2.3745, 0.5`1.7724, 0.5`1.7724, 0.5`1.1703, 0.5`1.1703, 0.5`0.5683, 0``0.1423, 0``0.1423, 0``0.1423, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2} In[31]:= Map[Length,Split[#]] Out[31]= {12,43,45} This is indeed curious.The problem seems to occur for values between 13 and 55 and then go away (for good???) At first I thought it maybe in some fascinating way related to some properties of the integer n, but now I am not sure. It certainly worth a careful examination. I hope whoever discovers the cause of this will let us know. Andrzej Andrzej Kozlowski Yokohama, Japan http://www.mimuw.edu.pl/~akoz/ http://platon.c.u-tokyo.ac.jp/andrzej/ On Wednesday, October 2, 2002, at 04:32 PM, Carl K. Woll wrote: > 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] > > > > > > >