
// Make newform 6384.2.a.c in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_6384_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_6384_2_a_c();".
// 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_6384_2_a_c();".
// 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_6384_a();"
function MakeCharacter_6384_a()
    N := 6384;
    order := 1;
    char_gens := [799, 4789, 2129, 913, 1009];
    v := [1, 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_6384_a_Hecke(Kf)
    return MakeCharacter_6384_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], [-4], [1], [6], [-4], [-4], [1], [-2], [2], [-4], [2], [6], [0], [8], [-14], [4], [-10], [-10], [4], [-14], [-2], [0], [6], [0], [4], [4], [-12], [-6], [18], [2], [20], [-18], [-20], [-18], [14], [-22], [24], [-8], [10], [-4], [16], [14], [26], [22], [-8], [-10], [16], [20], [-2], [6], [22], [28], [20], [-6], [2], [-6], [-8], [-10], [10], [4], [18], [8], [4], [-14], [-18], [10], [6], [-6], [-30], [4], [34], [32], [14], [34], [24], [34], [10], [30], [24], [12], [-2], [-12], [0], [-20], [-18], [-30], [-10], [36], [0], [8], [-4], [34], [-30], [-24], [-28], [42], [38], [-16], [-14], [-10], [-10], [-44], [-10], [4], [-38], [0], [16], [28], [-8], [24], [-34], [-2], [-12], [-12], [-22], [36], [-12], [-14], [36], [0], [22], [6], [-8], [4], [-6], [10], [-12], [32], [-30], [-4], [32], [-22], [46], [16], [18], [42], [-32], [2], [10], [40], [30], [-24], [28], [-44], [-48], [46], [-18], [-4], [-48], [-54], [12], [0], [24], [26], [-52], [0], [-52], [38], [2], [-30], [-22], [-4], [12], [-18], [-16], [30], [-14], [-38], [36], [24], [32], [42], [2], [-24], [40], [28], [-38], [40], [14], [44], [12], [-14], [34], [34], [28], [38], [44], [22], [-40], [12], [42], [-34], [54], [58], [6], [10], [22], [-44], [-36], [42], [-40], [-32], [4], [32], [4], [24], [24], [-6], [-48], [14], [28], [24], [20], [24], [52], [32], [6], [-12], [-6], [-30], [-32], [-18], [-24], [-12], [22], [-54], [-64], [68], [-54], [18], [24], [2], [6], [-28], [24], [-62], [14], [30], [-24], [72], [36], [-40], [6], [-22], [28], [-40], [-52], [-46], [-54], [50], [40], [54], [-20], [-16], [-50], [10], [4], [-42], [-18], [-14], [56], [10], [-76], [-24], [-44], [10], [40], [38], [-78], [0], [58], [18], [-44], [0], [48], [-18], [22], [10], [-16], [24], [40], [52], [28], [52], [18], [-34], [-54], [64], [58], [-10], [-8], [-86], [4], [-18], [48], [-20], [-68], [-4], [60], [54], [18], [-28], [80], [-8], [46], [8], [-4], [-34], [-46], [8], [-30], [26], [-50], [-90], [-32], [-72], [-52], [-66], [54], [52], [70], [-66], [6], [66], [52], [58], [-24], [4], [34], [18], [-82], [64], [4], [-40], [48], [-30], [38], [-42], [-48], [14], [-58], [-18], [-22], [46], [84], [-22], [38], [-16], [-12], [-36], [34], [-90], [24], [-50], [38], [48], [60], [18], [60], [42], [-56], [60], [-64], [-4], [-10], [-8], [42], [74], [-74], [68], [-6], [22], [-32], [10], [-36], [-34], [-6], [-72], [28], [-66], [-70], [-20], [-6], [-28], [-48], [36], [-10], [-16], [32], [-18], [-2], [2], [-68], [56], [38], [-60], [18], [-38], [-30], [-60], [10], [38], [58], [10], [48], [46], [54], [40], [64], [56], [-70], [-60], [-56], [22], [-96], [48], [-32], [28], [-40], [-50], [48], [82], [84], [96], [-46], [-44], [6], [28], [0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_6384_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_6384_2_a_c();".
// 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_6384_2_a_c(:prec:=1)
    chi := MakeCharacter_6384_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_6384_2_a_c();".
// 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_6384_2_a_c( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_6384_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![4, 1]>,<11,R![-6, 1]>,<13,R![4, 1]>,<17,R![4, 1]>,<23,R![2, 1]>],Snew);
    return Vf;
end function;