
// Make newform 280.4.a.c in Magma, downloaded from the LMFDB on 25 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_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_280_4_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_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], [5], [-5], [-7], [-39], [-19], [-37], [-18], [-90], [99], [-32], [46], [-248], [178], [429], [-652], [40], [-36], [-348], [72], [-1190], [699], [-116], [-704], [223], [522], [1697], [246], [345], [186], [2344], [958], [768], [-122], [-166], [-1725], [3686], [2594], [1457], [-3241], [-4596], [-1140], [-4131], [-2792], [2692], [-2640], [327], [4665], [-1071], [-3920], [-2616], [-6913], [2690], [3034], [-2266], [-7058], [3474], [-20], [-4186], [-7221], [23], [139], [6759], [1038], [-9507], [-1290], [-5404], [3094], [-1486], [6630], [-5417], [-9200], [4157], [8592], [2084], [-9292], [-1723], [3767], [-14967], [11374], [14076], [3769], [-7423], [-670], [6466], [14618], [7551], [-14076], [-18360], [2812], [2619], [-7546], [9398], [-5397], [11669], [4055], [12026], [-17622], [14684], [-5741], [-9268], [-23112], [-13284], [-10446], [-2252], [4457], [-25048], [177], [9009], [-25794], [4319], [-15134], [8394], [-1658], [-8071], [28130], [2693], [1376], [30342], [-15163], [-5688], [21488], [16453], [-3372], [14172], [30663], [-14485], [-8818], [-11408], [15233], [32113], [4596], [-15893], [15336], [33010], [30982], [-5915], [-24615], [6055], [27809], [-18654], [27285], [18592], [-37146], [11024], [42858], [-31522], [37026], [34380], [-29172], [-18178], [2608], [26880], [31208], [21494], [3704], [-16185], [8500], [33415], [-25884], [26404], [-21068], [298], [-8972], [7874], [-47585], [-42016], [1867], [-32027], [-30758], [59480], [-45374], [13509], [20674], [-20410], [31428], [-16451], [38381], [-54012], [-61468], [-27912], [9552], [4002], [28918], [-48520], [-9946], [-56896], [-6099], [-24847], [-51620], [10050], [-44718], [36035], [21508], [73868], [73297], [-44833], [47968], [23499], [61553], [-70858], [13098], [11122], [-76130], [258], [-4909], [-28294], [-12624], [-60794], [-17876], [91160], [58098], [75328], [67641], [71754], [-54016], [-32674], [-6936], [42942], [34046], [87722], [46138], [-11683], [-29374], [30633], [-22602], [86807], [1089], [-57751], [11628], [78344], [-33970], [93896], [-94935], [-99407], [-13063], [-31436], [-776], [-55245], [33558], [19976], [-116576], [72493], [-72866], [-100431], [8578], [-60256], [-36326], [45119], [30690], [54230], [100298], [-121380], [111152], [-39082], [42421], [-18170], [-27140], [97509], [-15199], [-92334], [-42118], [100636], [109065], [50346], [-105914], [-99371], [3890], [36868], [-108898], [120076], [109080], [28567], [-40812], [-52194], [45533], [34972], [47482], [-114647], [-76998], [825], [-40445], [61152], [121614], [-104999], [15465], [3842], [-157466], [139436], [70308], [-21915], [-9093], [-59780], [-5712], [9758], [12636], [-91574], [-10107], [-25580], [-22563], [-14117], [-83258], [86861], [127904], [83291], [93582], [-57126], [126032], [-8928], [136624], [10784], [41439], [-7266], [152462], [32482], [-48040], [-13214], [28545], [-142333], [-9075], [-91978], [-19732], [161058], [127352], [16686], [-1276], [-199437], [150236], [45844], [-191712], [-101586], [-40496], [-144930], [-210929], [18972], [-56875], [-20815], [-102574], [-150638], [-103379], [39650], [-84312], [18566], [-83011], [166346], [-153756], [51022], [-190696], [-135186], [-2289], [153304], [-101516], [-82611], [-99547], [-119275], [-70458], [-62770], [-15062], [-4194], [-78246], [-103652], [131688], [6060], [85261], [-34684], [147910], [-176249], [-131562], [-108723], [148349], [128460], [-45416], [-135313], [88358], [197378], [-196752], [-49651], [88113], [98838], [-258043], [101046], [-242018], [-20652], [158510], [-193988], [-224967], [220241], [101829], [-135028], [144931], [-75319], [-222589], [-42033], [-153916], [138153], [262208], [-4352], [-146676], [-189519], [-34214], [169712], [187140], [130734], [95879], [-143028], [100746], [205474], [88735], [-144596], [166108], [-280713], [-119274], [-288718], [-230828], [237738], [168], [-235223], [297996], [160834], [140121], [260705], [-136706], [183322], [58620], [-106715], [-12393], [154936], [-61710], [221396], [94836]];
    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_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_280_4_a_c(: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_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_280_4_a_c( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_280_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<3,R![-5, 1]>],Snew);
    return Vf;
end function;