Re: Simplifying Problems
- To: mathgroup at smc.vnet.net
- Subject: [mg22409] Re: Simplifying Problems
- From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
- Date: Wed, 1 Mar 2000 00:39:58 -0500 (EST)
- Organization: Universitaet Leipzig
- References: <89ce39$brr@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Hi,
> ------------------------
> 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]
f[k] /. Sin[k_*Pi]/k_ /; IntegerQ[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
This "declare" nothing. It is usesless like "declare" 2+2
Look at this session
In[]:= j \[Element] Integers;
In[]:= Simplify[Sin[j \[Pi]]]
Out[]=Sin[j \[Pi]]
you see nothing is declared. You should make a global list
of types like
$domains={Element[{i,j,k},Integers], Element[z,Complexes]}
ans use
Simplify[somthing, $domains]
The domain definition via Element[] is not connected a symbol.
Only inside Simplify[], FullSimplify[] and FunctionExpand[]
the domain definitions are used.
>
> 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?
The good old way:
x /: IntegerQ[x] := True
f[x_?IntegerQ] := x + 2
will work.
Hope that helps
Jens