
// Make newform 6336.2.a.bq in Magma, downloaded from the LMFDB on 12 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_6336_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_6336_2_a_bq();".
// 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_6336_2_a_bq();".
// 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_6336_a();"
function MakeCharacter_6336_a()
    N := 6336;
    order := 1;
    char_gens := [4159, 4357, 3521, 1729];
    v := [1, 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_6336_a_Hecke( : Kf := Kf)
    return MakeCharacter_6336_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 := [[0], [0], [1], [-4], [-1], [2], [0], [-2], [9], [4], [-5], [9], [-2], [-6], [-4], [-6], [5], [0], [-13], [-1], [14], [10], [-14], [13], [-19], [-12], [8], [-8], [-10], [7], [-2], [-16], [-13], [-16], [12], [-14], [-13], [20], [18], [-22], [-11], [-11], [15], [-12], [22], [0], [-12], [-25], [-24], [9], [12], [-18], [-4], [17], [-6], [-4], [14], [-10], [14], [-18], [8], [-10], [-34], [16], [7], [9], [13], [12], [10], [-8], [-3], [-22], [-13], [-32], [-7], [9], [-19], [-22], [30], [18], [24], [2], [-8], [5], [-20], [-11], [9], [0], [0], [5], [-19], [38], [31], [-8], [-28], [6], [23], [-17], [42], [10], [20], [-4], [-24], [-4], [-4], [-11], [-4], [12], [-24], [-40], [-2], [-32], [26], [37], [19], [5], [-41], [7], [39], [30], [-17], [22], [-12], [-12], [-5], [-20], [-7], [-39], [-1], [24], [-2], [-44], [1], [10], [-18], [-50], [-14], [-4], [-23], [-18], [-46], [-42], [27], [34], [11], [21], [-46], [-16], [23], [-24], [-42], [-21], [4], [42], [12], [-24], [-34], [46], [50], [-18], [-27], [36], [4], [-13], [-17], [49], [-32], [28], [2], [-41], [38], [-2], [18], [34], [17], [31], [28], [39], [28], [-52], [48], [54], [31], [-34], [23], [10], [38], [12], [-56], [14], [13], [-8], [51], [54], [-10], [17], [-20], [65], [-2], [0], [-66], [-30], [6], [-28], [-33], [33], [9], [16], [60], [-28], [48], [-45], [63], [20], [32], [-1], [26], [24], [24], [-45], [22], [54], [-45], [25], [-2], [34], [-66], [24], [26], [30], [-25], [14], [50], [-12], [31], [-50], [-63], [6], [-69], [55], [39], [16], [32], [27], [56], [24], [40], [-60], [-18], [-6], [-8], [40], [63], [46], [64], [-48], [-14], [12], [1], [-28], [16], [-62], [-40], [-12], [-30], [28], [3], [11], [26], [-26], [-5], [-27], [-70], [-2], [-2], [-41], [43], [-54], [10], [-2], [-34], [1], [66], [-2], [16], [-41], [-18], [48], [-67], [28], [-11], [-40], [-68], [44], [-24], [-42], [-11], [71], [-4], [2], [24], [-70], [-64], [36], [25], [-29], [59], [-45], [-64], [-66], [84], [10], [42], [-25], [8], [32], [7], [66], [2], [-50], [-22], [-43], [0], [-31], [-50], [19], [-63], [-59], [-42], [76], [10], [-2], [-44], [60], [12], [-59], [-17], [-84], [7], [-32], [19], [21], [-34], [71], [39], [-38], [13], [-43], [14], [3], [-50], [3], [10], [-36], [52], [30], [-49], [14], [66], [-13], [-30], [32], [-3], [24], [97], [17], [66], [58], [6], [-95], [56], [60], [-30], [62], [43], [60], [-52], [94], [-78], [-12], [-2], [-27], [80], [-48], [24], [-15], [-44], [-85], [-50], [69], [65], [3], [-87], [17], [-79], [-46], [-36], [18], [64], [-66], [84], [-21], [48], [90], [-40], [-72], [-30], [-38], [-68], [35], [-26], [-72], [-4], [8], [-20], [-79], [-60], [-53], [-30], [-10], [51], [-76], [24], [-68], [-50], [107], [-81], [100], [-83], [0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_6336_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_6336_2_a_bq();".
// 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_6336_2_a_bq(:prec:=1)
    chi := MakeCharacter_6336_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_6336_2_a_bq();".
// 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_6336_2_a_bq( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_6336_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![-1, 1]>,<7,R![4, 1]>,<13,R![-2, 1]>,<17,R![0, 1]>,<19,R![2, 1]>,<23,R![-9, 1]>,<47,R![4, 1]>],Snew);
    return Vf;
end function;