
// Make newform 2160.4.a.g in Magma, downloaded from the LMFDB on 16 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_g();".
// 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_g();".
// 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], [13], [30], [-61], [12], [49], [-18], [-186], [160], [-91], [378], [268], [-144], [570], [-204], [-877], [187], [606], [431], [-1151], [-102], [984], [-265], [-1248], [1225], [78], [2198], [1986], [-2792], [708], [-1686], [307], [-1812], [-203], [-214], [673], [3696], [3132], [-510], [-1087], [4056], [473], [2556], [2923], [3175], [2176], [3834], [-3202], [4152], [5466], [-943], [7290], [312], [8004], [-324], [7849], [-5758], [-2688], [-3260], [5922], [-3728], [732], [5357], [-4572], [-845], [8723], [-9018], [5759], [-5772], [2046], [1069], [7133], [8557], [-14328], [13500], [1334], [3474], [569], [9132], [-2971], [-12042], [-8566], [-7400], [2580], [13200], [18038], [5544], [17137], [15888], [-3942], [-1379], [-14214], [-9992], [21258], [-16614], [11838], [-2201], [-10795], [14185], [-3576], [9132], [25020], [15997], [-5971], [-19242], [8118], [-1902], [-14074], [13825], [15569], [11922], [-6899], [-11711], [9240], [17908], [-7530], [-22788], [-16440], [-12421], [6461], [-912], [14442], [-1892], [-7914], [-1291], [30210], [-15680], [13898], [-35300], [-28188], [-25163], [7979], [26622], [-35413], [-33834], [-13469], [-21168], [408], [36916], [-24636], [18187], [-1464], [-12295], [-46884], [12197], [-28182], [-25433], [16968], [-22423], [8442], [-41207], [-8472], [21799], [-23544], [-11072], [-21654], [-42835], [-48534], [-14676], [27372], [-3581], [1824], [-29778], [-9402], [24907], [27830], [-25771], [45948], [-35862], [52778], [-31668], [-44113], [45799], [22122], [-48692], [-4374], [60019], [-39382], [15343], [-31356], [-9646], [23784], [-21012], [-32814], [-49237], [-23807], [68441], [62772], [67847], [-60720], [39703], [-40560], [14460], [-34410], [65591], [8063], [76854], [-55902], [-38232], [53677], [69731], [-14887], [57126], [-36582], [-44915], [-23298], [35766], [-11423], [2405], [-57636], [37591], [4986], [-55854], [72179], [14092], [26250], [-26586], [-55698], [7709], [-24716], [41628], [-56000], [38454], [19667], [6312], [-8082], [-15887], [24408], [-23197], [-9236], [-27920], [-23766], [92485], [61656], [15245], [-70680], [-84426], [-44124], [-3750], [-17903], [89095], [-3121], [2592], [68514], [40279], [10968], [26332], [58386], [-3166], [-4716], [-56976], [-35215], [12942], [89880], [-74443], [105928], [32946], [30674], [22513], [55878], [-106219], [14405], [19296], [-23708], [-30378], [97302], [98908], [-54948], [-57505], [-86363], [99578], [-12719], [-48490], [39469], [127122], [-146590], [-15802], [-113430], [128802], [-104204], [16206], [55091], [-90767], [-54540], [112727], [118728], [-82457], [29622], [21822], [-24198], [-142134], [-54204], [100622], [83928], [61843], [-22140], [-44742], [130699], [80261], [72810], [43540], [149136], [-39653], [-4570], [-149220], [-20803], [-34056], [1493], [93648], [40692], [150834], [-58487], [21486], [-85822], [77592], [74946], [-120130], [-71634], [66817], [43553], [39498], [-44120], [147162], [-25291], [37096], [-65612], [-142962], [-174654], [-11419], [-67446], [-162299], [-29682], [87244], [-23394], [129155], [143670], [-103174], [167632], [-146047], [9246], [80670], [179761], [110040], [-91632], [-179710], [-118892], [152364], [-40914], [166405], [-44353], [139020], [22336], [98687], [-95226], [-134742], [-149598], [59910], [58746], [224609], [-51960], [163278], [-1320], [200269], [-1939], [20028], [60733], [181055], [145368], [-164705], [-155556], [158154], [9127], [25475], [189930], [147732], [-145195], [-32394], [-115321], [-68088], [-107850], [-93545], [-186906], [11665], [-99564], [199312], [-168301], [5473], [-18540], [-141478], [-42720], [4590], [-135641], [-38490], [-23953], [-220115], [151560], [-119540], [-194586], [122978], [-32274], [-134624], [8526], [-109476], [-140924], [78647], [-226722], [155437], [-267246], [-206098], [59100], [-130752], [-60761], [-296257], [85074], [216588], [85783], [-118398], [-218538], [-177414], [227522], [200844], [131040], [182882], [179676], [-274254], [159666], [-188480], [-165366]];
    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_g();".
// 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_g(: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_g();".
// 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_g( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2160_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<7,R![-13, 1]>,<11,R![-30, 1]>],Snew);
    return Vf;
end function;