
// Make newform 5520.2.a.bm in Magma, downloaded from the LMFDB on 18 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_5520_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_5520_2_a_bm();".
// 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_5520_2_a_bm();".
// 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
        poly := [-2, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    inp_vec := Vector(Rfbasis)*ChangeRing(Transpose(Matrix([[elt : elt in row] : row in input])),Kf);
    return Eltseq(inp_vec);
end function;


// To make the character of type GrpDrchElt, type "MakeCharacter_5520_a();"
function MakeCharacter_5520_a()
    N := 5520;
    order := 1;
    char_gens := [4831, 1381, 1841, 4417, 1201];
    v := [1, 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_5520_a_Hecke(Kf)
    return MakeCharacter_5520_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 := [[0, 0], [1, 0], [-1, 0], [1, 2], [4, 1], [2, -1], [1, 5], [2, -3], [1, 0], [-5, -1], [7, 2], [3, 0], [-9, 1], [-6, 0], [10, 1], [3, -3], [-3, -7], [4, -1], [3, -6], [1, 7], [-6, 3], [4, -8], [-7, 5], [-4, -10], [-4, -2], [-3, -11], [2, 2], [3, -1], [10, -3], [-9, 1], [-4, -3], [8, -4], [0, -2], [11, 0], [2, -5], [-2, -8], [7, 6], [2, 0], [-6, -9], [8, -4], [2, -4], [-4, 2], [-6, 3], [0, 6], [14, -2], [-2, 6], [5, 4], [14, 0], [-12, 4], [4, -14], [4, -4], [3, 1], [22, -1], [-2, -16], [6, -17], [9, 9], [-11, 11], [15, 6], [14, -8], [16, -1], [23, -4], [-13, -7], [-6, 15], [-12, 4], [9, -12], [-14, 11], [-1, 0], [14, -12], [-16, -2], [-1, 22], [-2, 23], [18, 5], [-3, -12], [4, 12], [-12, 12], [-13, 1], [6, -6], [-4, 8], [-18, 10], [-7, -6], [0, -17], [-6, -3], [8, -14], [1, 2], [10, -6], [2, 23], [-9, 3], [-31, 0], [-18, -6], [-10, 5], [-5, -1], [6, -9], [8, 13], [5, 5], [13, 0], [27, 9], [-12, 14], [-16, -11], [-12, 0], [20, -10], [4, -12], [3, -7], [-11, -7], [-2, 10], [-16, -9], [-20, 12], [-18, 16], [-18, -11], [-36, -2], [-7, 8], [20, -13], [-10, 16], [-5, -7], [20, -20], [-12, 15], [12, 5], [-33, 0], [0, 15], [-4, -1], [16, 13], [-14, -18], [12, -21], [-15, 3], [-6, -27], [10, -4], [-18, 13], [4, -9], [-15, 15], [23, 0], [-9, 6], [31, -16], [20, -4], [22, 9], [27, 0], [-27, -5], [-4, -17], [-6, -2], [19, 16], [21, 3], [21, 19], [-11, 20], [-24, 14], [-40, 4], [9, -29], [15, -6], [-18, -16], [-6, 18], [-18, -28], [57, 0], [-14, -2], [-10, -6], [18, -1], [-8, -7], [-2, 14], [-17, 10], [0, -4], [16, 0], [15, -19], [-40, 14], [-6, 1], [-16, -14], [30, 16], [-16, -11], [12, 30], [-17, -1], [17, 29], [-7, -4], [-20, 10], [0, 12], [-30, -13], [-24, -12], [5, -20], [18, -20], [-19, 0], [40, 0], [-18, 27], [18, 6], [3, 13], [-11, -30], [10, 27], [-34, 11], [18, 21], [-42, -6], [8, -7], [-7, 13], [-12, 15], [22, -25], [-23, 14], [7, 22], [45, -1], [-26, -9], [38, -4], [-14, 31], [51, -5], [-54, 4], [-7, -5], [30, 3], [-4, -6], [6, -20], [-30, -4], [10, -29], [34, 4], [2, 21], [2, -19], [-14, 23], [18, 30], [-16, -15], [-36, 11], [15, 21], [-54, -12], [38, 6], [-42, 10], [-10, 34], [18, -12], [33, -5], [20, 3], [-14, 6], [27, -27], [13, -31], [-52, 5], [-9, -30], [26, -22], [-37, -11], [1, 10], [0, -17], [-57, -6], [10, -2], [-29, 5], [20, -8], [-27, -31], [-34, -13], [-18, 27], [-34, -10], [-9, 15], [11, 0], [46, -8], [28, 33], [-42, 8], [-31, -25], [-9, 33], [57, 7], [-1, 50], [6, 42], [20, -30], [-20, 28], [-60, -6], [12, -39], [32, 23], [26, -6], [21, -33], [40, -6], [-6, 20], [-53, -7], [30, 6], [-4, -7], [1, 13], [-4, -9], [0, -48], [-28, 5], [-46, 8], [-47, -4], [-23, 7], [-7, -18], [-13, -20], [-12, 18], [-12, 15], [66, 9], [-6, -12], [-29, 4], [-4, -20], [7, -24], [-25, -16], [-25, 32], [-14, 44], [4, 25], [38, 7], [-46, 11], [19, -16], [-32, 33], [22, -7], [-18, -44], [-40, -27], [36, 2], [28, 12], [-30, 21], [-9, -1], [-11, 20], [-54, -12], [10, -26], [-30, -14], [18, 14], [-61, 7], [8, 14], [42, 21], [-12, -15], [0, 48], [-2, -53], [24, 27], [19, 5], [-10, -48], [59, 12], [-67, 5], [16, 14], [6, -15], [-8, -48], [-36, 27], [0, -1], [62, -12], [6, -3], [32, 25], [24, -16], [36, 11], [70, -1], [-12, 0], [31, 7], [16, 3], [5, -41], [15, 17], [-31, -14], [-56, -10], [-4, 41], [-23, 12], [46, -4], [-58, -12], [39, -15], [-36, 21], [4, -31], [46, -29], [28, 16], [-21, -27], [-45, 18], [24, 39], [57, -18], [-24, -9], [44, 12], [44, -4], [-22, 42], [42, 14], [-32, -34], [55, 4], [2, -6], [30, 20], [6, -6], [12, 15], [57, 1], [49, -13], [47, -18], [-10, 31], [34, 4], [-69, -17], [17, 10], [-44, -33], [-3, 15], [-35, 42], [44, -17], [6, 40], [32, 25], [-6, 20], [48, 13], [-6, -10], [63, -6], [-25, -31], [18, 18], [12, -42], [-66, 18], [42, 30], [18, -27], [-41, 32], [-52, -4], [27, -11], [67, -8], [46, 16], [-52, 10], [0, 48], [14, 9], [13, -17], [30, 6], [41, 30], [-36, 26], [2, -30], [2, 46], [-14, -22], [44, -12], [60, -19], [4, 22], [-6, -36], [17, 30], [52, -5], [9, -36], [69, 23], [54, -21], [54, 14], [65, 7], [56, 5], [-12, -15], [17, 34], [-34, -10], [-12, 26], [-24, 0], [-25, 37], [63, -12], [-18, -28], [-25, -50], [39, -17], [-39, 27], [-27, -42], [9, 30], [-26, -46], [38, 36], [-60, -12], [-48, 3], [12, 13], [52, 8], [64, 18], [-33, -30], [34, -32], [-52, 10], [-36, 3], [21, -21], [-36, -26], [12, -49], [40, 10], [48, -15], [0, 36], [-16, -25], [84, 0], [0, -2], [-87, -7], [-46, -34], [15, 43]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_5520_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_5520_2_a_bm();".
// 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_5520_2_a_bm(:prec:=2)
    chi := MakeCharacter_5520_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_5520_2_a_bm();".
// 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_5520_2_a_bm( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_5520_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<7,R![-7, -2, 1]>,<11,R![14, -8, 1]>,<13,R![2, -4, 1]>,<17,R![-49, -2, 1]>,<19,R![-14, -4, 1]>],Snew);
    return Vf;
end function;