Solution (source code)

= Solution

The <Biot-Savart law> is
$$
B(r)=\frac{\mu_0I}{4\pi}\int\frac{d\ell'\times(r-r')}{|r-r'|^3}.
$$
Here $r'$ is the current-element position, $d\ell'$ follows the <electric current>, and $r$ is the observation point. For a circular <current loop>, transverse components cancel on the axis. Each element contributes axial factor $a/\sqrt{a^2+x^2}$ in addition to the inverse-square distance. Integrating around length $2\pi a$ gives the <on-axis magnetic field of a circular current loop>
$$
\boxed{B_{\mathrm{axis}}(x)=\frac{\mu_0Ia^2}{2(a^2+x^2)^{3/2}},}
$$
with axial direction set by the <right-hand rule>.

For a finite straight wire parametrized by $z\in[-b,b]$, at perpendicular distance $a$, the <Biot-Savart law> gives
$$
B=\frac{\mu_0I}{4\pi}\int_{-b}^{b}\frac{a\,dz}{(a^2+z^2)^{3/2}}
=\boxed{\frac{\mu_0Ib}{2\pi a\sqrt{a^2+b^2}}.}
$$
The direction is azimuthal about the current axis by the <right-hand rule>. In the hairpin, the semicircle contributes $\mu_0I/(4a)$ and each semi-infinite straight segment contributes $\mu_0I/(4\pi a)$. For the indicated current, all three contributions point \b[out of the page]. Thus the <magnetic field at the center of a hairpin wire> is
$$
\boxed{B(P)=\frac{\mu_0I}{4\pi a}(\pi+2),\quad\text{out of the page}.}
$$