
// Title : On families of 13-congruent elliptic curves
// Author : T. Fisher
// Version : January 2020

// This is a MAGMA file containing some of the formulae
// mentioned in the paper.

//////////////////////////////////////////////////////////////////
//                                                              //
// XE13Cubics(k,a,b,coords)                                     //
//    The cubic forms defining X_E(13,k) (and some lines)       //
//    in Theorems 2.2, 5.10 and 5.14.                           //
//                                                              //
// XE13RawTwistedInvariants(k,Q,c6,coords)                      //
//    The twisted versions of Q and F initially computed        //
//    in Sections 5.2 and 5.3.                                  //
//                                                              //
// XE13TwistedInvariants(k,a,b,coords)                          //
//    The twisted versions of Q and F finally computed          //  
//    in Sections 5.2 and 5.3.                                  //
//                                                              //
// XE13AlternatingMatrix(k,a,b,coords)                          //
//    The alternating matrix N in Sections 5.2 and 5.3.         //
//                                                              //
// Z13Equations(k,r,s)                                          //
//    The equations for Z(13,k) in Theorem 2.4.                 //
//                                                              //
// Z13ModuliInterpretation(k,r,s)                               //
//    The polynomials A,B,D in Theorem 2.4(iii) such that       //
//     j*j' = A^3/D and (j - 1728)*(j'- 1728) = B^2/D.          //
//                                                              //
// ExtraRelationsDirect(zz)                                     //
//    The polynomials f1,f2,f3,f7,g2,h2,l2,l4,l6 used           //
//    in Section 6.1.                                           //
//                                                              //
// ExtraRelationsSkew(zz)                                       //
//    The polynomials f5,f8,f10,g10,f11,f12,f13,f15,f18,f20,f23 //
//    used in Section 6.2.                                      //
//                                                              //
//////////////////////////////////////////////////////////////////

function XE13Cubics(k,a,b,coords)
// The cubic forms defining X_E(13,k) (and some lines)      
// in Theorems 2.2, 5.10 and 5.14.                           
  assert k in [1,2];
  x1,x2,x3,x4,x5,x6,x7 := Explode(coords);
  if k eq 1 then 
  cubics := [
  6*x1^2*x7 + 24*x1*x2*x7 + 2*x1*x3*x5 + 6*x1*x4*x6 - 12*a*x1*x6*x7 -
    6*x2^2*x7 + 2*x2*x3*x5 - 6*x2*x4*x5 + 6*x2*x4*x6 - 12*a*x2*x5*x7 -
    12*a*x2*x6*x7 + 108*b*x2*x7^2 - x3^3 + 4*x3^2*x4 - 16*a*x3^2*x7 -
    6*x3*x4^2 + 60*a*x3*x4*x7 - 4*a*x3*x5^2 - 8*a*x3*x5*x6 -
    18*b*x3*x5*x7 - 9*a*x3*x6^2 - 72*b*x3*x6*x7 - 72*a^2*x3*x7^2 -
    2*x4^3 - 54*a*x4^2*x7 + 4*a*x4*x5^2 + 12*a*x4*x5*x6 +
    90*b*x4*x5*x7 + 12*a*x4*x6^2 + 162*b*x4*x6*x7 + 168*a^2*x4*x7^2 -
    7*b*x5^3 - 27*b*x5^2*x6 - 10*a^2*x5^2*x7 - 36*b*x5*x6^2 -
    12*a^2*x5*x6*x7 - 72*a*b*x5*x7^2 - 27*b*x6^3 - 216*a*b*x6*x7^2 +
    (-112*a^3 - 54*b^2)*x7^3,
  3*x1^2*x5 - 3*x1^2*x6 + 12*x1*x2*x5 - 18*x1*x2*x6 - 12*a*x1*x3*x7 +
    24*x1*x4^2 + 8*a*x1*x5^2 - 144*b*x1*x5*x7 - 54*b*x1*x6*x7 -
    96*a^2*x1*x7^2 - 15*x2^2*x5 - 27*x2^2*x6 - 6*x2*x3^2 + 36*x2*x3*x4
    - 60*a*x2*x3*x7 - 30*x2*x4^2 + 180*a*x2*x4*x7 - 4*a*x2*x5^2 -
    36*a*x2*x5*x6 - 198*b*x2*x5*x7 - 18*a*x2*x6^2 + 54*b*x2*x6*x7 -
    312*a^2*x2*x7^2 - 8*a*x3^2*x5 + 3*a*x3^2*x6 + 36*b*x3^2*x7 +
    10*a*x3*x4*x5 - 36*a*x3*x4*x6 - 36*b*x3*x4*x7 - 24*b*x3*x5^2 -
    18*b*x3*x5*x6 - 52*a^2*x3*x5*x7 + 27*b*x3*x6^2 + 24*a^2*x3*x6*x7 +
    180*a*b*x3*x7^2 + 15*a*x4^2*x5 + 63*a*x4^2*x6 - 54*b*x4^2*x7 -
    18*b*x4*x5^2 - 144*b*x4*x5*x6 - 12*a^2*x4*x5*x7 - 162*b*x4*x6^2 -
    228*a^2*x4*x6*x7 - 108*a*b*x4*x7^2 + a^2*x5^3 - 5*a^2*x5^2*x6 -
    54*a*b*x5^2*x7 - 12*a^2*x5*x6^2 + 144*a*b*x5*x6*x7 + (-48*a^3 +
    405*b^2)*x5*x7^2 - 9*a^2*x6^3 + 216*a*b*x6^2*x7 + (192*a^3 +
    405*b^2)*x6*x7^2 + 432*a^2*b*x7^3,
  6*x1^2*x5 + 36*x1*x2*x5 - 12*x1*x2*x6 + x1*x3^2 - 12*x1*x3*x4 +
    48*x1*x4^2 - 72*a*x1*x4*x7 + 16*a*x1*x5^2 + 12*a*x1*x5*x6 -
    180*b*x1*x5*x7 + 3*a*x1*x6^2 - 108*b*x1*x6*x7 - 48*a^2*x1*x7^2 +
    6*x2^2*x5 - 36*x2^2*x6 - 6*x2*x3^2 + 24*x2*x3*x4 - 48*a*x2*x3*x7 +
    12*x2*x4^2 + 72*a*x2*x4*x7 + 16*a*x2*x5^2 - 24*a*x2*x5*x6 -
    396*b*x2*x5*x7 - 18*a*x2*x6^2 - 336*a^2*x2*x7^2 - 8*a*x3^2*x5 +
    8*a*x3*x4*x5 - 24*a*x3*x4*x6 + 144*b*x3*x4*x7 - 30*b*x3*x5^2 -
    36*b*x3*x5*x6 - 32*a^2*x3*x5*x7 + 48*a^2*x3*x6*x7 - 72*a*b*x3*x7^2
    + 18*a*x4^2*x5 + 36*a*x4^2*x6 - 324*b*x4^2*x7 - 72*b*x4*x5*x6 -
    72*a^2*x4*x5*x7 - 108*b*x4*x6^2 - 240*a^2*x4*x6*x7 +
    648*a*b*x4*x7^2 + 6*a^2*x5^3 + 8*a^2*x5^2*x6 - 108*a*b*x5^2*x7 +
    72*a*b*x5*x6*x7 + 486*b^2*x5*x7^2 + 216*a*b*x6^2*x7 + (240*a^3 +
    324*b^2)*x6*x7^2,
  x1^2*x3 - 3*x1^2*x4 - 12*a*x1^2*x7 + 10*x1*x2*x3 - 36*x1*x2*x4 -
    72*a*x1*x2*x7 + 2*a*x1*x3*x5 + 2*a*x1*x3*x6 - 18*b*x1*x3*x7 -
    12*a*x1*x4*x5 - 6*a*x1*x4*x6 + 18*b*x1*x5^2 + 18*b*x1*x5*x6 +
    24*a^2*x1*x5*x7 + 9*b*x1*x6^2 + 24*a^2*x1*x6*x7 + 9*x2^2*x3 -
    45*x2^2*x4 + 12*a*x2^2*x7 - 6*a*x2*x3*x5 - 90*b*x2*x3*x7 +
    6*a*x2*x4*x5 - 6*a*x2*x4*x6 + 270*b*x2*x4*x7 + 9*b*x2*x5^2 -
    18*b*x2*x5*x6 + 96*a^2*x2*x5*x7 + 72*a^2*x2*x6*x7 -
    756*a*b*x2*x7^2 + 2*a*x3^2*x4 - 3*b*x3^2*x5 + 4*a^2*x3^2*x7 -
    15*a*x3*x4^2 - a^2*x3*x5^2 + 18*a*b*x3*x5*x7 + 72*a*b*x3*x6*x7 +
    (24*a^3 + 81*b^2)*x3*x7^2 + 25*a*x4^3 - 18*b*x4^2*x5 -
    54*b*x4^2*x6 - 60*a^2*x4^2*x7 + 5*a^2*x4*x5^2 + 6*a^2*x4*x5*x6 +
    18*a*b*x4*x5*x7 + 6*a^2*x4*x6^2 - 54*a*b*x4*x6*x7 + (72*a^3 -
    81*b^2)*x4*x7^2 - a*b*x5^3 - 9*a*b*x5^2*x6 + (4*a^3 -
    27*b^2)*x5^2*x7 - 9*a*b*x5*x6^2 + 162*b^2*x5*x6*x7 -
    180*a^2*b*x5*x7^2 + (-12*a^3 + 162*b^2)*x6^2*x7 +
    108*a^2*b*x6*x7^2 + (-64*a^4 + 432*a*b^2)*x7^3,
  -8*x1*x2*x3 + 24*x1*x2*x4 + 48*a*x1*x2*x7 - 8*a*x1*x3*x5 -
    4*a*x1*x3*x6 + 16*a*x1*x4*x5 + 72*b*x1*x4*x7 - 24*b*x1*x5^2 -
    36*b*x1*x5*x6 - 16*a^2*x1*x5*x7 - 18*b*x1*x6^2 - 144*a*b*x1*x7^2 -
    12*x2^2*x3 + 48*x2^2*x4 + 48*a*x2^2*x7 + 72*b*x2*x3*x7 +
    16*a*x2*x4*x5 - 144*b*x2*x4*x7 - 24*b*x2*x5^2 - 64*a^2*x2*x5*x7 -
    48*a^2*x2*x6*x7 + 288*a*b*x2*x7^2 + 2*a*x3^3 - 8*a*x3^2*x4 -
    9*b*x3^2*x6 + 32*a^2*x3^2*x7 + 20*a*x3*x4^2 + 24*b*x3*x4*x5 +
    36*b*x3*x4*x6 - 112*a^2*x3*x4*x7 + 12*a^2*x3*x5^2 +
    24*a^2*x3*x5*x6 + 30*a^2*x3*x6^2 + 72*a*b*x3*x6*x7 + (128*a^3 -
    108*b^2)*x3*x7^2 - 16*a*x4^3 + 36*b*x4^2*x6 + 144*a^2*x4^2*x7 -
    16*a^2*x4*x5^2 - 40*a^2*x4*x5*x6 - 144*a*b*x4*x5*x7 -
    48*a^2*x4*x6^2 - 288*a*b*x4*x6*x7 - 384*a^3*x4*x7^2 + 16*a*b*x5^3
    + 72*a*b*x5^2*x6 + 16*a^3*x5^2*x7 + 108*a*b*x5*x6^2 + (16*a^3 -
    216*b^2)*x5*x6*x7 + 288*a^2*b*x5*x7^2 + 81*a*b*x6^3 -
    324*b^2*x6^2*x7 + 432*a^2*b*x6*x7^2 + (256*a^4 - 432*a*b^2)*x7^3,
  x1^2*x2 - a*x1^2*x5 - a*x1^2*x6 - 9*b*x1^2*x7 + 4*x1*x2^2 -
    12*a*x1*x2*x5 - 2*a*x1*x2*x6 + 6*a*x1*x3*x4 + 3*b*x1*x3*x6 -
    16*a*x1*x4^2 + 6*b*x1*x4*x5 + 32*a^2*x1*x4*x7 - 4*a^2*x1*x5^2 -
    6*a^2*x1*x5*x6 + 36*a*b*x1*x5*x7 - 2*a^2*x1*x6^2 + 54*a*b*x1*x6*x7
    + (-16*a^3 - 108*b^2)*x1*x7^2 + x2^3 - 15*a*x2^2*x5 + 3*a*x2^2*x6
    + 81*b*x2^2*x7 + 6*a*x2*x3*x4 - 25*a*x2*x4^2 + 6*b*x2*x4*x5 +
    32*a^2*x2*x4*x7 - 11*a^2*x2*x5^2 - 6*a^2*x2*x5*x6 +
    162*a*b*x2*x5*x7 + 54*a*b*x2*x6*x7 + (56*a^3 - 189*b^2)*x2*x7^2 +
    2*b*x3^3 - 9*b*x3^2*x4 - 2*a^2*x3^2*x5 + 54*a*b*x3^2*x7 +
    12*b*x3*x4^2 + 6*a^2*x3*x4*x5 - 198*a*b*x3*x4*x7 + a*b*x3*x5^2 +
    (-24*a^3 + 36*b^2)*x3*x5*x7 + 18*a*b*x3*x6^2 + (-24*a^3 +
    162*b^2)*x3*x6*x7 + 276*a^2*b*x3*x7^2 - 6*b*x4^3 - 7*a^2*x4^2*x5 +
    7*a^2*x4^2*x6 + 225*a*b*x4^2*x7 - 3*a*b*x4*x5^2 - 18*a*b*x4*x5*x6
    + (56*a^3 - 54*b^2)*x4*x5*x7 - 27*a*b*x4*x6^2 + (40*a^3 -
    216*b^2)*x4*x6*x7 - 612*a^2*b*x4*x7^2 + (-3*a^3 - 3*b^2)*x5^3 +
    (-7*a^3 - 9*b^2)*x5^2*x6 + 15*a^2*b*x5^2*x7 - 6*a^3*x5*x6^2 -
    42*a^2*b*x5*x6*x7 + (-40*a^4 + 81*a*b^2)*x5*x7^2 + (-4*a^3 +
    27*b^2)*x6^3 - 54*a^2*b*x6^2*x7 + (-56*a^4 + 459*a*b^2)*x6*x7^2 +
    (312*a^3*b - 405*b^3)*x7^3,
  2*a*x1^2*x5 - 36*b*x1^2*x7 + 4*x1*x2^2 + 20*a*x1*x2*x5 +
    4*a*x1*x2*x6 - 288*b*x1*x2*x7 - a*x1*x3^2 + 4*a*x1*x3*x4 -
    12*b*x1*x3*x5 - 6*b*x1*x3*x6 - 16*a^2*x1*x3*x7 + 4*a*x1*x4^2 +
    12*b*x1*x4*x5 + 40*a^2*x1*x4*x7 + 4*a^2*x1*x5^2 + 4*a^2*x1*x5*x6 -
    108*a*b*x1*x5*x7 + a^2*x1*x6^2 - 36*a*b*x1*x6*x7 + (-80*a^3 +
    108*b^2)*x1*x7^2 + 8*x2^3 + 18*a*x2^2*x5 - 180*b*x2^2*x7 -
    2*a*x2*x3^2 + 16*a*x2*x3*x4 - 24*b*x2*x3*x5 - 16*a^2*x2*x3*x7 -
    20*a*x2*x4^2 + 84*b*x2*x4*x5 + 88*a^2*x2*x4*x7 + 8*a^2*x2*x5^2 -
    108*a*b*x2*x5*x7 - 6*a^2*x2*x6^2 + 72*a*b*x2*x6*x7 + (-176*a^3 -
    864*b^2)*x2*x7^2 + b*x3^3 + 2*a^2*x3^2*x6 + 24*a*b*x3^2*x7 -
    12*b*x3*x4^2 - 16*a^2*x3*x4*x6 - 72*a*b*x3*x4*x7 + 2*a*b*x3*x5^2 +
    24*a*b*x3*x5*x6 + 72*b^2*x3*x5*x7 + 27*a*b*x3*x6^2 + (16*a^3 +
    108*b^2)*x3*x6*x7 + 120*a^2*b*x3*x7^2 + 36*b*x4^3 + 6*a^2*x4^2*x5
    + 32*a^2*x4^2*x6 - 72*a*b*x4*x5*x6 + (-24*a^3 - 324*b^2)*x4*x5*x7
    - 72*a*b*x4*x6^2 + (-112*a^3 - 432*b^2)*x4*x6*x7 -
    216*a^2*b*x4*x7^2 + (2*a^3 + 18*b^2)*x5^3 + (4*a^3 +
    90*b^2)*x5^2*x6 + 108*b^2*x5*x6^2 + 96*a^2*b*x5*x6*x7 +
    162*a*b^2*x5*x7^2 + (-2*a^3 + 54*b^2)*x6^3 + 72*a^2*b*x6^2*x7 +
    (80*a^4 + 432*a*b^2)*x6*x7^2 + (288*a^3*b + 972*b^3)*x7^3 ];
  else
  cubics := [ 
  2*x1^2*x6 + x1^2*x7 - 4*x1*x2*x6 - 4*x1*x2*x7 - 2*x1*x3*x4 -
    4*x1*x3*x5 + 12*x1*x4^2 + 20*x1*x4*x5 + 4*x1*x5^2 - a*x1*x6^2 +
    2*a*x1*x7^2 + 12*x2^2*x7 + 8*x2*x4^2 + 8*x2*x4*x5 + 8*x2*x5^2 +
    2*a*x2*x6^2 - 4*a*x2*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 + 8*a^2*x4^2*x5 -
    32*a*b*x4^2*x6 - 64*a*b*x4^2*x7 + 12*a^2*x4*x5^2 - 52*a*b*x4*x5*x6
    - 128*a*b*x4*x5*x7 + 18*b^2*x4*x6^2 + 144*b^2*x4*x6*x7 + (5*a^3 +
    216*b^2)*x4*x7^2 + 12*a^2*x5^3 - 8*a*b*x5^2*x6 - 32*a*b*x5^2*x7 +
    a^3*x5*x6^2 + (-4*a^3 + 48*b^2)*x5*x6*x7 + (-8*a^3 +
    48*b^2)*x5*x7^2 + 5*a^2*b*x6^2*x7 + 10*a^2*b*x6*x7^2 +
    4*a^2*b*x7^3 ];
  end if;
  return cubics;
end function;

function XE13RawTwistedInvariants(k,Q,c6,coords)
// The twisted versions of Q and F initially computed
// in Sections 5.2 and 5.3.
  assert k in [1,2];
  y1,y2,y3,y4,y5,y6,y7 := Explode(coords);
  if k eq 1 then 
  QQ := Q*y1^2 - 4*Q^2*y1*y2 + 44*Q^5*y1*y4 + c6*y1*y6 - 36*Q^7*y1*y7
  - 2*Q^3*y2^2 - 124*Q^6*y2*y4 - c6*y2*y5 + 300*Q^8*y2*y7 + 6*Q^4*y3^2
  + c6*y3*y4 + 324*Q^7*y3*y5 - 12*Q^8*y3*y6 - 2*Q^2*c6*y3*y7 +
  502*Q^9*y4^2 + 24*Q^3*c6*y4*y5 + 27*Q^4*c6*y4*y6 - 396*Q^11*y4*y7 +
  4302*Q^10*y5^2 - 36*Q^11*y5*y6 - 35*Q^5*c6*y5*y7 + 150*Q^12*y6^2 -
  54*Q^6*c6*y6*y7 - (3282*Q^13 - c6^2)*y7^2;
  FF := -Q^2*y1^4 - 4*Q^3*y1^3*y2 - 124*Q^6*y1^3*y4 - c6*y1^3*y5 +
  300*Q^8*y1^3*y7 - 6*Q^4*y1^2*y2^2 - 372*Q^7*y1^2*y2*y4 -
  3*Q*c6*y1^2*y2*y5 + 900*Q^9*y1^2*y2*y7 + 18*Q^5*y1^2*y3^2 +
  3*Q*c6*y1^2*y3*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^13*y2^2*y5^2 - 13716*Q^14*y2^2*y5*y6 -
  1134*Q^8*c6*y2^2*y5*y7 + (774*Q^15 - 9*Q^2*c6^2)*y2^2*y6^2 -
  81*Q^9*c6*y2^2*y6*y7 + 66582*Q^16*y2^2*y7^2 - 3564*Q^10*y2*y3^2*y4 -
  33*Q^4*c6*y2*y3^2*y5 + 12*Q^5*c6*y2*y3^2*y6 + 9468*Q^12*y2*y3^2*y7 -
  567*Q^6*c6*y2*y3*y4^2 + (-194184*Q^13 - 3*c6^2)*y2*y3*y4*y5 +
  5400*Q^14*y2*y3*y4*y6 + 2424*Q^8*c6*y2*y3*y4*y7 -
  1746*Q^7*c6*y2*y3*y5^2 + 570*Q^8*c6*y2*y3*y5*y6 + (524232*Q^15 -
  6*Q^2*c6^2)*y2*y3*y5*y7 + 120*Q^9*c6*y2*y3*y6^2 + (-13752*Q^16 +
  12*Q^3*c6^2)*y2*y3*y6*y7 - 2073*Q^10*c6*y2*y3*y7^2 + (-119812*Q^15 -
  3*Q^2*c6^2)*y2*y4^3 - 16410*Q^9*c6*y2*y4^2*y5 -
  2997*Q^10*c6*y2*y4^2*y6 + (839628*Q^17 - 126*Q^4*c6^2)*y2*y4^2*y7 +
  (-2628828*Q^16 - 78*Q^3*c6^2)*y2*y4*y5^2 + (109512*Q^17 -
  81*Q^4*c6^2)*y2*y4*y5*y6 + 63066*Q^11*c6*y2*y4*y5*y7 + (25812*Q^18 +
  54*Q^5*c6^2)*y2*y4*y6^2 + 24624*Q^12*c6*y2*y4*y6*y7 + (-1992348*Q^19
  + 876*Q^6*c6^2)*y2*y4*y7^2 - 23025*Q^10*c6*y2*y5^3 +
  6462*Q^11*c6*y2*y5^2*y6 + (7120332*Q^18 - 120*Q^5*c6^2)*y2*y5^2*y7 +
  1911*Q^12*c6*y2*y5*y6^2 + (-360072*Q^19 + 450*Q^6*c6^2)*y2*y5*y6*y7
  - 48324*Q^13*c6*y2*y5*y7^2 + (252*Q^13*c6 + c6^3)*y2*y6^3 +
  (-9540*Q^20 + 90*Q^7*c6^2)*y2*y6^2*y7 - 23571*Q^14*c6*y2*y6*y7^2 +
  (2022996*Q^21 - 1320*Q^8*c6^2)*y2*y7^3 - 3*Q^8*y3^4 +
  27*Q^4*c6*y3^3*y4 - 36*Q^11*y3^3*y5 + 300*Q^12*y3^3*y6 -
  54*Q^6*c6*y3^3*y7 + 16110*Q^13*y3^2*y4^2 + 2076*Q^7*c6*y3^2*y4*y5 +
  699*Q^8*c6*y3^2*y4*y6 - 18108*Q^15*y3^2*y4*y7 + 7398*Q^14*y3^2*y5^2
  + (21708*Q^15 + 6*Q^2*c6^2)*y3^2*y5*y6 - 3723*Q^9*c6*y3^2*y5*y7 +
  846*Q^16*y3^2*y6^2 - 1554*Q^10*c6*y3^2*y6*y7 + (-64170*Q^17 +
  12*Q^4*c6^2)*y3^2*y7^2 + 1728*Q^9*c6*y3*y4^3 +
  831492*Q^16*y3*y4^2*y5 + (8388*Q^17 + 96*Q^4*c6^2)*y3*y4^2*y6 -
  2997*Q^11*c6*y3*y4^2*y7 + 52695*Q^10*c6*y3*y4*y5^2 +
  38976*Q^11*c6*y3*y4*y5*y6 + (-946728*Q^18 +
  123*Q^5*c6^2)*y3*y4*y5*y7 - 759*Q^12*c6*y3*y4*y6^2 + (-83016*Q^19 -
  396*Q^6*c6^2)*y3*y4*y6*y7 - 9762*Q^13*c6*y3*y4*y7^2 + (252396*Q^17 -
  5*Q^4*c6^2)*y3*y5^3 + (532116*Q^18 + 312*Q^5*c6^2)*y3*y5^2*y6 -
  82692*Q^12*c6*y3*y5^2*y7 + (8532*Q^19 + 24*Q^6*c6^2)*y3*y5*y6^2 +
  (-95730*Q^13*c6 + 6*c6^3)*y3*y5*y6*y7 + (-3818988*Q^20 +
  702*Q^7*c6^2)*y3*y5*y7^2 + (-2580*Q^20 - 8*Q^7*c6^2)*y3*y6^3 -
  42*Q^14*c6*y3*y6^2*y7 + (-169740*Q^21 + 516*Q^8*c6^2)*y3*y6*y7^2 +
  (1667*Q^15*c6 + 8*Q^2*c6^3)*y3*y7^3 + (-818167*Q^18 +
  18*Q^5*c6^2)*y4^4 + 18251*Q^12*c6*y4^3*y5 + (-612*Q^13*c6 +
  c6^3)*y4^3*y6 + (8268780*Q^20 - 201*Q^7*c6^2)*y4^3*y7 +
  (10424214*Q^19 - 117*Q^6*c6^2)*y4^2*y5^2 + (166428*Q^20 +
  2364*Q^7*c6^2)*y4^2*y5*y6 + 103824*Q^14*c6*y4^2*y5*y7 + (410958*Q^21
  - 45*Q^8*c6^2)*y4^2*y6^2 + (53001*Q^15*c6 - 12*Q^2*c6^3)*y4^2*y6*y7
  + (-30388338*Q^22 + 1494*Q^9*c6^2)*y4^2*y7^2 + (441174*Q^13*c6 -
  c6^3)*y4*y5^3 + 533781*Q^14*c6*y4*y5^2*y6 + (-11358252*Q^21 +
  3702*Q^8*c6^2)*y4*y5^2*y7 - 8076*Q^15*c6*y4*y5*y6^2 + (-223128*Q^22
  - 9483*Q^9*c6^2)*y4*y5*y6*y7 - 617577*Q^16*c6*y4*y5*y7^2 -
  5535*Q^16*c6*y4*y6^3 + (-3036924*Q^23 + 90*Q^10*c6^2)*y4*y6^2*y7 +
  (-307530*Q^17*c6 + 48*Q^4*c6^3)*y4*y6*y7^2 + (47713596*Q^24 -
  4956*Q^11*c6^2)*y4*y7^3 + (2313765*Q^20 - 140*Q^7*c6^2)*y5^4 +
  (4415796*Q^21 + 4047*Q^8*c6^2)*y5^3*y6 + (-586479*Q^15*c6 +
  4*Q^2*c6^3)*y5^3*y7 + (-275130*Q^22 + 576*Q^9*c6^2)*y5^2*y6^2 +
  (-1400400*Q^16*c6 + 144*Q^3*c6^3)*y5^2*y6*y7 + (-55525122*Q^23 +
  9000*Q^10*c6^2)*y5^2*y7^2 + (11268*Q^23 - 158*Q^10*c6^2)*y5*y6^3 -
  8691*Q^17*c6*y5*y6^2*y7 + (-8633844*Q^24 +
  13038*Q^11*c6^2)*y5*y6*y7^2 + (234050*Q^18*c6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y4^3 - 3456*Q^13*y1*y4^2*y5
  - 1620*Q^8*c6*y1*y4^2*y6 + 420*Q^9*c6*y1*y4^2*y7 +
  144*Q^7*c6*y1*y4*y5^2 + (264384*Q^15 + 3*Q^2*c6^2)*y1*y4*y5*y6 +
  (32832*Q^16 - 12*Q^3*c6^2)*y1*y4*y5*y7 + 67716*Q^10*c6*y1*y4*y6^2 -
  14616*Q^11*c6*y1*y4*y6*y7 - 21021*Q^12*c6*y1*y4*y7^2 + (-15552*Q^14
  - 8*Q*c6^2)*y1*y5^3 - 20952*Q^9*c6*y1*y5^2*y6 +
  34524*Q^10*c6*y1*y5^2*y7 + (-16407360*Q^17 +
  396*Q^4*c6^2)*y1*y5*y6^2 + (44457984*Q^18 +
  564*Q^5*c6^2)*y1*y5*y6*y7 + (-46015344*Q^19 -
  2538*Q^6*c6^2)*y1*y5*y7^2 - 1090692*Q^12*c6*y1*y6^3 +
  1537704*Q^13*c6*y1*y6^2*y7 - 3293829*Q^14*c6*y1*y6*y7^2 +
  (3440051*Q^15*c6 - 8*Q^2*c6^3)*y1*y7^3 + 9*Q^10*y2^4 +
  8*Q^4*c6*y2^3*y3 - 96*Q^11*y2^3*y4 - 36*Q^5*c6*y2^3*y5 + (-1584*Q^13
  + c6^2)*y2^3*y6 + (6372*Q^14 + 2*Q*c6^2)*y2^3*y7 -
  1080*Q^11*y2^2*y3^2 + 42*Q^5*c6*y2^2*y3*y4 - 1728*Q^12*y2^2*y3*y5 -
  2682*Q^7*c6*y2^2*y3*y6 + 2100*Q^8*c6*y2^2*y3*y7 - 360*Q^12*y2^2*y4^2
  - 96*Q^6*c6*y2^2*y4*y5 + (34128*Q^14 + 3*Q*c6^2)*y2^2*y4*y6 +
  (-26496*Q^15 + 6*Q^2*c6^2)*y2^2*y4*y7 + 24624*Q^13*y2^2*y5^2 +
  9540*Q^8*c6*y2^2*y5*y6 - 13356*Q^9*c6*y2^2*y5*y7 + (-51192*Q^16 -
  285*Q^3*c6^2)*y2^2*y6^2 + (-1182384*Q^17 - 231*Q^4*c6^2)*y2^2*y6*y7
  + (1540566*Q^18 + 678*Q^5*c6^2)*y2^2*y7^2 + 24*Q^5*c6*y2*y3^3 -
  2880*Q^12*y2*y3^2*y4 + 216*Q^6*c6*y2*y3^2*y5 +
  219456*Q^14*y2*y3^2*y6 + (-216432*Q^15 - 6*Q^2*c6^2)*y2*y3^2*y7 +
  24*Q^6*c6*y2*y3*y4^2 + (6912*Q^13 - 6*c6^2)*y2*y3*y4*y5 -
  7344*Q^8*c6*y2*y3*y4*y6 + 11508*Q^9*c6*y2*y3*y4*y7 -
  576*Q^7*c6*y2*y3*y5^2 + (155520*Q^15 + 120*Q^2*c6^2)*y2*y3*y5*y6 +
  (-680832*Q^16 + 156*Q^3*c6^2)*y2*y3*y5*y7 +
  278424*Q^10*c6*y2*y3*y6^2 - 555156*Q^11*c6*y2*y3*y6*y7 +
  96432*Q^12*c6*y2*y3*y7^2 + (-1536*Q^13 + c6^2)*y2*y4^3 -
  24*Q^7*c6*y2*y4^2*y5 + (136512*Q^15 - 54*Q^2*c6^2)*y2*y4^2*y6 +
  (25776*Q^16 - 96*Q^3*c6^2)*y2*y4^2*y7 + (27648*Q^14 +
  6*Q*c6^2)*y2*y4*y5^2 + 14544*Q^9*c6*y2*y4*y5*y6 -
  28896*Q^10*c6*y2*y4*y5*y7 + (-4955904*Q^17 +
  513*Q^4*c6^2)*y2*y4*y6^2 + (3068064*Q^18 +
  3450*Q^5*c6^2)*y2*y4*y6*y7 + (-5172192*Q^19 +
  4896*Q^6*c6^2)*y2*y4*y7^2 - 2664*Q^8*c6*y2*y5^3 + (-4266432*Q^16 -
  48*Q^3*c6^2)*y2*y5^2*y6 + (6342624*Q^17 - 6*Q^4*c6^2)*y2*y5^2*y7 -
  817344*Q^11*c6*y2*y5*y6^2 + 2461032*Q^12*c6*y2*y5*y6*y7 -
  1543500*Q^13*c6*y2*y5*y7^2 + (27646272*Q^19 +
  20211*Q^6*c6^2)*y2*y6^3 + (78445584*Q^20 -
  47796*Q^7*c6^2)*y2*y6^2*y7 + (-169402320*Q^21 -
  159057*Q^8*c6^2)*y2*y6*y7^2 + (184760100*Q^22 +
  34902*Q^9*c6^2)*y2*y7^3 + 560*Q^12*y3^4 - 8*Q^6*c6*y3^3*y4 +
  (-12672*Q^13 - 2*c6^2)*y3^3*y5 - 1432*Q^8*c6*y3^3*y6 +
  4200*Q^9*c6*y3^3*y7 + 864*Q^13*y3^2*y4^2 + 480*Q^7*c6*y3^2*y4*y5 +
  (176256*Q^15 - 3*Q^2*c6^2)*y3^2*y4*y6 + (-515520*Q^16 -
  12*Q^3*c6^2)*y3^2*y4*y7 + (41472*Q^14 + 6*Q*c6^2)*y3^2*y5^2 -
  27936*Q^9*c6*y3^2*y5*y6 + 14616*Q^10*c6*y3^2*y5*y7 + (-9940320*Q^17
  + 81*Q^4*c6^2)*y3^2*y6^2 + (26623296*Q^18 + 882*Q^5*c6^2)*y3^2*y6*y7
  + (-6529464*Q^19 - 270*Q^6*c6^2)*y3^2*y7^2 - 24*Q^7*c6*y3*y4^3 +
  (3456*Q^14 - 6*Q*c6^2)*y3*y4^2*y5 - 216*Q^9*c6*y3*y4^2*y6 +
  6888*Q^10*c6*y3*y4^2*y7 - 1440*Q^8*c6*y3*y4*y5^2 + (-580608*Q^16 +
  696*Q^3*c6^2)*y3*y4*y5*y6 + (1071360*Q^17 -
  606*Q^4*c6^2)*y3*y4*y5*y7 + 279288*Q^11*c6*y3*y4*y6^2 -
  1164240*Q^12*c6*y3*y4*y6*y7 + 637098*Q^13*c6*y3*y4*y7^2 +
  (-51840*Q^15 + 2*Q^2*c6^2)*y3*y5^3 + 76032*Q^10*c6*y3*y5^2*y6 -
  32256*Q^11*c6*y3*y5^2*y7 + (-2021760*Q^18 -
  11646*Q^5*c6^2)*y3*y5*y6^2 + (32876928*Q^19 -
  336*Q^6*c6^2)*y3*y5*y6*y7 + (-67186368*Q^20 +
  19428*Q^7*c6^2)*y3*y5*y7^2 + (-8907624*Q^13*c6 + c6^3)*y3*y6^3 +
  (33085800*Q^14*c6 + 6*Q*c6^3)*y3*y6^2*y7 + (-20261754*Q^15*c6 +
  12*Q^2*c6^3)*y3*y6*y7^2 + (-3716540*Q^16*c6 - 16*Q^3*c6^3)*y3*y7^3 +
  (-1296*Q^14 + Q*c6^2)*y4^4 - 32*Q^8*c6*y4^3*y5 + (210816*Q^16 -
  151*Q^3*c6^2)*y4^3*y6 + (-64128*Q^17 + 13*Q^4*c6^2)*y4^3*y7 +
  (13824*Q^15 + 6*Q^2*c6^2)*y4^2*y5^2 + 3168*Q^10*c6*y4^2*y5*y6 +
  168*Q^11*c6*y4^2*y5*y7 + (-10837152*Q^18 + 6213*Q^5*c6^2)*y4^2*y6^2
  + (1366848*Q^19 + 6888*Q^6*c6^2)*y4^2*y6*y7 + (4119192*Q^20 -
  7392*Q^7*c6^2)*y4^2*y7^2 - 960*Q^9*c6*y4*y5^3 + (-2638656*Q^17 -
  693*Q^4*c6^2)*y4*y5^2*y6 + (2439936*Q^18 + 954*Q^5*c6^2)*y4*y5^2*y7
  - 565920*Q^12*c6*y4*y5*y6^2 + (2096208*Q^13*c6 -
  12*c6^3)*y4*y5*y6*y7 + (-2291712*Q^14*c6 - 24*Q*c6^3)*y4*y5*y7^2 +
  (251906112*Q^20 - 82680*Q^7*c6^2)*y4*y6^3 + (-136411776*Q^21 -
  295299*Q^8*c6^2)*y4*y6^2*y7 + (249446736*Q^22 -
  46221*Q^9*c6^2)*y4*y6*y7^2 + (-344710848*Q^23 +
  441834*Q^10*c6^2)*y4*y7^3 + (116640*Q^16 + 90*Q^3*c6^2)*y5^4 +
  207504*Q^11*c6*y5^3*y6 - 388584*Q^12*c6*y5^3*y7 + (187557120*Q^19 +
  6093*Q^6*c6^2)*y5^2*y6^2 + (-526616640*Q^20 -
  7242*Q^7*c6^2)*y5^2*y6*y7 + (439244208*Q^21 -
  8886*Q^8*c6^2)*y5^2*y7^2 + (22835088*Q^14*c6 - Q*c6^3)*y5*y6^3 +
  (-108207360*Q^15*c6 + 222*Q^2*c6^3)*y5*y6^2*y7 + (153055908*Q^16*c6
  + 852*Q^3*c6^3)*y5*y6*y7^2 + (-51690564*Q^17*c6 +
  880*Q^4*c6^3)*y5*y7^3 + (-1543804272*Q^22 - 205137*Q^9*c6^2)*y6^4 +
  (-1620171072*Q^23 + 4117251*Q^10*c6^2)*y6^3*y7 + (5227442568*Q^24 +
  4640781*Q^11*c6^2)*y6^2*y7^2 + (-9223568208*Q^25 -
  9833377*Q^12*c6^2)*y6*y7^3 + (8864253225*Q^26 - 1969502*Q^13*c6^2 +
  2*c6^4)*y7^4;
  end if;
  return QQ,FF;
end function;

function XE13TwistedInvariants(k,a,b,coords)
// The twisted versions of Q and F finally computed
// in Sections 5.2 and 5.3.
  assert k in [1,2];
  x1,x2,x3,x4,x5,x6,x7 := Explode(coords);
  if k eq 1 then 
  QQ := x1^2 - 6*x2^2 + a*x3^2 + 9*b*x3*x6 - 6*a*x4^2 + 18*b*x4*x5 +
  24*a^2*x4*x7 + 2*a^2*x5^2 - 36*a*b*x5*x7 - 3*a^2*x6^2 + 162*b^2*x7^2;
  FF := -x1^4 - 12*x1^3*x2 - 54*x1^2*x2^2 - 18*a*x1^2*x4^2 +
  54*b*x1^2*x4*x5 + 72*a^2*x1^2*x4*x7 + 6*a^2*x1^2*x5^2 -
  108*a*b*x1^2*x5*x7 + 486*b^2*x1^2*x7^2 - 60*x1*x2^3 +
  12*a*x1*x2*x3^2 - 72*a*x1*x2*x3*x4 + 108*b*x1*x2*x3*x5 +
  108*b*x1*x2*x3*x6 + 144*a^2*x1*x2*x3*x7 + 36*a*x1*x2*x4^2 -
  108*b*x1*x2*x4*x5 - 324*b*x1*x2*x4*x6 - 144*a^2*x1*x2*x4*x7 -
  12*a^2*x1*x2*x5^2 - 72*a^2*x1*x2*x5*x6 + 216*a*b*x1*x2*x5*x7 -
  36*a^2*x1*x2*x6^2 + 648*a*b*x1*x2*x6*x7 - 972*b^2*x1*x2*x7^2 +
  6*b*x1*x3^3 - 54*b*x1*x3^2*x4 - 12*a^2*x1*x3^2*x5 -
  12*a^2*x1*x3^2*x6 + 108*a*b*x1*x3^2*x7 + 108*b*x1*x3*x4^2 +
  48*a^2*x1*x3*x4*x5 + 72*a^2*x1*x3*x4*x6 - 432*a*b*x1*x3*x4*x7 -
  36*a*b*x1*x3*x5^2 - 108*a*b*x1*x3*x5*x6 + (-48*a^3 +
  324*b^2)*x1*x3*x5*x7 - 54*a*b*x1*x3*x6^2 - 144*a^3*x1*x3*x6*x7 +
  432*a^2*b*x1*x3*x7^2 - 108*b*x1*x4^3 - 72*a^2*x1*x4^2*x5 -
  72*a^2*x1*x4^2*x6 + 648*a*b*x1*x4^2*x7 + 108*a*b*x1*x4*x5^2 +
  216*a*b*x1*x4*x5*x6 + (144*a^3 - 972*b^2)*x1*x4*x5*x7 +
  162*a*b*x1*x4*x6^2 + (432*a^3 + 972*b^2)*x1*x4*x6*x7 -
  1296*a^2*b*x1*x4*x7^2 - 54*b^2*x1*x5^3 + (-24*a^3 -
  324*b^2)*x1*x5^2*x6 - 216*a^2*b*x1*x5^2*x7 + (-36*a^3 -
  486*b^2)*x1*x5*x6^2 - 432*a^2*b*x1*x5*x6*x7 - 288*a^4*x1*x5*x7^2 +
  (-12*a^3 - 162*b^2)*x1*x6^3 - 324*a^2*b*x1*x6^2*x7 + (-576*a^4 -
  1944*a*b^2)*x1*x6*x7^2 + (1728*a^3*b + 5832*b^3)*x1*x7^3 - 15*x2^4 -
  24*a*x2^3*x5 + 216*b*x2^3*x7 + 24*a*x2^2*x3^2 - 72*a*x2^2*x3*x4 +
  216*b*x2^2*x3*x5 + 216*b*x2^2*x3*x6 + 288*a^2*x2^2*x3*x7 +
  18*a*x2^2*x4^2 - 378*b*x2^2*x4*x5 - 324*b*x2^2*x4*x6 -
  504*a^2*x2^2*x4*x7 - 78*a^2*x2^2*x5^2 - 144*a^2*x2^2*x5*x6 +
  1404*a*b*x2^2*x5*x7 - 72*a^2*x2^2*x6^2 + 1296*a*b*x2^2*x6*x7 -
  6318*b^2*x2^2*x7^2 + 6*b*x2*x3^3 - 108*b*x2*x3^2*x4 -
  12*a^2*x2*x3^2*x6 + 432*b*x2*x3*x4^2 + 48*a^2*x2*x3*x4*x5 +
  144*a^2*x2*x3*x4*x6 - 432*a*b*x2*x3*x4*x7 + 72*a*b*x2*x3*x5^2 +
  (96*a^3 - 648*b^2)*x2*x3*x5*x7 - 54*a*b*x2*x3*x6^2 + (-144*a^3 -
  972*b^2)*x2*x3*x6*x7 - 864*a^2*b*x2*x3*x7^2 - 540*b*x2*x4^3 -
  144*a^2*x2*x4^2*x5 - 288*a^2*x2*x4^2*x6 + 1296*a*b*x2*x4^2*x7 -
  108*a*b*x2*x4*x5^2 + 216*a*b*x2*x4*x5*x6 + (-144*a^3 +
  972*b^2)*x2*x4*x5*x7 + 324*a*b*x2*x4*x6^2 + (864*a^3 +
  3888*b^2)*x2*x4*x6*x7 + 1296*a^2*b*x2*x4*x7^2 + (-24*a^3 +
  54*b^2)*x2*x5^3 + (-96*a^3 - 324*b^2)*x2*x5^2*x6 +
  864*a^2*b*x2*x5^2*x7 + (-72*a^3 - 486*b^2)*x2*x5*x6^2 +
  864*a^2*b*x2*x5*x6*x7 + (288*a^4 - 5832*a*b^2)*x2*x5*x7^2 + (-12*a^3
  - 162*b^2)*x2*x6^3 + (-576*a^4 - 7776*a*b^2)*x2*x6*x7^2 +
  (-1728*a^3*b + 11664*b^3)*x2*x7^3 + 2*a^2*x3^4 - 12*a^2*x3^3*x4 +
  6*a*b*x3^3*x5 + 36*a*b*x3^3*x6 + (24*a^3 + 108*b^2)*x3^3*x7 +
  48*a^2*x3^2*x4^2 - 36*a*b*x3^2*x4*x5 - 162*a*b*x3^2*x4*x6 + (-96*a^3
  - 324*b^2)*x3^2*x4*x7 + (12*a^3 + 27*b^2)*x3^2*x5^2 +
  81*b^2*x3^2*x5*x6 - 144*a^2*b*x3^2*x5*x7 + (-12*a^3 +
  162*b^2)*x3^2*x6^2 + 108*a^2*b*x3^2*x6*x7 + (48*a^4 +
  972*a*b^2)*x3^2*x7^2 - 120*a^2*x3*x4^3 + 216*a*b*x3*x4^2*x5 +
  432*a*b*x3*x4^2*x6 + 288*a^3*x3*x4^2*x7 - 24*a^3*x3*x4*x5^2 +
  (24*a^3 - 162*b^2)*x3*x4*x5*x6 + 432*a^2*b*x3*x4*x5*x7 + (36*a^3 -
  486*b^2)*x3*x4*x6^2 - 432*a^2*b*x3*x4*x6*x7 - 1944*a*b^2*x3*x4*x7^2
  + 48*a^2*b*x3*x5^3 + 72*a^2*b*x3*x5^2*x6 + (96*a^4 -
  648*a*b^2)*x3*x5^2*x7 - 54*a^2*b*x3*x5*x6^2 + (48*a^4 -
  972*a*b^2)*x3*x5*x6*x7 - 1728*a^3*b*x3*x5*x7^2 - 108*a^2*b*x3*x6^3 +
  (72*a^4 + 972*a*b^2)*x3*x6^2*x7 + (-432*a^3*b + 2916*b^3)*x3*x6*x7^2
  + (-384*a^5 + 2592*a^2*b^2)*x3*x7^3 + 117*a^2*x4^4 - 378*a*b*x4^3*x5
  - 540*a*b*x4^3*x6 + (-552*a^3 - 324*b^2)*x4^3*x7 + (30*a^3 +
  324*b^2)*x4^2*x5^2 + 972*b^2*x4^2*x5*x6 + 324*a^2*b*x4^2*x5*x7 +
  972*b^2*x4^2*x6^2 + 1296*a^2*b*x4^2*x6*x7 + (576*a^4 +
  2430*a*b^2)*x4^2*x7^2 - 90*a^2*b*x4*x5^3 - 108*a^2*b*x4*x5^2*x6 +
  (-168*a^4 + 1296*a*b^2)*x4*x5^2*x7 + 108*a^2*b*x4*x5*x6^2 +
  1944*a*b^2*x4*x5*x6*x7 + (3024*a^3*b - 1458*b^3)*x4*x5*x7^2 +
  162*a^2*b*x4*x6^3 + (-144*a^4 - 1944*a*b^2)*x4*x6^2*x7 -
  8748*b^3*x4*x6*x7^2 + (576*a^5 - 5832*a^2*b^2)*x4*x7^3 + (a^4 +
  81*a*b^2)*x5^4 + 216*a*b^2*x5^3*x6 + (228*a^3*b - 1134*b^3)*x5^3*x7
  + (12*a^4 + 243*a*b^2)*x5^2*x6^2 + (432*a^3*b - 2916*b^3)*x5^2*x6*x7
  + (192*a^5 - 4050*a^2*b^2)*x5^2*x7^2 + (24*a^4 + 81*a*b^2)*x5*x6^3 +
  (216*a^3*b - 1458*b^3)*x5*x6^2*x7 - 7776*a^2*b^2*x5*x6*x7^2 +
  (-4320*a^4*b + 2916*a*b^3)*x5*x7^3 + 18*a^4*x6^4 + (108*a^3*b +
  1458*b^3)*x6^3*x7 + (144*a^5 - 972*a^2*b^2)*x6^2*x7^2 + (-1728*a^4*b
  + 11664*a*b^3)*x6*x7^3 + (-960*a^6 + 3888*a^3*b^2 - 2187*b^4)*x7^4;
  else
  QQ := x1*x7 + x2*x6 + x3*x5 + x4^2;
  FF := 48*a*x1^3*x2 + 36*b*x1^3*x3 + 72*b*x1^3*x5 + 8*a^2*x1^3*x6 +
  16*a^2*x1^3*x7 - 144*a*x1^2*x2^2 - 216*b*x1^2*x2*x3 +
  432*b*x1^2*x2*x4 + 432*b*x1^2*x2*x5 - 48*a^2*x1^2*x2*x7 +
  12*a^2*x1^2*x3^2 - 48*a^2*x1^2*x3*x4 - 48*a^2*x1^2*x3*x5 -
  36*a*b*x1^2*x3*x7 - 96*a^2*x1^2*x4*x5 + 72*a*b*x1^2*x4*x6 +
  144*a*b*x1^2*x4*x7 - 144*a^2*x1^2*x5^2 + 144*a*b*x1^2*x5*x6 +
  216*a*b*x1^2*x5*x7 + (-12*a^3 - 108*b^2)*x1^2*x6^2 + (-24*a^3 -
  216*b^2)*x1^2*x6*x7 + 192*a*x1*x2^3 + 432*b*x1*x2^2*x3 -
  864*b*x1*x2^2*x4 - 864*b*x1*x2^2*x5 + 96*a^2*x1*x2^2*x7 -
  48*a^2*x1*x2*x3^2 + 192*a^2*x1*x2*x3*x4 + 192*a^2*x1*x2*x3*x5 +
  144*a*b*x1*x2*x3*x7 - 192*a^2*x1*x2*x4^2 - 384*a^2*x1*x2*x4*x5 -
  288*a*b*x1*x2*x4*x7 - 192*a^2*x1*x2*x5^2 - 288*a*b*x1*x2*x5*x7 +
  (192*a^3 + 1296*b^2)*x1*x2*x6*x7 + (144*a^3 + 864*b^2)*x1*x2*x7^2 -
  12*a*b*x1*x3^3 + 72*a*b*x1*x3^2*x4 + 72*a*b*x1*x3^2*x5 + (24*a^3 +
  216*b^2)*x1*x3^2*x7 - 144*a*b*x1*x3*x4^2 - 288*a*b*x1*x3*x4*x5 +
  (-96*a^3 - 864*b^2)*x1*x3*x4*x7 - 144*a*b*x1*x3*x5^2 + (96*a^3 +
  432*b^2)*x1*x3*x5*x7 + 12*a^2*b*x1*x3*x7^2 - 288*a*b*x1*x4^2*x5 +
  (96*a^3 + 864*b^2)*x1*x4^2*x6 + (192*a^3 + 1728*b^2)*x1*x4^2*x7 -
  864*a*b*x1*x4*x5^2 + 864*b^2*x1*x4*x5*x6 - 192*a^3*x1*x4*x5*x7 +
  24*a^2*b*x1*x4*x6^2 + 48*a^2*b*x1*x4*x6*x7 - 672*a*b*x1*x5^3 +
  864*b^2*x1*x5^2*x6 + (96*a^3 + 1728*b^2)*x1*x5^2*x7 +
  48*a^2*b*x1*x5*x6^2 + 96*a^2*b*x1*x5*x6*x7 + 24*a^2*b*x1*x5*x7^2 +
  (8*a^4 + 48*a*b^2)*x1*x6^3 + (24*a^4 + 144*a*b^2)*x1*x6^2*x7 +
  (24*a^4 + 144*a*b^2)*x1*x6*x7^2 + (16*a^4 + 96*a*b^2)*x1*x7^3 -
  48*a*x2^4 - 144*b*x2^3*x3 + 576*b*x2^3*x4 - 64*a^2*x2^3*x6 +
  24*a^2*x2^2*x3^2 - 192*a^2*x2^2*x3*x4 - 144*a*b*x2^2*x3*x6 +
  192*a^2*x2^2*x4^2 + 384*a^2*x2^2*x4*x5 + 288*a*b*x2^2*x4*x7 +
  672*a^2*x2^2*x5^2 - 720*a*b*x2^2*x5*x6 - 288*a*b*x2^2*x5*x7 +
  (24*a^3 + 432*b^2)*x2^2*x6^2 + (-192*a^3 - 864*b^2)*x2^2*x6*x7 +
  (-240*a^3 - 1728*b^2)*x2^2*x7^2 + 12*a*b*x2*x3^3 -
  144*a*b*x2*x3^2*x4 - 108*b^2*x2*x3^2*x6 + 288*a*b*x2*x3*x4^2 +
  576*a*b*x2*x3*x4*x5 + (-192*a^3 - 864*b^2)*x2*x3*x4*x7 +
  1008*a*b*x2*x3*x5^2 + (96*a^3 - 432*b^2)*x2*x3*x5*x6 + (-192*a^3 -
  1728*b^2)*x2*x3*x5*x7 - 60*a^2*b*x2*x3*x6^2 - 96*a^2*b*x2*x3*x6*x7 +
  24*a^2*b*x2*x3*x7^2 - 192*a*b*x2*x4^3 - 576*a*b*x2*x4^2*x5 +
  (576*a^3 + 3456*b^2)*x2*x4^2*x7 - 576*a*b*x2*x4*x5^2 + (1152*a^3 +
  6912*b^2)*x2*x4*x5*x7 + 48*a^2*b*x2*x4*x7^2 + 576*a*b*x2*x5^3 -
  1728*b^2*x2*x5^2*x6 + 384*a^3*x2*x5^2*x7 - 192*a^2*b*x2*x5*x6^2 -
  480*a^2*b*x2*x5*x6*x7 - 144*a^2*b*x2*x5*x7^2 + (-16*a^4 -
  60*a*b^2)*x2*x6^3 + (-48*a^4 - 144*a*b^2)*x2*x6^2*x7 +
  144*a*b^2*x2*x6*x7^2 + (48*a^4 + 288*a*b^2)*x2*x7^3 + (a^3 +
  9*b^2)*x3^4 + (-16*a^3 - 144*b^2)*x3^3*x4 + (-16*a^3 -
  108*b^2)*x3^3*x5 + 4*a^2*b*x3^3*x6 + (48*a^3 + 432*b^2)*x3^2*x4^2 +
  (96*a^3 + 864*b^2)*x3^2*x4*x5 - 24*a^2*b*x3^2*x4*x7 + (72*a^3 +
  864*b^2)*x3^2*x5^2 + 60*a^2*b*x3^2*x5*x6 + 24*a^2*b*x3^2*x5*x7 +
  (6*a^4 + 18*a*b^2)*x3^2*x6^2 - 36*a*b^2*x3^2*x6*x7 + (-12*a^4 -
  72*a*b^2)*x3^2*x7^2 + (-64*a^3 - 576*b^2)*x3*x4^3 + (-192*a^3 -
  1728*b^2)*x3*x4^2*x5 + 48*a^2*b*x3*x4^2*x7 + (-192*a^3 -
  1728*b^2)*x3*x4*x5^2 + 96*a^2*b*x3*x4*x5*x7 + (-48*a^4 -
  288*a*b^2)*x3*x4*x7^2 - 64*a^3*x3*x5^3 + 192*a^2*b*x3*x5^2*x6 +
  288*a^2*b*x3*x5^2*x7 + (48*a^4 + 180*a*b^2)*x3*x5*x6^2 + (96*a^4 +
  288*a*b^2)*x3*x5*x6*x7 + (-48*a^4 - 432*a*b^2)*x3*x5*x7^2 +
  (-32*a^3*b - 180*b^3)*x3*x6^3 + (-84*a^3*b - 432*b^3)*x3*x6^2*x7 +
  (48*a^3*b + 432*b^3)*x3*x6*x7^2 + (132*a^3*b + 864*b^3)*x3*x7^3 +
  (128*a^3 + 864*b^2)*x4^4 + (384*a^3 + 2304*b^2)*x4^3*x5 -
  32*a^2*b*x4^3*x6 - 64*a^2*b*x4^3*x7 + 192*a^3*x4^2*x5^2 -
  192*a^2*b*x4^2*x5*x6 - 288*a^2*b*x4^2*x5*x7 + (-48*a^4 -
  288*a*b^2)*x4^2*x6^2 + (-96*a^4 - 576*a*b^2)*x4^2*x6*x7 + (-384*a^3
  - 4608*b^2)*x4*x5^3 - 384*a^2*b*x4*x5^2*x6 - 480*a^2*b*x4*x5^2*x7 +
  (-192*a^4 - 1152*a*b^2)*x4*x5*x6^2 + (-384*a^4 -
  2304*a*b^2)*x4*x5*x6*x7 + (-96*a^4 - 576*a*b^2)*x4*x5*x7^2 +
  (88*a^3*b + 576*b^3)*x4*x6^3 + (264*a^3*b + 1728*b^3)*x4*x6^2*x7 +
  (264*a^3*b + 1728*b^3)*x4*x6*x7^2 + (176*a^3*b + 1152*b^3)*x4*x7^3 +
  (-240*a^3 - 2304*b^2)*x5^4 - 80*a^2*b*x5^3*x6 - 32*a^2*b*x5^3*x7 +
  (-120*a^4 - 864*a*b^2)*x5^2*x6^2 + (-384*a^4 -
  2880*a*b^2)*x5^2*x6*x7 + (-48*a^4 - 576*a*b^2)*x5^2*x7^2 + (76*a^3*b
  + 576*b^3)*x5*x6^3 + (336*a^3*b + 2592*b^3)*x5*x6^2*x7 + (192*a^3*b
  + 1728*b^3)*x5*x6*x7^2 + (328*a^3*b + 2304*b^3)*x5*x7^3 + (a^5 +
  9*a^2*b^2)*x6^4 + (8*a^5 + 68*a^2*b^2)*x6^3*x7 + (12*a^5 +
  108*a^2*b^2)*x6^2*x7^2 + (56*a^5 + 392*a^2*b^2)*x6*x7^3 + (48*a^5 +
  320*a^2*b^2)*x7^4;
  end if;
  return QQ,FF;
end function;

function XE13AlternatingMatrix(k,a,b,coords)
// The alternating matrix N in Sections 5.2 and 5.3.
  assert k in [1,2];
  x1,x2,x3,x4,x5,x6,x7 := Explode(coords);
  if k eq 1 then 
  N := Matrix(7,7,[ 0, 12*x7, -2*x5 - 3*x6, 6*x5 + 6*x6, 2*x3 - 6*x4 +
  12*a*x7, 3*x3 - 6*x4 + 12*a*x7, -12*x2 - 12*a*x5 - 12*a*x6, -12*x7,
  0, -6*x5 - 6*x6, 12*x5 + 18*x6, 6*x3 - 12*x4 + 24*a*x7, 6*x3 - 18*x4
  + 36*a*x7, 12*x1 - 24*a*x5 - 36*a*x6, 2*x5 + 3*x6, 6*x5 + 6*x6, 0,
  -12*a*x7, -2*x1 - 6*x2 + 18*b*x7, -3*x1 - 6*x2, 12*a*x4 - 18*b*x5,
  -6*x5 - 6*x6, -12*x5 - 18*x6, 12*a*x7, 0, 6*x1 + 12*x2, 6*x1 + 18*x2
  + 54*b*x7, -12*a*x3 - 54*b*x6, -2*x3 + 6*x4 - 12*a*x7, -6*x3 + 12*x4
  - 24*a*x7, 2*x1 + 6*x2 - 18*b*x7, -6*x1 - 12*x2, 0, 12*a^2*x7,
  12*a*x1 + 24*a*x2 + 18*b*x3 - 12*a^2*x6, -3*x3 + 6*x4 - 12*a*x7,
  -6*x3 + 18*x4 - 36*a*x7, 3*x1 + 6*x2, -6*x1 - 18*x2 - 54*b*x7,
  -12*a^2*x7, 0, 12*a*x1 + 36*a*x2 + 54*b*x4 + 12*a^2*x5, 12*x2 +
  12*a*x5 + 12*a*x6, -12*x1 + 24*a*x5 + 36*a*x6, -12*a*x4 + 18*b*x5,
  12*a*x3 + 54*b*x6, -12*a*x1 - 24*a*x2 - 18*b*x3 + 12*a^2*x6,
  -12*a*x1 - 36*a*x2 - 54*b*x4 - 12*a^2*x5, 0 ]);
  else
  N := Matrix(7,7,[
    [ 0, 0, 0, x7, -x6, x5, -x4 ],
    [ 0, 0, -x7, -x6, 0, x4, x3 ],
    [ 0, x7, 0, -x5, x4, 0, -x2 ],
    [ -x7, x6, x5, 0, -x3, -x2, x1 ],
    [ x6, 0, -x4, x3, 0, -x1, 0 ],
    [ -x5, -x4, 0, x2, x1, 0, 0 ],
    [ x4, -x3, x2, -x1, 0, 0, 0 ] ]);
  end if;
  return N;
end function;

function Z13Equations(k,r,s)
// The equations for Z(13,1) and Z(13,2) in Theorem 2.4.
  assert k in [1,2];
  if k eq 1 then
    h := s^4 + (2*r^2 - 5*r + 7)*s^3 + (r^4 - 3*r^3 - 14*r^2 + r + 16)*s^2 + 
      r^2*(2*r^3 - 5*r^2 + 15*r + 27)*s + r^4*(r^2 - 1);
    g := 4*(7*r - 8)*s^6 + 22*(r - 2)*s^5 - (28*r^5 + 24*r^4 - 2*r^3 -
      39*r^2 + 2*r + 68)*s^4 + r^2*(84*r^3 + 233*r^2 - 116*r - 223)*s^3
      - r^4*(20*r^2 + 181*r + 181)*s^2 - 4*r^6*(r - 1)*(7*r + 3)*s;
  else
    h := r^3*s^4 + r*(2*r^3 + 7*r^2 + 1)*s^3 + (r^5 + 7*r^4 + 9*r^3 + r^2
      + 1)*s^2 + 2*(r^3 + 2*r + 1)*s + r + 1;
    g := 2*r^4*(5*r + 4)*s^7 + r^3*(19*r^3 + 48*r^2 + 33*r + 22)*s^6
      + r^2*(8*r^5 + 40*r^4 + 79*r^3 + 82*r^2 + 47*r + 21)*s^5
      - r*(r^7 - 29*r^5 - 91*r^4 - 75*r^3 - 53*r^2 - 34*r - 7)*s^4
      + r*(6*r^6 + 35*r^5 + 50*r^4 + 37*r^3 + 42*r^2 + 22*r + 10)*s^3
      + r*(14*r^4 + 33*r^3 + 30*r^2 + 14*r + 1)*s^2 + r^2*(10*r + 13)*s + 2*r;
  end if;
  return g,h;
end function;

function Z13ModuliInterpretation(k,r,s)
// The polynomials A,B,D in Theorem 2.4(iii) such that
// j*j' = A^3/D and (j - 1728)*(j'- 1728) = B^2/D.
  if k eq 1 then 
  A := s^16 + 4*(2*r^2 - r - 59)*s^15 + 2*(14*r^4 - 10*r^3 - 723*r^2 -
    82*r + 1167)*s^14 + 4*(14*r^6 - 7*r^5 - 938*r^4 - 496*r^3 +
    3410*r^2 + 688*r - 2429)*s^13 + (70*r^8 + 28*r^7 - 5334*r^6 -
    7620*r^5 + 32655*r^4 + 22504*r^3 - 50978*r^2 - 11960*r +
    22529)*s^12 + 4*(14*r^10 + 35*r^9 - 1113*r^8 - 3548*r^7 + 9710*r^6
    + 17633*r^5 - 26437*r^4 - 19990*r^3 + 26263*r^2 + 6089*r -
    8086)*s^11 + 2*(14*r^12 + 98*r^11 - 1043*r^10 - 7282*r^9 +
    9796*r^8 + 55960*r^7 - 47209*r^6 - 109304*r^5 + 97355*r^4 +
    70166*r^3 - 69059*r^2 - 13354*r + 14996)*s^10 + 4*(2*r^14 +
    35*r^13 - 84*r^12 - 2106*r^11 - 963*r^10 + 23790*r^9 - 203*r^8 -
    77477*r^7 + 35396*r^6 + 89790*r^5 - 62840*r^4 - 35851*r^3 +
    31375*r^2 + 3918*r - 4512)*s^9 + (r^16 + 52*r^15 + 198*r^14 -
    2524*r^13 - 9599*r^12 + 39224*r^11 + 68112*r^10 - 230940*r^9 -
    54419*r^8 + 496388*r^7 - 178712*r^6 - 388356*r^5 + 244014*r^4 +
    94900*r^3 - 80962*r^2 - 3984*r + 6832)*s^8 + 4*(r - 1)*(2*r^16 +
    36*r^15 - 4*r^14 - 1113*r^13 - 318*r^12 + 12863*r^11 - 5100*r^10 -
    47626*r^9 + 42157*r^8 + 66587*r^7 - 74549*r^6 - 32507*r^5 +
    45003*r^4 + 2637*r^3 - 8490*r^2 + 410*r + 372)*s^7 + 2*(r -
    1)^2*(14*r^16 + 112*r^15 - 192*r^14 - 1904*r^13 + 3666*r^12 +
    12936*r^11 - 33195*r^10 - 32612*r^9 + 100609*r^8 + 30600*r^7 -
    104704*r^6 - 7830*r^5 + 39958*r^4 - 1522*r^3 - 4280*r^2 + 240*r +
    72)*s^6 + 4*(r - 1)^3*r^2*(14*r^14 + 56*r^13 - 114*r^12 - 349*r^11
    + 1610*r^10 - 771*r^9 - 13377*r^8 + 3138*r^7 + 31982*r^6 -
    3678*r^5 - 23167*r^4 + 1142*r^3 + 5574*r^2 - 206*r - 270)*s^5 + (r
    - 1)^4*r^4*(70*r^12 + 168*r^11 - 188*r^10 + 104*r^9 + 928*r^8 -
    12236*r^7 - 25250*r^6 + 25584*r^5 + 52437*r^4 - 15420*r^3 -
    24938*r^2 + 1708*r + 3001)*s^4 + 4*(r - 1)^5*r^6*(14*r^10 + 28*r^9
    + 12*r^8 + 59*r^7 - 415*r^6 - 2127*r^5 - 1850*r^4 + 3058*r^3 +
    3294*r^2 - 884*r - 773)*s^3 + 2*(r - 1)^6*r^8*(14*r^8 + 32*r^7 +
    42*r^6 + 34*r^5 - 573*r^4 - 1558*r^3 - 710*r^2 + 1088*r + 831)*s^2
    + 4*(r - 1)^7*r^10*(r + 1)^2*(2*r^4 + 2*r^3 + 3*r^2 - 4*r - 59)*s
    + (r - 1)^8*r^12*(r + 1)^4;
  B := s^24 + 6*(2*r^2 - r + 85)*s^23 + 3*(22*r^4 - 18*r^3 + 1687*r^2 -
    134*r - 5407)*s^22 + 2*(110*r^6 - 99*r^5 + 11244*r^4 + 545*r^3 -
    73953*r^2 - 11829*r + 75520)*s^21 + 3*(165*r^8 - 110*r^7 +
    19597*r^6 + 9184*r^5 - 202306*r^4 - 96232*r^3 + 427240*r^2 +
    86642*r - 249215)*s^20 + 6*(132*r^10 + 16640*r^8 + 22032*r^7 -
    242909*r^6 - 249027*r^5 + 797234*r^4 + 465774*r^3 - 1002026*r^2 -
    211467*r + 394541)*s^19 + (924*r^12 + 1188*r^11 + 114660*r^10 +
    328948*r^9 - 2207700*r^8 - 4409796*r^7 + 10013570*r^6 +
    12936372*r^5 - 20581971*r^4 - 13098378*r^3 + 18144252*r^2 +
    3819666*r - 5213195)*s^18 + 6*(132*r^14 + 462*r^13 + 15012*r^12 +
    83508*r^11 - 343798*r^10 - 1377340*r^9 + 1991871*r^8 + 5709709*r^7
    - 6146327*r^6 - 9532033*r^5 + 9406125*r^4 + 6383315*r^3 -
    6291647*r^2 - 1323303*r + 1387894)*s^17 + 3*(165*r^16 + 1188*r^15
    + 16242*r^14 + 163416*r^13 - 314155*r^12 - 3396712*r^11 +
    1902696*r^10 + 19092236*r^9 - 9842562*r^8 - 46711380*r^7 +
    27199428*r^6 + 52395806*r^5 - 34515717*r^4 - 25315944*r^3 +
    18554752*r^2 + 3979110*r - 3278580)*s^16 + 2*(110*r^18 + 1485*r^17
    + 9891*r^16 + 152868*r^15 + 106818*r^14 - 4053603*r^13 -
    2688533*r^12 + 30857286*r^11 + 7156437*r^10 - 105626175*r^9 +
    9154092*r^8 + 175450656*r^7 - 53076377*r^6 - 142489290*r^5 +
    63962751*r^4 + 52492706*r^3 - 29203548*r^2 - 6583944*r +
    4310220)*s^15 + 3*(22*r^20 + 550*r^19 + 2855*r^18 + 38154*r^17 +
    193577*r^16 - 1230970*r^15 - 3896435*r^14 + 13386526*r^13 +
    21276203*r^12 - 65294008*r^11 - 44646880*r^10 + 154392248*r^9 +
    27197369*r^8 - 185757934*r^7 + 21585274*r^6 + 114700494*r^5 -
    34255036*r^4 - 33663892*r^3 + 14267169*r^2 + 3531368*r -
    1849064)*s^14 + 6*(2*r^22 + 99*r^21 + 800*r^20 + 3983*r^19 +
    56025*r^18 - 74842*r^17 - 1533832*r^16 + 1779071*r^15 +
    12417459*r^14 - 15842011*r^13 - 41339997*r^12 + 57973601*r^11 +
    61167083*r^10 - 101271937*r^9 - 37803200*r^8 + 91045810*r^7 +
    3410950*r^6 - 44557415*r^5 + 7664289*r^4 + 10927774*r^3 -
    3440672*r^2 - 1012070*r + 424980)*s^13 + (r^24 + 126*r^23 +
    2211*r^22 + 5800*r^21 + 74328*r^20 + 410202*r^19 - 3372387*r^18 -
    4909974*r^17 + 44695173*r^16 + 3818252*r^15 - 219819474*r^14 +
    94078998*r^13 + 475239640*r^12 - 328689996*r^11 - 485212284*r^10 +
    421835110*r^9 + 255245301*r^8 - 272904486*r^7 - 75764855*r^6 +
    115104312*r^5 - 507213*r^4 - 26279316*r^3 + 5370636*r^2 +
    2368080*r - 793288)*s^12 + 6*(r - 1)*(2*r^24 + 100*r^23 + 768*r^22
    + 759*r^21 + 29451*r^20 + 3838*r^19 - 825108*r^18 + 1063643*r^17 +
    7029193*r^16 - 10005196*r^15 - 22693124*r^14 + 31099599*r^13 +
    31593244*r^12 - 39323670*r^11 - 23341598*r^10 + 18431332*r^9 +
    17031214*r^8 - 3733408*r^7 - 9877366*r^6 + 2445262*r^5 +
    1686087*r^4 - 717500*r^3 + 47982*r^2 + 71032*r - 24960)*s^11 +
    3*(r - 1)^2*(22*r^24 + 572*r^23 + 1780*r^22 + 1898*r^21 +
    83489*r^20 - 218894*r^19 - 1139665*r^18 + 4611666*r^17 +
    5937143*r^16 - 21750058*r^15 - 14049699*r^14 + 33469004*r^13 +
    22698544*r^12 - 5617016*r^11 - 39336221*r^10 - 23240414*r^9 +
    44571892*r^8 + 13197854*r^7 - 21469354*r^6 - 1139748*r^5 +
    3553485*r^4 - 72416*r^3 - 170280*r^2 + 15504*r - 4320)*s^10 + 2*(r
    - 1)^3*r*(110*r^23 + 1650*r^22 + 1191*r^21 + 7186*r^20 +
    108417*r^19 - 470658*r^18 - 228655*r^17 + 5732514*r^16 +
    450261*r^15 - 16619142*r^14 - 11192334*r^13 + 7723173*r^12 +
    47086900*r^11 + 22973274*r^10 - 79848051*r^9 - 26129734*r^8 +
    60291771*r^7 + 7403694*r^6 - 19463556*r^5 - 265467*r^4 +
    2356098*r^3 + 34*r^2 - 93204*r + 1296)*s^9 + 3*(r -
    1)^4*r^2*(165*r^22 + 1518*r^21 - 717*r^20 + 7932*r^19 + 38190*r^18
    - 203690*r^17 + 356885*r^16 + 1832548*r^15 + 952*r^14 -
    4502092*r^13 - 11438424*r^12 + 2613212*r^11 + 33907981*r^10 +
    1936234*r^9 - 39406087*r^8 - 1133778*r^7 + 20237883*r^6 -
    384840*r^5 - 4407190*r^4 + 145182*r^3 + 348336*r^2 - 2208*r -
    7344)*s^8 + 6*(r - 1)^5*r^4*(132*r^20 + 792*r^19 - 648*r^18 +
    3936*r^17 + 7191*r^16 - 19538*r^15 + 159214*r^14 + 385596*r^13 +
    369246*r^12 - 1948316*r^11 - 4729000*r^10 + 3556113*r^9 +
    9989544*r^8 - 2876592*r^7 - 8475754*r^6 + 1267161*r^5 +
    3010487*r^4 - 272756*r^3 - 412280*r^2 + 17734*r + 16218)*s^7 + (r
    - 1)^6*r^6*(924*r^18 + 3960*r^17 - 1854*r^16 + 15322*r^15 +
    29913*r^14 + 150594*r^13 + 563654*r^12 + 1440426*r^11 +
    917208*r^10 - 10420646*r^9 - 12015348*r^8 + 17720466*r^7 +
    21213908*r^6 - 11222178*r^5 - 13634049*r^4 + 2993770*r^3 +
    3139203*r^2 - 265662*r - 207179)*s^6 + 6*(r - 1)^7*r^8*(132*r^16 +
    462*r^15 + 155*r^14 + 1249*r^13 + 5717*r^12 + 31582*r^11 +
    66901*r^10 + 136674*r^9 - 108431*r^8 - 941822*r^7 - 450033*r^6 +
    1222477*r^5 + 820277*r^4 - 504354*r^3 - 383119*r^2 + 62956*r +
    43945)*s^5 + 3*(r - 1)^8*r^10*(165*r^14 + 550*r^13 + 647*r^12 +
    1168*r^11 + 9216*r^10 + 43194*r^9 + 87881*r^8 + 93450*r^7 -
    218570*r^6 - 621338*r^5 - 124563*r^4 + 553434*r^3 + 267891*r^2 -
    111658*r - 67507)*s^4 + 2*(r - 1)^9*r^12*(110*r^12 + 396*r^11 +
    696*r^10 + 845*r^9 + 6951*r^8 + 29334*r^7 + 55878*r^6 + 29949*r^5
    - 106569*r^4 - 187462*r^3 - 37026*r^2 + 86250*r + 39304)*s^3 +
    3*(r - 1)^10*r^14*(r + 1)^2*(22*r^8 + 48*r^7 + 74*r^6 + 26*r^5 +
    1245*r^4 + 2818*r^3 + 2070*r^2 - 2864*r - 4879)*s^2 + 6*(r -
    1)^11*r^16*(r + 1)^4*(2*r^4 + 2*r^3 + 3*r^2 - 4*r + 85)*s + (r -
    1)^12*r^18*(r + 1)^6;   
  else // k = 2
  A := r^12*s^12 + 4*r^10*(2*r^3 + 4*r^2 + 7*r - 55)*s^11 +
    2*r^8*(14*r^6 + 56*r^5 + 138*r^4 - 424*r^3 - 381*r^2 - 1068*r +
    99)*s^10 + 4*r^6*(14*r^9 + 84*r^8 + 267*r^7 - 124*r^6 - 438*r^5 -
    2294*r^4 - 1254*r^3 - 1674*r^2 + 142*r + 5)*s^9 + r^4*(70*r^12 +
    560*r^11 + 2180*r^10 + 2544*r^9 + 1930*r^8 - 10832*r^7 - 12520*r^6
    - 26084*r^5 - 15651*r^4 - 13180*r^3 + 636*r^2 + 96*r + 1)*s^8 +
    4*r^3*(14*r^14 + 140*r^13 + 645*r^12 + 1470*r^11 + 2515*r^10 +
    1130*r^9 + 530*r^8 - 6132*r^7 - 10565*r^6 - 15221*r^5 - 9904*r^4 -
    4854*r^3 + 155*r^2 + 48*r + 1)*s^7 + 2*r^2*(14*r^16 + 168*r^15 +
    894*r^14 + 2760*r^13 + 6285*r^12 + 9716*r^11 + 15490*r^10 +
    11014*r^9 - 6382*r^8 - 40320*r^7 - 65494*r^6 - 63892*r^5 -
    35555*r^4 - 10276*r^3 + 407*r^2 + 102*r + 3)*s^6 + 4*r*(2*r^18 +
    28*r^17 + 169*r^16 + 628*r^15 + 1732*r^14 + 3910*r^13 + 8814*r^12
    + 15058*r^11 + 18321*r^10 + 10590*r^9 - 12771*r^8 - 40361*r^7 -
    55059*r^6 - 43191*r^5 - 20072*r^4 - 3673*r^3 + 180*r^2 + 30*r +
    1)*s^5 + (r^20 + 16*r^19 + 108*r^18 + 464*r^17 + 1558*r^16 +
    5120*r^15 + 17176*r^14 + 45316*r^13 + 91793*r^12 + 144604*r^11 +
    163740*r^10 + 115064*r^9 - 10708*r^8 - 136776*r^7 - 192242*r^6 -
    138652*r^5 - 55384*r^4 - 6664*r^3 + 326*r^2 + 36*r + 1)*s^4 +
    4*(r^18 + 15*r^17 + 150*r^16 + 870*r^15 + 3084*r^14 + 7980*r^13 +
    16993*r^12 + 29650*r^11 + 42284*r^10 + 46222*r^9 + 35261*r^8 +
    10423*r^7 - 13232*r^6 - 23232*r^5 - 16666*r^4 - 5634*r^3 - 422*r^2
    + 18*r + 1)*s^3 + 2*(3*r^16 + 42*r^15 + 579*r^14 + 3568*r^13 +
    12098*r^12 + 27740*r^11 + 47054*r^10 + 61770*r^9 + 62903*r^8 +
    47022*r^7 + 20386*r^6 - 3230*r^5 - 12543*r^4 - 9636*r^3 - 2483*r^2
    - 88*r + 3)*s^2 + 4*(r^14 + 13*r^13 + 237*r^12 + 1411*r^11 +
    4422*r^10 + 8981*r^9 + 12751*r^8 + 13272*r^7 + 9879*r^6 + 4887*r^5
    + 725*r^4 - 789*r^3 - 792*r^2 - 111*r + 1)*s + (r^3 + 3*r^2 + 3*r
    - 1)*(r^9 + 9*r^8 + 252*r^7 + 750*r^6 + 1386*r^5 + 1548*r^4 +
    1272*r^3 + 630*r^2 + 225*r - 1);
  B := r^18*s^18 + 6*r^16*(2*r^3 + 4*r^2 + 7*r + 89)*s^17 +
    3*r^14*(22*r^6 + 88*r^5 + 226*r^4 + 1840*r^3 + 2293*r^2 + 4016*r -
    2491)*s^16 + 2*r^12*(110*r^9 + 660*r^8 + 2235*r^7 + 13678*r^6 +
    30462*r^5 + 65328*r^4 + 26173*r^3 + 33309*r^2 - 33861*r -
    1090)*s^15 + 3*r^10*(165*r^12 + 1320*r^11 + 5550*r^10 + 28640*r^9
    + 82593*r^8 + 202956*r^7 + 226684*r^6 + 297638*r^5 + 66497*r^4 +
    42098*r^3 - 102881*r^2 - 1684*r - 139)*s^14 + 6*r^8*(132*r^15 +
    1320*r^14 + 6630*r^13 + 31455*r^12 + 102431*r^11 + 274244*r^10 +
    449094*r^9 + 707573*r^8 + 587876*r^7 + 485381*r^6 + 24676*r^5 -
    7078*r^4 - 123384*r^3 + 2840*r^2 - 289*r + 5)*s^13 + r^6*(924*r^18
    + 11088*r^17 + 64764*r^16 + 300768*r^15 + 1037454*r^14 +
    2915856*r^13 + 5845913*r^12 + 10578354*r^11 + 12834105*r^10 +
    13456836*r^9 + 7707897*r^8 + 4244874*r^7 - 376834*r^6 - 46824*r^5
    - 812433*r^4 + 101032*r^3 - 1779*r^2 + 204*r + 1)*s^12 +
    6*r^5*(132*r^20 + 1848*r^19 + 12306*r^18 + 58380*r^17 +
    208544*r^16 + 601888*r^15 + 1348954*r^14 + 2660974*r^13 +
    3854128*r^12 + 4539036*r^11 + 3410245*r^10 + 1918616*r^9 +
    199652*r^8 + 76442*r^7 + 77946*r^6 + 317635*r^5 + 35269*r^4 +
    38934*r^3 + 497*r^2 + 101*r + 1)*s^11 + 3*r^4*(165*r^22 +
    2640*r^21 + 19740*r^20 + 98304*r^19 + 364154*r^18 + 1074248*r^17 +
    2550312*r^16 + 5201724*r^15 + 7983310*r^14 + 9162148*r^13 +
    5219636*r^12 - 2743680*r^11 - 12009382*r^10 - 15302440*r^9 -
    11383938*r^8 - 3447242*r^7 + 1620821*r^6 + 2210186*r^5 +
    672899*r^4 + 111594*r^3 + 3419*r^2 + 342*r + 5)*s^10 +
    2*r^3*(110*r^24 + 1980*r^23 + 16425*r^22 + 87285*r^21 +
    339702*r^20 + 1035864*r^19 + 2532056*r^18 + 5058822*r^17 +
    7221618*r^16 + 5657136*r^15 - 5757963*r^14 - 30250968*r^13 -
    65515407*r^12 - 97945482*r^11 - 108769554*r^10 - 89397892*r^9 -
    48970635*r^8 - 12299961*r^7 + 5366737*r^6 + 5694996*r^5 +
    1616232*r^4 + 166359*r^3 + 6564*r^2 + 540*r + 10)*s^9 +
    3*r^2*(22*r^26 + 440*r^25 + 4010*r^24 + 22960*r^23 + 95537*r^22 +
    307648*r^21 + 766803*r^20 + 1409196*r^19 + 1406122*r^18 -
    1260464*r^17 - 10159940*r^16 - 29374336*r^15 - 61866647*r^14 -
    105322628*r^13 - 146968366*r^12 - 168651026*r^11 - 154191669*r^10
    - 108140660*r^9 - 51641742*r^8 - 11260596*r^7 + 4565888*r^6 +
    4145864*r^5 + 1001373*r^4 + 78930*r^3 + 3262*r^2 + 240*r + 5)*s^8
    + 6*r*(2*r^28 + 44*r^27 + 437*r^26 + 2714*r^25 + 12334*r^24 +
    43056*r^23 + 108623*r^22 + 160259*r^21 - 65625*r^20 - 1201196*r^19
    - 4379639*r^18 - 11290606*r^17 - 24114754*r^16 - 44759120*r^15 -
    72394865*r^14 - 102114687*r^13 - 123086639*r^12 - 124396404*r^11 -
    101698038*r^10 - 63920946*r^9 - 27492992*r^8 - 5290882*r^7 +
    2013609*r^6 + 1555204*r^5 + 308144*r^4 + 19902*r^3 + 771*r^2 +
    49*r + 1)*s^7 + (r^30 + 24*r^29 + 258*r^28 + 1760*r^27 + 9135*r^26
    + 35940*r^25 + 86692*r^24 + 25434*r^23 - 763437*r^22 -
    3920802*r^21 - 12929073*r^20 - 34044396*r^19 - 76365812*r^18 -
    149985012*r^17 - 261736758*r^16 - 412949178*r^15 - 587106399*r^14
    - 742623510*r^13 - 815897359*r^12 - 755064612*r^11 -
    566788122*r^10 - 325459428*r^9 - 127234398*r^8 - 21826332*r^7 +
    7684270*r^6 + 4891452*r^5 + 766920*r^4 + 40634*r^3 + 1362*r^2 +
    66*r + 1)*s^6 + 6*(r^28 + 23*r^27 + 148*r^26 + 10*r^25 - 4551*r^24
    - 32458*r^23 - 151133*r^22 - 566079*r^21 - 1765718*r^20 -
    4584485*r^19 - 10007790*r^18 - 18794787*r^17 - 31338120*r^16 -
    47472316*r^15 - 66390507*r^14 - 85866708*r^13 - 100683170*r^12 -
    103825348*r^11 - 90425736*r^10 - 63653743*r^9 - 33968968*r^8 -
    12190843*r^7 - 1894954*r^6 + 579501*r^5 + 292684*r^4 + 34456*r^3 +
    1407*r^2 + 37*r + 1)*s^5 + 3*(5*r^26 + 110*r^25 + 195*r^24 -
    7580*r^23 - 76519*r^22 - 404470*r^21 - 1496267*r^20 - 4335556*r^19
    - 10389347*r^18 - 21049330*r^17 - 36373974*r^16 - 54456024*r^15 -
    72608610*r^14 - 88899958*r^13 - 102557240*r^12 - 110816708*r^11 -
    108187859*r^10 - 90382468*r^9 - 60938013*r^8 - 30799524*r^7 -
    10298802*r^6 - 1461058*r^5 + 361862*r^4 + 136104*r^3 + 10940*r^2 +
    290*r + 5)*s^4 + 2*(10*r^24 + 210*r^23 - 690*r^22 - 28400*r^21 -
    238674*r^20 - 1160421*r^19 - 3930426*r^18 - 10136868*r^17 -
    20967606*r^16 - 35766570*r^15 - 51095355*r^14 - 62406363*r^13 -
    67212028*r^12 - 66763140*r^11 - 63440547*r^10 - 57004909*r^9 -
    45522426*r^8 - 29753568*r^7 - 14435685*r^6 - 4551267*r^5 -
    565284*r^4 + 114039*r^3 + 27429*r^2 + 1185*r + 10)*s^3 + 3*(5*r^22
    + 100*r^21 - 880*r^20 - 19836*r^19 - 153076*r^18 - 702688*r^17 -
    2220932*r^16 - 5230678*r^15 - 9629606*r^14 - 14219750*r^13 -
    17139503*r^12 - 17225754*r^11 - 14945770*r^10 - 11891758*r^9 -
    9136553*r^8 - 6638430*r^7 - 4154867*r^6 - 1933282*r^5 - 576425*r^4
    - 53870*r^3 + 10306*r^2 + 1082*r + 5)*s^2 + 6*(r^20 + 19*r^19 -
    282*r^18 - 4900*r^17 - 35858*r^16 - 156037*r^15 - 460047*r^14 -
    992771*r^13 - 1639351*r^12 - 2118925*r^11 - 2180251*r^10 -
    1814623*r^9 - 1264679*r^8 - 790243*r^7 - 469517*r^6 - 261681*r^5 -
    112474*r^4 - 31382*r^3 - 1239*r^2 + 351*r + 1)*s + (r^6 - 18*r^5 -
    45*r^4 - 68*r^3 - 45*r^2 - 18*r + 1)*(r^12 + 36*r^11 + 306*r^10 +
    1556*r^9 + 4383*r^8 + 7704*r^7 + 9324*r^6 + 7704*r^5 + 4383*r^4 +
    2060*r^3 + 810*r^2 + 540*r + 1);
  end if;
  if k eq 1 then
    delta := r^4 + r^3*s - r^3 + r*s^2 - r*s - s^2 + s;
    D := s^5*(r + s - 1)^4*(r^2 + s - 1)^2*delta^13;
  else
    delta := r^3*s + r^2*s^2 + 2*r^2*s + r*s^2 + r*s + r + s;
    D := -r^6*(r^2 + r*s + r + 1)^3*delta^13;
  end if;
  return A,B,D;
end function;

function ExtraRelationsDirect(zz)
// The polynomials f1,f2,f3,f7,g2,h2,l2,l4,l6 used    
// in Section 6.1.                                     
  z1,z2,z3,z4,z5,z6,z7,z8 := Explode(zz);
  f1 := z4;
  f2 := z4*z5 + z5^2 - z5*z6 - z5*z7;
  f3 := z2^2*z8 + z2*z5*z7 - z3*z4^2 + z3*z4*z5 + 2*z3*z4*z6 +
    4*z3*z4*z8 - 4*z3*z6*z8 + 3*z3*z8^2 + z4^3 + z4^2*z5 - 5*z4^2*z6 +
    3*z4^2*z8 - 2*z4*z5^2 + 2*z4*z5*z6 - 2*z4*z6*z8 - z5*z6*z7 -
    2*z5*z6*z8 - z5*z8^2 - z6^2*z8 - z6*z7*z8 + z6*z8^2 + z7*z8^2;
  g2 := z2*z6 - 2*z2*z7 - 2*z2*z8 - z3*z4 + z3*z5 - 4*z3*z7 - z3*z8 -
    z4^2 + 4*z4*z6 + z5^2 - z5*z7 - 3*z5*z8 + 3*z6*z8 + 3*z7*z8;
  h2 := z1*z2 - 3*z1*z8 + 3*z2*z5 - z2*z7 - z3*z4 - z3*z5 + z3*z7 -
    z3*z8 - z4^2 + 2*z5^2 + z6*z8;
  l2 := 432*z7^2 - 6288*z7*z8 - 4488*z8^2;
  l4 := -396*z7^4 + 37476*z7^3*z8 + 36900*z7^2*z8^2 + 40188*z7*z8^3 -
    552*z8^4;
  l6 := -z1*z2^5 + 6*z2^5*z5 + 510*z2^5*z7 + z2^4*z3*z8 -
    518*z2^4*z5^2 + 2537*z2^4*z5*z7 - 14625*z2^4*z7^2 - 64*z2^3*z3^3 +
    z2^3*z3^2*z8 - 516*z2^3*z3*z8^2 - 2044*z2^3*z5^3 +
    25540*z2^3*z5^2*z7 - 61788*z2^3*z5*z7^2 + 82576*z2^3*z7^3 +
    192*z2^2*z3^4 + 577*z2^2*z3^3*z8 + 3455*z2^2*z3^2*z8^2 -
    10464*z2^2*z5^4 + 67931*z2^2*z5^3*z7 - 163058*z2^2*z5^2*z7^2 +
    306603*z2^2*z5*z7^3 - 277125*z2^2*z7^4 - 192*z2*z3^5 +
    576*z2*z3^4*z6 - 1151*z2*z3^4*z8 - 12830*z2*z3^3*z8^2 -
    25903*z2*z3^2*z8^3 - 552*z2*z3*z8^4 - 16841*z2*z5^5 +
    51950*z2*z5^4*z7 - 118734*z2*z5^3*z7^2 + 443500*z2*z5^2*z7^3 -
    874789*z2*z5*z7^4 + 576330*z2*z7^5 + 64*z3^6 + z3^5*z4 -
    576*z3^5*z6 + 1536*z3^5*z7 + z3^5*z8 - 7*z3^4*z4^2 -
    2046*z3^4*z4*z6 + 37*z3^4*z4*z8 - 4224*z3^4*z6*z7 -
    2045*z3^4*z6*z8 + 4533*z3^4*z8^2 + 8*z3^3*z4^3 + 2622*z3^3*z4^2*z6
    + 4224*z3^3*z4*z6^2 - 2758*z3^3*z4*z6*z8 + 41608*z3^3*z4*z8^2 -
    24768*z3^3*z6^2*z7 + 2640*z3^3*z6^2*z8 - 34300*z3^3*z6*z8^2 +
    41669*z3^3*z8^3 + 496*z3^2*z4^4 - 7276*z3^2*z4^3*z6 +
    10401*z3^2*z4^2*z6^2 + 24768*z3^2*z4*z6^3 + 157991*z3^2*z4*z6^2*z8
    + 17044*z3^2*z4*z6*z8^2 + 61740*z3^2*z4*z8^3 - 2268*z3^2*z6^3*z7 -
    89425*z3^2*z6^3*z8 + 16901*z3^2*z6^2*z8^2 - 46053*z3^2*z6*z8^3 +
    81510*z3^2*z8^4 - 943*z3*z4^5 + 12032*z3*z4^4*z5 +
    18597*z3*z4^4*z6 - 31188*z3*z4^3*z5^2 - 18162*z3*z4^3*z6^2 +
    59607*z3*z4^2*z5^3 - 24768*z3*z4^2*z6^3 - 60292*z3*z4*z5^4 +
    2268*z3*z4*z6^4 - 501841*z3*z4*z6^3*z8 - 142105*z3*z4*z6^2*z8^2 -
    168844*z3*z4*z6*z8^3 - 149922*z3*z4*z8^4 + 16218*z3*z5^5 +
    78944*z3*z6^4*z7 + 284879*z3*z6^4*z8 - 40736*z3*z6^3*z7^2 +
    126804*z3*z6^3*z8^2 - 364028*z3*z6^2*z7^3 + 187758*z3*z6^2*z8^3 +
    531692*z3*z6*z7^4 + 100350*z3*z6*z8^4 + 741092*z3*z7^5 +
    1656*z3*z8^5 - 7695*z4^6 + 28160*z4^5*z5 - 73868*z4^5*z6 -
    12942*z4^5*z8 - 71838*z4^4*z5^2 + 221123*z4^4*z5*z6 +
    114895*z4^4*z5*z8 + 112675*z4^4*z6^2 + 21216*z4^4*z8^2 +
    78487*z4^3*z5^3 - 478616*z4^3*z5^2*z6 - 243189*z4^3*z5^2*z8 -
    447607*z4^3*z5*z6^2 - 18006*z4^3*z5*z8^2 - 121825*z4^3*z6^3 -
    126398*z4^3*z8^3 - 41866*z4^2*z5^4 + 786071*z4^2*z5^3*z6 +
    583712*z4^2*z5^3*z8 + 1194569*z4^2*z5^2*z6^2 -
    161869*z4^2*z5^2*z8^2 + 143137*z4^2*z5*z6^3 + 70814*z4^2*z5*z8^3 -
    1884*z4^2*z6^4 - 10416*z4^2*z8^4 + 22649*z4*z5^5 -
    1010969*z4*z5^4*z6 - 606439*z4*z5^4*z8 - 2497579*z4*z5^3*z6^2 +
    324621*z4*z5^3*z8^2 - 328867*z4*z5^2*z6^3 + 166709*z4*z5^2*z8^3 +
    285767*z4*z5*z6^4 + 45310*z4*z5*z8^4 - 78752*z4*z6^5 -
    198378*z4*z6^4*z8 - 359023*z4*z6^3*z8^2 + 543166*z4*z6^2*z8^3 -
    790*z4*z6*z8^4 + 516*z4*z8^5 - 12936*z5^6 + 709390*z5^5*z6 -
    170146*z5^5*z7 + 191478*z5^5*z8 + 3887646*z5^4*z6^2 -
    4742781*z5^4*z6*z7 + 2498316*z5^4*z6*z8 + 789840*z5^4*z7^2 +
    844428*z5^4*z7*z8 - 1846207*z5^4*z8^2 + 935720*z5^3*z6^3 -
    3136291*z5^3*z6^2*z7 + 6349844*z5^3*z6*z7^2 -
    9568655*z5^3*z6*z7*z8 + 2629021*z5^3*z6*z8^2 - 1080599*z5^3*z7^3 -
    1510665*z5^3*z7^2*z8 + 6196725*z5^3*z7*z8^2 - 669830*z5^3*z8^3 -
    56596*z5^2*z6^4 - 41576*z5^2*z6^3*z7 - 286966*z5^2*z6^2*z7^2 -
    218485*z5^2*z6*z7^3 + 13300156*z5^2*z6*z7^2*z8 -
    13109565*z5^2*z6*z7*z8^2 + 1852372*z5^2*z6*z8^3 - 15129*z5^2*z7^4
    - 3447392*z5^2*z7^3*z8 - 2501513*z5^2*z7^2*z8^2 +
    1406338*z5^2*z7*z8^3 - 462115*z5^2*z8^4 + 118336*z5*z6^5 +
    676363*z5*z6^4*z7 + 381182*z5*z6^4*z8 - 1242796*z5*z6^3*z7^2 +
    703496*z5*z6^3*z7*z8 - 429767*z5*z6^3*z8^2 - 2005447*z5*z6^2*z7^3
    - 702552*z5*z6^2*z7^2*z8 + 5956363*z5*z6^2*z7*z8^2 -
    1110660*z5*z6^2*z8^3 + 1733196*z5*z6*z7^4 - 4621349*z5*z6*z7^3*z8
    + 9058246*z5*z6*z7^2*z8^2 - 3734899*z5*z6*z7*z8^3 +
    406535*z5*z6*z8^4 + 473693*z5*z7^5 + 4027788*z5*z7^4*z8 -
    5217448*z5*z7^3*z8^2 - 409495*z5*z7^2*z8^3 + 865340*z5*z7*z8^4 +
    612*z5*z8^5 + 64*z6^6 - 192*z6^5*z7 + 429039*z6^5*z8 -
    48*z6^4*z7^2 - 107109*z6^4*z7*z8 + 31873*z6^4*z8^2 + 224*z6^3*z7^3
    - 1826129*z6^3*z7^2*z8 + 428729*z6^3*z7*z8^2 - 570594*z6^3*z8^3 +
    60*z6^2*z7^4 - 119069*z6^2*z7^3*z8 - 3755808*z6^2*z7^2*z8^2 +
    1197668*z6^2*z7*z8^3 - 53135*z6^2*z8^4 - 12*z6*z7^5 +
    1058333*z6*z7^4*z8 - 272565*z6*z7^3*z8^2 + 1346637*z6*z7^2*z8^3 -
    363453*z6*z7*z8^4 - 1650*z6*z8^5 + z7^6 - 103153*z7^5*z8 +
    3330022*z7^4*z8^2 - 357997*z7^3*z8^3 - 438931*z7^2*z8^4 -
    72*z7*z8^5 + z8^6;
  f7 := 2*z2^4*z5^2*z7 - 2*z2^4*z5*z7^2 - 2*z2^3*z5^4 +
    19*z2^3*z5^3*z7 + 12*z2^3*z5^2*z7^2 - 29*z2^3*z5*z7^3 -
    2*z2^3*z8^4 - 48*z2^2*z3*z8^4 - 15*z2^2*z5^5 - 12*z2^2*z5^4*z7 +
    223*z2^2*z5^3*z7^2 - 114*z2^2*z5^2*z7^3 - 82*z2^2*z5*z7^4 -
    2*z2^2*z8^5 - 270*z2*z3^2*z8^4 - 37*z2*z3*z8^5 + 7*z2*z5^6 -
    394*z2*z5^5*z7 + 593*z2*z5^4*z7^2 + 296*z2*z5^3*z7^3 -
    834*z2*z5^2*z7^4 + 332*z2*z5*z7^5 - z3^4*z4^3 + z3^4*z4^2*z6 +
    z3^4*z4*z8^2 - z3^4*z6*z8^2 + 16*z3^3*z4^4 - 43*z3^3*z4^3*z6 +
    27*z3^3*z4^2*z6^2 - 738*z3^3*z4*z6^2*z8 - 128*z3^3*z4*z6*z8^2 -
    122*z3^3*z4*z8^3 + 720*z3^3*z6^3*z8 + 99*z3^3*z6^2*z8^2 +
    113*z3^3*z6*z8^3 - 140*z3^3*z8^4 - 79*z3^2*z4^5 + 349*z3^2*z4^4*z6
    - 450*z3^2*z4^3*z6^2 + 162*z3^2*z4^2*z6^3 - 76*z3^2*z4*z6^3*z8 +
    1046*z3^2*z4*z6^2*z8^2 - 1273*z3^2*z4*z6*z8^3 - 40*z3^2*z4*z8^4 +
    772*z3^2*z6^4*z8 - 1460*z3^2*z6^3*z8^2 + 404*z3^2*z6^2*z8^3 -
    1474*z3^2*z6*z8^4 - 312*z3^2*z8^5 + 83*z3*z4^6 + 75*z3*z4^5*z5 -
    684*z3*z4^5*z6 - 420*z3*z4^4*z5^2 + 1378*z3*z4^4*z6^2 -
    291*z3*z4^3*z5^3 - 15*z3*z4^3*z6^3 - 199*z3*z4^2*z5^4 -
    18*z3*z4^2*z6^4 + 228*z3*z4*z5^5 + 4613*z3*z4*z6^4*z8 +
    4219*z3*z4*z6^3*z8^2 + 2600*z3*z4*z6^2*z8^3 + 2861*z3*z4*z6*z8^4 +
    1022*z3*z4*z8^5 + 146*z3*z5^6 - 4461*z3*z6^5*z8 -
    6499*z3*z6^4*z8^2 - 4002*z3*z6^3*z8^3 - 2640*z3*z6^2*z8^4 -
    905*z3*z6*z8^5 + 13*z3*z8^6 + 179*z4^7 + 75*z4^6*z5 - 711*z4^6*z6
    - 293*z4^6*z8 - 225*z4^5*z5^2 + 1869*z4^5*z5*z6 - 334*z4^5*z5*z8 +
    469*z4^5*z6^2 + 425*z4^5*z8^2 - 586*z4^4*z5^3 - 65*z4^4*z5^2*z6 -
    1984*z4^4*z5^2*z8 - 2613*z4^4*z5*z6^2 + 1928*z4^4*z5*z8^2 -
    2113*z4^4*z6^3 - 697*z4^4*z8^3 + 179*z4^3*z5^4 + 3157*z4^3*z5^3*z6
    + 254*z4^3*z5^3*z8 + 3917*z4^3*z5^2*z6^2 + 3520*z4^3*z5^2*z8^2 +
    4906*z4^3*z5*z6^3 - 4207*z4^3*z5*z8^3 + 2040*z4^3*z6^4 +
    1009*z4^3*z8^4 + 601*z4^2*z5^5 - 1659*z4^2*z5^4*z6 -
    580*z4^2*z5^4*z8 - 3649*z4^2*z5^3*z6^2 + 4678*z4^2*z5^3*z8^2 -
    9412*z4^2*z5^2*z6^3 - 10682*z4^2*z5^2*z8^3 - 5657*z4^2*z5*z6^4 +
    8336*z4^2*z5*z8^4 - 163*z4^2*z6^5 + 13*z4^2*z8^5 - 243*z4*z5^6 +
    57*z4*z5^5*z6 + 488*z4*z5^5*z8 + 5415*z4*z5^4*z6^2 -
    4128*z4*z5^4*z8^2 + 12385*z4*z5^3*z6^3 - 6836*z4*z5^3*z8^3 +
    8081*z4*z5^2*z6^4 + 25754*z4*z5^2*z8^4 - 4027*z4*z5*z6^5 -
    10251*z4*z5*z8^5 + 160*z4*z6^5*z8 - 498*z4*z6^4*z8^2 +
    9646*z4*z6^3*z8^3 + 7252*z4*z6^2*z8^4 + 10238*z4*z6*z8^5 + 20*z5^7
    - 41*z5^6*z6 - 717*z5^6*z7 + 559*z5^6*z8 - 6046*z5^5*z6^2 +
    665*z5^5*z6*z7 - 347*z5^5*z6*z8 - 151*z5^5*z7^2 + 3841*z5^5*z7*z8
    - 4144*z5^5*z8^2 + 2154*z5^4*z6^3 - 13742*z5^4*z6^2*z7 -
    7054*z5^4*z6*z7^2 + 10108*z5^4*z6*z7*z8 + 12175*z5^4*z6*z8^2 +
    3797*z5^4*z7^3 - 7193*z5^4*z7^2*z8 + 4235*z5^4*z7*z8^2 +
    3632*z5^4*z8^3 - 10557*z5^3*z6^4 + 17359*z5^3*z6^3*z7 -
    1911*z5^3*z6^2*z7^2 - 63994*z5^3*z6*z7^3 + 47405*z5^3*z6*z7^2*z8 +
    23007*z5^3*z6*z7*z8^2 - 31007*z5^3*z6*z8^3 - 4484*z5^3*z7^4 +
    69008*z5^3*z7^3*z8 - 100349*z5^3*z7^2*z8^2 + 11451*z5^3*z7*z8^3 +
    19575*z5^3*z8^4 + 720*z5^2*z6^5 - 1407*z5^2*z6^4*z7 +
    4631*z5^2*z6^3*z7^2 + 19384*z5^2*z6^2*z7^3 - 82729*z5^2*z6*z7^4 -
    102926*z5^2*z6*z7^3*z8 + 199146*z5^2*z6*z7^2*z8^2 -
    31404*z5^2*z6*z7*z8^3 - 66980*z5^2*z6*z8^4 + 860*z5^2*z7^5 +
    22440*z5^2*z7^4*z8 + 63428*z5^2*z7^3*z8^2 - 90073*z5^2*z7^2*z8^3 +
    59197*z5^2*z7*z8^4 - 51633*z5^2*z8^5 - 9*z5*z6^6 - 7570*z5*z6^5*z7
    - 1890*z5*z6^5*z8 + 5283*z5*z6^4*z7^2 - 9060*z5*z6^4*z7*z8 -
    126*z5*z6^4*z8^2 + 9749*z5*z6^3*z7^3 + 18966*z5*z6^3*z7^2*z8 -
    30008*z5*z6^3*z7*z8^2 + 15446*z5*z6^3*z8^3 - 3596*z5*z6^2*z7^4 -
    42371*z5*z6^2*z7^3*z8 - 67779*z5*z6^2*z7^2*z8^2 +
    42946*z5*z6^2*z7*z8^3 - 4401*z5*z6^2*z8^4 - 3182*z5*z6*z7^5 -
    56922*z5*z6*z7^4*z8 - 45789*z5*z6*z7^3*z8^2 +
    94485*z5*z6*z7^2*z8^3 - 50915*z5*z6*z7*z8^4 + 72058*z5*z6*z8^5 +
    675*z5*z7^6 - 89330*z5*z7^5*z8 + 125972*z5*z7^4*z8^2 +
    65090*z5*z7^3*z8^3 - 125437*z5*z7^2*z8^4 + 103281*z5*z7*z8^5 -
    7576*z6^6*z8 - 2346*z6^5*z7*z8 - 1966*z6^5*z8^2 +
    15078*z6^4*z7^2*z8 - 2767*z6^4*z7*z8^2 - 8762*z6^4*z8^3 +
    6186*z6^3*z7^3*z8 + 14546*z6^3*z7^2*z8^2 - 11143*z6^3*z7*z8^3 -
    8169*z6^3*z8^4 - 6825*z6^2*z7^4*z8 + 38274*z6^2*z7^3*z8^2 -
    23061*z6^2*z7^2*z8^3 - 14387*z6^2*z7*z8^4 - 10187*z6^2*z8^5 -
    2490*z6*z7^5*z8 - 66215*z6*z7^4*z8^2 - 10778*z6*z7^3*z8^3 +
    40447*z6*z7^2*z8^4 - 61835*z6*z7*z8^5 + 673*z7^6*z8 -
    89142*z7^5*z8^2 + 9902*z7^4*z8^3 + 46665*z7^3*z8^4 -
    51648*z7^2*z8^5;
  return f1,f2,f3,f7,g2,h2,l2,l4,l6;
end function;

function ExtraRelationsSkew(zz)
// The polynomials f5,f8,f10,g10,f11,f12,f13,f15,f18,f20,f23 
// used in Section 6.2      
  t1,t2,t3,u1,u2,u3,u4,u5 := Explode(zz);
  f5 := -149*t1*u1 + 84*t1*u4 + 149*t2*u1 + 312*t2*u2 - 163*t2*u3 -
    84*t2*u4 + 65*t2*u5 - 84*t3*u5;
  f8 := -1667*t1*u1^2 - 7596*t1*u1*u3 + 18082*t1*u1*u4 + 9463*t1*u1*u5
    + 188*t1*u2*u3 + 188*t1*u2*u5 - 6059*t1*u3^2 - 6059*t1*u3*u5 +
    8101*t1*u4^2 + 8372*t1*u4*u5 + 1170*t2^3*t3 - 1609*t2^2*t3^2 +
    10543*t2*t3^3 + 1460*t2*u1^2 - 937*t2*u1*u2 + 4218*t2*u1*u3 +
    11849*t2*u1*u4 + 15842*t2*u1*u5 + 4475*t2*u2*u3 + 7206*t2*u2*u4 +
    1407*t2*u2*u5 - 3825*t2*u3^2 + 11454*t2*u3*u5 + 62*t2*u4^2 -
    10729*t2*u4*u5 - 18778*t2*u5^2 - 4504*t3^4 + 22249*t3*u2*u4 +
    22433*t3*u2*u5 - 17745*t3*u4^2 - 30530*t3*u4*u5 - 8556*t3*u5^2;
  f10 := 200*t1^2*u1^2 - 198*t1^2*u1*u4 + 1045*t1^2*u1*u5 +
    89*t1^2*u2*u3 + 7*t1^2*u2*u5 + 358*t1^2*u3^2 + 192*t1^2*u3*u5 -
    51*t1^2*u4^2 + 940*t1^2*u4*u5 - 88*t1^2*u5^2 - 423*t1*t2*u1^2 +
    99*t1*t2*u1*u3 + 253*t1*t2*u1*u4 - 621*t1*t2*u1*u5 -
    503*t1*t2*u2*u3 - 671*t1*t2*u2*u5 - 75*t1*t2*u3^2 -
    164*t1*t2*u3*u5 + 1321*t1*t2*u4^2 + 2087*t1*t2*u4*u5 -
    388*t1*t2*u5^2 - 1270*t1*t3*u2*u5 + 196*t1*t3*u4^2 +
    1090*t1*t3*u4*u5 - 775*t1*t3*u5^2 - 89*t2^4*t3 - 17*t2^3*t3^2 +
    266*t2^2*t3^3 + 243*t2^2*u1^2 + 151*t2^2*u1*u2 - 100*t2^2*u1*u3 -
    625*t2^2*u1*u4 - 170*t2^2*u1*u5 + 5*t2^2*u2*u3 - 916*t2^2*u2*u4 -
    992*t2^2*u2*u5 + 221*t2^2*u3^2 + 636*t2^2*u3*u5 - 527*t2^2*u4^2 -
    1465*t2^2*u4*u5 + 1465*t2^2*u5^2 + 121*t2*t3^4 - 2306*t2*t3*u2*u5
    - 841*t2*t3*u4^2 + 1396*t2*t3*u4*u5 + 253*t2*t3*u5^2 + 94*t3^5 +
    639*t3^2*u2*u5 - 322*t3^2*u4^2 - 383*t3^2*u4*u5 - 77*t3^2*u5^2;
  g10 := 4*t1^2*u1*u5 - 4*t1^2*u4^2 + 4*t1^2*u4*u5 - 4*t1*t2*u1*u5 -
    4*t1*t2*u2*u5 - 4*t1*t2*u5^2 - 4*t1*t3*u2*u5 + 4*t1*t3*u4*u5 -
    4*t1*t3*u5^2 - 4*t2^2*u4*u5 - 4*t2*t3*u2*u5 - 4*t3^2*u2*u5;
  f11 := 3*t1*t2^3*u2 - t1*t2^3*u4 - t1*t2^3*u5 + 2*t1*u1^2*u3 -
    3*t1*u1^2*u5 + 2*t1*u1*u2*u5 + 2*t1*u1*u3^2 - 2*t1*u2*u3^2 +
    t1*u2*u3*u5 - t1*u3^2*u4 - t1*u3^2*u5 + 3*t2*u1*u5^2 +
    3*t2*u2*u3^2 + t2*u2*u4^2 - t2*u2*u4*u5 - 3*t2*u2*u5^2 -
    2*t3*u1^2*u2;
  f12 := -t1^4*t3^2 + t1^3*u2*u5 - 2*t1^2*t2^3*t3 + t1^2*t2*u4^2 -
    t1^2*t3^4 + 6*t1^2*t3*u2*u4 - 2*t1^2*t3*u4^2 - t1*t2^5 +
    2*t1*t2^4*t3 - t2^5*t3 + 2*t2^4*t3^2 - t2^3*t3^3 + t2^3*u2^2 -
    2*t2^3*u2*u3 - 5*t2^3*u2*u5 - 2*t2^3*u3*u5 - t2^3*u4*u5 -
    5*t2^3*u5^2 - t3^3*u2*u5 - t3^3*u3^2 + t3^3*u4^2 - u1^3*u5 -
    2*u1^2*u2*u5 - 2*u1^2*u4*u5 + u1*u2^2*u4 - 7*u1*u2*u4*u5 +
    8*u1*u3*u5^2 + 8*u1*u4^2*u5 - 5*u2^2*u3*u5 + u2^2*u4*u5 -
    3*u2^2*u5^2 + 4*u2*u3^2*u4 - 3*u2*u3^2*u5 - 5*u2*u3*u5^2 - u2*u4^3
    - u2*u5^3 - 2*u3^2*u5^2 - u3*u5^3 + u4*u5^3;
  f13 := 6247*t1^5*u2 - 18177*t1^5*u3 - 188*t1^5*u5 - 30776*t1^2*u1^3
    + 15978*t1^2*u1^2*u4 - 78450*t1^2*u1^2*u5 + 40042*t1^2*u1*u4^2 +
    15435*t1^2*u1*u4*u5 - 40996*t1^2*u1*u5^2 - 10451*t1^2*u2*u3^2 +
    11619*t1^2*u2*u3*u5 + 10257*t1^2*u2*u5^2 + 89901*t1^2*u3^3 +
    149539*t1^2*u3^2*u5 + 85868*t1^2*u3*u5^2 + 27404*t1^2*u4^3 +
    32835*t1^2*u4^2*u5 - 52775*t1^2*u4*u5^2 - 30953*t1^2*u5^3 +
    22693*t1*t2*u1^3 - 48268*t1*t2*u1^2*u4 + 22176*t1*t2*u1^2*u5 -
    4169*t1*t2*u1*u3^2 - 75859*t1*t2*u1*u3*u5 - 98685*t1*t2*u1*u4^2 -
    57199*t1*t2*u1*u4*u5 - 76959*t1*t2*u1*u5^2 + 55948*t1*t2*u2*u3^2 +
    27231*t1*t2*u2*u3*u5 + 36573*t1*t2*u2*u5^2 - 59640*t1*t2*u3^3 +
    33972*t1*t2*u3^2*u5 + 115973*t1*t2*u3*u5^2 - 22661*t1*t2*u4^3 -
    93518*t1*t2*u4^2*u5 - 44546*t1*t2*u4*u5^2 + 105340*t1*t2*u5^3 -
    11057*t1*t3*u2*u5^2 + 20367*t1*t3*u4^3 - 46249*t1*t3*u4^2*u5 -
    15374*t1*t3*u4*u5^2 + 40430*t1*t3*u5^3 - 18780*t2^5*u1 -
    3977*t2^5*u2 - 17147*t2^5*u3 - 20556*t2^5*u4 - 21732*t2^5*u5 -
    13203*t2^4*t3*u5 + 2010*t2^3*t3^2*u5 - 41331*t2^2*t3^3*u5 -
    2989*t2^2*u1^3 + 46810*t2^2*u1^2*u2 - 28738*t2^2*u1^2*u3 +
    6437*t2^2*u1^2*u4 - 4133*t2^2*u1^2*u5 + 45673*t2^2*u1*u2*u3 +
    109103*t2^2*u1*u2*u4 + 121438*t2^2*u1*u2*u5 - 36865*t2^2*u1*u3^2 -
    13004*t2^2*u1*u3*u5 - 59841*t2^2*u1*u4^2 - 13118*t2^2*u1*u4*u5 -
    90237*t2^2*u1*u5^2 + 10210*t2^2*u2*u3^2 + 83412*t2^2*u2*u3*u5 +
    118164*t2^2*u2*u4*u5 + 35465*t2^2*u2*u5^2 - 19083*t2^2*u3^3 -
    81044*t2^2*u3^2*u5 - 70534*t2^2*u3*u5^2 + 56719*t2^2*u4^3 -
    6126*t2^2*u4^2*u5 - 128242*t2^2*u4*u5^2 - 47417*t2^2*u5^3 +
    2026*t2*t3^4*u4 - 41923*t2*t3^4*u5 + 32317*t2*t3*u2*u5^2 +
    30272*t2*t3*u4^3 - 64678*t2*t3*u4^2*u5 - 40016*t2*t3*u4*u5^2 +
    17382*t2*t3*u5^3 - 16700*t3^5*u4 + 9390*t3^5*u5 +
    3357*t3^2*u2*u5^2 - 5615*t3^2*u4^3 - 26637*t3^2*u4^2*u5 +
    30273*t3^2*u4*u5^2 + 29308*t3^2*u5^3;
  f15 := -438*t1^6*u2 + 1068*t1^6*u3 + 57*t1^6*u5 - 644*t1^3*u2*u3^2 +
    1088*t1^3*u2*u3*u5 + 263*t1^3*u2*u5^2 + 8*t1^3*u3^3 -
    297*t1^3*u3^2*u5 + 701*t1^3*u3*u5^2 + t1^3*u5^3 + 806*t1^2*t3*u4^3
    - 152*t1^2*t3*u4^2*u5 - 780*t1^2*t3*u4*u5^2 - 947*t1^2*t3*u5^3 -
    11*t2^6*u1 + 237*t2^6*u2 - 64*t2^6*u3 - 256*t2^6*u4 + 116*t2^6*u5
    - 302*t2^5*t3*u5 + 78*t2^4*t3^2*u5 - 1004*t2^3*t3^3*u5 +
    85*t2^3*u1^3 + 291*t2^3*u1^2*u4 - 153*t2^3*u1^2*u5 +
    196*t2^3*u1*u3^2 - 493*t2^3*u1*u3*u5 + 1419*t2^3*u1*u4^2 -
    638*t2^3*u1*u4*u5 - 22*t2^3*u1*u5^2 + 407*t2^3*u2*u3^2 +
    316*t2^3*u2*u3*u5 - 37*t2^3*u2*u5^2 + 76*t2^3*u3^3 +
    295*t2^3*u3^2*u5 - 1366*t2^3*u3*u5^2 + 3636*t2^3*u4^3 +
    174*t2^3*u4^2*u5 - 1293*t2^3*u4*u5^2 - 2531*t2^3*u5^3 -
    2240*t2^2*t3^4*u5 - 3089*t2^2*t3*u5^3 - 436*t2*t3^5*u4 -
    1057*t2*t3^5*u5 + 1568*t2*t3^2*u4^3 - 2231*t2*t3^2*u4^2*u5 -
    1194*t2*t3^2*u4*u5^2 - 1302*t2*t3^2*u5^3 - 26*t3^6*u4 -
    396*t3^6*u5 - 138*t3^3*u4^3 - 526*t3^3*u4^2*u5 + 704*t3^3*u4*u5^2
    + 723*t3^3*u5^3 - 12*u1^5 - 142*u1^4*u2 + 226*u1^4*u3 -
    550*u1^4*u4 + 646*u1^4*u5 - 29*u1^3*u2*u3 + 251*u1^3*u2*u4 -
    1419*u1^3*u2*u5 + 20*u1^3*u3^2 + 452*u1^3*u3*u5 - 1413*u1^3*u4^2 +
    5737*u1^3*u4*u5 - 1012*u1^3*u5^2 - 36*u1^2*u2*u3^2 +
    371*u1^2*u2*u3*u5 - 1037*u1^2*u2*u4^2 + 818*u1^2*u2*u4*u5 +
    497*u1^2*u2*u5^2 + 80*u1^2*u3^3 - 290*u1^2*u3^2*u5 -
    2614*u1^2*u3*u5^2 - 202*u1^2*u4^3 + 4792*u1^2*u4^2*u5 -
    3542*u1^2*u4*u5^2 - 3713*u1^2*u5^3 + 583*u1*u2*u3^3 -
    469*u1*u2*u3^2*u5 + 1112*u1*u2*u3*u5^2 - 5366*u1*u2*u4^3 -
    851*u1*u2*u4^2*u5 + 2302*u1*u2*u4*u5^2 + 2556*u1*u2*u5^3 -
    103*u1*u3^4 - 87*u1*u3^3*u5 - 1065*u1*u3^2*u5^2 - 3261*u1*u3*u5^3
    + 696*u1*u4^4 + 1865*u1*u4^3*u5 - 2112*u1*u4^2*u5^2 -
    2582*u1*u4*u5^3 - 1333*u1*u5^4 - 547*u2^2*u3*u5^2 + 4343*u2^2*u4^3
    - 936*u2^2*u4^2*u5 - 1027*u2^2*u4*u5^2 + 518*u2^2*u5^3 +
    76*u2*u3^4 - 31*u2*u3^3*u5 + 1363*u2*u3^2*u5^2 + 2263*u2*u3*u5^3 -
    3249*u2*u4^4 - 1474*u2*u4^3*u5 + 1478*u2*u4^2*u5^2 +
    2902*u2*u4*u5^3 - 74*u2*u5^4 + 79*u3^5 + 122*u3^4*u5 -
    301*u3^3*u5^2 + 210*u3^2*u5^3 + 999*u3*u5^4 + 191*u4^5 - 5*u4^4*u5
    - 690*u4^3*u5^2 - 1424*u4^2*u5^3 - 673*u4*u5^4 + 969*u5^5;
  f18 := -100464*t1^6*u2*u3 - 16717*t1^6*u2*u5 + 231129*t1^6*u3^2 +
    156230*t1^6*u3*u5 - 13072*t1^6*u5^2 - 48188*t1^3*u2*u3^3 +
    20844*t1^3*u2*u3^2*u5 + 255015*t1^3*u2*u3*u5^2 +
    37320*t1^3*u2*u5^3 + 8654*t1^3*u3^4 - 122689*t1^3*u3^3*u5 -
    148186*t1^3*u3^2*u5^2 - 68899*t1^3*u3*u5^3 - 1609*t1^3*u5^4 -
    5120*t1^2*t3*u4^4 + 17165*t1^2*t3*u4^3*u5 +
    81319*t1^2*t3*u4^2*u5^2 - 96409*t1^2*t3*u4*u5^3 +
    48851*t1^2*t3*u5^4 - 4*t2^9 - 275*t2^8*t3 + 769*t2^7*t3^2 -
    4191*t2^6*t3^3 + 10455*t2^6*u1^2 + 7739*t2^6*u1*u3 +
    505*t2^6*u1*u4 + 10695*t2^6*u1*u5 - 1293*t2^6*u2*u3 +
    20063*t2^6*u2*u5 - 2686*t2^6*u3^2 + 7899*t2^6*u3*u5 -
    25195*t2^6*u4*u5 + 23757*t2^6*u5^2 - 5402*t2^5*t3^4 +
    12954*t2^5*t3*u5^2 - 1654*t2^4*t3^5 + 79221*t2^4*t3^2*u5^2 +
    6817*t2^3*t3^6 + 45140*t2^3*t3^3*u5^2 + 8576*t2^3*u1^4 -
    3828*t2^3*u1^3*u4 + 79465*t2^3*u1^3*u5 - 37699*t2^3*u1^2*u4^2 +
    13491*t2^3*u1^2*u4*u5 + 35533*t2^3*u1^2*u5^2 -
    50140*t2^3*u1*u3^2*u5 - 24050*t2^3*u1*u3*u5^2 -
    150799*t2^3*u1*u4^3 - 53876*t2^3*u1*u4^2*u5 +
    37432*t2^3*u1*u4*u5^2 + 125225*t2^3*u1*u5^3 - 19806*t2^3*u2*u3^3 -
    9333*t2^3*u2*u3^2*u5 - 12360*t2^3*u2*u3*u5^2 - 20503*t2^3*u2*u5^3
    - 4346*t2^3*u3^4 - 1148*t2^3*u3^3*u5 + 4632*t2^3*u3^2*u5^2 +
    69983*t2^3*u3*u5^3 - 217348*t2^3*u4^4 + 33805*t2^3*u4^3*u5 +
    132265*t2^3*u4^2*u5^2 + 164769*t2^3*u4*u5^3 + 23428*t2^3*u5^4 +
    5080*t2^2*t3^7 - 29850*t2^2*t3^4*u5^2 - 84193*t2^2*t3*u5^4 +
    10541*t2*t3^8 + 60532*t2*t3^5*u4^2 - 35974*t2*t3^5*u4*u5 +
    32442*t2*t3^5*u5^2 + 40684*t2*t3^2*u4^4 + 36120*t2*t3^2*u4^3*u5 -
    32018*t2*t3^2*u4^2*u5^2 - 37609*t2*t3^2*u4*u5^3 -
    84392*t2*t3^2*u5^4 + 5019*t3^9 + 80253*t3^6*u4^2 + 540*t3^6*u4*u5
    + 2101*t3^6*u5^2 + 118271*t3^3*u4^4 - 23584*t3^3*u4^3*u5 -
    52366*t3^3*u4^2*u5^2 - 53611*t3^3*u4*u5^3 - 32*t3^3*u5^4 -
    6559*u1^6 + 5345*u1^5*u2 - 15300*u1^5*u3 - 43201*u1^5*u4 -
    98231*u1^5*u5 - 22717*u1^4*u2*u3 + 34612*u1^4*u2*u4 -
    113464*u1^4*u2*u5 + 92124*u1^4*u3^2 + 96108*u1^4*u3*u5 -
    220629*u1^4*u4^2 - 308370*u1^4*u4*u5 - 26055*u1^4*u5^2 -
    64552*u1^3*u2*u3^2 - 145620*u1^3*u2*u3*u5 - 45154*u1^3*u2*u4^2 -
    415840*u1^3*u2*u4*u5 - 274596*u1^3*u2*u5^2 + 119204*u1^3*u3^3 +
    128391*u1^3*u3^2*u5 + 93910*u1^3*u3*u5^2 - 314560*u1^3*u4^3 -
    395058*u1^3*u4^2*u5 - 59648*u1^3*u4*u5^2 + 88538*u1^3*u5^3 -
    3162*u1^2*u2*u3^3 - 113499*u1^2*u2*u3^2*u5 -
    132409*u1^2*u2*u3*u5^2 - 127587*u1^2*u2*u4^3 -
    453378*u1^2*u2*u4^2*u5 - 207773*u1^2*u2*u4*u5^2 -
    89664*u1^2*u2*u5^3 + 12401*u1^2*u3^4 + 30523*u1^2*u3^3*u5 +
    96893*u1^2*u3^2*u5^2 + 124824*u1^2*u3*u5^3 - 176127*u1^2*u4^4 -
    194481*u1^2*u4^3*u5 + 5817*u1^2*u4^2*u5^2 + 94692*u1^2*u4*u5^3 +
    77011*u1^2*u5^4 + 15077*u1*u2*u3^4 - 20800*u1*u2*u3^3*u5 -
    78616*u1*u2*u3^2*u5^2 - 129337*u1*u2*u3*u5^3 - 354233*u1*u2*u4^4 -
    145308*u1*u2*u4^3*u5 - 73784*u1*u2*u4^2*u5^2 - 69033*u1*u2*u4*u5^3
    - 85088*u1*u2*u5^4 - 20940*u1*u3^5 - 32123*u1*u3^4*u5 +
    51090*u1*u3^3*u5^2 + 56935*u1*u3^2*u5^3 + 61614*u1*u3*u5^4 +
    46693*u1*u4^5 + 30242*u1*u4^4*u5 - 6038*u1*u4^3*u5^2 +
    33313*u1*u4^2*u5^3 + 51013*u1*u4*u5^4 + 70198*u1*u5^5 -
    55390*u2^2*u3*u5^3 - 209990*u2^2*u4^4 + 3112*u2^2*u4^3*u5 +
    85487*u2^2*u4^2*u5^2 + 43602*u2^2*u4*u5^3 + 22069*u2^2*u5^4 -
    3311*u2*u3^5 - 6304*u2*u3^4*u5 - 4041*u2*u3^3*u5^2 +
    104882*u2*u3^2*u5^3 + 182750*u2*u3*u5^4 - 7436*u2*u4^5 +
    23114*u2*u4^4*u5 - 47516*u2*u4^3*u5^2 - 11921*u2*u4^2*u5^3 -
    46746*u2*u4*u5^4 + 139782*u2*u5^5 - 7402*u3^6 - 2313*u3^5*u5 +
    14018*u3^4*u5^2 - 96762*u3^3*u5^3 - 289132*u3^2*u5^4 -
    212684*u3*u5^5 + 10755*u4^6 + 49342*u4^5*u5 - 142565*u4^4*u5^2 -
    26822*u4^3*u5^3 + 7858*u4^2*u5^4 - 20290*u4*u5^5 - 51994*u5^6;
  f20 := -18*t1^10 + 31*t1^7*u2*u3 - 105*t1^7*u2*u5 + 24*t1^7*u3^2 +
    408*t1^7*u3*u5 + 135*t1^7*u5^2 + 749*t1^4*u2*u3^3 -
    239*t1^4*u2*u3^2*u5 - 177*t1^4*u2*u3*u5^2 + 18*t1^4*u2*u5^3 +
    237*t1^4*u3^4 + 429*t1^4*u3^3*u5 - 288*t1^4*u3^2*u5^2 -
    762*t1^4*u3*u5^3 - 467*t1^4*u5^4 + 806*t1*u1^5*u5 +
    1069*t1*u1^4*u4*u5 - 1137*t1*u1^4*u5^2 + 331*t1*u1^3*u4^2*u5 -
    2738*t1*u1^3*u4*u5^2 + 1005*t1*u1^3*u5^3 + 1468*t1*u1^2*u4^3*u5 -
    1050*t1*u1^2*u4^2*u5^2 + 2871*t1*u1^2*u4*u5^3 + 278*t1*u1^2*u5^4 -
    173*t1*u1*u3^2*u5^3 - 2134*t1*u1*u3*u5^4 + 636*t1*u1*u4^4*u5 +
    39*t1*u1*u4^3*u5^2 + 3601*t1*u1*u4^2*u5^3 + 278*t1*u1*u4*u5^4 -
    1429*t1*u1*u5^5 - 144*t1*u2*u3^5 - 12*t1*u2*u3^4*u5 +
    143*t1*u2*u3^3*u5^2 - 159*t1*u2*u3^2*u5^3 + 848*t1*u2*u3*u5^4 +
    957*t1*u2*u5^5 - 72*t1*u3^5*u5 - 283*t1*u3^4*u5^2 -
    278*t1*u3^3*u5^3 - 1357*t1*u3^2*u5^4 - 2146*t1*u3*u5^5 +
    18*t1*u4^6 - 856*t1*u4^5*u5 + 1560*t1*u4^4*u5^2 + 541*t1*u4^3*u5^3
    + 225*t1*u4^2*u5^4 + 57*t1*u4*u5^5 - 251*t1*u5^6 + 4*t2^9*t3 -
    12*t2^8*t3^2 + 8*t2^7*t3^3 + 4*t2^7*u1^2 + 8*t2^7*u1*u3 +
    56*t2^7*u1*u4 + 78*t2^7*u1*u5 - 26*t2^7*u2*u3 + 132*t2^7*u2*u5 +
    4*t2^7*u3*u5 - 2*t2^7*u4*u5 + 57*t2^7*u5^2 + 4*t2^6*t3^4 +
    2*t2^6*t3*u5^2 + 310*t2^5*t3^2*u5^2 - 4*t2^4*t3^6 -
    151*t2^4*t3^3*u5^2 + 4*t2^4*u1^4 + 72*t2^4*u1^3*u4 -
    122*t2^4*u1^3*u5 - 110*t2^4*u1^2*u4*u5 - 411*t2^4*u1^2*u5^2 -
    85*t2^4*u1*u3^2*u5 + 188*t2^4*u1*u3*u5^2 + 85*t2^4*u1*u4*u5^2 +
    420*t2^4*u1*u5^3 - 9*t2^4*u2*u3^3 + 322*t2^4*u2*u3^2*u5 +
    362*t2^4*u2*u3*u5^2 - 341*t2^4*u2*u5^3 + 44*t2^4*u3^3*u5 -
    197*t2^4*u3^2*u5^2 - 467*t2^4*u3*u5^3 + 583*t2^4*u4*u5^3 -
    223*t2^4*u5^4 - 8*t2^3*t3^7 + 280*t2^3*t3^4*u5^2 -
    1248*t2^3*t3*u5^4 + 12*t2^2*t3^8 + 504*t2^2*t3^5*u5^2 -
    1271*t2^2*t3^2*u5^4 - 4*t2*t3^9 + 800*t2*t3^6*u4^2 -
    599*t2*t3^6*u4*u5 + 208*t2*t3^6*u5^2 - 1249*t2*t3^3*u4^4 -
    422*t2*t3^3*u4^3*u5 + 849*t2*t3^3*u4^2*u5^2 + 234*t2*t3^3*u4*u5^3
    - 1246*t2*t3^3*u5^4 + 20*t2*u1^5*u3 - 4*t2*u1^5*u4 -
    670*t2*u1^5*u5 + 348*t2*u1^4*u2*u3 + 12*t2*u1^4*u2*u4 +
    720*t2*u1^4*u2*u5 + 80*t2*u1^4*u3^2 + 856*t2*u1^4*u3*u5 -
    108*t2*u1^4*u4^2 - 343*t2*u1^4*u4*u5 + 1010*t2*u1^4*u5^2 +
    73*t2*u1^3*u2*u3^2 - 239*t2*u1^3*u2*u3*u5 - 370*t2*u1^3*u2*u4^2 +
    1817*t2*u1^3*u2*u4*u5 + 218*t2*u1^3*u2*u5^2 - 4*t2*u1^3*u3^3 +
    374*t2*u1^3*u3^2*u5 + 335*t2*u1^3*u3*u5^2 - 808*t2*u1^3*u4^3 +
    581*t2*u1^3*u4^2*u5 + 550*t2*u1^3*u4*u5^2 + 268*t2*u1^3*u5^3 -
    23*t2*u1^2*u2*u3^3 + 489*t2*u1^2*u2*u3^2*u5 +
    88*t2*u1^2*u2*u3*u5^2 + 13*t2*u1^2*u2*u4^3 +
    2645*t2*u1^2*u2*u4^2*u5 + 322*t2*u1^2*u2*u4*u5^2 -
    196*t2*u1^2*u2*u5^3 + 19*t2*u1^2*u3^4 + 300*t2*u1^2*u3^3*u5 +
    47*t2*u1^2*u3^2*u5^2 - 71*t2*u1^2*u3*u5^3 - 1240*t2*u1^2*u4^4 -
    88*t2*u1^2*u4^3*u5 + 134*t2*u1^2*u4^2*u5^2 - 145*t2*u1^2*u4*u5^3 -
    678*t2*u1^2*u5^4 + 90*t2*u1*u2*u3^4 - 48*t2*u1*u2*u3^3*u5 -
    435*t2*u1*u2*u3^2*u5^2 - 533*t2*u1*u2*u3*u5^3 - 1589*t2*u1*u2*u4^4
    + 1445*t2*u1*u2*u4^3*u5 - 377*t2*u1*u2*u4^2*u5^2 -
    339*t2*u1*u2*u4*u5^3 - 103*t2*u1*u2*u5^4 + 32*t2*u1*u3^5 +
    11*t2*u1*u3^4*u5 + 110*t2*u1*u3^3*u5^2 + 375*t2*u1*u3^2*u5^3 -
    529*t2*u1*u3*u5^4 + 1260*t2*u1*u4^5 - 519*t2*u1*u4^4*u5 +
    1795*t2*u1*u4^3*u5^2 + 2064*t2*u1*u4^2*u5^3 + 560*t2*u1*u4*u5^4 -
    1703*t2*u1*u5^5 + 215*t2*u2*u3^5 + 164*t2*u2*u3^4*u5 +
    215*t2*u2*u3^3*u5^2 + 112*t2*u2*u3^2*u5^3 + 458*t2*u2*u3*u5^4 -
    1822*t2*u2*u4^5 + 7*t2*u2*u4^4*u5 - 1670*t2*u2*u4^3*u5^2 -
    1753*t2*u2*u4^2*u5^3 - 514*t2*u2*u4*u5^4 + 1704*t2*u2*u5^5 +
    44*t2*u3^5*u5 - 83*t2*u3^4*u5^2 - 290*t2*u3^3*u5^3 -
    829*t2*u3^2*u5^4 - 3029*t2*u3*u5^5 + 1008*t2*u4^6 - 911*t2*u4^5*u5
    + 538*t2*u4^4*u5^2 + 2467*t2*u4^3*u5^3 + 1250*t2*u4^2*u5^4 -
    1334*t2*u4*u5^5 - 1870*t2*u5^6 + 778*t3^7*u4^2 - 876*t3^7*u4*u5 +
    338*t3^7*u5^2 + 261*t3^4*u4^4 - 1905*t3^4*u4^3*u5 +
    1029*t3^4*u4^2*u5^2 + 418*t3^4*u4*u5^3 - 1094*t3^4*u5^4 +
    596*t3*u2*u4^5 - 679*t3*u2*u4^4*u5 + 790*t3*u2*u4^3*u5^2 -
    1300*t3*u2*u4^2*u5^3 - 1441*t3*u2*u4*u5^4 + 926*t3*u2*u5^5 -
    54*t3*u4^6 - 372*t3*u4^5*u5 - 437*t3*u4^4*u5^2 + 2375*t3*u4^3*u5^3
    - 284*t3*u4^2*u5^4 - 670*t3*u4*u5^5 - 213*t3*u5^6;
  f23 := 62117*t1^10*u2 - 115722*t1^10*u3 - 23381*t1^10*u5 -
    160180*t1^7*u2*u3^2 - 75808*t1^7*u2*u3*u5 + 42409*t1^7*u2*u5^2 +
    25962*t1^7*u3^3 - 129130*t1^7*u3^2*u5 - 270715*t1^7*u3*u5^2 -
    73738*t1^7*u5^3 - 27075*t1^4*u2*u3^4 - 47696*t1^4*u2*u3^3*u5 +
    55909*t1^4*u2*u3^2*u5^2 - 9193*t1^4*u2*u3*u5^3 +
    24802*t1^4*u2*u5^4 - 22206*t1^4*u3^5 + 2995*t1^4*u3^4*u5 +
    189282*t1^4*u3^3*u5^2 + 244764*t1^4*u3^2*u5^3 + 51463*t1^4*u3*u5^4
    - 48241*t1^4*u5^5 - 4*t1*u1^6*u4 + 107345*t1*u1^6*u5 -
    2088*t1*u1^5*u4^2 + 92452*t1*u1^5*u4*u5 - 221391*t1*u1^5*u5^2 +
    40068*t1*u1^4*u4^3 - 7548*t1*u1^4*u4^2*u5 - 396150*t1*u1^4*u4*u5^2
    - 378656*t1*u1^4*u5^3 + 9936*t1*u1^3*u4^4 - 98392*t1*u1^3*u4^3*u5
    - 393852*t1*u1^3*u4^2*u5^2 - 461861*t1*u1^3*u4*u5^3 -
    233845*t1*u1^3*u5^4 + 21060*t1*u1^2*u4^5 - 15453*t1*u1^2*u4^4*u5 -
    191953*t1*u1^2*u4^3*u5^2 - 257583*t1*u1^2*u4^2*u5^3 -
    128774*t1*u1^2*u4*u5^4 - 22913*t1*u1^2*u5^5 +
    76646*t1*u1*u3^2*u5^4 + 120977*t1*u1*u3*u5^5 + 48600*t1*u1*u4^6 +
    96658*t1*u1*u4^5*u5 - 145958*t1*u1*u4^4*u5^2 -
    74095*t1*u1*u4^3*u5^3 - 68632*t1*u1*u4^2*u5^4 -
    17224*t1*u1*u4*u5^5 + 23158*t1*u1*u5^6 - 15864*t1*u2*u3^6 -
    15272*t1*u2*u3^5*u5 - 19743*t1*u2*u3^4*u5^2 -
    111630*t1*u2*u3^3*u5^3 - 138575*t1*u2*u3^2*u5^4 +
    29606*t1*u2*u3*u5^5 - 52785*t1*u2*u5^6 - 7932*t1*u3^6*u5 -
    17337*t1*u3^5*u5^2 + 20055*t1*u3^4*u5^3 + 94598*t1*u3^3*u5^4 +
    244583*t1*u3^2*u5^5 + 200903*t1*u3*u5^6 + 20412*t1*u4^7 +
    34649*t1*u4^6*u5 - 161397*t1*u4^5*u5^2 + 111203*t1*u4^4*u5^3 +
    82558*t1*u4^3*u5^4 + 35868*t1*u4^2*u5^5 - 130603*t1*u4*u5^6 +
    70313*t1*u5^7 + 4*t2^10*u1 + 574*t2^10*u2 + 4*t2^10*u3 -
    506*t2^10*u4 - 1175*t2^10*u5 + 8406*t2^9*t3*u5 +
    14286*t2^8*t3^2*u5 + 16494*t2^7*t3^3*u5 - 8*t2^7*u1^2*u4 -
    974*t2^7*u1^2*u5 - 1239*t2^7*u1*u3^2 + 10493*t2^7*u1*u3*u5 -
    1056*t2^7*u1*u4*u5 - 8315*t2^7*u1*u5^2 - 4232*t2^7*u2*u3^2 -
    10816*t2^7*u2*u3*u5 - 12761*t2^7*u2*u5^2 + 4*t2^7*u3^3 -
    1159*t2^7*u3^2*u5 + 9192*t2^7*u3*u5^2 - 12324*t2^7*u4*u5^2 -
    216*t2^7*u5^3 + 29583*t2^6*t3^4*u5 - 3067*t2^6*t3*u5^3 +
    18493*t2^5*t3^5*u5 + 13476*t2^5*t3^2*u5^3 - 53003*t2^4*t3^6*u5 +
    9055*t2^4*t3^3*u5^3 - 4*t2^4*u1^5 + 13054*t2^4*u1^4*u4 -
    34055*t2^4*u1^4*u5 - 71107*t2^4*u1^3*u4*u5 - 7664*t2^4*u1^3*u5^2 -
    17298*t2^4*u1^2*u4*u5^2 + 16876*t2^4*u1^2*u5^3 +
    8182*t2^4*u1*u3^2*u5^2 + 50237*t2^4*u1*u3*u5^3 +
    4495*t2^4*u1*u4*u5^3 + 75167*t2^4*u1*u5^4 - 80*t2^4*u2*u3^4 +
    10369*t2^4*u2*u3^3*u5 - 6723*t2^4*u2*u3^2*u5^2 -
    17515*t2^4*u2*u3*u5^3 - 71734*t2^4*u2*u5^4 - 2329*t2^4*u3^4*u5 -
    15149*t2^4*u3^3*u5^2 + 32631*t2^4*u3^2*u5^3 + 84932*t2^4*u3*u5^4 -
    2503*t2^4*u4*u5^4 + 91263*t2^4*u5^5 - 76375*t2^3*t3^7*u5 +
    15485*t2^3*t3^4*u5^3 + 20662*t2^3*t3*u5^5 - 49295*t2^2*t3^8*u5 +
    10098*t2^2*t3^5*u5^3 + 39237*t2^2*t3^2*u5^5 + 28680*t2*t3^9*u4 -
    42257*t2*t3^9*u5 + 110354*t2*t3^6*u4^3 - 46811*t2*t3^6*u4^2*u5 -
    129255*t2*t3^6*u4*u5^2 - 5804*t2*t3^6*u5^3 + 146551*t2*t3^3*u4^5 -
    45696*t2*t3^3*u4^4*u5 - 97803*t2*t3^3*u4^3*u5^2 -
    83457*t2*t3^3*u4^2*u5^3 - 6290*t2*t3^3*u4*u5^4 +
    47519*t2*t3^3*u5^5 + 13122*t2*u1^6*u3 + 4*t2*u1^6*u4 -
    25747*t2*u1^6*u5 + 22101*t2*u1^5*u2*u3 - 26228*t2*u1^5*u2*u4 +
    68455*t2*u1^5*u2*u5 - 13273*t2*u1^5*u3^2 - 57579*t2*u1^5*u3*u5 +
    52*t2*u1^5*u4^2 + 10112*t2*u1^5*u4*u5 - 21560*t2*u1^5*u5^2 +
    29642*t2*u1^4*u2*u3^2 + 63275*t2*u1^4*u2*u3*u5 -
    95595*t2*u1^4*u2*u4^2 + 44679*t2*u1^4*u2*u4*u5 +
    27713*t2*u1^4*u2*u5^2 - 23993*t2*u1^4*u3^3 + 4086*t2*u1^4*u3^2*u5
    - 49512*t2*u1^4*u3*u5^2 + 56652*t2*u1^4*u4^3 +
    110914*t2*u1^4*u4^2*u5 + 6156*t2*u1^4*u4*u5^2 - 36365*t2*u1^4*u5^3
    - 904*t2*u1^3*u2*u3^3 + 3174*t2*u1^3*u2*u3^2*u5 -
    47086*t2*u1^3*u2*u3*u5^2 - 222268*t2*u1^3*u2*u4^3 -
    61939*t2*u1^3*u2*u4^2*u5 - 9571*t2*u1^3*u2*u4*u5^2 -
    46071*t2*u1^3*u2*u5^3 + 3852*t2*u1^3*u3^4 - 8511*t2*u1^3*u3^3*u5 -
    5616*t2*u1^3*u3^2*u5^2 + 25394*t2*u1^3*u3*u5^3 -
    124452*t2*u1^3*u4^4 + 231040*t2*u1^3*u4^3*u5 +
    10246*t2*u1^3*u4^2*u5^2 - 89729*t2*u1^3*u4*u5^3 -
    31458*t2*u1^3*u5^4 + 27832*t2*u1^2*u2*u3^4 -
    10029*t2*u1^2*u2*u3^3*u5 - 75532*t2*u1^2*u2*u3^2*u5^2 -
    52914*t2*u1^2*u2*u3*u5^3 - 664216*t2*u1^2*u2*u4^4 -
    227180*t2*u1^2*u2*u4^3*u5 + 41266*t2*u1^2*u2*u4^2*u5^2 +
    114549*t2*u1^2*u2*u4*u5^3 + 50217*t2*u1^2*u2*u5^4 +
    8356*t2*u1^2*u3^5 - 2598*t2*u1^2*u3^4*u5 - 18072*t2*u1^2*u3^3*u5^2
    + 95108*t2*u1^2*u3^2*u5^3 + 61401*t2*u1^2*u3*u5^4 +
    23292*t2*u1^2*u4^5 + 334820*t2*u1^2*u4^4*u5 +
    58988*t2*u1^2*u4^3*u5^2 - 57337*t2*u1^2*u4^2*u5^3 -
    102283*t2*u1^2*u4*u5^4 - 3026*t2*u1^2*u5^5 + 7941*t2*u1*u2*u3^5 -
    57834*t2*u1*u2*u3^4*u5 - 40135*t2*u1*u2*u3^3*u5^2 -
    78366*t2*u1*u2*u3^2*u5^3 - 39751*t2*u1*u2*u3*u5^4 -
    922812*t2*u1*u2*u4^5 - 293148*t2*u1*u2*u4^4*u5 +
    113222*t2*u1*u2*u4^3*u5^2 + 174284*t2*u1*u2*u4^2*u5^3 +
    155872*t2*u1*u2*u4*u5^4 + 59732*t2*u1*u2*u5^5 - 2345*t2*u1*u3^6 -
    15006*t2*u1*u3^5*u5 + 32641*t2*u1*u3^4*u5^2 +
    120102*t2*u1*u3^3*u5^3 + 153115*t2*u1*u3^2*u5^4 +
    80834*t2*u1*u3*u5^5 + 389772*t2*u1*u4^6 + 149131*t2*u1*u4^5*u5 +
    101768*t2*u1*u4^4*u5^2 - 54798*t2*u1*u4^3*u5^3 -
    88129*t2*u1*u4^2*u5^4 - 19236*t2*u1*u4*u5^5 + 64956*t2*u1*u5^6 -
    4160*t2*u2*u3^6 + 711*t2*u2*u3^5*u5 + 2417*t2*u2*u3^4*u5^2 +
    8005*t2*u2*u3^3*u5^3 - 84307*t2*u2*u3^2*u5^4 + 22829*t2*u2*u3*u5^5
    - 551188*t2*u2*u4^6 - 139569*t2*u2*u4^5*u5 + 11706*t2*u2*u4^4*u5^2
    + 73925*t2*u2*u4^3*u5^3 + 73171*t2*u2*u4^2*u5^4 +
    10880*t2*u2*u4*u5^5 - 114934*t2*u2*u5^6 - 2345*t2*u3^6*u5 +
    1279*t2*u3^5*u5^2 + 26106*t2*u3^4*u5^3 - 10053*t2*u3^3*u5^4 +
    22362*t2*u3^2*u5^5 + 94657*t2*u3*u5^6 + 351449*t2*u4^7 -
    132*t2*u4^6*u5 + 83770*t2*u4^5*u5^2 - 89358*t2*u4^4*u5^3 -
    21580*t2*u4^3*u5^4 + 14155*t2*u4^2*u5^5 + 70306*t2*u4*u5^6 +
    48665*t2*u5^7 + 14465*t3^10*u4 - 15057*t3^10*u5 + 110967*t3^7*u4^3
    - 31534*t3^7*u4^2*u5 - 106477*t3^7*u4*u5^2 + 20161*t3^7*u5^3 +
    190509*t3^4*u4^5 - 53957*t3^4*u4^4*u5 - 193856*t3^4*u4^3*u5^2 +
    40083*t3^4*u4^2*u5^3 + 2717*t3^4*u4*u5^4 + 267*t3^4*u5^5 +
    92132*t3*u2*u4^6 - 143275*t3*u2*u4^5*u5 - 255900*t3*u2*u4^4*u5^2 +
    130854*t3*u2*u4^3*u5^3 + 169569*t3*u2*u4^2*u5^4 +
    162438*t3*u2*u4*u5^5 - 125983*t3*u2*u5^6 + 34020*t3*u4^7 -
    29045*t3*u4^6*u5 - 111974*t3*u4^5*u5^2 - 28470*t3*u4^4*u5^3 +
    28467*t3*u4^3*u5^4 + 52806*t3*u4^2*u5^5 + 13180*t3*u4*u5^6 +
    38707*t3*u5^7;
  return f5,f8,f10,g10,f11,f12,f13,f15,f18,f20,f23;
end function;

