Solution (source code)

= Solution

A field is irrotational when $\nabla\times F=0$. In $\mathbb R^3$ define
$$
V(x)=-\int_\gamma F\cdot d\ell,
$$
where $\gamma$ is any path from $x_0$ to $x$. The difference between two choices is the <circulation> around a closed loop. By the <Stokes theorem> it is the flux of $\nabla\times F$ through a spanning surface and hence zero. Thus $V$ is well-defined, $V(x_0)=0$, and <differentiation> gives $F=-\nabla V$.

If $\nabla\times A_0=B$, every solution is
$$
A=A_0+\nabla\chi
$$
for an arbitrary <differentiable> <scalar> $\chi$, since the difference is curl-free. A necessary condition is $\nabla\cdot B=0$, because the divergence of a curl vanishes.