
// Make newform 5456.2.a.r in Magma, downloaded from the LMFDB on 04 June 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_5456_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_5456_2_a_r();".
// 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_5456_2_a_r();".
// 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 := [-1, -1, 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_5456_a();"
function MakeCharacter_5456_a()
    N := 5456;
    order := 1;
    char_gens := [2047, 1365, 497, 1057];
    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_5456_a_Hecke(Kf)
    return MakeCharacter_5456_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], [1, 0], [-1, -1], [-2, 3], [-1, 0], [-3, 4], [-3, 2], [6, -2], [2, -2], [0, 0], [-1, 0], [-1, -2], [7, -5], [8, 1], [2, 5], [-1, 5], [-1, 2], [-8, 5], [7, 0], [8, -5], [7, -6], [5, 0], [-11, -1], [-6, 7], [4, 8], [12, -10], [-9, 0], [-4, 7], [-7, -6], [8, -8], [9, 6], [13, -5], [6, -6], [-1, 12], [1, -2], [8, -15], [-4, 9], [11, 0], [-10, -1], [14, 5], [19, 2], [-3, 5], [-2, 10], [9, 10], [6, -6], [-13, 16], [18, 0], [13, 6], [17, -20], [-24, 3], [-18, 4], [-18, 1], [7, 5], [-12, 5], [11, -26], [-21, -1], [-2, 19], [13, -15], [-10, 6], [12, 0], [-8, 23], [5, 8], [-9, 27], [13, -25], [0, 18], [-6, 18], [18, 10], [27, -3], [-5, -16], [13, -21], [-18, 19], [9, -18], [-9, -3], [14, -5], [-5, 15], [9, 4], [-31, 2], [13, 0], [-23, 10], [19, -18], [12, -4], [-3, 0], [23, -5], [-14, -9], [0, 10], [-6, 24], [-13, 11], [-18, 17], [-8, 10], [-2, -4], [6, -3], [-7, -1], [6, -13], [18, 0], [19, -33], [-8, -2], [-10, -10], [2, -25], [-9, 15], [27, -20], [-5, -1], [-6, -12], [30, -18], [21, -12], [3, -15], [-16, 13], [22, 5], [15, -17], [7, -14], [-18, 0], [-22, 18], [-27, 2], [-16, 28], [13, -1], [18, -15], [17, 5], [23, -9], [-24, 17], [4, -25], [-6, -18], [2, -30], [9, 20], [-10, -19], [-19, 20], [28, -10], [-28, 5], [15, -30], [-13, 16], [-15, -6], [-13, 24], [21, -12], [-3, 3], [-22, 30], [27, 12], [-23, -5], [45, 0], [35, 8], [6, -18], [27, -38], [-11, 22], [-7, -20], [27, -30], [21, -25], [20, 14], [19, -18], [21, -12], [0, 8], [21, -36], [29, -8], [-8, 13], [19, 8], [-23, 5], [6, 0], [7, -5], [-7, -12], [-17, -10], [30, -45], [-44, 13], [-36, 3], [27, 5], [25, -46], [10, -37], [-13, 0], [18, 0], [-13, 32], [10, 7], [33, 10], [-16, -2], [-2, 9], [-23, 19], [-7, 19], [7, -15], [-27, 0], [47, 4], [6, -22], [-12, -6], [-12, 5], [-18, -15], [15, 27], [-3, 26], [-30, -6], [13, -10], [-20, 8], [1, 34], [-19, 35], [-32, 34], [-5, 6], [-5, -13], [-39, 3], [-22, -5], [20, -47], [-39, 5], [-27, 15], [7, 10], [35, 19], [40, -17], [27, -50], [18, 7], [-9, 24], [1, -10], [36, -42], [3, -15], [51, -11], [12, -24], [-43, 16], [-12, 35], [-33, 6], [-34, 5], [12, -19], [8, -35], [-42, 10], [27, 10], [27, -17], [24, 21], [-26, 22], [-3, -15], [36, -28], [-23, 40], [12, -10], [24, 10], [-23, -15], [17, 6], [-29, -2], [-3, -32], [-47, 23], [18, 4], [8, 17], [-27, 34], [-19, -18], [-7, -10], [25, -37], [5, -30], [-57, -5], [-3, 0], [-15, -18], [-51, 26], [63, -6], [-33, 24], [34, -28], [13, 10], [11, 35], [3, -20], [-3, 3], [-16, -18], [12, 4], [-48, 11], [48, -22], [-27, -20], [-8, 21], [33, -24], [-3, 12], [-8, -10], [-18, 35], [-10, 25], [26, 11], [37, -29], [-18, 0], [61, -18], [-69, 4], [-4, 4], [24, 9], [57, -30], [17, -9], [17, -36], [9, -47], [9, -8], [-33, 51], [-23, -20], [57, -12], [0, -22], [-53, 0], [-39, 12], [-10, -27], [39, -8], [-66, 8], [-51, 39], [12, -10], [9, -38], [-28, 10], [18, 0], [48, 16], [-12, -25], [-4, 2], [27, 20], [-10, -21], [13, 40], [19, -10], [21, 19], [64, -18], [34, 22], [-23, -10], [-65, -1], [8, 17], [33, -60], [63, -18], [48, -36], [-27, 5], [-8, 34], [-30, 65], [-15, 34], [-6, 35], [-79, -1], [20, -65], [-17, 31], [58, -25], [-62, 30], [9, -44], [37, 6], [-42, 39], [62, 9], [-17, -14], [1, 43], [37, 10], [14, 39], [39, -9], [-28, 1], [10, 10], [33, -15], [-36, 10], [23, 19], [13, 5], [26, 39], [-13, 35], [69, -21], [21, -14], [32, 15], [-1, -3], [-15, -18], [-34, 67], [58, -23], [-3, -20], [-1, -37], [-5, -15], [0, 47], [-17, 45], [49, 1], [-3, -19], [9, -40], [12, 45], [-16, 36], [33, 2], [32, -8], [-57, -6], [33, -15], [18, -33], [-39, 48], [2, -20], [-1, 46], [-7, 25], [-48, 12], [33, -30], [22, -48], [37, -40], [18, 26], [56, 3], [63, -43], [-22, 4], [-27, 5], [17, -68], [-17, 46], [-51, -22], [27, 30], [36, -63], [-43, 26], [62, -15], [51, -34], [67, -23], [13, -69], [-3, 45], [3, 55], [43, -6], [0, 2], [26, 8], [18, -40], [-39, -16], [44, -13], [53, -20], [-2, -33], [-21, 47], [19, -27], [2, -20], [-11, 40], [22, -15], [-63, 22], [-41, 57], [-16, -16], [48, -30], [52, -43], [12, -7], [-36, -24], [-3, 16], [41, -79], [-25, -25], [-42, 3], [8, 40], [8, 22], [50, -50], [0, 15], [48, -25], [57, 0], [67, -39], [-58, 14], [-52, -17], [51, -36], [16, 13], [8, 15], [60, 6], [37, 10], [-22, -9], [-19, -37], [6, -4], [-86, 28], [93, 6], [-22, -5], [37, 27], [-18, 60], [29, -38], [52, 15], [-9, -36], [45, 12], [81, -12], [-48, 12], [-9, -48], [66, -12], [-38, -16], [10, 1], [27, -72], [24, 2], [33, -40], [-9, 53]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_5456_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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