
// Make newform 1008.6.a.a in Magma, downloaded from the LMFDB on 08 December 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_1008_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_1008_6_a_a();".
// 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_1008_6_a_a();".
// 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_1008_a();"
function MakeCharacter_1008_a()
    N := 1008;
    order := 1;
    char_gens := [127, 757, 785, 577];
    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_1008_a_Hecke( : Kf := Kf)
    return MakeCharacter_1008_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], [0], [-94], [49], [52], [-770], [2022], [-1732], [-576], [-5518], [-6336], [-7338], [3262], [-5420], [864], [-4182], [-11220], [-45602], [-1396], [18720], [46362], [-97424], [-81228], [3182], [4914], [166354], [-157160], [-6764], [178398], [45134], [205056], [72964], [94182], [47796], [124266], [446296], [-159746], [-247252], [-684488], [610474], [662252], [154630], [486904], [620546], [236570], [-82104], [-99892], [186704], [336372], [-926314], [-1257114], [-347016], [99170], [344428], [-295130], [-1272464], [-276774], [1289936], [1716550], [1472182], [-1028812], [1186066], [-1518916], [212808], [-1894], [1578978], [3394708], [2027314], [3488852], [965566], [-1153930], [1611104], [-3677472], [649766], [-320700], [-2361888], [3533898], [4048110], [-2076450], [2574314], [848148], [1436822], [2354376], [-3788078], [3643224], [2483892], [2631774], [-1161302], [-2813846], [-6842992], [3343140], [-4282480], [8931752], [2753060], [-4804084], [-6024648], [8429866], [-9250578], [-5844940], [9225326], [6443372], [-3742126], [-14638364], [-14180458], [1251604], [5943778], [-6461924], [2346054], [-13495920], [3878490], [533488], [5146102], [2378598], [-16002316], [-12345944], [3437550], [16219084], [11992856], [-1580094], [6983580], [3696022], [1846882], [7685010], [7121796], [3237868], [7391634], [-5333610], [-11456400], [24953992], [-14339826], [-922932], [-9389952], [408032], [25960454], [-18355410], [-747166], [-20269166], [4699820], [-584710], [16401270], [304948], [-34342838], [-15668376], [-29688636], [-23070802], [23264248], [19151510], [5346830], [-39585836], [-25028376], [-5025890], [26049030], [6824620], [23383496], [-39595916], [-4675704], [4925944], [32368774], [-33233718], [26642650], [31466300], [13451590], [28496312], [18185772], [-32094114], [15615384], [-48449936], [-45433562], [27942322], [22964386], [-56749116], [-16277730], [-16590240], [54820874], [14327200], [47349022], [61224980], [20059946], [45433752], [-48632882], [-73161632], [595812], [20690294], [4219534], [-14686536], [-71002142], [-78847346], [-28774852], [-9723926], [-43221632], [10921522], [13709460], [51536620], [-5115750], [-14039540], [83906766], [16504946], [-67741746], [-89342778], [84698232], [-55297742], [-104890016], [81895110], [98525554], [43325324], [73931962], [-55327632], [69484140], [75952182], [67789028], [67691538], [49409010], [26260568], [3352828], [105784568], [-23146358], [78353440], [103746950], [-61017728], [87769554], [-21715402], [-70593208], [113379646], [-113958752], [96150740], [1464710], [-19097746], [64260584], [116110264], [102073956], [21915358], [-113415268], [123568240], [87146966], [-8072316], [-65382288], [13681762], [80708938], [148757940], [-82240984], [59339724], [-165847356], [84213576], [109099198], [46816182], [146636584], [25035584], [101745428], [-68764], [181562712], [-47022610], [-123563562], [-85654496], [-86753702], [-117695446], [89179676], [77995718], [102047028], [71165682], [143574938], [19304800], [-124950628], [-138778954], [-133983682], [-72769418], [58924156], [127326162], [96444446], [-56454316], [-292918], [-18261170], [-12908948], [-68738774], [-209197616], [-57274238], [-108044408], [101707492], [-7482066], [6469930], [-86004412], [-11928832], [238567704], [29165528], [-6740090], [-139803212], [79793544], [34497298], [-252171222], [244940968], [-238780794], [-117687790], [-109876556], [-162885546], [-215178852], [246781726], [-10296070], [258430064], [-215158286], [-35371060], [-7670180], [139650570], [310024962], [170154800], [-208434308], [259443732], [-122312958], [-319681884], [-197703618], [34712368], [-329829866], [-291424368], [-186498854], [352112238], [-56473476], [-11572720], [-98238790], [-5949804], [105628008], [-47499662], [28947966], [-63345668], [197054842], [-366704646], [-43847120], [285246966], [-45542270], [-200754580], [-59785484], [-145393768], [98780106], [-258658850], [-284942766], [357475552], [-5737836], [-47339260], [39210892], [-23479090], [172274694], [257474714], [225813872], [306389926], [446806582], [162030498], [225473288], [272491858], [3104236], [-340255082], [500712116], [-31237584], [181558402], [-397108372], [68987754], [-161377582], [-253450464], [-56846330], [-253190882], [-409561632], [292466028], [-37741394], [472286544], [419981046], [208942430], [-485735352], [236894852], [-258780068], [48516298], [207739546], [247341560], [-331913286], [-317148612], [-371001564], [-69516792], [-117288054], [-64297976], [63930382], [146129908], [252015304], [-136308094], [-644736186], [-331918902], [171154234], [-335738538], [-320900008], [-32422274], [-266441700], [507816296], [-484798016], [-69143738], [419376820], [416134320], [179734690], [532998498], [615980340], [114827836], [-505581232], [-468483110], [87762800], [-563346], [178129572], [326846202], [348578366], [-317897186], [-73082896], [-370356402], [449860578], [-709090840], [448542846], [771276238], [-71188244], [-538299276], [-93454], [105168058], [-409778668], [-251140132], [-599939478], [-420339174], [833880360], [237879928], [-680356026], [280393704], [-721978638], [-329637242], [-154174648], [359289308], [-771383158], [510198954], [-243807188], [505199574], [-693230364], [-131655768]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1008_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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