[Date Index]
[Thread Index]
[Author Index]
Re: Replacement rule limitations
*To*: mathgroup at smc.vnet.net
*Subject*: [mg110564] Re: Replacement rule limitations
*From*: Bill Rowe <readnews at sbcglobal.net>
*Date*: Sat, 26 Jun 2010 03:08:55 -0400 (EDT)
On 6/25/10 at 7:26 AM, stevebg at ROADRUNNER.COM (S. B. Gray) wrote:
>Several responders have told me that replacement rules are the way
>to simplify complex expressions and to reduce redundant computations
>(?).
>So let's try an arbitrary expression as a very simple example of
>something that could be much more complicated:
>exp = 1/Sqrt[
>x^2+y^2+z^2] - (x^2+y^2+z^2) + (x^2+y^2+z^2)^( 1/3) /.
>x^2+y^2+z^2->dd This gives
>1/Sqrt[dd] + dd^(1/3)-x^2-y^2-z^2 which is not that useful.
Consider
In[1]:= FullForm[-(x^2 + y^2 + z^2)]
Out[1]//FullForm= Plus[Times[-1,Power[x,2]],Times[-1,Power[y,2]],Times[-1,Power[z,2]]]
That is after Mathematica evaluates -(x^2+y^2+z^2), there is
nothing left to match (x^2+y^2+z^2).
>But if I introduce a superfluous multiplier "s":
>exp = 1/Sqrt[x^2+y^2+z^2] -
>s(x^2+y^2+z^2) + (x^2+y^2+z^2)^( 1/3) /. {x^2+y^2+z^2->dd,
>s->1} I get
>1/Sqrt[dd] + dd^(1/3) - dd which is better. Asking for
Right. Now
In[2]:= FullForm[-s (x^2 + y^2 + z^2)]
Out[2]//FullForm= Times[-1,s,Plus[Power[x,2],Power[y,2],Power[z,2]]]
Now there is a match for (x^2+y^2+z^2) and for s. So, the
replacement occurs and you get the desired result.
>Unless I am missing something important (it wouldn't be the first
>time!), replacement rules are not a good substitute for real
>intermediate variables.
Replacement rules will work. But you have to understand they are
literal replacements which occur after other evaluation. And if
the other evaluation alters the form of what is being replaced,
then no replacement occurs.
>This does not even address a feature I'd like to see in Mathematica in
>which it would figure out what subexpressions appear repeatedly and
>make up its own simplifying intermediate variables. This could be
>incorporated into FullSimplify.
I don't think so. Consider what is required to find all
sub-expressions. The complexity of the problem rises very
rapidly with the number of things. Incorporating this into
FullSimplify would certainly increase the time for FullSimplify
to work unacceptably for all but fairly simple expressions. And
those are the ones where you likely don't really need FullSimplify.
Prev by Date:
**Re: and sampling a distribution**
Next by Date:
**Re: Lauching application from an icon**
Previous by thread:
** Re: Replacement rule limitations**
Next by thread:
**Reducible Trinomials How to do quickest algoritm**
| |