
// Make newform 8208.2.a.e in Magma, downloaded from the LMFDB on 11 December 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_8208_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_8208_2_a_e();".
// 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_8208_2_a_e();".
// 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_8208_a();"
function MakeCharacter_8208_a()
    N := 8208;
    order := 1;
    char_gens := [7183, 2053, 1217, 6481];
    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_8208_a_Hecke( : Kf := Kf)
    return MakeCharacter_8208_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], [-3], [2], [-4], [3], [-8], [-1], [8], [6], [0], [10], [7], [-3], [-13], [2], [-7], [14], [6], [-8], [-2], [-1], [-2], [1], [-4], [17], [-15], [13], [-19], [1], [-7], [-6], [-6], [1], [-22], [5], [-12], [1], [-12], [12], [-4], [9], [8], [-22], [7], [10], [-10], [-24], [-11], [-2], [24], [-15], [-8], [-12], [3], [21], [-10], [-8], [22], [-26], [-13], [-4], [-6], [-7], [9], [6], [30], [2], [2], [-2], [-24], [21], [-8], [-25], [-8], [-32], [-10], [0], [15], [-24], [30], [-17], [-14], [0], [-37], [-24], [9], [11], [-30], [-12], [-8], [-21], [37], [-36], [-41], [-1], [-4], [-2], [-28], [14], [22], [7], [36], [-15], [-29], [-41], [26], [-20], [-2], [18], [16], [20], [-12], [-25], [16], [-2], [17], [-9], [-21], [-31], [-17], [20], [-36], [9], [20], [22], [26], [-16], [-2], [28], [-37], [-48], [47], [8], [26], [33], [-12], [-52], [38], [-54], [-10], [-3], [14], [48], [2], [30], [6], [3], [-25], [-38], [-49], [30], [-36], [42], [-10], [-30], [-10], [-48], [-7], [4], [26], [-3], [54], [-15], [54], [6], [-13], [8], [28], [-57], [15], [-50], [39], [37], [-19], [36], [12], [47], [3], [-50], [8], [-28], [-50], [-13], [1], [39], [41], [8], [4], [-11], [36], [-24], [32], [60], [-30], [-6], [1], [34], [38], [48], [60], [32], [63], [-32], [42], [-18], [64], [-36], [18], [-14], [53], [-43], [6], [-35], [68], [-18], [-44], [30], [32], [2], [14], [-19], [-65], [-32], [49], [2], [63], [-50], [48], [12], [-40], [-64], [-11], [-42], [-21], [-7], [-7], [21], [44], [-22], [47], [-13], [62], [-63], [-65], [-41], [-38], [36], [-14], [3], [-38], [-18], [-24], [-56], [-22], [0], [18], [-38], [-6], [-73], [-61], [3], [36], [82], [-32], [-44], [20], [-30], [-36], [-6], [17], [42], [31], [50], [-22], [70], [-22], [-10], [56], [-28], [-48], [28], [-63], [54], [20], [-9], [11], [-52], [-16], [-58], [39], [64], [11], [84], [13], [33], [-1], [-61], [29], [40], [-41], [50], [6], [-19], [-1], [-32], [-7], [-82], [69], [-44], [-47], [-37], [-42], [-10], [9], [-14], [-2], [-48], [1], [-4], [70], [-53], [60], [-15], [-44], [-68], [80], [74], [-42], [-6], [40], [52], [42], [78], [-36], [42], [15], [-50], [42], [-22], [31], [8], [-72], [0], [44], [48], [88], [-32], [0], [-38], [2], [-56], [-54], [45], [-53], [57], [39], [36], [88], [-84], [-14], [54], [54], [52], [25], [66], [33], [37], [-60], [-46], [4], [-49], [-50], [-18], [-18], [17], [-13], [-73], [40], [60], [-36], [-20], [-60], [20], [-74], [-12], [-8], [-78], [-1], [42], [18], [-6], [-78], [-44], [84], [22], [-53], [61], [52], [-42], [-7], [14], [-88], [-43], [94], [16], [-36], [33], [-44], [56], [-46], [70], [63], [13], [-21], [25], [-54], [-17], [-40], [-38], [-24], [-38], [-73], [-43], [94], [-24], [36], [-76], [-79], [36]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_8208_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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