RE: Re[a + I b] = a
- To: mathgroup@smc.vnet.net
- Subject: [mg10683] RE: [mg10636] Re[a + I b] = a
- From: Ersek_Ted%PAX1A@mr.nawcad.navy.mil
- Date: Fri, 30 Jan 1998 04:24:21 -0500
A member of the group wanted to do the following: | |> for (n) an integer number Sin[n x] results 0 |> | Dave Wothoff (of Wolfram Research) replied with: | |Algorithmically, this is a much harder (and largely unsolved) problem. |If your needs are not too elaborate, though, you may be able to program |it yourself, as in | |In[4]:= Unprotect[Sin] ; | |In[5]:= Sin[p_ Pi] := 0 /; IntegerQ[p] | |In[6]:= Protect[Sin] ; | |In[7]:= IntegerQ[n] ^= True ; | |In[8]:= Sin[n Pi] | |Out[8]= 0 | | Dave, Please be patient and read on. The lines below are a small part of a package I am working on. Why doesn't Mathematica have the Rules below and many more built in? I doubt Mathematica will ever have all known transformations stored in a list of Rules, but I would think Wolfram Research could easily provide lists with many of the important Rules. You say "Algorithmically, this is a much harder (and largely unsolved) problem". I don't understand. Can you give me an example of why this is very difficult to achieve. Ted Ersek (Mathematica Input, Output with remarks below) ---------------------------------------------------------- RealNumericQ[expr], and VariableQ[expr] are useful in and of themselves. The function names pretty much explain what they do. In[1]:= RealNumericQ[expr_?NumericQ]:= FreeQ[ComplexExpand[expr,TargetFunctions->{Re,Im}],Complex[_,_]]/; FreeQ[expr,_?VaribleQ,{-1},Heads->False] VaribleQ[symb_]:=(Head@symb===Symbol)&&Not@NumericQ[symb] In the next Cell ArcSin[7] doesn't simplify, but RealNumericQ knows it's Complex. However it is not known if (Sqrt[x]+Sin[7]) is Complex. In[3]:= Clear[x]; {RealNumericQ[Sqrt[2]+ArcSin[1/7]], RealNumericQ[Sqrt[2]+ArcSin[7]], RealNumericQ[Sqrt[x]+Sin[7]]} Out[3]= {True, False, RealNumericQ[Sqrt[x] + Sin[7]]} Note: My command Declare[.....] is an extension of a package in mathsource. In[4]:= AssumedInterval[x_]:=x SetAttributes[Declare, HoldAll] Declare[x_Symbol,IntegerQ]/;(NumericQ[x]===False):= (AssumedInterval[x]^=Interval[{-Infinity,Infinity}]; IntegerQ[x]^=True;) Declare[x_Symbol,Positive]/;(NumericQ[x]===False):= (AssumedInterval[x]^=Interval[{0,Infinity}]; Sign[x]^=1;) Declare[LessEqual[a_?RealNumericQ,x_?VaribleQ,b_?RealNumericQ]]/; (a<b):= (AssumedInterval[x]^=Interval[{a,b}]) In[9]:= RuleList={ Sin[_?IntegerQ*Pi]:>0, Cos[_?EvenQ*Pi]:>1, Cos[_?OddQ*Pi]:>-1, Sign[x_?VaribleQ]/;(Min[AssumedInterval[x]]>0):>1, Sign[x_?VaribleQ]/;(Max[AssumedInterval[x]]<0):>-1, Arg[x_?VaribleQ]/;((Sign[x]/.RuleList)===1):>0, Arg[x_?VaribleQ]/;((Sign[x]/.RuleList)===-1):>-1, Positive[x_?VaribleQ]/;((Sign[x]/.RuleList)===1):>True, Positive[x_?VaribleQ]/;((Sign[x]/.RuleList)!=1):>False, Sqrt[x_^n_]/;(n*(Arg[x]/.RuleList)<=Pi):>x^(n/2) }; Note: The Rules for simplifying expressions don't slow down normal evaluation. They are only used when called on. In[10]:= Clear[n]; Declare[n,IntegerQ]; {Sin[n Pi], Sin[n Pi]/.RuleList} Out[10]= {Sin[n*Pi], 0} Note: The UpValue for Sign[x] also effects the result of Positive[x]. In[11]:= Clear[x]; Declare[x,Positive]; {Sign[x], Positive[x]} Out[11]= {1,True} After I Declare that (a) is in a Positive Interval, the RuleList knows how to handle Arg[a], Sign[a], Positive[a]. In[12]:= Clear[a]; Declare[Sqrt[3]<=a<=Sqrt[6]]; {Arg[a]/.RuleList, Sign[a]/.RuleList, Positive[a]/.RuleList} Out[12]= {0,1,True} RuleList also knows when Sqrt[x^n] can be simplified. In[13]:= Sqrt[a^2]/.RuleList Out[13]= a In[14]:= Clear[z]; Arg[z]^=Pi/6; Sqrt[z^4]/.RuleList Out[14]= z^2