# Interpretation of HeavisideTheta Integration Output

I need to integrate integrals of the type

Integrate[Boole[2 k*q >= Absolute[p^2 - k^2 - q^2]], q]


where $q$, $k$, and $p$ go from $0$ to $1$.

To learn to interpret the Mathematica output what I first evaluated (as a test) was

Integrate[Boole[2 k*q > (p^2 - k^2 - q^2)], {q, 0, 1},
Assumptions -> 0 < k < 1 && 0 < p < 1]


Performing the integral by hand I find $1-{\rm max}(0,p-k)$ as a result. The Mathematica result yields the following piecewise function

\begin{cases} 1 & 0 < k < 1\mathtt{\;\&\&\;}p > 0\mathtt{\;\&\&\;}k-p \ge 0\\ 1 + k - p & \mathtt{True} \end{cases}

OK, the first line of the output I can interpret as a new Heaviside function which tells me that $k\geq p$ but what does the second line of the output try to tell me? Is there a convenient way to transform the piecewise output into $\min$, $\max$ functions or construct new Heaviside functions?

• I wonder if you are reading the Piecewise expression backwards: this is telling you that, for $k \ge p$, the value of the integral is $1$; in all other cases, the integral has the value corresponding to the True condition, i.e. $1+k-p$ in this case. Notice also that you can have MMA Simplify your conditions: try Assuming[{0 < k < 1, 0 < p < 1}, Simplify@Integrate[Boole[2 k q >= p^2 - k^2 - q^2], {q, 0, 1}]]. – MarcoB Jan 27 '17 at 22:43
• @MarcoB Thanks for the quick answer! Ok Simplify makes the result much easier to read and I also understood now that True means that the following expression is true for all cases not mentioned in the above conditions but still I wonder if one can transform such piecewise expressions into other expressions like max,min functions or new boole functions automatically? Or do I have to go through the mathematica expressions by hand to create those functions? – Rico Jan 27 '17 at 23:04
• I don't know of an automated way to do what you ask. As a side note, frankly I find find the piece-wise output much more readable than the same thing expressed as a max function. – MarcoB Jan 27 '17 at 23:09
• @MarcoB If i solve the original problem with the abosolute function in the Boole function my piecewise function cases get messy and lengthy while in the min max representation I still get some handy expressions which are not that long. That is why I want to to try avoid piecewise expressions. – Rico Jan 27 '17 at 23:14
• SimplifyPWToUnitStep[%]? – Michael E2 Jan 28 '17 at 2:51

## 1 Answer

Expanding on the comment by @Michael E2, we could use:

pw = Integrate[Boole[2 k*q > (p^2-k^2-q^2)], {q,0,1}, Assumptions -> 0<k<1 && 0<p<1];

unit = SimplifyPWToUnitStep[pw]


(1-UnitStep[-1+k]) (1-UnitStep[-k]) UnitStep[k-p] (1-UnitStep[-p])+(1+k-p) (1+UnitStep[-1+k]+UnitStep[-k]-UnitStep[k-p]+UnitStep[-p]-UnitStep[-k] UnitStep[-p]-(1-UnitStep[k-p]) (UnitStep[-k]+UnitStep[-p]-UnitStep[-k] UnitStep[-p])-UnitStep[-1+k] (1+UnitStep[-k]-UnitStep[k-p]+UnitStep[-p]-UnitStep[-k] UnitStep[-p]-(1-UnitStep[k-p]) (UnitStep[-k]+UnitStep[-p]-UnitStep[-k] UnitStep[-p])))

This is a bit messy, so it would be nice to Simplify this and reduce the number of UnitStep objects:

Simplify[unit] //InputForm


Piecewise[{{1, Inequality[0, Less, k, Less, 1] && k >= p && p > 0}}, 1 + k - p]

Naturally, this returned the original Piecewise object. However, it is possible to convert pw to a simpler UnitStep version as follows:

Simplify[
pw,
ComplexityFunction -> (LeafCount[#] + 1000 Boole[!FreeQ[#, Piecewise]]&),
TransformationFunctions -> {Automatic, SimplifyPWToUnitStep}
]


1+k-p+(k-p) (-1+UnitStep[-1+k]) (-1+UnitStep[-k]) UnitStep[k-p] (-1+UnitStep[-p])

The ComplexityFunction penalizes the presence of Piecewise objects, and the TransformationFunctions option includes the Piecewise to UnitStep` transformation.