Looking at the solution for from this site I'm a bit confused on how two quantities necessarily reduce.
I'm given this wavefunction
$$ \psi(x) = \begin{cases} Ax & 0<x<a/2 \\ A(a-x) & a/2 < x < a \\ 0 & \text{otherwise} \end{cases} $$
If I take the derivative, we can express it as a step function.
\begin{align} \frac{\partial\ \psi(x)}{\partial x} &= \begin{cases} A & 0<x<a/2 \\ -A & a/2 < x < a \\ 0 & \text{otherwise} \end{cases} \\ &\\ &= A \left[ \theta(x) - \theta \left (x-\frac{a}{2} \right) - \theta \left( x-\frac{a}{2} \right) + \theta(x-a) \right] \, . \end{align}
First Question
How does the step function reduce to this?
$$ A \left[ \theta(x) - \theta \left(x-\frac{a}{2} \right) - \theta \left(x-\frac{a}{2} \right) + \theta(x-a) \right] = -A \left( 2 \theta \left(x-\frac{a}{2} \right) - 1 \right) \, , $$ i.e. where did the one come from?
So with that that quantity, I take second derivative to get
$$ \frac{\partial^2\ \psi(x)}{\partial^2 x} = -2A\ \delta \left(x-\frac{a}{2} \right) \, .$$
Second Question
So now what is left is integrating my second derivative with my step function, in which I have no idea which terms vanish.
$$ \int_{-\infty}^{\infty} \psi^{*} \frac{\partial^2\ \psi(x)}{\partial^2 x}dx = A \int_{0}^{a/2} x \delta(x-a/2) dx + A \int_{a/2}^{a} a \delta(x-a/2) dx - A \int_{a/2}^{a} x \delta(x-a/2) dx $$
How do I go about this and what is the reasoning?