
// Make newform 6930.2.a.d in Magma, downloaded from the LMFDB on 25 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_d();".
// 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_d();".
// 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], [-2], [-2], [-4], [-8], [-6], [8], [-2], [-2], [4], [-8], [10], [12], [-2], [-4], [-8], [2], [16], [4], [14], [10], [-6], [8], [-12], [14], [14], [0], [-12], [-10], [-12], [-14], [24], [-18], [-4], [0], [18], [4], [22], [16], [-14], [26], [0], [-12], [0], [4], [6], [-10], [0], [2], [12], [14], [8], [2], [-8], [-2], [22], [4], [26], [-20], [24], [-30], [-30], [28], [2], [-12], [-2], [30], [-8], [0], [30], [28], [24], [2], [30], [-18], [26], [4], [-26], [-16], [-38], [16], [36], [-18], [-38], [34], [-32], [-12], [0], [24], [-20], [4], [0], [18], [14], [-12], [-2], [-20], [2], [-12], [38], [12], [-6], [12], [14], [24], [26], [32], [-18], [22], [4], [-40], [30], [12], [-48], [-14], [-12], [22], [34], [26], [36], [28], [-38], [6], [0], [-24], [-2], [4], [8], [32], [-34], [30], [34], [-38], [12], [2], [6], [-28], [18], [40], [20], [-2], [24], [-26], [-42], [20], [-16], [38], [38], [-20], [0], [4], [16], [-24], [6], [2], [-46], [-52], [6], [-40], [12], [46], [48], [32], [-58], [-46], [10], [-52], [30], [24], [-38], [8], [30], [12], [-30], [40], [46], [16], [-60], [14], [-42], [64], [-6], [-42], [-4], [-22], [48], [-38], [-12], [-28], [18], [12], [-26], [50], [54], [30], [64], [-22], [40], [22], [18], [44], [-62], [56], [28], [22], [4], [-46], [-22], [-8], [44], [-56], [-6], [32], [-42], [8], [-62], [-10], [0], [-50], [-32], [-60], [-26], [-42], [0], [8], [-36], [-26], [-20], [32], [-42], [52], [-40], [-30], [-54], [60], [-24], [60], [36], [40], [-2], [-34], [-40], [32], [4], [-4], [-48], [-58], [22], [40], [-6], [-14], [-60], [38], [20], [-70], [-14], [-16], [12], [-26], [30], [-50], [-4], [-6], [-18], [-28], [42], [46], [-4], [-14], [80], [58], [-56], [-12], [-34], [10], [-60], [-8], [-40], [0], [-26], [20], [0], [2], [-38], [-32], [70], [-70], [36], [-26], [44], [6], [18], [40], [74], [-36], [-20], [-46], [-62], [-16], [-52], [12], [-62], [68], [-50], [56], [-18], [-56], [18], [62], [12], [88], [-38], [84], [48], [58], [-66], [28], [58], [-30], [-16], [54], [82], [-76], [-28], [16], [26], [-66], [66], [-56], [-12], [28], [-36], [-34], [-50], [-54], [16], [14], [6], [10], [24], [66], [84], [-26], [-28], [0], [42], [-84], [26], [42], [64], [-42], [-74], [80], [-36], [-50], [24], [-50], [-2], [-64], [60], [44], [-6], [82], [-56], [90], [68], [-60], [0], [-62], [-64], [-10], [52], [0], [10], [-42], [-62], [50], [22], [72], [-34], [-20], [64], [-96], [-10], [-44], [56], [-94], [58], [-84], [76], [-8], [58], [-24], [-2], [28], [18], [30], [-34], [64], [-42], [-54], [80], [70], [62], [92], [20], [-22], [42], [-76], [-76], [58], [34], [0], [-56], [62], [16], [42], [38], [64], [-36], [50], [-46], [12], [-74], [4], [72], [10], [-92], [-20], [24], [-2], [54], [10], [38], [20], [-32], [-84], [-66], [22], [16], [82], [-66], [68], [8], [50], [14], [60], [40], [76], [94], [-46], [-14], [-98], [36], [86], [6], [-52], [88], [-60], [-26], [68], [34], [72], [76], [30], [12], [16], [28], [96], [-94], [28], [62], [26], [56], [-40], [42], [2], [-34]];
    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_d();".
// 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_d(: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_d();".
// 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_d( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_6930_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<13,R![2, 1]>,<17,R![2, 1]>,<19,R![4, 1]>,<23,R![8, 1]>,<29,R![6, 1]>,<31,R![-8, 1]>],Snew);
    return Vf;
end function;