Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

For example, if I have Piecewise[{{x^2, x < 0}, {x, x > 0}}], how do I select only the function that is for x < 0? I want to set a new function equal to the x^2 only, not the entire piecewise function.

share|improve this question

You can use, for example

Refine[Piecewise[{{x^2, x < 0}, {x, x > 0}}], x < 0]
share|improve this answer

As you may know, Part ([[ ]]) works on non-lists as well. So, you can index your Piecewise like so:

Piecewise[{{x^2, x < 0}, {x, x > 0}}][[1, 1, 1]]


With Cases you can pick out the part with a specific condition:

Cases[Piecewise[{{x^2, x < 0}, {x, x > 0}}], {a_, x < 0} -> a, {2}] // First


share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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