Simplify & FullSimplify

Consider a special ComplexityFunction

One might like the following to simplify to 1-Exp[-x], and we would like FullSimplify[Log[10^20]] to return (20 Log[10]) which FullSimplify does by default.

FullSimplify[1-Cosh[x]+Sinh[x]]

1-Cosh[x]+Sinh[x]

The definitions in the next cell define a new setting for the ComplexityFunction that does the trick.

ClearAll[DigitsLength,Digits1,Digits2,VariableCount];DigitsLength[0|1]=1/20;DigitsLength[-1]=1/15;DigitsLength[n_]:=Length[IntegerDigits[n]];Digits1[expr_]:=Plus@@(DigitsLength[#]&/@Cases[expr,_Integer,-1]);Digits2[expr_]:=Plus@@Flatten[&IndentingNewLine;Map[DigitsLength[#]&,({Numerator[#],Denominator[#]}& /@Cases[expr,_Rational,{-1}]),{-1}&IndentingNewLine;]&IndentingNewLine;];VariableCount[expr_]:=Count[expr,_Symbol?(Not[NumericQ[#]]&),{-1}]*11/10&IndentingNewLine;SetOptions[FullSimplify,ComplexityFunction->(LeafCount[#]+Digits1[#]+Digits2[#]+VariableCount[#]&)];

In the next two cells we see that it works.

FullSimplify[Log[100000000000000000000]]

20 Log[10]

FullSimplify[1-Cosh[x]+Sinh[x]]

[Graphics:../Images/Tricks_gr_179.gif]

A simple problem Simplify & FullSimplify can't handle

Jürgen Tischer sent a problem to the MathGroup that Simplify couldn't simplify very well.  Simplify has trouble with the example in the next cell for the same reason as the more complicated example Jürgen Tischer provided.

[Graphics:../Images/Tricks_gr_180.gif]

[Graphics:../Images/Tricks_gr_181.gif]

The code in the next cell forces Simplify to make the appropriate simplification.  This is based on a very clever solution Allan Hayes sent to the MathGroup.

Unprotect[Simplify];HiddenSymbols`ModifySimplify=True;&IndentingNewLine;Simplify[expr_]/;HiddenSymbols`ModifySimplify:=Block[{HiddenSymbols`ModifySimplify},&IndentingNewLine;Module[{temp},&IndentingNewLine;Simplify[&IndentingNewLine;Factor[expr/.(n_Integer)^(k_):>&IndentingNewLine;(Times@@(temp[First[#]]^(k*Last[ #])&)/@FactorInteger[n])&IndentingNewLine;]/.temp[a_]:>a&IndentingNewLine;]&IndentingNewLine;]&IndentingNewLine;]&IndentingNewLine;Protect[Simplify];

After evaluating the previous cell Simplify does better with the example above.

[Graphics:../Images/Tricks_gr_182.gif]

[Graphics:../Images/Tricks_gr_183.gif]

One might wonder why [Graphics:../Images/Tricks_gr_184.gif] isn't returned in the output above.  The reason is that the kernel insists on changing [Graphics:../Images/Tricks_gr_185.gif] into [Graphics:../Images/Tricks_gr_186.gif].  As I mention on our wish list I would like to have a new type of hold that would send an expression to the Front End without further evaluation, but treat the expression as if it wasn't held in future evaluation. This new type of hold would come in handy here since it would allow the output to be formatted as [Graphics:../Images/Tricks_gr_187.gif].


Back to Main Page...

Converted by Mathematica      May 19, 2000
Styles converted by a program by Reinhold Kainhofer ( reinhold@wolfram.com )