Gauss Bonnet failure

This is a follow-up to this question:The OP asks how to compute the genus (or Euler characteristic) of a parametrized surface in $\mathbb{R}^3.$ One of the commenters recommends the Gauss-Bonnet formula, which I pooh-poohed in my answer, but then thought that I should try it before heaping scorn. Luckily, the code to compute Gauss curvature is given in another MSE post. and implementing this, one gets the following formula for the Gauss curvature of the torus given by

ParametricPlot3D[
{Cos[x] + .4 Cos[x] Sin[y], Sin[x] + .4 Sin[x] Sin[y], Cos[y]},
{  x, 0, 2 π}, {y, 0, 2 π}]


(this was one of the examples in the first referenced question).

Sure enough, I got:

(-0.260682 + 0.264024 Cos[2 y] - 0.00334208 Cos[4 y] -
0.568153 Sin[y] + 0.0501312 Sin[3 y])/(-0.78609 + 1. Cos[2 y] -
0.264011 Cos[4 y] + 0.0235115 Cos[6 y] - 0.000147386 Cos[8 y] -
1.26981 Sin[y] + 0.56683 Sin[3 y] - 0.0988186 Sin[5 y] +
0.00294771 Sin[7 y])


which seems reasonable, but then NIntegrating it over the parameter space $[0, 2 \pi] \times [0, 2 \pi]$ gives $-8.59435,$ which, whatever else it might be, is not zero. It is however, $-27/\pi.$ Would anyone care to explain what the heck is going on?

What you did is quite close, it's just missing the area form.

We have the parametrization below.

xyz[x_, y_] := {Cos[x] + .4 Cos[x] Sin[y], Sin[x] +
.4 Sin[x] Sin[y], Cos[y]};


Define the derivatives with respect to parameters.

dxyz = Transpose[{D[xyz[a, b], a], D[xyz[a, b], b]}]


Recalling that dx = D[x,a]*da + D[x,b]*db (and apologies for mixing differential forms notation with Mathematica), and the area form is the sum of the three edge products of distinct differentials from {dx,dy,dz}, with orientation taken into account I believe this is:

areaD = Det[dxyz[[1 ;; 2]]] + Det[dxyz[[2 ;; 3]]] +
Det[dxyz[[{3, 1}]]]


Changing variables to {a,b} notation, and setting gc to the expression for Gauss curvature, I get:

-1/(2*Pi)*NIntegrate[gc*areaD, {a, 0, 2*Pi}, {b, 0, 2*Pi}]

During evaluation of In[389]:= NIntegrate::slwcon: Numerical integration converging too slowly; suspect one of the following: singularity, value of the integration is 0, highly oscillatory integrand, or WorkingPrecision too small.

During evaluation of In[389]:= NIntegrate::eincr: The global error of the strategy GlobalAdaptive has increased more than 2000 times. The global error is expected to decrease monotonically after a number of integrand evaluations. Suspect one of the following: the working precision is insufficient for the specified precision goal; the integrand is highly oscillatory or it is not a (piecewise) smooth function; or the true value of the integral is 0. Increasing the value of the GlobalAdaptive option MaxErrorIncreases might lead to a convergent numerical integration. NIntegrate obtained -5.60142210393*10^-15 and 1.9833450181266685*^-11 for the integral and error estimates.

(* Out[389]= 8.91494016185*10^-16 *)
`

So either I made a mistake in the area form, or this vindicates your approach.

• You are right, of course, it was late at night, but still stupid to forget the area form. Apr 27 '17 at 21:19
• However, the fact that the integral is exactly $-27/\pi$ is kind of cool and mysterious. Apr 27 '17 at 21:19
• Yeah. But that's what made me think an area form might be missing: the appearance of pi sort of signalling a parametrization issue. Apr 27 '17 at 21:24