       Re: Confusing results with N[expr]?

• To: mathgroup at smc.vnet.net
• Subject: [mg62430] Re: Confusing results with N[expr]?
• From: marks at wolfram.com
• Date: Thu, 24 Nov 2005 06:33:27 -0500 (EST)
• References: <dlp320\$1bs\$1@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```This is a bug in NValues that has been fixed in our development
version.

Generally N works adaptively for arbitrary precision so that
when you given an input like Exp[1/1000] the function is
capable enough to know that the argument should be evaluated
to a given Accuracy in order to obtain the requested Precision
in the result.

For example:

In:= Exp[0.001``10]

Out= 1.001000500

In:= Precision[%]

Out= 10.

If Precision were used in coercing the argument, then the Precision
of the result would be too large (resulting in excessive intermediary
work):

In:= Exp[0.001`10]

Out= 1.001000500167

In:= Precision[%]

Out= 13.

Now when working with machine precision, only machine numbers
are used, but the code for NValues was not taking this into account.

A simple workaround is to add the second line here to map Accuracy to
Precision for NValues with MachinePrecision.

In:= N[a] = 2.;

In:= N[a, {Infinity, MachinePrecision}]:= N[a, {MachinePrecision,
Infinity}];

In:= k = z^(a*Pi);

In:= N[k]

6.28319
Out= z

Similarly this fix works for converting arguments to Exp:

In:= N[a] = 2.;

In:= N[a, {Infinity, MachinePrecision}]:= N[a, {MachinePrecision,
Infinity}];

In:= N[Exp[z a Pi]]

6.28319 z
Out= 2.71828

Mark Sofroniou
Research and Development
Wolfram Research

Thomas Bohl wrote:
> I have the impression that since some time (since Vers. 5.0?) N[expr] does
> not give anymore the results I expect.
>
> The following code should illustrate this:
>
> N[a] = 2.;
>
> k = z*(a*Pi);
> N[k]
> > 6.28319 z       (* "a" and "Pi" are replaced by their numerical value as
> > expected *)
>
> k = z^(a*Pi)
> N[k]
> > z^(3.14159 a)    (* "Pi" is replaced by its numerical value but not "a",
> > why not? *)
>
>
> There are more examples of this behaviour: If the expression is Log[z*a*Pi],
> the numerical values of "a" and "Pi" are evaluated, if the expression is
> Exp[z*a*Pi] the numerical value of "a" is not evaluated. Why not?
>
> The motivation behind my question is that I was used to write expressions
> symbolically and assign numerical values with N[expr] = num. value. This way
> you could keep those expressions symbolically and just apply //N when you
> needed numerical values. Now it seems that I have lost this possibility.
>
> Could you please comment my observation and maybe suggest a way out?
>
> Thank you very much for any idea.
>
> Kind regards,
> Thomas.

```

• Prev by Date: Re: Time needed for calculation
• Next by Date: Re: Timing of looping operators
• Previous by thread: Re: Confusing results with N[expr]?
• Next by thread: Re: Random Normal deviates within compiled function?