Convex union and intersection of intervals
Value
interval_union
returns the convex union of all intervals in intervals
.
This is the smallest interval completely containing all intervals.
interval_intersection
returns the set intersection of all intervals in
intervals
. The empty set is represented by the open interval (0, 0).
Examples
interval_union(
interval(c(0, 1), closed = TRUE),
interval(c(1, 2))
)
#> [0, 2)
interval_union(
interval(c(0, 5)),
interval(c(1, 4), closed = TRUE)
)
#> (0, 5)
# Convex union is not equal to set union:
interval_union(
interval(c(0, 1)),
interval(c(2, 3))
)
#> (0, 3)
# The empty union is {}
interval_union()
#> {}
interval_intersection(
interval(c(0, 1)),
interval(c(0.5, 2))
)
#> (0.5, 1)
interval_intersection(
interval(c(0, Inf)),
interval(c(-Inf, 0))
)
#> {}
interval_intersection(
interval(c(0, Inf), include_lowest = TRUE),
interval(c(-Inf, 0), include_highest = TRUE)
)
#> {0}
interval_intersection(
interval(c(0, 5)),
interval(c(1, 6), closed = TRUE)
)
#> [1, 5)
# The empty intersection is (-Inf, Inf)
interval_intersection()
#> (-Inf, Inf)