Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

share|improve this question
3  
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
add comment

1 Answer 1

up vote 2 down vote accepted
(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 *)
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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