
// Make newform 6930.2.a.v in Magma, downloaded from the LMFDB on 18 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_v();".
// 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_v();".
// 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], [0], [-2], [-4], [-10], [-4], [-4], [6], [6], [6], [-6], [-12], [0], [2], [2], [-10], [0], [-16], [18], [-14], [6], [0], [-4], [-6], [-6], [8], [-20], [-10], [10], [-6], [16], [18], [18], [-2], [10], [-16], [-4], [-6], [-26], [-22], [-8], [-28], [0], [-12], [-16], [-26], [2], [2], [-12], [24], [-12], [-18], [12], [4], [-12], [8], [-2], [16], [24], [6], [-18], [-16], [-2], [-12], [20], [-24], [18], [24], [24], [16], [14], [10], [14], [16], [-14], [-36], [-34], [14], [26], [20], [28], [-20], [34], [30], [4], [0], [12], [-24], [-40], [0], [6], [18], [-22], [4], [22], [30], [30], [-20], [-20], [-24], [14], [28], [0], [-30], [2], [8], [16], [-30], [10], [32], [44], [-16], [-2], [30], [4], [44], [46], [-38], [12], [10], [-18], [-46], [-32], [-32], [-46], [-12], [-16], [16], [28], [10], [-26], [-18], [16], [34], [-36], [34], [6], [44], [4], [0], [12], [50], [-36], [-22], [-48], [-12], [-2], [-30], [14], [58], [18], [8], [30], [58], [-10], [-12], [22], [8], [36], [-6], [54], [-48], [18], [-18], [26], [-12], [-12], [26], [-26], [-4], [-58], [-16], [-30], [-40], [20], [28], [20], [-36], [32], [16], [-22], [-16], [16], [6], [-36], [-38], [36], [56], [-2], [-12], [4], [14], [-8], [12], [42], [42], [56], [2], [-10], [36], [-2], [-20], [36], [-48], [-54], [6], [30], [16], [-32], [0], [-34], [-48], [62], [24], [-66], [-50], [32], [8], [44], [12], [22], [24], [-14], [-24], [8], [-64], [-74], [-16], [0], [-28], [46], [-30], [10], [-8], [20], [12], [78], [-32], [34], [-24], [60], [72], [28], [44], [4], [-60], [14], [56], [-10], [6], [48], [6], [8], [-18], [-22], [-20], [-36], [-24], [46], [-8], [-30], [-6], [26], [34], [-6], [-76], [46], [-26], [-56], [-2], [-32], [44], [-26], [30], [60], [-78], [-72], [54], [-76], [12], [30], [-54], [-38], [-60], [-30], [-30], [-28], [78], [44], [20], [-46], [28], [22], [20], [-24], [-62], [-42], [-72], [52], [-52], [-6], [68], [44], [10], [-24], [66], [-34], [52], [58], [-36], [-2], [-60], [-22], [-86], [-24], [46], [22], [2], [-24], [34], [-70], [-84], [-8], [36], [-22], [50], [-66], [8], [-64], [-48], [-32], [74], [-24], [-34], [72], [12], [34], [-86], [48], [-54], [-48], [24], [-34], [-88], [-2], [-22], [82], [-34], [56], [-10], [36], [-64], [-20], [-90], [8], [96], [18], [72], [60], [4], [-38], [70], [20], [-22], [-100], [34], [28], [62], [-20], [-40], [-84], [-46], [-30], [70], [26], [34], [26], [40], [50], [-14], [-58], [16], [22], [46], [34], [82], [26], [12], [-60], [-14], [10], [32], [78], [-48], [-86], [-36], [10], [92], [-36], [-42], [32], [-24], [-48], [-44], [-12], [-14], [22], [-76], [80], [-58], [-38], [34], [-40], [32], [-66], [-94], [-70], [-76], [44], [-10], [-82], [60], [-56], [-50], [24], [34], [-28], [4], [-42], [-94], [50], [-38], [62], [38], [36], [68], [-16], [-106], [74], [110], [66], [32], [50], [-74], [-8], [34], [64], [-76], [-106], [14], [34], [58], [4], [78], [18], [-44], [96], [60], [86], [-16], [-42], [24], [64], [-40], [-34], [68], [-76], [40], [-70], [12], [-2], [90], [0], [90], [-66], [10], [46]];
    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_v();".
// 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_v(: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_v();".
// 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_v( : 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![0, 1]>,<19,R![2, 1]>,<23,R![4, 1]>,<29,R![10, 1]>,<31,R![4, 1]>],Snew);
    return Vf;
end function;