
// Make newform 280.6.a.b in Magma, downloaded from the LMFDB on 16 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_280_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_280_6_a_b();".
// 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_280_6_a_b();".
// 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_280_a();"
function MakeCharacter_280_a()
    N := 280;
    order := 1;
    char_gens := [71, 141, 57, 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_280_a_Hecke(Kf)
    return MakeCharacter_280_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+1)]];
    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], [4], [25], [-49], [124], [766], [-1102], [-764], [168], [-6866], [-4096], [-4682], [13130], [18220], [-7104], [-20026], [-38964], [-56274], [-24060], [-31896], [-23670], [37744], [-68204], [-19078], [-115646], [100790], [13304], [128204], [-176450], [-166734], [228112], [131796], [-187862], [-106404], [-177466], [117048], [-31986], [37060], [185880], [464990], [835300], [-498682], [295168], [77506], [310486], [639080], [985636], [1269200], [-1018428], [442358], [396810], [649872], [716082], [-411860], [-1518558], [-1775464], [550014], [-64144], [112998], [606330], [-565444], [-726474], [1693460], [2526840], [1009658], [-1147922], [-3023492], [-763054], [-3935748], [4284238], [603906], [2788584], [-3048832], [-1574650], [4009292], [-3445904], [1091254], [68990], [249938], [1218362], [-1215020], [882646], [-6950864], [7097234], [4404440], [-2590660], [1618882], [-7324118], [5860862], [-1159744], [-6378892], [-2528928], [-991272], [-6585060], [6398308], [1915464], [-2724370], [4282602], [3610348], [11775534], [-10796764], [-11138274], [4498356], [-5149286], [1955436], [2501794], [13135180], [-16167054], [-13986408], [5956090], [-14414224], [-1089226], [-983542], [13048252], [8599512], [-7402878], [-7680380], [-2003208], [3640894], [3027204], [-5767578], [14387170], [-4132618], [-5153556], [-1012988], [7190414], [-24186122], [18830480], [14251336], [-945586], [-2015340], [-12282952], [6439792], [10886982], [-25741158], [-23874558], [17053398], [21532596], [-7384498], [-28041526], [10716508], [-22848090], [-13664440], [-15949668], [-615250], [-5077016], [22832486], [10385690], [-9666068], [-24716016], [38767198], [12167666], [-45497836], [13095208], [9985516], [-15834672], [44046168], [-13364766], [-27218006], [30941982], [6390580], [-37244710], [43462712], [-48847428], [14644050], [-45848664], [18603680], [32633782], [16816562], [8384134], [-38821620], [12131054], [-18570136], [1795626], [-41329264], [8509626], [-12411764], [16485014], [38614072], [-36327074], [-36141616], [53239764], [64155286], [3439754], [61095424], [-51100506], [49416590], [-45880604], [18600330], [-3934560], [-13535326], [-90741428], [73823588], [-44920626], [76302244], [50970218], [8595698], [-46130514], [49932258], [-1644136], [3274846], [-33144208], [56236902], [-9579998], [-45979652], [-12235538], [-4271360], [-51587356], [-3315670], [-83879748], [-84189422], [-79982490], [-32458456], [-14160612], [18141256], [57347914], [-15635712], [83430994], [102627912], [-65352114], [-12415530], [31377368], [-69907326], [-58988480], [-37203980], [111341318], [43444698], [-55752064], [107410712], [101530396], [52080222], [-135408220], [-100025792], [73601130], [66517740], [-139315488], [-98463790], [-60664218], [70064044], [67692520], [160077396], [77892460], [154255192], [157399838], [-63619534], [180689400], [70016304], [-95292940], [159042748], [180752864], [-91595282], [20234562], [-128163912], [-79146006], [79806846], [106471556], [-3086330], [-105622692], [-73491722], [-44719558], [-28037776], [105408708], [-9990698], [-153905906], [136431682], [106233620], [85344574], [180055322], [-175517572], [26412822], [-215541378], [-38051116], [-44114022], [97616448], [-215984302], [-124947768], [-88848612], [-32281010], [124142762], [112056548], [-137403056], [277711752], [-97053336], [-182113770], [127726540], [-58043824], [110435090], [-151281114], [-114045640], [-121386270], [-187868994], [-32407468], [-87841446], [-181528324], [-234494018], [122167886], [14123200], [290583302], [-307885812], [-76974172], [-145848438], [-52022082], [-333327888], [-343670732], [-224964084], [-266861278], [-122569076], [10576606], [201703736], [-60326314], [-103691008], [211723142], [-72421342], [37919492], [43637784], [61609738], [-340315932], [-81676800], [383395554], [153131154], [-340958940], [-340576326], [216429390], [45111184], [-303374518], [-174594894], [176493684], [42979324], [21084144], [99794166], [-17671554], [-45627666], [-99702656], [347848324], [-38467524], [41906140], [-57549714], [31472066], [358969162], [-196804352], [-462511354], [-148704934], [7068118], [256493928], [114442638], [348112148], [335164918], [47908428], [500968464], [510813254], [203446100], [43031850], [-224966882], [-131230144], [305239814], [500719002], [-285031776], [141457820], [57861938], [397795144], [401841686], [-131538518], [-385478368], [-174056980], [422306372], [-476030518], [388964510], [-4452136], [-577354054], [548966580], [224069884], [-456617568], [-399918426], [488242552], [355129134], [113003844], [-245186912], [-296357374], [-24558286], [-325585798], [-335438418], [-173476950], [399392456], [-508480670], [-563897196], [122918712], [-326778512], [694957766], [-354267332], [627933840], [272722818], [-88111338], [-650283940], [209895284], [127263672], [-371174790], [-141231456], [-602391094], [271515868], [-707890970], [114552110], [-674391486], [-728250784], [-388223782], [-81337802], [-347794520], [25491550], [-511161422], [700176948], [-217841420], [-142720654], [618277606], [-666987300], [8836532], [38038090], [-56259490], [-216649632], [473071096], [318421938], [-409336536], [-348433170], [-127976138], [-22662144], [-690101044], [-158196854], [-484594498], [509564788], [-910240262], [-72752372], [428547416]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_280_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_280_6_a_b();".
// 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_280_6_a_b(:prec:=1)
    chi := MakeCharacter_280_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_280_6_a_b();".
// 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_280_6_a_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_280_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<3,R![-4, 1]>],Snew);
    return Vf;
end function;