MathGroup Archive 2010

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

Search the Archive

Re: using rules for square roots

  • To: mathgroup at smc.vnet.net
  • Subject: [mg110284] Re: using rules for square roots
  • From: Kent Holing <KHO at statoil.com>
  • Date: Fri, 11 Jun 2010 08:44:37 -0400 (EDT)

> Using the Mathematica session
> str={Sqrt[a],Sqrt[b^2],Sqrt[c^3],Sqrt[d^4],Sqrt[e^5]};
> g[x_,n_]:=Module[{m=Quotient[n,2]},If[EvenQ[n],x^m,x^m
> Sqrt[x]]]; 
> rule1=Sqrt[x_ y_]->Sqrt[x] Sqrt[y]; 
> rule2=Sqrt[x_^2]->x; 
> rule=Sqrt[x_^n_]->x^Quotient[n,2] Sqrt[x^Mod[n,2]]; 
> rule0=Sqrt[x_^n_]->g[x,n];
> 
> Now, str/.rule gives the "correct" answer
> {Sqrt[a],b,c^3/2,d^2,e^5/2}.
> 
> But why does not rule0 work? 
> str/.rule returns
> {Sqrt[a],b^3/2,c^3/2,d^5/2,e^5/2}.
> 
> I would also like that rule (and rule0) should return
> say
> e^5/2 as e^2 Sqrt[e]. How can this be accomplished?
> 
> Kent
> 

rule0=Sqrt[x_^n_]->Hold[g[x,n]]; 
tstr0=ReleaseHold[str/.rule0]; 
fixes the rule0. 

I still want to have feedback on my last question, i.e. how to return say expressions like e^5/2 as e^2 Sqrt[e]?

Kent


  • Prev by Date: Re: can't get ListVectorPlot3D to work.
  • Next by Date: Re: O'Reilly Ebook Deal of Day: Mathematica Cookbook
  • Previous by thread: using rules for square roots
  • Next by thread: Re: using rules for square roots