
// Make newform 6370.2.a.q 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_q();".
// 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_q();".
// 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], [-1], [1], [0], [-1], [1], [-4], [0], [-1], [-6], [7], [5], [7], [-2], [-5], [-14], [-8], [-1], [-13], [-6], [7], [1], [-2], [-10], [9], [-11], [-2], [-18], [-2], [1], [3], [0], [-14], [-4], [5], [0], [-13], [20], [12], [18], [-26], [5], [-12], [-12], [-15], [-14], [-4], [1], [12], [22], [7], [22], [10], [-5], [-24], [0], [-1], [13], [-16], [-10], [7], [-30], [22], [-8], [-26], [9], [23], [-11], [-16], [-32], [3], [10], [-10], [18], [20], [-7], [0], [-28], [34], [-14], [15], [-25], [18], [-22], [16], [-14], [-24], [24], [6], [4], [32], [-8], [4], [18], [1], [24], [-24], [12], [-25], [38], [-2], [-3], [27], [-11], [24], [-2], [26], [-38], [5], [28], [-28], [-17], [24], [48], [-26], [27], [-36], [-38], [-34], [-4], [-14], [7], [17], [27], [44], [22], [3], [30], [2], [-24], [36], [0], [31], [-38], [27], [7], [6], [-36], [-7], [-10], [8], [-6], [-1], [-16], [-10], [21], [14], [-12], [-43], [24], [-21], [26], [34], [-44], [-38], [-32], [17], [3], [0], [56], [12], [14], [38], [25], [-42], [56], [-15], [39], [16], [-14], [36], [8], [-33], [30], [-50], [24], [53], [38], [-16], [-35], [-20], [45], [-62], [21], [44], [-54], [-16], [-20], [48], [-57], [-12], [-57], [-30], [18], [28], [42], [-32], [-26], [34], [-36], [-21], [56], [2], [4], [0], [18], [16], [-66], [34], [7], [13], [15], [37], [20], [-7], [19], [23], [44], [-18], [11], [0], [59], [-30], [16], [37], [-2], [18], [69], [2], [-63], [-6], [20], [8], [11], [-31], [55], [13], [-3], [-30], [8], [45], [-11], [36], [62], [-65], [-64], [-33], [56], [19], [57], [27], [30], [16], [-2], [-35], [-80], [18], [-78], [31], [-3], [24], [58], [-16], [-45], [-41], [-24], [43], [3], [21], [-60], [23], [13], [71], [-64], [64], [-72], [-4], [-59], [22], [76], [12], [-12], [40], [32], [-40], [-65], [37], [-74], [25], [-58], [-20], [15], [-26], [-56], [-26], [18], [30], [-27], [-83], [-40], [28], [-19], [8], [-6], [32], [-46], [42], [-30], [30], [-4], [-80], [58], [-67], [-66], [12], [50], [72], [-40], [14], [-23], [-11], [14], [-45], [-16], [16], [-62], [59], [-14], [4], [-80], [-25], [2], [-16], [-84], [17], [-78], [-90], [33], [-26], [-56], [10], [-87], [70], [21], [-37], [-66], [-10], [-52], [-39], [91], [6], [-14], [-9], [-26], [-80], [66], [5], [-66], [39], [-2], [6], [-6], [87], [-13], [23], [35], [60], [-2], [-83], [-84], [69], [-38], [-66], [88], [18], [-50], [-55], [-53], [-92], [-28], [68], [4], [-58], [-28], [-64], [-12], [56], [-11], [-40], [84], [16], [-2], [17], [-68], [18], [-69], [1], [82], [14], [-22], [0], [42], [80], [41], [46], [84], [81], [-64], [86], [-30], [62], [-40], [18], [-104], [-49], [70], [-4], [-48], [23], [26], [66], [-92], [-76], [96], [6], [-40], [-64], [-46], [70], [90]];
    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_q();".
// 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_q(: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_q();".
// 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_q( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_6370_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![1, 1]>,<11,R![1, 1]>,<17,R![4, 1]>,<23,R![1, 1]>],Snew);
    return Vf;
end function;