A piecewise function is a function specified by different formulas on different parts of its domain. A common example is the absolute value,
|
(1)
|
Piecewise functions are implemented in the Wolfram Language as Piecewise[{{val1, cond1}, {val2, cond2}, ...}].
Additional piecewise functions include the Heaviside step function, rectangle function, and triangle function.
For a real argument , suppose the formulas
apply from left to right, with breakpoints
assigned to the pieces on their right. If each formula is defined on the whole domain,
the piecewise function can be written as
|
(2)
|
where
is the Heaviside step function with
. On each interval the active terms telescope to
its formula (Oldham and Spanier 1974, §6.9).
On the interior of each piece, ordinary differentiation uses the formula for that piece. For a real-variable function with finitely many pieces that extend to continuously differentiable functions on their closures, being differentiable at an interior boundary requires continuity and agreement of the one-sided derivatives. Under the same piecewise regularity assumption, each jump discontinuity contributes a delta function, multiplied by the jump size, to the derivative in the sense of generalized functions. Merely differentiating the separate formulas omits these contributions (Trott 2006).
Semicolons and commas are sometimes used at the end of either the left or the right column, with particular usage apparently depending on the author. The words "if" and "for" are sometimes used in the right column, as is "otherwise" for the final (default) case.
For example, Knuth (1996, pp. 175 and 180) uses the notations
|
(3)
| |||
|
(4)
| |||
|
(5)
|
both with and without the left-column commas. Similarly, Arfken (1985, pp. 488-489) uses
|
(6)
|
which lacks semicolons but only sometimes lacks right-column commas.
In this work, commas and semicolons are not used.