Quantcast
Channel: Applying several functions to the same argument - Mathematica Stack Exchange
Viewing all articles
Browse latest Browse all 7

Answer by E. Chan-López for Applying several functions to the same argument

$
0
0

A dirty alternative:

ComapApplyPureFunction[funcs_?VectorQ, pf_Function] := Module[{strpf},strpf = StringDelete[ToString[pf], "&"];ToExpression[#1 <> #2 & @@@ Thread[{ToString@#2@#1 & @@@ Thread[{strpf, ToString /@ funcs}], Array["&" &, Length@funcs]}]]]

Testing ComapApplyPureFunction:

ComapApplyPureFunction[{f1, f2}, Exponent[#, Variables[expr]] &](*{f1[Exponent[#1, Variables[expr]]] &, f2[Exponent[#1, Variables[expr]]] &}*)

Addendum:

Perhaps using Function instead of an anonymous function will allow you to implement what you are looking for in a more concise way. The following example can be useful:

expr = x^2 + 2  x + 1;With[{f1 = #^2 &, f2 = #^3 &}, ReleaseHold@#2@#1 & @@@ Thread[{HoldForm[Function[x, Exponent[x, Variables[x]]]@expr], {f1, f2}}]](*{{4}, {8}}*)

Viewing all articles
Browse latest Browse all 7

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>