From: S. B. Gray on
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.

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

exp^2 gives, as desired,

(1/Sqrt[dd] + dd^(1/3) - dd)^2 . But trying to proceed as if this
were regular algebra where cascaded substitutions are routine, I try:

exp/.{x->a^2, y->3b, z->Sqrt[d + e]} , I get the useless result

1/Sqrt[dd] + dd^(1/3) - dd .

Unless I am missing something important (it wouldn't be the first
time!), replacement rules are not a good substitute for real
intermediate variables. 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.

Comments will be greatly appreciated.

Steve Gray

From: Bill Rowe on
On 6/25/10 at 7:26 AM, stevebg(a)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.


From: Peter Pein on
Am Fri, 25 Jun 2010 11:25:53 +0000 (UTC)
schrieb "S. B. Gray" <stevebg(a)ROADRUNNER.COM>:

> 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.
>
> 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
>
> exp^2 gives, as desired,
>
> (1/Sqrt[dd] + dd^(1/3) - dd)^2 . But trying to proceed as if
> this were regular algebra where cascaded substitutions are routine, I
> try:
>
> exp/.{x->a^2, y->3b, z->Sqrt[d + e]} , I get the useless result
>
> 1/Sqrt[dd] + dd^(1/3) - dd .
>
> Unless I am missing something important (it wouldn't be the first
> time!), replacement rules are not a good substitute for real
> intermediate variables. 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.
>
> Comments will be greatly appreciated.
>
> Steve Gray
>

Hi,

rules are one way constructs. Once you eliminated x, y and z by
your multiplier-method, exp is free of these variables. You'll have to
do a backsubstitution first:

exp/.{dd->x^2+y^2+z^2,x->a^2, y->3b, z->Sqrt[d + e]}

should give what you want.

Peter

P.S.: Did I hear a flat hand slapping against someone's forehead? ;-)



 | 
Pages: 1
Prev: Image processing Questions
Next: Display question