A minimum example is this:
ls = {1 + I, 2 - I};
Max@Re[ls]
Min@Im[ls]
#[ls] & /@ {Max@Re, Min@Im} (*want {2, -1}*)
The result is:
{{1, 2}, {1, -1}}
I don't know why is this..
For a minimal change in your code, you can replace @
with Composition (@*)
#[ls] & /@ {Max@*Re, Min@*Im}
{2, -1}
Consider also Through
:
Through @ {Max @* Re, Min @* Im} @ ls
{2, -1}
Aside: Why your code gives {{1, 2}, {1, -1}}
:
Trace[#[ls] & /@ {Max@Re, Min@Im}] // Column
Notice that Max@Re
is replaced with Re
and Min@Im
is replaced with Im
in the very first step of evaluation.
Max@Re[ls] Min@Im[ls]
work as expected but not work when using Apply
?
$\endgroup$
Apr 8, 2020 at 3:56
{{1, 2}, {1, -1}}
if you use {Max@Re, Min@Im}
instead of {Max@*Re, Min@*Im}
or {Max@Re@#&, Min@Im@#&}
$\endgroup$
Map[{Max[Re[#]], Min[Im[#]]} &, ls, {0}]
Gives
{2, -1}
From help on Map
Level 0 corresponds to the whole expression.
ls = {1 + I, 2 - I};
Using Comap
(new in 14.0)
Comap[{Max @* Re, Min @* Im}] @ ls
{2, -1}
ls = {1 + I, 2 - I};
Query[{Max @* Re, Min @* Im}] @ ls
{2, -1}
ls = {1 + I, 2 - I};
Another way using Thread
:
Last@Activate@#1@#2 & @@@ Thread[{{Max@Re, Min@Im}, Inactive[ls]}]
Result:
{2, -1}
@
does not denote function composition. It denotes function applications.f@g[x]
is not(f@g)[x]
butf@(g[x])
, merely a different notation forf[g[x]]
. $\endgroup${Max@Re[#], Min@Im@#} &@ls
applying your function tols
instead of mapping it. $\endgroup$Max[Re[ls]]
gives just a number, why need composite? AlsoMax@Re[ls]
gives a number $\endgroup$