
// Make newform 7623.2.a.bn in Magma, downloaded from the LMFDB on 08 May 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_7623_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_7623_2_a_bn();".
// 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_7623_2_a_bn();".
// 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_7623_a();"
function MakeCharacter_7623_a()
    N := 7623;
    order := 1;
    char_gens := [848, 4357, 4600];
    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_7623_a_Hecke(Kf)
    return MakeCharacter_7623_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, 1], [0, 0], [-1, 2], [-1, 0], [0, 0], [3, -2], [2, 0], [-5, 4], [2, 0], [5, 0], [4, 4], [5, -4], [-4, 4], [2, 4], [-3, -4], [0, -4], [5, -8], [-6, -4], [-7, 10], [-4, 4], [1, 6], [-6, 4], [14, -4], [-6, 4], [-10, 12], [16, -4], [-4, -4], [-3, 14], [4, 4], [12, -4], [-10, 12], [0, 12], [-10, 12], [-4, 8], [21, 0], [-10, 0], [10, -4], [-7, 2], [14, -12], [-14, 4], [-6, 20], [0, 8], [-22, 4], [-8, 4], [2, -16], [14, -16], [6, -20], [2, -16], [10, -4], [14, 0], [2, 8], [3, -18], [3, 10], [11, 0], [-9, 14], [21, -6], [6, -12], [19, -16], [2, -20], [5, 4], [-1, 12], [0, 0], [-4, -16], [0, 0], [2, 8], [16, -8], [-16, 0], [34, -4], [8, -8], [11, -18], [-11, 10], [16, 8], [-16, 0], [-6, 0], [15, -2], [-12, 8], [32, -4], [14, 8], [26, 0], [14, -4], [-17, 0], [-5, -20], [17, 2], [26, -12], [-1, -16], [-14, 0], [6, -4], [26, -20], [6, 8], [-3, 6], [-23, 8], [-10, -16], [-20, 16], [17, -18], [23, -2], [-16, 16], [-14, -12], [19, -18], [21, -12], [-8, 20], [-26, 0], [-23, 24], [-4, 16], [-2, 0], [-6, -24], [20, 4], [-17, 32], [30, -16], [2, -4], [9, 6], [15, 8], [24, 0], [12, -24], [-20, 16], [-12, 24], [4, -12], [14, -32], [-5, -28], [-24, -8], [5, -18], [20, -28], [-12, -8], [24, -4], [-32, -8], [24, -24], [-38, 16], [-41, 4], [11, -20], [-10, 4], [-6, 20], [-26, -16], [5, -22], [9, -10], [-35, 12], [18, 4], [-1, 10], [3, 10], [13, -36], [41, -2], [17, 20], [-47, 4], [-37, 24], [9, -26], [-23, -2], [-8, -8], [29, -36], [10, 12], [-34, 12], [22, -8], [0, -16], [28, 0], [-37, -2], [-9, -10], [4, 8], [4, 32], [-4, 36], [-16, -4], [-3, -6], [6, 20], [46, -12], [44, 0], [-11, 12], [32, -28], [-25, 8], [-10, -4], [40, 0], [5, -10], [-14, 44], [26, -52], [7, -6], [49, -10], [-10, -28], [-12, 24], [8, -12], [50, 0], [18, 12], [30, -8], [26, -12], [9, -32], [-27, 18], [-35, 14], [14, -12], [6, -24], [26, 0], [12, 0], [15, 18], [4, 24], [-2, 0], [-40, 24], [6, 20], [-24, 0], [27, 2], [-39, 26], [-27, 38], [-43, 22], [-23, -6], [50, -4], [-22, -8], [-34, -16], [24, 12], [-2, -16], [-3, 16], [2, 24], [-11, -10], [44, 0], [-14, -12], [36, -12], [35, -30], [18, -40], [-16, -4], [64, -4], [-23, 30], [-45, 18], [-4, 24], [-24, -20], [26, -20], [28, -36], [16, 20], [0, -20], [36, -24], [-52, 8], [-15, -24], [4, 12], [-13, -22], [50, 0], [-12, -36], [-23, -22], [-2, -12], [45, 0], [-5, -30], [-2, 0], [-43, 20], [22, -40], [17, -20], [24, 4], [-28, -20], [6, -36], [45, -48], [-10, 0], [37, -52], [14, -24], [4, -16], [-12, 0], [22, 0], [-32, 48], [18, -32], [20, 16], [45, 8], [-64, 12], [5, -22], [46, -4], [46, -52], [-24, -24], [52, 0], [-16, 20], [-24, -8], [21, 4], [37, -20], [1, -10], [37, -34], [-52, 0], [-8, 24], [58, 4], [-19, -14], [13, 10], [-14, -36], [-52, 0], [59, 6], [38, -44], [14, 40], [-36, 48], [-35, 50], [-36, -4], [20, 0], [-3, 6], [52, -24], [-14, 36], [-34, -16], [24, 24], [-22, 44], [-8, 36], [36, -16], [-10, -24], [-15, 18], [3, -12], [46, -20], [-9, -8], [-30, -8], [-6, 56], [30, -44], [-24, 60], [-16, 0], [-19, 20], [-44, 48], [30, -24], [6, -12], [28, -16], [50, 4], [18, -24], [-9, 20], [55, 2], [23, 16], [52, 16], [8, 24], [-27, 50], [-17, 0], [16, -16], [-48, 40], [-24, 32], [-32, 36], [-32, -28], [16, 0], [1, 4], [32, -32], [60, 0], [-34, -4], [-8, -32], [-40, -8], [-30, 24], [-30, 16], [-17, 4], [27, -24], [14, -12], [-44, 8], [-33, 12], [-18, 12], [32, 8], [12, 8], [31, 14], [-7, -48], [-38, 28], [54, 8], [87, -8], [20, 28], [-14, 4], [-55, 48], [-45, 36], [-60, 24], [-4, 52], [-8, 24], [14, -32], [-54, 52], [42, -76], [3, -54], [24, 28], [65, -34], [12, -44], [-28, 0], [-38, 8], [-42, 68], [-12, -16], [-83, 0], [-32, -20], [-17, 0], [48, 0], [24, -24], [13, -36], [-26, 32], [49, -12], [20, 20], [24, 4], [26, -28], [16, -28], [-27, 54], [-22, -16], [63, 0], [-60, -4], [82, -24], [60, 4], [-42, -4], [-54, -20], [63, -26], [-17, 24], [8, 32], [-25, 28], [79, 8], [-57, 6], [-3, -26], [22, -32], [18, 28], [21, 22], [18, 0], [-36, 28], [33, -60], [60, -32], [29, 20], [-79, 22], [24, -16], [-60, 12], [43, 4], [65, 8], [42, -76], [-52, 48], [14, 8], [-10, -24], [-42, 24], [-13, -40], [-91, 2], [-72, 24], [81, -32], [31, -42], [-22, 48], [-28, 52], [50, -36], [34, 4], [9, 0], [-5, -52], [-46, 16], [-4, 8], [-4, 8], [42, -12], [-6, -24], [-30, -40], [-14, -32], [54, 12], [7, -14], [9, -6], [16, -16], [66, -20], [-34, 40], [-2, -4], [15, 22], [30, 4], [28, 4], [64, -64], [55, -30], [-24, 64], [9, 28], [-22, -4], [10, 4]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_7623_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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