Univariate Linear Piecewise Function
UnivariateLinearPiecewiseFunction represents the graph obtained by linearly interpolating consecutive points
Solver mathematical model
Kotlin uses one binary selector
Rust uses point weights
Adjacency is enforced by
Consequently only the two endpoints of the selected segment may have positive weights. Although the internal formulas differ, both sides now represent the same single active segment and exclude arbitrary convex combinations of non-adjacent points.
Kotlin/Rust example
val piecewise = UnivariateLinearPiecewiseFunction.fromPoints(
x = input,
points = points,
converter = IntoValue.Identity,
name = "ulp"
)let piecewise = UnivariateLinearPiecewiseFunction::new(
1,
"ulp",
input,
vec![
Point2::new(0.0, 0.0),
Point2::new(1.0, 2.0),
Point2::new(2.0, 0.0),
],
);
assert_eq!(piecewise.selector_variables().len(), 2);Evaluation and boundaries
On segment
Missing input values and values outside the point domain return null in Kotlin and None in Rust. Duplicate, descending, non-finite, or insufficient points are rejected.
Tests and references
- Kotlin focused test:
UnivariateLinearPiecewiseFunctionDedicatedTest.kt - Kotlin boundary/registration test:
UnivariateLinearPiecewiseFailureBoundaryTest.kt - Kotlin implementation:
UnivariateLinearPiecewise.kt - Rust implementation:
univariate_linear_piecewise.rs - Rust dedicated test:
function_symbol_univariate_linear_piecewise.rs
The focused tests assert the helper counts and every selector/segment graph row, along with endpoint and out-of-domain behavior and invalid point validation.
The point and segment forms share the same ordered-breakpoint contract. Kotlin uses breakpoints/slopes/intercepts directly; Rust also provides UnivariateLinearPiecewiseFunction::from_segments, with one slope and intercept for each adjacent breakpoint pair. Invalid values are rejected before helper registration.