
// Make newform 5610.2.a.bd in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_5610_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_5610_2_a_bd();".
// 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_5610_2_a_bd();".
// 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_5610_a();"
function MakeCharacter_5610_a()
    N := 5610;
    order := 1;
    char_gens := [1871, 3367, 1531, 3301];
    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_5610_a_Hecke(Kf)
    return MakeCharacter_5610_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+1)]];
    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 := [[1], [-1], [1], [3], [-1], [0], [1], [-8], [3], [3], [3], [10], [0], [-1], [4], [8], [-6], [10], [4], [-6], [6], [4], [4], [0], [-1], [6], [-11], [-5], [-4], [14], [10], [12], [-11], [-5], [-20], [20], [-10], [9], [2], [6], [6], [-25], [11], [-14], [12], [-24], [13], [-11], [-13], [4], [21], [14], [17], [0], [27], [-15], [6], [-7], [10], [17], [-26], [-5], [28], [24], [9], [1], [1], [-26], [20], [6], [-11], [18], [-22], [-6], [-16], [0], [-26], [14], [-17], [4], [-15], [-16], [-23], [16], [-34], [-35], [21], [22], [10], [16], [-12], [-9], [18], [8], [16], [12], [-2], [30], [-33], [-36], [-42], [-27], [-24], [38], [20], [2], [-21], [26], [21], [-10], [-24], [10], [-26], [2], [-26], [9], [-41], [30], [-39], [-41], [-32], [44], [-6], [12], [-8], [22], [-6], [34], [5], [-4], [-6], [-24], [-27], [-19], [-17], [10], [8], [-28], [24], [26], [-16], [-15], [22], [-3], [-26], [34], [-17], [-13], [-25], [-52], [-17], [-57], [24], [-20], [-41], [52], [47], [-11], [-2], [-30], [-18], [6], [-34], [-8], [18], [-21], [-7], [45], [-1], [-47], [41], [28], [28], [-59], [-20], [42], [44], [22], [16], [-23], [5], [-20], [-34], [26], [16], [26], [-41], [-20], [-19], [32], [19], [36], [-61], [51], [-57], [-56], [22], [10], [13], [-57], [-6], [2], [41], [52], [-6], [56], [42], [-24], [-12], [-59], [-12], [-51], [-16], [25], [-56], [-44], [-34], [-49], [-24], [-26], [17], [4], [-28], [-26], [24], [-9], [34], [-30], [-38], [-10], [-11], [-43], [-19], [65], [0], [3], [8], [-16], [-9], [24], [48], [58], [9], [-70], [11], [55], [-54], [-53], [62], [-55], [64], [28], [4], [14], [25], [-15], [-54], [30], [-11], [-10], [4], [18], [14], [-39], [-8], [-7], [51], [52], [58], [57], [21], [-10], [54], [-23], [77], [-44], [-12], [31], [50], [-52], [65], [16], [0], [-41], [62], [-32], [-18], [18], [-70], [13], [10], [-12], [76], [-46], [-37], [10], [30], [-84], [66], [25], [-79], [51], [-62], [24], [40], [38], [-59], [46], [71], [22], [-26], [-14], [32], [-44], [-63], [0], [-52], [72], [-66], [-41], [-65], [17], [0], [-57], [34], [7], [40], [49], [-24], [-20], [78], [17], [-42], [0], [-36], [48], [-24], [-49], [-44], [70], [-10], [58], [-71], [-38], [4], [54], [-18], [-8], [39], [-83], [-60], [10], [-45], [36], [78], [-46], [-1], [-60], [-15], [6], [-13], [-42], [-60], [2], [92], [-36], [-30], [66], [-50], [90], [24], [-78], [50], [-93], [4], [52], [-9], [-55], [14], [22], [76], [-21], [-64], [-39], [-3], [-1], [58], [33], [102], [-96], [-16], [39], [38], [22], [8], [-4], [28], [62], [94], [-8], [84], [82], [-36], [-76], [-30], [-26], [-46], [34], [18], [-75], [-46], [6], [-84], [-45], [65], [62], [-24], [28], [-28], [-48], [54], [-82], [16], [-36], [-30], [42], [-28], [-18], [73], [33]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_5610_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_5610_2_a_bd();".
// 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_5610_2_a_bd(:prec:=1)
    chi := MakeCharacter_5610_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_5610_2_a_bd();".
// 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_5610_2_a_bd( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_5610_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<7,R![-3, 1]>,<13,R![0, 1]>,<19,R![8, 1]>,<23,R![-3, 1]>],Snew);
    return Vf;
end function;