MathGroup Archive 1993

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

Search the Archive

Re: test for "evenness" and "oddness"

  • To: mathgroup at, gray at
  • Subject: Re: test for "evenness" and "oddness"
  • From: jacobson at
  • Date: Mon, 25 Jan 93 09:11:56 -0800

Gary L. Gray asks

> I have a number of expression that are functions of some
> variable, say x.  I would like to be able to test each of
> those functions to see whether they are odd or even in the
> variable x and then eliminate (maybe set to zero) those
> functions that are even.  I have not been able to find a
> Mathematica function that will test for "evenness" or
> "oddness" with respect to a variable or variables.  Does

How about this:

EvenFunctionQ[f_,var_] := TrueQ[Simplify[f - (f/. var -> -var)] == 0]

OddFunctionQ[f_,var_] := TrueQ[Simplify[f + (f/. var -> -var)] == 0]

Actually f is an expression, not a function.  Var is the variable that
you want to test.

Here are some examples:

In[6]:= EvenFunctionQ[x^4*y,x]

Out[6]= True

In[7]:= EvenFunctionQ[x^4*y,y]

Out[7]= False

In[9]:= OddFunctionQ[Sin[x],x]

Out[9]= True

  -- David Jacobson

  • Prev by Date: Re: Exporting Mathematica output to word processing program
  • Next by Date: EllipticTheta[3,real,Exp[I real] ]
  • Previous by thread: test for "evenness" and "oddness"
  • Next by thread: Re: Bug in x11ps (was: contour graphics)