
// Make newform 280.4.a.d in Magma, downloaded from the LMFDB on 23 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_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_280_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_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 := 4;
    raw_aps := [[0], [7], [5], [7], [9], [23], [41], [34], [-6], [131], [4], [26], [-260], [-190], [167], [-368], [324], [-164], [200], [784], [-410], [1211], [-1132], [-72], [-707], [-1410], [-813], [1078], [-2135], [158], [604], [-1914], [-2144], [-2266], [-1854], [-1037], [1058], [-2810], [1395], [4445], [-1740], [2488], [2053], [448], [3312], [1060], [1711], [795], [5899], [-2468], [-3960], [1183], [-2878], [5570], [2594], [638], [1106], [-8084], [-2854], [-165], [4973], [7593], [8205], [-1430], [-1081], [5326], [-1732], [2002], [6054], [10162], [5893], [6896], [-5729], [-11800], [8548], [1668], [-739], [-1235], [11313], [-6942], [-120], [-9479], [-16239], [-7058], [10810], [-17830], [4743], [-2976], [7872], [3148], [8321], [8518], [-934], [10515], [10157], [3197], [8250], [-8818], [16844], [12659], [21092], [1232], [9148], [19066], [-18884], [-14197], [-2080], [22763], [6113], [-10230], [6597], [20762], [-1994], [-14362], [13337], [12882], [-2465], [-18696], [1542], [-2819], [-30128], [12520], [-8521], [-16788], [-14508], [-17681], [-1093], [8870], [-23368], [6667], [-5015], [-15896], [-16533], [-16376], [29482], [-12942], [11599], [11987], [40989], [-8239], [18018], [-31155], [32860], [-9486], [5860], [-32454], [45938], [-9930], [4628], [-46008], [-40074], [-11744], [-14128], [16336], [45202], [-35352], [7527], [28896], [3013], [-51788], [35600], [-17800], [-20406], [-25128], [-37470], [-27507], [-2960], [27769], [48373], [-40858], [-7160], [814], [-7011], [-5482], [-17086], [13964], [15901], [24589], [41876], [39164], [38528], [49464], [26058], [62058], [-5448], [-5154], [9180], [68503], [37145], [40100], [-4498], [-17454], [-9477], [46464], [24468], [-43861], [5543], [-5132], [-20519], [26747], [-60706], [-47018], [1614], [-49622], [-59498], [-10671], [-30830], [43432], [27510], [40772], [-67524], [-62150], [69132], [8211], [-79306], [86784], [21226], [11804], [7614], [-30222], [-62070], [-72338], [11541], [89290], [-26205], [58262], [-97291], [-85831], [85219], [-27204], [-4544], [45370], [-82592], [57065], [73715], [22739], [-48520], [70656], [-4269], [47230], [-86512], [-71560], [-69729], [-20778], [78483], [40670], [-42752], [94950], [-76233], [-91878], [109966], [-13778], [62376], [3976], [-86142], [46909], [19630], [-88084], [15471], [-62981], [-77038], [-120714], [130008], [82907], [-21466], [16510], [61261], [122142], [39784], [19006], [-64288], [-45052], [126749], [37892], [-89454], [15031], [-63964], [106810], [-137543], [132918], [-43133], [2027], [69648], [-33530], [-117205], [77241], [158530], [-47538], [28320], [91120], [-114419], [47969], [-105248], [137556], [43966], [81184], [-59430], [102391], [38932], [48631], [-147319], [55026], [-107987], [-69336], [-25469], [-123006], [-105542], [-127896], [-6896], [150268], [55176], [7623], [-41682], [-158314], [-87062], [-97648], [38622], [110465], [50737], [-122459], [-7190], [-129112], [109730], [-51028], [134846], [29296], [99291], [43732], [89728], [14028], [172886], [164268], [-73994], [71997], [37956], [71695], [137689], [159198], [106942], [-17609], [194238], [22772], [-77618], [-94907], [124974], [-48428], [-31522], [109216], [-15306], [130013], [-170340], [69860], [131613], [125743], [-124099], [-103974], [60426], [-42670], [110766], [26942], [50852], [71212], [-22096], [143365], [37004], [-178674], [-11715], [202702], [147181], [31765], [-199324], [-14724], [-178129], [-211838], [222618], [119016], [11293], [166843], [78086], [-16441], [-37278], [-211710], [68432], [227730], [-36344], [14891], [89833], [-111433], [-194156], [-180295], [113377], [-119359], [-110425], [-188412], [260217], [-62560], [212696], [194264], [-167967], [-247990], [182920], [-74808], [130122], [249181], [-85068], [-229610], [241310], [-157417], [-68636], [-188820], [141813], [131582], [-208690], [250812], [-52930], [11800], [53937], [-201988], [301926], [178507], [-5375], [120034], [-210078], [8764], [-237337], [-216291], [-259476], [90442], [-123592], [-52836]];
    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_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_280_4_a_d(:prec:=1)
    chi := MakeCharacter_280_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_280_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_280_4_a_d( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_280_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<3,R![-7, 1]>],Snew);
    return Vf;
end function;