Re: Simplifying Problems
- To: mathgroup at smc.vnet.net
- Subject: [mg22402] Re: [mg22392] Simplifying Problems
- From: Andrzej Kozlowski <andrzej at tuins.ac.jp>
- Date: Wed, 1 Mar 2000 00:39:51 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
on 2/28/00 12:55 AM, Jordan Rosenthal at jr at ece.gatech.edu wrote: > Hi all, > > Two questions: > > ------------------------ > First question: > ------------------------ > I have an expression which has a sum of a number of sinc-like terms. For > example, > > f[k] = Sin[k Pi] / k > > If I try using simplify with the assumption that k is an integer I get > > In[2]:= > Simplify[f[k], k \[Element] Integers] > > Out[2]= > 0 > > Although this is true for most integers, it is incorrect for the integer > k==0 since f[0] = Pi. So why is this happening? I would have expected it > to either leave the expression untouched or to give me an If expression. > > What I would like is to be able to convert the expression to > > If[ k==0, Pi, 0] > > What is the best way to do this? I can setup a rule like: > > f[k] /. Sin[k_*Pi]/k_ -> If[k == 0, Pi, 0] > > but my problem is that this does not account for the fact that the pattern > k_ must be an integer. How do I include that information? (See my second > question for why I can't just use k_?IntegerQ). > > ------------------------ > Second question: > ------------------------ > Let's say I declare a variable to be an Integer with > > j \[Element] Integers > > Now I set up a function which should only work on integers > > f[x_?IntegerQ] = x+2 > > This, however, does not recognize that the variable j has been declared an > integer: > > In[3]:= > f[2] > > Out[3]= > 4 > > In[4]:= > f[j] > > Out[4]= > f[j] > > Is there a way I can get the function to work for variables declared as > integers with the Element function? > > > Any help is appreciated. Thanks, > > Jordan > > ************************************************** I just send my reply to your message and then noticed that the main part was missing. Sorry about that. I am resending it again. ****************************************************** First question. Actually, though this may sound pedantic, it is not strictly true that Sin[0]/0 is 1. The expression is undefined: what is true that the limit of Sin[x]/x is 1 as x ->0. This distinction is often ignored by applied mathematicians, but convenience is not quite the same as mathematical correctness! Still, there are good rounds for arguing that in a program like Mathematica convenience should take precedence. Moreover, the answer given by Simplify[Sin[Pi*k]/k,Element[k,Integers] is definitely incorrect for k=0. So some time ago I made exactly your point on this list and received and received the following reply from David Withoff <withoff at wolfram.com>: > You may be interested to know that this is not currently considered a > bug in Simplify. The Simplify function only adds transformations. It > does not disable transformations that would already have been done by > the system without Simplify. > > To underscore this point, consider > > In[1]:= Simplify[0/x, x==0] > > Out[1]= 0 > > To behave otherwise the Simplify function would need to implement its > own system of algebra. There are not currently any plans to do that. > > Similar observations apply to a wide variety of calculations. I was not quite satisfied with the above since it is not difficult to modify Simplify to behave the way you suggest. Below are two ways to do so. One is based on modifying Mathematica 4.0's Assumptions mechanism: In[1]:= Unprotect[Simplify]; In[3]:= Simplify[expr_, {___, Element[k_, Integers], ___}] := expr /. Sin[k*Pi]/k :> If[k == 0, Pi, 0] In[5]:= Protect[Simplify]; In[7]:= Simplify[Sin[k*Pi]/k, {Element[k, Integers]}] Out[7]= If[k == 0, \[Pi], 0] Next, comes a pre-Mathematica 4.0 version: In[1]:= Unprotect[Simplify]; In[2]:= Simplify[expr_] := expr /. Sin[k_?IntegerQ*Pi]/k_ :> If[k == 0, Pi, 0] In[3]:= Protect[Simplify]; In[4]:= i /: IntegerQ[i] = True; In[5]:= Simplify[Sin[Pi*i]/i] Out[5]= If[i == 0, \[Pi], 0] Note that, however, in either case: In[6]:= Simplify[Sin[Pi*0]/0] \!\(Power::"infy" \(\(:\)\(\ \)\) "Infinite expression \!\(1\/0\) encountered."\) \[Infinity]::"indet": "Indeterminate expression \!\(0\\ \ \*InterpretationBox[\"ComplexInfinity\", DirectedInfinity[]]\) encountered." Out[6]= Indeterminate which is strictly speaking correct and is just the point David Withoff was making. -- Andrzej Kozlowski Toyama International University JAPAN http://sigma.tuins.ac.jp