
// Make newform 5408.2.a.d in Magma, downloaded from the LMFDB on 12 March 2026.
// To make the character of type GrpDrchElt, type "MakeCharacter_5408_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_5408_2_a_d();".
// 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_5408_2_a_d();".
// 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_5408_a();"
function MakeCharacter_5408_a()
    N := 5408;
    order := 1;
    char_gens := [2367, 677, 1185];
    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_5408_a_Hecke( : Kf := Kf)
    return MakeCharacter_5408_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], [-2], [1], [0], [-4], [0], [3], [2], [-2], [5], [-2], [5], [3], [4], [-6], [13], [-12], [-7], [14], [-6], [7], [-8], [-4], [14], [-2], [-11], [-14], [-6], [-10], [-9], [22], [18], [-1], [16], [21], [-22], [5], [-16], [4], [-2], [-16], [5], [-6], [-21], [-18], [14], [-18], [-18], [-18], [-18], [6], [12], [7], [22], [11], [-24], [14], [-12], [1], [-21], [20], [-19], [-26], [-10], [-34], [-3], [8], [-1], [-10], [-10], [3], [-20], [22], [-3], [-2], [-4], [33], [-34], [-33], [-9], [-14], [9], [12], [-1], [-8], [4], [-10], [-25], [21], [20], [-24], [-6], [-32], [16], [14], [28], [-3], [-25], [-16], [-23], [-22], [-23], [-24], [6], [20], [-29], [-16], [-1], [30], [-9], [34], [1], [-37], [36], [-20], [-17], [4], [-38], [14], [-28], [13], [-5], [26], [38], [-20], [-10], [21], [48], [28], [1], [-20], [48], [20], [38], [38], [38], [-6], [-22], [30], [-25], [2], [30], [-52], [0], [-31], [26], [-39], [-21], [-50], [-24], [41], [-29], [58], [56], [16], [32], [30], [3], [55], [-46], [38], [42], [38], [-18], [-17], [-18], [2], [-55], [18], [53], [-34], [-3], [2], [19], [46], [-9], [-2], [17], [0], [-34], [34], [4], [1], [-6], [16], [29], [-42], [26], [19], [60], [39], [10], [-24], [-18], [8], [-2], [-33], [-51], [11], [-38], [-15], [30], [-63], [-37], [2], [57], [20], [16], [-21], [-28], [3], [14], [46], [10], [-66], [-49], [-62], [15], [-48], [2], [-39], [-70], [55], [8], [-16], [29], [-9], [16], [-18], [44], [-11], [44], [22], [15], [-6], [-30], [-30], [-51], [-54], [-12], [26], [70], [-28], [69], [51], [-12], [30], [48], [-4], [-6], [-62], [-66], [64], [59], [-42], [-8], [62], [0], [-10], [-65], [-32], [12], [-23], [-27], [-33], [2], [46], [39], [-66], [-11], [13], [-64], [51], [-2], [-34], [-14], [-44], [9], [-53], [58], [16], [-54], [72], [-71], [-32], [-22], [15], [41], [-44], [-81], [18], [72], [-33], [-26], [-46], [-3], [-62], [13], [-16], [-38], [3], [45], [60], [36], [30], [11], [72], [-47], [84], [-23], [-40], [74], [43], [-16], [42], [67], [26], [86], [-2], [-17], [-66], [30], [29], [-56], [-82], [43], [14], [-80], [-52], [-39], [1], [57], [-66], [-46], [40], [-58], [85], [34], [39], [28], [94], [-21], [25], [92], [54], [-32], [-43], [-36], [-30], [6], [8], [-2], [53], [-58], [61], [71], [-36], [32], [-57], [-18], [-71], [3], [-30], [88], [16], [-26], [-10], [-52], [19], [-78], [-70], [-30], [73], [22], [-55], [-54], [60], [14], [47], [51], [62], [55], [-44], [-42], [-84], [-54], [0], [-74], [66], [22], [51], [73], [-72], [-20], [-84], [62], [56], [-58], [0], [9], [-34], [94], [-20], [-33], [-39], [-34], [-66], [63], [-4], [-52], [-65], [5], [-60], [70], [-17], [-27], [-58], [-42], [54], [24], [-63], [-103], [8], [58], [38], [-7], [-32], [103], [58], [50]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_5408_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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