// bolza.m
//
// author: Nils Bruin
//
// Formulas relating Bolza's formulas for genus 2 curves with (4,4)-split
// Jacobians to Bruin-Doerksen. See:
//
// Oskar Bolza, Ueber die reduction hyperelliptischer integrale erster
// ordnung und erster gattung auf elliptische durch eine transformation vierten
// grade, Math. Ann. 28 (1887), no. 3, 447-456.
//
// This file is formatted for MAGMA. However, the actual formulas should be very
// easy to adjust for any other reasonable computer algebra system.
//
// Notational convention:
// Bolza uses parameters (lambda, mu, nu, lambda', mu', nu'). These are encoded as
// (l,m,n, lp,mp,np) in this file.

K<l,m,n>:=RationalFunctionField(Rationals(),3);
L<s,b,c>:=RationalFunctionField(Rationals(),3);
P<x>:=PolynomialRing(K);

lp:=-(2*l^2*n-l*m^2-m*n)/(-n^2+3*l*m*n-2*m^3)/3;
mp:=(l^2*m+l*n-2*m^2)/(-n^2+3*l*m*n-2*m^3)/9;
np:=-(2*l^3-3*l*m+n)/(-n^2+3*l*m*n-2*m^3)/27;

R:=np*x^6-6*l*np*x^5+3*(4*m*np+l*mp)*x^4+2*(l*lp+5*n*np)*x^3+3*(4*mp*n+lp*m)*x^2-6*lp*n*x+n;
R1:=(l*x-2*n)*(np*x^3-3*(9*l^2*np-6*m*np-l*mp)*x^2+12*(9*l*n*np+3*mp*n+lp*m)*x+12*n*(3*m*mp-l*lp));
R2:=(lp*x-2*np)*(n*x^3-3*(9*lp^2*n-6*mp*n-lp*m)*x^2+12*(9*lp*np*n+3*m*np+l*mp)*x+12*np*(3*mp*m-lp*l));

z1:=(l*x^4+4*l*n*x+3*m*n)/(l*x^2+2*l^2*x+(3*l*m-n)/2);
z2:=(lp+4*lp*np*x^3+3*mp*np*x^4)/(lp+2*lp^2*x+(3*lp*mp-np)/2*x^2)/x^2;

//Bolza considers the genus 2 curve C: y^2=R(x). It admits degree 4 covers to
//the elliptic curves
//
// E1: w1^2=l * R1(z1)
// E2: w2^2=lp * R2(z2)
//
// by putting:
//
//  w1 = sqrt(l * R1(z1) * R(x)) / y
//  w2 = sqrt(lp* R2(z2) * R(x)) / y


//In Bruin-Doerksen, the elliptic curves with models
//E1 : v1^2=u^3+b*u+c
//E2 : v2^2=d*(u-a)*(u^3+b*u+c)
//are considered. For certain a=a(s) and d=d(s), these curves have
//anti-isometric 4-torsion and hence there may be a genus 2 curve whose jacobian
//is (4,4)-isogenous to E1xE2. We can express (s,b,c) as functions in (l,m,n)
//to express Bolza's family as a cover of Bruin-Doerksen's representation.
//Below are S,B,C and also the resulting A,D.

S:=(48*l^5*m*n^3 - 77*l^4*m^3*n^2 - 16*l^4*n^4 + 39*l^3*m^5*n - 39*l^3*m^2*n^3
    -  6*l^2*m^7 + 63*l^2*m^4*n^2 + 21*l^2*m*n^4 - 20*l*m^6*n - 3*l*m^3*n^3 -
    l*n^5 - 6*m^5*n^2 - 3*m^2*n^4)/(l*m - n);

A:=(12*l^5*m*n^3 - 26*l^4*m^3*n^2 - 4*l^4*n^4 + 21*l^3*m^5*n + 6*l^3*m^2*n^3 - 
    6*l^2*m^7 - 9*l^2*m^4*n^2 - 6*l^2*m*n^4 + 4*l*m^6*n + 15*l*m^3*n^3 + 2*l*n^5
    - 6*m^5*n^2 - 3*m^2*n^4)/(l*m - n);

B:=432*l^7*m^2*n^5 - 1791*l^6*m^4*n^4 - 288*l^6*m*n^6 + 2784*l^5*m^6*n^3 + 
    1056*l^5*m^3*n^5 + 48*l^5*n^7 - 2079*l^4*m^8*n^2 - 990*l^4*m^5*n^4 - 
    306*l^4*m^2*n^6 + 756*l^3*m^10*n + 96*l^3*m^7*n^3 + 132*l^3*m^4*n^5 + 
    96*l^3*m*n^7 - 108*l^2*m^12 + 228*l^2*m^9*n^2 + 114*l^2*m^6*n^4 + 
    24*l^2*m^3*n^6 - 15*l^2*n^8 - 72*l*m^11*n - 36*l*m^8*n^3 - 72*l*m^5*n^5 - 
    36*l*m^2*n^7 - 12*m^10*n^2 + 12*m^7*n^4 + 21*m^4*n^6 + 6*m*n^8;

C:=7776*l^10*m^4*n^7 - 35478*l^9*m^6*n^6 - 12096*l^9*m^3*n^8 + 69903*l^8*m^8*n^5 + 
    41040*l^8*m^5*n^7 + 6912*l^8*m^2*n^9 - 76986*l^7*m^10*n^4 - 
    54576*l^7*m^7*n^6 - 12510*l^7*m^4*n^8 - 1728*l^7*m*n^10 + 51102*l^6*m^12*n^3
    + 32384*l^6*m^9*n^5 + 1326*l^6*m^6*n^7 - 1056*l^6*m^3*n^9 + 160*l^6*n^11 - 
    20412*l^5*m^14*n^2 - 3540*l^5*m^11*n^4 + 11754*l^5*m^8*n^6 + 
    4500*l^5*m^5*n^8 + 894*l^5*m^2*n^10 + 4536*l^4*m^16*n - 5724*l^4*m^13*n^3 - 
    9870*l^4*m^10*n^5 - 180*l^4*m^7*n^7 + 1080*l^4*m^4*n^9 - 48*l^4*m*n^11 - 
    432*l^3*m^18 + 2880*l^3*m^15*n^2 + 2488*l^3*m^12*n^4 - 3800*l^3*m^9*n^6 - 
    3510*l^3*m^6*n^8 - 856*l^3*m^3*n^10 - 10*l^3*n^12 - 432*l^2*m^17*n + 
    240*l^2*m^14*n^3 + 2328*l^2*m^11*n^5 + 1890*l^2*m^8*n^7 + 696*l^2*m^5*n^9 + 
    138*l^2*m^2*n^11 - 144*l*m^16*n^2 - 384*l*m^13*n^4 - 60*l*m^10*n^6 + 
    108*l*m^7*n^8 + 6*l*m^4*n^10 - 12*l*m*n^12 - 16*m^15*n^3 - 104*m^12*n^5 - 
    124*m^9*n^7 - 50*m^6*n^9 - 4*m^3*n^11 + n^13;
    
D:=36*l^5*m^2*n^2 - 51*l^4*m^4*n - 48*l^4*m*n^3 + 18*l^3*m^6 + 6*l^3*m^3*n^2 + 
    12*l^3*n^4 + 54*l^2*m^5*n + 72*l^2*m^2*n^3 - 24*l*m^7 - 90*l*m^4*n^2 - 
    30*l*m*n^4 + 24*m^6*n + 18*m^3*n^3 + 3*n^5;

// Both (s,b,c) and (l,m,n) are homogeneous with weights (1,2,3).
// In order to show that Bolza's family is birational to Bruin-Doerksen,
// we express m/l^2 and n/l^3 as rational functions in (s,b,c):

mu_over_lambda_squared:=(243*s^14*c^2 - 756*s^13*b^2*c + 540*s^12*b^4 -
    3726*s^12*b*c^2 + 5184*s^11*b^3*c - 9234*s^11*c^3 - 360*s^10*b^5 +
    24597*s^10*b^2*c^2 - 5796*s^9*b^4*c +  41958*s^9*b*c^3 + 756*s^8*b^6 -
    15552*s^8*b^3*c^2 + 43011*s^8*c^4 +  2592*s^7*b^5*c - 28836*s^7*b^2*c^3 +
    336*s^6*b^7 + 9261*s^6*b^4*c^2 -  13608*s^6*b*c^4 + 900*s^5*b^6*c +
    12636*s^5*b^3*c^3 - 16524*s^5*c^5 +  68*s^4*b^8 + 3402*s^4*b^5*c^2 +
    26622*s^4*b^2*c^4 - 96*s^3*b^7*c +  1782*s^3*b^4*c^3 + 20088*s^3*b*c^5 +
    24*s^2*b^9 + 171*s^2*b^6*c^2 +  1296*s^2*b^3*c^4 + 9720*s^2*c^6 + 20*s*b^8*c
    + 126*s*b^5*c^3 - 108*s*b^2*c^5 + 4/3*b^10 + 36*b^7*c^2 + 279*b^4*c^4 +
    648*b*c^6) / (36*s^14*b^3 + 243*s^14*c^2 + 216*s^12*b^4 + 1458*s^12*b*c^2 +
    360*s^11*b^3*c +  2430*s^11*c^3 + 444*s^10*b^5 + 2997*s^10*b^2*c^2 +
    1512*s^9*b^4*c +  10206*s^9*b*c^3 + 336*s^8*b^6 + 3456*s^8*b^3*c^2 +
    8019*s^8*c^4 +  1872*s^7*b^5*c + 12636*s^7*b^2*c^3 + 28*s^6*b^7 +
    3213*s^6*b^4*c^2 +  20412*s^6*b*c^4 + 528*s^5*b^6*c + 5004*s^5*b^3*c^3 +
    9720*s^5*c^5 -  40*s^4*b^8 + 1386*s^4*b^5*c^2 + 11178*s^4*b^2*c^4 -
    184*s^3*b^7*c +  486*s^3*b^4*c^3 + 11664*s^3*b*c^5 + 4*s^2*b^9 -
    213*s^2*b^6*c^2 -  1044*s^2*b^3*c^4 + 3888*s^2*c^6 + 8*s*b^8*c -
    42*s*b^5*c^3 - 648*s*b^2*c^5 + 4*b^7*c^2 + 27*b^4*c^4);

nu_over_lambda_cubed:=(243*s^18*c^2 - 972*s^17*b^2*c + 972*s^16*b^4 -
    5832*s^16*b*c^2 +  12312*s^15*b^3*c - 16038*s^15*c^3 - 1296*s^14*b^5 +
    73872*s^14*b^2*c^2 -  22680*s^13*b^4*c + 193914*s^13*b*c^3 + 3024*s^12*b^6 -
    106596*s^12*b^3*c^2 + 270459*s^12*c^4 + 25272*s^11*b^5*c -
    259038*s^11*b^2*c^3 - 432*s^10*b^7 +  109998*s^10*b^4*c^2 -
    123930*s^10*b*c^4 - 9648*s^9*b^6*c +  124578*s^9*b^3*c^3 - 196344*s^9*c^5 +
    936*s^8*b^8 + 12636*s^8*b^5*c^2 +  338013*s^8*b^2*c^4 - 7992*s^7*b^7*c -
    63666*s^7*b^4*c^3 + 256608*s^7*b*c^5 + 1680*s^6*b^9 + 1512*s^6*b^6*c^2 -
    83916*s^6*b^3*c^4 + 163296*s^6*c^6 +  2520*s^5*b^8*c + 1134*s^5*b^5*c^3 -
    136080*s^5*b^2*c^5 + 528*s^4*b^10 +  10260*s^4*b^7*c^2 + 35397*s^4*b^4*c^4 -
    81648*s^4*b*c^6 + 1128*s^3*b^9*c +  17334*s^3*b^6*c^3 + 59616*s^3*b^3*c^5 -
    46656*s^3*c^7 + 48*s^2*b^11 +  2151*s^2*b^8*c^2 + 23814*s^2*b^5*c^4 +
    77760*s^2*b^2*c^6 + 60*s*b^10*c +  1782*s*b^7*c^3 + 16200*s*b^4*c^5 +
    46656*s*b*c^7 + 4/3*b^12 + 60*b^9*c^2 +  963*b^6*c^4 + 6480*b^3*c^6 +
    15552*c^8) / (36*s^18*b^3 + 243*s^18*c^2 + 288*s^16*b^4 + 1944*s^16*b*c^2 +
    504*s^15*b^3*c +  3402*s^15*c^3 + 864*s^14*b^5 + 5832*s^14*b^2*c^2 +
    3096*s^13*b^4*c +  20898*s^13*b*c^3 + 1152*s^12*b^6 + 10404*s^12*b^3*c^2 +
    17739*s^12*c^4 +  6552*s^11*b^5*c + 44226*s^11*b^2*c^3 + 552*s^10*b^7 +
    15174*s^10*b^4*c^2 +  77274*s^10*b*c^4 + 5112*s^9*b^6*c + 40698*s^9*b^3*c^3
    + 41796*s^9*c^5 -  96*s^8*b^8 + 14148*s^8*b^5*c^2 + 99873*s^8*b^2*c^4 +
    360*s^7*b^7*c +  19134*s^7*b^4*c^3 + 112752*s^7*b*c^5 - 256/3*s^6*b^9 +
    3600*s^6*b^6*c^2 +  34524*s^6*b^3*c^4 + 42768*s^6*c^6 - 696*s^5*b^8*c +
    4806*s^5*b^5*c^3 +  64152*s^5*b^2*c^5 + 64/3*s^4*b^10 - 1620*s^4*b^7*c^2 -
    3843*s^4*b^4*c^4 +  54432*s^4*b*c^6 + 280/3*s^3*b^9*c - 1098*s^3*b^6*c^3 -
    9360*s^3*b^3*c^5 +  15552*s^3*c^7 - 4/3*s^2*b^11 + 111*s^2*b^8*c^2 +
    234*s^2*b^5*c^4 -  3888*s^2*b^2*c^6 - 8/3*s*b^10*c + 30*s*b^7*c^3 +
    324*s*b^4*c^5 - 4/3*b^9*c^2 - 9*b^6*c^4);
