I would like to apply a list of functions to an expression, like
ApplyList[{Re, Im}, Exp[I x]] = {Cos[x], Sin[x]}
How do I do that?
Answer
thru1 = Assuming[Element[x, Reals], Simplify @ Through @ {Re, Im} @ ComplexExpand@#]&;
thru1 @ Exp[ I x]
(* {Cos[x], Sin[x]} *)
Or
thru2 = Composition[Assuming[Element[x, Reals], Simplify@#] &,
Through@{Re, Im}@# &, ComplexExpand];
thru2 @ Exp[I x]
(* {Cos[x], Sin[x]} *)
Or
thru3 = Fold[#2[#] &, Exp[I x],
{ComplexExpand, Through@{Re, Im}@# &, Assuming[Element[x, Reals], Simplify@#] &}];
thru3 @ Exp[I x]
(* {Cos[x], Sin[x]} *)
Comments
Post a Comment