       Re: Simplify last version

• To: mathgroup at smc.vnet.net
• Subject: [mg14924] Re: [mg14868] Simplify last version
• From: Jurgen Tischer <jtischer at col2.telecom.com.co>
• Date: Wed, 25 Nov 1998 17:48:44 -0500
• Sender: owner-wri-mathgroup at wolfram.com

```Thanks, Ted. I want to point out that this was my error, not Allan's.

Jurgen

"Ersek, Ted R" wrote:
>
> Jugen Tischer posted the following solution by Allan Hayes,
>
> >
> >
> >expr =(-7253*2^(1 + 2*n)*5^n - 523*4^n*5^(1 + n) + 17121*20^n +
> >130321*20^n*n^4)/130321
> >
> >simpl[expr_] :=
> >  Simplify[Factor[
> >        expr /. (x_Integer)^(k_) :>
> >            Times@@(C[#1[]]^(k  #1[]) &)/@FactorInteger[x]] /.
> >      C[x_] -> x]
> >
> >simpl[expr]
> >
> >20^n  n^4
> >
> >
>
> Nice solution.  However, using patterns on the left side Rule(->) may give
> you a result you don't want.  Consider the following.
>
> In:=
> x=123;
>
> ...
> ...
> ...
>
>   We still have a global value for (x).
> In:=
> {C,C,C}/.C[x_]->x
> Out=
> {123,123,123}
>  We didn't get what we wanted for Out.
>
>  Instead used RuleDelayed (:>) as below.
> In:=
> {C,C,C}/.C[x_]:>x
> Out=
> {10,20,30}
>  That's better.
>
>  If you absolutely must use a pattern on
>  the left side of (->), do so inside a block as below.
> In:=
> x=145;
> Block[{x},{C,C,C}/.C[x_]->x]
> Out=
> {10,20,30}
>   That works too.
>
> _________________________
>
> With that said I recommend the following over the solution above.
>
> simpl[expr_] :=
>   Simplify[Factor[
>         expr /. (x_Integer)^(k_) :>
>             Times@@(C[#1[]]^(k  #1[]) &)/@FactorInteger[x]] /.
>       C[x_] :> x]
>
> _________________________
>
> Note:
> Set, UpSet, and TagSet have the same trouble that Rule does (shown above)
> with patterns on the left side.
>
> Cheers,
> Ted Ersek

```

• Prev by Date: Re: PlotLabel question
• Next by Date: Fourier Transform PDF Characteristic Function
• Previous by thread: Re: complexity function for computer code
• Next by thread: Fourier Transform PDF Characteristic Function