Solution (source code)

= Solution

Let $S$ be a compact piecewise smooth <oriented surface>, $\mathbf n$ its chosen unit <normal vector>, and $\partial S$ its entire oriented boundary. Let $\mathbf A$ be a continuously differentiable <vector field> on a neighborhood of $S$. <Stokes theorem> states
$$
\boxed{\iint_S(\nabla\times\mathbf A)\cdot\mathbf n\,dS=\oint_{\partial S}\mathbf A\cdot d\mathbf r.}
$$
Here $\nabla\times\mathbf A$ is the <curl>, $dS$ is the <surface area element>, and $d\mathbf r$ is the directed <line integral> element. The boundary follows the <right-hand rule> relative to $\mathbf n$; equivalently the surface lies to the left when walking along its boundary with one's head toward $\mathbf n$.

The topological requirement is <orientability>, together with the regularity and boundary assumptions above. \b[Simple connectivity is unnecessary.] An annulus or cylindrical side is allowed, provided every boundary component is included with its induced direction. For a concrete counterexample to a disk-only restriction, take the planar annulus $1\le x^2+y^2\le4$ and $\mathbf A=(-y/2,x/2,0)$. The <curl> is $\mathbf e_z$, the <surface integral> is $3\pi$, and the outer counterclockwise and inner clockwise <line integrals> sum to $4\pi-\pi=3\pi$.

For $S$ in the $xy$ <plane> with upward <normal vector> and $\mathbf A=(P,Q,0)$, its <curl> has vertical component $Q_x-P_y$. Thus <Stokes theorem> becomes <Green's theorem>:
$$
\boxed{\oint_{\partial D}(P\,dx+Q\,dy)=\iint_D\left(\frac{\partial Q}{\partial x}-\frac{\partial P}{\partial y}\right)dx\,dy.}
$$
The outer boundary is counterclockwise and any inner boundaries are clockwise.