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 MathematicaAlternatives 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.