
// Make newform 7623.2.a.cm in Magma, downloaded from the LMFDB on 24 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_cm();".
// 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_cm();".
// 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], [1, -1, -2, 0], [1, -1, -1, 0], [-1, 0, 1, 1], [-2, -1, -1, 0], [4, 1, -1, 2], [0, -1, -1, -1], [-3, 2, 1, 2], [3, 1, -2, -1], [-4, -1, 0, 1], [-2, 3, -2, 0], [4, 2, -2, 2], [-1, -6, 0, -7], [1, 0, 1, 3], [-5, -4, 2, -4], [6, -6, -2, 1], [-1, 5, -2, -2], [-3, -2, -3, 0], [6, -2, 1, 1], [5, 0, -4, 3], [9, 3, -2, 2], [0, 4, -1, 3], [-1, 1, 0, -4], [6, -2, 0, -1], [-3, 7, -1, 1], [-6, 8, 0, 0], [8, -5, -6, 1], [7, 1, 1, -6], [4, -6, 2, -5], [-13, -5, 0, -4], [0, -4, 6, -1], [-10, 3, 0, -3], [8, -1, 1, -1], [1, -2, -1, 6], [2, 2, 3, -1], [9, 1, 5, 4], [-8, 8, 4, 2], [2, 1, -7, 3], [12, 1, 1, -4], [18, -13, -4, -1], [-4, -1, -3, -3], [7, -6, -1, 5], [-9, 7, 3, 3], [-16, 9, 3, 1], [14, -8, 1, 1], [6, -8, -2, 6], [-10, -4, 0, -3], [16, -5, 1, 3], [9, 4, 3, -3], [2, 6, 6, 0], [-4, -3, -4, -4], [16, -3, 1, 8], [-8, -8, -2, -12], [-2, 5, -3, 15], [7, -5, -1, -5], [10, 5, -1, 5], [-10, -4, 6, -4], [-5, -1, 7, -2], [-3, 4, 7, 1], [-6, 5, 0, 2], [10, -1, -1, 7], [0, 5, -1, 2], [6, -2, 1, 6], [1, -4, 3, -12], [4, 1, -1, -2], [-6, -5, 1, -3], [0, 2, 8, 2], [0, 11, -1, 4], [1, -8, 5, -13], [18, -1, 6, -1], [-10, -6, -7, -6], [-16, -3, -4, -10], [-2, -2, -4, 0], [-2, 2, 2, 4], [-10, -5, 9, -5], [7, 4, 5, -9], [-1, -6, 4, -1], [3, -2, -4, 10], [0, -4, -8, 2], [5, -11, 0, -2], [-10, 0, 0, -8], [16, 3, 9, 0], [0, -7, -9, -3], [8, 15, 0, 11], [-5, 9, -5, 12], [-3, -2, -9, -2], [-1, 11, -2, 17], [14, 6, 3, 1], [7, 10, 0, 12], [2, 11, -3, 14], [-24, 0, -5, -8], [8, -8, 3, 3], [6, 7, -10, 8], [-7, 16, 4, 3], [1, 1, -2, -6], [4, -1, 6, -3], [11, -4, 1, -8], [16, -10, 0, 2], [-5, 3, 5, -6], [-8, -1, 9, -10], [14, -2, 2, 14], [-17, 10, 11, -5], [5, -2, 4, 1], [-13, -7, -7, -14], [0, -8, -2, 4], [15, -17, 0, -2], [7, -5, 4, 10], [-8, 15, -2, 17], [-8, 14, 4, 16], [20, 5, 1, 9], [6, -16, 3, 2], [-16, 2, -2, -11], [26, -8, -6, 6], [22, -3, -6, -2], [16, -3, 1, 4], [18, -22, -2, -11], [-8, 1, -1, -3], [11, 11, 5, 17], [-2, -4, -5, -7], [6, -15, 5, 9], [14, 4, -10, 2], [28, -5, -3, 6], [-15, 0, 2, 6], [-20, 0, -4, 6], [19, -1, 8, -4], [3, 0, -9, 1], [-23, -8, -3, -10], [14, 7, -3, 8], [-19, 0, -10, 14], [-9, 8, 2, -12], [17, 3, -7, 12], [12, -8, -8, -4], [8, -5, -4, 16], [10, -5, 9, -23], [0, -11, -2, 8], [4, 12, 8, 11], [-7, 13, -2, 2], [18, 13, -11, 9], [9, 10, 3, 18], [32, 0, -8, 1], [9, 16, 11, 13], [-4, 1, 0, 10], [-26, 8, -6, 8], [10, -6, -1, 7], [2, 1, -5, 5], [10, 3, 7, 15], [-1, -10, 1, -8], [10, 16, 2, 22], [-19, 0, -4, -4], [11, -13, -5, 2], [7, -12, 3, -2], [0, -13, 1, 1], [-25, 10, -3, -4], [2, -11, -4, -16], [5, 8, -1, -5], [6, 4, -10, -4], [-20, 8, -10, -12], [4, 15, -3, -3], [7, 1, 5, 3], [-28, 3, -6, 4], [8, -3, 15, 4], [-8, 8, 6, 14], [5, 12, 3, 4], [26, 0, 4, 12], [-9, -4, -5, -4], [-18, -2, -10, -10], [18, -12, 2, 2], [9, -16, 7, -25], [-22, -13, -13, -18], [10, 8, -4, 24], [-10, 10, 0, -2], [26, -21, -4, -8], [-11, -5, -11, -13], [-8, -17, -1, -7], [26, -4, 8, 2], [-8, 13, 7, 3], [4, 18, -9, 10], [31, -7, -4, 9], [-16, 14, -7, 6], [-12, -10, -14, -8], [-28, 7, 5, -1], [25, -5, -2, 15], [23, -19, -5, 13], [-10, -1, -11, 13], [17, 9, -3, -3], [-21, 15, 9, -2], [29, -18, -7, 1], [-14, -7, 1, -13], [-13, -8, -4, 0], [-4, -16, -4, -26], [12, 5, -5, -3], [8, 5, 10, -8], [7, 4, 5, -12], [25, -22, -10, -10], [22, -14, 2, -6], [10, -4, 4, 16], [-26, -6, 0, -14], [-25, 7, -10, -8], [22, 25, -1, 23], [7, -15, 6, -14], [-16, 7, 0, 16], [8, 16, 4, 18], [31, -5, 4, -12], [-14, 19, -1, 14], [8, 1, 11, -24], [-7, 16, 3, -1], [-9, -3, 23, -7], [-2, 18, 0, 0], [-13, -16, 5, 6], [-3, -8, -8, -3], [9, 3, 15, -10], [-12, 6, -8, -20], [3, -11, -1, -19], [-11, 23, 9, 12], [22, -8, -2, 8], [-6, 21, -3, -3], [1, 11, -1, 1], [14, -22, 2, -18], [-4, 17, -5, 22], [-10, -18, -9, -14], [-38, 12, -1, 19], [-22, -2, -4, 14], [-8, 12, 18, -14], [-6, 15, 17, 4], [12, -7, -3, 11], [18, 3, 11, 1], [8, 14, 1, 16], [-2, 0, -10, -16], [8, -5, -8, -5], [-2, -12, 8, -15], [2, 9, 5, -3], [2, -2, 15, -9], [-29, 32, 7, 19], [20, -21, -1, -2], [24, -13, -5, 13], [9, 0, 2, -7], [-6, 25, 7, 12], [-25, 4, -5, -5], [-2, -6, 10, -4], [-25, -22, -5, -26], [18, 6, 2, -14], [-31, 19, 11, 4], [-4, -3, 9, -1], [10, -16, -2, -22], [-5, 15, 5, 19], [20, 2, -6, 0], [12, -1, -4, 25], [-19, -21, -17, -24], [38, 2, -10, 3], [-17, -20, -3, -5], [24, -6, 4, 0], [14, -5, 5, 10], [-31, 22, 8, 4], [-17, 8, -3, -29], [7, -2, 6, 11], [-27, 6, 17, -1], [28, 19, 2, 23], [-4, 23, -11, 28], [-14, 1, 9, 3], [7, 19, -4, 16], [20, -30, 4, 4], [19, -4, 3, -25], [-20, -9, -1, -14], [5, -10, 12, -19], [-12, 25, 10, 11], [0, 15, -17, 7], [18, -29, -3, -17], [-19, 6, 7, -18], [42, -1, 3, 3], [3, 15, 19, 5], [68, -1, 5, 3], [7, 1, 12, 16], [-22, 27, -5, 20], [15, 5, 19, -7], [15, 4, 3, 22], [-19, -3, -9, 10], [-9, 1, -4, -7], [-5, 8, 4, 8], [1, 7, -16, 11], [23, -26, -1, 11], [12, 10, 0, 4], [-56, -2, -6, -3], [12, 20, -3, 10], [28, 19, 7, 14], [17, 24, -7, 17], [-10, 22, -7, 25], [6, 14, 0, -16], [38, -10, 0, -10], [-18, -15, -11, -9], [19, -7, -9, 20], [1, 5, 7, 13], [-22, -4, 11, -15], [33, -19, 2, -26], [-21, 16, 16, -19], [24, 4, 18, 16], [14, 17, 5, -5], [34, -7, 9, -15], [-44, 30, 2, -6], [-15, -7, -1, -7], [16, -30, -10, -17], [2, -6, 20, -10], [6, 0, 11, 4], [-12, -16, 2, -20], [-13, 3, -4, -18], [-26, 10, 4, -14], [-31, 29, 13, -5], [-6, -8, 17, -3], [28, -1, -3, 20], [-30, -4, -10, -19], [3, -8, 13, 2], [-20, -15, -11, -13], [7, 29, 8, 22], [58, -14, 0, 12], [-22, 20, 6, 1], [0, 2, 0, 32], [-10, 15, -1, 27], [-12, 13, -7, -17], [16, 6, 7, -4], [-12, -32, 10, -18], [-36, 4, -7, 30], [46, 2, -8, -8], [-8, -14, 22, -6], [-27, 32, -2, -10], [-14, 13, 13, 1], [-56, 9, 3, 1], [10, -26, -10, -16], [-51, 4, -7, -8], [44, 2, -4, 7], [-47, -9, -8, -2], [20, 2, -24, 4], [-13, -22, 13, 6], [2, 9, 18, -18], [-32, 4, 16, -12], [-8, 30, -5, 35], [21, 6, -11, 13], [-3, 3, -4, 4], [-13, -18, 6, -16], [-14, 10, -2, -19], [-24, 18, -3, -23], [-59, -6, -14, -16], [4, -11, -11, -10], [-16, 40, 0, 17], [25, -1, 10, -6], [25, -4, 8, -24], [-43, -1, -20, -25], [-30, -27, 24, -20], [22, -11, -11, 1], [-20, 6, 3, -6], [-4, -18, 16, -17], [25, -7, 12, -4], [25, -14, 1, -18], [-13, 5, 11, -6], [-8, -25, 18, -4], [36, -16, -7, 1], [-8, -15, 21, -3], [-22, 1, -15, -13], [-7, -22, -7, -34], [48, 10, -2, 10], [2, 21, 1, 9], [-6, -23, -3, -23], [-8, 16, -22, -12], [-8, -2, -11, -12], [11, 5, -10, 31], [5, 13, 1, 15], [-9, 12, -21, 20], [30, -10, -12, -12], [49, -22, 1, 3], [4, 8, -14, 39], [24, -1, 11, -15], [4, -3, 17, 11], [-2, -18, 23, -6], [4, 41, 12, 36], [6, 39, 3, 33], [14, 16, 14, 16], [23, 29, 1, 18], [12, 13, 9, 27], [28, 34, -2, 32], [-38, 9, 13, -10], [0, 15, 12, 17], [-58, 30, 2, -8], [7, 24, -17, 7], [-28, -21, 6, -8], [7, 30, 14, 30], [9, 17, -6, -6], [-21, 7, -9, 1], [-40, 4, -8, 8], [-3, -24, 13, -6], [-18, 5, -18, 0], [10, -22, -10, -30], [14, 10, 0, 2], [4, 12, 2, -17], [22, 8, 4, 4], [56, 1, 9, 23], [-7, -18, 24, -11], [-23, 22, 7, 18], [-2, 10, 4, 5], [24, -19, 17, -3], [-34, 12, -18, -18], [43, 0, -13, 12], [-47, 12, 14, -17], [7, -9, 24, -7], [-41, -26, 19, -15], [-3, 0, -16, 2], [8, -28, 6, 10], [-41, -17, 2, -12], [1, 11, 32, 1], [5, 34, -7, 5], [-36, -21, 3, -33], [46, 23, 13, 20], [-32, -3, 0, -7], [3, 21, 15, 3], [-54, 23, 2, 2], [36, 8, -6, 20], [21, 2, -13, 7], [-8, -1, -14, 12], [48, -12, -2, 16], [18, -26, -22, -9], [-38, 8, -8, 30], [12, 6, 6, -31], [-7, -9, 4, -29], [32, -14, -2, 28], [-23, 12, 6, 21], [2, 4, -16, 4], [22, -17, 13, -25], [-37, -11, 30, -16], [-31, 19, -11, 32]];
    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_cm();".
// 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_cm(: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_cm();".
// 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_cm( : 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![-11, -6, 8, 6, 1]>,<13,R![358, 32, -40, -2, 1]>],Snew);
    return Vf;
end function;