
// Make newform 2124.2.a.i in Magma, downloaded from the LMFDB on 11 June 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_2124_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_2124_2_a_i();".
// 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_2124_2_a_i();".
// 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 := [3, -4, -9, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 1, 0, 0], [-9, -8, 1, 1], [3, 16, 1, -2]];
    Rf_basisdens := [1, 1, 3, 3];
    Rf_basisnums := ChangeUniverse([[z : z in elt] : elt in Rf_num], Kf);
    Rfbasis := [Rf_basisnums[i]/Rf_basisdens[i] : i in [1..Degree(Kf)]];
    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_2124_a();"
function MakeCharacter_2124_a()
    N := 2124;
    order := 1;
    char_gens := [1063, 1181, 1477];
    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_2124_a_Hecke(Kf)
    return MakeCharacter_2124_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, 0, 0], [0, 0, 0, 0], [0, 0, -1, -1], [0, 0, 0, 1], [-2, -1, 1, 0], [-1, 1, 0, 1], [0, 1, 1, -1], [-1, 0, 2, 1], [-3, -1, 0, 0], [-2, 1, 0, 0], [-1, -3, 3, 1], [2, 2, 1, 0], [-6, 1, -2, 2], [-3, -1, -2, 1], [-5, 2, -1, 0], [0, -4, 1, -1], [1, 0, 0, 0], [-1, -1, -3, -1], [3, 1, 0, -1], [-4, 2, -1, -1], [-1, -3, -1, 1], [3, 4, -2, -2], [-5, -2, -1, -2], [1, 0, -1, -2], [1, 1, -6, -5], [0, 4, -4, -2], [-4, -2, 2, 0], [-8, -3, -1, 3], [2, 4, 1, -2], [-4, 5, 3, 2], [-5, 2, -2, 4], [-10, 2, -4, 2], [-2, -2, 1, -3], [5, -2, 2, 0], [-3, 1, -2, 4], [7, -1, -1, -5], [1, -1, 6, 1], [-2, -2, 2, 1], [-4, -1, 2, -2], [11, 0, -3, -4], [-4, 1, -5, 2], [-6, -2, 4, 5], [-4, 3, 1, -6], [-6, -2, 0, 2], [8, 0, -2, 0], [2, -6, 2, -1], [0, 8, -1, 2], [0, -4, -2, -2], [-5, -3, 6, 2], [5, -1, 1, 1], [14, 4, 0, -2], [-14, -8, 5, 5], [-2, 4, 0, -2], [2, 2, 7, 1], [-6, 0, 0, 6], [0, -5, -4, -4], [12, -5, -3, 0], [-3, 2, 0, 6], [-7, 0, 4, 2], [-6, -8, 6, 8], [-2, 6, 1, -2], [10, 3, 1, 5], [6, 2, -10, -6], [-6, -1, -3, -5], [0, -6, 3, -2], [4, -2, 9, 9], [2, -4, -4, -6], [12, -6, -5, -4], [5, 6, -1, -8], [-7, -1, 0, 3], [15, 5, 0, 0], [4, 0, 2, 8], [-9, -5, 0, 5], [-1, 0, 2, 1], [-3, -8, -2, -10], [6, -2, 3, -9], [18, 0, 4, 6], [-7, 7, -2, 7], [1, -1, 0, -4], [-14, 0, 0, 2], [-2, -2, 10, 6], [3, -5, -6, -1], [-9, 0, 9, 8], [-1, 0, -4, -1], [5, 4, 2, -9], [7, 1, -8, -2], [6, -6, 7, 3], [5, 1, 5, -7], [10, -3, -1, -5], [-12, -2, -1, 0], [14, -6, 12, 0], [-4, 17, -5, 5], [-11, 0, -12, -7], [-18, -1, 0, 0], [3, 4, -4, 2], [25, -2, 1, 0], [15, -4, 1, -6], [8, 5, -8, -6], [-7, -6, 2, -6], [19, -3, 10, 1], [1, 0, 12, 1], [20, 4, 0, 2], [8, 1, -7, -2], [3, 0, 9, 6], [9, 3, -8, -9], [-1, 10, -4, 6], [-8, -7, 3, 10], [6, -5, 10, 14], [-16, -6, -2, 6], [2, 0, 5, 4], [15, -10, 10, 0], [8, 0, 6, -2], [-18, -3, -5, -11], [-3, -8, -2, 4], [1, 8, -4, -12], [-8, 2, -9, 5], [-1, -8, 4, 11], [2, -2, 10, 12], [12, 9, 0, 0], [-7, 17, 0, 8], [-10, -4, 10, 1], [8, 12, -2, -4], [14, -2, 6, -4], [8, 1, -13, -8], [4, 2, 10, 10], [3, 0, -9, -2], [6, 0, -2, 0], [1, -1, 8, 14], [14, 8, -6, -12], [-1, 2, -8, -16], [-16, -4, -5, 8], [-2, -5, 19, 11], [2, -6, 10, -2], [-13, 4, 2, -7], [-32, 0, -3, -1], [12, -6, 3, -10], [10, -8, 16, 12], [-12, -10, 10, 8], [-6, 8, -10, -10], [1, 7, -20, -10], [-14, 8, -6, -2], [-9, 0, 5, 14], [9, -13, -10, -5], [-16, 0, -5, 11], [-10, -16, 12, 3], [-10, -5, -9, -4], [19, 10, -2, -9], [-16, 1, 7, -4], [18, 6, 2, -2], [3, -9, 8, -2], [-20, 8, -4, -4], [-8, -4, -2, -6], [-26, 8, -10, -2], [2, 5, -1, -8], [13, 8, -4, -8], [-24, 5, -4, 0], [-18, -4, 0, 4], [-8, 7, 11, 10], [3, -7, 0, 7], [-18, 15, -1, 2], [-12, 7, 10, -2], [-10, 2, 4, 0], [14, -2, -3, -8], [-6, 3, -15, -15], [-44, 3, -7, 6], [12, -9, -3, -2], [2, -8, 3, -14], [4, 6, 4, 13], [4, 8, -14, -2], [-6, -16, -2, 6], [-26, -2, -7, -7], [-16, 6, -6, -8], [-8, 1, -5, 1], [-25, -3, -8, 5], [18, 8, 6, -10], [-14, -10, -3, -9], [-23, -6, -8, -2], [6, 0, 10, 4], [21, -2, -8, -3], [18, -2, 8, -14], [-20, 4, 12, 10], [-12, 2, -14, -6], [5, 19, -10, -5], [-14, 10, -2, 12], [-10, 12, 7, 3], [-15, 1, -4, 4], [4, 2, -12, -16], [26, -4, 2, 6], [-1, -5, 28, 17], [-11, -13, 0, -8], [5, -5, 16, 13], [-14, 5, -7, -8], [-12, 10, 4, 12], [-4, -11, 6, 12], [0, -14, 14, 12], [-23, 11, -6, 0], [19, -8, 12, 11], [23, 3, -9, -3], [-25, 12, -17, 4], [23, 1, -4, 6], [-6, -6, -18, -10], [-35, -4, 10, 6], [-17, -8, 4, -3], [24, -10, 7, 2], [8, 10, -8, -6], [-17, -8, 11, 14], [-3, 1, -10, 3], [13, -9, 4, 4], [-25, -5, 8, -2], [16, 10, 2, 12], [2, 2, 5, 18], [-4, 6, 13, 15], [-13, 0, -2, -1], [0, 2, 4, -10], [4, 12, 9, 11], [10, 0, -9, -6], [17, 6, 2, 4], [-8, 11, 6, -8], [27, -3, 12, 6], [-4, 2, -13, -3], [5, -15, 10, -1], [-7, -3, -2, 9], [-10, -12, -4, -20], [24, 0, -4, -3], [22, -4, 0, 6], [-25, 3, -21, -5], [18, 11, 1, 1], [-16, 4, -14, 4], [0, 4, -4, -8], [-14, 5, 15, 9], [-3, 3, 1, 5], [-15, 9, -6, -3], [-22, -8, 1, -2], [-28, 1, 9, 10], [4, 2, 6, -12], [-40, 6, -5, 3], [7, 3, 12, 5], [37, -4, 1, 2], [-12, -1, -23, -14], [8, 19, -2, 12], [36, 6, -9, -7], [38, 14, -2, -2], [-1, 2, -14, -4], [-38, 0, 2, -8], [-14, 11, -9, -7], [26, 17, -8, -18], [13, -5, 12, 13], [-16, -13, -5, 12], [-6, 4, -16, -1], [6, 12, 3, 3], [-5, -22, 6, -5], [-15, 5, -8, 2], [31, -14, 7, -6], [-7, 14, 4, -10], [14, -12, 9, -1], [2, -24, 13, -1], [5, -8, 8, 10], [-42, 4, -14, -10], [16, -1, 11, 2], [-3, -4, 6, -3], [11, 11, -8, -13], [-2, -6, 5, 9], [44, 8, 0, 4], [2, -20, 4, 0], [-22, 16, 17, 7], [4, -2, 2, 8], [24, 9, 3, -9], [-26, -16, 6, 4], [7, -10, 6, 4], [22, 2, 9, 13], [-34, 2, -2, -16], [12, -2, -10, -3], [10, -6, 1, 8], [-11, 14, -8, -12], [7, 0, 20, 12], [-24, 26, -9, 10], [22, 1, 10, 6], [7, -10, 16, 12], [-31, -21, 18, 15], [2, -16, 11, 1], [24, 4, -17, -9], [20, -2, -2, 10], [10, -10, 6, 26], [34, 18, -8, -12], [-3, 19, -4, -3], [-11, -12, -1, 4], [-1, 3, -2, 11], [-28, 17, -15, -1], [-7, 7, -16, -17], [-12, 14, -8, 16], [-10, 15, -9, 6], [40, -12, 8, 2], [30, -3, -15, -9], [28, 11, 3, -2], [-27, -2, 0, 8], [-2, 19, 1, -10], [14, -6, 10, 7], [26, 18, -1, 7], [-29, -16, 3, 4], [11, 1, 6, 13], [-4, -12, 4, 7], [24, -3, -11, -4], [55, -9, 16, -3], [18, -4, 12, 12], [16, 12, -8, -6], [25, -5, 24, 15], [-10, 16, -9, -1], [5, 1, -5, 15], [27, -10, 7, 10], [14, -16, 22, 0], [32, -14, 23, -1], [24, -7, -5, -5], [-14, -4, 7, -1], [-7, 17, 13, 13], [4, -3, -19, -7], [29, 9, -6, -5], [19, 20, -23, -12], [-28, 4, 3, 3], [-42, 8, -20, 4], [6, 2, 1, -19], [24, -12, -8, 4], [-52, -6, 10, 8], [14, -1, -16, -8], [6, -16, 6, 4], [54, -4, 3, 7], [-12, -6, -10, -14], [-29, 1, 2, 11], [6, 2, -28, -20], [-6, 2, 0, -18], [-27, -12, 11, 2], [20, 14, -7, 6], [32, -8, 24, -2], [8, 0, -4, 16], [-12, -10, -13, 9], [-7, 10, 12, 23], [6, 17, -6, -6], [0, -28, 2, 11], [8, -12, -2, 4], [1, -1, 15, 17], [11, -8, 2, -18], [-54, 4, -6, 2], [-54, 15, 5, 4], [6, -10, -18, -4], [28, 14, 0, 8], [24, -22, 10, -10], [22, 3, 1, -22], [21, 15, -2, -9], [-12, 8, 0, -8], [-26, 19, 5, 8], [28, 11, -15, -10], [34, 6, -5, 0], [54, 8, 0, 5], [-40, -19, 14, 12], [25, -3, 19, 7], [6, -24, -2, -7], [34, 6, -4, 0], [10, 8, -8, -14], [-48, -9, -6, -10], [-18, -5, -5, -7], [-22, -22, 5, 11], [-13, 21, -10, -13], [30, 3, 17, -9], [-8, -6, 10, -10], [-16, 1, -1, -2], [-72, -4, -2, 3], [5, 21, 11, -13], [-50, -20, 10, 20], [-22, 10, -8, 4], [-36, 16, -4, 6], [-2, 25, -20, -8], [51, -1, 8, 17], [30, 13, -23, -14], [-2, -21, 11, 5], [-26, 10, -18, -14], [2, -6, 4, 13], [-9, 5, 22, 6], [-49, 7, -20, -10], [-7, -11, -13, -1], [-24, -6, 12, 18], [39, 6, -20, -10], [-30, 6, 2, 20], [-5, -8, 7, -12], [-15, 20, 0, 5], [-18, 1, -9, 2], [-31, 0, 14, 16], [12, 7, 5, 4], [-23, -10, -10, -28], [2, 24, -8, -13], [3, 2, 14, -13], [4, -7, 5, 0], [-55, 9, 2, 1], [43, 13, 4, -20], [-65, 3, -12, 2], [32, -10, 4, 16], [-15, 12, 13, 4], [22, -6, 16, 14], [0, -2, -4, 7], [24, 2, -14, -2], [39, -18, 20, 1], [-32, 8, 11, -3], [-41, -4, -20, -2], [-4, -18, 22, 2], [10, 28, 0, -12], [-22, -11, -4, 20], [14, 5, -5, -9], [-23, -19, 14, 17], [48, -16, 20, 0], [-32, 14, -2, 2], [-25, -9, -10, -25], [-32, -22, 15, 11], [-29, -24, 4, 9], [-32, -1, -14, -10], [-55, -1, 14, 6], [19, -2, 18, 12], [-23, -20, 14, 16], [26, 12, 18, -12], [-34, 8, -20, -12], [-31, 7, -15, 13], [-2, -15, 11, -12], [12, 9, 22, -8], [17, 7, -22, -8], [11, 30, -22, -4], [-56, -13, 9, 1], [18, -26, -6, -2], [-12, 0, -14, -22], [-64, 0, -8, -4], [33, -9, 10, 0], [-84, -1, 0, 6], [22, -16, -20, -9], [-46, 0, 5, 1]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2124_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_2124_2_a_i();".
// 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_2124_2_a_i(:prec:=4)
    chi := MakeCharacter_2124_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_2124_2_a_i();".
// 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_2124_2_a_i( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2124_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![15, -8, -12, 0, 1]>,<7,R![-3, 18, -9, -2, 1]>],Snew);
    return Vf;
end function;