The failsafe command Edit does not get enough emphasis in the Mathematica literature. This command guarantees that Mathematica is never worse than a yellow pad. Whenever you have an expression ’expr’ and the functions at your disposal are not doing what you want just enter
In[102]:=Edit[expr]
|
Mathematica throws you into a file containing expr. You can edit it with the vi or emacs editor or whatever is set up. Then exiting the file throws your edited expression into the Out[102] (see above). A truly remarkable feature is that
YOU CAN EDIT Mathematica FUNCTIONS (INCLUDING NCAlgebra FUNCTIONS) INTO EXPR, APPLYING DIFFERENT FUNCTIONS TO DIFFERENT PARTS OF EXPR, then these are automatically executed when you finish editing the file. A tutorial example of this extremely powerful feature is
Out[32]= x**y + x**z + x**y**x
In[33]:= Edit[%] |
A new screen comes up and you can use your resident editor on it.
x**y + x**z + x**y**x
|
I usually make another copy of the expression for safety sake and make edits on one of them, while commenting out the second so it does not get read by Mathematica. This way if I make errors, I still have the original expression to fall back on and check with. This is especially useful when dealing with complicated expressions. For example, you could write
NCCollect[x ** y + x ** z,x] + x ** y **x;
(* x**y + x**z + x**y**x *) |
Now quit editing and close the file, (e.g., :wq for vi).
Out[33]: x ** (y + z) + x ** y ** x
|