Basic Examples (2)
A contiguous slice of the parent set is convex:
A subset with a gap element 4 lies between 3 and 5 in the parent set but is absent:
Scope (3)
Non-contiguous, irregularly spaced parent sets are supported:
Operates on real-valued and rational elements, or any type supporting LessEqual:
Strings use lexicographic order:
Options (3)
Guarded (1)
Guarded mode performs a preliminary containment check before testing order-convexity:
Since no elements of Range[10] lie between 20 and 30, the convexity condition is vacuously satisfied. With "Guarded"→True, the function first verifies that the subset is contained in the parent set and returns False because the elements 20 and 30 are not present in Range[10].
ComparisonFunction (2)
A custom comparison function can redefine the ordering of the parent set. Under the standard order 1 < 2 < 3, the subset {1, 3} is not order-convex because 2 lies between 1 and 3:
Under the default ordering, the element 2 lies between 1 and 3, so the subset {1, 3} is not order-convex. With the custom ordering 1 < 3 < 2, the interval between 1 and 3 contains only {1, 3}, and the subset becomes order-convex:
Applications (5)
DateRange produces DateObject expressions, which carry additional structural information. To obtain a simple totally ordered representation suitable for detecting gaps in a schedule, the example maps the dates to their day numbers using DateValue[…,"Day"]:
The first call returns True because the scheduled days form a contiguous interval within the full set of days. Removing one day from the schedule introduces a gap in the interval, and OrderConvexQ correctly returns False:
Given a discretized grid of expected measurement points and the actual readings, identify whether any measurement was skipped within the active range:
Enumerate all convex subsets of a finite set. The convex subsets of a totally ordered n-element set are exactly the contiguous subintervals plus the empty set, giving
in total:
Discretize a Poincaré section and test whether the numerical orbit of a logistic map fills an interval without gaps.
The orbit at r=3.8 does not fill the unit interval densely at resolution 0.01, consistent with the known fractal structure of the logistic attractor near this parameter value:
In a subshift of finite type, the admissible cylinder sets under a lexicographic order must be convex intervals:
The admissible 2-blocks {00, 01, 10} form a convex set under lexicographic order within {00, 01, 10, 11} the forbidden block 11 lies at the upper extreme, so no interior gap exists.
Properties and Relations (9)
The empty set is vacuously convex:
A singleton is trivially convex:
The parent set itself is always convex in itself:
OrderConvexQ is equivalent to checking that the convex defect is empty:
If two subsets are order-convex in a parent set, their intersection is also order-convex:
The union of two convex subsets is convex if and only if they overlap or are adjacent:
A subset is convex if and only if it equals its own convex closure within the parent set:
The number of convex subsets of {1,…,n} is
, the n-triangular number plus one:
OrderConvexQ can be expressed purely in terms of IntervalMemberQ and SubsetQ:
Possible Issues (4)
Symbolic elements may produce unexpected results. When Min/Max remain unevaluated, the Select filter cannot compare elements numerically, and SubsetQ may return True based on list containment alone — without actually verifying order-convexity:
The result True is not meaningful, it does not reflect a genuine convexity test. OrderConvexQ requires a decidable total order on its elements; it is not designed for symbolic manipulation.
If subset contains elements not in parentSet, the function does not signal this directly. Instead, it proceeds with the convexity test using Min and Max of the subset, which may extend beyond the parent set. In this case the result happens to be False because the expanded Interval[{3, 99}] includes parent elements (5 through 10) that are absent from subset. The function therefore reports non-convexity, but the cause is incidental rather than an explicit containment check:
The "Guarded" option provides an explicit containment check, returning False immediately upon detecting that subset is not contained in parentSet — without performing the convexity test:
Both calls return False, but for different reasons: the unguarded form fails the convexity test because Select[Range[10], 3 <= # <= 99 &] returns {3, 4, 5, 6, 7, 8, 9, 10}, which is not a subset of {3, 4, 99}. The guarded form never reaches the convexity test — it short-circuits at the containment check SubsetQ[Range[10], {3, 4, 99}], which is False.
For partial orders (divisibility, inclusion, Hasse diagrams), the function gives incorrect results because the Min/Max characterization only holds in total orders:
Under divisibility, the Interval[{2,6}] is {2,3,6} (4 does not divide 6), so the set is actually convex, but OrderConvexQ uses ≤ and sees 4 and 5 as "missing". A partial-order variant would require a different algorithm.
Duplicate elements in the subset are handled correctly:
Neat Examples (3)
Visualize the lattice of convex subsets. Plot the Hasse diagram of all convex subsets of:
Random walk convexity over time. Track how the orbit of a random walk on {1,…,50} fills its convex hull as time increases, a measure of how "explored" the range is:
The walk starts convex (trivially, at a single point), quickly becomes non-convex as it explores with gaps, and eventually returns to convex once every site in its range has been visited, a discrete analogue of the cover time of a random walk on a path graph.
This example illustrates how OrderConvexQ can be used to detect gaps in the angular exploration of a quasiperiodic orbit on a Poincaré section.
Angular coverage of a quasiperiodic orbit on a Poincaré section: A quasiperiodic orbit of the Swing–Spring Hamiltonian system produces a smooth invariant curve on a Poincaré section. Parametrizing the curve by the polar angle around its centroid provides a convenient angular coordinate. Discretizing this angular domain allows one to track how the sampled orbit explores its angular support, while OrderConvexQ can be used to detect gaps in the resulting discretized sampling:
OrderConvexQ detects whether the sampled angular coordinates form a contiguous interval in the discretized angular grid, providing a discrete test of angular coverage along the invariant curve.
The first plot shows the quasiperiodic orbit on the Poincaré section. Computing the polar angle around the centroid provides a natural angular parametrization of the invariant curve. The second plot colors the orbit according to this angular coordinate, revealing how the trajectory winds around the curve.
The third plot measures how many points of a discretized angular grid remain unvisited as the integration time increases. The number of missing grid points decreases initially and then stabilizes once the orbit has explored the full angular support of the invariant curve.
Finally, the angular Histogram shows the distribution of sampled angles along the curve, highlighting the subset of the angular domain actually occupied by the orbit. The shape of the distribution reflects the nonuniform angular velocity along the invariant curve: regions where the angular motion slows down appear as peaks in the histogram. The overlaid curve shows the theoretical density induced by an approximate elliptical geometry of the invariant curve. Interestingly, this angular distribution resembles profiles familiar from simple quantum systems, such as probability densities associated with the harmonic oscillator.