Piecewise Functions & Models
- Piecewise functions are defined by partitioning the domain into intervals with distinct rules, enabling varied behaviors and structures.
- They are computationally represented using techniques that allow exact integration, efficient transforms, and fast evaluation across the pieces.
- Applications of piecewise methods span stochastic processes, statistical inference, and signal processing, highlighting their versatility and practical impact.
Searching arXiv for the cited papers to ground the article in current records. A piecewise object is defined by partitioning its domain into regions and assigning a potentially different rule on each region. In the simplest real-variable setting, a piecewise function of returns a value computed from a rule that can be different in each interval of the values of ; more generally, the same principle appears in polyhedral coverings for piecewise affine mappings, change-point segmentations for piecewise stationary processes, local boundary splits for piecewise continuous regression, and interval-based constructions for piecewise probability laws (Berthod, 23 Sep 2025, Gorokhovik, 2011, Khaleghi et al., 2019, Park, 2021, Gelimson, 2022). Across these settings, “piecewise” does not denote a single regularity class. The pieces may be affine, polynomial, exponential, stationary ergodic, continuously differentiable, or merely measurable, and the global object may be continuous, discontinuous, convex, nonconvex, smooth on each piece, or nonsmooth at interfaces.
1. Formal definitions and canonical constructions
For a real variable , a piecewise function is specified by a finite collection of intervals and a branch rule on each interval. A standard form is
with intervals such as
together with endpoint-inclusion flags and, on each piece, one or more formula objects with parameter vectors (Berthod, 23 Sep 2025). In this formulation,
so the local rule itself may already be a sum of several elementary components (Berthod, 23 Sep 2025).
An important geometric variant is the piecewise affine mapping between finite-dimensional normed spaces. Here the domain is covered by finitely many convex polyhedral sets , and on each the restriction of 0 coincides with an affine map 1. This gives the class 2 of mappings satisfying 3 on a polyhedral covering (Gorokhovik, 2011). The same domain-decomposition pattern also underlies piecewise polynomial interpolation, where 4 is defined by polynomial pieces 5 on intervals 6, each of degree at most 7 (Pinheiro et al., 2020).
In stochastic process theory, piecewise structure is imposed through change points. A piecewise stationary ergodic process is generated by stationary ergodic marginals 8 on segments determined by indices
9
with allocation map 0 iff 1. Stationarity is recovered as the special case 2 (Khaleghi et al., 2019). In survival analysis, the classical piecewise exponential model similarly partitions time into intervals 3 and sets the hazard to a constant 4 on each interval,
5
or equivalently uses the log-hazard 6 (Hardcastle et al., 9 May 2025).
A recurrent misconception is that “piecewise” means “piecewise constant.” The cited literature explicitly contradicts this. Piecewise models appear as piecewise affine mappings (Gorokhovik, 2011), piecewise differentiable functions represented by straight-line programs with 7 nodes (Griewank et al., 2017), piecewise linear image models (Liu et al., 2018), piecewise continuous regression functions (Park, 2021), and piecewise linear probability distributions (Gelimson, 2022).
2. Geometric structure, ordering, and convexity
For piecewise affine mappings, one of the central characterizations is geometric. If 8 is partially ordered by a polyhedral convex cone 9, then 0 is piecewise affine if and only if both the 1-epigraph and 2-hypograph of 3 are finite unions of convex polyhedral subsets of 4 (Gorokhovik, 2011). This converts a local “glueing of affine pieces” description into a global statement about the geometry of subsets in product space.
When the cone is minihedral, equivalently when 5 is a vector lattice, the collection of all mappings 6 inherits pointwise lattice operations. In that setting, the class of piecewise affine mappings is the smallest vector sublattice containing all affine mappings, and every convex piecewise affine mapping is the least upper bound of finitely many affine mappings (Gorokhovik, 2011). Thus piecewise affinity admits both a polyhedral decomposition view and a lattice-theoretic envelope view.
Convexity for piecewise-defined functions requires additional compatibility conditions. If 7, where each 8 is proper convex on a convex domain 9, the family of sets 0 must be compatible, the formulas must agree on overlaps, and at overlap points the active subdifferentials must have nonempty intersection except possibly on a finite exceptional set 1. Under these conditions, 2 is convex; in the smooth case, matching one-sided gradient limits across interfaces suffices (Bauschke et al., 2014). Conversely, if there exists 3 such that
4
then convexity fails (Bauschke et al., 2014).
This makes precise a second common misconception: convexity of each piece does not imply convexity of the global piecewise-defined function. The interface conditions are decisive. The relevant obstruction is not merely discontinuity of formula labels, but failure of common support by active subgradients (Bauschke et al., 2014).
3. Computational representations and exact transforms
The Julia module "Piecewise" implements piecewise functions by three core types: Formula{N}, which wraps a function 5 of one real argument and 6 real parameters; Piece, which stores an interval, endpoint-inclusion booleans, formulas, and parameter vectors; and PiecewiseFunction, which stores a vector of pieces together with an overall parity tag :even, :odd, or :none (Berthod, 23 Sep 2025). Evaluation dispatches to the appropriate piece, checks endpoint inclusion, and sums the formulas on that piece.
A higher-level constructor piecewisefit automatically segments a target function 7 on a user-supplied grid, fits one or more chosen formula families in each segment using least-squares, and returns a PiecewiseFunction approximant of prescribed tolerance (Berthod, 23 Sep 2025). The built-in formula families include polynomial, exponential, power-law, logarithmic, shifted exponential, and step-type behaviors; the actual seven families are exposed in code under names such as POLY, EXP, POWER, LOG, MIXED, and HEAVISIDE (Berthod, 23 Sep 2025).
The main computational consequence is that the moments
8
are obtained by closed-form antiderivatives. For a piecewise representation, one has
9
so the complexity is 0, with no quadrature error and machine-precision evaluation (Berthod, 23 Sep 2025). For example, monomials, exponentials, power laws, logarithms, shifted exponentials, and Heaviside steps all admit explicit symbolic antiderivatives for the kernels 1 (Berthod, 23 Sep 2025).
The companion module PiecewiseHilbert.jl extends these formulas to the Hilbert transform,
2
by providing closed-form antiderivatives of 3 on each piece (Berthod, 23 Sep 2025). PiecewiseLorentz.jl similarly implements what the paper calls a Lorentz transform,
4
again through piecewise closed forms analytic off the real axis (Berthod, 23 Sep 2025).
The reported benchmarks quantify the computational advantage of exact piecewise antiderivative evaluation. For a single piece with up to 5 formulas, computing the 0th–10th moments is typically 10–100× faster than composite Gauss–Legendre quadrature of comparable accuracy, and for 50 moments or a dense set of Hilbert-transform values the speedup grows to 5–6 (Berthod, 23 Sep 2025). A plausible implication is that piecewise analytic surrogates are especially effective when endpoint singularities would force locally refined quadrature.
4. Piecewise models in stochastic processes and statistical inference
In survival extrapolation, the diffusion piecewise exponential model replaces deterministic knot locations and random walk priors by two coupled priors: a discretised diffusion for the log-hazard and a Poisson process prior for knot locations (Hardcastle et al., 9 May 2025). The discretised diffusion may be written as Euler–Maruyama,
7
or via the paper’s “skew-symmetric” Barker step with increment density
8
while 9 and the ordered knot locations define the time change from diffusion index to observation time (Hardcastle et al., 9 May 2025). Efficient posterior sampling is obtained by a sticky PDMP sampler that handles both transdimensional knot updates and non-Lipschitz posteriors (Hardcastle et al., 9 May 2025).
In time-series clustering, piecewise stationarity relaxes global stationarity while preserving stationary ergodic structure within each segment. Two piecewise stationary distributions are considered equivalent when they have the same set of stationary marginals, 0, irrespective of the order or timing of transitions (Khaleghi et al., 2019). The resulting class distance
1
is a metric on equivalence classes, and a clustering algorithm based on list-estimated change points and empirical distributional distances is shown to be asymptotically consistent when the segment lengths satisfy a uniform linear-growth condition 2 (Khaleghi et al., 2019).
For regression with discontinuities, the "Jump Gaussian Process" model estimates a local GP at each test point 3 after partitioning the local neighborhood by a learned linear boundary 4 (Park, 2021). Only the local data lying on the same side of the hyperplane as 5 are used for the posterior, with cross-covariance between opposite sides set to zero (Park, 2021). The split is learned jointly with covariance hyperparameters by minimizing a smooth approximation to the negative log-likelihood using a 6 relaxation (Park, 2021). On 2D synthetic examples with 7 noisy training points, a 8 evaluation grid, and 9 local neighbors, the method reduces mean absolute error by roughly 50% relative to the local GP when only points within 0 of the true boundary are evaluated (Park, 2021).
These three cases illustrate distinct statistical roles of piecewise structure. In survival analysis it regularizes extrapolation, in clustering it defines the equivalence relation itself, and in local GP regression it prevents boundary bias caused by averaging across discontinuities.
5. Approximation, linearization, and signal reconstruction
Piecewise differentiable functions 1 arising from straight-line programs with smooth univariates and the absolute value can be locally approximated by a piecewise linear secant model constructed from two sample points 2 and 3 (Griewank et al., 2017). Using midpoint and half-difference variables for all intermediates, smooth univariate nodes are replaced by secant slopes, products are linearized bilinearly around midpoints, and absolute-value nodes retain their kink structure. The resulting non-incremental model is
4
and satisfies the second-order secant error bound
5
on a suitable convex neighborhood (Griewank et al., 2017). Successive piecewise linearization yields generalized Newton schemes with quadratic convergence in tangent mode and superlinear rate 6 in secant mode under metric regularity and smallness assumptions on the model constants (Griewank et al., 2017).
In image processing, the notion of “piecewise” is explicitly shifted from intensities to gradients. A spatially piecewise linear image model assumes
7
so that the gradient field is piecewise constant on each region (Liu et al., 2018). This motivates applying a classical piecewise-constant filter 8 to the gradient channels 9 and 0, obtaining 1 and 2, and then reconstructing 3 by solving
4
The reconstruction is solved by PCG with an incomplete-Cholesky preconditioner (Liu et al., 2018). The method is designed to eliminate gradient-reversal artifacts that arise when a piecewise-constant model is used for detail enhancement or HDR tone mapping (Liu et al., 2018). For quantized weighted-median filtering, the reported runtimes are about 19 s per megapixel in the intensity domain with 5 bins, versus about 2.6 s per megapixel in the gradient-domain framework with 6 bins and reconstruction (Liu et al., 2018).
Piecewise rational approximation provides a different route to suppressing Gibbs oscillations. The univariate PiPC method subdivides an interval into cells, maps each cell to 7, estimates local Chebyshev coefficients by Gauss-Chebyshev quadrature, and on each cell builds a Padé–Chebyshev approximant through the Maehly moment-matching equations (Singh, 2021). The bivariate extension Pi2DPC applies the same principle on tensor-product cells in 8, solving one small Padé problem per cell (Singh, 2021). The paper states that Pi2DPC yields the smallest 9-error overall in its examples, typically 0–1 on a 2 grid, and that only the piecewise Padé–Chebyshev construction shows essentially no oscillation along the crossing discontinuity lines of the sign-function test case (Singh, 2021).
6. Piecewise probability laws and optimization over disjoint domains
Piecewise probability distribution theory treats a one-dimensional law as a combination of continuous pieces and point masses. If 3 is partitioned into intervals 4 with kernels 5 and point masses 6 at 7, then the unnormalized density-measure decomposition is
8
with normalization
9
(Gelimson, 2022). In the continuous piecewise-linear case, with heights 00 at knots 01, the normalization reduces to the trapezoid-area formula
02
and closed forms are given for 03, 04, 05, as well as constructive algorithms for the median and mode (Gelimson, 2022). Polygonal, tetragonal, and triangular distributions arise as hierarchical special cases (Gelimson, 2022).
A different piecewise construction appears in nonlinear programming with disjoint feasible regions induced by prohibited operating zones. If a decision variable must lie in a disconnected union
06
the Piecewise Polynomial Interpolation approach introduces interval parameters 07, affine interval maps 08, and a Heaviside-weighted function 09 formed from quadratic gap terms (Pinheiro et al., 2020). The key property is
10
so the original disconnected feasibility condition is replaced by smooth equality and box constraints (Pinheiro et al., 2020). The paper further states that 11 is of class 12 and satisfies the normalization
13
which supports the use of gradient-based methods such as SQP and Interior-Point algorithms on the transformed problem (Pinheiro et al., 2020).
Taken together, these constructions show that piecewise formulations are not merely descriptive devices. They are operational tools for exact integration, statistically coherent segmentation, rational approximation near singularities, and reformulation of disconnected constraints into continuously differentiable systems. A plausible implication is that the enduring utility of piecewise methods lies in this dual role: they preserve local structural fidelity while converting global irregularity into a finite, analyzable collection of interfaces.