
// Make newform 336.4.a.c in Magma, downloaded from the LMFDB on 02 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_336_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_336_4_a_c();".
// 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_336_4_a_c();".
// 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_336_a();"
function MakeCharacter_336_a()
    N := 336;
    order := 1;
    char_gens := [127, 85, 113, 241];
    v := [1, 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_336_a_Hecke( : Kf := Kf)
    return MakeCharacter_336_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 := [[0], [-3], [-2], [7], [-52], [86], [-30], [4], [-120], [246], [-80], [-290], [-374], [-164], [-464], [-162], [-180], [-666], [628], [-296], [-518], [1184], [-220], [-774], [-1086], [-290], [88], [-372], [1430], [1810], [-1168], [1268], [474], [2684], [-1314], [-3000], [774], [2292], [1672], [-2730], [-2572], [3214], [1520], [-62], [-1074], [-552], [-1692], [-528], [1876], [-5474], [3418], [-7360], [-2126], [7788], [-3470], [3096], [-3274], [-960], [910], [-6486], [-3796], [-6882], [-7228], [-7912], [2218], [8118], [10780], [3122], [828], [4614], [9458], [-2952], [10592], [6478], [-5780], [6912], [-9010], [10774], [-78], [-15254], [7316], [-11330], [6016], [-13550], [2760], [3036], [12962], [11866], [10998], [9088], [-18236], [11424], [8536], [18732], [21700], [1048], [-8890], [13962], [-16420], [-14554], [-588], [10726], [740], [17386], [-1108], [-13694], [2844], [9410], [14952], [2570], [8176], [8862], [-1126], [-9892], [-11256], [-5694], [-30028], [-18680], [-3034], [-26508], [-24658], [23266], [5694], [14796], [-4540], [-18666], [10974], [-28240], [-6232], [21638], [-24364], [-3112], [20576], [-4754], [-10950], [-28798], [-12866], [13156], [20454], [15706], [-6532], [-46754], [-22008], [-45412], [13670], [26568], [1070], [42906], [-11252], [-29264], [25782], [-9054], [-8092], [-11944], [31804], [-27840], [-12536], [-25870], [-6086], [3894], [20692], [46986], [-53960], [7068], [54130], [23064], [10768], [12766], [-4846], [19950], [-26916], [-46298], [-44232], [24986], [-52096], [4506], [25292], [62510], [-59304], [63734], [1424], [-3756], [-19042], [-39318], [-2272], [45774], [-27930], [-22636], [-41990], [-9280], [-52894], [-34004], [7652], [6822], [45636], [-10038], [-30574], [35718], [-51086], [4968], [-40954], [-15968], [-28050], [-2238], [77372], [-37018], [-68208], [-48892], [28890], [7740], [38450], [78510], [7720], [79884], [58152], [-24070], [59232], [49890], [46056], [-64234], [-8962], [-41560], [-56350], [-98208], [-24284], [-38226], [-3654], [-32176], [-48040], [58540], [854], [-56988], [6736], [26522], [-4228], [-5200], [93458], [-36770], [18684], [-7672], [-15916], [-20372], [-20168], [67862], [26850], [-15144], [53872], [-37580], [73244], [65280], [-72890], [65298], [114520], [-76294], [-119274], [-60684], [-93938], [-72596], [47326], [-94614], [28592], [17604], [-50690], [37574], [-3694], [120404], [-74906], [80890], [138636], [105358], [-23018], [96804], [103082], [31376], [25842], [-49880], [-9604], [-70874], [23386], [-130524], [-83712], [-92968], [-91112], [34814], [-45732], [20480], [-52942], [116318], [42088], [-133294], [23718], [98532], [-15862], [-38052], [-84266], [16934], [-50512], [39726], [-99412], [112660], [-53478], [80486], [-134048], [-148428], [-122708], [-21470], [-94004], [-152330], [-59448], [116030], [-47856], [-143074], [38626], [-2284], [103416], [-169574], [-178460], [-75984], [81058], [138898], [-11804], [-5942], [-174970], [-49456], [100826], [6130], [160468], [9868], [-22128], [14830], [-66922], [-188938], [13232], [-140716], [67772], [34636], [72390], [-100782], [-129638], [-52448], [-16882], [-99222], [-56418], [-84520], [-46090], [-141980], [55390], [82812], [-49264], [-94066], [-99852], [-193062], [108902], [176736], [84782], [-65446], [-44960], [220764], [163890], [207592], [26814], [-79670], [-82304], [207836], [55124], [79674], [46806], [-74728], [153546], [27204], [-180260], [-31136], [-290], [-154424], [-111994], [8676], [-176400], [-81630], [199554], [97354], [151110], [-3654], [-96696], [-246174], [-20940], [-9624], [-128800], [52878], [28460], [-221504], [60866], [152254], [-40980], [169540], [-126008], [192138], [81520], [43178], [227900], [-35810], [-133850], [261858], [-31488], [128282], [143230], [-40168], [72726], [269874], [230276], [181428], [103538], [-186306], [74364], [25812], [-215302], [-162218], [-189488], [-186472], [-223326], [14040], [148950], [-56738], [158880], [171148], [-59430], [-80426], [-3148], [-151254], [266028], [-209160]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_336_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_336_4_a_c();".
// 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_336_4_a_c(:prec:=1)
    chi := MakeCharacter_336_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_336_4_a_c();".
// 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_336_4_a_c( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_336_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<5,R![2, 1]>,<11,R![52, 1]>],Snew);
    return Vf;
end function;