6
$\begingroup$

When FullSimplify invoked on a large expression, it can run for hours. If I do not have time to wait, and abort the evaluation, I get no result, although, conceivably, some forms simpler than the initial argument have been found already.

Is it possible to create a version of FullSimplify that can display the simplest form found so far in a temporary cell, and return it if the evaluation is aborted?

$\endgroup$
0

2 Answers 2

6
$\begingroup$

The only method I can think of that will use the built-in simplification routines is to snoop on transformations using either TransformationFunctions or ComplexityFunction. Unfortunately neither of these will be restricted to the entire expression therefore what is produced may not be usable. Nevertheless as an example:

FullSimplify[Gamma[1 - x] Gamma[x] Sin[Pi x], 
 TransformationFunctions -> {Automatic, (Print[#]; #) &}]
During evaluation of In[2]:= Gamma[1-x] Gamma[x] Sin[π x]

During evaluation of In[2]:= Gamma[1-x]

During evaluation of In[2]:= 1-x

During evaluation of In[2]:= -x

During evaluation of In[2]:= -x

During evaluation of In[2]:= Gamma[x]

During evaluation of In[2]:= Sin[π x]

During evaluation of In[2]:= π/2-π x

During evaluation of In[2]:= π-2 π x

During evaluation of In[2]:= -2 π x

During evaluation of In[2]:= 1/2 (π-2 π x)

During evaluation of In[2]:= π x

During evaluation of In[2]:= Gamma[1-x] Gamma[x] Sin[π x]

π

Notes:

For ComplexityFunction one would use e.g. ComplexityFunction -> ((Print[#]; LeafCount[#]) &).

It may be necessary to use ClearSystemCache[] beforehand to see the steps shown as otherwise the final simplified version may be pulled from cache.

$\endgroup$
1
  • $\begingroup$ Nice trick. I can use this for tracing also, should be useful. $\endgroup$
    – Nasser
    Commented Dec 5, 2013 at 19:27
5
$\begingroup$

Maybe TimeConstraint is helpful:

y = Gamma[1 - x] Gamma[x] Sin[Pi x] + Gamma[x] Gamma[1 - x] Sin[Pi (1 - x)];
FullSimplify[y, TimeConstraint -> 0.000001]
FullSimplify[y, TimeConstraint -> 0.0001]
FullSimplify[y, TimeConstraint -> 0.01]
Gamma[1 - x] Gamma[x] Sin[π (1 - x)] + Gamma[1 - x] Gamma[x] Sin[π x]
2 Gamma[1 - x] Gamma[x] Sin[π x]
2 π
$\endgroup$
5
  • $\begingroup$ Does reentering the simplification process using the intermediate expression work the same way as continued simplification? I assumed that it did not, and many things that were already tried would be inefficiently tried again, but perhaps with caching this is not an issue. Do you have experience with this? $\endgroup$
    – Mr.Wizard
    Commented Dec 6, 2013 at 0:24
  • $\begingroup$ @Mr.Wizard It is just examples! I propose very simple idea: use one FullSimplify with an appropriate TimeConstraint (e.g. 5 min). $\endgroup$
    – ybeltukov
    Commented Dec 6, 2013 at 0:28
  • $\begingroup$ I don't know if you understood my question. I think I understand what you are proposing, and it seems good, however my concern is this: will using FullSimplify with a TimeConstraint of five minutes, then again for another five minutes starting with the output from the first run be as efficient as running it for ten minutes to begin with? If it is there is no reason to do anything else. However if it is not one would prefer to let the simplification run uninterrupted and somehow monitor progress. $\endgroup$
    – Mr.Wizard
    Commented Dec 6, 2013 at 0:32
  • $\begingroup$ Suppose for example that the expression was very hard to simplify and that after five minutes the original expression was returned. Would repeatedly running the process again (with the five minute limitation each time) produce anything other than the original, or would caching occur and eventually a simpler expression would be found? $\endgroup$
    – Mr.Wizard
    Commented Dec 6, 2013 at 0:34
  • $\begingroup$ @Mr.Wizard Now I understand you... I think Mathematica forget everything, but I have no experience with this. It will be nice if we can see intermediate results every 5 minutes. But I think it is not very useful. You can re-run FullSimplify with a TimeConstraint of 1,2,4,8,16,... minutes. Slowdown will be not more then 2 times with comparison to the best TimeConstraint. $\endgroup$
    – ybeltukov
    Commented Dec 6, 2013 at 0:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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