MathGroup Archive 2009

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

Search the Archive

Re: Replace not spotting a replacement

  • To: mathgroup at smc.vnet.net
  • Subject: [mg103585] Re: [mg103399] Replace not spotting a replacement
  • From: danl at wolfram.com
  • Date: Tue, 29 Sep 2009 07:38:17 -0400 (EDT)
  • References: <200909201021.GAA24204@smc.vnet.net>

> Hi Daniel,
>
> Awesome - that's a start - thank you.  Actually it doesn't spit out the
> simplest variant (i.e. "mu tau") but it's a step in the right direction.
> MM
> internally must be doing this kind of stuff to carry out functions like
> FullSimplify.
>
> Regards,
> David.

I realized later, from another respondent's post, that you probably wanted
a mu times tau result. It can be attained as below.

In[6]:= replacementFunction[
 Sqrt[2 \[Pi]] \[Tau]^(3/2), {Sqrt[
    2 \[Pi] \[Tau]] - \[Mu], \[Mu]^2 - \[Tau]}, {Sqrt[\[Tau]], \[Mu]}]

Out[6]= (\[Mu] \[Tau])/(2 \[Pi])

At this point we get a bit into magic, trying to second guess what
variables are created internally, so as to impose an ordering. If you
realize that Sqrt[\[Tau]] will be, in some form, an internal "variable",
then it is just a matter of getting the ordering right to impose the
relation you have in mind.

You are correct that FullSimplify may use some of this machinery behind
the scenes, but there is is even more difficult to second guess.

Daniel Lichtblau
Wolfram Research

>> -----Original Message-----
>> From: danl at wolfram.com [mailto:danl at wolfram.com]
>> Sent: 20 September 2009 22:00
>> To: claranet news
>> Cc: mathgroup at smc.vnet.net
>> Subject: Re: [mg103399] Replace not spotting a replacement
>>
>> > Hi Folks,
>> >
>> > Seems the replace function is being a bit dim here.  This fails:
>> >
>> > Sqrt[2 \[Pi]] \[Tau]^(3/2) /. Sqrt[ 2 \[Pi] \[Tau]] -> \[Mu]
>> >
>> > Apologies if this is an FAQ - I couldn't see anything about it.  What
>> do I
>> > need to do here to coerce Mathematica into making this replacement? I
>> > tried using the
>> > Collect function on tau first, but that didn't seem to work.  I also
>> tried
>> > re-writing the replacement rule as
>> >
>> > Sqrt[2 \[Pi]] \[Tau]^(3/2) /. Sqrt[ 2 \[Pi] ] t^(1/2) -> \[Mu]
>> >
>> > But still no joy.
>> >
>> > Anyone know?
>> >
>> > Many thanks,
>> > David.
>>
>> It's more of an Occasionally Asked Question. Replacement is working
>> fine;
>> the fact is, your expression does not contain \[Tau]^(1/2). Syntactic
>> replacement cares about niceties of that sort.
>>
>> What you want can usually be attained by algebraic replacement. I say
>> "usually" because it can be a bit tricky to get the right algebraic
>> relation recognized where it is needed. Here is a slight alteration of
>> some code from a few years back, that works on your example.
>>
>> replacementFunction[expr_, rep_, vars_] :=
>>  Module[{num = Numerator[expr], den = Denominator[expr],
>>    hed = Head[expr], base, expon},
>>   If[PolynomialQ[num, vars] &&
>>     PolynomialQ[den, vars] && ! NumberQ[den],
>>    replacementFunction[num, rep, vars]/
>>     replacementFunction[den, rep, vars],
>>    If[hed === Power && Length[expr] == 2,
>>     base = replacementFunction[expr[[1]], rep, vars];
>>     expon = replacementFunction[expr[[2]], rep, vars];
>>     PolynomialReduce[base/expon, rep, vars][[2]],
>>     If[Head[hed] === Symbol &&
>>       MemberQ[Attributes[hed], NumericFunction],
>>      Map[replacementFunction[#, rep, vars] &, expr],
>>      PolynomialReduce[expr, rep, vars][[2]]]]]]
>>
>> In[10]:= replacementFunction[Sqrt[2 \[Pi]] \[Tau]^(3/2),
>>  Sqrt[2 \[Pi] \[Tau]] - \[Mu], \[Tau]]
>>
>> Out[10]= \[Mu]^3/(2 \[Pi])
>>
>> Some day I'll have an epiphany, or at least a minor vision, and see a
>> way
>> to code this so that it always just "does the right thing", whatever
>> that
>> might be.
>>
>> Daniel Lichtblau
>> Wolfram Research




  • Prev by Date: Re: Replace not spotting a replacement
  • Next by Date: Re: Full expansion with a mixture of Times and NonCommutativeMultiply
  • Previous by thread: Re: Replace not spotting a replacement
  • Next by thread: Re: Replace not spotting a replacement