
// Make newform 8624.2.a.bh in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_8624_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_8624_2_a_bh();".
// 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_8624_2_a_bh();".
// 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 := [-2, 0, 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_8624_a();"
function MakeCharacter_8624_a()
    N := 8624;
    order := 1;
    char_gens := [5391, 6469, 7745, 3137];
    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_8624_a_Hecke(Kf)
    return MakeCharacter_8624_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, 1], [2, 1], [0, 0], [-1, 0], [1, -2], [2, 4], [-2, -1], [2, -3], [-3, -4], [-4, 0], [-8, 1], [4, -1], [0, -4], [-2, 6], [-2, -7], [-7, -1], [-9, 2], [-7, -3], [4, -5], [8, -1], [9, -3], [2, 10], [-4, 6], [1, -2], [-9, -2], [12, -1], [-4, -5], [8, -6], [-11, -2], [-3, 9], [-2, -1], [-11, 4], [0, 0], [12, -4], [3, -9], [-12, 4], [3, 9], [1, -9], [7, -2], [9, 7], [2, -4], [10, 2], [12, -7], [-9, -6], [10, 7], [-6, 1], [10, 1], [-26, 2], [-12, 8], [0, -1], [1, 15], [-8, 3], [-12, 10], [11, -10], [-7, -17], [-8, -4], [-11, -11], [-1, -2], [-4, -9], [-22, 1], [8, -2], [0, -7], [4, -9], [15, -4], [20, 8], [17, -5], [-24, 3], [-16, 1], [0, 0], [14, 8], [-15, 3], [2, 9], [-3, 12], [-1, 19], [12, 13], [-10, 9], [-22, 0], [7, -8], [10, 9], [-12, 10], [12, 8], [19, 1], [-12, 10], [-9, 13], [10, 16], [28, 4], [-6, 4], [-3, -8], [-10, 2], [-34, 0], [-19, -5], [4, -4], [-22, -2], [-8, 10], [-17, -15], [2, 8], [0, -20], [0, 9], [-27, -10], [-8, 19], [16, 6], [2, -5], [-4, 0], [-8, 13], [21, 8], [-35, -7], [6, 21], [-20, 16], [2, 24], [-26, 12], [6, -16], [-25, 12], [12, 24], [-36, -9], [-13, -20], [3, 1], [-8, -27], [0, 13], [12, 0], [-2, 12], [-10, -11], [24, -8], [-15, -1], [21, -5], [5, 22], [12, 17], [-10, -6], [-6, -30], [13, 0], [10, -30], [2, -8], [-40, 4], [14, 4], [-14, 12], [-6, 12], [-12, -24], [-2, -11], [2, -4], [-24, 16], [4, 20], [-21, 6], [18, -18], [-14, -25], [-26, -3], [-10, 6], [-14, 0], [12, -16], [7, 9], [-14, 15], [-3, -16], [19, 18], [-3, 9], [-13, -7], [-22, -8], [22, -6], [-8, 10], [15, -18], [18, -1], [-19, 4], [-32, 2], [-10, -11], [8, -20], [35, 9], [40, 0], [-10, -30], [20, 13], [-16, -2], [36, 16], [26, -12], [-10, -18], [-48, -9], [19, 5], [10, 32], [-2, -11], [3, -6], [4, -5], [-6, 36], [8, 26], [-2, 16], [-12, 25], [14, -14], [-40, 0], [12, 16], [0, -17], [-12, 25], [-39, 4], [47, 3], [-6, -3], [17, 7], [-32, -8], [16, -15], [-15, 3], [-14, 5], [36, -12], [-31, 0], [0, -32], [4, -37], [40, -17], [3, 31], [-3, -12], [-7, 7], [-22, 7], [-20, 27], [45, 1], [16, 4], [20, 4], [34, 17], [-10, 3], [11, 5], [-20, 11], [-6, 12], [12, 0], [4, 22], [-3, 33], [31, -8], [39, 17], [-14, -41], [8, -8], [18, -4], [-15, 22], [-45, -15], [31, 0], [6, -25], [2, -18], [7, 4], [33, 2], [-24, -11], [3, 3], [26, -2], [12, 28], [14, -22], [9, -1], [14, 24], [33, -3], [-7, -1], [60, 4], [-7, -8], [25, 9], [12, 11], [-8, 6], [-24, 8], [16, -12], [-12, -19], [-8, -5], [-18, -4], [-2, 11], [-9, 31], [-22, -1], [15, -27], [3, -16], [32, -24], [-22, 27], [4, -50], [63, 8], [10, 2], [-18, 32], [-28, -8], [16, -11], [10, 41], [40, 8], [4, 16], [32, -14], [7, 14], [1, 20], [-1, 39], [-16, 36], [5, 32], [-42, 3], [32, 2], [2, -20], [-4, 12], [-13, 20], [-12, -10], [2, -39], [4, -13], [35, -13], [-11, -38], [-60, 7], [66, -11], [-11, -49], [10, -30], [-51, -3], [45, -6], [-46, 10], [-2, -2], [-33, 34], [42, -24], [-2, -39], [-8, -12], [2, -8], [-33, 37], [-54, -5], [6, 2], [1, 2], [-31, 0], [14, -19], [40, -24], [30, -2], [14, -7], [58, 15], [-17, -16], [45, 5], [17, 11], [-7, -41], [7, 32], [15, -5], [16, 24], [-18, -26], [16, 2], [-5, -23], [-8, 33], [-28, -8], [68, -6], [51, -1], [-2, -23], [27, 37], [-20, -26], [28, 14], [-30, 29], [-60, 7], [5, 24], [-33, 10], [-16, 7], [-30, 21], [-51, -26], [40, -2], [-40, -30], [41, -25], [-33, -14], [-24, 40], [28, -39], [15, 33], [18, -9], [-18, -23], [57, -23], [-38, -25], [-48, -32], [-57, 16], [48, -10], [-72, -7], [8, -12], [-43, -26], [-14, 17], [32, 5], [-46, -17], [-38, 7], [-63, 15], [80, 8], [26, -5], [-28, 16], [36, 22], [44, 21], [63, -15], [-52, 12], [36, -9], [52, 24], [10, -42], [24, -21], [-52, 16], [25, 52], [-52, -17], [-60, -16], [-24, 0], [63, 13], [47, -4], [-4, 36], [-4, 54], [-6, -12], [-1, -1], [-32, 38], [-11, 9], [24, -30], [-49, -15], [-88, 0], [29, 11], [-8, 26], [70, 8], [-54, 8], [28, -28], [22, 27], [-42, 32], [-63, 17], [26, -28], [-52, -8], [6, -6], [-42, -3], [-24, 21], [-12, 32], [18, -22], [21, -24], [6, 21], [-25, -51], [3, 31], [20, 31], [8, 8], [-69, 11], [15, 12], [53, 9], [19, 42], [-13, 24], [1, -38], [5, -23], [-77, -16], [-27, -22], [-32, -18], [36, -41], [0, 4], [-26, 16], [-27, -35], [2, 29], [16, 16], [-37, -21], [10, 30], [-22, -15], [58, 8], [-73, 21], [-16, -32], [-13, 40], [-3, 15], [28, 17], [-25, 48], [-14, -18], [100, 3], [29, 40], [88, 0], [5, -23], [-2, -48], [-11, -7], [17, 49]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_8624_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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