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