
// Make newform 5408.2.a.i in Magma, downloaded from the LMFDB on 16 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_i();".
// 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_i();".
// 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], [1], [-1], [-3], [-2], [0], [-3], [-2], [4], [2], [-4], [-5], [12], [7], [9], [4], [-6], [-4], [10], [15], [2], [-8], [4], [-2], [-10], [4], [4], [-12], [19], [-6], [16], [-21], [4], [19], [6], [-5], [-22], [-20], [8], [16], [11], [20], [18], [-12], [-15], [26], [27], [15], [12], [9], [-27], [-27], [-22], [-8], [-7], [0], [-4], [-15], [-8], [-18], [20], [7], [26], [2], [23], [-18], [16], [-25], [11], [7], [24], [8], [10], [36], [8], [7], [6], [-14], [24], [-12], [1], [3], [-3], [-25], [-2], [-11], [-26], [34], [-21], [-8], [-36], [-15], [8], [31], [4], [10], [-30], [-1], [-4], [17], [17], [-7], [39], [15], [29], [-10], [-20], [34], [42], [21], [-38], [-22], [-8], [0], [-25], [-2], [2], [-26], [32], [20], [14], [13], [-40], [16], [32], [20], [30], [-18], [-14], [29], [-16], [-51], [-4], [20], [-14], [-8], [51], [52], [54], [47], [4], [15], [-46], [-18], [14], [40], [9], [30], [4], [9], [-23], [-35], [-11], [20], [-5], [26], [-48], [-36], [-2], [1], [46], [-33], [43], [-51], [14], [-27], [2], [-10], [30], [14], [-38], [-27], [-28], [32], [22], [39], [-52], [-50], [-12], [-28], [-40], [52], [46], [6], [-4], [-46], [-6], [22], [44], [0], [-51], [-52], [57], [30], [-19], [-14], [-36], [36], [40], [22], [-33], [-48], [57], [17], [40], [-18], [43], [4], [-6], [-7], [-18], [2], [40], [14], [-45], [-20], [64], [21], [12], [49], [60], [19], [44], [-5], [-7], [-10], [-9], [-32], [42], [10], [-26], [20], [-40], [51], [-3], [-3], [-6], [21], [-48], [-54], [-14], [31], [-76], [-39], [-30], [-60], [63], [-36], [-38], [-18], [11], [-78], [23], [23], [24], [14], [56], [18], [-52], [38], [4], [-21], [-19], [-30], [-48], [-37], [59], [60], [-36], [-32], [-32], [10], [42], [16], [14], [56], [-58], [66], [56], [1], [52], [-33], [30], [-10], [-28], [-22], [9], [-35], [29], [18], [-60], [87], [-24], [-34], [-22], [-60], [22], [76], [-31], [-70], [15], [-69], [54], [-36], [-39], [16], [-9], [28], [12], [-56], [32], [85], [7], [20], [27], [-11], [46], [-56], [44], [-50], [84], [48], [-88], [-1], [-32], [-38], [-62], [44], [68], [72], [-22], [48], [36], [-8], [80], [-8], [-70], [-4], [72], [-26], [-1], [51], [-25], [74], [-51], [-29], [50], [-48], [75], [18], [10], [-58], [31], [8], [70], [-46], [-57], [82], [-69], [51], [38], [54], [54], [56], [28], [73], [-83], [64], [1], [33], [41], [-3], [94], [-44], [26], [-30], [-30], [4], [-70], [54], [34], [62], [-4], [90], [60], [33], [57], [88], [66], [88], [18], [53], [30], [43], [-75], [-7], [55], [101], [-60], [-21], [-77], [-86], [-49], [12], [69], [50], [9], [-72], [94], [64], [73], [-94], [21], [-17], [-23], [48], [-53], [-48], [-18], [-18], [96], [94], [16], [25], [-8], [46], [19], [32], [-52], [14]];
    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_i();".
// 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_i(: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_i();".
// 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_i( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_5408_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![-1, 1]>,<5,R![1, 1]>,<7,R![3, 1]>,<37,R![5, 1]>],Snew);
    return Vf;
end function;