Skip to main content
replaced http://mathematica.stackexchange.com/ with https://mathematica.stackexchange.com/
Source Link

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.

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.

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.

Tweeted twitter.com/#!/StackMma/status/374189047717322752
Source Link
Mr.Wizard
  • 273.1k
  • 34
  • 595
  • 1.4k

How can one write a robust ListableQ function?

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.