Re: Troubling Bug involving RandomReal, NestList, and Table
- To: mathgroup at smc.vnet.net
- Subject: [mg86249] Re: Troubling Bug involving RandomReal, NestList, and Table
- From: Mark Fisher <particlefilter at gmail.com>
- Date: Fri, 7 Mar 2008 02:25:06 -0500 (EST)
- References: <fqo8tn$t2o$1@smc.vnet.net>
On Mar 6, 3:10 am, "jwmerr... at gmail.com" <jwmerr... at gmail.com> wrote: > When making tables of 250 or more directions, Mathematica seems to > forget how to do arithmetic. I realize these "random" directions are > not properly uniform, but that's beside the point. > > $Version > > > "6.0 for Mac OS X x86 (32-bit) (April 20, 2007)" > > randomDirection3[] := > NestList[Sqrt[1 - #^2] &, RandomReal[], 1] > > ListPlot[Table[randomDirection3[], {249}], AspectRatio -> Automatic] > ListPlot[Table[randomDirection3[], {250}], AspectRatio -> Automatic] > > > [Graphs you'll need to generate for yourself] > > Variance[Table[Norm[randomDirection3[]], {249}]] > Variance[Table[Norm[randomDirection3[]], {250}]] > > > 1.49104*10^-33 > > 0.0513843 > > What!?! > > Jason Merrill This is bad. It looks to me like the bug is located in compiling randomDirection3. (I'm guessing Table compiles its first argument when the length of the list is 250 or greater.) Consider this: rd = Compile[{}, NestList[Sqrt[1 - #^2] &, RandomReal[], 1]] rd[] returns a pair of numbers that don't lie on the unit circle. I'm using 6.0.1. Does anyone know if this is fixed in 6.0.2? Hey Dan and Rob! What gives? --Mark