MathGroup Archive 2001

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Re: Automatic expansion of Log[a^n] for a,n explicit positive integers?


>>>>> "Chris" == Chris Johnson <cjohnson at shell.faradic.net> writes:

Chris> You could use this function:

Chris> lg[z_?IntegerQ] := Plus @@ Apply[#2 Log[#1] &, FactorInteger[z], 2]

Chris> I tried to incorporate this into the definition of Log by:

Chris> Unprotect[Log];
Chris> Log[z_?IntegerQ] := Plus @@ Apply[#2Log[#1] &, FactorInteger[z], 2];
Chris> Protect[Log];

Chris> But I get a recursion error.  I hope someone else might be able to suggest
Chris> a way to avoid this.  Putting Hold around the Log in the pure function
Chris> leaves the Hold in the output.  I hoped I could first define

Chris> Log[z_?PrimeQ] := Log[z] 

Chris> to catch the Prime case, but this also leads to recursion.

You were very close, indeed!

Mianlai Zhou <lailai at carmen.nikhef.nl> wrote me that he solved this problem
by:

Unprotect[Log]
Log[n_Integer?Positive /; !PrimeQ[n]] :=
    Plus @@ (#2 Log[#1] & @@@ FactorInteger[n])
Protect[Log]

I haven't checked the performance degradation that this might involve, tho.

Cheers,
-Harald


  • Prev by Date: Re: Help with Fold/outer one-liner (II)
  • Next by Date: Re: InputAliases
  • Previous by thread: Re: Re: Automatic expansion of Log[a^n] for a,n explicit positive integers?
  • Next by thread: Re: Re: Automatic expansion of Log[a^n] for a,n explicit positive integers?