[Date Index]
[Thread Index]
[Author Index]
"Best" ComplexityFunction Setting ?
*To*: mathgroup at smc.vnet.net
*Subject*: [mg24306] "Best" ComplexityFunction Setting ?
*From*: "Ersek, Ted R" <ErsekTR at navair.navy.mil>
*Date*: Fri, 7 Jul 2000 00:11:50 -0400 (EDT)
*Sender*: owner-wri-mathgroup at wolfram.com
Below I give three examples where the default setting of ComplexityFunction
doesn't return the expression in the "simplest" form.
In[1]:=
FullSimplify[1-Cosh[x]+Sinh[x]]
Out[1]=
1 - Cosh[x] + Sinh[x]
-------
In[2]:=
FullSimplify[8(-1+x)(1+x)]
Out[2]=
8*(-1 + x)*(1 + x)
-------
In[[3]:=
n1=59^5*1579^7;
n2=3^5*19^7*113^5;
FullSimplify[Log[n1*n2]]
Out[5]=
7*Log[19] + 5*Log[59] + 5*Log[113] + Log[243] +
7*Log[1579]
--------
Next I define functions used for a new ComplexityFunction setting. This new
setting gives results that are "simpler" or "just as simple" as those we get
using the default setting. Well at least it does in all cases I looked at so
far.
In[6]:=
ClearAll[DigitsLength,Digits1,Digits2,VariableCount];
DigitsLength[0|1]=1/10;
DigitsLength[-1]=1/8;
DigitsLength[n_]:=Length[IntegerDigits[n]];
Digits1[expr_]:=2*Plus@@(DigitsLength[#]&/@Cases[expr,_Integer,-1]);
Digits2[expr_]:=2*Plus@@Flatten[
Map[DigitsLength[#]&,
({Numerator[#],Denominator[#]}& /@Cases[expr,_Rational,{-1}]),
{-1}
]
];
VariableCount[expr_]:=Count[expr,_Symbol?(Not[NumericQ[#]]&),{-1}];
SetOptions[
FullSimplify,ComplexityFunction->
(LeafCount[#]+Digits1[#]+Digits2[#]+3*VariableCount[#]&)
];
Below we see that using the new setting for ComplexityFunction,
FullSimplify gives a "simpler" result in each case considered above.
---------
In[15]:=
FullSimplify[1-Cosh[x]+Sinh[x]]
Out[15]=
1 - E^(-x)
---------
In[16]:=
FullSimplify[8(-1+x)(1+x)]
Out[16]=
8*(-1 + x^2)
---------
In[17]:=
n1=59^5*1579^7;
n2=3^5*19^7*113^5;
FullSimplify[Log[n1*n2]]
Out[19]=
5*Log[20001] + 7*Log[30001]
---------
Notice the last example takes a surprising amount of time using my
ComplexityFunction. The time needed to simplify a similar but large
expression would be very long. It seems this is a case where we have to
trade off the extent of the search with the time needed to complete the
search.
My ComplexityFunction above doesn't take into account the number of digits
in Re[z] or Im[z] when Re[z] or Im[z] are Integer or Rational. I could find
a way to do that, but it's a bit messy. Without exploiting that short coming
can anyone find an example where
ComplexityFunction->Automatic can find a form "more simple" than using my
ComplexityFunction. For me the search for the "best" ComplexityFunction is
interesting.
--------------------
Regards,
Ted Ersek
Download Mathematica tips, tricks from
http://www.verbeia.com/mathematica/tips/Tricks.html
Prev by Date:
**RE: LogPlot != Plot[Log]**
Next by Date:
**Re: Divisors**
Previous by thread:
**Re: Transposing a triangular matrix.**
Next by thread:
**RE: Re: Conditionals with multiple tests?(2) ++ evaluating CompoundExpression**
| |