I'm considering the following integral:
$$\int^a_b H(g(x))\:dx$$
Where $a$ and $b$ are constants, H is the Heaviside function, see
https://en.wikipedia.org/wiki/Heaviside_step_function#Discrete_form
And $g(x)$ some function. In order to evaluate this I've try integration by parts:
$$ \int^a_b {dv\over dx} u \: dx = \left.uv\right|^a_b -\int^a_b {du\over dx} v\: dx $$
Set $u = H(g(x))$ and ${dv\over dx} = 1$. Then:
$$ {du\over dx} = {d\over dx}H(g(x)) = g'(x)\delta(g(x)), \:\: v = \int dx = x $$
The former determined via Wolfram alpha. Substituting we find:
$$ \left. H(g(x)) x \right|^a_b -\int^a_b g'(x)\delta(g(x)) x\: dx $$ $$ H(g(a))a - H(g(b))b -\int^a_b g'(x)\delta(g(x)) x\: dx $$
Now we must evaluate:
$$\int^a_b g'(x)\delta(g(x)) x\: dx$$
I believe I am right in saying that
$$\int^{+\infty}_{-\infty} \delta(g(x)) f(x) dx = \sum_{x_0: \{g(x_0)=0 | -\infty < x_0 < +\infty \}} {f(x_0)\over|g^\prime(x_0)| } $$
Hence
$$\int^a_b g'(x)\delta(g(x)) x\: dx = \sum_{x_0} {g^\prime(x_0) x_0\over|g^\prime(x_0)| } = \sum_{x_0: \{g(x_0)=0 | b\leq x_0\leq a \} } sgn(g^\prime(x_0)) x_0$$
Where $sgn(x)$ is the sign of $x$. Hence
$$\int^a_b H(g(x))\:dx = H(g(a))a - H(g(b))b - \sum_{x_0: \{g(x_0)=0 | b\leq x_0\leq a \} } sgn(g^\prime(x_0)) x_0 $$
If I consider a trivial example:
$$\int^{2\pi}_0 H(\sin(x))\:dx = \pi$$
Wolfram suggest that the answer is $\pi$. The roots we seek are in the range $g(b)<x_i=g^{-1}(0)<g(a) => \sin(0)<x_i=g^{-1}(0)<\sin(2\pi) => 0 <x_i=\sin^{-1}(0)< 0$, which leaves only $x_1=0$. Substituting into my equation we get:
$$ 2\pi H(\sin(2\pi)) - [H(\sin(0))\times0] - (0) =2\pi$$
Clearly my derivation is wrong somewhere. Where have I made a mistake?
$H$ is not differentiable and so you cannot use integration by parts (unless you evaluate the limits very carefully). In the present case, better writing simply $$ \int_0^{2\pi}H(\sin x)\,dx=\int_0^\pi 1\,dx=\pi, $$ since $H(\sin x)=0$ for $x\not\in[0,\pi]$.