Why “is $f(x)$ an odd function?” does not work with this function?

We know that $$f(x)$$ is odd if $$-f(x)=f(-x)$$. The function is $$f(x)=\begin{cases}2x-1&\text{if -2 Now I want to know if $$f$$ is odd, so I query to WA is Piecewise[{{2x-1,-2<x<0},{2x+1,0<=x<=2}}] an odd function?:  Now, if we query plot -Piecewise[{{2x-1,-2<x<0},{2x+1,0<=x<=2}}] from -2 to 2 then we see the graph of $$-f(x)$$: If we query plot Piecewise[{{2(-x)-1,-2<-x<0},{2(-x)+1,0<=-x<=2}}] from -2 to 2 then we obtain $$f(-x)$$: As the plots are the same, then $$-f(x)=f(-x)$$, so the function is odd.

However in the first input, WA did not recognize that. Why?

• $f(0)=1{{{}}}$. – Lord Shark the Unknown May 19 at 5:26
• @LordSharktheUnknown that is true, thanks. – manooooh May 19 at 5:33

As noted in the comments, $$f(0)=1 \ne -f(-0)$$. Also, the domain you have specified for $$f$$ includes $$2$$ but not $$-2$$. Mathematica's Piecewise functions have zero as a default value (you can actually see this in your first plot), and so your function has $$f(-2)=0$$ but $$f(2)=5$$.
• Thanks! Got it. However, this question comes from this other, where the given function includes the $=$ to a part of the piecewise function, so I guess we need to find another expression instead of $2x-1$ to make it odd. – manooooh May 19 at 5:45
The definition of odd function requires first that $$-x$$ be in the domain of the function whenever $$x$$ is. In your example, $$2$$ is in the domain but $$-2$$ is not, so it couldn't be odd. Also, for any odd function, it follows that $$f(-0)=f(0)=-f(0)\implies f(0)=0.$$ This, however, is not the case with your function. These are the two characteristics that prevent it from being odd.
• Thanks! Got it. However, this question comes from this other, where the given function includes the $=$ to a part of the piecewise function, so I guess we need to find another expression instead of $2x-1$ to make it odd. – manooooh May 19 at 5:47