Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

sqrt(x^2) = x

0 views
Skip to first unread message

Francisco Javier

unread,
Oct 11, 2005, 4:00:16 AM10/11/05
to
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

--
----
Francisco Javier García Capitán
http://garciacapitan.auna.com

wtpl...@ehu.es

unread,
Oct 11, 2005, 4:53:26 AM10/11/05
to

Hi,

I think Refine[Sqrt[x^2],x>0]

is what you need.

Bye,

Ruth

Jens-Peer Kuska

unread,
Oct 11, 2005, 6:30:54 AM10/11/05
to
Hi,

Simplify[Sqrt[x^2], x > 0]

Regards
Jens

"Francisco Javier" <pac...@ctv.es> schrieb im
Newsbeitrag news:difreg$fg6$1...@smc.vnet.net...

Francisco Javier

unread,
Oct 12, 2005, 2:07:18 AM10/12/05
to
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?

curtis

unread,
Oct 12, 2005, 2:10:20 AM10/12/05
to
This *might* work for "simple" x -- I haven't tested it thoroughly.
Probably the gurus on the site will tell you about Hold on the sqrt
function. Anyway, on your output, try

output/.{Sqrt[a_^2]->a}

As far as I can tell, this will just pattern-match without regard as
to the positiveness or even realness of the argument a.

Cheers,
C.O.

Francisco Javier wrote:

>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
>
>
>

--
|=====
| Curtis Osterhoudt
| gard...@mail.wsu.edu
| PGP Key ID: 0x235FDED1
| Please avoid sending me Word or PowerPoint attachments.
| http://www.gnu.org/philosophy/no-word-attachments.html
|=====

Bill Rowe

unread,
Oct 12, 2005, 2:16:31 AM10/12/05
to
On 10/11/05 at 3:22 AM, pac...@ctv.es (Francisco Javier) wrote:

>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?

PowerExpand will do what you want, i.e.,

In[20]:= PowerExpand[Sqrt[x^2]]
Out[20]= x

This tranformation is not included amoung the tranformations applied by Simplify or FullSimplify since it is not valid for all possible values of x.
--
To reply via email subtract one hundred and four

Bob Hanlon

unread,
Oct 13, 2005, 1:55:34 AM10/13/05
to
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" <pac...@ctv.es>
> Date: 2005/10/12 Wed AM 01:42:23 EDT
> Subject: 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?
> >

Bob Hanlon

unread,
Oct 13, 2005, 1:57:09 AM10/13/05
to
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

0 new messages