Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #9843

Re: Distinquishing #'s in nested pure functions

From Bill Rowe <readnews@sbcglobal.net>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Distinquishing #'s in nested pure functions
Date 2012-04-28 09:28 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <jngd7c$n2$1@smc.vnet.net> (permalink)

Show all headers | View raw


On 4/27/12 at 6:48 AM, dsnead6@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

Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread


Thread

Re: Distinquishing #'s in nested pure functions Bill Rowe <readnews@sbcglobal.net> - 2012-04-28 09:28 +0000

csiph-web