###############################################################################
# This maple script deliniates the derivation of the summands of the
# two dimensional isometric error term $F_{metric}^{2D}$.
# It uses an integral similar to equation (6) for a finite deformation
# induced by the map.

restart;
with(LinearAlgebra):

# we consider the line segment S = (x0,y0)->(x1,y1)
x0 := 0;
y0 := 0;

x1 := x0 + r*rx;
y1 := y0 + r*ry;

# we map S by a linear map and get  the line segment SS = (xx0,yy0)->(xx1,yy1)
xx0 := u_x*x0 + u_y*y0;
yy0 := v_x*x0 + v_y*y0;

xx1 := u_x*x1 + u_y*y1;
yy1 := v_x*x1 + v_y*y1;

# we compare the lenth of S and SS: 
hh := factor((xx1-xx0)^2 + (yy1-yy0)^2 - (x1-x0)^2 - (y1-y0)^2);
hhh := factor(hh/r^2);

# this corresponds to equation (6) for a finite map
err := factor(int((eval(hhh,{rx=cos(t),ry=sin(t)}))^2,t=0..2*Pi))/(2*Pi);

J := Matrix([[u_x,u_y], [v_x,v_y]]);
JT := Transpose(J);
E := Eigenvalues(Multiply(JT,J));

# singular values of Jacobian
s1 := E[1];
s2 := E[2];

# this is an unweighted summand of $F_{metric}^{2D}$,
# we discard the scaling factor (1/2) for the error term.
eerr := (1/2) * ( (s1 - 1)^2 + (s2 - 1)^2  - (1/4)*(s1 - s2)^2 );

factor(err-eerr);