
// Make newform 2160.2.a.bb in Magma, downloaded from the LMFDB on 25 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_2_a_bb();".
// 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_2_a_bb();".
// 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
        poly := [-18, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    inp_vec := Vector(Rfbasis)*ChangeRing(Transpose(Matrix([[elt : elt in row] : row in input])),Kf);
    return Eltseq(inp_vec);
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 := 2;
    raw_aps := [[0, 0], [0, 0], [1, 0], [0, -1], [1, -1], [3, 0], [3, -1], [-2, 1], [3, 1], [1, -1], [-7, 1], [4, -1], [0, 2], [-3, 1], [1, 1], [0, 2], [12, 0], [-4, 1], [-10, -1], [4, 2], [0, 1], [5, 0], [6, 0], [-8, 0], [-4, -3], [15, -1], [-12, -1], [-14, 0], [0, 2], [3, -3], [2, 2], [11, -1], [2, 4], [8, 1], [5, 1], [5, 4], [3, 1], [-1, 2], [-4, -4], [2, -2], [0, 2], [-10, -3], [-6, 2], [-8, -1], [20, 0], [15, 0], [0, -3], [4, -4], [-8, 2], [20, -2], [-22, 2], [6, 0], [-11, 4], [5, -1], [7, -1], [12, 0], [-9, 3], [6, 1], [10, 0], [2, 2], [-8, 4], [10, 4], [1, 1], [4, 0], [-14, -3], [8, -4], [-8, 1], [-22, -1], [0, 6], [8, -7], [-19, 1], [-12, 2], [-4, 3], [1, 4], [14, -3], [-9, -1], [-15, -3], [17, 3], [-8, 2], [11, 2], [3, -1], [-10, 1], [4, -6], [-18, 4], [-16, 0], [-8, -4], [-18, -2], [8, 2], [26, 2], [16, -5], [-32, 0], [20, -2], [2, 1], [24, 2], [20, -4], [-5, 5], [13, -1], [-36, 2], [-11, 2], [-12, -1], [-9, 2], [0, 8], [2, -2], [0, -4], [24, -1], [14, -7], [22, -4], [-9, 5], [-14, 4], [35, -3], [-16, -5], [7, -2], [-7, 3], [-20, 3], [-2, 1], [18, -6], [5, 1], [0, 6], [8, 4], [-40, 0], [-12, 1], [-20, 7], [-28, 4], [20, -2], [-10, -6], [-15, -1], [26, 5], [-18, 0], [20, -4], [-26, 4], [16, 4], [-11, -7], [1, 8], [1, -10], [-10, -4], [-9, 12], [30, -4], [-1, -8], [-8, -8], [24, 0], [22, 2], [14, 2], [6, 7], [6, -2], [34, 1], [26, 6], [-25, 2], [-22, -4], [20, 1], [-11, -3], [-23, 0], [26, -4], [2, -3], [21, -3], [35, 0], [0, -8], [19, -5], [-12, 6], [-12, -1], [-11, 7], [18, -2], [25, 5], [0, 1], [33, 1], [-5, 1], [19, -7], [11, -4], [27, -3], [-47, 4], [-18, -6], [11, 5], [-26, 4], [-6, -10], [-10, -1], [3, -8], [44, -2], [32, 4], [10, -4], [-2, -1], [-26, 4], [-14, 7], [-32, 4], [19, 9], [15, -9], [-40, 4], [30, -8], [7, 4], [-17, -6], [32, -1], [-2, 2], [16, 9], [6, 6], [-18, 11], [31, -1], [12, 8], [34, 0], [20, 5], [-1, 8], [-10, 4], [60, -2], [-5, 3], [10, -15], [40, -3], [0, -1], [15, 5], [-4, -2], [-37, 2], [6, 4], [6, -12], [-46, -3], [-26, 1], [27, 7], [10, 7], [-10, 0], [-6, -4], [-9, 4], [-14, -2], [-22, 12], [21, -5], [-6, 0], [2, -3], [5, -7], [16, -4], [-16, 8], [10, 0], [-36, 1], [27, 3], [18, 0], [26, -3], [-27, -3], [32, -3], [-26, -6], [-5, 3], [22, -8], [-14, -7], [12, -12], [23, 2], [-4, 4], [-44, -6], [20, 8], [-56, 2], [-46, 5], [-32, 5], [-4, -3], [-10, 6], [24, -6], [32, -3], [-21, 3], [-22, -2], [-65, 1], [-9, 13], [60, 0], [-24, -8], [-44, -5], [26, 0], [-27, -3], [2, 5], [19, -5], [-2, 8], [-26, 4], [50, -3], [-30, 8], [40, 3], [15, 2], [33, 1], [8, -12], [6, 4], [36, 2], [13, 1], [-24, 4], [6, -1], [-19, 4], [10, 0], [-37, 6], [-14, -4], [-50, 5], [-12, 6], [-40, -2], [43, 5], [3, -3], [-27, -9], [1, -11], [3, 1], [-46, -1], [11, 6], [-10, 10], [30, -9], [-42, -2], [-21, 8], [-10, 4], [-25, -3], [-28, -2], [-15, 3], [36, -8], [-46, -4], [-42, -2], [-46, 3], [-42, -6], [-27, 15], [14, -1], [22, 9], [-36, -2], [21, -7], [-54, -6], [-4, -11], [-2, -8], [34, -2], [-16, 19], [-30, 10], [-31, 12], [15, -1], [-50, 2], [-26, 0], [11, 6], [19, 1], [9, 7], [3, -5], [4, -10], [-20, 14], [-26, -4], [54, 1], [-42, -3], [-23, 11], [28, -4], [51, 5], [25, -4], [28, 4], [-4, 8], [-53, -7], [-12, -2], [20, -1], [6, -8], [-23, -8], [30, -4], [-16, -12], [-18, -4], [-34, -5], [-18, 12], [21, -5], [30, 6], [-7, 8], [67, -7], [54, -4], [-33, 10], [-12, -4], [55, -9], [14, -12], [-12, -16], [12, -8], [22, -4], [-18, 13], [-34, -1], [-23, 5], [34, -6], [-38, -5], [-7, -9], [0, -6], [51, 5], [-7, -9], [-49, -7], [4, -5], [-36, -12], [-24, 6], [-25, 15], [-65, -2], [66, 5], [64, -4], [-16, -1], [-21, -4], [47, 7], [-56, -3], [1, -3], [-34, 0], [2, -1], [5, 2], [15, 9], [0, -12], [2, 13], [-30, 0], [32, -15], [13, 5], [-23, 7], [10, -1], [49, -1], [52, -9], [-19, -15], [-8, 0], [44, 1], [91, -2], [41, -3], [11, 1], [-2, -2], [40, 6], [11, 0], [52, -6], [-2, -1], [-58, -3], [24, 16], [30, -14], [-57, 5], [-32, 6], [-43, -5], [-52, 4], [33, 7], [42, 6], [-32, 4], [13, -18], [-18, -12], [-38, 1], [-23, 11], [-2, -16], [58, -10], [-26, 6], [44, -15], [-24, -7], [14, -24], [42, 6], [-58, 11], [46, 8], [23, 13], [49, 3], [30, 4], [-13, -17], [57, -7], [-14, 0], [42, 6], [-16, 2], [-56, 2], [-38, 10], [-26, -16]];
    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_2_a_bb();".
// 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_2_a_bb(:prec:=2)
    chi := MakeCharacter_2160_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 2));
    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_2_a_bb();".
// 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_2_a_bb( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2160_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<7,R![-18, 1, 1]>,<11,R![-18, -1, 1]>,<13,R![-3, 1]>,<17,R![-12, -5, 1]>],Snew);
    return Vf;
end function;