Re: Simplifying Problems
- To: mathgroup at smc.vnet.net
- Subject: [mg22399] Re: [mg22392] Simplifying Problems
- From: BobHanlon at aol.com
- Date: Wed, 1 Mar 2000 00:39:47 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
Clear[j, k];
f[x_ /; x == 0] = Pi;
f[x_Integer] := 0;
f[x_?IntegerQ] := 0;
f[x_] := Sin[x*Pi]/x;
{f[0], f[1], f[j], f[k]}
{Pi, 0, Sin[j*Pi]/j, Sin[k*Pi]/k}
Simplify[f[k], Element[k, Integers]]
0
j /: IntegerQ[j] = True;
f[j]
0
Bob Hanlon
In a message dated 2/27/2000 8:14:50 PM, jr at ece.gatech.edu writes:
>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?
>