
// Make newform 7623.2.a.bs in Magma, downloaded from the LMFDB on 23 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_bs();".
// 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_bs();".
// 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 := [-3, -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], [-2, -2], [5, -1], [3, 0], [5, -1], [7, -1], [1, 0], [4, -4], [7, 0], [-4, 1], [-5, 3], [6, 3], [-9, 1], [2, 1], [-3, 5], [2, 1], [5, 0], [6, 1], [3, 0], [-6, 9], [1, -2], [-3, -1], [-12, -1], [17, -2], [8, 0], [13, -1], [-2, 0], [-6, 0], [-6, 7], [-17, -2], [2, -3], [-9, 4], [-2, 4], [-11, 6], [4, -4], [1, -1], [11, -2], [-16, -4], [13, 6], [-14, 7], [-6, -2], [1, 8], [-4, -5], [7, 3], [-5, 5], [2, -2], [18, 0], [1, 11], [-12, 5], [-9, 2], [-18, 5], [-12, 14], [0, -7], [17, 5], [0, -13], [11, -2], [-9, 2], [-9, 6], [-11, 12], [-11, 2], [13, 1], [-15, -1], [10, 6], [-21, 4], [5, 2], [7, -1], [-12, 3], [-4, -13], [10, -12], [4, 7], [-2, -6], [-11, -12], [-6, 6], [21, 4], [12, 4], [-16, -2], [20, 8], [-8, -6], [13, -7], [-10, 17], [-7, -9], [3, -13], [-15, -11], [-5, -7], [15, -3], [-17, -6], [-21, 15], [-1, -12], [11, -6], [-15, 1], [-4, 3], [24, -8], [-20, -1], [11, -8], [10, 15], [37, -2], [0, 13], [-25, 14], [2, -1], [0, 0], [11, -16], [-7, 4], [9, 2], [18, 2], [24, -4], [-8, 6], [-14, 15], [-13, 20], [6, -12], [26, 6], [15, -20], [15, 6], [31, -14], [-6, -2], [-7, 6], [-23, 12], [-16, -1], [-10, 8], [8, 1], [-18, 1], [6, -10], [-15, -7], [0, 11], [11, -14], [8, 7], [16, -4], [27, 7], [15, 13], [-20, 12], [-10, -6], [42, 0], [14, 11], [-3, -12], [34, -5], [1, 12], [15, -3], [4, 16], [-9, -8], [26, 4], [-28, 6], [34, -9], [-33, -4], [25, 9], [-13, 21], [-23, -1], [-13, -8], [-1, -20], [-9, -11], [13, -9], [28, 7], [5, -2], [9, 18], [9, -28], [0, 12], [-27, -2], [19, 8], [4, -22], [17, -10], [-29, -5], [34, -12], [-17, -10], [30, -9], [-23, -9], [-48, 1], [-13, -10], [7, -16], [-27, -4], [-31, 5], [-32, 22], [-1, 8], [-34, 3], [-19, -7], [37, 0], [-20, 15], [-9, -5], [23, -21], [15, 14], [-10, 30], [19, -1], [43, -10], [-7, 16], [-39, -6], [53, 1], [-39, 12], [13, -30], [19, 1], [1, -5], [16, -9], [-25, 13], [11, -20], [-23, -1], [21, -15], [16, 0], [29, -4], [24, 3], [-57, 2], [-5, -16], [-10, 19], [-5, 14], [-2, -5], [33, -26], [24, 5], [47, -2], [33, 6], [-33, 9], [5, -13], [-11, 23], [-13, 19], [14, 22], [1, 10], [-12, -3], [31, -17], [10, 18], [42, 0], [9, -21], [-11, 20], [-42, -1], [29, -8], [9, 0], [-8, -11], [0, -6], [-40, -7], [29, -11], [18, -30], [32, 12], [-7, 5], [26, -16], [-14, 22], [-13, 3], [-15, 14], [-18, 28], [27, -35], [51, -18], [45, -12], [45, 14], [7, 22], [30, 5], [-25, 26], [39, -24], [-7, 28], [33, -8], [-24, 12], [-26, 1], [-34, 5], [-45, -3], [42, -23], [6, -4], [-25, 36], [-19, -8], [-41, 22], [-28, -14], [-15, 22], [-43, 2], [56, -5], [-26, 5], [7, -2], [23, 12], [1, 5], [36, -17], [13, 8], [-6, 0], [12, -20], [48, -12], [-31, 28], [-4, 2], [2, 1], [-38, 22], [-2, 5], [-66, 4], [-41, 18], [35, -22], [-1, -12], [33, -33], [-11, 25], [32, -3], [-39, 12], [6, -17], [5, -24], [-27, 26], [41, -22], [29, -30], [-15, 30], [19, -25], [25, -10], [-42, -2], [-24, 22], [-30, -17], [-29, -9], [21, 6], [26, -5], [-28, -11], [-13, 12], [-9, -11], [53, 6], [41, -17], [-27, 13], [-5, 20], [31, -7], [-41, -14], [27, -25], [-49, 18], [-16, 32], [-37, 4], [-8, 38], [3, 3], [3, 3], [51, -24], [-5, 13], [-34, -11], [33, 14], [-45, 6], [-27, 1], [-31, 2], [-9, -14], [-9, -2], [-21, -4], [1, -20], [14, -1], [-2, 10], [-20, 10], [30, 7], [15, 14], [11, 25], [-36, -10], [18, -15], [-51, -2], [-54, 17], [37, -22], [-8, 33], [-46, 20], [-31, 25], [-54, 3], [22, -48], [54, 4], [6, -8], [-9, -26], [-22, 21], [-39, 36], [29, -38], [-17, 31], [-36, 28], [-51, -8], [2, -16], [-35, 1], [-36, 27], [-3, 24], [-39, -8], [-40, 19], [-31, 22], [16, -34], [9, -19], [-15, 48], [2, -14], [-50, 25], [55, -2], [66, -14], [4, 6], [-32, 14], [23, -2], [54, -17], [-37, 7], [21, -23], [73, 8], [56, -25], [-29, 5], [12, -3], [-4, -17], [43, 3], [35, -46], [10, -17], [45, -17], [-15, 34], [44, -21], [-77, 0], [44, 1], [-9, -18], [-59, -5], [41, 4], [-41, 42], [-1, 0], [-25, 3], [-10, -26], [44, -29], [-48, 2], [-13, -22], [40, 12], [64, -11], [20, 0], [-25, 44], [-43, -16], [-27, 12], [-30, 2], [16, -9], [1, 20], [-28, 44], [-7, -24], [42, 4], [-12, -19], [-12, -30], [12, 6], [0, 25], [-46, 31], [37, -16], [63, -32], [50, -6], [35, -10], [-30, 45], [51, -32], [15, -4], [53, -4], [20, -22], [-33, -6], [74, -6], [2, 4], [20, 26], [-13, 16], [29, -34], [36, 2], [-22, 28], [37, -12], [-49, -4], [42, 0], [-15, 18], [57, 13], [-1, -19], [-35, 24]];
    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_bs();".
// 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_bs(: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_bs();".
// 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_bs( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_7623_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<2,R![-3, -1, 1]>,<5,R![-13, 0, 1]>,<13,R![-4, 6, 1]>],Snew);
    return Vf;
end function;