# Piecewise

Piecewise[{{val1,cond1},{val2,cond2},}]

represents a piecewise function with values vali in the regions defined by the conditions condi.

Piecewise[{{val1,cond1},},val]

uses default value val if none of the condi apply. The default for val is 0.

# Details

• The condi are typically inequalities such as .
• The condi are evaluated in turn, until one of them is found to yield True.
• If all preceding condi yield False, then the vali corresponding to the first condi that yields True is returned as the value of the piecewise function.
• If any of the preceding condi do not literally yield False, the Piecewise function is returned in symbolic form.
• Only those vali explicitly included in the returned form are evaluated.
• Elements of the form {vali,False} are dropped, as are all elements after the first {vali,True}.
• Piecewise[conds] automatically evaluates to Piecewise[conds,0].
• Piecewise can be used in such functions as Integrate, Minimize, Reduce, DSolve, and Simplify, as well as their numeric analogs.
• Piecewise[{{v1,c1},{v2,c2},}] can be input in the form  v1 c1 v2 c2 …
. The piecewise operator can be entered as pw or \[Piecewise]. The grid of values and conditions can be constructed by first entering , then using and .
• In StandardForm and TraditionalForm, Piecewise[{{v1,c1},{v2,c2},}] is normally output using a brace, as in  v1 c1 v2 c2 …
.

# Examples

open allclose all

## Basic Examples(3)

Set up a piecewise function with different pieces below and above zero:

 In[1]:=
 Out[1]=

Find the derivative of a piecewise function:

 In[1]:=
 Out[1]=

Use pw to enter and and then for each additional piecewise case:

 In[1]:=
 Out[1]//InputForm=