Solution (source code)

= Solution

With $N\triangleleft G$, the internal <semidirect product> conditions are $G=NH$ and $N\cap H=\{1\}$. Every element then has a unique expression $nh$. The extra data needed to reconstruct the <group> are the <conjugation> action
$$
\phi:H\to\operatorname{Aut}(N),\qquad\phi_h(n)=hnh^{-1}.
$$
On the set $N\times H$, the external <semidirect product> $N\rtimes_\phi H$ has multiplication
$$
\boxed{(n,h)(n',h')=(n\phi_h(n'),hh').}
$$
The map $(n,h)\mapsto nh$ identifies it with $G$. A direct product results when this action is trivial.

For example, $S_3=A_3\rtimes\langle(12)\rangle\cong C_3\rtimes C_2$. The two <subgroup>[subgroups] intersect trivially and their orders multiply to six, so they generate $S_3$. <Conjugation> by the transposition inverts the three-cycle. This action is nontrivial, and $S_3$ is nonabelian whereas $C_3\times C_2$ is abelian, so this is not their direct product.