Re: Radicals simplify
- To: mathgroup at smc.vnet.net
- Subject: [mg106450] Re: Radicals simplify
- From: Richard Fateman <fateman at cs.berkeley.edu>
- Date: Wed, 13 Jan 2010 05:56:58 -0500 (EST)
- References: <hic37h$5ef$1@smc.vnet.net> <201001111030.FAA23508@smc.vnet.net> <201001112354.SAA21089@smc.vnet.net> <hihgi8$faq$1@smc.vnet.net>
Andrzej Kozlowski wrote: > Yes, but Adam Strzebonski has already posted here the default > CoplexityFunction in the past, and knowing it really wont help you much: > > > SimplifyCount[p_] := > If[Head[p]===Symbol, 1, > If[IntegerQ[p], > If[p==0, 1, Floor[N[Log[2, Abs[p]]/Log[2, 10]]]+If[p>0, 1, > 2]], > If[Head[p]===Rational, > SimplifyCount[Numerator[p]]+SimplifyCount[Denominator[p]]+1, > If[Head[p]===Complex, > SimplifyCount[Re[p]]+SimplifyCount[Im[p]]+1, > If[NumberQ[p], 2, > SimplifyCount[Head[p]]+If[Length[p]==0, 0, > Plus@@(SimplifyCount/@(List@@p))]]]]]] > > Would it be helpful to have this in the Documentation? It would be more helpful if it were more readable, that's for sure. I think Adam's function is equivalent to SimplifyCount[0]=1 SimplifyCount[_Symbol]:=1 SimplifyCount[p_Integer]:= Floor[N[Log[2, Abs[p]]/Log[2, 10]]]+If[p>0, 1, 2] SimplifyCount[p_Rational]:= SimplifyCount[Numerator[p]]+SimplifyCount[Denominator[p]]+1, SimplifyCount[p_Complex]:= SimplifyCount[Re[p]]+SimplifyCount[Im[p]]+1, SimplifyCount[p_?NumberQ]:= 2 SimplifyCount[p_] := Plus@@(SimplifyCount/@(Append[List@@p,Head[p]])) (*everything else*) not tested, but you get the idea. Adam's program may be faster in some way, or he may have written because he thinks in terms of If[Head[]==] and it did not occur to him to use pattern matching. Or maybe my program doesn't work because the interactions of the multiple patterns cause problems -- I require that the patterns be applied in the right order and Mathematica may be randomizing them in some way. (That is, 0 is an Integer, but we want to use the first line, not the 3rd). One way to make documentation readable is to have a system that is logically consistent --- the semantics are simpler. By this measure, it would be much easier to understand the system and read this documentation if the pattern matching for p/q and r+s*I did not need special cases when p and q , or s were numbers, but just looked like the same patterns as the cases when p,q, s are symbols. Then the complexity function would look like this SimplifyCount[0]=1 SimplifyCount[_Symbol]:=1 SimplifyCount[p_Integer]:= Floor[N[Log[2,Abs[p]]/Log[2,10]]]+If[p>0,1,2] SimplifyCount[p_?NumberQ]:= 2 SimplifyCount[p_] := Plus@@(SimplifyCount/@(Append[List@@p,Head[p]])) 5 lines, not 11. [In fact, it may be that this documentation would be worth providing if it were noted that this is a "simplification" of how it really works.] RJF
- References:
- Re: Radicals simplify
- From: dh <dh@metrohm.com>
- Re: Re: Radicals simplify
- From: Murray Eisenberg <murray@math.umass.edu>
- Re: Radicals simplify