For example how can I write
In:
pureFunctionSyntax[myF] /@ {7, 3}
Out:
{myF[7, Log[7]], myF[3, Log[3]]}
Mathematica Stack Exchange is a question and answer site for users of Wolfram Mathematica. It only takes a minute to sign up.
Sign up to join this communityFor example how can I write
In:
pureFunctionSyntax[myF] /@ {7, 3}
Out:
{myF[7, Log[7]], myF[3, Log[3]]}
Imo the most common/readable/flexible way:
Function[h, h[#, Log[#]] &][myF] /@ {7, 3}
and for fun, less general, as pointed in comments:
Through@*#[Identity, Log] &[myF] /@ {7, 3}
which can be even shorter, thanks to ybeltukov
Through@*#[# &, Log] &[myF] /@ {7, 3}
Through@*#[# &, Log] &
.
$\endgroup$
– ybeltukov
Nov 18 '15 at 17:10
myF
has a definition. For example Through@*#[Identity, Log] &[f[#1] + #2 &] /@ {7, 3}
outputs {Log[7] + f[Identity][7], Log[3] + f[Identity][3]}
not {f[7] + Log[7], f[3] + Log[3]}
.
$\endgroup$
– user
Nov 18 '15 at 21:19
Yes, you can use only pure functions:
f = ## &[#, Log@#] & /* # &;
f[myF] /@ {7, 3}
(* {myF[7, Log[7]], myF[3, Log[3]]} *)
It can be shorter with a bit different syntax:
g = ## &[#, Log@#] &;
g /* myF /@ {7, 3}
(* {myF[7, Log[7]], myF[3, Log[3]]} *)
I like this syntax:
In:
f[#, Log[#]] & /. f -> # &[myF] /@ {7, 3}
Out:
{myF[7, Log[7]], myF[3, Log[3]]}