MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Confusing results with N[expr]?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg62412] Re: Confusing results with N[expr]?
  • From: Bill Rowe <readnewsciv at earthlink.net>
  • 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[1]:= $Version

>Out[1]= 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[2]:= Map[f, a^b]

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

>In[3]:= f /@ a^b

>Out[3]=
>  b
>a

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

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

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

>In[5]:= f //@ a^b

>Out[5]=
>     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[1]:=Hold[f/@a^b]//FullForm

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

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

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

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

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

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

Out[4]//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]?