0
$\begingroup$

I have an expression:

a + b 2^(1/2) + (c + d 2^(1/2))*I

I want to replace each occurrence of 2^(1/2) with -2^(1/2) and each occurrence of I with -I. So I input:

a + b 2^(1/2) + (c + d 2^(1/2)) I /. {2^(1/2) -> -2^(1/2), I -> (-I)}

Mathematica returns:

(* a - Sqrt[2] b - I (c - Sqrt[2] d) *)

as I expected.

Now I want to make the same replacement again on this expression. So I input:

a + b 2^(1/2) + (c + d 2^(1/2)) I /. {2^(1/2) -> -2^(1/2), 
  I -> (-I)}/. {2^(1/2) -> -2^(1/2), I -> (-I)}

Mathematica returns:

(*a + Sqrt[2] b - I (c + Sqrt[2] d) *)

I do not expect the MINUS sign in the middle of this expression. It seems like it should be PLUS.?

$\endgroup$
  • 1
    $\begingroup$ Please format your code. Edit your post and apply the {} button where needed. $\endgroup$ – Edmund Dec 29 '15 at 18:11
  • $\begingroup$ Perhaps a + b 2^(1/2) + (c + d 2^(1/2)) I /. {2^(1/2) -> (-2)^(1/2), I -> (-I)} $\endgroup$ – Dr. belisarius Dec 29 '15 at 18:15
  • 2
    $\begingroup$ This is a common problem with replacing complex numbers, and it is has been answered before. In the second replacement, try Complex[0, -1] -> I. $\endgroup$ – march Dec 29 '15 at 18:24
  • 5
    $\begingroup$ See this or this other or this third $\endgroup$ – Daniel Lichtblau Dec 29 '15 at 18:36
  • 1
    $\begingroup$ more generally ` c_Complex:> Conjugate[c] ` ( which is in Daniels third link.. ) $\endgroup$ – george2079 Dec 29 '15 at 19:10