CompleteSquarep[exp, x]
completes the square of a second
order polynomial in the momentum x.
Overview, ExpandScalarProduct.
[4 SP[p] + SP[b, p] + c, p] CompleteSquare
4 (\frac{\overline{b}}{8}+\overline{p})^2-\frac{\overline{b}^2}{16}+c
[4 SP[p] + SP[b, p] + c, p, q] CompleteSquare
\left\{-\frac{\overline{b}^2}{16}+4 \overline{q}^2+c,\overline{q}\to \frac{\overline{b}}{8}+\overline{p}\right\}
= 5 SP[2 p + 3 r, p + r] ex1
5 \left((\overline{p}+\overline{r})\cdot (2 \overline{p}+3 \overline{r})\right)
= CompleteSquare[ex1, p] ex2
10 (\overline{p}+\frac{5 \overline{r}}{4})^2-\frac{5 \overline{r}^2}{8}
- ex2 // ScalarProductExpand // Expand ex1
0
[5 SP[2 p + 3 r, p + r], p, q] CompleteSquare
\left\{10 \overline{q}^2-\frac{5 \overline{r}^2}{8},\overline{q}\to \overline{p}+\frac{5 \overline{r}}{4}\right\}
[a] + 2 SPD[a, b]
SPD
= CompleteSquare[%, a] ex
2 (a\cdot b)+a^2
(a+b)^2-b^2
// StandardForm
ex
(*-Pair[Momentum[b, D], Momentum[b, D]] + Pair[Momentum[a, D] + Momentum[b, D], Momentum[a, D] + Momentum[b, D]]*)