This is documentation for Mathematica 8, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.1)

Piecewise

Piecewise
represents a piecewise function with values in the regions defined by the conditions .
Piecewise
uses default value val if none of the apply. The default for val is .
  • The are typically inequalities such as .
  • The are evaluated in turn, until one of them is found to yield True.
  • If all preceding yield False, then the corresponding to the first that yields True is returned as the value of the piecewise function.
  • If any of the preceding do not literally yield False, the Piecewise function is returned in symbolic form.
  • Only those 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 can be input in the form . The piecewise operator can be entered as Esc pw Esc or \[Piecewise]. The grid of values and conditions can be constructed by first entering Ctrl+Comma, then using Ctrl+
    DynamicBox[ToBoxes[If[$OperatingSystem === MacOSX, Return, Enter], StandardForm], ImageSizeCache -> {35., {0., 9.}}]
    and Ctrl+Comma.
Set up a piecewise function with different pieces below and above zero:
Find the derivative of a piecewise function:
Use Esc pw Esc to enter and Ctrl+Comma and then
Ctrl+DynamicBox[ToBoxes[If[$OperatingSystem === MacOSX, Return, Enter], StandardForm], ImageSizeCache -> {35., {0., 9.}}]
for each additional piecewise case:
Set up a piecewise function with different pieces below and above zero:
In[1]:=
Click for copyable input
Out[1]=
 
Find the derivative of a piecewise function:
In[1]:=
Click for copyable input
Out[1]=
 
Use Esc pw Esc to enter and Ctrl+Comma and then
Ctrl+DynamicBox[ToBoxes[If[$OperatingSystem === MacOSX, Return, Enter], StandardForm], ImageSizeCache -> {35., {0., 9.}}]
for each additional piecewise case:
In[1]:=
Click for copyable input
Out[1]//InputForm=
Define a piecewise function:
Evaluate it at specific points:
Plot it:
Refine it under assumptions:
Automatic simplification of Piecewise functions:
Remove unreachable cases:
Remove False conditions:
Merge cases with the same values:
If values are not specified in a region, they are assumed to be zero:
This specifies that the default value should be 1:
Compute limits of piecewise functions:
Compute the limit in the direction of the positive imaginary axis:
Compute the series of a piecewise function:
Integrate a piecewise function:
Integration constants are chosen to make the result continuous:
Compute a definite integral of a piecewise function:
Laplace transform of a piecewise function:
Solve a piecewise differential equation:
Reduce a piecewise equation:
Integrating an implicitly piecewise integrand can give an explicit Piecewise result:
Symbolic minimization can give piecewise functions:
Compute the volume of an ellipsoid:
PiecewiseExpand converts nested piecewise functions into a single piecewise function:
Min, Max, UnitStep, and Clip are piecewise functions of real arguments:
Abs, Sign, and Arg are piecewise functions when their arguments are assumed to be real:
KroneckerDelta and DiscreteDelta are piecewise functions of complex arguments:
Boole is a piecewise function of a Boolean argument:
If, Which, and Switch can be interpreted as piecewise functions:
Convert Floor, Ceiling, Round, IntegerPart, and FractionalPart for finite ranges:
Convert Mod and Quotient when the number of cases is finite:
UnitBox and UnitTriangle are piecewise functions of real arguments:
Convert SquareWave, TriangleWave, and SawtoothWave for finite ranges:
BernsteinBasis and BSplineBasis are piecewise functions of real arguments:
New in 5.1