Re: test for "evenness" and "oddness"
- To: mathgroup at yoda.physics.unc.edu, gray at cmgroup.engr.wisc.edu
- Subject: Re: test for "evenness" and "oddness"
- From: jacobson at cello.hpl.hp.com
- 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