
// Make newform 350.4.a.h in Magma, downloaded from the LMFDB on 17 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_350_a();"
// 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_4_a_h();".
// 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_4_a_h();".
// 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
        Kf := Rationals();
    end if;
    return [Kf!elt[1] : elt in input];
end function;


// To make the character of type GrpDrchElt, type "MakeCharacter_350_a();"
function MakeCharacter_350_a()
    N := 350;
    order := 1;
    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;

function MakeCharacter_350_a_Hecke( : Kf := Kf)
    return MakeCharacter_350_a();
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 := 4;
    raw_aps := [[-2], [4], [0], [7], [5], [-82], [12], [-42], [-175], [1], [226], [19], [16], [-281], [-334], [398], [106], [48], [-483], [-15], [-1044], [-1253], [-758], [86], [-710], [0], [838], [2164], [-1827], [93], [1433], [868], [2646], [896], [2523], [2433], [2572], [-2488], [-3054], [3894], [-1108], [-1920], [-936], [-3163], [349], [0], [1676], [-1176], [-2234], [4274], [5427], [3516], [-3890], [2512], [-6934], [-5505], [-8698], [2054], [-8450], [4469], [794], [6462], [-56], [10656], [2010], [-3903], [-3277], [-6462], [3787], [7398], [9654], [-7691], [6836], [-12123], [10811], [12778], [-383], [-12050], [-7523], [-4534], [8494], [-8765], [-6696], [4148], [6182], [-616], [-8653], [7785], [-14718], [-2864], [1878], [-9914], [12883], [-16567], [2044], [14610], [18074], [-13554], [-11984], [3863], [-19579], [7437], [5690], [-24771], [-8633], [-1666], [7536], [-3568], [-24901], [-23744], [22894], [7811], [-11833], [-4186], [12079], [4017], [-13508], [1346], [10274], [-13116], [23070], [-24922], [-14294], [4979], [6744], [-17682], [-3514], [-34132], [-22112], [22180], [-16279], [-29068], [20], [-22961], [2832], [-20204], [27882], [-36304], [21096], [15879], [33402], [10506], [-1035], [-30137], [35464], [-1492], [-19288], [-2656], [3786], [45503], [32626], [-25754], [9165], [-1472], [-22412], [15163], [-6501], [1464], [14064], [-39114], [15068], [-27847], [33704], [-30006], [-14457], [43742], [-8201], [-4274], [-49021], [-59568], [-9021], [38386], [-41905], [-5722], [3344], [-13300], [-42361], [37330], [39922], [-42398], [-6069], [-19360], [-8001], [41818], [-3711], [1314], [-21403], [74022], [74425], [61368], [-20214], [21585], [6965], [-39290], [-67889], [-2432], [-91], [31163], [-53822], [9518], [75650], [-52198], [-46370], [-34316], [-27068], [-46512], [-45950], [60100], [-80505], [21332], [12947], [-3248], [9499], [-30336], [42464], [17752], [-92161], [44082], [-36543], [-35125], [29273], [-45820], [-57773], [-61727], [79590], [-10586], [-104804], [-49009], [29752], [-33403], [31675], [66022], [38932], [2779], [63262], [-99970], [-66232], [3525], [67517], [-13480], [99069], [56102], [-48454], [25979], [-77874], [70572], [47078], [-18934], [-88140], [-89880], [-5446], [71496], [45216], [-3296], [103134], [-66940], [30809], [60920], [76570], [-53498], [73224], [7191], [26498], [44958], [54476], [17440], [88251], [-122336], [78223], [85787], [-8756], [46092], [-99728], [-82437], [91560], [51432], [-35841], [-61990], [-68149], [-106608], [728], [52760], [28134], [30688], [-3500], [28893], [52021], [-54279], [-99524], [-122138], [66667], [-32586], [-5793], [105740], [118361], [81096], [92236], [33210], [109200], [-36174], [-6688], [119154], [-11569], [45471], [165655], [-109010], [-57919], [127118], [10335], [-150866], [-149868], [-38830], [-88143], [-76924], [-19935], [122180], [91690], [-50292], [-44332], [-28555], [109740], [104950], [123918], [115673], [-127203], [133226], [152103], [130082], [-182991], [-66897], [-104010], [115319], [-145182], [4572], [-86388], [142366], [-25967], [-38706], [76918], [153260], [163534], [43671], [-55668], [-188129], [-168425], [20097], [77740], [80695], [89886], [-174308], [-139076], [-28715], [-151566], [-139754], [151971], [170394], [215526], [54492], [159186], [221644], [-61391], [470], [-132816], [-104575], [50634], [27830], [-71602], [-110673], [-89517], [196641], [249294], [36525], [-159030], [50870], [226981], [-95952], [-55583], [-14400], [20182], [-138224], [-101724], [45813], [-9003], [223941], [-220424], [-14868], [49913], [-61986], [-54245], [260576], [-767], [-122154], [141765], [63590], [250889], [-135637], [24292], [107682], [-47784], [140421], [-151490], [95181], [35409], [223254], [-16650], [-47658], [128849], [-8370], [-265032], [78726], [-217902], [-134861], [-266100], [-104581], [-178149], [72142], [96424], [-45072], [-124852], [171170], [-266438], [-243608], [137688], [167904], [-190846], [-71752], [-7853], [1794], [105208], [-173766]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_350_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_350_4_a_h();".
// 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_4_a_h(:prec:=1)
    chi := MakeCharacter_350_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 4));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(2999) - 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_4_a_h();".
// 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_4_a_h( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_350_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<3,R![-4, 1]>,<11,R![-5, 1]>],Snew);
    return Vf;
end function;