Solution (source code)

= Solution

For a subgroup $H$ of a <finite group> $G$, distinct left <cosets> are disjoint and partition $G$. Each coset $gH$ has exactly $|H|$ elements because $h\mapsto gh$ is a bijection. Counting the partition proves <Lagrange's theorem>:
$$
\boxed{|G|=[G:H]|H|.}
$$
A <cyclic group> is generated by a single element. In a group of order four, an element of order four generates the whole group, giving $C_4$. Otherwise all three nonidentity elements have order two. Choose two of them $a,b$; cancellation makes $ab=c$ the third. Since $c^{-1}=c$, $(ab)^{-1}=b^{-1}a^{-1}=ba=ab$. The remaining products then give the <Klein four-group>. This proves that \b[there are precisely two groups of order four up to <isomorphism>], distinguished by whether an element of order four exists.

For the square, take $r$ to be counterclockwise rotation by $90^\circ$ and $s$ reflection in the horizontal axis. They satisfy $r^4=s^2=e$ and $sr=r^{-1}s$. The <dihedral group> here is $D_4$ of order eight, with elements $e,r,r^2,r^3,s,rs,r^2s,r^3s$. Both generators are necessary: one generator would give a cyclic, hence abelian, group, while $r$ and $s$ do not commute. In the following <Cayley table>, the row acts after the column; the formula $(r^as^b)(r^cs^d)=r^{a+(-1)^bc}s^{b+d}$, with exponents reduced modulo four and two, computes every entry.
$$
\begin{array}{c|cccccccc}
 &e&r&r^2&r^3&s&rs&r^2s&r^3s\\\hline
e&e&r&r^2&r^3&s&rs&r^2s&r^3s\\
r&r&r^2&r^3&e&rs&r^2s&r^3s&s\\
r^2&r^2&r^3&e&r&r^2s&r^3s&s&rs\\
r^3&r^3&e&r&r^2&r^3s&s&rs&r^2s\\
s&s&r^3s&r^2s&rs&e&r^3&r^2&r\\
rs&rs&s&r^3s&r^2s&r&e&r^3&r^2\\
r^2s&r^2s&rs&s&r^3s&r^2&r&e&r^3\\
r^3s&r^3s&r^2s&rs&s&r^3&r^2&r&e\\
\end{array}.
$$
The largest <cyclic subgroup> is $\langle r\rangle=\{e,r,r^2,r^3\}$, of order four. Every reflection has order two and there is no element of order eight. The other subgroups of order four are
$$
\boxed{H_0=\{e,r^2,s,r^2s\},\qquad H_1=\{e,r^2,rs,r^3s\}.}
$$
Both are Klein four-groups, generated by the commuting involutions $r^2$ and one reflection. For completeness, any order-four subgroup containing $r$ or $r^3$ equals $\langle r\rangle$. Otherwise it contains a reflection $f$; the product of two distinct reflections is a nonidentity rotation, which must be $r^2$ if odd powers of $r$ are excluded. This forces the subgroup to be $\{e,r^2,f,r^2f\}$, giving exactly the two displayed choices. It is the square case of the <classification of subgroups of a dihedral group>.