
// Make newform 928.4.a.a in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_928_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_928_4_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_928_4_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_928_a();"
function MakeCharacter_928_a()
    N := 928;
    order := 1;
    char_gens := [639, 581, 321];
    v := [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_928_a_Hecke(Kf)
    return MakeCharacter_928_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], [-13], [16], [-45], [61], [-102], [-68], [194], [-29], [149], [400], [280], [263], [509], [-605], [-578], [-718], [-260], [738], [652], [-917], [678], [-1008], [-1764], [-1360], [1498], [-772], [763], [-1218], [1544], [-1916], [72], [1394], [-135], [-1708], [128], [1235], [-2398], [-1258], [154], [3089], [-1088], [-228], [2226], [-1908], [583], [-1594], [2682], [-960], [-1225], [-1650], [-3503], [-5571], [-4891], [-1287], [-3826], [-1713], [7086], [7063], [-5002], [4086], [-1909], [-5808], [-6783], [-6090], [-3801], [-2374], [-5346], [9003], [10222], [719], [-6084], [-1451], [896], [13016], [-6560], [2757], [4995], [3930], [-3230], [6110], [14218], [-10008], [-11338], [10180], [-90], [-8906], [-9646], [11578], [4671], [195], [15604], [-18507], [-1882], [-7645], [1255], [-873], [14996], [2672], [-4776], [-134], [-437], [-23990], [-100], [6078], [-4214], [-28293], [8843], [-22548], [-17061], [21251], [200], [-19533], [12570], [17446], [-11324], [2922], [23120], [32901], [-18494], [-15119], [6946], [31124], [12664], [-18715], [-7531], [35338], [-13976], [7172], [-35091], [-10992], [-20988], [-39094], [-27270], [3462], [-10632], [-3754], [9378], [-3708], [13232], [5445], [-17576], [10143], [-8558], [-30467], [-154], [-10463], [24749], [-20586], [5051], [-38990], [-27180], [-17435], [-11500], [-7969], [-24414], [-18694], [14394], [-11925], [-53321], [-38301], [-40011], [-53500], [28449], [48529], [8142], [-30572], [14885], [25656], [-15392], [5995], [23150], [-13022], [19966], [-57346], [4060], [19822], [1843], [54038], [-31393], [42567], [9526], [9981], [-5952], [-5783], [38414], [3760], [-32974], [-28920], [-4123], [-65491], [-3873], [9288], [21656], [-6278], [-4252], [-40306], [-19899], [25024], [-42888], [-37270], [25016], [11912], [-13496], [-495], [61619], [-46266], [12679], [60557], [86544], [-14598], [-2513], [-60589], [87936], [22421], [-12660], [59412], [73584], [-23306], [60818], [-54412], [-66190], [88367], [-18228], [-38358], [-55348], [-18136], [-55811], [-33320], [37644], [752], [57936], [24276], [67178], [45736], [-11866], [-7208], [100596], [58553], [-33531], [-85694], [-32022], [-41620], [-62290], [-47934], [5438], [-71982], [12630], [42455], [9010], [-72873], [-103021], [34304], [58224], [17212], [-38164], [-86963], [-25742], [-56975], [120776], [11339], [-56082], [-126134], [-42286], [58039], [107136], [6330], [108348], [-5517], [39563], [-33566], [36557], [14384], [-123100], [-91167], [-9320], [-39779], [-1444], [-119594], [-150802], [86590], [112636], [-65034], [-100396], [1272], [75842], [28652], [-129196], [20505], [-23743], [-84598], [103957], [141869], [-13214], [-167043], [82161], [-94129], [-13780], [-64964], [102034], [95082], [4224], [-38109], [-140628], [-105895], [65855], [-75559], [77820], [24185], [59822], [12040], [-172722], [-90410], [165444], [-97481], [-80100], [5482], [-133115], [174738], [-78447], [56761], [-2986], [72835], [98583], [-114752], [-58246], [-44092], [-35253], [52239], [-64132], [31929], [-68540], [-78004], [-147191], [51416], [-101330], [82290], [193046], [-85556], [32906], [-155006], [218274], [38172], [135030], [210747], [-158622], [-32276], [-84113], [-143274], [144814], [-63866], [25570], [185162], [-18066], [-34038], [-173655], [-140800], [-88346], [120730], [48509], [-132287], [207047], [-216534], [73631], [-62400], [-21744], [69670], [111430], [-135393], [-142862], [48868], [-181314], [-94238], [-16961], [203076], [-79113], [116474], [257223], [-28139], [-18468], [209417], [-211271], [-53230], [51832], [-46836], [112904], [175557], [240103], [5624], [50714], [-24753], [-154231], [24889], [202941], [-21695], [177064], [-136288], [158910], [143454], [189322], [4170], [-112640], [-94971], [76641], [-21922], [216595], [-34950], [-135565], [-10496], [-208918], [293147], [102512], [61590], [12248], [153638], [-157581], [80834], [234256], [61763], [-43502], [-205282], [-152265], [261849], [-13833], [15363], [179750], [-121652], [71022], [-36865]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_928_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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