Basic Examples (4)
The closure fills in missing elements within the range:
A convex set is a fixed point. It returns itself:
The closure of a singleton is the singleton itself:
Applied to a non-contiguous parent set:
Scope (3)
Works with rational elements:
Works with strings under lexicographic order:
Works with symbolic heads that have a canonical ordering:
Options (3)
The default value of "ComparisonFunction" is LessEqual:
Use GreaterEqual to compute the closure under the reverse order:
A custom comparison function. Closure under order by string length:
Applications (3)
Find intermediate stations between two stops on a Mexico City Metro line, using positional ordering rather than alphabetical order via a custom index-based comparison:
Determine the contiguous range of monthly periods between two known events in a fiscal calendar:
The function reconstructs the full sequence of monthly periods between the two given dates, ensuring interval completeness within the fiscal calendar.
Extract all rows in a dataset whose key falls between two boundary values:
Properties and Relations (6)
Idempotence. Applying the closure twice yields the same result:
A subset is convex if and only if it equals its closure:
The closure equals the subset joined with its defect (disjoint union):
The result of OrderConvexClosure always satisfies OrderConvexQ:
Extensiveness. The closure contains the original subset:
Monotonicity. If , then
:
Possible Issues (1)
OrderConvexClosure does not verify . If subset contains elements absent from parentSet, the closure is computed based on the range of subset but filtered from parentSet only.
The function is designed for total orders only. For partial orders, the interval characterization does not hold. When using a custom "ComparisonFunction", the function must be a valid total preorder: reflexive, transitive, and total. Passing a non-transitive relation yields undefined behaviour. If subset has elements not in parent set, they act as bounds but do not appear in the output:
Neat Examples (4)
Visualize the closure on a number line. Red points show the original subset. Green marks the convex closure:
Enumerate all distinct closures obtainable from 2-element subsets of {1,…,8}:
Fractal structure of the logistic map attractor. Discretize the orbit at r = 3.82 on a grid of resolution 0.001. Compare the orbit with its convex closure. The difference is the convex defect. Its size reflects gaps in the Cantor-like attractor:
Sweep the parameter r from 3.5 to 4.0 and plot the size of the convex closure relative to the discretised orbit. As approaches 4, the attractor fills the interval and the ratio tends to 1: