
// Make newform 7623.2.a.cg in Magma, downloaded from the LMFDB on 20 April 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_cg();".
// 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_cg();".
// 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, 2, -4, -2, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 1, 0, 0], [-2, -2, 1, 0], [1, -4, -2, 1]];
    Rf_basisdens := [1, 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_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, 0, 0, 1], [0, 0, 0, 0], [1, 0, 0, 1], [-1, 0, 0, 0], [0, 0, 0, 0], [3, -1, 0, 0], [-1, -3, 1, -2], [5, 0, -1, 1], [2, -3, 1, 0], [0, -1, -3, 2], [0, -1, 3, -1], [1, -2, 1, 2], [1, 1, 0, 3], [4, -1, 0, -3], [2, -1, -4, 0], [0, 2, 2, 2], [1, -2, 0, -3], [-5, 4, 3, -1], [-1, 4, -2, 0], [2, 2, -2, 3], [9, 1, 0, 2], [9, -6, -3, 0], [-2, 4, 1, 3], [-5, -4, 0, -5], [-1, -1, 0, 2], [-12, 2, -1, 1], [1, -3, -2, 4], [2, -2, 0, -7], [9, -1, 3, 5], [-6, 4, 0, 0], [4, -1, 2, -3], [-7, -1, -5, -4], [0, -2, 2, 1], [5, -1, 2, 8], [0, 8, 2, 5], [2, 3, 4, 5], [-12, -1, -3, -1], [-3, -2, -5, -6], [2, 0, -1, -3], [15, -1, -1, 2], [-4, 4, 4, 2], [-10, -7, 1, -5], [-12, -5, -1, -8], [6, 3, 0, 3], [16, -7, -1, -1], [5, -2, 5, -3], [3, 3, 3, -9], [0, 9, 3, 9], [-10, 2, 1, -1], [10, 0, -2, 6], [2, 4, -4, 3], [0, -7, 3, 5], [3, -8, -3, 1], [-2, 6, -2, -4], [12, -7, 2, 4], [0, 3, 3, -4], [0, -4, -2, -4], [2, -3, -7, -1], [-1, 3, -1, -1], [2, 3, 5, -5], [-2, 0, 6, -8], [-3, -7, 5, -8], [-5, 8, -3, -3], [-2, 9, 6, 2], [2, -9, -5, -9], [-12, 7, -3, -10], [-14, 2, 1, -2], [1, 4, 3, -8], [-8, 7, 9, -6], [18, 7, 1, 9], [-8, 2, 4, 2], [12, -7, 1, 0], [-13, 4, -5, 3], [6, 7, 2, 11], [-6, 6, 1, -14], [-24, 13, 6, 2], [10, -14, 0, -12], [-10, 10, 2, 4], [-14, 1, -1, -3], [5, -12, -5, -1], [17, 2, 0, 7], [7, -10, -8, -2], [-4, 0, 4, -2], [11, 9, 6, 6], [-14, -4, -4, -4], [-8, 5, -5, 12], [4, -13, -7, -5], [8, -9, 0, 3], [5, 7, 1, -10], [17, -6, -1, -2], [17, 7, -4, -3], [-10, -12, 7, -5], [-13, -6, -4, -12], [-26, 1, 7, -2], [8, 12, -1, 4], [-4, 18, -1, 13], [18, 7, 0, 12], [23, 0, 4, -5], [-1, 9, -4, 10], [4, -1, -10, 9], [11, -12, 1, -4], [4, -14, 4, -6], [13, -3, -1, 0], [-8, -3, -9, -2], [14, -6, -2, -6], [-3, -18, -3, -21], [3, -18, 0, -7], [21, 7, -5, 4], [-20, 4, -2, 0], [1, 7, 2, -2], [5, -9, 2, -2], [12, -1, -6, 1], [-20, 6, 0, -4], [-12, 5, 9, -7], [10, 0, 7, 2], [-16, 6, 14, -5], [14, 8, 2, 6], [-6, 13, 0, 14], [-4, -1, -9, 12], [-14, 2, 6, -9], [8, 1, -5, -3], [15, -9, -3, -7], [22, -6, 3, -13], [-2, 3, -9, -5], [-6, 4, 2, 2], [-4, 9, 11, 6], [21, -12, 2, -14], [-4, -16, -4, -14], [5, 3, -10, 4], [-3, -8, 9, -15], [17, -12, -7, -6], [-22, -3, -5, -8], [-11, 12, 10, -2], [11, 4, -6, 4], [7, -7, -1, -10], [-8, 12, 4, 8], [8, 3, 2, -8], [6, -1, -3, 5], [8, 5, 4, -4], [4, -20, -4, -15], [-1, 1, -12, -2], [-18, 11, 7, -1], [9, -26, -1, -18], [-16, 16, -4, 11], [11, -12, -7, -11], [-20, -7, -6, -2], [-22, -8, -10, -16], [10, 12, -9, 17], [-18, -7, -1, -11], [22, 1, 5, 9], [15, -6, -3, 12], [6, 8, 14, -2], [1, 8, 0, 8], [13, 17, -11, 4], [3, 8, 3, 2], [-40, 1, -1, -5], [15, -22, -3, -12], [-2, 5, -10, 4], [-5, -4, 5, -9], [10, -12, 2, 8], [-8, -12, -2, -16], [12, -3, -9, -5], [23, -7, 5, -13], [20, 7, 0, -12], [4, -5, -11, -4], [8, -20, 6, -10], [-15, 16, 3, 12], [30, -4, 0, 8], [23, -12, 3, -16], [26, 14, -10, 2], [-10, 0, -2, -18], [19, -4, 5, -1], [14, -3, 1, 10], [-30, 20, 0, -4], [14, -6, -12, 6], [-18, 19, 2, 16], [-19, 19, -3, -9], [12, 1, 13, -17], [-14, -12, -8, -22], [-8, 21, -1, -5], [-16, -2, -1, -6], [5, -7, -14, -3], [-8, 14, -7, -10], [12, 6, 18, 12], [-8, -3, 3, -7], [23, -1, 12, 3], [-13, 5, -1, 21], [30, 7, -11, 5], [5, 9, 9, -3], [-11, 21, 7, 12], [-9, 2, 11, -15], [-30, -5, -5, -7], [-21, -12, 8, 4], [-28, 20, 0, 10], [-8, 3, -11, -13], [24, 9, 4, 4], [11, 8, 5, 0], [41, 6, 2, 10], [2, -26, 6, -10], [38, -20, -12, -4], [2, 26, -8, 6], [45, -1, -4, 0], [-34, 1, 11, -9], [-19, -7, 4, 10], [-16, 3, -6, -20], [16, 0, 4, -10], [-3, -1, -18, -4], [-14, 9, 5, 6], [40, 3, 1, 0], [11, -20, -7, -1], [-21, 1, -9, -3], [26, -10, -16, 8], [19, -12, 9, 22], [3, 8, 0, 17], [-9, 9, -15, 12], [-12, 14, -4, 4], [-25, -7, 7, -7], [19, -15, -5, -6], [-10, 0, 14, -8], [-18, -1, -9, 11], [-31, -1, 11, -3], [26, 14, -2, 10], [-8, 27, 1, 34], [-2, -2, -1, 2], [-14, -2, -13, -3], [-22, -14, 8, -22], [8, -12, 6, 10], [6, 13, 19, 4], [-16, 1, -7, 11], [-30, -7, 1, -13], [12, 18, 17, 20], [-14, 0, 2, -8], [-32, -13, -8, -13], [10, 4, 4, 7], [-22, 25, 9, -3], [2, -12, 3, -7], [-11, 4, -7, -13], [-4, -11, 1, -14], [12, -11, 9, 11], [-1, -4, 10, -7], [2, -9, -11, 16], [29, 16, 1, 7], [-10, 2, 10, -4], [-29, 10, -9, 10], [-2, -14, -2, -2], [-9, -11, -7, -6], [-16, 29, -3, -1], [-10, -16, 2, -22], [27, 7, 13, -9], [-4, -10, 2, 4], [16, -21, -4, -3], [3, 1, 9, -2], [18, -18, -2, 1], [-35, 24, -1, 19], [8, 6, -4, -8], [-34, 5, 7, 6], [-35, -6, 0, 0], [-3, 4, -13, -1], [25, 2, -6, -5], [15, 2, 11, -21], [-20, -21, 10, -17], [-20, -3, 7, -4], [2, 1, 1, 3], [-35, 15, 2, -12], [12, -10, -12, -4], [-27, 24, 13, 7], [-16, 17, 1, 6], [35, -18, -8, 1], [4, 1, -6, 31], [40, 9, -3, 5], [26, -5, -11, 15], [37, -6, -13, 10], [6, -33, 3, -13], [23, -5, 11, -3], [-4, 3, 5, -17], [-7, -11, -10, -16], [-6, -23, -11, -8], [11, 5, -17, 17], [-5, 0, -5, 14], [-13, 11, 5, 12], [-19, 13, 14, 1], [-9, 20, -4, -8], [-21, 31, 10, 7], [9, -18, 9, -21], [-28, 2, 0, -4], [4, 22, -14, 15], [-16, 8, -3, -2], [48, 1, 5, -14], [27, 12, -5, 1], [-18, 24, 5, 15], [-14, -14, 12, -4], [26, -14, -16, 2], [-14, -9, -9, -23], [-19, -9, 5, -6], [-11, 25, -1, 25], [10, 14, 15, 15], [11, 1, -4, 22], [21, 4, 12, 9], [0, -12, 14, -4], [38, -19, 5, -17], [-18, 21, -3, -3], [0, -2, -14, -10], [-15, 25, -9, 37], [-32, 10, -2, 17], [-14, -18, 0, 10], [-34, 8, -5, 4], [0, 16, -6, 32], [5, -1, -10, 6], [2, -34, -8, -22], [-27, -3, -15, -9], [-14, 6, -19, 15], [36, 9, 7, -8], [38, -8, -10, 15], [-1, 8, 9, -14], [-8, 27, 15, 13], [5, -27, 6, -10], [38, -6, -4, 12], [-6, -4, -22, -5], [-24, -22, 20, -8], [2, -23, 9, -15], [-16, -11, -3, -17], [12, -14, -9, 16], [12, -16, -2, -22], [40, -20, 5, -10], [10, 10, -8, 24], [-20, -14, 2, 10], [5, -24, -2, 2], [10, -43, -3, -31], [24, 19, -7, 15], [34, 14, -2, 4], [1, -24, 1, 12], [-40, 6, 12, -11], [-5, -5, -6, -14], [20, 22, 8, 20], [-17, -18, -3, -6], [46, 13, 12, 6], [24, 16, 4, 8], [20, 8, 11, 1], [11, 10, -17, 13], [3, 7, 10, 24], [-13, -14, 10, 0], [-18, 18, 14, -1], [20, -8, -11, 23], [-7, -30, 14, 0], [-4, 15, -13, 22], [-4, -4, -8, -21], [-29, -5, 4, -6], [-19, -16, 8, -32], [23, -17, -26, 11], [-10, 21, 2, 12], [14, -39, 5, -19], [-4, 10, -1, -10], [-32, -14, 8, -11], [27, 5, 6, 32], [9, 26, -15, 34], [-3, 11, -7, 4], [0, -1, -12, -4], [-24, 6, -3, -1], [44, -13, -1, 3], [26, -13, -5, 9], [-47, 6, -11, -10], [40, -18, 10, 26], [-2, 19, -5, 7], [-34, -9, 11, -21], [16, 0, 6, -12], [28, 34, -11, 24], [41, -11, -8, 11], [41, -23, 1, -9], [-53, 12, -9, -20], [-22, 18, 0, 8], [7, 14, 7, 27], [32, 8, 6, 9], [48, -15, -3, -9], [32, 13, -11, 3], [46, -22, -5, 6], [-4, 5, 2, 0], [10, 17, -11, 19], [6, 8, 22, 0], [-15, 3, -5, -36], [-4, 13, -15, 3], [12, 6, -6, -24], [26, -9, -13, 22], [-24, -5, 0, 1], [22, 6, 14, -16], [25, 20, -7, 27], [-20, 15, -12, -28], [-17, 2, -6, 18], [27, 29, 20, 34], [-25, 7, 11, -3], [0, -24, -4, 0], [-7, -20, 5, -34], [-22, 17, 0, -8], [26, -30, 2, -26], [-10, -6, 4, 26], [64, 0, -10, -3], [-10, -12, -24, 0], [12, -27, 5, 19], [31, 26, 8, 25], [-31, -2, -1, -22], [-14, -6, -12, 11], [4, 25, 5, 25], [10, -4, -2, -2], [-1, 0, -17, -12], [-17, 20, 10, 19], [5, -25, 2, -35], [-51, -6, 9, -11], [1, 0, 28, 2], [20, 12, 2, -2], [37, -5, 8, 28], [-25, 3, -2, -15], [19, -22, -9, 5], [24, 25, 9, 33], [-14, -7, 7, -36], [4, 17, -8, 1], [-29, 17, -5, -1], [-26, -17, 28, -6], [-28, -12, -10, 0], [-5, 6, -19, -9], [56, -5, 0, 0], [24, -8, 6, -24], [-6, -6, -14, 9], [-18, 20, -4, 18], [32, -38, -2, 11], [11, -21, 2, 3], [-20, -14, 10, 12], [7, 24, -2, 29], [22, 16, 16, -8], [2, 13, 11, 9], [9, -15, -4, 16], [31, -11, -1, 6]];
    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_cg();".
// 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_cg(:prec:=4)
    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_cg();".
// 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_cg( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_7623_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<2,R![-2, -8, -4, 2, 1]>,<5,R![1, 2, -4, -2, 1]>,<13,R![-2, -32, 32, -10, 1]>],Snew);
    return Vf;
end function;