(*This transforms the unit cube [0,1]^5 into the simplex defined by the
  inequalities X1>=X2>=X3>=X4>=X5>=0. We call this the standard simplex.*)

CubeToStandard[X_]:={X[[1]],X[[1]] X[[2]],X[[1]] X[[2]] X[[3]],X[[1]] X[[2]] X[[3]] X[[4]],X[[1]] X[[2]] X[[3]] X[[4]] X[[5]]};

(*This transforms the standard simplex in R5 to the simplex defined by
  the inequalities X_j>=0 and X1+...+X6=1.  We call this the symmetric  
  Simplex*)

StandardToSymmetric[X_]:=(
m=Transpose[{{-1,1,0,0,0,0},{0,-1,1,0,0,0},{0,0,-1,1,0,0},{0,0,0,-1,1,0},{0,0,0,0,-1,1}}];
m.X+{1,0,0,0,0,0})


(*This transforms the symmetric simplex to a simplex whose
  vertices are specified by some (5x6) matrix m - 6 rows*)

SymmetricToGeneral[m_,X_]:=Transpose[m].X;

(**These are the vertices for our moduli space*)

VTX:={{1,1,0,0,0},
{0,0,1,1,0},
{1,0,0,1,1},
{0,1,1,0,1},
{1,1,0,1,1},
{0,1,1,1,1},
{1,0,1,1,1},
{1,1,1,1,0},
{1,1,1,0,1},
{1,.5,1,.5,.5},
{.5,1,.5,1,.5},
{1,1,1,1,1}};

(**This is the list of 14 tetrahedra*)

CODE:={{6,4,3,2,1,0},
    {0,1,2,4,6,7},
    {0,1,3,4,5,8},
    {0,1,3,4,6,8},
    {0,1,3,5,7,8},
    {0,1,4,5,7,8},
    {0,1,4,5,7,10},
    {0,1,4,6,7,8},
    {0,1,6,7,8,9},
    {0,2,3,4,6,8},
    {1,2,3,4,5,6},
    {1,3,4,5,6,8},
    {1,4,5,6,7,8},
    {4,5,6,7,8,11}};

Simplex[k_]:=(
a1=CODE[[k]];
a2=Table[VTX[[a1[[j]]+1]],{j,1,6}])


(*These are the 14  maps which carry the cube to the desired simplex*)

CubeToGeneral[k_,X_]:=(
Y1=CubeToStandard[X];
Y2=StandardToSymmetric[Y1];
mm=Simplex[k];
Y3=SymmetricToGeneral[mm,Y2];
Expand[Simplify[Y3]])

(*These are the two maps:*)

(*Cayley Menger determinant, restricted to the set d12=1 *)

F1[d13_,d14_,d23_,d24_,d34_]:=(
-2 d13^2 d23^2 + 2 d14^2 d23^2 + 2 d13^2 d14^2 d23^2 - 2 d14^4 d23^2 - 
 2 d14^2 d23^4 + 2 d13^2 d24^2 - 2 d13^4 d24^2 - 2 d14^2 d24^2 + 
 2 d13^2 d14^2 d24^2 + 2 d13^2 d23^2 d24^2 + 2 d14^2 d23^2 d24^2 - 
 2 d13^2 d24^4 - 2 d34^2 + 2 d13^2 d34^2 + 2 d14^2 d34^2 - 
 2 d13^2 d14^2 d34^2 + 2 d23^2 d34^2 + 2 d14^2 d23^2 d34^2 + 
 2 d24^2 d34^2 + 2 d13^2 d24^2 d34^2 - 2 d23^2 d24^2 d34^2 - 2 d34^4)

(*Directional derivative, restricted to the set d12=1*)

F2[d13_,d14_,d23_,d24_,d34_]:=(
-4 d13^2 d23 + 4 d14^2 d23 + 4 d13^2 d14^2 d23 - 4 d14^4 d23 - 
 4 d13 d23^2 - 4 d13^2 d23^2 + 4 d14 d23^2 + 4 d13^2 d14 d23^2 + 
 4 d14^2 d23^2 + 4 d13 d14^2 d23^2 - 8 d14^3 d23^2 - 8 d14^2 d23^3 - 
 4 d14 d23^4 + 4 d13^2 d24 - 4 d13^4 d24 - 4 d14^2 d24 + 
 4 d13^2 d14^2 d24 + 4 d13^2 d23^2 d24 + 4 d14^2 d23^2 d24 + 
 4 d13 d24^2 + 4 d13^2 d24^2 - 8 d13^3 d24^2 - 4 d14 d24^2 + 
 4 d13^2 d14 d24^2 - 4 d14^2 d24^2 + 4 d13 d14^2 d24^2 + 
 4 d13^2 d23 d24^2 + 4 d14^2 d23 d24^2 + 4 d13 d23^2 d24^2 + 
 4 d14 d23^2 d24^2 - 8 d13^2 d24^3 - 4 d13 d24^4 - 4 d34 + 
 4 d13^2 d34 + 4 d14^2 d34 - 4 d13^2 d14^2 d34 + 4 d23^2 d34 + 
 4 d14^2 d23^2 d34 + 4 d24^2 d34 + 4 d13^2 d24^2 d34 - 
 4 d23^2 d24^2 d34 - 8 d34^2 + 4 d13 d34^2 + 4 d13^2 d34^2 + 
 4 d14 d34^2 - 4 d13^2 d14 d34^2 + 4 d14^2 d34^2 - 
 4 d13 d14^2 d34^2 + 4 d23 d34^2 + 4 d14^2 d23 d34^2 + 
 4 d23^2 d34^2 + 4 d14 d23^2 d34^2 + 4 d24 d34^2 + 
 4 d13^2 d24 d34^2 - 4 d23^2 d24 d34^2 + 4 d24^2 d34^2 + 
 4 d13 d24^2 d34^2 - 4 d23 d24^2 d34^2 - 8 d34^3 - 4 d34^4)


(*In this function, you can change the coefficient 4 to 6*)

F3[{d13_,d14_,d23_,d24_,d34_}]:=ExpandAll[F2[d13,d14,d23,d24,d34]-4 F1[d13,d14,d23,d24,d34]]


MAIN[k_,X_]:=Expand[F3[CubeToGeneral[k,X]]];

(*This extracts the coefficients of a polynomial in a,b,c,d,e*)

ExtractCoeff[Y_]:=(
Y1=Table[Y[[j]],{j,1,Length[Y]}];
{a,b,c,d,e}={1,1,1,1,1};
Y2=Y1;
Clear[a,b,c,d,e];
Y2)

(*This extracts the kth exponent*)

ExtractExponent[Y_,k_]:=(
Y0=ExtractCoeff[Y];
Y1=Table[Y[[j]],{j,1,Length[Y]}];
list={1,1,1,1,1};
list[[k]]=2;
{a,b,c,d,e}=list;
Y2=Y1/Y0;
Clear[a,b,c,d,e];
Y3=Table[LOG2[Y2[[j]]],{j,1,Length[Y2]}];
Y3)

(*This extracts all the exponents*)

ExtractExponents[Y_]:=(
Y2=Table[ExtractExponent[Y,k],{k,1,5}];
Y3=Transpose[Y2];
Y3)

LOG2[n_]:=Floor[Log[n]/Log[2]+.000000001];

(*This extracts the coefficients and all exponents*)

ExtractAll[Y_]:=(
a1=ExtractCoeff[Chop[Y]];
a2=ExtractExponents[Chop[Y]];
a1=Floor[a1];
a3=Table[Flatten[{a1[[j]],a2[[j]]}],{j,1,Length[a1]}])

(*This puts everything together and writes it to a file.
  The writing is in quasi-Java.  After the file is written, 
  I have to go in and lightly edit it.*)

FILE=OpenWrite["test2"];
Do[{
Write[FILE,"public static int[][] main() {"];
Write[FILE,"int[][] y="];
Write[FILE,ExtractAll[MAIN[k,{a,b,c,d,e}]]]
Write[FILE,"return(y);"];
Write[FILE,"}"];},{k,1,14}]