Formula for powers of product in group of class two

Statement
Suppose $$G$$ is a group and $$x,y \in G$$ are elements such that the subgroup generated by $$x$$ and $$y$$ has nilpotence class two. Equivalently, suppose that $$[x,y]$$ commutes with both $$x$$ and $$y$$, where we define:

$$[x,y] = x^{-1}y^{-1}xy$$

Then, we have the identity:

$$x^ry^r = [x,y]^{r(r-1)/2}(xy)^r$$

(Note that the formula remains the same even if we follow the other definition of commutators, i.e.:

$$[x,y] = xyx^{-1}y^{-1}$$

because, in this case, the two commutators are the same.)

Proof
To go back and forth between $$x^ry^r$$ and $$(xy)^r$$, we need to flip adjacent $$x$$'s and $$y$$'s. Each flip involves a multiplication by $$[x,y]$$. Explicitly, we can rewrite:

$$yx = [x,y]^{-1}xy$$

The expression $$[x,y]^{-1}$$ is central because the group has class two, so it can be pulled to the left. The number of such flip operations we need to do is $$0 +1 + 2 + \dots + (r - 1)$$ (0 for the right-most $$y$$, 1 for the second $$y$$ from the right, and so on), which becomes $$r(r - 1)/2$$. Thus, we get:

$$(xy)^r = ([x,y]^{-1})^{r(r - 1)/2}x^ry^r$$

Rearranging gives us the formula in the suggested form.

The detailed manipulations are shown for $$r = 2$$ and $$r = 3$$ below.

Case $$r = 2$$
In this case:

$$(xy)^2 = xyxy = x(yx)y = x([x,y]^{-1}xy)y = [x,y]^{-1}x(xy)y = [x,y]^{-1}x^2y^2$$

Rearranging gives:

$$x^2y^2 = [x,y](xy)^2$$

This fits the formula, because for $$r = 2$$, $$r(r-1)/2 = 1$$.

Case $$r = 3$$
In this case:

$$(xy)^3 = xyxyxy = xyx(yx)y = xyx([x,y]^{-1}xy)y = [x,y]^{-1}xyx^2y^2 = [x,y]^{-1}x(yx)xy^2 = [x,y]^{-1}x([x,y]^{-1}xy)xy^2$$

$$ = [x,y]^{-2}x^2yxy^2 = [x,y]^{-2}x^2(yx)y^2 = [x,y]^{-2}x^2([x,y]^{-1}xy)y^2 = [x,y]^{-3}x^3y^3$$

Rearranging gives:

$$x^3y^3 = [x,y]^3(xy)^3$$

This fits the formula because for $$r = 3$$, $$r(r - 1)/2 = 3(3 - 1)/2 = 3$$.