Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to compute the integral

$Assumptions = {0 < x[3] < 1, 0 < x[4] < 1, 0 < x[5] < 1};
Integrate[
  x[2] Boole[2 (x[2] + x[3]) + x[4] < 1 &&  
             2 x[2] + x[3] + x[4] + 2 x[5] > 1 && 
             x[2] + x[5] < x[3] + x[4]],
  {x[2], 0, 1}]

but for some reason it takes forever. However, if I manually simplify the integrand

Boole[2 (x[2] + x[3]) + x[4] < 1 && 
      2 x[2] + x[3] + x[4] + 2 x[5] > 1 && 
      x[2] + x[5] < x[3] + x[4]] ==
Boole[(1 - x[3] - x[4])/2 - x[5] < x[2] < 
      Min[(1 - x[4])/2 - x[3], x[3] + x[4] - x[5]]] // PiecewiseExpand // Simplify

(* True *)

the integral is easily computed as

Integrate[Boole[a < x[2] < b] x[2], {x[2], 0, 1}] /.
  a -> (1 - x[3] - x[4])/2 - x[5] /. 
  b -> Min[(1 - x[4])/2 - x[3], x[3] + x[4] - x[5]] // PiecewiseExpand // Simplify

I'd appreciate any hints as to how I can compute the integral more quickly without manual intervention.

share|improve this question
up vote 0 down vote accepted

The following works for me: it uses the undocumented function Simplify`PWToUnitStep that I learned about here.

f = x[2] Boole[2 (x[2] + x[3]) + x[4] < 1 && 2 x[2] + x[3] + x[4] + 2 x[5] > 1 && x[2] + x[5] < x[3] + x[4]];
Integrate[#, {x[2], 0, 1}]&/@Expand@Simplify`PWToUnitStep@PiecewiseExpand@f 
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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