[Date Index] [Thread Index] [Author Index]
Re: test for "evenness" and "oddness"
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:= EvenFunctionQ[x^4*y,x] Out= True In:= EvenFunctionQ[x^4*y,y] Out= False In:= OddFunctionQ[Sin[x],x] Out= True -- David Jacobson