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.

Clear[x, a] ;  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/10 ;  ... tyFunction (LeafCount[#] + Digits1[#] + Digits2[#] + (33/10) * VariableCount[#] &)] ;


In the next cell we see that using the new setting for ComplexityFunction
FullSimplify does what we want.

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

1 - ^(-x)


The next example is taken from the Help Browser. In this case the new setting
for ComplexityFunction gives the same result we get using ComplexityFunction
→Automatic.

n = 70017833065954769132658110933808716053755043900310001 ;    FullSimplify[Log[n]]

5 Log[20001] + 7 Log[30001]


In the next cell we see that when using the new setting for
ComplexityFunction FullSimplify still does a nice job of simplifying a
complicated algebraic expression.

FullSimplify[x^3 Cot[a^2] - 1/4 Csc[a^2] (4 ^( a^2) x^3 + Sin[a^2] (2  ... (1 - ^(2  (a^2 + x^2))) + 4 a^2 x Cot[a^2 + x^2] - 2 π x Tan[x^2])) ]

x^3 Cot[a^2 + x^2]

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.

Clear[n] ;  Simplify[5 (20^n) + 7 (20^n)]

4^n 5^(1 + n) + 7 20^n


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 ;     Simplify[ex ... ]) ]/.temp[a_] a] ] ]     Protect[Simplify] ;


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

Simplify[5 (20^n) + 7 (20^n)]

3 4^(1 + n) 5^n

One might wonder why (12 (20^n)) isn't returned in the output above.  The reason is that the kernel  insists on changing (12 (20^n)) into (3 4^(1 + n) 5^n).  You can use a function I defined called HoldTemporary which prevents  further evaluation of an expression, but does not have to have a hold  released when used in the future. Through use of HoldTemporary one can have  the output above displayed as (12  20^n ).  I have a package which defines HoldTemporary posted at  http://library.wolfram.com/infocenter/MathSource/705


Created by Mathematica  (May 16, 2004)

Back to Ted’s Tricks index page