MathGroup Archive 2012

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

Search the Archive

Re: Distinquishing #'s in nested pure functions

  • To: mathgroup at smc.vnet.net
  • Subject: [mg126280] Re: Distinquishing #'s in nested pure functions
  • From: A Retey <awnl at gmx-topmail.de>
  • Date: Sat, 28 Apr 2012 05:28:35 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <201204260933.FAA05752@smc.vnet.net> <jndtj1$jit$1@smc.vnet.net>

Hi,

> Is there a way to distinguish the #'s in nested pure functions?
>
> As a simple example:
>
> f[x_, y_] := x - y
>
> Select[{1, 2, 3}, (f[#, #]&  /@ {-1, -2, -3}) == {3, 4, 5}&]
>
> I want the 1st # to correspond with the outer&  (the equal)
> and the 2nd # with the inner&  (the map)
> The answer in this example should by {2}
> (of course, the statement as written above does not do the job)
>
> Can Mathematica distinguish these #'s?

it often does the right thing, but of course there are ambiguities which 
just can't be resolved. What you'd usually do is to use pure functions 
with named arguments, which will resolve these ambiguities. You probably 
should note that the notation with # and & is just a shortcut for 
Function. Look up the documentation of Function for more details. Here 
is an example:

Select[{1, 2, 3},
  Function[outerarg,
   Function[innerarg, f[outerarg, innerarg]] /@ {-1, -2, -3} == {3,
     4, 5}]]

That's of course somewhat more verbose, but you can of course also mix 
those with the shortcut notation, e.g.:

Select[{1, 2, 3},
  Function[outerarg, f[outerarg, #] & /@ {-1, -2, -3} == {3, 4, 5}]]


hth,

albert



  • Prev by Date: Re: from a 2d-figure to an interactive 3d model? is it possible with mathematica?
  • Next by Date: Re: Distinquishing #'s in nested pure functions
  • Previous by thread: Re: Distinquishing #'s in nested pure functions
  • Next by thread: Integration bug? Integrate[Sin[2 t]^2 Cos[Cos[t - p]], {t, 0, 2 Pi}]