       Re: Rule and Module not working together

• To: mathgroup at smc.vnet.net
• Subject: [mg77920] Re: [mg77864] Rule and Module not working together
• From: Carl Woll <carlw at wolfram.com>
• Date: Tue, 19 Jun 2007 07:01:16 -0400 (EDT)
• References: <200706181107.HAA19846@smc.vnet.net>

Steven Siew wrote:

>On Mathematica 5.2, I tried to write a function which applies the rule
>Log[A_] + Log[B_] -> Log[A * B] but somehow it does not work as I
>expected.
>
>

Use Log[A_] + Log[B_] :> Log[A B] instead.

On another note, there is no need to use Return in your code below. The
last expression in a Module is automatically returned.

Carl Woll
Wolfram Research

>Instead of Log[f] + Log[g] becoming Log[f * g], I get the result of
>Log[666 * f] even though I have marked both A and B as private
>variables.
>
>Can anyone help? I'm sure I made a big mistake somewhere in my
>understanding of Mathematica.
>
>
>
>In:= AppendTo[\$Echo,"stdout"]
>Out= {stdout}
>
>In:= (* Write your mathematica code below *)
>
>In:= If[Length[Names["Global`*"]] > 0, Remove["Global`*"]]
>
>In:= Off[General::spell, General::spell1]
>
>In:= myfunc[x_] := Module[{s, A, B},
>   s = {Log[A_] + Log[B_] -> Log[A*B]}; Return[x /. s]]
>
>In:= ? myfunc
>Global`myfunc
>
>myfunc[x_] := Module[{s, A, B}, s = {Log[A_] + Log[B_] -> Log[A*B]};
>     Return[x /. s]]
>
>In:= B = 666;
>
>In:= myfunc[Log[f] + Log[g]]
>
>Out= Log[666 f]
>
>In:= myfunc[Log + Log]
>
>Out= Log
>
>In:= (* End of mathematica code *)
>
>In:= Quit[];
>
>
>

• Prev by Date: Re: Mathematica 6.0 not running in Fedora 7?
• Next by Date: Re: Indefinate integrals, erroneus Natural log?
• Previous by thread: Rule and Module not working together
• Next by thread: Re: Rule and Module not working together