# Using transformation rules to manipulate expressions

I'm trying out Mathematica as a replacement for LaTeX for typesetting math. It works very well, but I would like to take advantage of Mathematica's computer algebra capabilities as well. Specifically, instead of manually figuring out and typing the result of a transformation to an expression, I would like Mathematica to do it.

For example, suppose I am trying to prove that associativity of multiplication holds in the complex numbers. The first step might be the following:

(a+bi)((c+di)(e+fi)) = (a+bi)(ce + cfi + edi - df)


How can I automate this using transformation rules? I can do the following:

In:  (a+bi)((c+di)(e+fi)) /. x_*(y_*z_)->x+y+z
Out: a + bi + c + di + e + fi


which works as expected, so the pattern is matching properly (I've tried various other simple transformations as well). However, the following does not work as expected:

In:  (a+bi)((c+di)(e+fi)) /. x_*(y_*z_)->x*(Expand[y*z])
Out: (a+bi)(c+di)(e+fi)


What am I missing? Am I even on the right track, or is there a better way to accomplish this?

-
Mathematica already knows a lot about parentheses and multiplication, so I would be very wary of using actual parentheses and multiplication for this project. You're likely to trigger simplifications without realizing it. I would instead specify new functions paren and mult that look like parentheses and multiplication, but will not be treated as such by Mathematica. Then you can build up whatever transformations you want. –  Xerxes Feb 26 '13 at 1:24

(a+bi)((c+di)(e+fi)) /. x_*(y_*z_):>x*(Expand[y*z])
(* (a + bi) (c e + di e + c fi + di fi) *)


Check RuleDelayed in docs

x_*(y_*z_) :> x*(Expand[y*z])
x_*(y_*z_) -> x*(Expand[y*z])

(* x_ y_ z_ :> x Expand[y z] *)
(* x_ y_ z_ -> x y z *)

-