Between
Details
- Between uses LessEqual to decide whether a value x is between some given limits.
- The values x, mini, maxi can be numbers, quantities, dates or general symbolic expressions.
- The second argument of Between can also be given as an interval, with head Interval, CenteredInterval or DateInterval.
- Between[range][x] is equivalent to Between[x,range].
Examples
open all close allBasic Examples (3)
Check that a number is included in an interval:
Between[3, {2, 5}]Between[{2, 5}][3]For symbolic expressions, the result is given as inequalities:
Between[x, {a, b}]Select the numbers between 10 and 20, both included:
Select[{5, 10, 15, 20, 25}, Between[{10, 20}]]Discard those numbers instead:
Discard[{5, 10, 15, 20, 25}, Between[{10, 20}]]Scope (9)
Use Between with numbers:
Between[5, {0, 10}]Between[2, {E, Pi}]Use Between with numeric Quantity objects:
Between[Quantity[1, "Pounds"], {Quantity[500., "Grams"], Quantity[1., "Kilograms"]}]Use Between with dates:
Between[Today, {Yesterday, Tomorrow}]Between[DateObject[{2015, 7, 1}], {DateObject[{2015, 6, 1}], DateObject[{2015, 8, 1}]}]Use Between with intervals:
Between[3, Interval[{2, 5}]]Between[Interval[{3, 4}], Interval[{2, 5}]]Between[Interval[{2, 4}], Interval[{2, 5}]]Between[Interval[{0, 1}], Interval[{2, 5}]]Use centered intervals as well:
Between[Interval[{3, 4}], CenteredInterval[5, 3]]Between[CenteredInterval[4, 1], CenteredInterval[5, 3]]Use Between with date intervals:
Between[Today, DateInterval[{Yesterday, Tomorrow}]]Between[Yesterday, DateInterval[{Today, Tomorrow}]]Use Between with the union of several ranges:
Between[3, {{2, 5}, {8, 12}}]Between[6, {{2, 5}, {8, 12}}]Use Between with a multi-range interval and quantities:
Between[Quantity[1, "Meters"], Interval[Quantity[{0, 3}, "Feet"], {Quantity[0, "Inches"], Quantity[2, "Yards"]}]]Use Between in operator form:
Between[{2, 5}] /@ Range[7]Between[x, {2, 5}]Between[3, {2, max}]Between[1, {2, max}]Applications (4)
Find the particles whose mass is in a given range:
EntityValue[EntityClass["Particle", {"Mass" -> Between[{Quantity[900., "Megaelectronvolts"/"SpeedOfLight"^2], Quantity[1000., "Megaelectronvolts"/"SpeedOfLight"^2]}]}], "Entities"]Find surfaces with algebraic degree between 7 and 10, both included:
EntityValue[EntityClass["Surface", {"AlgebraicDegree" -> Between[{7, 10}]}], {"Entity", "AlgebraicDegree"}]//SortBy[Last]Find movies with runtime in a given range, returning the result as an association:
EntityValue[EntityClass["Movie", {"Runtime" -> Between[{Quantity[220, "Minutes"], Quantity[225, "Minutes"]}]}], "Runtime", "EntityAssociation"]//SortTake tabular data about car models:
tab = ResourceData["Sample Tabular Data: Car Models"]Select the cars whose "mpg" value is between 39 and 40:
Select[tab, Between[#mpg, {39, 40}]&]Properties & Relations (7)
Between[x,{min,max}] includes the min, max limits:
Between[3, {3, 5.}]Between[5, {3, 5.}]The limits min, max in Between[x,{min,max}] are assumed to be sorted:
Between[3, {2, 5}]Between[3, {5, 2}]Use Interval to sort limits automatically:
Between[3, Echo@Interval[{5, 2}]]Symbolic limits in Between are assumed to be sorted:
Between[x, {a, b}]% /. {x -> 3, a -> 5, b -> 2}Use the limits in both orders to bypass this assumption:
Between[x, {{a, b}, {b, a}}]% /. {x -> 3, a -> 5, b -> 2}Equivalently, wrap Interval around the limits:
Between[x, Interval[{a, b}]]% /. {x -> 3, a -> 5, b -> 2}Between[x,{}] returns False, because there are no intervals that include x:
Between[3, {}]Between[x, {}]Use Interval objects and IntervalMemberQ instead of Between:
IntervalMemberQ[Interval[{0, 10}], 7]Between[7, {0, 10}]Alternatively, use intervals directly in Between:
Between[7, Interval[{0, 10}]]Use CenteredInterval range specifications:
Between[4, CenteredInterval[5, 2]]Between[1, CenteredInterval[5, 2]]Like LessEqual, Between uses seven bits of tolerance when comparing inexact real numbers:
Between[1. + 2 ^ 7 10 ^ -16, {0., 1.}]Between[1. + 2 ^ 8 10 ^ -16, {0., 1.}]Compare to IntervalMemberQ, which uses only one bit of tolerance:
IntervalMemberQ[Interval[{0., 1.}], 1. + 2 ^ 1 10 ^ -16]IntervalMemberQ[Interval[{0., 1.}], 1. + 2 ^ 2 10 ^ -16]Related Guides
History
Text
Wolfram Research (2015), Between, Wolfram Language function, https://reference.wolfram.com/language/ref/Between.html.
CMS
Wolfram Language. 2015. "Between." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/Between.html.
APA
Wolfram Language. (2015). Between. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Between.html
BibTeX
@misc{reference.wolfram_2026_between, author="Wolfram Research", title="{Between}", year="2015", howpublished="\url{https://reference.wolfram.com/language/ref/Between.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_between, organization={Wolfram Research}, title={Between}, year={2015}, url={https://reference.wolfram.com/language/ref/Between.html}, note=[Accessed: 12-June-2026]}