# Solving for intervals without using NumberLinePlot

I've been struggling to find a way to find an interval solution to an equation/inequality. I know mathematica can do this since for example,

NumberLinePlot[Sin[x] < 0.5, {x, 0, 6.28}]


gives a plot of the correct interval. How can I have mathematica just give me the Interval instead of the plot?

• Like this? Reduce[0 <= x <= 2 \[Pi] && Sin[x] < 1/2, x]. The || symbol means Or. Commented Nov 1, 2015 at 5:41
• Reduce[Sin[x] < 1/2 && 0 < x < 2 π, x] gives 0 < x < π/6 || (5*π)/6 < x < 2*π. The || march refers is in the result. Commented Nov 1, 2015 at 5:47
• Ah ok, thanks march and goldberg! Does mathematica have a built in function to convert the result into intervals? I can write a (sloppy) function for it myself but I'd rather use built-in functions.
– ra91
Commented Nov 1, 2015 at 5:58

Note that

foo = Reduce[{
Sin[x] < 1/2,
0 <= x <= 2 π
}, x, Reals]
(* 0 <= x < π/6 || (5 π)/6 < x <= 2 π *)


almost gives you what you want. We can rewrite this to be in interval form,

ineqsToIntervals[x_Or] := List @@ (
x /. {
Inequality[a_, Less, _, Less, b_] :>
Row[{"(", a, ",", b, ")"}],
Inequality[a_, LessEqual, _, Less, b_] :>
Row[{"[", a, ",", b, ")"}],
Inequality[a_, Less, _, LessEqual, b_] :>
Row[{"(", a, ",", b, "]"}],
Inequality[a_, LessEqual, _, LessEqual, b_] :>
Row[{"[", a, ",", b, "]"}]
}
)


so that ineqsToIntervals[foo] gives $\{ [0,\frac{\pi}{6}), (\frac{5\pi}{6},2\pi] \}$.

• Note: you do not need to specify the domain to Reduce. The inequality 0 <= x <= 2 π is sufficient to tell Reduce it is working over the reals. Commented Nov 1, 2015 at 6:20
• Awesome, thanks!
– ra91
Commented Nov 1, 2015 at 6:31

You might try

List @@ (Drop[#, {2, -2}]& /@ List @@@ Reduce[Sin[x] < 1/2 && 0 < x < 2 π, x])


{{0, π/6}, {(5 π)/6, 2 π}}