MathGroup Archive 1998

[Date Index] [Thread Index] [Author Index]

Search the Archive

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
  • Organization: Universidad del Valle
  • References: <E1168E31432DD211AF990000F806EFD82E667A@nems04.nawcad.navy.mil>
  • 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[[1]]]^(k  #1[[2]]) &)/@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[6]:=
> x=123;
> 
> ...
> ...
> ...
> 
>   We still have a global value for (x).
> In[86]:=
> {C[10],C[20],C[30]}/.C[x_]->x
> Out[86]=
> {123,123,123}
>  We didn't get what we wanted for Out[86].
> 
>  Instead used RuleDelayed (:>) as below.
> In[87]:=
> {C[10],C[20],C[30]}/.C[x_]:>x
> Out[87]=
> {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[88]:=
> x=145;
> Block[{x},{C[10],C[20],C[30]}/.C[x_]->x]
> Out[88]=
> {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[[1]]]^(k  #1[[2]]) &)/@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