
// Make newform 2832.2.a.o 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_o();".
// 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_o();".
// 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, -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_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], [1, 0], [1, -2], [4, -1], [1, -2], [-3, -2], [-3, 3], [5, -5], [3, 1], [8, -1], [-4, 9], [-5, 3], [0, 5], [-1, 6], [6, 3], [3, 2], [1, 0], [-8, 3], [-1, -6], [-5, 8], [-4, 3], [3, 0], [0, 1], [4, -11], [3, 0], [-6, 6], [0, 2], [-9, 5], [-9, 3], [-9, 0], [-3, -8], [-2, 14], [9, 2], [-15, 2], [11, 5], [12, -9], [9, 0], [4, 9], [14, -13], [14, -1], [7, -4], [-2, 15], [3, -12], [8, 0], [2, -14], [2, 9], [7, -3], [16, -4], [27, -3], [-14, 3], [-18, 6], [-5, 4], [-4, -12], [1, -10], [0, -12], [0, -1], [-5, -4], [11, -2], [1, -4], [0, 6], [-1, 15], [21, -1], [0, 16], [13, -25], [-3, -11], [-13, -10], [-18, 18], [-23, 5], [-10, -13], [-27, 0], [5, -13], [-4, 16], [9, -24], [23, 7], [-3, -12], [15, 2], [26, 4], [3, 0], [-9, -5], [-30, 12], [-14, 28], [1, 0], [-14, 1], [15, -7], [33, 1], [-5, 1], [-19, 16], [-10, 27], [-7, 19], [-9, 3], [24, -24], [23, -5], [-25, 19], [-16, 17], [-5, 12], [14, -11], [-12, 29], [-4, 17], [-27, 8], [3, -18], [-27, 9], [-6, -12], [-15, 22], [16, -17], [-21, 12], [19, -4], [-17, 20], [8, 5], [20, -14], [25, -1], [-9, 14], [-16, -14], [27, -3], [17, -18], [21, 12], [-15, -8], [15, 3], [-32, -8], [32, 5], [3, -3], [0, 19], [-2, -4], [-44, 10], [-39, 0], [-6, -18], [36, -11], [-18, -6], [-13, -1], [-26, 0], [27, -4], [15, -39], [23, 1], [34, -18], [-43, 1], [21, 6], [-23, 21], [6, 14], [14, -6], [2, -2], [19, -7], [8, -14], [6, -29], [-21, 6], [19, -10], [-2, -27], [41, -10], [-25, 13], [23, -32], [-22, 4], [-37, 11], [-42, 16], [-6, -6], [4, 12], [29, -4], [7, 8], [-18, 39], [-22, 22], [-39, -6], [-13, 40], [-5, 28], [-4, -13], [-8, 8], [9, -15], [-29, -11], [5, -16], [45, -22], [7, -19], [16, 23], [-8, -4], [-6, 0], [-35, 16], [-14, 0], [-17, -5], [-21, 22], [-44, 8], [3, 6], [49, 2], [6, 34], [31, -27], [-6, -20], [2, 16], [-24, 12], [45, -28], [26, 2], [-13, 40], [25, -47], [10, -30], [4, -22], [27, -48], [-27, 31], [7, 32], [-5, -14], [4, 12], [-2, 37], [8, 20], [3, 3], [-13, -9], [6, -29], [-32, -13], [-21, 7], [-20, -8], [-11, 44], [-39, -3], [13, 9], [18, 6], [-6, 23], [13, 6], [27, -21], [-47, 25], [28, -30], [51, -9], [19, -32], [23, -33], [42, 0], [7, -2], [21, 13], [11, -12], [24, -9], [-3, 15], [29, -10], [49, -16], [27, 4], [-8, -20], [36, -19], [32, -38], [-6, -21], [-1, -31], [46, -46], [24, -12], [21, 3], [6, -15], [41, -30], [-15, 7], [19, -8], [2, -8], [-41, 4], [-27, -2], [14, 25], [27, -6], [-16, -17], [-57, 6], [-32, 0], [-13, 24], [-60, 14], [-27, -13], [22, -25], [15, -40], [-33, -18], [0, 7], [3, 6], [-47, -1], [-27, -29], [62, -13], [-3, 18], [-35, 8], [-35, 2], [27, -6], [40, 6], [1, -16], [47, -5], [39, -30], [-9, 8], [42, -46], [18, -30], [11, 4], [-60, 12], [-31, -17], [72, -2], [-35, 36], [-33, 40], [-26, 12], [6, 45], [1, 9], [-15, -16], [1, 30], [1, -9], [6, -31], [5, 0], [-5, 0], [-25, 20], [63, 12], [34, 14], [-24, -38], [-6, -36], [39, -6], [-8, 7], [-15, 2], [-11, 55], [-43, 6], [-14, -32], [-57, 34], [18, -6], [27, -59], [-23, 40], [33, -52], [3, 6], [12, -9], [7, 44], [0, 9], [11, 34], [54, -31], [15, -10], [-25, -26], [66, -12], [48, -32], [21, -44], [13, 28], [22, 35], [-42, 45], [38, -18], [-59, -16], [11, -11], [-49, 8], [0, 3], [-7, 23], [39, 20], [-52, 25], [33, -42], [-4, 42], [13, 14], [42, 0], [-42, 6], [52, -47], [42, -4], [1, -16], [-42, 24], [-37, 34], [10, -42], [24, -40], [26, 31], [-33, 33], [-16, -38], [-16, 12], [-25, 32], [-33, 73], [8, -13], [14, 15], [6, 12], [2, 15], [13, -42], [22, -6], [-41, 68], [-42, 62], [-72, 4], [-30, 6], [-9, 14], [-39, 24], [-36, -12], [7, 20], [1, -28], [-13, 25], [54, -19], [-42, 41], [0, 37], [-4, 9], [-28, 32], [18, -36], [-66, 39], [55, -7], [7, 22], [15, -54], [-35, 43], [0, -20], [37, 2], [-14, 39], [-60, 45], [-68, -8], [0, 54], [18, -4], [44, -43], [45, -52], [45, 6], [9, -9], [48, -22], [46, 9], [-51, 45], [-15, -39], [6, -45], [58, -40], [61, -18], [64, -22], [12, 15], [33, -3], [63, -6], [15, -50], [21, -10], [1, -18], [-18, 33], [-1, -21], [27, 2], [-3, -34], [63, -41], [-53, -5], [-14, -10], [-24, 9], [12, -38], [28, -9], [22, -64], [45, -67], [19, -74], [49, -64], [18, -52], [26, 30], [26, -11], [-17, 23], [-37, -30], [-22, 46], [6, -54], [3, -24], [-15, 12], [-61, 45], [18, 7], [25, 11], [-59, 18], [21, -30], [-36, -24], [20, -52], [52, -3], [-23, 52], [-42, 49], [13, 1], [-33, -22], [-13, 19], [16, -26], [12, 36], [0, 40], [-53, 23], [-48, -23], [-32, 51], [27, -42]];
    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_o();".
// 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_o(:prec:=2)
    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_o();".
// 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_o( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2832_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![-5, 0, 1]>,<7,R![11, -7, 1]>,<11,R![-5, 0, 1]>],Snew);
    return Vf;
end function;