6
$\begingroup$

I have this expression:

Log[i] > (i Log[i])/n + Log[n - i] - (i Log[n - i])/n

And I attempt to simplify it and get this:

FullSimplify[%]
(* output: n (-i + n) (Log[i] - Log[-i + n]) > 0 *)

I have no idea, how the software got this and I fail to derive the same result on paper myself. How could I obtain the process which derives this output?

$\endgroup$
8
$\begingroup$

Here is one way to extract some intermediate results:

expr = Log[i] > (i Log[i])/n + Log[n - i] - (i Log[n - i])/n;

Select[FullSimplify[expr == #] &]@
 Reap[
   FullSimplify[expr, TransformationFunctions -> {Automatic, Sow}]
 ][[2, 1]]

(* .{
  Log[i] > (i Log[i])/n + Log[-i + n] - (i Log[-i + n])/n,
  Log[i] > (i Log[i] + (-i + n) Log[-i + n])/n, 
  n (-i + n) (Log[i] - Log[-i + n]) > 0, 
  n (-i + n) (Log[i] - Log[-i + n]) > 0
} *)

As you can see, the steps are roughly:

  • Put everything on the right side in one fraction
  • Multiply by n, move the right side to the left and group terms

How it works

The idea is to add Sow to TransformationFunctions. This allows us to take note of most of the expressions that FullSimplify generates during the simplification. We then use Select to filter out those expressions that are equivalent to the initial expression. The other terms are subexpressions, which might also be useful, depending on how much detail you want. (If you want to look at them as well, just remove the Select[...]@ part)

$\endgroup$
  • $\begingroup$ Very interesting! Unfortunately, on my system (mma 12, windows) nothing is reaped. $\endgroup$ – Fred Simons May 2 at 16:58
  • $\begingroup$ Can you try again after restarting the kernel? $\endgroup$ – Lukas Lang May 2 at 17:01
  • $\begingroup$ Even stranger. The first time it works, reevaluation fails. Does this happen on your system as well? $\endgroup$ – Fred Simons May 2 at 17:50
  • 3
    $\begingroup$ It seems to be a problem with caching. When I reevaluate a Reap command, it reaps nothing, but when I first execute ClearSystemCache[], it works fine again. $\endgroup$ – Fred Simons May 2 at 18:24
2
$\begingroup$

It is a very old and very interesting task, which as far as I know still lacks a satisfactory solution. One of most interesting attempts is given in M. Trott's celebrated "The Mathematica Guide for Symbolic", page 1036. Here I provide slightly modified version of it

id = (Log[i] > (i Log[i])/n + Log[n - i] - (i Log[n - i])/n);

csc := (count1 = 0; count2 = 0; count3 = 0;
  lf = LeafCount[id];
  (*simplify and keep track of intermediate results*)
  FullSimplify[id, ComplexityFunction -> ((count1++;
         Which[LeafCount[#] === lf, count2++, LeafCount[#] < lf, 
          lf = LeafCount[#]; count2++; count3++]; LeafCount[#]) &[
       Print[#]; #] &)])

Evaluating

csc

will print all attempts to simplify any part of the expression. Of course, most of them are useless. I don't know how to construct from them entire simplification tree. Your can print only those transformations which leads to decrease of LeafCount.

$\endgroup$
  • $\begingroup$ This is nice! You could do one better by using Sow instead of Print and in doing so be able to directly capture all the results. $\endgroup$ – b3m2a1 May 3 at 7:06
  • $\begingroup$ The output is quite hard to decipher, imho. $\endgroup$ – user1747134 May 3 at 7:17
  • $\begingroup$ Try it to run on something simpler like id=Sin[x]^2Cos[x]+Cos[x]^3 and your will see what is going and why the task is difficult. $\endgroup$ – user18792 May 3 at 7:22
  • $\begingroup$ The complexity function is used on every attempt to find a simplification. An extra transformation function, as done by @Lucas Lange, is used at least on all relevant intermediate results. I tested this on a pretty complicated expression that can be simplified to 0. The complexity function was called 17530 times, while the extra transformation function was called only 1633 times. Hence, for this expression, the complexity function produces almost 16000 avoidable useless results. But using the complexity function for inspecting intermediate results is a very nice idea. $\endgroup$ – Fred Simons May 3 at 18:43
  • $\begingroup$ I did't expect that the difference is so large! You can more or less mimic TransformationFunctions by sowing/printing successful transformations only by Which[LeafCount[#] === lf, Print[#]; count2++, LeafCount[#] < lf, Print[#]; Note, that TransformationFunctions misses the factorization step (just compare how it works on the above id=Sin[x]^2Cos[x]+Cos[x]^3 expression.). Though I think that simplification tree can be reconstructed from the particular data, the FullSimplify step by step logic and the rules attempted requires internal option like Monitor to be implemented. $\endgroup$ – user18792 May 6 at 5:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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