
// Make newform 2160.2.a.k in Magma, downloaded from the LMFDB on 21 September 2025.
// 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_k();".
// 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_k();".
// 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 := 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]];
    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], [-1], [4], [-6], [-4], [-3], [7], [9], [0], [7], [2], [6], [-2], [0], [9], [12], [-7], [-2], [-6], [2], [1], [-9], [-6], [8], [12], [4], [12], [5], [6], [-2], [6], [-9], [4], [-6], [16], [-10], [22], [-3], [-9], [0], [5], [-18], [8], [15], [-20], [13], [-14], [15], [-25], [-6], [-18], [-25], [12], [15], [12], [6], [7], [-22], [-24], [-2], [15], [34], [-24], [20], [9], [-8], [-28], [12], [-19], [18], [6], [4], [-4], [-23], [9], [-30], [8], [6], [17], [-30], [-37], [36], [-4], [19], [27], [-24], [8], [-6], [22], [-33], [-6], [-38], [30], [-5], [33], [-12], [30], [-32], [-10], [-26], [6], [12], [36], [7], [14], [-39], [-21], [-36], [-7], [22], [-16], [-15], [-20], [-23], [0], [4], [-27], [9], [24], [14], [-28], [30], [39], [37], [-6], [-46], [6], [28], [-40], [-11], [-24], [-23], [14], [0], [5], [9], [-26], [3], [30], [28], [-30], [22], [-3], [2], [12], [32], [-39], [13], [-27], [2], [0], [52], [-3], [-44], [24], [-56], [6], [44], [-42], [3], [42], [22], [-42], [-54], [33], [13], [26], [23], [3], [-12], [-13], [-36], [-4], [13], [-36], [-5], [-24], [-38], [2], [-38], [-60], [50], [-54], [39], [-12], [8], [52], [5], [0], [-34], [33], [1], [24], [-57], [-45], [41], [44], [54], [0], [54], [-8], [-58], [35], [-24], [-66], [16], [27], [-60], [-44], [-4], [30], [-32], [60], [60], [17], [-62], [-24], [-3], [45], [-22], [31], [24], [-74], [27], [-1], [-21], [-54], [-2], [12], [38], [43], [64], [30], [64], [63], [5], [-57], [6], [-18], [12], [55], [46], [53], [66], [-6], [52], [12], [-20], [15], [-58], [6], [27], [5], [69], [48], [41], [-44], [45], [-52], [46], [57], [59], [44], [63], [-44], [72], [78], [-14], [-42], [-25], [70], [-10], [7], [-70], [4], [-39], [-67], [-55], [6], [-24], [-5], [-39], [-13], [-20], [24], [38], [-42], [-35], [-72], [-72], [-63], [6], [-42], [26], [-24], [55], [-6], [-48], [64], [14], [-3], [-32], [-9], [13], [50], [-12], [-1], [30], [2], [-69], [72], [12], [-68], [-69], [23], [48], [18], [-40], [54], [-71], [-4], [-48], [-44], [-39], [-34], [-83], [28], [-48], [51], [-22], [6], [16], [-48], [52], [-12], [-85], [-27], [26], [-2], [-28], [-3], [-36], [-23], [78], [-6], [-25], [-56], [48], [39], [52], [2], [-72], [-44], [-34], [69], [12], [60], [54], [-63], [80], [54], [-36], [-6], [88], [-4], [-3], [-2], [-70], [-42], [-17], [87], [-78], [-41], [-52], [54], [-90], [38], [54], [2], [-48], [-45], [16], [-87], [40], [-72], [37], [-4], [70], [-24], [-94], [-27], [-66], [-38], [-90], [-46], [49], [48], [1], [-24], [-22], [-66], [-92], [-6], [12], [43], [-10], [-42], [16], [-48], [86], [-57], [21], [-5], [-34], [-60], [-102], [64], [27], [-21], [72], [86], [-21], [-18], [-70], [15], [-63], [66], [25], [30]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2160_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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