
// Make newform 54.6.c.b in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_54_c();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_54_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_54_6_c_b();".
// 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_54_6_c_b();".
// 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 := [32331, -3585, 3700, -231, 118, -3, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0], [22035, 16626, -269, 176, 5, -2], [-26145, 840, -843, 6, -3, 0], [1104636, 435399, 40288, 29567, 128, 331], [854100, 648093, -7764, 31029, -696, 333], [-1610349, 606843, -133067, 33389, -1783, 331]];
    Rf_basisdens := [1, 60606, 74, 6734, 6734, 6734];
    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_54_c();"
function MakeCharacter_54_c()
    N := 54;
    order := 3;
    char_gens := [29];
    v := [2];
    // 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_54_c_Hecke();"
function MakeCharacter_54_c_Hecke(Kf)
    N := 54;
    order := 3;
    char_gens := [29];
    char_values := [[-1, 1, 0, 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+1)]];
    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 := 6;
    raw_aps := [[0, 4, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [18, -18, 0, 0, 0, -1], [0, -44, 0, 0, -1, 0], [0, 105, 0, 5, -1, 0], [-248, 248, -2, 0, -2, -11], [-483, 0, -4, 9, 0, -9], [377, 0, 6, 5, 0, -5], [1056, -1056, -1, 0, -1, 14], [0, 1716, 0, -59, 6, 0], [-2870, 2870, 17, 0, 17, -44], [6656, 0, 10, -40, 0, 40], [-1683, 1683, 70, 0, 70, -80], [0, -10463, 0, -117, 39, 0], [0, -4308, 0, -40, 49, 0], [16008, 0, -54, 116, 0, -116], [-20985, 20985, -71, 0, -71, 255], [0, -25322, 0, 37, -82, 0], [-10997, 10997, -15, 0, -15, -519], [21612, 0, -130, 354, 0, -354], [-1411, 0, -68, 901, 0, -901], [0, 29734, 0, 724, -15, 0], [0, -10878, 0, 476, 211, 0], [-11022, 0, 98, 294, 0, -294], [0, 15415, 0, -16, 386, 0], [0, 34074, 0, 45, -88, 0], [67492, -67492, 655, 0, 655, 1376], [45555, 0, 54, -1501, 0, 1501], [6932, 0, -586, 824, 0, -824], [-31908, 31908, 142, 0, 142, 155], [-106954, 0, 1188, 294, 0, -294], [-141894, 141894, 987, 0, 987, 260], [0, 13785, 0, -576, -938, 0], [83419, -83419, 87, 0, 87, -2357], [93792, -93792, -1662, 0, -1662, -1613], [0, 59440, 0, -3770, -235, 0], [156178, -156178, -392, 0, -392, -2755], [238388, 0, -176, -1312, 0, 1312], [-149034, 149034, 269, 0, 269, 3382], [0, -62016, 0, -957, 1212, 0], [269916, 0, 828, 1580, 0, -1580], [-14746, 0, -450, -6770, 0, 6770], [0, 224784, 0, -6384, 149, 0], [-262889, 262889, -1042, 0, -1042, 2464], [-335184, 0, 436, -298, 0, 298], [311498, 0, -854, 4248, 0, -4248], [175450, -175450, 1443, 0, 1443, -310], [0, -775724, 0, 508, 491, 0], [0, -82599, 0, 4645, -1177, 0], [-610532, 610532, 1124, 0, 1124, 6835], [38139, 0, -5182, 3457, 0, -3457], [-192684, 192684, -4917, 0, -4917, -10602], [0, 526555, 0, -10950, -2236, 0], [-147315, 0, 2978, 11149, 0, -11149], [632499, -632499, 2924, 0, 2924, 2344], [0, -816516, 0, 5706, 1871, 0], [-1589628, 0, 214, -180, 0, 180], [55100, 0, 4740, 8328, 0, -8328], [0, -332780, 0, -16343, 3548, 0], [0, -13476, 0, -23241, -3896, 0], [-245870, 245870, -4715, 0, -4715, -14440], [-405420, 405420, 1664, 0, 1664, 30665], [-961513, 0, -2626, -27337, 0, 27337], [-427212, 427212, 6947, 0, 6947, -21330], [0, 344071, 0, -4774, -1344, 0], [0, -811404, 0, -287, 9562, 0], [0, 895822, 0, 18938, 5399, 0], [106945, -106945, 5324, 0, 5324, -1948], [-3504207, 3504207, 3087, 0, 3087, -4989], [0, 1543294, 0, -14849, 9532, 0], [0, 3379011, 0, 10342, 1926, 0], [434142, 0, -1904, 32098, 0, -32098], [0, -906242, 0, -31272, -6315, 0], [-1063004, 1063004, -12514, 0, -12514, 48513], [-1171543, 0, 2880, 17359, 0, -17359], [-448326, 448326, -11447, 0, -11447, 23902], [0, -27288, 0, 36499, 19276, 0], [3496664, 0, -7202, -9620, 0, 9620], [-2897559, 2897559, -5482, 0, -5482, -24276], [-836597, 836597, -200, 0, -200, -12966], [2464278, -2464278, -15095, 0, -15095, 10586], [0, -1074518, 0, -20555, 15538, 0], [32178, 0, 15936, -39290, 0, 39290], [-252457, 0, -7776, 46719, 0, -46719], [0, -1352966, 0, -34352, 22121, 0], [0, -4536789, 0, 39413, 12109, 0], [1242873, 0, 23440, -64271, 0, 64271], [0, -1794389, 0, 21568, 518, 0], [0, 4255872, 0, -31687, -20218, 0], [402250, -402250, -16675, 0, -16675, 15240], [4543665, 0, 6918, -36955, 0, 36955], [0, -2879160, 0, -58718, 17459, 0], [-2319274, 0, -1688, -52110, 0, 52110], [-1189167, 1189167, 19757, 0, 19757, -87571], [1884961, -1884961, 15363, 0, 15363, 44253], [5123808, 0, -11390, 18082, 0, -18082], [-3580470, 3580470, 1154, 0, 1154, 112773], [-3384843, 0, 54646, 44531, 0, -44531], [3213020, 0, -2558, 85978, 0, -85978], [-4922896, 0, -16356, 13234, 0, -13234], [0, 1026697, 0, -68295, 2337, 0], [1120422, 0, -48226, -63414, 0, 63414], [2171841, -2171841, -33185, 0, -33185, -21037], [0, 11347785, 0, 15550, -8552, 0], [4676353, -4676353, -19383, 0, -19383, 78991], [-618379, 0, 25928, 151361, 0, -151361], [0, -556569, 0, -25979, 2785, 0], [-7919070, 0, 22150, 39506, 0, -39506], [6569166, -6569166, 31029, 0, 31029, 52006], [0, 524245, 0, -20530, -55850, 0], [4108066, -4108066, 31203, 0, 31203, 98146], [2731772, 0, -71066, -72104, 0, 72104], [-4614597, 4614597, -13198, 0, -13198, -100134], [0, 4994581, 0, -127367, 18077, 0], [-859648, 0, -25700, -82732, 0, 82732], [0, 3357537, 0, -74966, 14460, 0], [-4025195, 4025195, 34125, 0, 34125, -35169], [600498, 0, -35416, -75562, 0, 75562], [1513848, -1513848, -800, 0, -800, 158397], [0, 5758722, 0, 137858, -25851, 0], [-4889654, 4889654, 3724, 0, 3724, 120785], [0, -2822168, 0, -19947, -14240, 0], [0, -6814242, 0, 83537, 61680, 0], [-5662089, 0, -20666, -115169, 0, 115169], [0, -8311190, 0, -33060, -19239, 0], [-1535718, 0, 19850, 26962, 0, -26962], [0, -6313286, 0, -78445, -12220, 0], [2577924, 0, -8944, 33356, 0, -33356], [0, 5891188, 0, 165942, -35343, 0], [-10852532, 10852532, 61954, 0, 61954, 15029], [-3759847, 0, -91132, 148859, 0, -148859], [-7253796, 7253796, -63127, 0, -63127, -77432], [-14064770, 14064770, -47249, 0, -47249, -214110], [1408826, 0, 39640, 42484, 0, -42484], [-5427912, 5427912, 47456, 0, 47456, 212821], [-3521840, 3521840, 47150, 0, 47150, -115275], [-2533986, 0, 35978, 60854, 0, -60854], [4857490, -4857490, -24995, 0, -24995, 144512], [-8291010, 8291010, 20818, 0, 20818, 86489], [8984649, 0, -54136, -146319, 0, 146319], [6737951, 0, 59826, 81147, 0, -81147], [0, -3741012, 0, -229895, 67282, 0], [-10263578, 10263578, 21829, 0, 21829, 296860], [-5892108, 0, 18940, 250508, 0, -250508], [774422, 0, -31862, -126654, 0, 126654], [0, -4155342, 0, -94022, -55591, 0], [0, -8029832, 0, -406933, 22486, 0], [0, -6136548, 0, 318811, -32524, 0], [5614297, -5614297, -51723, 0, -51723, 371323], [4837872, 0, 124132, -280204, 0, 280204], [-2724194, 2724194, 56806, 0, 56806, -232293], [-10538526, 0, -37294, -248114, 0, 248114], [16805123, 0, -22790, 178551, 0, -178551], [5882490, -5882490, -102145, 0, -102145, -63936], [0, 1057003, 0, 139589, -2965, 0], [0, -4703298, 0, -57164, -4045, 0], [-23987806, 0, -45088, 19742, 0, -19742], [0, -23864136, 0, 196803, -12984, 0], [-9637546, 0, 2010, -421298, 0, 421298], [-2474250, 2474250, -189796, 0, -189796, 85031], [0, -21688125, 0, 378079, 119675, 0], [19670337, 0, 15320, 484409, 0, -484409], [17721064, -17721064, -107707, 0, -107707, -67178], [22723020, 0, -100278, -58182, 0, 58182], [-18440079, 18440079, 35952, 0, 35952, 568042], [0, 2838438, 0, 169256, -176865, 0], [-6169984, 0, -152076, 335604, 0, -335604], [0, 19079842, 0, -339881, -97240, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_54_c_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_54_6_c_b();".
// 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_54_6_c_b(:prec:=6)
    chi := MakeCharacter_54_c();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 6));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(997) - 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_54_6_c_b();".
// 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_54_6_c_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_54_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<5,R![46562734656, -1007927064, 33470577, -179334, 7587, -54, 1]>],Snew);
    return Vf;
end function;