
// Make newform 280.6.a.a in Magma, downloaded from the LMFDB on 24 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_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_280_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_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], [-12], [25], [-49], [556], [-354], [770], [-2684], [-1528], [-2418], [7840], [-314], [-17878], [16476], [5376], [1654], [-29492], [27630], [57716], [70648], [74202], [74336], [44068], [129306], [-137646], [52086], [128216], [113340], [-138946], [-28046], [-26704], [7028], [140202], [-95876], [-347002], [-270328], [-151186], [588148], [61912], [4862], [-17964], [228422], [-357840], [-494174], [595302], [-261208], [788564], [-1358416], [-461068], [1255094], [503914], [1509024], [-63022], [-964820], [-495150], [2180920], [-473346], [-2192336], [388502], [-75462], [2172716], [142902], [1052772], [-3112136], [-1956758], [2747998], [2230188], [3134386], [2430028], [3460622], [-1256270], [878712], [234880], [97430], [-1997220], [119664], [327670], [4466526], [-1832494], [-5593926], [562772], [679158], [5894656], [-1644990], [-4201384], [-565684], [648386], [-1747126], [-317378], [-5846784], [-3672572], [-1663328], [4345048], [-6650164], [742996], [-5571256], [-5912466], [6340650], [118300], [5362478], [-579116], [6618798], [-2659068], [-11264998], [-4052420], [-5075662], [-9070788], [14779266], [9062120], [-2654822], [15293040], [14906950], [5120298], [-4831396], [5782120], [-16569086], [-9284908], [-13150472], [-6282066], [-21600716], [-5792346], [14507106], [16677462], [3355548], [80036], [12640302], [10320342], [13232976], [1894472], [-3250226], [25636612], [-11033160], [17597664], [-9254442], [13663962], [-29849822], [23287830], [-10169148], [2431918], [14195978], [1755484], [16971462], [-8852408], [24841772], [3556910], [25140104], [-10124218], [-10552182], [33775756], [-31265168], [-28992114], [-6432110], [-24116380], [4163592], [-41824772], [-2963232], [22235496], [-9650462], [-44511590], [10898334], [-13737020], [-27886726], [7364440], [-8715076], [-16003182], [-38174616], [-37697872], [44025142], [-36433166], [-8936794], [26121180], [-52821650], [48241336], [45295370], [-8000496], [51978714], [-21519588], [59382102], [2628376], [40954974], [-39113072], [25378228], [40786278], [-68126694], [23449824], [35283110], [-71077346], [29579284], [-3510902], [-3851040], [24189778], [38019804], [8343924], [-61455026], [-15824172], [33271482], [-318030], [-68732066], [46268434], [13896760], [17869758], [27838256], [-32766362], [-53166782], [4027484], [-14475666], [50542368], [51776500], [110151210], [85708348], [-13443438], [79461222], [98679944], [14338508], [47311880], [-56321302], [102708352], [46791250], [46790536], [780030], [-12857674], [136759640], [-88417470], [-12000224], [-35283548], [-99106490], [124894986], [80958256], [123333016], [45295980], [-123981874], [123209220], [36447120], [-101408918], [11908444], [-35266752], [27469650], [-149550570], [-47572580], [107813352], [65139108], [436204], [59476024], [4425214], [-113481022], [-58499016], [32466608], [22766388], [-65144020], [-158282624], [37041118], [138114690], [-156161640], [108481578], [9327998], [-29214060], [-66029050], [-82215220], [41623926], [-118454294], [-158934896], [144244948], [-41895338], [23785678], [66585522], [-44274668], [-66134370], [-218574950], [155972076], [-170596154], [36811646], [83458052], [-248703862], [332784], [-86320382], [55169544], [9838092], [62957550], [-173574614], [43936612], [-148026960], [-57196840], [-76903288], [-237189546], [120786140], [241788672], [-147431502], [219221814], [-13939880], [74934050], [110063134], [30826052], [270901434], [-114979236], [107613422], [301635342], [22414112], [-242699802], [-57830996], [-232959148], [75836954], [-53789394], [104556064], [-210508380], [-266740292], [-161151838], [260299612], [201530846], [-315769464], [291543462], [-32970304], [226121126], [247032994], [81192628], [85257144], [-196358166], [177298084], [-72687408], [244093010], [240715666], [-204797596], [300862202], [-220516914], [221932112], [71244138], [-108725422], [135170660], [-92748500], [-237031440], [29462086], [102667614], [311342878], [-323170336], [142014804], [-93449076], [-76362644], [-329258450], [-232547886], [-215662230], [-55194400], [341944982], [-430461030], [331116438], [203999000], [258925790], [-142321468], [270114358], [-252342916], [-446218512], [231501382], [74830836], [189756362], [-515161410], [222689152], [-87655706], [-440377782], [77376064], [127888956], [-98990766], [319234216], [189590694], [92881002], [-187851584], [-536141252], [170878196], [-245858454], [3675006], [383740504], [-233455750], [148572548], [279508060], [543082624], [223694694], [-380107272], [-447357986], [-427996764], [522411504], [-461983598], [480953522], [-445105558], [68150830], [-317775030], [-505971032], [455844898], [-130403212], [415963512], [-696529312], [380693830], [547458924], [193631664], [-561011710], [-413185194], [489421964], [698359236], [149923080], [-337876102], [600184928], [22871978], [-542068276], [23039430], [-258448274], [240917410], [282183008], [-536662806], [207767286], [264871432], [-124869618], [-752005966], [-709386204], [495590676], [564698210], [296911542], [795416396], [-365178460], [-599684566], [681672030], [-55752816], [334894040], [316677474], [-195900888], [626571374], [340494198], [198757152], [-334322292], [694299706], [786229694], [100556516], [-496612102], [-797751412], [743645688]];
    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_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_280_6_a_a(: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_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_280_6_a_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_280_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<3,R![12, 1]>],Snew);
    return Vf;
end function;