Re: Replacement problem

• To: mathgroup at smc.vnet.net
• Subject: [mg36961] Re: Replacement problem
• From: carlos at colorado.edu (Carlos Felippa)
• Date: Thu, 3 Oct 2002 00:16:54 -0400 (EDT)
• References: <anbop9\$e93\$1@smc.vnet.net> <ane7e5\$k79\$1@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```Jens-Peer Kuska <kuska at informatik.uni-leipzig.de> wrote in message news:<ane7e5\$k79\$1 at smc.vnet.net>...
> Hi,
>
>
> Sqrt[a] is internal Power[a,Rational[1,2]] and
> 1/Sqrt[a] is interal Power[a,Rational[-1,2]]
> and so a rule Sqrt[a]->q will not match with
> 1/Sqrt[a]. You need
>
> f = B*(A + Sqrt[X + Y + Z]) + C/(Sqrt[X + Y + Z]/4*F^2);
> (f /. (X + Y + Z)^Rational[n_, 2] -> Q^n)
>
> Regards
>   Jens

Thanks.  That is exactly what I need for the Sqrt. These and similar rules
ought to be in the help Examples under \. and \\.

I should clarify three things. First, why use of FullForm is
impractical.  The source expressions I am dealing with are highly complex,
with thousands of terms. The subexpressions to be replaced appear in
hundreds of places, in many nested combinations.  Detailed eye
examination after each run would take a long time.

Second, the operation subexpression->letter is used as preparation
for conversion of those expressions to C.  The "letters" will be names
of "temps" (temporary variables) in C code.  Upon replacing all
subexpressions the source contracts to about 1-5% of original size.

Third, there is a brute force replacement method which can be used (and was):
output in InputForm, save cell as text, use a smart text editor that
ignores blanks and CRs (e.g. emacs), and re-input for C conversion.
This is cumbersome (the text has to be telnet'd to a Unix machine
and back) and error prone but available as last resort.

Perhaps a future version of Mathematica may incorporate a <- operator
for this kind of "reverse expansion" to extract common subexpressions.
The output would be the contracted expression and a temps list.

```

• Prev by Date: Re: FindRoot on complex 'interval'
• Next by Date: Re: Re: Re: Are configuration & UI better in 4.2?
• Previous by thread: Re: Replacement problem
• Next by thread: Re: Solve simultaneous eqns