`Integrate`

around a convex combination of two functions that contain `Min`

or `Max`

or `Piecewise`

It doesn't end in 5 min. Conversely, `Integrate`

it ends in one or two seconds when the argument is a linear function, and similarly when the argument contains a function with `Min`

or `Max`

or `Piecewise`

, and similarly when the argument contains a convex combination of linear functions.

In the following example, the integrals of `d`

, `da`

, `d1`

, `d2`

take <2s and the integrals of `d1a`

, `d2a`

not finish in 5 min.

Am I making a simple mistake or how to accelerate similar integrals of convex combinations of `Piecewise`

functions?

MWE:

```
Clear(d, d1, d2, da, d1a, d2a, cdf, pdf, cdf1, pdf1, cdf2, pdf2, s,
vi, vj, vlo, mui, muj, pi, pj, pis, pjs)
$Assumptions =
Flatten@{Thread(0 < {s, pi, pj, pis, pjs, vlo, vi, vj}), s < 1};
cdf(v_) = v - vlo; pdf(v_) = 1;
cdf1(v_) = Max(0, Min(1, v - vlo)); pdf1(v_) = 1;
cdf2(v_) =
Piecewise({{0, v < vlo}, {v - vlo, vlo <= v <= vlo + 1}, {1,
v > vlo + 1}});
pdf2(v_) =
Piecewise({{0, v < vlo || v > vlo + 1}, {1, vlo <= v <= vlo + 1}});
d(pi_, pj_, s_, pis_) =
Integrate((1 - cdf(Max(pi, vj - pj + pi - s)))*pdf(vj), {vj, vlo,
vlo + 1});
d(0.2, 0.3, 0.1, 0.25) /. {vlo -> 0.1, mui -> 0.4}
da(pi_, pj_, s_, pis_) =
Integrate((mui*(1 - cdf(Max(pi, vj - pj + pi - s))) + (1 - mui)*(1 -
cdf(Max(0, vj - pj) + Max(pi, pis + s))))*pdf(vj), {vj, vlo,
vlo + 1});
da(0.2, 0.3, 0.1, 0.25) /. {vlo -> 0.1, mui -> 0.4}
d1(pi_, pj_, s_, pis_) =
Integrate((1 - cdf1(Max(pi, vj - pj + pi - s)))*pdf1(vj), {vj, vlo,
vlo + 1});
d1(0.2, 0.3, 0.1, 0.25) /. {vlo -> 0.1, mui -> 0.4}
d1a(pi_, pj_, s_, pis_) =
Integrate((mui*(1 - cdf1(Max(pi, vj - pj + pi - s))) + (1 -
mui)*(1 - cdf1(Max(0, vj - pj) + Max(pi, pis + s))))*
pdf1(vj), {vj, vlo, vlo + 1});
d1a(0.2, 0.3, 0.1, 0.25) /. {vlo -> 0.1, mui -> 0.4}
d2(pi_, pj_, s_, pis_) =
Integrate((1 - cdf2(Max(pi, vj - pj + pi - s)))*pdf2(vj), {vj, vlo,
vlo + 1});
d2(0.2, 0.3, 0.1, 0.25) /. {vlo -> 0.1, mui -> 0.4}
d2a(pi_, pj_, s_, pis_) =
Integrate((mui*(1 - cdf2(Max(pi, vj - pj + pi - s))) + (1 -
mui)*(1 - cdf2(Max(0, vj - pj) + Max(pi, pis + s))))*
pdf2(vj), {vj, vlo, vlo + 1});
d2a(0.2, 0.3, 0.1, 0.25) /. {vlo -> 0.1, mui -> 0.4}
```

The use of Simplify`PWToUnitStep @ does not seem to accelerate integration.