As far as I know, the complexity must be a positive value. But I get such example:
Reap[FullSimplify[ArcSin[Cos[x]], 0 <= x <= 1,
ComplexityFunction -> (Sow[-LeafCount[#] +
Count[#, _Cos, {0, Infinity}]*100] &)]]
{1/2 (Pi-2 x),{{97,98,-1,-1,98,98,98,98,97,97,97,97,97,97,97,97,89,89,89,89,89,89,89,89,89,89,89,93,93,93,93,93,93,95,95,95,97,-1,-1,-1,-3,-3,-3,-3,-1,-1,-3,-3,-3,-3,-3,-3,-3,-5,-5,-5,-5,-5,-5,-5,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-5,-5,-5,-5,-9,-9,-9,-9,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-1,-1,-3,-3,-3,-3,-3,-3,-3,-5,-5,-5,-5,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-1,-1,-3,-3,-3,-3,-3,-3,-3,-5,-5,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9}}}
Well, since the negative value works, why I can't change the 100
to 2
? Such as:
Reap[FullSimplify[ArcSin[Cos[x]], 0 <= x <= 1,
ComplexityFunction -> (Sow[-LeafCount[#] +
Count[#, _Cos, {0, Infinity}]*2] &)]]
I will get some error information ($RecursionLimit::reclim
).
Update for george2079's comment:
I made a variable tem
to collect the value in intermediate caculation:
tem = <||>;
cache := (AssociateTo[tem, # -> #]; #) &
FullSimplify[ArcSin[Cos[x]], 0 <= x <= 1,
ComplexityFunction -> (cache[100 - LeafCount[#]] &)]
This code will give some error information:
You cannot finish the calculation normally. Click the alt+. after a certain time. Then you will get some value producing in intermediate caculation.
Counts[Sign[Values[tem]]]
<|1->83,-1->288,0->1|>
Of course, you can get a same case by my original example. But this case is more obvious those value producing in intermediate caculation is not all of negtive.