5
$\begingroup$

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?

$\endgroup$
  • 2
    $\begingroup$ Use SameQ instead of Equal $\endgroup$ – Algohi May 22 '15 at 20:52
  • 1
    $\begingroup$ i am a she btw :3 $\endgroup$ – baloo May 22 '15 at 20:59
  • 2
    $\begingroup$ @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) $\endgroup$ – Mr.Wizard May 22 '15 at 21:03
  • 1
    $\begingroup$ @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. $\endgroup$ – C. E. May 22 '15 at 21:07
  • 1
    $\begingroup$ @Pickett localSet from (1992) makes such uses worry-free; I hope you'll consider using it if you do that often. $\endgroup$ – Mr.Wizard May 22 '15 at 21:14
6
$\begingroup$

Rather than imposing x>0 one can also do

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

which yields False.

| improve this answer | |
$\endgroup$
  • 2
    $\begingroup$ Any thoughts about using Resolve in place of FullSimplify here? (p.s. I am out of votes for the day or I would upvote.) $\endgroup$ – Mr.Wizard May 22 '15 at 22:20
  • $\begingroup$ i like this answer the most. intuitive, simple.. Thanks :) $\endgroup$ – baloo May 22 '15 at 22:20
  • $\begingroup$ *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. $\endgroup$ – baloo May 22 '15 at 22:28
  • 1
    $\begingroup$ @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! $\endgroup$ – evanb May 22 '15 at 22:54
  • $\begingroup$ 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? $\endgroup$ – Mr.Wizard May 22 '15 at 22:56
7
$\begingroup$
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}

| improve this answer | |
$\endgroup$
  • $\begingroup$ 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. $\endgroup$ – evanb May 22 '15 at 22:05
  • $\begingroup$ @evanb, thank you; it looks like we don't need the assumption. $\endgroup$ – kglr May 22 '15 at 22:20
4
$\begingroup$

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
| improve this answer | |
$\endgroup$
  • $\begingroup$ Please be careful with regards to functions of complex variables. $\endgroup$ – evanb May 22 '15 at 22:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.