[Date Index]
[Thread Index]
[Author Index]
Re: Replacement Rule with Sqrt in denominator
*To*: mathgroup at smc.vnet.net
*Subject*: [mg114404] Re: Replacement Rule with Sqrt in denominator
*From*: Richard Fateman <fateman at cs.berkeley.edu>
*Date*: Fri, 3 Dec 2010 05:21:46 -0500 (EST)
*References*: <ic5igm$44p$1@smc.vnet.net> <ic8ad7$81f$1@smc.vnet.net> <id7t95$lh1$1@smc.vnet.net>
On 12/2/2010 2:43 AM, Roland Franzius wrote:
....
>
> Use rules like
>
> HoldPattern[x^Rational[a_,2]] :> G^a
>
> eg this works for contraction of products of fractional powers
>
> ((1 + I x)^(1/2)/(1 - I x)^(1/2)) /.
> {HoldPattern[a_^Rational[b_, c_] d_^Rational[e_, c_]]
> :> (a^b d^e)^(1/c)}
Not really. Consider the very similar example
((1 + I x)^(a/2)/(1 - I x)^(a/2)) /. {HoldPattern[
a_^Rational[b_, c_] d_^Rational[e_, c_]] :> (a^b d^e)^(1/c)}
where we have a/2 instead of 1/2
and the pattern does not match. Maybe you don't want it to match in
this case, but the problem persists even if you do. Like this pattern:
((1 + I x)^(a/2)/(1 - I x)^(a/2)) /. {HoldPattern[
a_^(b_/c_) d_^(e_/c_)] :> (a^b d^e)^(1/c)}
which fails.
or this pattern
((1 + I x)^(a/2)/(1 - I x)^(a/2)) /. {HoldPattern[
a_^(b_*Rational[-1, c_]) d_^(e_*Rational[-1, c] _)] :> (a^b d^
e)^(1/c)}
which fails too.
Now try this (note, the rule must be delayed... :> )
aa^(rr/ss)*bb^(qq/ss) /. (
a_^r_*b_^s_ /; Denominator[r] == Denominator[s] :>
(a^Numerator[r]*b^Numerator[s])^(1/Denominator[r]))
and then it works. you get (aa^rr*b^qq)^(1/ss).
really you probably want to take out something like the
greatest multiple of r and s, not 1/Denominator[s], but
that's up to you.,
Basically, if the rules for your pattern matching reflect
the SEMANTICS of what you are doing, e.g. "denominator" and
"numerator", rather than the SYNTAX of FullForm, being
Rational or maybe Times or ..., then you have a better chance of
winning.
Each time someone defends Mathematica via "you have to look
at FullForm" he/she is essentially saying, "Mathematica is now too
stupid to do what you want, and the programmers of the system
are too resistant to making it smarter. Thus the burden falls on
you to look at the data representation underlying the abstraction
to make your program work."
It's not so hard to make the system smarter. But you pay for what
you get.
RJF
Prev by Date:
**Re: Using a Correlation Matrix to reduce risk**
Next by Date:
**Re: Re-virginating Manipulates?**
Previous by thread:
**Re: Replacement Rule with Sqrt in denominator**
Next by thread:
**Re: Replacement Rule with Sqrt in denominator**
| |