Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2005

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

Search the Archive

Re: Re: Re: sqrt(x^2) = x

  • To: mathgroup at smc.vnet.net
  • Subject: [mg61226] Re: Re: [mg61189] Re: sqrt(x^2) = x
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Thu, 13 Oct 2005 01:39:34 -0400 (EDT)
  • Reply-to: hanlonr at cox.net
  • Sender: owner-wri-mathgroup at wolfram.com

I over simplified the starting point.  This is a better start

Clear[mySqrt];
mySqrt[a_.*x_^n_?EvenQ]:=
    mySqrt[a]*x^(n/2);
mySqrt[a_.*x_^n_?OddQ]:=
    mySqrt[a*x]*x^((n-1)/2);
mySqrt[a_*b_]:=
    mySqrt[a]*mySqrt[b];
mySqrt[a_?AtomQ]:=
    Sqrt[a];

convertSqrt=
    Power[x_,Rational[1,2]]:>mySqrt[x];

{Sqrt[x^2],Sqrt[a*x^2],Sqrt[a*x^5],Sqrt[a*Pi*
    x^6],Sqrt[Pi*x^5*y^6]}/.convertSqrt

{x, Sqrt[a]*x, Sqrt[a]*x^(5/2), Sqrt[a]*Sqrt[Pi]*x^3, 
  Sqrt[Pi]*x^(5/2)*y^3}


Bob Hanlon

> 
> From: Bob Hanlon <hanlonr at cox.net>
To: mathgroup at smc.vnet.net
> Date: 2005/10/12 Wed AM 09:58:43 EDT
> To: "Francisco Javier" <pacoga at ctv.es>, <mathgroup at smc.vnet.net>
> Subject: [mg61226] Re: [mg61189] Re: sqrt(x^2) = x
> 
> Changing the definition of a built-in function is dangerous since it may 
have 
> unintended side effects. I recommend that you use something like
> 
> Clear[mySqrt];
> mySqrt[a_.*x_^2]:=mySqrt[a]*x;
> mySqrt[a_?AtomQ]:=Sqrt[a];
> 
> convertSqrt=Power[x_,Rational[1,2]]:>mySqrt[x];
> 
> {Sqrt[x^2],Sqrt[a*x^2],Sqrt[Pi*x^2*y^2]}/.convertSqrt
> 
> {x, Sqrt[a]*x, Sqrt[Pi]*x*y}
> 
> 
> Bob Hanlon
> 
> > 
> > From: "Francisco Javier" <pacoga at ctv.es>
To: mathgroup at smc.vnet.net
> > Date: 2005/10/12 Wed AM 01:42:23 EDT
> > Subject: [mg61226] [mg61189] Re: sqrt(x^2) = x
> > 
> > Francisco Javier a formulé ce martes :
> > > Dear all, I am new in this group
> > >
> > > How can I tell Mathematica that I want to simplify all expressions like 
> > > Sqrt[x^2] as x, whithout taking into account that x is or not a 
> > > positive real number?
> > >
> > > Thank you very much
> > 
> > Dear F.Jaccard and Ruth for your answers, but what I really mean has 
> > not a such simple solution.
> > 
> > I want to "teach" to Mathematica that in next calculations Sqrt[x^2] is 
> > equivalent to x,
> > 
> > I have tried
> > 
> > Unprotect[Sqrt];
> > Sqrt[(x_)^2] := x;
> > 
> > This seems works fine then with calculations like
> > 
> > Sqrt[y^2]
> > y
> > 
> > but it fails with
> > 
> > Sqrt[x^2 y^4]
> > 
> > or even with
> > 
> > Sqrt[x^2 y^4]
> > 
> > Any ideas?
> > 
> > -- 
> > ----
> > Francisco Javier García Capitán
> > http://garciacapitan.auna.com
> > 
> > 
> 
> 


  • Prev by Date: Re: Language vs. Library why it matters
  • Next by Date: Re: Re: Language vs. Library
  • Previous by thread: Re: Re: sqrt(x^2) = x
  • Next by thread: help on MVSET