
// Make newform 8352.2.a.l in Magma, downloaded from the LMFDB on 12 December 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_8352_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_8352_2_a_l();".
// 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_8352_2_a_l();".
// 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_8352_a();"
function MakeCharacter_8352_a()
    N := 8352;
    order := 1;
    char_gens := [1567, 5221, 929, 4033];
    v := [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_8352_a_Hecke( : Kf := Kf)
    return MakeCharacter_8352_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], [0, 0], [-1, 0], [-2, 0], [1, -1], [1, 2], [0, 2], [-2, 4], [4, 2], [-1, 0], [-1, 1], [0, -4], [2, -2], [-1, -3], [3, -1], [-3, 6], [4, 6], [4, -6], [-4, 0], [6, -2], [-8, 0], [-1, 7], [4, -6], [6, 2], [-6, -2], [0, -8], [6, -10], [6, 0], [5, 4], [-2, -4], [14, 4], [-6, 8], [4, 8], [-4, -6], [-9, -2], [6, -4], [2, 6], [9, 1], [-2, -6], [10, 4], [-6, -6], [15, 8], [-6, 8], [-2, 18], [6, 8], [10, 4], [21, 1], [-2, 2], [6, 14], [2, -6], [-7, -8], [16, -2], [1, -16], [5, -3], [5, 14], [13, -9], [20, 6], [1, 3], [-6, 0], [5, -12], [12, -6], [-2, -8], [11, 5], [18, 8], [-25, -6], [20, -2], [17, 1], [4, -6], [30, -2], [7, 10], [-2, 4], [-15, 9], [-18, -12], [11, 0], [-6, -16], [10, -12], [-16, -12], [-1, -4], [-3, -12], [-6, 16], [34, -2], [4, 10], [4, 14], [28, 0], [-12, 10], [10, -4], [-26, -8], [2, 20], [6, -8], [-4, 14], [25, 3], [-1, -11], [-26, 8], [-13, 9], [8, -22], [23, 5], [-7, -18], [-13, 10], [-12, 12], [20, 16], [-10, -8], [34, -8], [-13, -21], [-2, -4], [8, 20], [-8, -18], [32, -2], [-17, -18], [29, -7], [-30, 10], [1, -29], [-7, 16], [-20, 8], [-3, 9], [42, -2], [4, 26], [14, -4], [-4, -30], [-18, 6], [25, -3], [10, 0], [-15, -8], [-6, 0], [-8, -12], [40, 4], [3, 26], [-7, -2], [-10, 10], [-10, -8], [16, -12], [-13, -5], [-6, 32], [26, 4], [-12, 14], [26, -12], [-20, 18], [-42, 2], [-22, 14], [4, -10], [-8, 8], [-30, -4], [15, -14], [30, -4], [-21, 3], [20, -6], [-13, 15], [22, 0], [-3, -18], [37, 11], [-26, 6], [27, -6], [2, -20], [10, 16], [13, -17], [-18, 20], [-25, 5], [-34, -14], [34, 0], [42, 8], [19, -4], [-3, -5], [17, -8], [-3, -23], [-26, 12], [-11, 18], [-17, 15], [-18, -26], [-12, -8], [-17, 6], [12, -8], [14, 0], [-3, -8], [2, 30], [26, 12], [48, -2], [22, 12], [-36, -12], [32, -18], [-25, -9], [42, -12], [3, 19], [-37, -5], [-6, 16], [17, 14], [16, -4], [13, 32], [40, -14], [-46, 0], [20, -14], [-30, -12], [-51, 0], [45, -3], [39, -7], [-12, 20], [-30, -8], [-10, -12], [-12, -20], [18, 28], [15, -16], [-16, 12], [6, 30], [-16, 22], [-10, -6], [-42, 14], [18, 16], [29, -16], [-21, 35], [18, -34], [-37, 14], [-3, -21], [6, -22], [-22, 0], [-3, 23], [25, -13], [2, -24], [11, -30], [20, 12], [-16, 24], [28, 20], [-10, 28], [-24, -6], [-34, 12], [-26, -8], [27, -5], [40, -12], [2, 44], [44, 8], [-2, 16], [-11, -15], [2, 40], [8, -20], [-48, 8], [2, 24], [-40, 8], [-26, -10], [-2, -12], [-48, -2], [50, 6], [-22, 4], [41, -9], [-33, 13], [6, 18], [-2, -18], [-8, -40], [6, -16], [-42, -2], [-28, -2], [-28, -26], [10, -6], [-7, -3], [20, 18], [-41, -6], [-21, 37], [16, -8], [2, -18], [-60, 0], [-66, -6], [-17, 31], [42, 20], [49, 12], [-14, -16], [-23, 23], [-22, 20], [-36, 2], [24, -34], [35, -23], [20, 0], [16, 18], [38, -20], [-29, -36], [39, -14], [-34, 6], [61, 12], [22, 4], [44, 4], [27, -27], [-46, -8], [-49, -20], [12, -16], [4, -30], [42, 22], [14, -2], [-20, -8], [22, -32], [66, -8], [-62, -8], [36, -2], [10, -18], [-34, -36], [-1, 12], [5, 44], [8, 26], [3, 4], [29, 25], [2, -48], [-25, -2], [25, -39], [-35, 30], [6, 0], [-50, 20], [-20, 18], [14, -32], [-30, -8], [-15, 31], [38, 28], [-17, 22], [-21, -45], [21, 14], [-30, 16], [19, 0], [40, -22], [34, -34], [30, 0], [36, 18], [-18, -40], [11, -36], [6, 4], [-6, -10], [-9, 6], [44, 30], [-25, -5], [31, -14], [-22, 48], [17, 27], [29, -36], [-34, -6], [22, -18], [-4, -8], [-19, -11], [3, -16], [32, 40], [-9, -14], [-20, 8], [10, 56], [-27, -21], [-4, 32], [54, 0], [14, 44], [-26, -16], [-12, -36], [24, -38], [6, -4], [-32, -6], [-76, 0], [2, -4], [-11, 7], [-40, 10], [-26, -32], [61, 17], [-10, -20], [20, -2], [18, 28], [-70, 0], [-40, 34], [-24, -26], [28, -30], [-27, 3], [26, -32], [-8, 10], [-2, -54], [63, -12], [23, 8], [-3, -35], [6, -42], [-5, -3], [18, 38], [44, 28], [-14, 54], [-6, 0], [-9, 19], [-2, -10], [-54, 8], [30, 24], [0, -34], [-35, -28], [-6, 36], [7, -63], [-8, -10], [47, -18], [3, -54], [24, -44], [65, 2], [17, 57], [4, 2], [-70, -12], [66, -12], [-26, -32], [-19, 14], [-27, -7], [30, 8], [-18, -36], [-43, -10], [-23, 1], [-51, 3], [-19, 35], [27, 10], [-20, -56], [56, -28], [-30, -34], [-38, 16], [50, -28], [-38, 4], [14, 0], [51, -24], [-57, 22], [-16, 30], [-67, 0], [-12, -34], [23, -23], [8, 24], [18, 32], [-3, -14], [26, -44], [48, 2], [-10, -46], [-10, 44], [23, 29], [34, 26], [-36, 44], [49, 41], [6, 32], [-66, 16], [27, 29], [-9, -35], [-1, 20], [-17, 0], [-12, 10], [-8, -52], [-8, 34], [-5, -59]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_8352_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_8352_2_a_l();".
// 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_8352_2_a_l(:prec:=2)
    chi := MakeCharacter_8352_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_8352_2_a_l();".
// 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_8352_2_a_l( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_8352_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![1, 1]>,<7,R![2, 1]>,<11,R![-1, -2, 1]>],Snew);
    return Vf;
end function;