I generate very long and complex analytic expressions of the general form:
(...something not so complex...)(...ditto...)(...ditto...)...lots...
When I try to use Simplify, Mathematica grinds to a halt, I am assuming due to the fact that it tries to expand the brackets and or simplify across different brackets. The brackets, while containing long expressions, are easily simplified by Mathematica on their own. Is there some way I can limit the scope of Simplify to a single bracket at a time?
Edit: Some additional info and progress.
So using the advice from you guys I have now started using something in the vein of
In[1]:= trouble = Log[(x + I y) (x - I y) + Sqrt[(a + I b) (a - I b)]];
In[2]:= Replace[trouble, form_ /; (Head[form] == Times) :> Simplify[form],{3}]
Out[2]= Log[Sqrt[a^2 + b^2] + (x - I y) (x + I y)]
Changing Times to an appropriate head like Plus or Power makes it possible to target the simplification quite accurately. The problem / question that remains, though, is the following: Simplify will still descend deeper than the level specified to Replace, e.g.
In[3]:= Replace[trouble, form_ /; (Head[form] == Plus) :> Simplify[form], {1}]
Out[3]= Log[Sqrt[a^2 + b^2] + x^2 + y^2]
simplifies the square root as well.
My plan was to iteratively use Replace from the bottom up one level at a time, but this clearly will result in vast amount of repeated work by Simplify and ultimately result in the exact same bogging down of Mathematica I experienced in the outset. Is there a way to restrict Simplify to a certain level(s)?
I realize that this sort of restriction may not produce optimal results, but the idea here is getting something that is “good enough”.
There are a number of ways you can do this, but it can be a little tricky and depends on the structure of your actual expression. However, usually a product of a number of terms in brackets will have the head
Times, and you can useFullFormto verify this:You can use the higher-order function
Mapwith expressions with headTimesthe same way you use it with expressions with headList, and that may allow you toSimplifythe expression one term at a time, like so:You can use
Expandon the result if you need to subsequently expand out the brackets.EDIT to add: If you want to specify the forms that you do want to simplify, you can use
ReplaceorReplaceAllinstead of one of the relatives ofMap.Replaceis particularly useful because it takes a level specification, allowing you to only affect the factors in the topmost product. As a simple example, consider the following:If you don’t want to simplify factors that depend on
a. you can do this instead:Only the second term, which depends on
b, has been changed. One thing to bear in mind though is that some transformations are done automatically byTimesorPlus; for instancea + awill be turned into2 aeven without use ofSimplify.