
// Make newform 3360.2.a.r in Magma, downloaded from the LMFDB on 25 December 2025.
// 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_r();".
// 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_r();".
// 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_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 := 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]];
    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], [1], [-1], [1], [2], [0], [-6], [-6], [-8], [6], [-6], [-10], [2], [-4], [8], [-12], [12], [-10], [-4], [-2], [4], [4], [12], [6], [16], [-10], [0], [-16], [-14], [-4], [-8], [8], [-8], [2], [18], [-8], [-12], [12], [8], [-26], [-22], [-14], [18], [-14], [-24], [10], [-4], [20], [12], [14], [12], [6], [-18], [20], [6], [28], [-10], [-26], [22], [22], [-20], [-10], [16], [0], [16], [-12], [-20], [-14], [20], [22], [-6], [2], [-28], [-6], [-16], [-16], [-6], [-16], [-30], [34], [24], [6], [-18], [-16], [26], [-28], [34], [30], [18], [8], [12], [24], [32], [-6], [-24], [24], [-18], [-6], [16], [14], [-44], [-28], [-4], [42], [-16], [-32], [12], [-6], [18], [-26], [-12], [-26], [4], [26], [20], [-2], [-32], [24], [8], [-10], [-2], [22], [30], [36], [-10], [-18], [-10], [-12], [-36], [-32], [40], [-28], [-12], [34], [-26], [-26], [6], [-48], [-50], [-18], [34], [22], [32], [32], [50], [28], [-48], [30], [14], [-48], [22], [30], [-12], [-24], [-44], [-30], [4], [-2], [-12], [18], [52], [4], [0], [12], [28], [-32], [20], [32], [-50], [-50], [-14], [10], [30], [10], [6], [10], [12], [2], [20], [34], [32], [12], [10], [-22], [44], [54], [-10], [40], [-2], [52], [24], [-56], [40], [10], [-36], [-22], [-50], [-30], [-26], [-64], [6], [34], [-4], [-34], [20], [6], [-50], [-24], [30], [-58], [-34], [54], [-56], [-36], [-28], [-18], [48], [-42], [-28], [-16], [-26], [42], [-2], [64], [44], [26], [6], [10], [-8], [10], [58], [-22], [-8], [-18], [40], [-32], [2], [-48], [-30], [12], [-56], [-6], [32], [-46], [-10], [-52], [-68], [-48], [-4], [-48], [22], [-58], [0], [50], [-18], [-54], [74], [-20], [30], [8], [-8], [28], [-18], [-12], [74], [-26], [-34], [-70], [4], [-64], [-62], [4], [-32], [44], [-40], [60], [-48], [46], [-22], [44], [16], [20], [0], [34], [-32], [-30], [-74], [-12], [10], [14], [-50], [-12], [76], [48], [-54], [50], [-50], [50], [20], [-56], [-4], [8], [24], [-20], [56], [-22], [0], [22], [-42], [-14], [24], [-18], [-38], [76], [-72], [-34], [-48], [-38], [-56], [-6], [14], [-10], [42], [-8], [64], [-10], [64], [-36], [24], [-20], [-22], [-80], [-2], [-4], [20], [-4], [-66], [-66], [-58], [-44], [82], [-20], [-34], [-32], [-24], [-74], [-18], [-60], [68], [22], [50], [78], [38], [80], [-70], [-54], [36], [-96], [-12], [-4], [-62], [10], [36], [6], [80], [94], [42], [88], [26], [-54], [70], [-60], [-54], [-10], [62], [-56], [42], [-56], [-14], [92], [46], [36], [-8], [-88], [42], [64], [-60], [-16], [-76], [-16], [-58], [34], [-98], [-8], [70], [66], [-42], [6], [-64], [-2], [-14], [44], [-80], [-82], [-38], [-34], [-2], [74], [28], [-20], [44], [44], [12], [28], [-78], [-26], [94], [-36], [90], [-96], [-6], [16], [20], [52], [64], [-58], [-8], [58], [-50], [12]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_3360_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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