       Re: Confusing results with N[expr]?

• To: mathgroup at smc.vnet.net
• Subject: [mg62412] Re: Confusing results with N[expr]?
• Date: Wed, 23 Nov 2005 01:13:03 -0500 (EST)
• Sender: owner-wri-mathgroup at wolfram.com

```On 11/22/05 at 4:41 AM, Steven.Hancock at cern.ch (Steven HANCOCK)
wrote:

>There may be a clue in the following, equally distressing
>nonsense...

>In:= \$Version

>Out= 5.1 for Microsoft Windows (October 25, 2004)

>(* Map[f, expr] or f /@ expr applies f to each element on the first
>level in expr. *)

>In:= Map[f, a^b]

>Out=
>     f[b]
>f[a]

>In:= f /@ a^b

>Out=
>  b
>a

>(* MapAll[f, expr] or f //@ expr applies f to every subexpression
>in expr. *)

>In:= MapAll[f, a^b]

>Out=
>       f[b]
>f[f[a]    ]

>In:= f //@ a^b

>Out=
>     b
>f[a]

The issues above with Map and MapAll is simply an operator precedence issue. The expression f/@a^b can be taken as either f/@(a^b) or (f/@a)^b. Likewise, the expression f//@a^b can be taken as (f//@a)^b or f//@(a^b). In both cases, Mathematica applies the operators in the order in which they appear.

But the precendence with either Map[f, a^b] or MapAll[f, a^b] is different. This grouping makes it clear Power is to be done first.

The following shows more clearly this is what is occurring

In:=Hold[f/@a^b]//FullForm

Out//FullForm=
Hold[Power[Map[f,a],b]]

In:=Hold[Map[f,a^b]]//FullForm

Out//FullForm=
Hold[Map[f,Power[a,b]]]

In:=Hold[f//@a^b]//FullForm

Out//FullForm=
Hold[Power[MapAll[f,a],b]]

In:=Hold[MapAll[f,a^b]]//FullForm

Out//FullForm=
Hold[MapAll[f,Power[a,b]]]
--
To reply via email subtract one hundred and four

```

• Prev by Date: Re: Re: How to View Mathematica and Hardcopy Books
• Next by Date: Re: Re: How to read a data file in text format?_from a new learner
• Previous by thread: Re: Confusing results with N[expr]?
• Next by thread: Re: Confusing results with N[expr]?