
// Make newform 336.6.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_6_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_6_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 := 6;
    raw_aps := [[0], [-9], [-64], [-49], [54], [738], [-848], [1604], [3670], [-4330], [4760], [-2094], [-6116], [-7916], [-6572], [-7894], [41664], [-26570], [41736], [-83574], [-42314], [-508], [8364], [-49220], [159670], [-67020], [-165768], [-103146], [60094], [-126246], [-308636], [61012], [-317242], [7236], [126058], [-200296], [510894], [-21184], [267180], [-91948], [402826], [-796222], [-474934], [716022], [-221814], [333616], [176404], [125016], [272104], [-325822], [-534682], [-1485122], [1176886], [-14080], [-1868508], [-802890], [-197448], [2019280], [1579930], [1443918], [1680460], [-2310924], [793964], [-1183764], [994970], [1846194], [1558012], [3287978], [-3661374], [-3768106], [1977936], [-3174102], [-3621632], [-3657370], [-1078020], [-3869544], [-3758450], [-1471058], [-5303130], [-6469842], [-554024], [-3378998], [-2903382], [-5056838], [2432568], [2358322], [798466], [-3533366], [-1987092], [-6331748], [-274560], [-933460], [6056000], [-1657566], [-4088044], [7430360], [-3512904], [4814064], [2426596], [4825426], [-1345432], [-938438], [-11612416], [-6948762], [-2594120], [-15161238], [1298264], [11500224], [-9998542], [8054050], [-4036672], [16052086], [13477038], [17379660], [-14690804], [16016590], [-8486236], [18548676], [-3012706], [6060598], [14289926], [-5296802], [11854956], [16562490], [4697476], [-21088970], [-16868282], [11960640], [2207224], [-384494], [-8042416], [1852906], [-11932640], [-5558858], [27159852], [-8756678], [-3968564], [21111236], [-29508540], [13002], [-26178996], [32120898], [24975844], [30922902], [-16904662], [-27778284], [-17750450], [15003996], [-910972], [-14883722], [-23995138], [7858792], [17458580], [700092], [-37297868], [29987258], [27831632], [18819100], [5396130], [39994152], [-30931378], [-15584822], [26013084], [8843156], [-27000954], [16989168], [-37792248], [-51692138], [-45195954], [11442820], [-21847186], [19163310], [-21970782], [34259158], [54499656], [11322680], [-66506048], [-43845330], [50776304], [54384142], [76040828], [-60803036], [28826938], [28080016], [30583254], [-53785428], [-7411594], [78623836], [-57383418], [28601448], [-64592794], [42013782], [42447868], [43340652], [64408934], [76233912], [-47744642], [-25512382], [-60277700], [38365460], [52026002], [7633128], [-102018166], [-18498026], [72750636], [-31529340], [-88463864], [58523118], [-51988438], [-33013372], [43023618], [-52815192], [-23992480], [2879172], [-102949604], [69200898], [81378312], [18076040], [123267750], [2547526], [-14740554], [5111240], [100933706], [55065552], [72433220], [108061346], [36197004], [89107774], [12107288], [41103210], [155291326], [-72928820], [-79244824], [4200490], [112078004], [-127443072], [2260406], [-91444014], [85435850], [-50826120], [-135422126], [2959804], [-110083376], [-24595694], [129355404], [122738396], [16062392], [-61986008], [82530936], [-99560714], [163772822], [29761808], [-71681182], [-132122394], [-84536924], [201330006], [129922490], [119653108], [-173316276], [-28004478], [-61555052], [32214834], [-110122254], [-55848602], [-93720840], [-55069868], [187503226], [-22116848], [-215699184], [-194362050], [-58481306], [49488668], [-216557338], [217122744], [77506158], [-224092952], [88066126], [11965714], [151327694], [-34915368], [130196184], [81164284], [2764752], [-162704058], [240263908], [94580778], [-157536942], [253859266], [-186113400], [-43781772], [156041058], [121066436], [262474910], [-117618952], [-40627378], [84488164], [-146241912], [178166552], [-65982144], [-43915604], [24748394], [219228438], [-57209364], [43649334], [-77516040], [-186156886], [138506970], [64149754], [-232086550], [-194637670], [-101949896], [-295602922], [-38083034], [303595700], [358155718], [-163948490], [-34576060], [141962078], [140615278], [-259913202], [51770788], [271798358], [-188584308], [148107416], [-208668478], [39551582], [-275745160], [-229574596], [182984418], [-51246066], [-96919818], [138237390], [357648848], [85545752], [-238229504], [10306000], [-107709170], [-308575292], [377062430], [-133544464], [249412614], [-114604050], [-368401560], [184730944], [-82158058], [-457066026], [-68946230], [-417756892], [-296171368], [87621428], [-527539556], [-745850], [-371194110], [348496248], [-349293978], [134796024], [-385088976], [-108151100], [-331826838], [402683394], [424599782], [110661012], [-427122534], [122534670], [338213460], [350849174], [203534928], [267504348], [-309151298], [-93855950], [-272851148], [198858642], [39345970], [-432045736], [226292850], [-366843148], [-16121298], [217055114], [677110736], [353642998], [231840556], [354804506], [40198160], [-561612726], [61819228], [-545282400], [355055056], [678581450], [-462040880], [-148612564], [368519822], [140048416], [83905542], [-15540612], [-5368822], [-488844142], [-65005624], [-729790664], [160626848], [-124113690], [43838598], [485623754], [51786372], [387450924], [-453283840], [386428696], [-51829150], [-314798174], [-445532100], [-538228824], [461127378], [-395289762], [-371599814], [498898412], [186578358], [294749904], [-621975754], [52599248], [694154616], [469574012], [867940230], [205616150], [213267450], [-472449924], [-821517510], [838850484], [-438822286], [-360482466], [-257553308], [751345916]];
    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_6_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_6_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, 6));
    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_6_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_6_a_c( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_336_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<5,R![64, 1]>,<11,R![-54, 1]>],Snew);
    return Vf;
end function;