I define three points (xia,yia,zia,xib...), the vectors xab,yab,zab,xcb.. , the distances rab2 and rcb2, the dot product, the angle a-b-c and then the energy of bending the angle - e. I take the derivative of e with respect to xia and I get a long output in terms of xia-xib, xic-xib and so on. I want to condense the output by using all the previous defines. I normally would do this by hand doing string replacements in emacs. Tedious and error prone. Is there a command or script that will do the back substitution. Simplify dies with out of memory errors and is not really what I am trying to do. I had the same problem in Mathmatica and never found a good solution.