
// Make newform 3360.2.a.bd in Magma, downloaded from the LMFDB on 23 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_3360_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_3360_2_a_bd();".
// 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_3360_2_a_bd();".
// 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
        poly := [-1, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [-2, 4]];
    Rf_basisdens := [1, 1];
    Rf_basisnums := ChangeUniverse([[z : z in elt] : elt in Rf_num], Kf);
    Rfbasis := [Rf_basisnums[i]/Rf_basisdens[i] : i in [1..Degree(Kf)]];
    inp_vec := Vector(Rfbasis)*ChangeRing(Transpose(Matrix([[elt : elt in row] : row in input])),Kf);
    return Eltseq(inp_vec);
end function;


// To make the character of type GrpDrchElt, type "MakeCharacter_3360_a();"
function MakeCharacter_3360_a()
    N := 3360;
    order := 1;
    char_gens := [1471, 421, 1121, 2017, 1921];
    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_3360_a_Hecke(Kf)
    return MakeCharacter_3360_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, 0], [-1, 0], [1, 0], [-1, 0], [0, 0], [0, 1], [0, 1], [0, 0], [-2, 1], [4, -1], [2, -1], [4, -1], [2, -2], [-6, 1], [-2, -1], [2, 0], [4, 0], [8, -1], [2, 1], [-2, 3], [4, -1], [-4, 2], [8, -2], [2, 2], [0, 1], [2, 2], [0, -4], [2, -1], [14, 0], [-2, 0], [0, 0], [8, 2], [2, -2], [0, 0], [8, 1], [12, -2], [12, -1], [-2, -1], [6, -1], [6, 0], [16, 0], [0, 3], [10, -3], [-10, 2], [6, -2], [2, 3], [-8, 0], [-8, 4], [8, 2], [16, -1], [-6, -2], [-2, -5], [-6, 0], [16, 2], [4, -1], [14, 1], [22, 0], [-2, 5], [0, 1], [-14, 4], [-12, -4], [-14, -2], [16, -2], [16, -4], [-4, -1], [2, 4], [-32, 0], [-2, -2], [14, 1], [20, 1], [-4, 3], [-2, 3], [12, -2], [-16, -3], [-28, -2], [-10, 3], [20, -1], [12, 3], [-18, 2], [14, 2], [24, 2], [6, -4], [30, -1], [-4, -5], [-26, 1], [6, 1], [6, -6], [-26, 2], [2, -6], [-12, -2], [12, -4], [8, 4], [28, 2], [0, 0], [-20, -2], [26, 1], [22, 0], [-34, 0], [-16, 2], [-6, 2], [2, -3], [10, 0], [-12, 0], [6, -6], [-4, -2], [20, -5], [12, 4], [-8, 1], [2, 1], [-18, -2], [-8, -4], [-28, -1], [-30, 2], [-36, 2], [-16, 4], [-2, -2], [12, 0], [18, -3], [-22, 4], [4, 6], [-24, -5], [10, 8], [6, -4], [10, -5], [-8, -4], [-4, 3], [-14, 6], [-16, 0], [20, 2], [-16, -3], [-16, 0], [6, -3], [-20, 2], [-16, 1], [-18, -4], [18, 0], [-30, -2], [12, 8], [-42, 0], [14, 6], [8, 8], [0, -7], [12, 2], [-2, -3], [20, -3], [32, -4], [-36, -1], [-4, -5], [-4, -2], [26, -5], [16, -7], [-6, 6], [6, 7], [-38, -3], [14, -5], [-14, -3], [12, -10], [22, 4], [0, -7], [-2, 0], [-34, 5], [6, -8], [12, 2], [12, 0], [2, 6], [10, 9], [28, -2], [-4, 3], [18, 8], [-34, 0], [16, 4], [12, 9], [-38, 1], [-2, -6], [10, 3], [-6, -6], [-16, 0], [28, 3], [52, -2], [16, -1], [0, -4], [16, -2], [-40, 5], [-8, -3], [6, 1], [-22, 2], [-20, -5], [-8, -2], [10, 0], [16, 8], [16, -3], [2, -1], [-12, -6], [-6, 6], [-10, -3], [-8, -3], [2, 0], [-4, -5], [36, -1], [-30, -7], [28, 3], [-22, -9], [0, 5], [30, -2], [36, -4], [2, -6], [-14, -1], [14, 1], [-6, 12], [4, 2], [18, 4], [-10, 0], [-24, -4], [-8, 14], [-8, -4], [-22, 8], [20, 2], [-26, -8], [-34, -7], [-14, -8], [2, 14], [6, 13], [46, 2], [36, 2], [-24, -6], [-14, -10], [28, 7], [14, -9], [-12, 10], [-72, 0], [-20, 3], [0, -12], [-32, -4], [34, 0], [40, -6], [-2, -9], [-18, -2], [-26, -2], [32, -8], [-20, 10], [-42, 1], [20, 6], [0, 4], [10, 2], [24, 1], [-52, 2], [28, 10], [20, 4], [-28, 6], [-6, -5], [-8, -7], [30, -8], [-2, -7], [10, 12], [2, -6], [-4, -6], [6, -16], [-4, -4], [-22, 10], [-36, -1], [-20, -10], [-34, -7], [-4, 1], [4, -9], [-4, 7], [-8, 8], [4, 7], [-10, 0], [-2, -9], [2, 4], [44, -7], [46, -5], [64, 1], [-16, 12], [32, 5], [-32, -4], [-14, -13], [-6, 10], [-6, 0], [12, -12], [2, -7], [60, 2], [14, 3], [48, -5], [32, 10], [6, 7], [-10, 14], [2, 0], [10, -13], [-26, -8], [60, 3], [-52, 0], [34, 10], [20, -12], [-4, 15], [18, 2], [-6, -17], [-38, 6], [32, 2], [-12, 8], [8, 1], [18, 8], [44, -2], [22, 1], [-36, -2], [26, -4], [-2, 5], [60, 5], [-50, -1], [40, 1], [-30, 9], [12, -9], [22, 6], [-2, -9], [-22, -5], [46, -6], [-4, 8], [26, 9], [-16, 5], [-14, -4], [12, 6], [-22, -12], [10, -6], [0, 12], [54, -4], [-22, 0], [-12, 10], [-24, -10], [-2, 5], [6, 2], [30, -12], [18, -8], [-54, -1], [-48, -10], [8, -4], [8, -2], [-54, 6], [32, -11], [-2, 10], [48, -8], [-64, -3], [-78, 2], [-26, 4], [-24, -8], [2, 0], [24, 0], [-24, 3], [2, -15], [-36, -6], [-14, 6], [60, -6], [-18, 6], [16, -11], [-72, -4], [-22, -10], [20, -5], [0, -8], [12, 4], [22, -12], [18, 3], [32, -3], [22, 4], [-14, 3], [-20, -2], [36, -4], [6, -6], [-30, -2], [8, 8], [26, 8], [-28, -6], [-4, -2], [58, 3], [-36, -5], [14, 5], [-32, 13], [-8, 10], [26, -3], [-12, -13], [-10, 8], [-36, 7], [-6, 14], [-58, 0], [44, -10], [6, 0], [-40, -4], [-2, -13], [16, 16], [0, 1], [66, -7], [-46, 1], [-38, 4], [30, -4], [36, -6], [72, 6], [-34, -9], [-14, 4], [-18, 13], [-62, -6], [64, 4], [16, 9], [24, -13], [-10, 12], [40, -12], [0, 13], [-42, 4], [30, 5], [-80, 5], [-18, 6], [-32, -6], [52, -4], [-32, -3], [-10, 18], [-34, 9], [-28, 6], [-18, -6], [38, 0], [38, -13], [8, 12], [-20, -9], [-14, -3], [4, -5], [68, -1], [-2, -3], [-4, 4], [-28, -13], [2, 10], [10, -13], [-6, -4], [92, 2], [8, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_3360_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_3360_2_a_bd();".
// 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_3360_2_a_bd(:prec:=2)
    chi := MakeCharacter_3360_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_3360_2_a_bd();".
// 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_3360_2_a_bd( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_3360_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<11,R![0, 1]>,<13,R![-20, 0, 1]>,<17,R![-20, 0, 1]>,<19,R![0, 1]>,<23,R![-16, 4, 1]>],Snew);
    return Vf;
end function;