9

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!

mmal
  • 3,508
  • 2
  • 18
  • 38
Andrei
  • 901
  • 5
  • 17

3 Answers3

6

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}
bill s
  • 68,936
  • 4
  • 101
  • 191
2

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.

Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371
2

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.

amr
  • 5,487
  • 1
  • 22
  • 32