Brahmagupta's Identity

Brahmagupta's identity states that for integers $a, b, c, d, n,$ \begin{align*} (a^2+nb^2)(c^2+nd^2) &= (ac+nbd)^2 + n(ad-bc)^2 \\ &= (ac-nbd)^2 + n(ad+bc)^2. \\ \end{align*}

Thus, the product of two integers that can both be written in the form $x^2 + ny^2$ for a given integer $n$ can be written in the same form for the same value of $n$.

Proof

We expand the left side: \begin{align*} (a^2+nb^2)(c^2+nd^2) &= a^2c^2 + na^2d^2 + nb^2c^2 + n^2b^2d^2 \\ &= (ac)^2 + (nbd)^2 + n(ad)^2 + n(bc)^2. \\ \end{align*}

Adding and then subtracting $2nabcd$ to the result yields \[\begin{split} (ac)^2 + 2(ac)(nbd) + (nbd)^2 + n(ad)^2 - 2n(ad)(bc) + n(bc)^2 \\ = (ac+nbd)^2 + n(ad-bc)^2, \end{split}\] while subtracting and then adding $2nabcd$ yields \[\begin{split} (ac)^2 - 2(ac)(nbd) + (nbd)^2 + n(ad)^2 + 2n(ad)(bc) + n(bc)^2 \\ = (ac-nbd)^2 + n(ad+bc)^2. \end{split}\]

Application to the Pell equation

Substituting $n = -D$, the forms involved in Brahmagupta's identity lend themselves to use with solutions to the Pell equation \[x^2 - Dy^2 = 1.\]

Composition of solutions

If $(a,b)$ and $(c,d)$ are both solution pairs to the Pell equation for a given value of $D$, then \[(ac-Dbd)^2 - D(ad-bc)^2 = (a^2-Db^2)(c^2-Dd^2) = 1 \cdot 1 = 1,\] and likewise \[(ac+Dbd)^2 - D(ad+bc)^2 = (a^2-Db^2)(c^2-Dd^2) = 1.\] Thus, $(ac-Dbd, ad-bc)$ and $(ac+Dbd, ad+bc)$ are two (not necessarily distinct) solutions to the same equation.