(* ::Package:: *)


SetDirectory @ NotebookDirectory[];
Import["../utils.m"]


(* ::Section:: *)
(*Secondary equation for 2-loop massless double box by Macaulay matrix method*)
P = Get["pfaffian_matrix_by_mm.m"] // ReplaceAll[{e -> 1 / 11, d -> 1 / 17}];
sys = P // RightComposition[
    {-#, #}&,
    Transpose[#, {1, 3, 2}]&,
    Outer[Times, #[[1]], #[[1]] // Length // IdentityMatrix, 2]
    +
    Outer[Times, #[[2]] // Length // IdentityMatrix, #[[2]], 2]&,
    Flatten[#, {{1, 4}, {2, 3}}]&,
    Identity
];


(* ::Text:: *)
(*Export to Maple*)


MaplePut[sys, "secondary_equation.mma", "sys"]


(* ::Text:: *)
(*At this point you should run the `secondary.mpl` script*)


(* ::Text:: *)
(*Import from Maple*)


sol = MapleGet["secondary_equation_solutions.mma"] // Transpose // Map[Partition[#, P // Length]&];


(* ::Text:: *)
(*Select the dimension 2 eigenspaces*)


eigenvals = sol // Map[Eigenvalues /* Factor /* Gather /* DeleteCases[x_ /; Length[x] > 2]]


(* ::Text:: *)
(*These eigenspaces generate 4 symmetry relations, which reduce the rank from 12 down to expected 8*)


Rmaple = Join[
    sol[[1]] - eigenvals[[1, 1, 1]] IdentityMatrix[12] // getNullSpace,
    sol[[3]] - eigenvals[[3, 1, 1]] IdentityMatrix[12] // getNullSpace,
    sol[[3]] - eigenvals[[3, 2, 1]] IdentityMatrix[12] // getNullSpace,
    {}
] // rowReduce // Normal;
Rmaple // Dimensions
