
// Make newform 3328.2.a.p in Magma, downloaded from the LMFDB on 16 April 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_p();".
// 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_p();".
// 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;
    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], [-1, 1], [-1, -2], [3, -1], [-2, -2], [-1, 0], [1, 0], [0, -4], [6, -2], [2, 4], [-2, -4], [-7, 0], [4, -4], [7, -1], [5, 3], [2, 4], [-8, 0], [0, 0], [-6, 2], [1, 9], [-4, -4], [-2, 10], [2, 10], [8, -4], [-2, 4], [12, -4], [2, -10], [6, 0], [9, 4], [-10, 0], [6, -2], [7, -1], [-10, -4], [-3, -1], [10, -8], [-5, -3], [-16, -4], [6, -6], [-2, -4], [-14, 0], [-3, 7], [2, 4], [22, 2], [10, 8], [7, 0], [10, 6], [3, -1], [11, 1], [4, 12], [-11, 6], [15, -2], [15, -5], [4, 12], [2, -8], [17, -4], [-12, 4], [0, 0], [-11, -1], [8, -12], [-4, 0], [-2, -20], [9, 4], [20, 0], [-16, -4], [-19, 10], [6, -16], [-6, -2], [-15, -2], [25, 3], [-1, -2], [-18, -4], [30, 4], [2, 18], [-8, -16], [6, 6], [15, 9], [-28, 0], [18, 8], [-2, -20], [-22, -4], [-1, -3], [7, 14], [11, -13], [-15, 18], [-4, 20], [-15, 5], [-10, 8], [32, 4], [5, -4], [-6, -12], [-2, 0], [-11, -1], [-6, -12], [-1, 19], [16, 4], [-12, 4], [-10, 8], [-27, -10], [14, 8], [7, 0], [23, 5], [15, -12], [-7, -17], [-9, -4], [23, 9], [4, -4], [10, -6], [-2, 16], [4, 8], [5, -12], [-4, -8], [22, 16], [4, 32], [32, 4], [-25, 13], [-14, 0], [-26, 2], [8, -12], [-16, -4], [2, 24], [18, 8], [-7, -20], [18, -20], [-6, 2], [-12, -16], [-14, 0], [-18, -8], [14, 14], [-34, 2], [-39, 6], [-4, 8], [13, -9], [-28, 0], [-6, 16], [-12, 8], [0, 16], [7, -14], [-32, 4], [4, -20], [-19, 6], [-12, 12], [3, -22], [-28, 0], [0, -24], [6, 12], [22, -12], [9, 18], [-34, -8], [6, 16], [11, -13], [9, -10], [21, -8], [5, -15], [16, 4], [27, 11], [-2, 10], [40, -4], [-20, 12], [26, 8], [21, 14], [-38, -2], [-9, 24], [25, 1], [33, -7], [-10, -8], [3, -1], [-20, -12], [42, 0], [0, -8], [14, 28], [-14, 14], [15, 16], [4, -20], [-8, 0], [14, 14], [9, 26], [-12, 28], [38, -8], [0, 28], [10, 20], [2, 4], [-10, 16], [6, 40], [-24, 0], [26, -4], [-8, 12], [20, -16], [-8, -4], [-20, -8], [-10, 8], [11, 18], [36, -12], [-29, 21], [-30, 24], [-15, 13], [-10, -24], [-28, 0], [-14, 0], [-2, -24], [0, 0], [-5, 18], [-2, -18], [11, -20], [23, 30], [-24, 24], [28, 0], [-29, 5], [22, 20], [-14, -8], [-5, -27], [18, 8], [22, -12], [-18, 6], [4, -16], [41, 5], [14, -4], [28, 28], [-17, 6], [58, 4], [23, 4], [-36, -16], [27, -23], [4, -20], [-41, 9], [-11, -7], [8, 16], [33, -10], [14, -14], [-4, -36], [38, 10], [32, -20], [22, 12], [38, 20], [19, 16], [13, 25], [15, 23], [-48, -16], [1, 30], [-70, 0], [10, -22], [20, 0], [31, 7], [-40, 4], [9, 18], [-2, 12], [10, 34], [-11, 13], [-16, -16], [-22, 38], [28, 0], [-5, 18], [18, 16], [47, 17], [15, 32], [10, -8], [-18, -6], [-26, -24], [-48, 12], [-22, -16], [-52, 16], [52, 20], [27, 27], [23, 32], [-14, 0], [-12, 28], [47, 7], [5, -4], [-42, 12], [-4, 24], [-20, -12], [-58, -4], [-60, 8], [42, -4], [10, -50], [-10, -8], [-2, 24], [-16, 0], [-22, 40], [4, -16], [21, 1], [42, 14], [3, -15], [62, -2], [-6, 16], [-10, 18], [-12, 32], [23, -38], [15, -12], [-9, 31], [46, 16], [-48, -12], [-13, -29], [-16, -20], [42, -26], [-42, 0], [12, -4], [6, -2], [-16, -32], [29, -15], [6, -22], [15, 48], [51, 18], [-2, 10], [-6, 8], [-23, -15], [30, -4], [-13, 35], [-12, 32], [18, 8], [-52, 8], [-38, 22], [27, -44], [35, -4], [34, -32], [27, 33], [-39, 4], [-60, 8], [14, 28], [20, -32], [58, 24], [26, -28], [12, 20], [18, 8], [-19, -31], [52, 4], [-26, 24], [-30, 34], [-12, -4], [-26, -38], [-2, 24], [26, -32], [24, -8], [-2, 10], [-18, -6], [-12, -16], [-24, -8], [10, -8], [44, 8], [30, -16], [18, 22], [-17, 22], [29, -22], [-75, 4], [32, -20], [65, -10], [-23, 39], [-16, -4], [-46, 2], [-31, 29], [-38, 36], [12, -12], [14, 28], [13, -16], [4, -48], [-10, 8], [22, -32], [9, -3], [10, -46], [57, 18], [5, -11], [18, -48], [6, 32], [42, -14], [-58, 26], [-26, -8], [-27, -40], [27, -16], [46, -20], [-53, -14], [-37, -19], [-33, 33], [-3, 15], [76, 12], [16, 4], [30, -24], [10, 50], [-4, -36], [2, -28], [30, -16], [30, -32], [42, 0], [26, 16], [66, -8], [18, 44], [-30, 2], [19, 3], [-73, -13], [-6, 44], [44, 4], [-34, 2], [20, -16], [-1, 12], [36, 36], [7, -13], [-33, 11], [-39, 4], [-5, 25], [19, 30], [6, 8], [49, 0], [65, 4], [-22, 40], [-39, -15], [-26, -48], [-55, 30], [-52, -20], [-75, 18], [20, -8], [-6, 14], [0, 20], [-19, 8], [-12, -52], [5, 9], [-47, -17], [55, 6], [-66, 8], [-1, 33], [-36, 12], [-90, 0], [-28, 0], [-6, 16], [34, -16], [46, 36], [-55, 1], [-62, -4], [-14, 0], [29, -29], [-24, 16], [-24, -32], [-58, -18]];
    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_p();".
// 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_p(: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_p();".
// 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_p( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_3328_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![-1, 2, 1]>,<5,R![-7, 2, 1]>,<7,R![7, -6, 1]>],Snew);
    return Vf;
end function;