
// Make newform 5400.2.a.bp in Magma, downloaded from the LMFDB on 17 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_5400_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_5400_2_a_bp();".
// 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_5400_2_a_bp();".
// 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_5400_a();"
function MakeCharacter_5400_a()
    N := 5400;
    order := 1;
    char_gens := [1351, 2701, 1001, 2377];
    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_5400_a_Hecke( : Kf := Kf)
    return MakeCharacter_5400_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], [3], [4], [-1], [4], [-1], [-4], [0], [-4], [9], [0], [8], [12], [8], [4], [-5], [-11], [8], [-1], [-5], [-8], [12], [-5], [0], [-1], [-12], [-14], [-12], [-4], [-16], [12], [9], [8], [-1], [2], [15], [12], [0], [24], [21], [12], [-23], [12], [25], [13], [-4], [24], [10], [-16], [8], [-15], [-16], [-8], [8], [-4], [-25], [-10], [32], [16], [-12], [0], [12], [-3], [24], [17], [3], [24], [-33], [-8], [12], [23], [1], [11], [0], [4], [-14], [24], [-39], [-12], [17], [-28], [14], [36], [-8], [4], [-38], [28], [19], [12], [-40], [11], [12], [0], [-36], [-12], [-28], [29], [9], [7], [-28], [32], [28], [-33], [13], [-28], [-40], [0], [10], [-5], [-35], [-36], [-17], [7], [40], [24], [-32], [-24], [-24], [-13], [-19], [44], [-16], [-40], [-36], [-7], [-8], [-12], [-2], [32], [-4], [3], [31], [-4], [47], [24], [-7], [-16], [-40], [40], [-12], [25], [-20], [-35], [24], [1], [-24], [-27], [44], [33], [-28], [7], [-56], [5], [16], [-20], [-40], [-51], [12], [36], [36], [-59], [12], [24], [-12], [25], [26], [29], [20], [-24], [30], [20], [-37], [-31], [-40], [-16], [60], [29], [-34], [-35], [56], [6], [12], [-48], [-24], [-37], [-45], [13], [-12], [-25], [24], [-11], [28], [-60], [-20], [19], [59], [4], [24], [-4], [23], [43], [-35], [-48], [-24], [-1], [12], [-28], [-5], [-39], [-60], [53], [-20], [-16], [-49], [4], [-20], [-24], [24], [29], [36], [-48], [-20], [-12], [11], [-12], [-12], [63], [4], [-9], [-8], [68], [-44], [-45], [4], [5], [-28], [8], [40], [-24], [23], [17], [-65], [36], [-52], [5], [0], [-32], [16], [30], [-12], [-68], [-35], [-36], [-36], [29], [32], [0], [-10], [-13], [-12], [49], [21], [-40], [-16], [44], [-40], [-56], [4], [-5], [-29], [74], [-53], [2], [-17], [12], [-34], [-38], [-80], [44], [-44], [32], [-25], [-77], [-68], [31], [-72], [-43], [-28], [4], [48], [-40], [0], [-30], [-32], [5], [-36], [48], [1], [13], [64], [-52], [32], [45], [-14], [-12], [41], [32], [49], [12], [-48], [-16], [47], [68], [-10], [-12], [84], [-62], [36], [-53], [-43], [-40], [-76], [-40], [21], [24], [-72], [20], [-60], [1], [48], [-33], [48], [48], [24], [55], [-36], [-58], [-36], [41], [12], [-24], [75], [-16], [-20], [42], [80], [-24], [28], [15], [55], [64], [60], [-25], [-20], [-8], [80], [80], [-24], [13], [48], [24], [-76], [-37], [-15], [36], [-61], [55], [-52], [-75], [-32], [16], [-83], [31], [36], [96], [-7], [-24], [-53], [-60], [64], [33], [72], [31], [-72], [60], [67], [95], [84], [-2], [-64], [36], [-63], [-60], [-1], [15], [84], [-40], [16], [-34], [48], [44], [-32], [40], [-68], [-61], [-72], [103], [60], [46], [-40], [76], [1], [-81], [-20], [84], [-23], [0], [-104], [20], [-38], [-68], [-16], [-106], [64], [-52], [-72], [-24], [16]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_5400_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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