Why is Stokes theorem not applicable / not used correctly in this case? I am doing some exercises and I don't understand what is wrong with my solution here.
The problem is: given the integral $$ I = \int_S (1 + x^2) f(x) dydz - 2xy f(x) dz dx - 3z dx dy$$
Find such a continuously differentiable function $f$ such that the integral $I$ is equal for all surfaces $S$, whose border is a circle $ C := \{ (\cos t, \sin t, 1) \; | \; t \in [0, 2 \pi ] \}$ and then calculate the integral $I$.
My thinking is that any function that is defined everywhere and $C^1$ should be alright! Let's denote $\overrightarrow{R}$ the vector field over which we are integrating. For any well defined $C^1$ function $f(x)$, field $\overrightarrow{R}$ will be well defined and $C^1$. Then by Stokes theorem we have:
$$ \int_S rot \overrightarrow{R} d\vec{S} = \int_{\partial S} \overrightarrow{R} d \vec{r}$$
where $\partial S = C$, which is a fixed number, so the integral on the left will be equal for every surface $S$ with the same border.
However, the  solution uses Gauss's theorem instead and shows that the sufficient condition is that $div \overrightarrow{R} = 0$. It also states (without proof) that this condition is also necessary.
To sum up, I would appreciate if you help me figure out

*

*What is wrong with my reasoning using Stokes theorem?

*How to show that $div \overrightarrow{R} = 0$ is a necessary condition?

 A: The expression in a chart for a differential 1-form (using Einstein conv.) looks like:
$$\omega = \omega_idx^i$$
$$\implies d\omega  = d\omega_i \wedge dx^i = \partial_j\omega_idx^j\wedge dx^i.$$
For $n=3$, we have (invoking multilinearity and skew-symmetry of $\wedge$) that:
$$d\omega = (\partial_x\omega_idx\wedge dx^i)+(\partial_y\omega_idy\wedge dx^i) + (\partial_z\omega_idz\wedge dx^i)$$
$$= \bigg(\partial_x\omega_1dx\wedge dx+\partial_x\omega_2dx\wedge dy+\partial_x\omega_3dx\wedge dz\bigg)+\bigg(\partial_y\omega_1dy\wedge dx+\partial_y\omega_2dy\wedge dy+\partial_y\omega_3dy\wedge dz\bigg)+\bigg(\partial_z\omega_1dz\wedge dx+\partial_z\omega_2dz\wedge dy+\partial_z\omega_3dz\wedge dz\bigg)$$
$$= (\partial_x\omega_2-\partial_y\omega_1)dx\wedge dy + (\partial_y\omega_3-\partial_z\omega_2)dy\wedge dz+(\partial_x\omega_3-\partial_z\omega_1)dx\wedge dz$$
$$= (\partial_y\omega_3-\partial_z\omega_2)dydz+(\partial_z\omega_1-\partial_x\omega_3)dzdx+(\partial_x\omega_2-\partial_y\omega_1)dxdy.$$

Since we have:
$$d\omega := (1+x^2)f(x)dydz-2xyf(x)dzdx-3zdxdy$$
Combinining with the above gives a system that $\omega$ satisfies:
$$(i)\text{ }\partial_y\omega_3 - \partial_z\omega_2 = (1+x^2)f(x)$$
$$(ii)\text{ } \partial_z\omega_1 - \partial_x\omega_3 = -2xyf(x)$$
$$(iii)\text{ } \partial_x\omega_2 - \partial_y\omega_1 = -3z$$

Now, bear with me as I proceed to find (a) solution to this system (not claiming uniqueness). If we assume that:
$$\omega_3 \equiv 0,$$
then (i) and (ii) simplify to:
$$\partial_z\omega_2 = -(1+x^2)f(x)$$
$$\partial_z\omega_1 = -2xyf(x)$$
Integrating these with respect to $z$ gives:
$$\omega_1 = -2xyzf(x)+G_1(x,y)$$
$$\omega_2 = -z(1+x^2)f(x)+G_2(x,y)$$
where $G_i(x,y)$ are constants of integration w.r.t. $z$.
Let's assume these vanish identically as well. Then combining these results with (iii) gives:
$$\partial_x\omega_2 - \partial_y\omega_1 = -z[2xf(x)+(1+x^2)f'(x)] +2xzf(x)$$
$$=-z(1+x^2)f'(x) = -3z$$
Assuming $z\neq 0$ and $x\neq i$ gives:
$$f'(x) = \frac{3}{1+x^2}$$
Or equivalently:
$$f(x) = 3tan^{-1}(x)+C.$$
This is a good reaffirmation of the exactness discussion!
Take $C=0$.

Putting this all together gives (a) primitive:
$$\omega = (-6xyz\cdot tan^{-1}(x))dx+(-3z(1+x^2)\cdot tan^{-1}(x))dy$$
Provided $z\neq 0$ (which won't matter over $C$).

Finally, in your application of Stoke's Theorem:
$$I = \int_Sd\omega = \int_{\partial S = C}\omega$$
So dump in the parameterization for $C$ $\bigg($i.e. $(x,y,z)(t) = (cos(t),sin(t),1)\bigg)$ for $t\in [0,2\pi]$ and the result will follow!
