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


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

Re: Distinquishing #'s in nested pure functions

From Bob Hanlon <hanlonr357@gmail.com>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Distinquishing #'s in nested pure functions
Date 2012-04-28 09:31 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <jngdd4$p0$1@smc.vnet.net> (permalink)
References <201204260933.FAA05752@smc.vnet.net>

Show all headers | View raw


f[x_, y_] := x - y

f[x, y] // FullForm

Plus[x,Times[-1,y]]

Plus is Listable, e.g.,

f[2, {-1, -2, -3}]

{3, 4, 5}

Consequently, the Map is not necessary

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

{2}

However, often it is necessary to use a helper function to avoid
ambiguity, e.g.,

g[x_] := f[x, {-1, -2, -3}]

Select[{1, 2, 3}, g[#] == {3, 4, 5} &]

{2}


Bob Hanlon


On Fri, Apr 27, 2012 at 6:48 AM, Dave Snead <dsnead6@charter.net> wrote:
> 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?
>
> Thanks in advance,
> Dave Snead
>

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


Thread

Re: Distinquishing #'s in nested pure functions Bob Hanlon <hanlonr357@gmail.com> - 2012-04-28 09:31 +0000

csiph-web