
// Make newform 8325.2.a.g in Magma, downloaded from the LMFDB on 17 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_8325_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_8325_2_a_g();".
// 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_8325_2_a_g();".
// 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_8325_a();"
function MakeCharacter_8325_a()
    N := 8325;
    order := 1;
    char_gens := [3701, 7327, 5626];
    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_8325_a_Hecke( : Kf := Kf)
    return MakeCharacter_8325_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 := [[-2], [0], [0], [5], [-3], [2], [-4], [-4], [-2], [-2], [0], [1], [-7], [10], [11], [-3], [0], [-4], [-16], [15], [-11], [-12], [-3], [4], [-8], [5], [10], [-12], [-16], [14], [11], [-12], [-6], [-4], [-3], [-8], [-3], [2], [-12], [5], [10], [13], [20], [-14], [-17], [-14], [-13], [29], [-8], [15], [22], [-18], [-14], [-22], [12], [7], [-18], [9], [-32], [-8], [28], [-2], [-19], [-12], [14], [-2], [10], [13], [-22], [-10], [-32], [-9], [-16], [15], [7], [24], [-12], [-15], [18], [-4], [9], [-28], [-18], [-13], [4], [21], [-20], [18], [-18], [-34], [-34], [-18], [12], [4], [-16], [-36], [15], [33], [2], [-8], [0], [42], [-6], [-12], [-25], [20], [0], [-17], [39], [10], [-4], [37], [5], [39], [20], [-15], [22], [32], [20], [-17], [36], [-23], [-31], [-14], [4], [-36], [-4], [-39], [-16], [-11], [-9], [9], [-23], [30], [43], [-2], [51], [-47], [-28], [26], [7], [39], [16], [18], [-4], [-12], [-54], [8], [16], [-24], [38], [-26], [32], [37], [16], [-38], [-2], [14], [-9], [-22], [-40], [9], [-10], [24], [-20], [-19], [-22], [-42], [9], [-24], [-34], [-38], [60], [17], [21], [24], [44], [-10], [-3], [-14], [36], [-14], [-20], [4], [-64], [-21], [3], [-26], [-50], [25], [-10], [12], [-2], [-17], [11], [25], [32], [-52], [-53], [-66], [-60], [-43], [58], [-45], [-8], [32], [-48], [-4], [20], [59], [-38], [18], [40], [-28], [-28], [-29], [-14], [22], [-22], [22], [23], [63], [9], [-6], [45], [0], [-70], [-35], [-51], [-14], [21], [11], [-17], [51], [43], [9], [34], [6], [22], [-14], [-60], [64], [21], [34], [-18], [42], [42], [-64], [71], [-4], [-4], [-50], [56], [56], [2], [1], [33], [-36], [-63], [-62], [4], [12], [-2], [-34], [-12], [-79], [51], [-56], [-7], [-56], [-20], [72], [74], [-30], [14], [-44], [-60], [4], [43], [-2], [75], [-50], [4], [-15], [10], [-47], [38], [6], [-22], [46], [-12], [-22], [-15], [15], [-45], [53], [-3], [-6], [86], [-3], [66], [65], [-17], [36], [32], [-78], [10], [58], [45], [-6], [29], [-33], [23], [61], [-20], [-40], [63], [-32], [-33], [-70], [-48], [45], [-50], [52], [9], [44], [-12], [8], [6], [42], [-35], [40], [-26], [-4], [36], [-12], [-63], [27], [-8], [72], [19], [-1], [-54], [-36], [-18], [-90], [-67], [-17], [28], [-53], [24], [1], [60], [38], [-46], [6], [-84], [-24], [83], [14], [26], [63], [2], [54], [-31], [38], [-30], [50], [-74], [-6], [-6], [-40], [-2], [-14], [-65], [60], [-7], [-14], [50], [91], [100], [32], [-56], [-18], [80], [-103], [-49], [22], [18], [26], [91], [-6], [10], [18], [43], [-66], [-32], [7], [-57], [10], [81], [66], [48], [-6], [58], [91], [-2], [-6], [-28], [-83], [25], [-73], [2], [4], [64], [-54], [-16], [-17], [42], [24], [-24], [-22], [-8], [35], [38], [63], [-36], [-41], [92], [-50]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_8325_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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