
// Make newform 2832.2.a.t in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_2832_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_2832_2_a_t();".
// 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_2832_2_a_t();".
// 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 := [-1, -4, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-3, 0, 1]];
    Rf_basisdens := [1, 1, 1];
    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_2832_a();"
function MakeCharacter_2832_a()
    N := 2832;
    order := 1;
    char_gens := [2479, 709, 1889, 769];
    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_2832_a_Hecke(Kf)
    return MakeCharacter_2832_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], [1, 0, 0], [-1, 1, -1], [-3, -1, 0], [1, 1, 1], [1, -1, -1], [2, -2, 3], [-2, 0, 1], [0, 2, 1], [-3, 1, 2], [-5, 1, -2], [-2, -2, -1], [-1, 3, -2], [-1, -5, 3], [-5, 1, -4], [1, -5, 1], [-1, 0, 0], [1, 1, 4], [-5, -1, -5], [-9, 3, -1], [1, -3, -4], [-1, 3, -1], [-1, 5, -6], [-9, 3, -4], [5, -5, 1], [-4, -2, 0], [2, -6, 4], [-10, -4, 3], [-10, -2, 3], [-3, 7, 1], [-3, 1, 1], [0, 8, -6], [-1, 5, -1], [-1, 3, -7], [-12, -4, -1], [1, 3, -6], [-5, -3, -5], [3, -3, 0], [-13, -3, 2], [-1, 11, 2], [17, -3, 3], [11, -1, 4], [5, 5, 3], [4, 2, -2], [-4, 2, 4], [1, 7, 2], [0, -6, 5], [0, 8, -4], [8, -2, 5], [11, 11, -6], [0, -2, -4], [7, -5, -5], [8, -10, 2], [-9, -5, 5], [12, -6, -6], [9, -5, 12], [1, 15, -3], [9, -7, 3], [5, -5, 3], [-14, -4, 2], [-2, 4, -3], [14, -10, 3], [8, 4, 8], [-22, 0, 1], [-10, -2, 5], [9, 3, 9], [-4, -4, -6], [-6, -6, 5], [3, -11, 12], [-9, 1, -13], [4, 4, 1], [0, 0, 4], [-1, 3, -3], [12, 4, -7], [5, 13, -3], [-27, -3, -1], [-10, 0, 8], [-7, 3, 1], [-14, 2, 3], [-2, -20, 4], [-10, 2, -2], [-1, 1, -1], [1, 3, 4], [-18, 6, -15], [4, -18, 1], [20, 10, -7], [21, -1, 11], [-13, 7, 6], [6, -10, -9], [14, 0, -3], [0, -4, -12], [4, 2, 7], [-4, 10, 3], [-5, 5, 4], [-1, 15, -9], [-7, 3, 0], [15, -9, -8], [-9, 11, -18], [13, -3, -3], [3, 1, -11], [-12, 2, -3], [-6, -4, 4], [-11, -3, 5], [33, 9, -4], [29, -3, -1], [-5, 21, 1], [1, 5, -5], [-9, -5, -2], [10, 6, -4], [-16, -4, 5], [1, 1, 3], [14, -12, 18], [-6, 18, -11], [15, -13, 1], [17, 5, -3], [17, 3, 11], [4, -10, -1], [-8, -8, 12], [11, 11, -2], [20, -14, 1], [-23, 5, 2], [14, -4, 4], [2, 0, -6], [15, 3, 9], [12, 16, -2], [-17, 15, -4], [16, 6, -4], [14, -12, -7], [-38, -6, 2], [11, 9, 5], [-12, 6, 9], [-18, -16, 3], [-16, -16, 2], [0, -4, -9], [-17, -3, -9], [18, 2, -7], [12, -10, 20], [-12, 4, -10], [-12, -10, 8], [-12, -16, 15], [-6, -10, 8], [-33, 3, -2], [3, 3, 7], [-7, 13, -5], [17, -7, -4], [1, -11, 1], [10, 14, -15], [9, 11, -11], [10, 2, -6], [2, -8, 5], [38, -8, 0], [8, 6, -8], [20, -16, 4], [-9, 7, 5], [15, -9, 19], [-9, 25, 2], [-20, -12, 10], [17, -1, -5], [-31, -1, 1], [-19, 3, 1], [-7, 15, 4], [-4, 2, 2], [-6, -24, 11], [-2, 12, -13], [31, -7, 7], [-11, 9, -7], [-4, -14, -7], [-3, -7, 14], [36, 2, -6], [10, 0, 12], [-3, 13, 9], [2, 20, -8], [12, 10, -1], [-5, 5, 1], [8, 0, 16], [9, -1, 17], [3, -1, 13], [-16, 2, 0], [-42, 8, -13], [10, -4, 4], [-6, -6, 10], [-36, 0, 4], [3, -11, 11], [0, -22, -4], [3, -1, -5], [-30, 10, -7], [-8, -10, -4], [6, 18, -20], [-27, 3, -23], [-16, -10, -1], [-3, 11, -19], [-5, 3, 15], [-4, -4, -8], [5, 21, 4], [-8, -12, -20], [-26, 6, 11], [-12, 16, 5], [19, 19, -2], [33, 1, -4], [22, -4, 17], [8, -14, 18], [5, 1, 9], [-12, 24, -9], [10, 10, -11], [0, -32, 6], [23, -5, -2], [21, -19, 13], [-26, -8, 9], [-2, 10, -7], [-26, 2, -20], [2, -2, 7], [-29, 1, 1], [-4, 2, 7], [30, -14, 14], [17, 1, 3], [-10, 6, 1], [-25, -5, -17], [-11, 13, -22], [12, -6, 19], [15, -23, 11], [7, 1, -5], [-39, 5, -5], [-52, -2, 6], [23, 5, -8], [-6, -14, 0], [31, -9, 30], [30, -2, 9], [16, 4, 6], [-36, -8, -12], [-34, -16, 5], [-39, 13, 2], [-11, 9, -23], [-32, 10, -9], [-15, -13, 9], [-30, 18, -10], [-1, -21, 3], [-43, -9, -9], [17, -15, 6], [-9, 15, 11], [29, -1, 12], [-15, -11, -1], [8, -8, 24], [35, -17, 7], [10, -24, 18], [-26, -14, -1], [-1, -15, 6], [-3, -7, 19], [3, 3, -9], [1, -25, 16], [13, 21, -21], [2, 2, 27], [-16, 0, 1], [31, -3, 16], [-25, 21, 3], [9, -17, 15], [31, -5, 25], [-31, 3, -19], [-2, -6, -16], [-21, 9, -5], [0, 12, -3], [7, -9, 11], [-9, 15, 3], [-8, 14, -28], [0, -2, -20], [35, -11, 33], [-4, 20, -16], [30, -2, -13], [42, -16, 22], [1, 9, -3], [-25, -11, -23], [30, 0, 12], [-23, 3, -6], [-30, -22, 13], [-3, 25, -15], [-37, -15, -9], [24, 2, 19], [9, -21, -6], [25, -9, 31], [-31, 7, -27], [31, -1, 3], [-1, 19, 3], [-4, 12, 2], [-22, -2, -20], [-6, 4, 16], [-53, -1, 3], [-19, -13, 6], [-27, 7, -1], [38, 14, -9], [33, -7, 17], [-14, 16, -8], [-13, -3, -15], [52, 4, 6], [50, -6, 21], [-37, -33, 17], [33, -9, 19], [-37, 13, -15], [37, 7, -12], [11, 1, -7], [43, 9, -14], [31, -21, 19], [-3, -31, 8], [-5, -11, 17], [3, -13, 15], [-46, -2, 10], [8, 28, -12], [-61, 1, -1], [17, -7, 17], [3, -13, -18], [13, 15, 4], [-32, 14, -4], [9, 5, -15], [-6, -10, -11], [15, 1, -3], [-31, 7, 2], [30, 4, -7], [21, -5, 21], [-17, -3, -30], [15, 23, -3], [-38, -4, -22], [47, -3, 11], [-38, 14, -10], [-8, -14, -4], [-9, -1, -34], [-30, -30, 14], [-7, -5, -17], [-2, 20, -12], [31, -5, 15], [-8, -16, -18], [12, -36, 20], [7, 3, 18], [8, -12, 19], [-38, 4, -26], [-28, -8, -4], [-1, 31, -9], [34, 24, -9], [-7, 7, 12], [11, -1, -8], [22, -16, -4], [15, 11, 22], [27, 3, 25], [16, -10, 28], [13, 7, 1], [-4, 38, -4], [-16, -12, 8], [-12, -18, 16], [-9, -1, 3], [-5, -11, -9], [-8, -4, 16], [-3, -43, 15], [-1, 13, -1], [-24, -6, -7], [25, -11, -16], [-47, 1, 4], [-49, 21, -10], [-25, -25, 6], [4, 6, -26], [22, 38, -6], [-25, 13, -2], [26, 34, -23], [13, -3, -1], [35, 1, 13], [-2, -22, -1], [12, 20, 0], [37, 13, -19], [7, 5, 6], [-5, 3, 20], [12, 2, 18], [-26, 10, -40], [10, 24, -20], [19, 5, 8], [7, 15, 5], [25, -19, -7], [-66, -2, -9], [14, -2, 8], [25, 17, 12], [-2, 36, -9], [-58, 8, -9], [43, 7, 18], [10, -12, 4], [-29, -23, -5], [22, -20, 6], [-31, -31, 0], [20, 14, 5], [-5, -39, 17], [45, -15, -9], [13, -31, 13], [3, -45, 13], [-11, -35, -4], [-68, -18, 11], [3, -9, -17], [21, -1, -13], [-26, -6, -1], [-14, 4, -23], [12, 48, -22], [3, -11, -18], [2, -36, 14], [17, -5, 16], [6, -4, 20], [-20, 10, -19], [-3, 23, -7], [1, 39, -29], [-42, 16, -16], [-4, 8, 2], [-31, 37, -8], [16, -16, 13], [19, 19, 7], [64, -10, 16], [12, -10, 4], [21, -27, -17], [25, -7, 17], [-10, -10, -11], [27, -25, -16], [36, 6, 31], [-29, 23, 5], [63, -11, -1], [44, -26, 18], [8, 32, -32], [-33, -27, 10], [-29, 21, -5], [-55, -1, -14], [-18, -2, -11], [13, 23, -3], [12, 26, 19], [-2, 14, -8], [12, 18, 14], [-32, -14, 26], [42, -12, 13], [-5, 31, 10], [-67, 3, -16], [45, -19, 43]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2832_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_2832_2_a_t();".
// 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_2832_2_a_t(:prec:=3)
    chi := MakeCharacter_2832_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_2832_2_a_t();".
// 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_2832_2_a_t( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2832_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![-2, -5, 2, 1]>,<7,R![16, 23, 9, 1]>,<11,R![-4, -11, -2, 1]>],Snew);
    return Vf;
end function;