tags:

views:

249

answers:

2

When I write out a proof or derivation on paper I frequently make sign errors or drop terms as I move from one step to the next. I'd like to use Mathematica to save myself from these silly mistakes. I don't want Mathematica to solve the expression, I just want to use it carry out and display a series of algebraic manipulations. For a (trivial) example

In[111]:= MultBothSides[Equal[a_, b_], c_] := Equal[c a, c b];

In[112]:= expression = 2 a == a b

Out[112]= 2 a == a b

In[113]:= MultBothSides[expression, 1/a]

Out[113]= 2 == b

Can anyone point me to a package that would support this kind of manipulation?

Edit

Thanks for the input, not quite what I'm looking for though. The symbol manipulation isn't really the problem. I'm really looking for something that will make explicit the algebraic or mathematical justification of each step of a derivation. My goal here is really pedagogical.

+1  A: 

I don't think you need a package. What you want to do is to manipulate each formula according to an inference rule. In MMa, you can model inference rules on a formula using transformations. So, if you have a formula f, you can apply an inference rule I by executing (my MMa syntax is 15 years rusty)

f ./ I

to produce the next formula in your sequence.

MMa will of course try to simplify your formulas if they contain standard algebraic operators and terms, such as constant numbers and arithmetic operators. You can prevent MMa from applying its own "inference" rules by enclosing your formula in a Hold[...] form.

Ira Baxter
+1  A: 

Mathematica also provides a number of high-level functions for manipulating algebraic. Among these are Expand, Apart and Together, and Cancel, though there are quite a few more.

Also, for your specific example of applying the same transformation to both sides of an equation (that is, and expression with the head Equal), you can use the Thread function, which works just like your MultBothSides function, but with a great deal more generality.

In[1]:=  expression = 2 a == a b
Out[1]:= 2 a == a b

In[2]:=  Thread[expression /a, Equal]
Out[2]:= 2 == b

In[3]:=  Thread[expression - c, Equal]
Out[3]:= 2 a - c == a b - c


In either of the presented solutions, it should be relatively easy to see what the step entailed. If you want something a little more explicit, you can write your own function like so:

In[4]:=  ApplyToBothSides[f_, eq_Equal] := Map[f, eq]

In[5]:=  ApplyToBothSides[4 * #&, expression]
Out[5]:= 8 a == 4 a b

It's a generalization of your MultBothSides function that takes advantage of the fact that Map works on expressions with any head, not just head List. If you're trying to communicate with an audience that is unfamiliar with Mathematica, using these sorts of names can help you communicate more clearly. In a related vein, if you want to use replacement rules as suggested by Ira Baxter, it may be helpful to write out Replace or ReplaceAll instead of using the /. syntactic sugar.

In[6]:=  ReplaceAll[expression, a -> (x + y)]
Out[6]:= 2 (x + y) == b (x + y)

If you think it would be clearer to have the actual equation, instead of the variable name expression, in your input, and you're using the notebook interface, highlight the word expression with your mouse, call up the contextual menu, and select "Evaluate in Place".

The notebook interface is also a very pleasant environment for doing "literate programming", so you can also explain any steps that are not immediately obvious in words. I believe this is a good practice when writing mathematical proofs regardless of the medium.

Pillsy
Thanks for your answer. I was hoping a canned package along these lines already existed, but the point you make will help me get started on my own package.
Charles E. Grant