
#Maple set to prove Lemma 1
restart;
with(LinearAlgebra):

#(23); we assume 0<=t<=1
# we can also assume t<0 0r t>1 by setting s:=0 instead, which gives the same results	
s := (1-t)*t;

#(22)
uf := -4*y;
vf := 2*x-40*s^3;
Vf := Vector([uf,vf]);

#(24),(25)
x_Ra := 20*s^3;
y_Ra := 15*s^2*(2*t-1);
a_Ra :=  -60*s^2*(2*t-1);
b_Ra := 0;
c_Ra := 0;


###

#derivativs of Vf
NablaVf := Matrix([
[diff(Vf[1],x) , diff(Vf[1],y) ], 
[diff(Vf[2],x) , diff(Vf[2],y)]]);
Vf_t := Vector([diff(Vf[1],t),diff(Vf[2],t)]);

#unknown Killing field (7) and its derivatives
Wf := Vector([a-c*y,b+c*x]):
NablaWf := Matrix([
[diff(Wf[1],x) , diff(Wf[1],y) ], 
[diff(Wf[2],x) , diff(Wf[2],y)]]);
Wf_t := Vector([a_t-c_t*y,b_t+c_t*x]):

#(12)
Mf := Vf_t - Wf_t + Multiply( NablaVf, Wf) - Multiply( NablaWf, Vf);


#compute e1 in (14)
hM := Multiply( Transpose(Mf), Mf);
hM2 := eval(hM,{x=xxx+r*cos(al),y=yyy+r*sin(al)});
hM3 := factor(int(int(hM2*r,r=0..R),al=0..2*Pi)/(Pi*R^2));
e1 := eval(hM3,{xxx=x,yyy=y});

#intext formula between (17) and (18)
e2 := Multiply( Transpose(Vf-Wf),Vf-Wf);

#(18)
e := mu*e1 + e2;

# we consider e and its derivatives of the curve
evalset := {a=a_Ra,b=b_Ra,c=c_Ra,x=x_Ra,y=y_Ra,a_t=0,b_t=0,c_t=0};

#proof of (26)
simplify(eval(e,evalset));


#compute partial derivatives of e 

e_x := diff(e,x);
e_y := diff(e,y);
e_a := diff(e,a);
e_b := diff(e,b);
e_c := diff(e,c);

#Gradient of e
NablaXA_e := Vector([e_x,e_y,e_a,e_b,e_c]);

e_xx := diff(e_x,x);
e_xy := diff(e_x,y);
e_xa := diff(e_x,a);
e_xb := diff(e_x,b);
e_xc := diff(e_x,c);
e_yy := diff(e_y,y);
e_ya := diff(e_y,a);
e_yb := diff(e_y,b);
e_yc := diff(e_y,c);
e_aa := diff(e_a,a);
e_ab := diff(e_a,b);
e_ac := diff(e_a,c);
e_bb := diff(e_b,b);
e_bc := diff(e_b,c);
e_cc := diff(e_c,c);

#Hessian of e
HXA_e := Matrix([
[e_xx ,e_xy ,e_xa ,e_xb ,e_xc ], 
[e_xy ,e_yy ,e_ya ,e_yb ,e_yc ], 
[e_xa ,e_ya ,e_aa ,e_ab ,e_ac ], 
[e_xb ,e_yb ,e_yb ,e_bb ,e_bc ], 
[e_xc ,e_yc ,e_ac ,e_bc ,e_cc ]]);


#proof of (27)
simplify(eval(NablaXA_e , evalset ));

#(13) of additional material
H1 := Matrix([
[0 ,0 ,0 ,0 ,0 ], 
[0 ,0 ,0 ,0 ,0 ], 
[0,0,8,0, 240*(t - 1/2)*s^2 ], 
[0,0,0,32, 640*s^3], 
[0,0, 240*(t - 1/2)*s^2,640*s^3 , 200*s^4*(64*s^2 - 36*s + 9) ]]);

#(14) of additional material
H_R := Matrix([
[0 ,0 ,0 ,0 ,0 ], 
[0 ,0 ,0 ,0 ,0 ], 
[0 ,0 ,0 ,0 ,0  ], 
[0 ,0 ,0 ,0 ,0 ], 
[0 ,0 ,0 ,0 ,4 ]]);

#(14) of additional material
H2 := Matrix([
[8 ,0 ,0 ,-4 ,-80*s^3 ], 
[0 ,32 ,8 ,0 ,-240*(t - 1/2)*s^2 ], 
[0 ,8 ,2 ,0 ,-60*(t - 1/2)*s^2  ], 
[-4 ,0 ,0 ,2 ,40*s^3 ], 
[-80*s^3 ,-240*(t - 1/2)*s^2 ,-60*(t - 1/2)*s^2 ,40*s^3 ,50*(16*s^2 - 36*s + 9)*s^4 ]]);

#proof of (12) of additional material
simplify(mu*H1 + mu*R^2*H_R + H2 - eval(HXA_e,evalset));

#(21) of additional material
Rank(H1);
Rank(H2);
Rank(H_R);

#(22)-(25) of additional material
s1 := 200*s^4*(-4*s*(-16*s + 9) + 9) + 40;
p1 := 6400*s^4*(-4*s*(-4*s + 9) + 9) + 256;
s2 := 50*s^4*(-4*s*(-4*s + 9) + 9) + 44;
p2 := 100*s^4*(-4*s*(-68*s + 45) + 45) + 340;

#compute Eigenvalues of H1, H2
EV1 := Eigenvalues(H1);
EV2 := Eigenvalues(H2);

#proof that s1,p1,s2,p2 are correct
simplify(EV1[4]+EV1[5]-s1);
simplify(EV1[4]*EV1[5]-p1);
simplify(EV2[4]+EV2[5]-s2);
simplify(EV2[4]*EV2[5]-p2);

#(27) of additional material
Determinant(eval(HXA_e,evalset));






