Solution (source code)

= Solution

For a <principal connection> with connection form $\mathcal A$, the <horizontal distribution of a principal connection> is $H=\ker\mathcal A$, the complement of the tangent spaces to the $G$-orbits. Its <curvature of a principal connection> is
$$
\mathcal F=d\mathcal A+\frac12[\mathcal A\wedge\mathcal A].
$$
If $X,Y$ are horizontal vector fields, then $\mathcal A(X)=\mathcal A(Y)=0$, and hence
$$
\mathcal F(X,Y)=d\mathcal A(X,Y)=-\mathcal A([X,Y]).
$$
The <Frobenius theorem> says that $H$ is integrable exactly when $[X,Y]$ is horizontal for all horizontal $X,Y$. The displayed identity makes this equivalent to the vanishing of the horizontal two-form $\mathcal F$, hence to $\mathcal F=0$. Thus the horizontal distribution is integrable exactly for a <flat principal connection>.