Solution (source code)

= Solution

The <cyclic subgroup> $A=\langle a\rangle$ has order four and index two. Every index-two <subgroup> is normal: its complement is both the only nontrivial left <coset> and the only nontrivial right <coset>. Thus <conjugation> by $b$ is an <automorphism> of $A$. It must send its generator $a$ to another element of order four, namely $a$ or $a^3$. Since $b^{-1}=b$,
$$
bab=a\quad\text{or}\quad bab=a^3,
$$
equivalently $ab=ba$ or $ab=ba^3$, as required. Also $b\notin A$, since otherwise $a,b$ could generate at most four elements.

In the commuting case, every word reduces uniquely to $a^jb^\varepsilon$ with $0\leq j<4$ and $\varepsilon\in\{0,1\}$. The eight expressions are distinct because $A$ and $Ab$ are disjoint. Multiplication is addition of the two exponents modulo four and two, respectively. Therefore
$$
\boxed{G\cong C_4\times C_2}.
$$
This gives the <multiplication table> independently of any other properties of $G$, proving uniqueness up to <group isomorphism>.

In the inversion case, the relation $ba=a^{-1}b$ gives the same eight unique normal forms, now with multiplication
$$
(a^ib^\varepsilon)(a^jb^\eta)
=a^{i+(-1)^\varepsilon j}b^{\varepsilon+\eta},
$$
with exponents reduced modulo four and two. Thus this case also has a uniquely determined <group> structure. A faithful geometric realization is the <dihedral group> of a square, with $a$ a quarter-turn and $b$ a reflection in a line through opposite edge midpoints. For example, on the plane,
$$
a=\begin{pmatrix}0&-1\\1&0\end{pmatrix},\qquad
b=\begin{pmatrix}1&0\\0&-1\end{pmatrix}.
$$
These preserve the square with vertices $(\pm1,\pm1)$ and satisfy $a^4=b^2=I$, $bab=a^{-1}$. They generate eight distinct transformations, so
$$
\boxed{G\cong D_4\quad\text{(the symmetry group of a square, of order eight)}}.
$$