
// Make newform 350.5.d.a in Magma, downloaded from the LMFDB on 04 June 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_350_d();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_350_d_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_350_5_d_a();".
// 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_350_5_d_a();".
// 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 := [408321, 0, 38340, 0, 1800, 0, -60, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0, 0], [-191700, 0, -24390, 0, 813, 0, -10, 0], [130680, 0, -1278, 0, -60, 0, 2, 0], [0, 15128964, 0, 371700, 0, -12390, 0, 242], [0, -2856330, 0, -999018, 0, 26016, 0, -320], [-38340, 0, -4878, 0, 120, 0, -2, 0], [0, -41414868, 0, -891684, 0, 44292, 0, -724], [0, -7123572, 0, -2741436, 0, 76812, 0, -1124]];
    Rf_basisdens := [1, 327807, 50787, 3605877, 3605877, 21087, 3605877, 3605877];
    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_350_d();"
function MakeCharacter_350_d()
    N := 350;
    order := 2;
    char_gens := [127, 101];
    v := [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_350_d_Hecke();"
function MakeCharacter_350_d_Hecke(Kf)
    N := 350;
    order := 2;
    char_gens := [127, 101];
    char_values := [[-1, 0, 0, 0, 0, 0, 0, 0], [-1, 0, 0, 0, 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]];
    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 := 5;
    raw_aps := [[0, 0, 0, 0, 0, 1, 0, 0], [0, 0, 0, 0, -1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 19, 0, 0, -1, -9, 0, -1], [90, 0, 36, 0, 0, 0, 0, 0], [0, 0, 0, 0, -1, 0, 0, -1], [0, 0, 0, 0, 20, 0, 0, -2], [0, 0, 0, -19, 0, 0, 10, 0], [0, -198, 0, 0, 0, -96, 0, 0], [-306, 0, 228, 0, 0, 0, 0, 0], [0, 0, 0, 72, 0, 0, 18, 0], [0, 974, 0, 0, 0, -108, 0, 0], [0, 0, 0, 110, 0, 0, 2, 0], [0, 922, 0, 0, 0, 360, 0, 0], [0, 0, 0, 0, -124, 0, 0, -38], [0, 1458, 0, 0, 0, -1032, 0, 0], [0, 0, 0, -5, 0, 0, -50, 0], [0, 0, 0, -221, 0, 0, -85, 0], [0, 262, 0, 0, 0, 288, 0, 0], [-5382, 0, 1098, 0, 0, 0, 0, 0], [0, 0, 0, 0, -266, 0, 0, -104], [-3194, 0, -1350, 0, 0, 0, 0, 0], [0, 0, 0, 0, -397, 0, 0, 100], [0, 0, 0, 270, 0, 0, 36, 0], [0, 0, 0, 0, -344, 0, 0, 286], [0, 0, 0, 969, 0, 0, 87, 0], [0, 0, 0, 0, -518, 0, 0, 292], [0, 2502, 0, 0, 0, 3408, 0, 0], [3374, 0, -3600, 0, 0, 0, 0, 0], [0, -1998, 0, 0, 0, -978, 0, 0], [0, 13510, 0, 0, 0, 5112, 0, 0], [0, 0, 0, -705, 0, 0, 420, 0], [0, 1854, 0, 0, 0, 816, 0, 0], [0, 0, 0, -217, 0, 0, 658, 0], [-5778, 0, 4368, 0, 0, 0, 0, 0], [-7046, 0, -5616, 0, 0, 0, 0, 0], [0, 0, 0, 0, -555, 0, 0, -843], [0, 5114, 0, 0, 0, 12636, 0, 0], [0, 0, 0, 0, -970, 0, 0, 1312], [0, 0, 0, 0, 2007, 0, 0, 171], [-26586, 0, 1356, 0, 0, 0, 0, 0], [0, 0, 0, -4027, 0, 0, 121, 0], [-51174, 0, 126, 0, 0, 0, 0, 0], [0, -12398, 0, 0, 0, 3942, 0, 0], [0, -59058, 0, 0, 0, -1908, 0, 0], [0, 0, 0, -2066, 0, 0, -796, 0], [-4166, 0, -21528, 0, 0, 0, 0, 0], [0, 0, 0, 0, -1608, 0, 0, 1416], [0, 0, 0, 0, -2055, 0, 0, -726], [0, 0, 0, 4599, 0, 0, -639, 0], [0, 8514, 0, 0, 0, -17760, 0, 0], [-22266, 0, 9264, 0, 0, 0, 0, 0], [0, 0, 0, -4364, 0, 0, 422, 0], [0, 0, 0, -2171, 0, 0, 1240, 0], [0, 0, 0, 0, 768, 0, 0, -2100], [0, -38214, 0, 0, 0, -174, 0, 0], [0, 0, 0, 1057, 0, 0, -2057, 0], [0, 0, 0, 8180, 0, 0, -44, 0], [0, 38254, 0, 0, 0, -26316, 0, 0], [73890, 0, 8928, 0, 0, 0, 0, 0], [0, 0, 0, 0, -531, 0, 0, 72], [0, 0, 0, 0, -5671, 0, 0, 1441], [0, 0, 0, 0, 885, 0, 0, -2076], [0, 0, 0, 3070, 0, 0, 1486, 0], [0, 0, 0, 0, 2858, 0, 0, 14], [0, 63342, 0, 0, 0, 21996, 0, 0], [-65798, 0, 25164, 0, 0, 0, 0, 0], [0, 74318, 0, 0, 0, -27054, 0, 0], [0, -117594, 0, 0, 0, -36984, 0, 0], [0, 0, 0, -4123, 0, 0, -4319, 0], [0, 0, 0, 0, -248, 0, 0, 1832], [-44730, 0, -17952, 0, 0, 0, 0, 0], [0, 0, 0, 0, -6284, 0, 0, 4516], [0, 180626, 0, 0, 0, -17820, 0, 0], [-141946, 0, -17820, 0, 0, 0, 0, 0], [0, 0, 0, 0, -256, 0, 0, -2750], [-67698, 0, -43620, 0, 0, 0, 0, 0], [0, 0, 0, 0, -16575, 0, 0, 255], [-119214, 0, 28014, 0, 0, 0, 0, 0], [0, 0, 0, 15278, 0, 0, 3154, 0], [0, 0, 0, -18247, 0, 0, 572, 0], [41618, 0, -44568, 0, 0, 0, 0, 0], [-38790, 0, -31368, 0, 0, 0, 0, 0], [0, 0, 0, 0, -18492, 0, 0, 30], [0, 0, 0, 18498, 0, 0, -1938, 0], [0, -191430, 0, 0, 0, 36900, 0, 0], [116190, 0, -8856, 0, 0, 0, 0, 0], [0, 235214, 0, 0, 0, 62478, 0, 0], [0, 0, 0, 2831, 0, 0, 5387, 0], [0, 191642, 0, 0, 0, 19062, 0, 0], [0, 0, 0, 0, 12093, 0, 0, -3354], [0, 0, 0, 1000, 0, 0, 11062, 0], [0, 307526, 0, 0, 0, -47376, 0, 0], [99738, 0, -42336, 0, 0, 0, 0, 0], [52742, 0, 132804, 0, 0, 0, 0, 0], [0, 0, 0, 0, 2702, 0, 0, 70], [0, 0, 0, 7501, 0, 0, -1175, 0], [0, 0, 0, 10550, 0, 0, 866, 0], [0, 0, 0, 0, 8153, 0, 0, -11638], [285554, 0, 4536, 0, 0, 0, 0, 0], [0, 66502, 0, 0, 0, -151308, 0, 0], [0, -23634, 0, 0, 0, -31392, 0, 0], [0, 0, 0, 0, 38619, 0, 0, -1350], [-132210, 0, -93714, 0, 0, 0, 0, 0], [118490, 0, -65664, 0, 0, 0, 0, 0], [0, 0, 0, 0, -6832, 0, 0, 4220], [0, 0, 0, 0, 37527, 0, 0, -3822], [0, 0, 0, 0, 1676, 0, 0, 6532], [75942, 0, -72642, 0, 0, 0, 0, 0], [0, 0, 0, -26478, 0, 0, 1152, 0], [0, 0, 0, 0, -18776, 0, 0, -5096], [0, 277970, 0, 0, 0, 47448, 0, 0], [0, -4050, 0, 0, 0, 94302, 0, 0], [0, 0, 0, 18943, 0, 0, -3724, 0], [-239974, 0, -59670, 0, 0, 0, 0, 0], [-28206, 0, -176730, 0, 0, 0, 0, 0], [0, 0, 0, 0, -25137, 0, 0, -126], [0, 0, 0, 0, -52290, 0, 0, 1980], [0, -329742, 0, 0, 0, -24, 0, 0], [-93978, 0, 219456, 0, 0, 0, 0, 0], [0, 0, 0, -5971, 0, 0, 1903, 0], [0, 472066, 0, 0, 0, 52344, 0, 0], [0, 0, 0, 0, 18951, 0, 0, 10749], [0, 60858, 0, 0, 0, 44088, 0, 0], [0, 0, 0, -3381, 0, 0, 14100, 0], [156978, 0, 127464, 0, 0, 0, 0, 0], [-138610, 0, 46872, 0, 0, 0, 0, 0], [0, 0, 0, -9188, 0, 0, 17614, 0], [0, 0, 0, 0, -102, 0, 0, 10356], [0, 0, 0, 0, -2277, 0, 0, 4833], [-370298, 0, 129276, 0, 0, 0, 0, 0], [0, -102726, 0, 0, 0, 213168, 0, 0], [140986, 0, 284112, 0, 0, 0, 0, 0], [0, 641198, 0, 0, 0, 4536, 0, 0], [0, 0, 0, 20090, 0, 0, -10834, 0], [0, 0, 0, 40208, 0, 0, 11326, 0], [0, 0, 0, 0, -7103, 0, 0, -19681], [0, 0, 0, 0, -24179, 0, 0, -24026], [0, 0, 0, 0, -17931, 0, 0, 28857], [554958, 0, 48702, 0, 0, 0, 0, 0], [0, 0, 0, 55857, 0, 0, 9096, 0], [-111726, 0, 80652, 0, 0, 0, 0, 0], [0, 106106, 0, 0, 0, 188946, 0, 0], [0, 399654, 0, 0, 0, -85332, 0, 0], [0, 0, 0, 21949, 0, 0, -11203, 0], [0, 0, 0, 14606, 0, 0, 22508, 0], [0, 0, 0, 0, 1565, 0, 0, 22481], [0, 0, 0, 0, 13214, 0, 0, -19694], [0, 0, 0, -68573, 0, 0, -10312, 0], [0, 570906, 0, 0, 0, 211614, 0, 0], [0, 179374, 0, 0, 0, -129708, 0, 0], [0, 0, 0, -30012, 0, 0, -5604, 0], [0, 100762, 0, 0, 0, -405648, 0, 0], [0, 0, 0, 0, 41042, 0, 0, 21724], [0, -558586, 0, 0, 0, -221076, 0, 0], [-994374, 0, -110640, 0, 0, 0, 0, 0], [-678970, 0, -7002, 0, 0, 0, 0, 0], [0, 0, 0, -61480, 0, 0, 17126, 0], [0, 0, 0, 0, -69598, 0, 0, 10412], [0, 0, 0, 89303, 0, 0, -13711, 0], [0, -529434, 0, 0, 0, -245784, 0, 0], [0, 34722, 0, 0, 0, -418320, 0, 0], [0, 603334, 0, 0, 0, 46080, 0, 0], [0, 0, 0, -5527, 0, 0, -23878, 0], [0, -162018, 0, 0, 0, -238656, 0, 0], [0, 0, 0, 0, 55238, 0, 0, -1580], [294586, 0, -71442, 0, 0, 0, 0, 0], [0, 0, 0, 0, 28695, 0, 0, -20355]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_350_d_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_350_5_d_a();".
// 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_350_5_d_a(:prec:=8)
    chi := MakeCharacter_350_d();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 5));
    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_350_5_d_a();".
// 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_350_5_d_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_350_d();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,5,sign)));
    Vf := Kernel([<3,R![20448, 0, -288, 0, 1]>],Snew);
    return Vf;
end function;