Solution (source code)

= Solution

Define $\mathbf d$ to point from the negative charge to the positive charge. The <electric dipole moment> is $\mathbf p=q\mathbf d$. In a uniform <electric field>, the two <forces> cancel, so \b[the net force is zero]. They nevertheless form a <couple> with <torque>
$$
\boxed{\boldsymbol\tau=\mathbf p\times\mathbf E,\qquad |\boldsymbol\tau|=pE|\sin\theta|.}
$$
For a positive angular displacement increasing $\theta$, the restoring torque component is $-pE\sin\theta$. Thus $dU/d\theta=pE\sin\theta$ and
$$
\boxed{U=-\mathbf p\cdot\mathbf E=-pE\cos\theta,}
$$
with the additive constant chosen to make $U=0$ at $\theta=\pi/2$. Alignment is a stable minimum and antialignment an unstable maximum. The zero-force result uses a uniform field; a field gradient can exert a net <force> on a dipole.