[Date Index]
[Thread Index]
[Author Index]
Re: How to declare Integers?
*To*: mathgroup at smc.vnet.net
*Subject*: [mg13010] Re: [mg12966] How to declare Integers?
*From*: BobHanlon at aol.com
*Date*: Tue, 30 Jun 1998 00:26:07 -0400
*Sender*: owner-wri-mathgroup at wolfram.com
Carlos,
The issue is not with whether or not Mathematica knows whether m is an
integer, since even after you told it that m is an integer it still did
not know the integral. Obviously, it does not know the value of the
integral for the general case of m being an integer. If you expect to
encounter this integral frequently, tell it the answer. However, there
are a number of special cases which you then would then want it to
treat smartly:
Unprotect[Integrate];
Integrate[Sin[(m_)?EvenQ*(x_)]/Sin[x_],
{x_, 0, Pi}] := 0;
Integrate[Sin[(m_)?OddQ*(x_)]/Sin[x_],
{x_, 0, Pi}] :=
Pi /; Positive[m]||NonNegative[m];
Integrate[Sin[(m_)?OddQ*(x_)]/Sin[x_],
{x_, 0, Pi}] := -Pi /; Negative[m];
Integrate[Sin[(m_)?OddQ*(x_)]/Sin[x_],
{x_, 0, Pi}] := Sign[m]*Pi;
Integrate[Sin[(m_)?IntegerQ*(x_)]/Sin[x_],
{x_, 0, Pi}] :=
(1 - (-1)^m)/2*Pi /; Positive[m]||NonNegative[m];
Integrate[Sin[(m_)?IntegerQ*(x_)]/Sin[x_],
{x_, 0, Pi}] :=
(-1 + (-1)^m)/2*Pi /; Negative[m];
Integrate[Sin[(m_)?IntegerQ*(x_)]/Sin[x_],
{x_, 0, Pi}] := (1 - (-1)^m)/2*Sign[m]*Pi; Protect[Integrate];
n1/: IntegerQ[n1] = True;
Integrate[Sin[n1*x]/Sin[x], {x, 0, Pi}] Table[%, {n1, -5, 5}]
1/2*(1 - (-1)^n1)*Pi*Sign[n1]
{-Pi, 0, -Pi, 0, -Pi, 0, Pi, 0, Pi, 0, Pi}
n2/: EvenQ[n2] = True;
Integrate[Sin[n2*x]/Sin[x], {x, 0, Pi}]
0
n3/: OddQ[n3] = True;
Integrate[Sin[n3*x]/Sin[x], {x, 0, Pi}]
Pi*Sign[n3]
n4/: OddQ[n4] = True;
n4/: Positive[n4] = True;
Integrate[Sin[n4*x]/Sin[x], {x, 0, Pi}]
Pi
n5/: OddQ[n5] = True;
n5/: NonNegative[n5] = True;
Integrate[Sin[n5*x]/Sin[x], {x, 0, Pi}]
Pi
n6/: OddQ[n6] = True;
n6/: Negative[n6] = True;
Integrate[Sin[n6*x]/Sin[x], {x, 0, Pi}]
-Pi
n7/: IntegerQ[n7] = True;
n7/: Positive[n7] = True;
Integrate[Sin[n7*x]/Sin[x], {x, 0, Pi}]
1/2*(1 - (-1)^n7)*Pi
n8/: IntegerQ[n8] = True;
n8/: Negative[n8] = True;
Integrate[Sin[n8*x]/Sin[x], {x, 0, Pi}]
1/2*(-1 + (-1)^n8)*Pi
n9/: IntegerQ[n9] = True;
n9/: NonNegative[n9] = True;
Integrate[Sin[n9*x]/Sin[x], {x, 0, Pi}]
1/2*(1 - (-1)^n9)*Pi
I suspect this is why Mathematica does not handle all of the obvious
special cases for its large number of functions.
Bob Hanlon
In a message dated 6/28/98 6:09:36 AM, wexler at einstein.phys.ufl.edu
wrote:
>How can one declare a variable to be integer in Mathematica?
>
>Let me just give an example:
>
> Integrate[Sin[m x]/Sin[x], {x,0,Pi}]
>
>is well behaved if one explicitly sets m=1,2,3,... BEFORE doing the
>integral:
>
>In[1]:= Integrate[Sin[1 x]/Sin[x], {x,0,Pi}] Out[1]= Pi
>
>In[2]:= Integrate[Sin[2 x]/Sin[x], {x,0,Pi}] Out[2]= 0
>
>but
>
>In[3]:= Integrate[Sin[m x]/Sin[x], {x,0,Pi}] Out[3]= Integrate::"idiv":
> Integral of Csc[x] Sin[m x] does not converge on {0,Pi}
>
>Other examples include evaluation of Sin[m Pi], etc...
>
>I tried the following trick stated in the manual:
>
>In[4]:= m/: IntegerQ[m] = True
>Out[4]= True
>
>but still Sin[m Pi] does not simplify to 0 nor does Mathematica figures
>out that the integral above does converge in this case.
>
>How can one declare m to be integer? There has to be a way! In Maple it
>is rather easy and the expected behavior is obtained. I cannot believe
>that it is not possible to accomplish the same in Mathematica as well.
Prev by Date:
**Re: multivariable functins with variable number of arguments**
Next by Date:
**Integer declaration**
Previous by thread:
**Re: How to declare Integers?**
Next by thread:
**Re: How to declare Integers?**
| |