# How do I use Replace All? [duplicate]

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 b - I (c - Sqrt 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 b - I (c + Sqrt d) *)


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

• Please format your code. Edit your post and apply the {} button where needed. – Edmund Dec 29 '15 at 18:11
• Perhaps a + b 2^(1/2) + (c + d 2^(1/2)) I /. {2^(1/2) -> (-2)^(1/2), I -> (-I)} – Dr. belisarius Dec 29 '15 at 18:15
• 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. – march Dec 29 '15 at 18:24
• See this or this other or this third – Daniel Lichtblau Dec 29 '15 at 18:36
• more generally  c_Complex:> Conjugate[c]  ( which is in Daniels third link.. ) – george2079 Dec 29 '15 at 19:10