
// Make newform 350.6.c.i in Magma, downloaded from the LMFDB on 09 June 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_350_c();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_350_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_350_6_c_i();".
// 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_6_c_i();".
// 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 := [400, 0, -39, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, -19, 0, 1], [0, 59, 0, -1], [-78, 0, 4, 0]];
    Rf_basisdens := [1, 20, 10, 1];
    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_c();"
function MakeCharacter_350_c()
    N := 350;
    order := 2;
    char_gens := [127, 101];
    v := [1, 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_350_c_Hecke();"
function MakeCharacter_350_c_Hecke(Kf)
    N := 350;
    order := 2;
    char_gens := [127, 101];
    char_values := [[-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 := 6;
    raw_aps := [[0, -4, 0, 0], [0, -10, 0, 1], [0, 0, 0, 0], [0, -49, 0, 0], [-535, 0, -3, 0], [0, -368, 0, 29], [0, -952, 0, 50], [-414, 0, 114, 0], [0, -827, 0, -37], [1123, 0, 32, 0], [144, 0, -427, 0], [0, 4493, 0, -390], [5614, 0, -297, 0], [0, -1701, 0, 767], [0, 7786, 0, -108], [0, 8094, 0, 952], [46464, 0, 331, 0], [7586, 0, 521, 0], [0, 39483, 0, 1665], [-10411, 0, 2303, 0], [0, -36442, 0, -547], [36053, 0, -1923, 0], [0, 23700, 0, 4631], [4960, 0, 1875, 0], [0, -13396, 0, 5859], [45006, 0, 3951, 0], [0, -45162, 0, 3038], [0, 129448, 0, 110], [-16017, 0, 7392, 0], [0, -13415, 0, -5714], [0, 147355, 0, 3273], [243316, 0, -3084, 0], [0, -32418, 0, -474], [191886, 0, -10381, 0], [-134631, 0, -8064, 0], [-173315, 0, 15427, 0], [0, 133014, 0, 3889], [0, 74988, 0, -10982], [0, 103860, 0, -26547], [0, -179414, 0, 12910], [-167344, 0, 30034, 0], [-207958, 0, 25085, 0], [-12732, 0, 10854, 0], [0, 253533, 0, 23488], [0, 177471, 0, 14332], [-222862, 0, -38803, 0], [57132, 0, -58580, 0], [0, 850846, 0, -27425], [0, -827070, 0, 13498], [-802998, 0, -22942, 0], [0, -620445, 0, 44076], [-329704, 0, -53266, 0], [-834494, 0, 18426, 0], [-1562404, 0, -9314, 0], [0, -230876, 0, 18879], [0, 345295, 0, 57151], [164288, 0, 10327, 0], [-370388, 0, 87365, 0], [0, 222250, 0, -47872], [1283397, 0, 12880, 0], [0, -1734294, 0, 31270], [0, 962276, 0, -81745], [0, -1554372, 0, -41870], [193812, 0, -101910, 0], [0, 415838, 0, -13582], [0, -1483517, 0, -101060], [-167469, 0, 4801, 0], [0, 548150, 0, 72968], [0, -1726699, 0, -53673], [-2734154, 0, -41126, 0], [0, 434748, 0, -37797], [2778323, 0, -81273, 0], [0, 2617978, 0, 106695], [0, -447055, 0, -189244], [486029, 0, 23071, 0], [0, 1500008, 0, 733], [1488167, 0, 218058, 0], [0, 959010, 0, 106348], [1154925, 0, 93212, 0], [-3113710, 0, -36650, 0], [1474084, 0, -14149, 0], [118851, 0, 275606, 0], [-3867612, 0, -38466, 0], [0, 1139400, 0, -275294], [280812, 0, -273337, 0], [0, -2566620, 0, -85994], [6631625, 0, -42650, 0], [0, 3792695, 0, 90728], [-4720040, 0, 151327, 0], [0, -236036, 0, -110838], [0, 5333462, 0, 220316], [6225316, 0, 141299, 0], [0, 386777, 0, -345669], [5192305, 0, -290893, 0], [4691344, 0, 188486, 0], [0, 2376006, 0, 193980], [-4349936, 0, 163881, 0], [-5709802, 0, -134476, 0], [0, 2193804, 0, -102298], [-10327805, 0, 99092, 0], [0, 757619, 0, 292069], [0, -1939853, 0, -87134], [0, -1008598, 0, -205266], [2621991, 0, 134634, 0], [-1271761, 0, -407147, 0], [0, -11236862, 0, -189600], [0, 4012346, 0, -446383], [0, -4814156, 0, 159122], [5760053, 0, 358657, 0], [3937760, 0, 597352, 0], [0, 2004396, 0, 158347], [0, -3897533, 0, -498406], [0, 1601665, 0, -42552], [4377784, 0, 678801, 0], [-15084333, 0, 82985, 0], [2511701, 0, -73594, 0], [0, -1110552, 0, 804698], [0, -6011598, 0, 359696], [0, -11631850, 0, -104934], [-12672952, 0, 140102, 0], [994286, 0, -48004, 0], [0, -4543138, 0, 701904], [0, -11504246, 0, -331546], [0, -1208341, 0, 905277], [-10394926, 0, -61207, 0], [17518846, 0, 174436, 0], [1141374, 0, -500254, 0], [-4824370, 0, -1077875, 0], [0, 5566792, 0, 280676], [0, -657612, 0, 1158128], [1473255, 0, 698105, 0], [0, 20801800, 0, -191314], [-17217112, 0, -281766, 0], [0, -4260843, 0, 139156], [16540344, 0, 205548, 0], [-14422834, 0, -182391, 0], [0, -5411436, 0, -151983], [0, 7737382, 0, 839151], [0, 4142004, 0, 1409934], [19275477, 0, 626178, 0], [-18351962, 0, 89284, 0], [20061318, 0, -881346, 0], [0, -19408055, 0, -365369], [0, -829599, 0, -67253], [-20412228, 0, 235738, 0], [21435198, 0, 303197, 0], [0, -21932292, 0, -699182], [0, -3718786, 0, 272239], [-33894762, 0, 191562, 0], [0, 5773179, 0, -472403], [0, 16157270, 0, -590292], [23915068, 0, -99021, 0], [0, 15555657, 0, 333189], [0, 8330022, 0, 807511], [0, 28072172, 0, 664116], [20805719, 0, -463427, 0], [22145597, 0, -1010527, 0], [-30993946, 0, -874129, 0], [0, 36628606, 0, -544193], [2797148, 0, -541801, 0], [0, -9462020, 0, 1490928], [0, -2831063, 0, 445544], [0, 7299112, 0, 1299216], [31970838, 0, 118284, 0], [0, 3571665, 0, -273312], [0, -1684528, 0, -2582901], [7316791, 0, 844491, 0], [0, 26405390, 0, 1220418]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_350_c_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_350_6_c_i();".
// 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_6_c_i(:prec:=4)
    chi := MakeCharacter_350_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_350_6_c_i();".
// 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_6_c_i( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_350_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<3,R![46656, 0, 832, 0, 1]>,<11,R![283381, 1070, 1]>],Snew);
    return Vf;
end function;