enter image description here Can someone explain why the 0, True occurs?

As a second question, I like to fill the endpoints as follows:

Plot[f[x], {x, -2, 2},
 Epilog -> {Blue, PointSize[Large],
   Point[{{-1, 3}, {-1, -1}, {1, 1}, {1, 0}}],
   White, PointSize[Medium],
   Point[{{-1, 3}, {1, 1}}]

enter image description here

Does anyone use an easier method for filled and unfilled endpoints?

Update: A lot of folks mentioned the possibility that x could be a complex number. I gave that a try. Watch what happened.

enter image description here

So I still am not sure how to explain this 0, True situation to my students.

  • 2
    $\begingroup$ It's a default added automatically to the end of Piecewise. If none of the conditions above it evaluate to True, then the last condition automatically evaluates to True, and the function spits out a 0. You can change that default by explicitly putting in, say {-1, True}. Piecewise tests its arguments in order: for example, ponder on the output when you evaluate Piecewise[{{-1, True}, {1, x > 0}}]. $\endgroup$
    – march
    Dec 17, 2015 at 4:20
  • 1
    $\begingroup$ As for your update, see this post. $\endgroup$
    – march
    Dec 17, 2015 at 5:09
  • 2
    $\begingroup$ What happens when you let x be a complex number? It will default to 0 in that case. $\endgroup$
    – Greg Hurst
    Dec 17, 2015 at 5:11
  • 1
    $\begingroup$ I can only speculate, but I imagine it's because there might be some problems with checking to see if all the conditions cover every possible value of x. There might also be something about the implementation of Piecewise that makes that sort of thing difficult. For possible hints of that, take your f[x], Simplify it, and look at the output. $\endgroup$
    – march
    Dec 17, 2015 at 6:09
  • 4
    $\begingroup$ "every possible value of $x$" - I don't see your construction covering complex arguments; recall that Mathematica assumes everything is complex unless told otherwise. $\endgroup$ Dec 17, 2015 at 6:43

1 Answer 1


Help says:

Piecewise[conds] automatically evaluates to Piecewise[conds,0].

This implies that the default {0, True} item is added to the Piecewise. It is the same as if you wrote

f[x_] = Piecewise[{{2 - x, x < -1}, {x, -1 <= x < 1}, {(x - 1)^2, x >= 1}, {0, True}}]

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.