# Making pure functions listable [closed]

I have a very large number of functions defined in the following manner:

f[1] = Function[{x}, x^2];

f[2] = Function[{x}, x^3];


I would like to make all of these Listable. Is there any simple way of doing this? I have tried:

Attributes[f[2]] = {Listable};


and

SetAttributes[f[2],Listable];


both of which failed miserably!

Thanks!

• AppendTo[f[1], Listable]? – Carl Woll May 3 '17 at 23:13
• Your functions (at least those you have as your examples) are already Listable, because Power operation maintains listability. Moreover, if you give them explicit Listable attribute, you will only make matters worse. Read this. – Leonid Shifrin May 3 '17 at 23:14
• My actual functions are way more complicated, this was just an example to see if this is possible. – user12588 May 3 '17 at 23:17
• Try this f[1] = Function[{x}, x^2]; f[2] = Function[{x}, x^3]; SetAttributes[f, Listable]; f[{1, 2}] but I doubt this is what you really want to do. – Bill May 3 '17 at 23:18
• What @CarlWoll suggested may be a bit hard to understand, but he meant this: f[1] = Function[{x}, x^2, Listable]. Pure functions can have a subset of symbol attributes (including Listable), and then you specify them as a third optional argument to Function. Still, read the link I provided, to not run into nasty performance surprises. Because adding Listable attribute won't make the performance better, but can easily make it worse, so adding it for performance reasons doesn't make much sense, and can be counterproductive. – Leonid Shifrin May 3 '17 at 23:20