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: [mg103614] Re: [mg103399] Replace not spotting a replacement
  • From: "David Carter-Hitchin" <david at carter-hitchin.clara.co.uk>
  • Date: Wed, 30 Sep 2009 05:00:54 -0400 (EDT)
  • References: <200909201021.GAA24204@smc.vnet.net> <52579.98.212.148.221.1253480392.squirrel@webmail.wolfram.com> <00bf01ca4079$2e230d30$8a692790$@clara.co.uk> <50884.140.177.99.93.1254191276.squirrel@webmail.wolfram.com>

Hi Daniel,

Many thanks, but your post doesn't make sense to me.  If we start with:

  Sqrt(2 pi) * tau^(3/2)
= Sqrt(2 pi) * tau^(1/2) * tau
= Sqrt(2 pi t) * tau
= mu tau

This is not the result your function gives.  I also do not understand the
way the second argument is constructed:

{Sqrt[2 \[Pi] \[Tau]] - \[Mu], \[Mu]^2 - \[Tau]}

Does that mean replace Sqrt(2 pi tau) with mu, then replace mu^2 with tau?
Which case the second replacement is wrong - it should be "2 pi tau".  If I
do that then its fine:

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


Out[4]= \[Mu] \[Tau]

However, as you said, this is quite reliant on spotting the kind of
expression that turns up the first time and adapting it for a second go.
What would be nice would be to somehow specify "minimal" (i.e. simpler)
adjustments to the expression before replacement. 

Nevertheless your function is very useful and have saved it for the next
time I'm working on something like this.

Many thanks,
Kind regards,
David.
 

> -----Original Message-----
> From: danl at wolfram.com [mailto:danl at wolfram.com]
> Sent: 29 September 2009 03:28
> To: David Carter-Hitchin
> Cc: danl at wolfram.com; mathgroup at smc.vnet.net
> Subject: RE: [mg103399] Replace not spotting a replacement
> 
> > 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
> 
> 
> No virus found in this incoming message.
> Checked by AVG - www.avg.com
> Version: 8.5.409 / Virus Database: 270.13.113/2398 - Release Date:
> 09/27/09 05:51:00



  • Prev by Date: Re: Help generalizing Liouville's Polynomial Identity
  • Next by Date: Re: Resume an aborted calculation?
  • Previous by thread: Re: Replace not spotting a replacement
  • Next by thread: Re: Replace not spotting a replacement