5
$\begingroup$

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
$\endgroup$
5
$\begingroup$

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.

| improve this answer | |
$\endgroup$
3
$\begingroup$

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}

| improve this answer | |
$\endgroup$
  • $\begingroup$ 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. $\endgroup$ – Szabolcs Nov 16 '16 at 14:15
  • $\begingroup$ @Szabolcs Not sure, but I guess it won't do any harm to add BooleanConvert just in case. $\endgroup$ – corey979 Nov 16 '16 at 14:22
1
$\begingroup$

to answer your question:

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

(*-0.994987 < x < -0.866025 || 0.866025 < x < 0.994987*)

{xmin1, xmax1} = {sol[[1, 1]], sol[[1, 5]]}
{-0.994987, -0.866025}

{xmin2, xmax2} = {sol[[2, 1]], sol[[2, 5]]}
{0.866025, 0.994987}
| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.