# Extract result of Reduce when solving an inequalities

I defined this function

getInt[ptmin_, ptmax_, sqrts_] :=
(
Reduce[4 ptmin^2/sqrts^2 < 1 - x^2 < 4 ptmax^2/sqrts^2]
);


which solves an inequality. It returns for example

In: getInt[50, 250, 1000] // N

Out: -0.994987 < x < -0.866025 || 0.866025 < x < 0.994987


I need to integrate a function over these intervals so I want to use these results on an integral. How to extract these values from the output of Reduce?

For example, I want to store these values on 4 variables

xmin1 = -0.994987
xmax1 = -0.866025
xmin2 = 0.866025
xmax2 = 0.994987


Regions can help.

int = getInt[50, 250, 1000] // N
(* -0.994987 < x < -0.866025 || 0.866025 < x < 0.994987 *)

Integrate[x^2, x ∈ ImplicitRegion[int, x]]
(* {0.223679} *)


Why the braces around the result? When using the syntax x \[Element] region, x is considered to be a vector. This is a 1D region, so it is a 1D (single-component) vector.

Verification of the result:

Integrate[x^2, {x, -0.9949874371066199, -0.8660254037844386}] +
Integrate[x^2, {x, 0.8660254037844386, 0.9949874371066199}]
(* 0.223679 *)


Alternative for versions prior to 10.0, when the region functionality was introduced:

Integrate[x^2 Boole[int], {x, -Infinity, Infinity}]


Integrate and NIntegrate are smart about Boole are able to resolve the integration boundaries internally.

To extract the boundaries:

int = getInt[50, 250, 1000] // N


-0.994987 < x < -0.866025 || 0.866025 < x < 0.994987

reg = RegionBounds @ ImplicitRegion[#, x] & /@ (List @@ BooleanConvert @ int)


{{{-0.994987, -0.866025}}, {{0.866025, 0.994987}}}

x = Flatten @ reg


{-0.994987, -0.866025, 0.866025, 0.994987}

• Do you think BooleanConvert would make this safer? It's not clear to me if it can happen that the result from Reduce is not already in disjunctive normal form when there were no parameters. – Szabolcs Nov 16 '16 at 14:15
• @Szabolcs Not sure, but I guess it won't do any harm to add BooleanConvert just in case. – corey979 Nov 16 '16 at 14:22

getInt[ptmin_, ptmax_, sqrts_] := (Reduce[