
// Make newform 5616.2.a.bb in Magma, downloaded from the LMFDB on 15 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_5616_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_5616_2_a_bb();".
// 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_5616_2_a_bb();".
// 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_5616_a();"
function MakeCharacter_5616_a()
    N := 5616;
    order := 1;
    char_gens := [703, 4213, 2081, 3889];
    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_5616_a_Hecke( : Kf := Kf)
    return MakeCharacter_5616_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], [2], [3], [1], [-1], [4], [4], [1], [-3], [1], [9], [-6], [-1], [12], [-1], [-5], [-8], [16], [-4], [4], [-4], [17], [-15], [8], [-15], [2], [0], [10], [6], [-4], [-10], [-3], [0], [-2], [-8], [16], [0], [12], [-6], [12], [12], [-15], [-10], [-12], [14], [5], [-4], [12], [13], [8], [-10], [-6], [-4], [-14], [-5], [-23], [16], [-14], [7], [-17], [-12], [12], [-27], [27], [6], [16], [-15], [-24], [18], [-29], [36], [14], [8], [34], [6], [-10], [29], [15], [12], [-30], [26], [-28], [19], [0], [2], [38], [8], [26], [31], [6], [2], [17], [0], [-30], [-3], [18], [28], [-4], [33], [13], [44], [28], [-40], [-36], [-22], [-11], [-43], [-36], [13], [-32], [23], [6], [-46], [-7], [32], [-24], [-19], [18], [18], [-25], [-50], [-34], [31], [-8], [18], [26], [-29], [-30], [-31], [-38], [34], [-30], [20], [-35], [-40], [30], [2], [-31], [-32], [2], [-30], [16], [47], [-2], [42], [-49], [18], [-15], [-2], [27], [-20], [1], [23], [-28], [7], [20], [-35], [3], [30], [-21], [-48], [1], [-36], [-45], [-6], [2], [10], [-10], [23], [-39], [-21], [32], [-26], [10], [16], [-50], [-30], [-64], [56], [-8], [-34], [36], [-27], [-36], [21], [16], [54], [-8], [-18], [-5], [-33], [11], [62], [48], [-44], [-44], [46], [10], [15], [-62], [-56], [-58], [-53], [48], [-30], [-5], [-30], [-23], [-67], [-18], [-39], [-40], [68], [56], [-46], [10], [20], [-48], [-66], [62], [27], [-45], [7], [54], [-40], [-36], [12], [-36], [31], [12], [29], [-29], [8], [39], [-52], [32], [-10], [-4], [1], [69], [25], [32], [-29], [9], [59], [59], [36], [-76], [56], [-45], [15], [26], [-35], [-3], [24], [-10], [26], [42], [-74], [-40], [66], [1], [-54], [-58], [-20], [-80], [7], [-2], [-5], [-14], [-56], [-32], [56], [7], [-83], [27], [35], [40], [-62], [-20], [-1], [28], [-13], [-26], [-47], [-1], [24], [79], [-44], [53], [-54], [29], [24], [30], [-67], [-38], [-21], [-78], [4], [-10], [-50], [16], [-2], [-39], [20], [-48], [14], [-28], [26], [-63], [24], [52], [80], [64], [71], [-12], [48], [62], [-36], [65], [-26], [67], [-16], [11], [78], [24], [54], [52], [27], [7], [39], [60], [-87], [12], [57], [73], [-69], [-70], [54], [37], [18], [-48], [-60], [74], [10], [78], [32], [-30], [-86], [42], [-40], [-76], [90], [-64], [82], [-20], [-43], [8], [-48], [-10], [-90], [-72], [44], [-13], [45], [-66], [-16], [-14], [20], [-63], [92], [-1], [32], [-34], [-45], [-27], [70], [6], [14], [30], [70], [-12], [-39], [8], [84], [-3], [-58], [-46], [72], [34], [-22], [-51], [84], [-84], [67], [51], [60], [-17], [-10], [-10], [102], [32], [-50], [-16], [2], [-35], [78], [4], [-36], [-43], [14], [-4], [20], [-57], [71], [66], [-38], [3], [-100], [-98], [26], [62], [50], [-92], [76], [10], [-15], [72], [-77]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_5616_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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