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