Brahmagupta's identity

In algebra, Brahmagupta's identity says that, for given n, the product of two numbers of the form a2 + nb2 is itself a number of that form. In other words, the set of such numbers is closed under multiplication. Specifically:

This identity holds in both the ring of integers and the ring of rational numbers, and more generally in any commutative ring.

Also, it can be viewed as a special case of the following identity: