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


Groups > comp.soft-sys.math.mathematica > #14433 > unrolled thread

Re: Listable Attribute of Pure Function that returns a

Started byAlex Krasnov <akrasnov@eecs.berkeley.edu>
First post2013-05-07 07:53 +0000
Last post2013-05-07 07:53 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.soft-sys.math.mathematica

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Listable Attribute of Pure Function that returns a Alex Krasnov <akrasnov@eecs.berkeley.edu> - 2013-05-07 07:53 +0000

#14433 — Re: Listable Attribute of Pure Function that returns a

FromAlex Krasnov <akrasnov@eecs.berkeley.edu>
Date2013-05-07 07:53 +0000
SubjectRe: Listable Attribute of Pure Function that returns a
Message-ID<kmabtk$qd8$1@smc.vnet.net>
On Mon, 6 May 2013, Dan O'Brien wrote:

> Now, I do the same but instead I define a pure function
> In[37]:= ClearAll[func]
> SetAttributes[func, Listable]
> func = {{#1, #2}, {#3, #4}} &;
> func[a, b, c, Array[d, 4]]
>
> Out[40]= {{a, b}, {c, {d[1], d[2], d[3], d[4]}}}
>
> Clearly this is not behaving as a listable function, its simply
> substituting the list of d's for the 4th argument.

In my understanding, pure functions with anonymous parameters do not 
support attributes. Pure functions with named parameters do as follows:

In:	Function[{a, b, c, d}, {{a, b}, {c, d}}, Listable][a, b, c, Array[d, 4]]
Out:	{{{a, b}, {c, d[1]}}, {{a, b}, {c, d[2]}}, {{a, b}, {c, d[3]}}, {{a, b}, {c, d[4]}}}

> If I do the same for a pure function that does not return a list,
> everything is fine:
>
> In[42]:= ClearAll[func2]
> SetAttributes[func2, Listable]
> func2 = (#1 + #2)/(#3 - #4) &
> func2[a, b, c, Array[d, 4]]
>
> Out[44]= (#1 + #2)/(#3 - #4) &
>
> Out[45]= {(a + b)/(c - d[1]), (a + b)/(c - d[2]), (a + b)/(
>  c - d[3]), (a + b)/(c - d[4])}
>
> And in any case, mathematica behaves the same here if I don't do
> anything with the Attributes of func2, that is, there is no need to
> explicitly SetAttributes to Listable for this particular example.

In this case, func2 is not Listable, but Plus, Minus, Divide are.

Alex

[toc] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web