MathGroup Archive 1997

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

Search the Archive

Re [mg 7343] How to make Sqrt[a^2]/;(a>

  • To: mathgroup at smc.vnet.net
  • Subject: [mg7409] Re [mg 7343] How to make Sqrt[a^2]/;(a>
  • From: Ersek_Ted%PAX1A at mr.nawcad.navy.mil
  • Date: Fri, 30 May 1997 01:20:50 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

In  [mg 7343]  Carl needed to make Mma simplify Sqrt[a^2] to a
when "a" is a variable known to be Positive.

This was needed so he could make a power series and a limit come out right.
I am working on a nifty package that handles this.  Part of my package is 
shown below.

I tried to make my package completely correct mathematically speaking.
The many possible extensions to my package should be obvious.

          Ted Ersek

 ----------------------------------------------------------------------------  
 ---------------

In[1]:=
Assume[x_,Positive]/;(NumericQ[x]==False):=  (
   Positive[x]^=True;
   Negative[x]^=False;
   NonNegative[x]^=True;
   NonPositive[x]^=False;
   Im[x]^=0;
   x > y_    /;(y<=0)^=True;
   x >= y_ /;(y<=0)^=True;
   x < y_   /;(y<=0)^=False;
   x <= y_/;(y<=0)^=False;
   x == y_/;(y<=0)^=False;)

ClearAssume[x_]:=(
    x/:Positive[x]=.        ;
    x/:Negative[x]=.        ;
    x/:NonNegative[x]=.  ;
    x/:NonPositive[x]=.  ;
    x/:Im[x]=.                      ;
    x/:HoldPattern[x>y_/;  y<=0] =.   ;
    x/:HoldPattern[x>=y_/;y<=0 ] =.  ;
    x/:HoldPattern[x<y_/;  y<=0   ]=.   ;
    x/:HoldPattern[x<=y_/;y<=0 ] =.    ;
    x/:HoldPattern[x==y_/;y<=0]=.   ;    )

Unprotect[Sqrt,Power ];
   Sqrt[(x_)^(n_)]:=x^(n/2)/;(Positive[x]&&Im[n]==0);
   Sqrt[(x_)^(n_)]:=x^(n/2)/;(Im[x]==0&&EvenQ[n/2]);
   Sqrt[(x_)^(n_)]:=-x^(n/2)/;(Negative[x]&&OddQ[n/2]);
   ((x_)^a_)^b_:=x^(a b)/;(Positive[x]&&Im[a]==0&&Im[b]==0);
   ((x_)^a_)^b_:=-x^(a b)/;(Negative[x]&&EvenQ[a]&&OddQ[a b]);
Protect[Sqrt, Power ];
(*--------------------------------------------------------------------------  
 ------*)
In[4]:=   Assume[a,Positive]

(*  Now that a is "assumed"  Positive my package knows a lot about a.   *)

In[5]:=  {Positive[a], Negative[a], a>-4, a<=-Pi, a==-E}

Out[5]=  {True,False,True,False,False}
(*--------------------------------------------------------------------------  
 ------*)
(*  The rules I added for Sqrt allow Sqrt[a^2] to be simplified.   *)

In[6]:=  Sqrt[a^2]

Out[6]=  a
(*--------------------------------------------------------------------------  
 -------*)
(*   Now that Mma can simplify Sqrt[a^2] it can do the Series and Limit 
below.   *)

In[7]:=  Series[b^2/(a-Sqrt[a^2-b^2]), {b,0,2}]

Out[7]:=  2 a- b^2/(2 a) + O[b]^4


In[8]:=  Limit[b^2/(a-Sqrt[a^2-b^2]), b->0]

Out[8]=  2 a

(*--------------------------------------------------------------------------  
 ------*)
(*  Now I Clear the assumptions about a, and all the assumptions are 
removed.  *)

In[9]:=  ClearAssume[a]

In[10]:=  {Positive[s],Negative[s],s>-4, s<=-Pi, s==-E}

Out[10]=  {Positive[s],Negative[s],s>-4,s\[LessEqual]-\[Pi],s==-E}




  • Prev by Date: Abs and Sign anomolies
  • Next by Date: Re: Is there a better way to do a 3D List Plot?
  • Previous by thread: Re: Abs and Sign anomolies
  • Next by thread: Re: Re [mg 7343] How to make Sqrt[a^2]/;(a>