
// Make newform 6930.2.a.k in Magma, downloaded from the LMFDB on 20 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_6930_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_6930_2_a_k();".
// 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_6930_2_a_k();".
// 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_6930_a();"
function MakeCharacter_6930_a()
    N := 6930;
    order := 1;
    char_gens := [1541, 1387, 2971, 2521];
    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_6930_a_Hecke(Kf)
    return MakeCharacter_6930_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 := [[-1], [0], [1], [-1], [1], [-6], [0], [6], [-4], [2], [4], [-12], [2], [6], [-6], [6], [-4], [8], [10], [-10], [-10], [8], [0], [6], [2], [-6], [-8], [-12], [-6], [-10], [8], [-20], [-6], [2], [-18], [-8], [-6], [10], [10], [-18], [-24], [-12], [-2], [14], [-10], [0], [12], [-24], [28], [8], [-6], [-18], [-22], [-20], [-8], [12], [-14], [20], [28], [28], [16], [26], [-8], [0], [-10], [-14], [-32], [-10], [-20], [-20], [24], [-2], [-16], [32], [-16], [34], [-26], [-10], [0], [10], [4], [-18], [2], [26], [-20], [-20], [-28], [-22], [-14], [4], [0], [-28], [-40], [0], [32], [-30], [30], [14], [28], [-10], [-2], [-30], [-28], [36], [32], [46], [-28], [0], [-10], [10], [-24], [-24], [-18], [-22], [-32], [4], [16], [18], [34], [4], [4], [-10], [30], [-4], [-6], [-38], [18], [-40], [-40], [10], [12], [-32], [-32], [-44], [30], [30], [18], [-24], [-18], [-12], [10], [50], [-4], [-36], [8], [-52], [10], [-12], [-22], [40], [28], [10], [10], [26], [18], [22], [-32], [-6], [-54], [42], [-12], [42], [24], [-4], [6], [-22], [32], [-6], [-34], [6], [-28], [-4], [6], [62], [36], [-14], [-8], [30], [-40], [-4], [-4], [-12], [-12], [-48], [-56], [-42], [24], [-32], [-10], [-44], [26], [-52], [-8], [50], [12], [12], [30], [0], [52], [14], [-50], [0], [-38], [30], [12], [18], [52], [-4], [48], [-22], [-50], [50], [48], [32], [0], [14], [-48], [-38], [16], [66], [-18], [-40], [72], [28], [68], [-10], [56], [54], [40], [48], [8], [46], [56], [32], [4], [74], [34], [22], [-64], [-44], [-36], [-10], [-24], [66], [24], [36], [-32], [4], [52], [-36], [-36], [-6], [-48], [22], [50], [-8], [-26], [-16], [2], [-38], [44], [-12], [80], [38], [-72], [-30], [6], [14], [34], [38], [-20], [-26], [54], [0], [14], [56], [-68], [-42], [-34], [60], [-26], [-24], [50], [60], [52], [10], [-86], [-74], [76], [-42], [30], [-20], [18], [-20], [-52], [-66], [36], [26], [20], [-32], [34], [58], [0], [-12], [76], [-6], [84], [-12], [-50], [64], [70], [2], [12], [50], [20], [-10], [12], [-42], [-22], [72], [70], [6], [78], [24], [-66], [-38], [-52], [8], [-68], [-26], [-46], [-30], [48], [-16], [-24], [48], [-38], [-40], [-2], [56], [-44], [-50], [-26], [32], [-42], [-72], [0], [22], [-24], [-30], [-14], [2], [-62], [-56], [22], [12], [-72], [-4], [-22], [48], [-8], [22], [48], [12], [36], [-54], [-62], [52], [90], [-20], [34], [68], [10], [36], [48], [36], [-50], [34], [2], [42], [30], [54], [-72], [-2], [-22], [-22], [16], [62], [-66], [78], [18], [86], [-52], [-44], [6], [-30], [24], [-22], [48], [-66], [84], [-74], [28], [-60], [-70], [-40], [32], [-96], [84], [-36], [34], [-54], [-44], [8], [-34], [54], [14], [-48], [96], [90], [30], [-46], [-12], [-84], [70], [82], [-4], [-40], [-2], [-24], [98], [84], [20], [58], [-6], [70], [42], [46], [-34], [-100], [-36], [0], [-10], [-74], [86], [-34], [-88], [-106], [-74], [-32], [-94], [-72], [44], [-62], [-66], [30], [106], [84], [86], [46], [52], [-96], [-68], [-58], [88], [-50], [64], [16], [-8], [-98], [-44], [-44], [-32], [90], [12], [-58], [-42], [-72], [-18], [66], [-102], [-54]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_6930_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_6930_2_a_k();".
// 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_6930_2_a_k(:prec:=1)
    chi := MakeCharacter_6930_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(3449) - 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_6930_2_a_k();".
// 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_6930_2_a_k( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_6930_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<13,R![6, 1]>,<17,R![0, 1]>,<19,R![-6, 1]>,<23,R![4, 1]>,<29,R![-2, 1]>,<31,R![-4, 1]>],Snew);
    return Vf;
end function;