# How is it possible to check if a function is even or odd?

I tried it like this:

myEvenFunction[x_] := x^2
Equal[myEvenFunction[x],myEvenFunction[-x]]
Out = x^2
Out = True

myOddFunction[x_] := x^3
Equal[myOddFunction[x], myOddFunction[-x]]
Out = x^3
Out = x^3 == -x^3


Shouldn't it say false here?

• Use SameQ instead of Equal – Algohi May 22 '15 at 20:52
• i am a she btw :3 – baloo May 22 '15 at 20:59
• @Bichoy Yes, it is unsafe, and it should only be used when needed. You can use Block in some cases to make it safe; see: (6664). If you have frequent need of this kind of protected evaluation see: (1992) – Mr.Wizard May 22 '15 at 21:03
• @Bichoy Yes, it's certainly not recommended. But sometimes if you know what you're doing, in rare cases, it can be used. For example when defining an interpolation you can do f[x_] = 5 + Interpolation[{1, 2, 3, 5, 8, 5}][x]. In this case you don't want to execute the expensive Interpolation function every time you call the function. This is just a toy example, I can't come up with a real world scenario right now but I seem to remember that I've seen some. – C. E. May 22 '15 at 21:07
• @Pickett localSet from (1992) makes such uses worry-free; I hope you'll consider using it if you do that often. – Mr.Wizard May 22 '15 at 21:14

Rather than imposing x>0 one can also do

FullSimplify[ ForAll[x, myOddFunction[x] == myOddFunction[-x]]]


which yields False.

• Any thoughts about using Resolve in place of FullSimplify here? (p.s. I am out of votes for the day or I would upvote.) – Mr.Wizard May 22 '15 at 22:20
• i like this answer the most. intuitive, simple.. Thanks :) – baloo May 22 '15 at 22:20
• *intuitional. Actually i had this in mind, but couldn't transform it into a piece of code. Thanks, again. ^^ I'll try it with Resolve too. – baloo May 22 '15 at 22:28
• @Mr.Wizard I don't have any thoughts about Resolve because I didn't know about it until your comment! So IDK :-P Thanks for the accept, @sudo_math! Welcome to Mma.SE! – evanb May 22 '15 at 22:54
• Okay. I think it may be faster but less robust than FullSimplify. With what I do I use ForAll so rarely that I don't have much experience with Resolve. Let me know what you find out if you remember, OK? – Mr.Wizard May 22 '15 at 22:56
evenFQ[f_] := Simplify[f[t] - f[-t]] === 0
oddFQ[f_] := Simplify[f[t] + f[-t]] === 0


Examples:

ef[x_] := x^2
of[x_] := x^3

evenFQ/@ {ef, of}


{True, False}

oddFQ/@ {ef, of}


{False, True}

evenFQ /@ {# &, Im, Sin, Tan, Sinh, Erf}


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

oddFQ /@ {# &, Im, Sin, Tan, Sinh, Erf}


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

• I'm concerned about the assumption that the arguments are real. evenFQ[Im] and oddFQ[Im] both give true, for example, while Im is really odd. – evanb May 22 '15 at 22:05
• @evanb, thank you; it looks like we don't need the assumption. – kglr May 22 '15 at 22:20

You need Simplify with an assumption:

myOddFunction[x_] := x^3;

Simplify[
Equal[myOddFunction[x], myOddFunction[-x]],
x > 0
]

False


Refine also works in this case, again with the appropriate assumption:

Refine[Equal[myOddFunction[x], myOddFunction[-x]], x > 0]

False

• Please be careful with regards to functions of complex variables. – evanb May 22 '15 at 22:05