
// Make newform 6370.2.a.bb in Magma, downloaded from the LMFDB on 03 December 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_6370_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_6370_2_a_bb();".
// 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_6370_2_a_bb();".
// 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
        Kf := Rationals();
    end if;
    return [Kf!elt[1] : elt in input];
end function;


// To make the character of type GrpDrchElt, type "MakeCharacter_6370_a();"
function MakeCharacter_6370_a()
    N := 6370;
    order := 1;
    char_gens := [5097, 5981, 1471];
    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_6370_a_Hecke( : Kf := Kf)
    return MakeCharacter_6370_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]];
    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 := [[1], [3], [1], [0], [3], [-1], [2], [6], [-3], [-6], [5], [-5], [-7], [-6], [7], [-12], [8], [-15], [-7], [4], [7], [1], [-6], [-6], [-15], [3], [14], [2], [-2], [-1], [13], [20], [2], [4], [-11], [-22], [7], [24], [16], [14], [-12], [-25], [8], [18], [3], [-22], [18], [1], [-18], [-6], [5], [-2], [-2], [5], [-20], [12], [25], [-25], [-8], [6], [31], [4], [28], [12], [10], [-33], [-17], [3], [28], [22], [-17], [-30], [-36], [10], [-4], [5], [-10], [-18], [-20], [-22], [-31], [27], [-36], [26], [-26], [14], [-16], [30], [16], [32], [28], [0], [-8], [-12], [5], [-24], [-20], [-6], [35], [-26], [-8], [-13], [15], [1], [12], [-34], [-34], [-2], [45], [48], [-44], [5], [-24], [-24], [50], [15], [14], [-22], [-6], [-16], [-12], [5], [-7], [-31], [-44], [-28], [-13], [36], [14], [-4], [4], [26], [11], [-52], [21], [-19], [-34], [-42], [17], [6], [-16], [22], [-19], [36], [26], [51], [4], [12], [7], [-6], [49], [42], [34], [42], [-20], [-36], [5], [21], [-32], [30], [36], [-46], [-4], [47], [26], [40], [29], [31], [0], [6], [4], [-34], [-25], [2], [54], [10], [25], [10], [6], [55], [28], [39], [32], [13], [-18], [18], [-48], [64], [-34], [37], [-20], [17], [-56], [-6], [30], [-24], [-54], [50], [62], [-12], [35], [-14], [34], [-16], [-58], [18], [16], [42], [28], [1], [-65], [-27], [-5], [66], [-9], [-35], [-63], [-58], [-72], [5], [66], [49], [-4], [38], [-35], [-64], [46], [9], [68], [57], [-68], [8], [-4], [-33], [-23], [-33], [-49], [-49], [42], [32], [67], [11], [-42], [6], [-57], [10], [3], [-32], [31], [19], [-55], [18], [-2], [-10], [-71], [24], [-8], [-10], [63], [-3], [-28], [2], [12], [51], [15], [56], [-65], [73], [3], [-6], [49], [31], [-13], [-12], [54], [-40], [-60], [25], [10], [28], [24], [-82], [54], [-8], [-28], [-13], [-49], [-14], [39], [-54], [22], [-29], [64], [-42], [16], [10], [-50], [-7], [27], [-18], [-38], [35], [-16], [36], [46], [-52], [48], [-42], [60], [16], [-44], [42], [1], [6], [36], [-38], [-68], [-60], [46], [-39], [51], [-56], [-51], [-10], [84], [-60], [-33], [72], [-40], [-36], [27], [12], [40], [12], [-47], [-52], [54], [93], [62], [-18], [-10], [-13], [-30], [1], [-31], [0], [-74], [68], [47], [55], [-72], [-54], [55], [48], [-24], [72], [-21], [-70], [77], [56], [-26], [-32], [-27], [3], [-21], [5], [-8], [2], [-7], [-58], [-1], [68], [-46], [-22], [-4], [14], [-91], [-5], [12], [82], [26], [-42], [-60], [-4], [-46], [-12], [-60], [41], [60], [18], [30], [-54], [17], [-48], [-72], [69], [-25], [-60], [0], [-54], [-10], [34], [38], [21], [56], [36], [-101], [78], [-52], [-84], [-46], [44], [-12], [-8], [17], [14], [84], [2], [51], [54], [60], [-30], [-82], [4], [26], [-16], [82], [82], [34], [0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_6370_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_6370_2_a_bb();".
// 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_6370_2_a_bb(:prec:=1)
    chi := MakeCharacter_6370_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_6370_2_a_bb();".
// 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_6370_2_a_bb( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_6370_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![-3, 1]>,<11,R![-3, 1]>,<17,R![-2, 1]>,<23,R![3, 1]>],Snew);
    return Vf;
end function;