Adding a conditional definition to Sqrt.

• To: mathgroup at yoda.physics.unc.edu
• Subject: Adding a conditional definition to Sqrt.
• From: PRAVEEN at vtcs1.cs.vt.edu
• Date: Tue, 8 Sep 1992 12:19:49 -0400 (EDT)

```Hi Mathgroup,

I was trying to have Sqrt, the square root function simplify Sqrt[x^2] to x.
With the standard definition, the expression is returned unchanged. I
redifined Sqrt[x^y] to be x^(y/2) when y is an even integer. However, I find
that Mathematica does not use this definition all the time.

The following lines from
an interactive session should clarify my point. The first input lines are only
to show the functioning of the standard Sqrt function.

In[1]:= Sqrt[x^4]

4
Out[1]= Sqrt[x ]

In[2]:= Sqrt[4 x^4]

4
Out[2]= 2 Sqrt[x ]

In[3]:= Unprotect[Sqrt]

Out[3]= {Sqrt}

In[4]:= Sqrt[x_^y_] := x^(y/2)/;EvenQ[y]

In[5]:= Protect[Sqrt]

Out[5]= {Sqrt}

In[6]:= Sqrt[x^4]

2
Out[6]= x

In[7]:= Sqrt[4 x^4]

4
Out[7]= 2 Sqrt[x ]

In[8]:= 2 Sqrt[x^4]

2
Out[8]= 2 x

I would very much appreciate if some one could point out what I am missing,
else if there is any other way of resolving this.