Re: Replace not spotting a replacement
- To: mathgroup at smc.vnet.net
- Subject: [mg103584] Re: [mg103399] Replace not spotting a replacement
- From: "David Carter-Hitchin" <david at carter-hitchin.clara.co.uk>
- Date: Tue, 29 Sep 2009 07:38:05 -0400 (EDT)
- References: <200909201021.GAA24204@smc.vnet.net> <52579.98.212.148.221.1253480392.squirrel@webmail.wolfram.com>
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. > -----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.111/2386 - Release Date: > 09/21/09 05:51:00
- References:
- Replace not spotting a replacement
- From: "claranet news" <david@carter-hitchin.clara.co.uk>
- Replace not spotting a replacement