# Map over list of functions

I would like to convert a list of $n$ complex equations to a list of $2n$ real ones. At the moment I am doing it like this:

eqs = {a + I b == 0, c + I d == 0}
Flatten[{ComplexExpand[Re[First[#]]] == 0 & /@ eqs,
ComplexExpand[Im[First[#]]] == 0 & /@ eqs}]


I would like to know how I can write this more compactly, since I'm basically using the same command twice, with the only difference being changing the function Re -> Im. Perhaps I can use a pure function to map over a list of these 2 functions?

Thanks!

• Equal[#, 0] & /@ {Re@#, Im@#} & /@ First /@ eqs Jan 8, 2013 at 18:52
• @belisarius you forgot ComplexExpand. Jan 8, 2013 at 22:33
• @Mr.Wizard One more item for the list I'm sowing thru my life Jan 8, 2013 at 22:35

I would probably do something like this:

eqs = {a + I b == 0, c + I d == 0};

Join @@ Thread /@ ComplexExpand @ Map[{Re@#, Im@#} &, eqs, {2}]

{a == 0, b == 0, c == 0, d == 0}


Or shorter:

Join @@ ComplexExpand[Map[#, eqs, {2}] & /@ {Re, Im}]

{a == 0, c == 0, b == 0, d == 0}


The order is slightly different, if it matters.

This seems like a good place for Through, since it can take multiple functions (like Im and Re) and apply them to the same arguments, so for example,

Through[{Re, Im}[a + b I]]

{-Im[b] + Re[a], Im[a] + Re[b]}


For the specific problem at hand, this can be done

eqs = {a + I b == 0, c + I d == 0};
Join@@Thread/@(ComplexExpand@Through[{Re, Im}[First[#]]] == {0, 0} & /@ eqs)

{a == 0, b == 0, c == 0, d == 0}


Using Outer:

eqs = {a + I b == 0, c + I d == 0};
Flatten@Outer[
ComplexExpand[#1[#2]] == 0 &,
{Re, Im}, {First /@ eqs}]


Might have to specify the level in the general case.