I would like to have a test that determines if a particular function is Listable. In the case of Symbols this is merely a matter of checking Attributes
. Function
definitions with the Listable
attribute are a bit more involved but quite easy.
However I specifically want to test for inherent listability in as many cases as possible.
For example consider the function from Case #4 in Alternatives to procedural loops and iterating over lists in Mathematica:
(3 - #)/(7 * #) &
This function is inherently listable:
fn = (3 - #)/(7*#) &;
Map[fn, {1, 2, 3}]
fn @ {1, 2, 3}
{2/7, 1/14, 0} {2/7, 1/14, 0}
One must consider Functions with multiple arguments, both the
Slot
and named parameter type.Ideally the test would handle pattern-based (DownValues) functions to the extent that is possible.
{3, 4, {1,2}}
? Then, listablef
, gives{f[3], f[4], {f[1], f[2]}}
. So, while(3 - #)/(7 #)&
is inherently listable, I don't think it is completely listable. So,ListableQ
will have some limitations. $\endgroup$/
is a listable binary operator so it works out fine since both arguments will have the same shape. $\endgroup$