Subgroup test (source code)

= Subgroup test

A nonempty subset $H$ of a <group> $G$ is a <subgroup> if and only if $gh^{-1}\in H$ for every $g,h\in H$. Necessity follows from <closure> and the existence of <inverse elements> in a <subgroup>.

Conversely, choose $a\in H$. Setting $g=h=a$ gives the <identity element> $e=aa^{-1}\in H$. Taking $g=e$ then gives $h^{-1}\in H$ for every $h\in H$. Finally, using $h^{-1}$ as the second element gives $g(h^{-1})^{-1}=gh\in H$, proving <closure>. The inherited multiplication is <associative>, so these properties establish the <group> axioms on $H$.