
// Make newform 3360.2.a.be in Magma, downloaded from the LMFDB on 25 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_be();".
// 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_be();".
// 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 := [-2, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [0, 2]];
    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, 1], [-2, -1], [2, -2], [0, 1], [-4, 0], [-2, 2], [0, 1], [-6, 2], [-2, 2], [-4, -2], [0, -4], [2, -3], [0, 0], [-2, -4], [-4, 0], [-8, 1], [-2, 1], [-4, 4], [-12, 2], [6, -2], [-10, -1], [-6, 4], [-8, 0], [-8, 0], [-2, 4], [18, -1], [0, 2], [0, -2], [2, 1], [0, -7], [6, -4], [-4, -2], [-10, 1], [-12, 2], [-8, 6], [2, 6], [8, 1], [-18, -2], [-16, -1], [10, 0], [10, -1], [0, -3], [-20, 0], [0, -6], [-12, -2], [14, 4], [26, -1], [16, 1], [2, 2], [0, -4], [18, 4], [-4, 6], [-6, -4], [8, -1], [-14, -6], [2, -6], [-4, 4], [-14, 2], [-12, 2], [-8, 0], [-2, -1], [10, 1], [-4, 0], [10, 4], [24, -2], [-18, -4], [10, 6], [8, -9], [24, -2], [10, 0], [4, 2], [0, 10], [-2, -4], [6, 3], [10, 4], [2, -4], [0, 6], [-10, 4], [-8, -3], [22, 3], [16, 1], [8, -6], [2, 0], [-14, -2], [-6, -8], [8, 10], [12, -6], [8, 4], [0, -2], [-8, 9], [12, 2], [0, -14], [10, -4], [-2, -6], [-28, -2], [22, 8], [-20, 0], [18, 1], [-12, -4], [2, 8], [-4, -14], [-2, -1], [-4, 4], [34, -2], [24, 3], [-30, -2], [24, 2], [-22, 2], [26, 3], [16, 9], [4, -8], [-6, -2], [-28, 2], [-8, 6], [18, 3], [0, -13], [6, 0], [34, 2], [10, 6], [16, 2], [-32, 7], [30, 6], [6, 4], [32, -2], [32, -2], [6, -13], [20, -2], [-20, -2], [20, 0], [-22, 0], [-2, -2], [-6, 6], [-14, -6], [-36, -2], [18, 6], [-22, 6], [24, 9], [-18, -10], [8, 10], [0, 16], [6, -10], [32, -6], [-34, -1], [10, 12], [-8, -9], [-36, 0], [26, -10], [-26, 6], [-4, -8], [24, 4], [12, 8], [-8, 3], [12, -4], [6, -10], [-50, -3], [34, 0], [0, 18], [-14, 15], [8, -12], [-8, 0], [-22, -5], [-40, 4], [-20, 12], [-10, -5], [42, -4], [-38, -2], [40, -3], [-2, 10], [-8, -11], [-30, 8], [0, -1], [-10, -18], [-20, -4], [30, 4], [24, 2], [30, 10], [16, 0], [-16, -12], [10, 8], [-6, -6], [-20, -6], [-22, 12], [18, 10], [-12, 2], [-14, 0], [-16, 6], [-18, 15], [0, -16], [-12, -2], [26, 4], [40, -2], [-22, -6], [-6, -4], [42, -4], [-46, 0], [16, -6], [-10, 6], [-16, -7], [-18, 17], [2, 10], [0, -16], [10, 2], [8, -1], [64, 0], [-22, -6], [16, -9], [-30, 6], [-14, 0], [16, 12], [-20, -6], [-40, 2], [-14, 6], [-48, -2], [-18, -6], [4, 14], [2, 7], [6, -12], [8, 1], [-14, 6], [-32, -8], [-12, 0], [6, -12], [-22, 16], [8, 11], [-32, 8], [-16, 1], [-6, -8], [8, -11], [-20, -6], [-38, 2], [12, -6], [-32, -12], [26, 4], [18, 3], [-40, 1], [-32, 14], [8, 4], [-40, -3], [0, -8], [70, 0], [-6, 24], [24, -2], [48, 2], [32, 6], [-12, 0], [-20, -12], [-22, -14], [14, 14], [4, -16], [-30, 12], [-38, -10], [8, -11], [6, 4], [-4, -24], [-14, -6], [-2, -13], [-16, -18], [-24, 2], [30, 12], [-2, 21], [10, -2], [8, -1], [6, -18], [-50, 6], [-36, 12], [-38, 11], [62, -2], [28, -14], [-10, -9], [20, 8], [-50, -1], [0, -10], [8, -16], [-2, 8], [-54, -8], [-32, 4], [-64, 0], [4, -20], [32, -4], [6, 10], [-4, 18], [48, -5], [42, 2], [-38, 13], [-16, -15], [-10, -6], [-26, -2], [-36, 10], [10, -1], [-24, 6], [-22, -4], [-38, 8], [24, 19], [-46, 8], [-56, 0], [-44, 2], [6, -19], [2, 27], [-68, -6], [40, 6], [4, 10], [2, 8], [56, 4], [22, 0], [-24, -11], [74, 0], [40, -8], [-10, -10], [-38, -4], [-12, -24], [12, 16], [26, 18], [-56, 6], [32, 11], [-2, -25], [-54, 0], [16, -9], [26, 18], [-38, -8], [24, 4], [-14, 1], [50, -2], [20, -18], [-36, -12], [-20, 8], [50, 1], [-26, 4], [2, -25], [-16, -9], [-28, -16], [-20, -8], [-44, -4], [38, -4], [-6, -8], [-38, 6], [-8, -6], [-38, -8], [-14, 15], [-30, -4], [-12, 2], [26, -13], [-48, 11], [30, 16], [-28, 8], [8, -6], [-30, -22], [-40, -7], [50, -6], [6, -2], [24, 20], [14, 8], [34, -6], [-8, 10], [0, -22], [10, -5], [4, 2], [-86, 0], [-26, -6], [-28, 14], [-56, 7], [-12, 30], [82, 2], [26, 12], [-16, 12], [42, 8], [0, 17], [-8, 7], [-12, -2], [6, 20], [8, -9], [-22, -26], [-32, -18], [-16, -25], [30, 11], [38, 10], [-42, -7], [34, 8], [2, -9], [-8, -26], [2, 33], [-48, -11], [32, 6], [4, -8], [-18, 15], [-4, 24], [-40, -8], [58, 0], [-38, 0], [32, -1], [4, -14], [8, 25], [-6, 24], [-16, 11], [-18, 10], [-12, 18], [6, 6], [-34, 2], [26, 15], [0, -16], [18, 24], [42, -4], [56, 7], [-6, 6], [-62, -4], [52, 12], [-8, -20], [-58, -11], [-62, 1], [-32, 18], [28, -8], [34, -12], [10, -4], [-8, 25], [8, -14], [-54, 2], [0, 0], [-26, 16], [22, -21], [36, 2], [-8, 4], [62, -9], [26, 10], [32, -4], [-30, -16], [72, 7], [64, -6]];
    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_be();".
// 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_be(: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_be();".
// 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_be( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_3360_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<11,R![-8, 0, 1]>,<13,R![-4, 4, 1]>,<17,R![-28, -4, 1]>,<19,R![-8, 0, 1]>,<23,R![4, 1]>],Snew);
    return Vf;
end function;