Re: avoiding non-machine numbers
- To: mathgroup at smc.vnet.net
- Subject: [mg115593] Re: avoiding non-machine numbers
- From: "Rolf.Mertig at gmail.com" <rolf.mertig at gmail.com>
- Date: Sun, 16 Jan 2011 05:50:33 -0500 (EST)
- References: <igpbd4$fae$1@smc.vnet.net>
Compile seems sufficiently fast:
In[7]:=
fun = Compile[{{n, _Integer}}, Module[{t},
t = RandomReal[NormalDistribution[0, 20], n]; Exp[-t^2]]];
Timing[re = fun[400000];Min[re] ]
Out[8]= {0.094,0.}
Rolf
--
GluonVision GmbH
http://www.gluonvision.com
Berlin, Germany
On Jan 14, 12:17 pm, wpb <wicher.berg... at gmail.com> wrote:
> By default, Mathematica switches to non-machine numbers when needed,
> eg,
>
> In[4334]:= Exp[-50.^2]
>
> Out[4334]= 1.835672669162*10^-1086
>
> But this has a severe possible drawback in terms of computational
> speed. For example, the following is very quick
>
> In[4420]:= t = RandomReal[NormalDistribution[0, .1], 400000];
> Exp[-t^2]; // Timing
>
> Out[4421]= {0., Null}
>
> but in the following computation non-machine numbers are generated,
> and we get an enormous decrease in speed:
>
> In[4422]:= t = RandomReal[NormalDistribution[0, 20], 400000];
> Exp[-t^2]; // Timing
>
> Out[4423]= {1.25, Null}
>
> So is it possible to get a computation such as Exp[-50.^2] to evaluate
> to zero in a very fast way? That is, that small numbers outside
> machine-precision range evaluate to zero automatically?
>
> Thanks, Wicher