Re: avoiding non-machine numbers
- To: mathgroup at smc.vnet.net
- Subject: [mg115760] Re: avoiding non-machine numbers
- From: wpb <wicher.bergsma at gmail.com>
- Date: Thu, 20 Jan 2011 06:28:30 -0500 (EST)
- References: <ih164u$jd2$1@smc.vnet.net>
On Jan 17, 10:37 am, DrMajorBob <btre... at austin.rr.com> wrote: > The difference could be 4GB of RAM here, speed of the hard drive, other = > applications running... who knows? > > Bobby > > On Sun, 16 Jan 2011 04:53:51 -0600, Achilleas Lazarides > > > > > > > > <achilleas.lazari... at gmx.com> wrote: > > Strange, I just tried again and got the same answer: > > In[9]:= Exp[-#^2] &@ > > RandomReal[NormalDistribution[0, 20], 400000]; // Timing > > switchCatchUnderflow[]; > > Exp[-#^2] &@RandomReal[NormalDistribution[0, 20], 400000]; // Timing > > switchCatchUnderflow[]; > > $Version > > > Out[9]= {1.66873, Null} > > > Out[11]= {0.130301, Null} > > > Out[13]= "8.0 for Mac OS X x86 (64-bit) (November 6, 2010)" > > > No difference after quitting and restarting the kernel etc. > > > On Jan15, 2011, at 9:07 PM, DrMajorBob wrote: > > >> It made far less difference here: > > >> switchCatchUnderflow[] := (SetSystemOptions[ > >> CatchMachineUnderflow -> #1] &)[! CatchMachineUnderflow /. > >> SystemOptions[CatchMachineUnderflow]] > > >> Exp[-#^2] &@RandomReal[NormalDistribution[0, 20], 400000]; // Timing > >> switchCatchUnderflow[]; > >> Exp[-#^2] &@RandomReal[NormalDistribution[0, 20], 400000]; // Timing > > >> {1.54747, Null} > > >> {1.4913, Null} > > >> $Version > > >> "8.0 for Mac OS X x86 (64-bit) (November 6, 2010)" > > >> Bobby > > >> On Sat, 15 Jan 2011 03:47:22 -0600, Achilleas Lazarides > >> <achilleas.lazari... at gmx.com> wrote: > > >>> I have this in my init.m: > > >>> switchCatchUnderflow[]:==(SetSystemOptions[CatchMachineUnderflow-= >#1]&)[!CatchMachineUnderflow/.SystemOptions[CatchMachineUnderflow]] > > >>> which flips the option indicated. I get: > > >>> In[65]:== Exp[-#^2] &@ > >>> RandomReal[NormalDistribution[0, 20], 400000]; // Timing > >>> switchCatchUnderflow[]; > >>> Exp[-#^2] &@RandomReal[NormalDistribution[0, 20], 400000]; // Timing > > >>> Out[65]== {1.62773, Null} > > >>> Out[67]== {0.12662, Null} > > >>> On Jan14, 2011, at 12:17 PM, wpb wrote: > > >>>> t == RandomReal[NormalDistribution[0, 20], 400000]; > >>>> Exp[-t^2]; // Timing > > >> -- > >> DrMajor... at yahoo.com > > -- > DrMajor... at yahoo.com Ah, googling "CatchMachineUnderflow" I found a 2006 mathgroup post from which I derived the following perfect solution: SetSystemOptions["CatchMachineUnderflow" -> False] This doesn't cause any slowdown if there is no underflow. (So, the Wolfram people have already solved it properly, my request of the previous message is not needed.) Here is how it works out for me: In[64]:= SetSystemOptions["CatchMachineUnderflow" -> True]; (*default setting*) Exp[-#^2] &@RandomReal[NormalDistribution[0, 20], 400000]; // Timing SetSystemOptions["CatchMachineUnderflow" -> False]; Exp[-#^2] &@RandomReal[NormalDistribution[0, 20], 400000]; // Timing Out[64]= {1.265, Null} Out[66]= {0.047, Null} However, it seems hard/impossible to find this out from the Mathematica documentation. Thanks all for the contributions, Wicher