
// Make newform 5824.2.a.bv in Magma, downloaded from the LMFDB on 27 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_5824_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_5824_2_a_bv();".
// 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_5824_2_a_bv();".
// 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, -3, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-2, -1, 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_5824_a();"
function MakeCharacter_5824_a()
    N := 5824;
    order := 1;
    char_gens := [2367, 1093, 4161, 4929];
    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_5824_a_Hecke(Kf)
    return MakeCharacter_5824_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, 0, -1], [0, -1, 0], [1, 0, 0], [-1, 1, 2], [1, 0, 0], [-2, -2, 1], [2, 1, 0], [-3, 2, 0], [3, -2, -2], [-3, 4, -1], [1, 3, 2], [0, -2, -2], [-4, 3, 1], [0, -5, -2], [0, 3, 5], [-5, -3, -1], [4, 2, -2], [-4, 2, 4], [-1, 1, 4], [-9, 4, 1], [-4, 5, -3], [3, -2, -7], [-1, 0, 5], [-1, -4, 3], [-2, -6, 3], [-4, 6, 4], [-1, -5, -5], [3, -7, -2], [-6, 5, 3], [1, -7, -1], [0, 2, 2], [-7, -3, -4], [2, 2, 1], [1, 3, 10], [-3, 1, 8], [14, -10, -3], [-4, 2, -4], [-10, 11, 2], [0, 8, -3], [-16, 3, 3], [8, -4, 1], [-11, -7, -1], [2, -8, -6], [8, -4, -8], [4, 4, -5], [-7, -4, -4], [-5, -8, 3], [-2, -6, -10], [-1, -5, -5], [-5, 8, 0], [4, -2, 4], [-8, -5, -14], [-8, 6, 7], [12, 0, 3], [-4, -1, 7], [-12, 2, -6], [-6, -6, -8], [7, 8, 2], [5, -13, -8], [0, -6, -10], [3, 4, -7], [-9, -2, -3], [-4, -4, 5], [-22, 4, 1], [-6, 12, -4], [6, 0, -4], [6, -3, 5], [-12, -8, 8], [5, -4, -5], [-1, -1, -5], [-5, -7, 6], [10, -14, -9], [15, -11, -5], [-1, 13, 4], [-16, 8, 8], [-5, 1, 5], [9, -8, -11], [16, -6, 2], [5, 6, -7], [-8, -6, 9], [-7, 3, -16], [8, 16, -4], [-8, -6, 0], [-12, -4, -4], [11, 6, 0], [-22, 16, 10], [3, 17, -4], [-16, -2, 2], [11, 1, 14], [-8, 14, -3], [-11, -8, -21], [26, -6, 0], [-7, -7, 13], [1, 5, -4], [-10, -12, -8], [-11, -6, -19], [-16, 10, -4], [22, -2, -8], [1, 3, -8], [-13, -4, 10], [-28, -6, 2], [-18, 24, 6], [33, 2, 6], [17, -20, -16], [-10, 4, 2], [23, 2, 5], [14, -13, -16], [-6, 7, 5], [-14, -4, 0], [-26, 2, -5], [-14, -4, -8], [22, 6, -2], [-10, 14, -2], [2, 0, 0], [9, 4, -10], [2, 6, 2], [2, -2, -5], [22, 0, 10], [-25, 12, 4], [-8, 5, 12], [-4, 3, 5], [-16, 0, 5], [-12, 4, -6], [4, -7, 0], [-9, -4, 0], [21, 13, -6], [-14, -2, 7], [-2, -10, 12], [0, 5, 2], [1, -19, 14], [24, -8, 4], [-8, 13, -1], [17, 6, 24], [-20, 1, -6], [14, 7, 0], [8, -14, -18], [-11, 2, 3], [26, -24, -12], [7, -2, 10], [20, 4, 14], [-18, 8, 6], [17, 9, 11], [12, -18, -20], [-30, 6, 5], [-6, 22, 2], [4, 7, 16], [12, 12, -8], [34, 8, 8], [6, -20, 0], [21, -3, 10], [28, -2, -8], [-41, -5, 5], [-12, -8, -6], [-9, 22, 6], [36, -1, -3], [-4, -12, 4], [-8, 1, 12], [-28, -6, 1], [-12, -19, 0], [4, 6, 12], [-13, 14, 12], [19, 11, 16], [-12, -14, 12], [-5, -5, -2], [14, 7, 14], [1, 1, -9], [8, 6, -10], [9, 11, -16], [8, -2, 15], [-1, 1, -6], [40, -10, -8], [-11, -12, -14], [-15, -21, 18], [2, -10, 16], [6, 10, -18], [-32, 2, 12], [14, 20, -6], [32, -4, 1], [-2, 2, 13], [-8, -2, -12], [30, -2, 7], [39, -15, -7], [11, 2, -19], [-9, -5, 12], [-18, -12, 5], [2, 13, 15], [7, -24, -9], [8, 12, 26], [-2, -5, -12], [-16, -18, -21], [6, 10, 8], [-3, -20, 6], [-6, -19, 10], [-3, -30, 10], [-2, -8, 5], [-5, 27, -12], [19, 8, 34], [-2, 25, 18], [22, -14, -2], [15, 3, -6], [-42, -4, 7], [-11, 12, 21], [-8, -26, -8], [8, -19, -12], [8, 18, 14], [-9, -10, -13], [0, -1, -3], [29, -5, 14], [12, 12, 18], [5, 6, -4], [20, 4, 5], [14, 2, 8], [12, 4, 22], [27, -4, 11], [-18, -13, -22], [40, -35, -13], [-12, 0, 2], [-12, 20, 6], [-5, 21, 0], [58, -1, -3], [49, 3, -7], [18, 12, 26], [38, 0, -12], [-46, 4, 10], [34, -7, -13], [-46, 12, -2], [-2, 5, 3], [0, -6, -25], [-19, 29, 10], [11, -7, -29], [28, -28, -21], [0, -6, -10], [-11, -13, -23], [34, 8, -2], [2, 13, -20], [-48, -6, -4], [-6, -18, -6], [-19, 2, -14], [-32, 10, 0], [10, -32, 0], [28, -6, 4], [24, -8, -4], [-14, 28, -10], [-10, 13, -2], [-14, 30, -3], [-16, -9, -8], [-35, 22, 21], [7, 1, 6], [13, -16, -14], [14, 2, 6], [-4, 2, -12], [32, -12, -22], [4, -4, 16], [-10, 28, 12], [-12, 24, 22], [-5, 6, -22], [48, -8, 2], [-10, 8, -28], [4, -21, 0], [-11, -14, -36], [-28, 25, 1], [-27, 16, -9], [8, 22, 31], [-32, -10, -30], [-2, 20, -16], [-4, -10, 4], [-21, 28, 13], [17, -39, -14], [17, 11, -19], [-10, -12, 23], [25, 23, 4], [-20, 22, -8], [11, -2, -16], [10, 12, 3], [-26, 14, -6], [19, -11, -6], [-41, -1, -2], [-6, 24, 36], [-22, 8, 6], [-10, 34, 6], [12, 14, 46], [-36, 18, 16], [-9, 2, 1], [31, 1, 19], [18, -1, -19], [-29, -12, -22], [28, -18, 2], [-44, 4, 10], [4, -30, -17], [32, 15, -3], [-14, -16, -24], [32, -34, -10], [-42, 1, 2], [38, -33, -17], [2, -14, 22], [0, 4, 28], [-18, 40, 26], [-40, 18, 7], [5, 6, -9], [-54, 26, 3], [41, -29, -10], [3, 28, 28], [25, -4, -28], [-33, -16, -20], [-21, -23, 12], [3, -33, -23], [44, -18, -19], [-40, -2, 6], [-8, 15, -35], [28, 0, 27], [-13, -1, 2], [45, 15, 9], [2, -25, 7], [-29, -13, -4], [-4, 24, -4], [-11, 18, 25], [-33, -21, 0], [0, 13, -20], [21, -28, 2], [4, 6, 26], [6, 0, -6], [6, 10, 19], [6, -2, 4], [-24, 16, 28], [-34, -28, 15], [20, -10, 14], [21, -12, 9], [-45, -5, 1], [45, -25, -19], [3, 25, -14], [20, -17, -17], [10, -32, 9], [-36, -3, 18], [9, -27, -2], [18, -7, 24], [-19, -3, -16], [38, -4, -10], [5, 13, -11], [20, 14, 0], [-1, -1, 0], [41, -9, -17], [-23, -7, 17], [-57, -9, -15], [11, 13, 38], [-3, 25, -27], [18, 0, -7], [-7, -37, -8], [0, -15, -12], [-16, 16, -9], [-12, -1, -22], [-47, -11, 10], [-55, -7, 6], [8, -36, -10], [-9, -19, 25], [-26, 0, -5], [-9, -24, -31], [7, -34, 23], [19, 21, 31], [-27, 37, -2], [6, 12, 10], [36, 0, 24], [-8, -3, -1], [21, -29, -22], [-42, 32, 19], [11, -12, -22], [-24, 15, -4], [-13, -29, 0], [10, -37, -9], [-31, 41, 19], [-16, 4, -15], [-47, 39, 6], [-17, -10, -6], [-6, -24, -1], [5, 12, 48], [24, -20, 26], [-67, -7, -21], [-1, 3, 7], [20, 18, 30], [12, -34, 2], [-24, 31, -16], [20, -18, 20], [-21, 19, -8], [27, -5, 10], [-42, -33, 20], [27, 0, -15], [1, 13, -24], [-12, 6, 32], [-47, 3, 14], [-30, 20, 15], [6, -6, 24], [-2, 19, -6], [-36, 4, -18], [-8, -36, 10], [-48, 16, -4], [22, -39, -11], [-30, -10, 22], [18, -22, 4], [-6, -1, -17], [-12, 10, 4], [-49, 20, -5], [-4, -19, -25], [11, -15, 26], [-14, -3, 8], [13, 18, 51], [-52, 16, 19], [-4, 16, -6], [-35, -15, 10], [42, -1, 0], [2, -41, -20], [8, 4, 8], [4, 13, 39], [-29, 0, -42], [-25, -9, 3], [70, 3, 5], [24, -20, -25], [-4, -34, -20], [-42, 32, 20], [14, -8, 36], [-34, 46, 1], [-54, 1, -5], [5, -39, -7], [-13, -27, -12], [50, 0, -9], [16, 18, 18], [-45, 44, 11], [4, 3, 41], [32, 14, -8], [-8, -35, -2], [-30, -32, 12]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_5824_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_5824_2_a_bv();".
// 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_5824_2_a_bv(:prec:=3)
    chi := MakeCharacter_5824_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_5824_2_a_bv();".
// 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_5824_2_a_bv( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_5824_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![-2, -4, 0, 1]>,<5,R![-1, -3, 1, 1]>,<11,R![10, -14, 2, 1]>,<17,R![-74, 0, 8, 1]>,<19,R![-5, 13, -7, 1]>],Snew);
    return Vf;
end function;