
// Make newform 2160.4.a.s in Magma, downloaded from the LMFDB on 23 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_2160_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_2160_4_a_s();".
// 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_2160_4_a_s();".
// 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_2160_a();"
function MakeCharacter_2160_a()
    N := 2160;
    order := 1;
    char_gens := [271, 1621, 2081, 1297];
    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_2160_a_Hecke(Kf)
    return MakeCharacter_2160_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], [0], [5], [22], [-9], [17], [75], [4], [183], [-129], [187], [-34], [-264], [-443], [609], [228], [60], [-454], [244], [444], [398], [349], [1038], [-852], [914], [-1155], [574], [294], [-340], [-681], [-578], [-783], [-234], [-3170], [1263], [-851], [2279], [1297], [324], [174], [-4596], [548], [4638], [-3442], [3312], [-1745], [3358], [-3512], [2112], [2900], [5178], [5010], [-5203], [-549], [7095], [4284], [6669], [5560], [6734], [7710], [-4736], [5550], [-5663], [-1920], [2816], [-5784], [4354], [3896], [7608], [4286], [-2907], [5988], [3214], [9419], [-4544], [11487], [-7845], [4133], [-3324], [1871], [5409], [-13084], [-7848], [-10222], [-5672], [444], [-10434], [11180], [-15018], [-16166], [2964], [-5412], [-12356], [16740], [14092], [-2313], [-14925], [-5820], [20875], [22442], [-8615], [-19524], [13014], [18336], [-3182], [7088], [6342], [-26253], [-5382], [-28411], [-15374], [-23983], [13773], [11146], [2080], [31050], [-9083], [-4740], [8196], [6912], [-28438], [1946], [25956], [-8184], [-30422], [-27273], [28940], [-606], [13084], [27074], [3580], [-13947], [31273], [-31729], [3138], [20807], [-33078], [12541], [-31980], [3792], [-24086], [-9774], [-38636], [-16458], [20252], [-40722], [12113], [1926], [-4394], [-37491], [-21325], [-17982], [25636], [4221], [28393], [-10056], [37249], [1668], [2786], [-8613], [-55602], [10785], [35062], [-49701], [7911], [37719], [-54725], [-6505], [24305], [-50634], [25965], [14618], [31686], [-4396], [-4373], [13920], [-52220], [-23238], [29512], [-63070], [33544], [45456], [-5281], [-51681], [23568], [-7674], [23813], [6625], [35942], [11778], [-66226], [-33462], [-63500], [-66387], [-15132], [73398], [-68002], [-29275], [-31710], [-9840], [9393], [-77060], [-73474], [12350], [-87279], [23268], [-6305], [-44526], [-46518], [-46628], [-42544], [43305], [-59660], [77514], [78618], [-27025], [77794], [16362], [-80127], [-78246], [60332], [102031], [31860], [-29972], [52218], [40994], [-6861], [-105534], [69544], [27159], [78494], [-12962], [49921], [-24570], [-47612], [-46140], [44147], [9024], [-76800], [-79512], [-7992], [-79676], [-87674], [24254], [97422], [-13704], [76774], [-84231], [65374], [-18933], [-41245], [79956], [-89976], [47474], [76926], [8439], [31820], [-11261], [-128154], [90830], [724], [56766], [-61270], [-70447], [-13503], [8512], [-43050], [-50880], [-21539], [66684], [-11164], [16351], [-95902], [23095], [-51334], [68512], [-33336], [40556], [-57931], [34149], [63609], [-67061], [-113073], [3032], [29269], [-13554], [54440], [11130], [-49565], [126534], [97137], [66468], [-108171], [-22836], [-21130], [-73134], [85720], [70914], [147579], [-19964], [-78208], [68760], [115639], [47250], [112282], [4394], [64878], [53654], [-85686], [-101581], [-24417], [4890], [164202], [-111227], [152175], [11279], [101385], [116232], [21044], [-103578], [82708], [-68824], [-105537], [-44876], [-12657], [-83383], [4444], [-145532], [15975], [-103644], [-49762], [59946], [76105], [-91974], [100492], [-82830], [78368], [-57510], [-214333], [-9002], [110579], [157983], [-167346], [131179], [21348], [177261], [-72610], [-59852], [-160020], [-37674], [79708], [181208], [111963], [-130358], [186668], [-198843], [200412], [-24435], [4125], [-77373], [-56866], [-166572], [164916], [-227115], [41641], [-48424], [93804], [62674], [-158437], [-103539], [37498], [144273], [-60426], [-61184], [-82813], [-176439], [-31548], [255392], [-178482], [129722], [3015], [-100635], [125152], [52389], [-15734], [-32091], [-150176], [-197494], [-52427], [34401], [1181], [-12846], [-94428], [-6407], [-206748], [-242176], [-139616], [138180], [36070], [-78327], [-28060], [235017], [-131276], [-241731], [-15426], [34792], [184739], [-281538], [96364], [226743], [-140182], [50274], [-123570], [-38366], [226454], [42558], [-63438], [164416], [178026], [73443], [-138081], [-137878], [76299], [229179], [60302], [-94854], [251424], [-147720], [120454], [-120414]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2160_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_2160_4_a_s();".
// 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_2160_4_a_s(:prec:=1)
    chi := MakeCharacter_2160_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_2160_4_a_s();".
// 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_2160_4_a_s( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2160_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<7,R![-22, 1]>,<11,R![9, 1]>],Snew);
    return Vf;
end function;