
// Make newform 3328.2.a.m in Magma, downloaded from the LMFDB on 04 March 2026.
// To make the character of type GrpDrchElt, type "MakeCharacter_3328_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_3328_2_a_m();".
// 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_3328_2_a_m();".
// 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 := [-3, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    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_3328_a();"
function MakeCharacter_3328_a()
    N := 3328;
    order := 1;
    char_gens := [1535, 261, 769];
    v := [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_3328_a_Hecke( : Kf := Kf)
    return MakeCharacter_3328_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, 0], [-2, 0], [0, -2], [-3, 1], [-3, -1], [1, 0], [2, 2], [1, -1], [4, 0], [2, 0], [5, 1], [2, 4], [-2, -4], [-4, 2], [-5, -1], [-4, 4], [-5, -3], [-4, 4], [1, -1], [-3, -3], [4, 2], [-2, -2], [-5, 1], [0, 10], [-4, 6], [12, 0], [0, 4], [-2, 4], [-2, 0], [6, -2], [4, 0], [-6, -8], [-6, -4], [-10, 0], [6, 4], [5, -7], [-10, -4], [-15, -1], [3, -5], [0, 4], [0, 6], [2, 4], [18, -2], [-12, 6], [10, -4], [-4, 12], [-6, 8], [-5, 3], [-15, 7], [-12, 10], [-10, -4], [-17, -1], [-20, -6], [-4, 6], [-10, -8], [-10, -10], [6, -8], [15, 3], [12, -8], [8, -10], [16, 2], [-26, -4], [1, -1], [8, -4], [10, -6], [0, 2], [-5, 13], [-2, 2], [-14, 4], [20, -6], [-18, 4], [9, 13], [-2, 14], [-6, 12], [-1, 9], [19, -5], [-2, 0], [-8, 2], [8, -2], [-6, -4], [10, 12], [0, -14], [-27, -7], [14, -12], [-4, 4], [-30, 0], [28, -6], [14, 0], [14, 4], [7, -5], [-12, -14], [-23, 1], [-13, -17], [0, -14], [9, -1], [34, -2], [4, 6], [-6, 18], [14, 0], [-10, 4], [-2, 8], [14, 12], [4, 2], [14, 0], [20, -10], [-14, 4], [-13, 5], [6, -8], [-14, -18], [-6, 6], [10, -10], [10, -20], [-24, -10], [-3, -9], [-23, -11], [2, -14], [11, 1], [24, 8], [-10, 4], [-14, 0], [0, -10], [2, 18], [-28, 4], [-23, 3], [-7, 23], [-6, -20], [-12, -10], [-24, -4], [-16, -4], [20, 10], [7, -27], [-27, -3], [-8, 4], [-20, -12], [2, -12], [28, 2], [-24, -2], [17, 7], [-30, 0], [2, 2], [37, -9], [24, 14], [20, 0], [7, 1], [-8, -12], [5, -15], [24, 18], [-6, 8], [18, 0], [-3, 1], [-20, -2], [-6, -16], [-28, -2], [6, 14], [-16, 22], [14, -10], [-18, -10], [24, -2], [-14, 16], [8, 14], [19, 17], [18, 8], [17, -15], [-30, 8], [-48, -6], [11, 3], [26, -10], [8, -24], [-12, -10], [-28, -8], [-29, -3], [-30, 4], [12, 20], [-8, -2], [40, 12], [10, -16], [35, 5], [-56, 2], [12, -8], [-38, -8], [53, 5], [44, 2], [8, 0], [-8, -10], [-19, 21], [-18, 4], [-18, 0], [-29, 17], [14, 8], [-39, 1], [30, 14], [33, -13], [42, 8], [6, -20], [-36, 2], [-6, -20], [14, -12], [10, -12], [-30, 20], [6, 6], [24, -6], [18, -18], [6, 12], [-2, 6], [-37, 5], [-4, 4], [-37, 3], [-10, -24], [12, -14], [-4, -34], [-50, -12], [24, -24], [14, -22], [-15, 11], [5, -3], [22, 16], [-26, -22], [6, -16], [-33, 19], [-22, 12], [-24, 16], [23, 7], [20, 6], [-7, -27], [-8, -22], [8, -20], [42, -8], [6, 6], [-44, -12], [5, 7], [-22, -16], [-46, -4], [15, -17], [-18, 6], [18, 4], [-7, -19], [48, 2], [24, -10], [-28, 2], [14, 26], [-51, -5], [16, 10], [22, 26], [12, 10], [-18, 32], [-8, 32], [-43, -3], [17, 15], [-43, -17], [-16, 8], [-28, 14], [18, -8], [45, -7], [-2, -26], [-6, 4], [-9, 21], [-34, -4], [-15, 35], [-38, -20], [42, -4], [-40, -8], [-46, -20], [-34, -16], [24, -16], [0, -22], [22, -12], [-10, -16], [48, -6], [-35, 15], [72, -4], [-12, -24], [41, 15], [12, 10], [-8, -20], [-34, -26], [25, 1], [-75, -1], [2, -12], [-52, 2], [-44, 22], [70, 2], [33, 13], [30, 14], [-38, -12], [-19, -17], [12, 40], [42, 16], [-42, 12], [-31, 21], [-18, -24], [0, 40], [-18, -28], [-44, -10], [57, 3], [26, -16], [54, -4], [38, 14], [2, -40], [-6, -32], [-47, -1], [30, 8], [-12, 10], [-24, 20], [-14, -4], [-6, -28], [-4, -14], [-32, -6], [4, 36], [-55, -3], [62, 12], [42, 6], [14, 12], [-34, 2], [46, -16], [27, 35], [-62, 6], [-7, -17], [39, 7], [14, -20], [54, 2], [32, -6], [-34, 0], [44, 20], [23, 11], [-34, -16], [-14, 24], [-49, -19], [69, -1], [8, -36], [42, 8], [-52, -18], [42, -20], [-6, 34], [-1, 29], [59, 5], [-1, -15], [8, 30], [-6, -20], [12, 22], [-20, -36], [-52, 6], [2, -14], [-2, 12], [44, 4], [36, -14], [32, 10], [50, 8], [-9, -23], [-11, -27], [38, -20], [-5, -15], [-10, -32], [-30, 0], [-16, -20], [-40, -4], [-6, 30], [-15, -7], [-39, -5], [-2, -12], [-1, -37], [-16, 26], [-2, 30], [-26, -30], [69, -17], [-28, 6], [18, 46], [-30, 12], [-53, -13], [34, -10], [-2, 12], [-20, -34], [29, 21], [60, 12], [-62, -6], [64, 0], [15, 13], [36, -24], [-34, 8], [66, 0], [-6, -42], [-38, 24], [18, 24], [-5, 27], [-26, 8], [-51, 11], [-3, 33], [9, 5], [-8, 20], [21, -9], [6, -6], [-66, 0], [6, -20], [21, 47], [-22, -8], [-25, -17], [22, -8], [29, 25], [-62, 14], [18, 4], [-50, 12], [-38, 8], [18, 42], [-67, 21], [-6, -24], [28, 2], [14, -2], [8, 6], [-24, -22], [-9, -35], [27, 1], [22, 8], [28, 28], [18, -20], [28, -18], [-22, 44], [-8, -8], [-41, 31], [54, -26], [24, 10], [-8, 8], [0, -12], [-10, -20], [-25, -1], [42, -8], [-14, 20], [-78, -12], [-48, 22], [-52, 18], [-35, -1], [14, -22]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_3328_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_3328_2_a_m();".
// 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_3328_2_a_m(:prec:=2)
    chi := MakeCharacter_3328_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_3328_2_a_m();".
// 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_3328_2_a_m( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_3328_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![2, 1]>,<5,R![-12, 0, 1]>,<7,R![6, 6, 1]>],Snew);
    return Vf;
end function;