Using ReplaceAll (/.) with complex variables?

I have hopefully a simple question. (I’m using home version of Mathematica 7)

If define a simple complex matrix

test = {{a + Ib, b + Ic}, {d + Ie, e + If}}

and do a simple replacement

test /. {e -> 1, f -> 2}

How come the complex parts using the symbols e and f are not replaced? The above yields

{{a + Ib, b + Ic}, {d + Ie, 1 + If}}

If I do something simple

test2 = a + I b

test2 /. {a -> 4, b -> 2}

Yields: 4 + 2 I

as expected, but if I call up the [[2,2]] element of the array above and try the ReplaceAll it doesn’t work

test6 = test[[2, 2]]

Yields: e + If

but

test6 /. {e -> 3, f -> 5}    

Yields: 3 + If

So how come the complex part doesn’t get replaced? How can I do this replacement?

Hint:

Ie

is a single symbol.

I*e

or

I e

is the product of two things.

2I

or

2*I

or

2 I

also happen to be the product of two things.

That should be enough.

You could’ve noticed it from the coloring already; unknown symbols are blue (or green inside e.g. Module) (a,b,c,d,e,f), known symbols are black (I)…

Note that you can’t use replace(all) on complex numbers:

3 + 4 I /. 4 -> 5

as they are treated as an ‘atom’, so it will just return 3 + 4I.

This is not the whole story. ReplaceAll (and related functions) use the FullForm for pattern matching, and to replace a part of the complex number one needs to use this form. It is true that 3 + 4 I is atomic but one may use the head of this expression to get into its parts

FullForm[3 + 4 I]

returns

Complex[3,4]

therefore

3+ 4 I /. Complex[x_,4]:> Complex[x,12]

returns

3 + 12 I

as expected

Thanks Bill, for some reason I thought that I was reserved, so Ie and If would be a product to two things.

Sorry about the coloring, don’t really know how that happened. a,b,c,d,e,f were suppose to be unknown symbols.

Your thinking that I is reserved is correct, but that isn’t sufficient to override the principle that anything beginning with a letter followed by any number of letters and digits will be considered to be one symbol. This kind of problem shows up again and again and again and again…

Without any disrespect, whats the fuzz? The OP’s replacements does seem to work (provided there is a space left between I and the variable symbol):

In[1]:= test = {{a + I b, b + I c}, {d + I e, e + I f}}

Out[1]= {{a + I b, b + I c}, {d + I e, e + I f}}

In[2]:= test /. {e -> 1, f -> 2}

Out[2]= {{a + I b, b + I c}, {I + d, 1 + 2 I}}

Because you wrote it correctly. Compare the inputs (and the coloring).

{{a + Ib, b + Ic}, {d + Ie, e + If}}
{{a + I b, b + I c}, {d + I e, e + I f}}

That is not your fault, that is caused because you need a space between symbols:

If
Ie

versus

I f
I e