Services & Resources / Wolfram Forums / MathGroup Archive
-----

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: [mg126273] Re: Distinquishing #'s in nested pure functions
  • From: Bill Rowe <readnews at sbcglobal.net>
  • Date: Sat, 28 Apr 2012 05:26:09 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com

On 4/27/12 at 6:48 AM, dsnead6 at charter.net (Dave Snead) wrote:

>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?

Did you try your example above? Did it work as you wanted? The
most efficient way to answer questions of the form "Can
Mathematica ... ?" is to try it.

If you try you I expect you to get an empty list as a result no
regardless of the contents of the list you give to Select to
select from.

Since you use parenthesis you are telling Mathematica to
evaluate the Map operation for every item in the list. That
operation will always return {0,0,0} since each both slots (#)
are filled with the the same element of the list f[#,#]& is
mapped to.

This result ({0,0,0}) is compared to {3,4,5} and found not
equal. So, for every element of the list you supply to Select,
the selection function returns False and no element is ever selected.

To see that things work as I've described above do

Trace[Select[{1, 2, 3}, (f[#, #] & /@ {-1, -2, -3}) == {3, 4, 5} &]]//TableForm




  • Prev by Date: Re: Distinquishing #'s in nested pure functions
  • Next by Date: Re: LinearModelFit doesn't work with constraints?
  • Previous by thread: Re: Question about Integration and citation
  • Next by thread: Black box optimization