I have a function taking a function as input as well as other values, e.g.
f2[f_, a_, b_, c_, d_] = f[{a, b}, c, d];
Of course, the behavior differs for f1 being Listable or not. So if I define
f1[x_, y_, z_] = If[x > 0, x*y + z, -x + y + z]
it will yield
In= Attributes[f1] = {};f2[f1, 1, 2, 3, 4]
Out= If[{1, 2} > 0, {1, 2} 3 + 4, -{1, 2} + 3 + 4]
in contrast to
In= SetAttributes[f1, Listable]; f2[f1, 1, 2, 3, 4]
Out= {7, 10}
.
Now my question is: can I implement that f2 will always treat the given input function as Listable? So that I don't have to explicitely give the Attribute to the input function beforehand and still get the listable-ish output (in this case {7,10}.
I was trying
f3[f_, a_, b_, c_, d_] = Assuming[Element[Listable, Attributes[f]], f[{a, b}, c, d]];
but this behaves exactly like f2.
(Of course, in this simple case, I could map over the list {a,b} but let's assume this is not possible or not convenient.)
Thread?Listableis just an automaticThread.f3[f_, a_, b_, c_, d_] = Thread[f[{a, b}, c, d]];– vapor Mar 10 '17 at 14:48Threaddidn't work in a similar though slightly different context – riddleculous Mar 10 '17 at 14:53Threaddoes not work? – vapor Mar 10 '17 at 16:17a,b,c,darguments? Can they be lists themselves? Do you wantffunction to thread them simultaneously with list you create inf2body? Explicit mapping is safest in this respect, since it won't accidentally thread where you don't want it. – jkuczm Mar 11 '17 at 09:21#1, #2, etc) and it simply got too complicated to do the mapping in the right order. – riddleculous Mar 11 '17 at 09:44{a,b}is actuall explicitely given in the definition off2as{"T","S"}. – riddleculous Mar 11 '17 at 09:49ListableQis not useful in your use case. It would be if you'd have large numeric lists over which you'd like listable function to map, then adding top levelListableattribute could spoil performance of built-in listable functions. – jkuczm Mar 11 '17 at 15:22