
// Make newform 2160.3.c.m in Magma, downloaded from the LMFDB on 02 January 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_2160_c();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_2160_c_Hecke();"
// To make the coeffs of the qexp of the newform in the Hecke field type "qexpCoeffs();"
// To make the newform (type ModFrm), type "MakeNewformModFrm_2160_3_c_m();".
// This may take a long time!  To see verbose output, uncomment the SetVerbose lines below.
// The precision argument determines an initial guess on how many Fourier coefficients to use.
// This guess is increased enough to uniquely determine the newform.
// To make the Hecke irreducible modular symbols subspace (type ModSym)
// containing the newform, type "MakeNewformModSym_2160_3_c_m();".
// This may take a long time!  To see verbose output, uncomment the SetVerbose line below.
// The default sign is -1.  You can change this with the optional parameter "sign".
function ConvertToHeckeField(input: pass_field := false, Kf := [])
    if not pass_field then
        poly := [31, 0, 14, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 7, 0, 1], [7, 0, 1, 0], [0, 13, 0, 1]];
    Rf_basisdens := [1, 3, 3, 3];
    Rf_basisnums := ChangeUniverse([[z : z in elt] : elt in Rf_num], Kf);
    Rfbasis := [Rf_basisnums[i]/Rf_basisdens[i] : i in [1..Degree(Kf)]];
    inp_vec := Vector(Rfbasis)*ChangeRing(Transpose(Matrix([[elt : elt in row] : row in input])),Kf);
    return Eltseq(inp_vec);
end function;


// To make the character of type GrpDrchElt, type "MakeCharacter_2160_c();"
function MakeCharacter_2160_c()
    N := 2160;
    order := 2;
    char_gens := [271, 1621, 2081, 1297];
    v := [2, 2, 1, 1];
    // chi(gens[i]) = zeta^v[i]
    assert UnitGenerators(DirichletGroup(N)) eq char_gens;
    F := CyclotomicField(order);
    chi := DirichletCharacterFromValuesOnUnitGenerators(DirichletGroup(N,F),[F|F.1^e:e in v]);
    return MinimalBaseRingCharacter(chi);
end function;

// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_2160_c_Hecke();"
function MakeCharacter_2160_c_Hecke(Kf)
    N := 2160;
    order := 2;
    char_gens := [271, 1621, 2081, 1297];
    char_values := [[1, 0, 0, 0], [1, 0, 0, 0], [-1, 0, 0, 0], [-1, 0, 0, 0]];
    assert UnitGenerators(DirichletGroup(N)) eq char_gens;
    values := ConvertToHeckeField(char_values : pass_field := true, Kf := Kf); // the value of chi on the gens as elements in the Hecke field
    F := Universe(values);// the Hecke field
    chi := DirichletCharacterFromValuesOnUnitGenerators(DirichletGroup(N,F),values);
    return chi;
end function;


function ExtendMultiplicatively(weight, aps, character)
    prec := NextPrime(NthPrime(#aps)) - 1; // we will able to figure out a_0 ... a_prec
    primes := PrimesUpTo(prec);
    prime_powers := primes;
    assert #primes eq #aps;
    log_prec := Floor(Log(prec)/Log(2)); // prec < 2^(log_prec+1)
    F := Universe(aps);
    FXY<X, Y> := PolynomialRing(F, 2);
    // 1/(1 - a_p T + p^(weight - 1) * char(p) T^2) = 1 + a_p T + a_{p^2} T^2 + ...
    R<T> := PowerSeriesRing(FXY : Precision := log_prec + 1);
    recursion := Coefficients(1/(1 - X*T + Y*T^2));
    coeffs := [F!0: i in [1..prec]];
    coeffs[1] := 1; //a_1
    for i := 1 to #primes do
        p := primes[i];
        coeffs[p] := aps[i];
        b := p^(weight - 1) * F!character(p);
        r := 2;
        p_power := p * p;
        //deals with powers of p
        while p_power le prec do
            Append(~prime_powers, p_power);
            coeffs[p_power] := Evaluate(recursion[r + 1], [aps[i], b]);
            p_power *:= p;
            r +:= 1;
        end while;    
    end for;
    Sort(~prime_powers);
    for pp in prime_powers do
        for k := 1 to Floor(prec/pp) do
            if GCD(k, pp) eq 1 then
                coeffs[pp*k] := coeffs[pp]*coeffs[k];
            end if;
        end for;
    end for;
    return coeffs;
end function;


function qexpCoeffs()
    // To make the coeffs of the qexp of the newform in the Hecke field type "qexpCoeffs();"
    weight := 3;
    raw_aps := [[0, 0, 0, 0], [0, 0, 0, 0], [3, 1, 1, 0], [0, 1, 0, 2], [0, -2, 0, 3], [0, 0, 0, 3], [-3, 0, 7, 0], [3, 0, 3, 0], [-15, 0, -14, 0], [0, 9, 0, 0], [17, 0, 15, 0], [0, 14, 0, -2], [0, -1, 0, -6], [0, -7, 0, 4], [60, 0, -14, 0], [51, 0, -9, 0], [0, 4, 0, -9], [-49, 0, 24, 0], [0, 8, 0, -26], [0, 6, 0, -21], [0, 16, 0, -7], [-45, 0, 63, 0], [-27, 0, 58, 0], [0, -29, 0, 0], [0, 10, 0, -22], [0, -8, 0, 6], [0, 28, 0, 2], [36, 0, 30, 0], [-19, 0, -90, 0], [12, 0, 30, 0], [0, 34, 0, 14], [0, -18, 0, -12], [27, 0, 135, 0], [-38, 0, 102, 0], [0, 35, 0, -12], [20, 0, -66, 0], [0, 16, 0, -19], [0, 28, 0, -10], [-21, 0, 60, 0], [69, 0, -29, 0], [0, -20, 0, 12], [113, 0, -42, 0], [0, -66, 0, -12], [0, 34, 0, 17], [279, 0, -1, 0], [-114, 0, 30, 0], [-171, 0, -105, 0], [0, 74, 0, -2], [87, 0, -232, 0], [-59, 0, 114, 0], [126, 0, 82, 0], [0, 44, 0, 48], [-191, 0, -90, 0], [0, 36, 0, -30], [87, 0, -213, 0], [-60, 0, 118, 0], [0, -18, 0, 72], [-115, 0, 147, 0], [0, -22, 0, 49], [0, -27, 0, 0], [0, -53, 0, 86], [-45, 0, -129, 0], [0, 0, 0, 60], [0, 114, 0, 21], [0, 112, 0, 20], [57, 0, 211, 0], [266, 0, 126, 0], [0, 56, 0, -95], [150, 0, 240, 0], [-37, 0, 84, 0], [6, 0, -182, 0], [0, 18, 0, 84], [0, -107, 0, -16], [0, 18, 0, 12], [-91, 0, -165, 0], [-465, 0, -76, 0], [0, -119, 0, -78], [0, -106, 0, -23], [0, 106, 0, 18], [-491, 0, -30, 0], [0, 50, 0, -63], [391, 0, 24, 0], [0, -152, 0, -33], [0, -8, 0, -103], [-135, 0, -189, 0], [-447, 0, 6, 0], [0, 33, 0, -132], [0, 98, 0, 82], [0, -78, 0, 30], [0, 132, 0, -96], [675, 0, 48, 0], [0, -34, 0, 93], [0, -51, 0, 30], [0, 18, 0, 132], [681, 0, -57, 0], [357, 0, 54, 0], [0, 54, 0, -192], [0, -17, 0, 6], [0, -137, 0, 86], [-80, 0, 210, 0], [0, 67, 0, -10], [210, 0, -66, 0], [-384, 0, -106, 0], [0, 19, 0, 12], [-127, 0, 699, 0], [0, 170, 0, -77], [309, 0, 162, 0], [-549, 0, -237, 0], [0, 162, 0, -75], [437, 0, -30, 0], [0, 53, 0, 16], [0, -176, 0, 14], [315, 0, -269, 0], [266, 0, -174, 0], [427, 0, -153, 0], [0, 38, 0, 192], [0, -45, 0, 12], [339, 0, 252, 0], [-855, 0, -49, 0], [0, 94, 0, -27], [668, 0, 258, 0], [0, -84, 0, 33], [444, 0, 94, 0], [147, 0, 268, 0], [65, 0, -345, 0], [0, -100, 0, -114], [636, 0, -378, 0], [0, -28, 0, 18], [0, 36, 0, -108], [0, -334, 0, -92], [-827, 0, 51, 0], [-498, 0, -576, 0], [-473, 0, -537, 0], [0, -166, 0, -2], [0, 153, 0, -156], [-687, 0, 102, 0], [-459, 0, -45, 0], [0, -155, 0, -82], [1011, 0, -281, 0], [0, -15, 0, -90], [692, 0, -282, 0], [0, 100, 0, -192], [0, -189, 0, 114], [615, 0, -424, 0], [180, 0, -930, 0], [0, -68, 0, 72], [0, -88, 0, 40], [945, 0, -537, 0], [653, 0, 315, 0], [-75, 0, 30, 0], [0, 226, 0, 83], [0, -117, 0, 342], [0, 123, 0, -90], [-531, 0, -798, 0], [0, -318, 0, 102], [0, -348, 0, -111], [762, 0, 366, 0], [0, -129, 0, -120], [0, -14, 0, 176], [0, -4, 0, -180], [-399, 0, 150, 0], [-294, 0, 814, 0], [0, -136, 0, 274], [0, -342, 0, -90], [-678, 0, 402, 0], [-243, 0, -70, 0], [-433, 0, 207, 0], [0, -120, 0, 159], [433, 0, -738, 0], [177, 0, 111, 0], [0, 6, 0, -60], [183, 0, 120, 0], [0, -146, 0, -69], [0, 212, 0, -62], [595, 0, -117, 0], [0, -201, 0, 216], [391, 0, -225, 0], [0, -213, 0, 0], [0, 23, 0, 178], [652, 0, 774, 0], [0, 223, 0, 38], [0, 266, 0, -276], [0, -88, 0, -242], [1068, 0, 534, 0], [-117, 0, 1124, 0], [0, -84, 0, 264], [0, -64, 0, -185], [0, 166, 0, -130], [-323, 0, -522, 0], [0, 176, 0, -123], [0, 66, 0, 264], [-1425, 0, 52, 0], [-961, 0, 243, 0], [0, 66, 0, -174], [1077, 0, 330, 0], [-843, 0, -825, 0], [-1287, 0, -342, 0], [0, -42, 0, -246], [-186, 0, -1290, 0], [-144, 0, -706, 0], [0, -105, 0, 216], [654, 0, 30, 0], [0, -54, 0, 432], [-97, 0, 144, 0], [0, 314, 0, -237], [-786, 0, -150, 0], [-1146, 0, -462, 0], [-573, 0, -356, 0], [0, 284, 0, -378], [-610, 0, -162, 0], [0, 364, 0, 83], [0, 165, 0, 186], [0, -122, 0, -52], [12, 0, 378, 0], [0, 118, 0, -486], [1003, 0, -804, 0], [0, 335, 0, -254], [0, 202, 0, 258], [-369, 0, -1280, 0], [1461, 0, -589, 0], [-1818, 0, -504, 0], [-701, 0, -261, 0], [0, 21, 0, -246], [0, 133, 0, 242], [1257, 0, -678, 0], [-843, 0, -174, 0], [-165, 0, 779, 0], [0, 100, 0, -225], [0, 56, 0, -248], [0, -110, 0, 270], [0, -22, 0, 439], [-701, 0, -537, 0], [-1070, 0, 882, 0], [0, -270, 0, 6], [0, 65, 0, -314], [63, 0, 80, 0], [1197, 0, 606, 0], [1401, 0, 919, 0], [0, -300, 0, 174], [0, 168, 0, 237], [-1284, 0, -102, 0], [-1997, 0, 627, 0], [0, -10, 0, -32], [233, 0, 558, 0], [-1074, 0, 386, 0], [0, -372, 0, -288], [0, 312, 0, 162], [0, -366, 0, -237], [1586, 0, 138, 0], [-2373, 0, 124, 0], [0, 396, 0, -12], [0, 284, 0, 126], [-159, 0, 670, 0], [-409, 0, -732, 0], [1581, 0, 535, 0], [0, -222, 0, 474], [-869, 0, -1272, 0], [0, 65, 0, 304], [-501, 0, -1165, 0], [0, -122, 0, 539], [0, 9, 0, 252], [-1149, 0, 392, 0], [-535, 0, 1026, 0], [0, 518, 0, 64], [2499, 0, 327, 0], [542, 0, -1386, 0], [0, -102, 0, 138], [0, -322, 0, 96], [0, 92, 0, 256], [2202, 0, 294, 0], [-949, 0, -384, 0], [0, -208, 0, -212], [0, 56, 0, -167], [-815, 0, 219, 0], [0, 440, 0, -395], [0, 133, 0, 146], [1185, 0, 634, 0], [-1253, 0, 1500, 0], [-475, 0, 1086, 0], [0, 648, 0, 111], [-132, 0, -1074, 0], [871, 0, 1671, 0], [-825, 0, 700, 0], [2119, 0, -588, 0], [0, -388, 0, -194], [0, 538, 0, -471], [0, -408, 0, 534], [-1098, 0, 302, 0], [-31, 0, 1803, 0], [0, -260, 0, -306], [0, -676, 0, -162], [381, 0, 774, 0], [270, 0, -162, 0], [0, -222, 0, 66], [0, -62, 0, 671], [0, -6, 0, -150], [-321, 0, -1485, 0], [-30, 0, -762, 0], [0, -280, 0, 420], [0, 507, 0, -558], [0, -664, 0, -305], [-555, 0, 1215, 0], [2018, 0, 222, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2160_c_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_2160_3_c_m();".
// This may take a long time!  To see verbose output, uncomment the SetVerbose lines below.
// The precision argument determines an initial guess on how many Fourier coefficients to use.
// This guess is increased enough to uniquely determine the newform.
function MakeNewformModFrm_2160_3_c_m(:prec:=4)
    chi := MakeCharacter_2160_c();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 3));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(1999) - 1;
    while true do
        trunc_vec := Vector(Kf, [0] cat [f_vec[i]: i in [1..prec]]);
        B := Basis(S, prec + 1);
        S_basismat := Matrix([AbsEltseq(g): g in B]);
        if Rank(S_basismat) eq Min(NumberOfRows(S_basismat), NumberOfColumns(S_basismat)) then
            S_basismat := ChangeRing(S_basismat,Kf);
            f_lincom := Solution(S_basismat,trunc_vec);
            f := &+[f_lincom[i]*Basis(S)[i] : i in [1..#Basis(S)]];
            return f;
        end if;
        error if prec eq maxprec, "Unable to distinguish newform within newspace";
        prec := Min(Ceiling(1.25 * prec), maxprec);
    end while;
end function;


// To make the Hecke irreducible modular symbols subspace (type ModSym)
// containing the newform, type "MakeNewformModSym_2160_3_c_m();".
// This may take a long time!  To see verbose output, uncomment the SetVerbose line below.
// The default sign is -1.  You can change this with the optional parameter "sign".
function MakeNewformModSym_2160_3_c_m( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2160_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<7,R![124, 0, 188, 0, 1]>,<17,R![-89, 6, 1]>],Snew);
    return Vf;
end function;