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?

  • 3
    $\begingroup$ 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. $\endgroup$
    – Xerxes
    Feb 26, 2013 at 1:24

1 Answer 1

(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 *)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.