
// Make newform 1050.4.a.d in Magma, downloaded from the LMFDB on 21 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_1050_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_1050_4_a_d();".
// 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_1050_4_a_d();".
// 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_1050_a();"
function MakeCharacter_1050_a()
    N := 1050;
    order := 1;
    char_gens := [701, 127, 451];
    v := [1, 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_1050_a_Hecke( : Kf := Kf)
    return MakeCharacter_1050_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], [-3], [0], [7], [-8], [42], [2], [-124], [-76], [254], [-72], [-398], [462], [-212], [264], [162], [-772], [30], [764], [-236], [-418], [552], [-1036], [30], [1190], [1370], [-464], [2136], [-1226], [-338], [-2088], [-292], [-818], [-2156], [-2850], [1672], [-446], [-2708], [-896], [-4034], [-3480], [-2898], [2652], [-146], [2546], [-2536], [-1300], [-2576], [1836], [-1874], [-3730], [2004], [-646], [1260], [-5910], [-2988], [-1318], [-5640], [-6446], [4930], [6260], [2310], [-196], [-6736], [-394], [6714], [692], [1566], [5328], [11326], [2130], [3044], [-12416], [7442], [100], [-8080], [-5482], [-10446], [-11334], [8594], [10500], [-12066], [4332], [1918], [-7992], [-3184], [11426], [16934], [-17038], [13592], [-8612], [7432], [6616], [17040], [-2948], [-17304], [4650], [16854], [124], [5382], [-17460], [9514], [-3988], [11346], [-8436], [-2098], [-9436], [1314], [-8940], [16058], [-3936], [-174], [-16018], [-3068], [24656], [7594], [3724], [-3792], [-24702], [-20144], [-2522], [10414], [22230], [-18192], [8108], [-5794], [-1954], [-32016], [23072], [-31782], [-24396], [32604], [-7680], [-366], [29374], [-38990], [20470], [-29916], [-4914], [34250], [-41804], [30862], [-10576], [10680], [-1178], [-5600], [826], [-45918], [42380], [26524], [-20614], [-23730], [9028], [-37200], [-23988], [15276], [-10760], [-52890], [6118], [-32230], [18544], [-25930], [-8192], [-54444], [25446], [-33192], [11024], [40714], [28226], [-48330], [44456], [61054], [-3900], [32166], [27984], [-11242], [7548], [-22730], [-16688], [-24946], [2136], [39676], [62690], [17386], [62140], [-27078], [-2022], [36052], [32346], [65280], [13718], [70824], [-28484], [-5150], [14736], [27386], [16610], [-24646], [77658], [-33840], [-58122], [17472], [36706], [76410], [-73164], [-35922], [9872], [52704], [25482], [30140], [75118], [-18046], [-8472], [23980], [-27792], [-74086], [-29056], [24526], [62084], [42530], [-7778], [-35840], [-42414], [95264], [-68796], [-56866], [49250], [106196], [-54336], [20208], [11754], [25828], [-14096], [-36870], [-52556], [-27312], [79018], [-56622], [38880], [46760], [-48712], [-75388], [2872], [39990], [28490], [-92160], [24360], [-12140], [1532], [9084], [125018], [-44658], [3564], [-120638], [56702], [19984], [3758], [-9420], [-14378], [94582], [22184], [-94376], [68878], [-34846], [107298], [109132], [27414], [-42490], [-75196], [-44022], [43710], [-69404], [-51378], [120224], [47894], [18912], [69560], [-45690], [90250], [-139452], [22752], [-83616], [40824], [-69034], [-9732], [95500], [-94674], [-17950], [26864], [-93450], [13110], [47028], [56190], [101948], [21418], [131346], [-114784], [-161154], [-13956], [67620], [-32650], [55266], [-41336], [-51648], [55628], [-73586], [-6656], [-137242], [-28652], [98050], [-113808], [125894], [-78310], [73396], [110164], [-11230], [20412], [-30556], [-21770], [60090], [107924], [149318], [8610], [-118288], [-14762], [118442], [-121276], [-135004], [-92476], [41690], [-56554], [45074], [-31416], [-201892], [52828], [44884], [-17610], [81226], [-36526], [488], [-141518], [-79746], [176274], [152952], [-80814], [63408], [29678], [-71924], [10080], [-96714], [-61276], [-23498], [-117738], [93312], [-70610], [136010], [-5920], [-172524], [-71602], [-173812], [51266], [-83522], [2836], [51400], [38180], [133750], [60438], [-145872], [-122246], [11416], [62764], [-208284], [65774], [-118736], [-40102], [-114900], [40084], [243854], [-96290], [-249074], [-116958], [202774], [-17320], [-126930], [158284], [-27032], [243536], [-104494], [178340], [66584], [-178078], [-64962], [80296], [86140], [92420], [-47802], [149056], [129766], [-53940], [121078], [143054], [-41922], [-67864], [-11678], [-71934], [-5752], [-157366], [-208542], [-39212], [201028], [48830], [252218], [-120304], [-251364], [-77786], [-56726], [119860], [-22048], [-271950], [293536], [167950], [-150278], [183524], [-178332], [203350], [-156098], [233752], [190290], [-315660], [191056]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1050_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1050_4_a_d();".
// 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_1050_4_a_d(:prec:=1)
    chi := MakeCharacter_1050_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_1050_4_a_d();".
// 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_1050_4_a_d( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1050_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<11,R![8, 1]>,<13,R![-42, 1]>],Snew);
    return Vf;
end function;