MathGroup Archive 1998

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Re: How to declare Integers?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg13072] Re: [mg13013] Re: How to declare Integers?
  • From: BobHanlon at aol.com
  • Date: Sat, 4 Jul 1998 16:45:11 -0400
  • Sender: owner-wri-mathgroup at wolfram.com

Tri,

There are some problems with your definitions, specifically:

Cos[m_ * Pi] /; IntegerQ[m] = 1;
Sin[m_ * Pi + x_] /; IntegerQ[m] = Sin[x]; Cos[m_ * Pi + x_] /;
IntegerQ[m] = Cos[x];

The correct definitions follow:

Unprotect[Sin, Cos];

Sin[m_ * Pi + x_:0] /; IntegerQ[m] && EvenQ[m] := Sin[x]; Sin[m_ * Pi +
x_:0] /; IntegerQ[m] && OddQ[m] := -Sin[x]; Sin[m_ * Pi + x_:0] /;
IntegerQ[m] := (-1)^m * Sin[x];

Cos[m_ * Pi + x_:0] /; IntegerQ[m] && EvenQ[m] := Cos[x]; Cos[m_ * Pi +
x_:0] /; IntegerQ[m] && OddQ[m] := -Cos[x]; Cos[m_ * Pi + x_:0] /;
IntegerQ[m] := (-1)^m * Cos[x];

Cos[m_ * Pi/2 + x_:0] /; IntegerQ[m] && EvenQ[m] := 
	(-1)^(m/2) * Cos[x];
Cos[m_ * Pi/2 + x_:0] /; IntegerQ[m] && OddQ[m] := 
	I * (-1)^(m/2) * Sin[x];
	
Sin[m_ * Pi/2 + x_:0] /; IntegerQ[m] && EvenQ[m] := 
	(-1)^(m/2) * Sin[x];
Sin[m_ * Pi/2 + x_:0] /; IntegerQ[m] && OddQ[m] := 
	-I * (-1)^(m/2) * Cos[x];
	
Protect[Sin, Cos];

defineEven[n_Symbol] := Module[{},
	n/: IntegerQ[n] = True;
	n/: EvenQ[n] = True;
	n/: OddQ[n] = False;
	n/: (-1)^n = 1;]

defineOdd[n_Symbol] := Module[{},
	n/: IntegerQ[n] = True;
	n/: OddQ[n] = True;
	n/: EvenQ[n] = False;
	n/: (-1)^n = -1;]
	
Unprotect[IntegerQ];

IntegerQ[m_?IntegerQ + n_?IntegerQ] = True; IntegerQ[m_?IntegerQ *
n_?IntegerQ] = True; IntegerQ[(m_?IntegerQ)^(n_ /; IntegerQ[n] &&
(Positive[n] || NonNegative[n]))] = True;

Protect[IntegerQ];

n /: IntegerQ[n] = True;
n /: Positive[n] = True;
m /: IntegerQ[m] = True;
k /: IntegerQ[k] = True;
k /: NonNegative[k] = True;

{IntegerQ[m+n], IntegerQ[m-n], IntegerQ[m*n], IntegerQ[m^n],
IntegerQ[m^k], IntegerQ[n^m], IntegerQ[m*(n-1)*(n+1)]}

{True,True,True,True,True,False,True}

Clear[m]; m /: IntegerQ[m] = True;
{Sin[m * Pi + x], Sin[m * Pi], Cos[m * Pi + x], Cos[m * Pi]}

{(-1)^m*Sin[x], 0, (-1)^m*Cos[x], (-1)^m}

Clear[m]; defineEven[m];
{Sin[m * Pi + x], Sin[m * Pi], Cos[m * Pi + x], Cos[m * Pi]}

{Sin[x],0,Cos[x],1}

Clear[m]; defineOdd[m];
{Sin[m * Pi + x], Sin[m * Pi], Cos[m * Pi + x], Cos[m * Pi]}

{-Sin[x],0,-Cos[x],-1}

Clear[m]; defineEven[m];
{Sin[m * Pi/2 + x], Sin[m * Pi/2], Cos[m * Pi/2 + x], Cos[m * Pi/2]}

{(-1)^(m/2)*Sin[x], 0, (-1)^(m/2)*Cos[x], (-1)^(m/2)}

Clear[m]; defineOdd[m];
{Sin[m * Pi/2 + x], Sin[m * Pi/2], Cos[m * Pi/2 + x], Cos[m * Pi/2]}

{-I*(-1)^(m/2)*Cos[x], -I*(-1)^(m/2), I*(-1)^(m/2)*Sin[x], 0}

Bob Hanlon

In a message dated 6/30/98 4:48:43 AM, lvtri at cs.uwm.edu wrote:

>Hi Carlos, it is interesting to try this:
>
>Unprotect[IntegerQ];
>IntegerQ[m_+n_]/;IntegerQ[m]&&IntegerQ[n]=True;
>IntegerQ[m_*n_]/;IntegerQ[m]&&IntegerQ[n]=True;
>IntegerQ[m_^n_]/;IntegerQ[m]&&IntegerQ[n]&&Positive[n]=True;
>Unprotect[Sin,Cos];
>Sin[m_*Pi]/;IntegerQ[m]=0;
>Cos[m_*Pi]/;IntegerQ[m]=1;
>Sin[m_*Pi+x_]/;IntegerQ[m]=Sin[x];
>Cos[m_*Pi+x_]/;IntegerQ[m]=Cos[x];
>
>This should work for any simple expressions for you. How ever, more will
>be involved if you need to do things like this:
>  IntegerQ[m]=True;
>  IntegerQ[n*n]=True;
>Should IntegerQ[m*(n-1)*(n+1)] return True ? I dont know how to do it
>yet :)
>Tri.
>
>Carlos Wexler wrote in message <6n4op4$njn at smc.vnet.net>...
>>
>>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.
>>
>>Thanks!!


  • Prev by Date: Problems with interpolating
  • Next by Date: Re: MaxBend in ParametricPlot?
  • Previous by thread: Re: Re: How to declare Integers?
  • Next by thread: Re: How to declare Integers?