
// Make newform 1250.2.a.l in Magma, downloaded from the LMFDB on 20 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1250_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_1250_2_a_l();".
// 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_1250_2_a_l();".
// 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 := [16, 4, -9, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 1, 0, 0], [0, -5, -1, 1], [-5, -1, 1, 0]];
    Rf_basisdens := [1, 1, 4, 1];
    Rf_basisnums := ChangeUniverse([[z : z in elt] : elt in Rf_num], Kf);
    Rfbasis := [Rf_basisnums[i]/Rf_basisdens[i] : i in [1..Degree(Kf)]];
    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_1250_a();"
function MakeCharacter_1250_a()
    N := 1250;
    order := 1;
    char_gens := [627];
    v := [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_1250_a_Hecke(Kf)
    return MakeCharacter_1250_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, 0, 0, 0], [0, 1, 0, 0], [0, 0, 0, 0], [1, 0, 0, 1], [-1, 0, 0, -1], [2, -1, -1, -1], [3, 0, 1, -1], [-3, 1, -4, 1], [-1, -2, 0, -1], [4, 1, 1, 0], [-1, -2, 4, -1], [4, -2, 1, 0], [2, 1, -1, -1], [-1, 0, -4, -1], [1, 0, 0, 1], [3, -3, -1, 0], [2, -4, 4, -2], [5, -2, 3, 2], [7, 0, 0, 3], [-3, 0, 4, 1], [5, 3, -1, 2], [0, -2, 4, 0], [-9, 2, -4, -1], [-1, -1, -3, 3], [8, 0, 5, 0], [4, -6, 1, 0], [2, -1, 0, -2], [-1, 5, 4, 3], [2, 3, -5, 3], [0, 1, 5, 0], [2, 0, 0, -2], [-7, 2, -8, 1], [-8, -2, -5, -3], [-4, -3, 8, 0], [-4, 1, 3, -3], [-12, -2, 0, -4], [9, 0, 1, 1], [5, 1, 8, -3], [-1, 3, -8, -1], [-9, -3, 1, -1], [-3, 4, -4, 5], [7, 3, 5, -1], [-11, -2, -4, -3], [-1, 7, 7, 4], [-1, 1, -5, 0], [4, 5, 0, 8], [4, 5, 4, 0], [11, -4, 8, -1], [3, 2, 8, 3], [-7, 0, -5, 6], [-5, 3, -9, 0], [9, 1, 0, 1], [-1, 0, 9, -5], [-5, 4, 0, 3], [-6, 0, 3, -1], [-17, 1, -8, -1], [19, -4, 7, 4], [-15, 5, -16, -3], [-5, 1, -11, 3], [2, -5, -5, -5], [2, -2, 12, -2], [-3, -4, 17, -3], [-10, 6, -20, 2], [-6, -3, -12, 2], [10, 3, -4, 0], [12, -1, 4, 6], [11, 5, 4, -1], [-8, 4, -8, -2], [-21, 1, -4, -1], [-2, -1, -11, -6], [2, 2, -8, 0], [-8, 3, 4, 4], [3, 2, -12, 3], [15, 0, 12, 5], [-3, -2, 4, -11], [20, -5, 8, 4], [0, -6, 3, -11], [19, -8, 12, 1], [13, 7, -9, 2], [4, -11, -11, -4], [-6, -6, 16, -6], [-10, -4, -3, 2], [-16, 2, -4, 4], [14, 5, 11, -1], [-9, -2, 12, -1], [4, -4, 0, 8], [10, 3, 9, 10], [15, 3, -8, 1], [-13, 9, -11, 3], [3, 3, 0, 7], [7, 0, 20, 3], [3, -5, 16, -5], [13, -6, 20, -3], [-8, 6, -12, 0], [3, -1, 12, -9], [5, -1, -8, -3], [17, -4, 21, 1], [12, 8, 3, 1], [2, -2, 0, -10], [12, 11, -15, 8], [8, 3, 4, 0], [18, -7, 21, -2], [-1, -7, 4, -5], [-22, 9, -11, -6], [-20, 3, 4, -4], [1, 12, 4, 3], [14, 2, -4, 2], [-21, 9, -7, -1], [-20, -4, -16, 4], [7, 5, -9, 4], [3, -15, 16, -1], [-13, -4, 9, -5], [-7, 9, -1, -2], [1, 0, 12, 5], [2, 12, 4, 2], [6, -8, 0, 4], [31, 0, 0, -1], [3, -6, 8, -1], [-14, 11, -11, -2], [-5, 8, 16, 3], [13, 11, 0, -5], [-15, 5, -3, 5], [8, 11, -12, 10], [-5, -10, 0, 7], [-18, -3, -28, -6], [-7, -5, 3, -6], [10, 1, 7, -9], [-16, 5, -12, 0], [-4, -2, -12, -8], [8, -8, -8, 2], [14, -12, 4, -2], [7, -1, 0, 3], [3, 7, -8, 11], [-16, 11, -21, 1], [7, -2, -1, 0], [-8, 12, -8, -2], [8, 6, 19, -3], [24, 4, 0, 4], [-3, -2, -13, 10], [-10, -7, -11, -10], [20, 4, -4, 12], [5, 5, 8, 3], [2, 0, 4, 2], [22, 3, 24, -2], [17, -7, 11, 2], [-33, 0, -20, -1], [16, -2, 19, -11], [-2, -5, 12, -12], [9, -1, 4, 1], [-24, 2, -8, 8], [-6, -10, 7, -5], [-26, 2, -24, 4], [-4, 17, -24, 4], [-23, -2, -24, 1], [2, -11, 4, -14], [-21, 4, 8, 3], [13, -10, -12, -7], [-2, -1, -15, -2], [16, 8, -11, 16], [-10, 2, -15, 2], [-21, 3, 0, 11], [-4, 0, -15, 4], [4, 10, -8, 20], [12, -2, -12, -4], [-14, 11, -29, 3], [17, 2, 4, -7], [25, -1, 20, 13], [-29, -2, -28, -7], [-17, 4, -13, -4], [-8, 10, 7, 9], [2, 3, 4, -6], [19, 4, 11, 0], [11, 6, 24, 7], [11, -9, 13, -1], [14, 11, -4, 10], [-19, 6, -23, -7], [-9, 4, -12, 7], [-12, -3, 1, -8], [11, -6, 16, -5], [2, -7, 5, -2], [-22, 6, -20, -2], [6, 1, 28, -2], [-23, 5, -15, 1], [-6, -1, 17, 2], [8, -12, -8, 0], [-13, 6, -12, 9], [-23, 3, -31, -7], [7, -8, 20, -13], [-3, 10, -27, 1], [-8, -7, 8, -4], [3, 10, 20, 13], [12, -12, 0, 0], [12, 4, -32, 4], [2, -1, -21, 3], [-19, 12, -28, 5], [-51, 4, -5, 2], [-5, -2, 20, 5], [-1, -8, 3, -12], [7, -5, 11, -8], [13, -15, 0, -7], [-38, 6, -1, 3], [-26, 2, -20, -10], [23, 0, 28, -3], [14, 2, 11, 3], [-6, -7, -16, -2], [-14, -2, 17, -2], [-22, -2, -24, -6], [-22, 1, 12, -6], [-23, 0, 3, 6], [16, -14, 8, -12], [-5, -10, 19, 0], [-30, -5, -20, -4], [-45, 10, -12, -1], [7, -5, -16, -1], [-20, 12, -8, 4], [-14, -1, -1, -9], [0, -5, -4, 8], [-26, -5, -5, -1], [-4, -1, -20, -12], [28, 2, 21, 8], [0, -8, 1, -4], [-5, -12, -20, -1], [-4, 16, 8, 2], [-8, 5, -8, 4], [-23, 8, -40, -3], [-8, -10, -15, 4], [6, 14, -17, 23], [-49, -3, -20, 3], [36, 8, -8, 8], [2, -5, 24, 6], [22, 1, 9, 10], [28, 10, 20, -4], [20, -10, 24, -8], [-4, -9, 25, -4], [-38, 6, -40, -6], [18, -17, -4, -2], [-15, 4, -7, -11], [-28, 7, -49, 1], [-23, -2, 0, 13], [-2, 1, 8, 2], [2, -1, 4, -6], [34, -6, 12, 14], [-9, 2, 4, -9], [-16, -17, 23, -11], [-7, -22, 23, -6], [-7, -6, -16, 9], [26, -4, -4, -2], [-22, -13, 28, -10], [14, -13, 12, -18], [6, -15, -12, -14], [1, 9, 17, 1], [-2, 3, -35, 6], [10, 6, 16, -14], [19, -9, 39, -8], [11, 12, 12, -7], [11, -20, -16, -17], [35, 2, 29, 3], [-14, 2, 0, 2], [4, -2, -11, -8], [-35, 6, -19, 1], [-5, -6, -32, -9], [-3, 16, 12, 9], [-30, 6, -25, 3], [-4, -3, 7, -7], [-29, -2, -23, -17], [-18, 7, 8, 2], [21, 5, 19, -2], [42, -16, 5, 2], [-30, -9, -36, 6], [-1, 10, 7, 8], [-13, -7, -9, 8], [2, -4, -8, 14], [-6, 4, -1, 3], [8, -15, 16, 0], [25, -7, 9, -11], [49, -10, -8, -7], [-12, -10, -12, -8], [-2, -5, -7, 18], [22, -6, 5, -18], [22, 12, 32, -6], [-8, 22, -8, 0], [-13, 8, 4, 15], [50, 9, 16, -10], [-49, 3, -13, 0], [-24, 0, 8, -12], [-54, -2, -4, -14], [23, -6, 3, 12], [29, -22, -3, -11], [17, 10, 4, 5], [21, 7, 27, 6], [-3, 17, -19, 5], [56, -1, 8, 0], [5, -3, -3, 1], [-23, 14, 16, 1], [-24, 9, -5, 1], [-9, -13, -33, -4], [7, -22, 8, -9], [40, 3, -15, -4], [41, -10, 40, -3], [-29, -12, 20, -5], [5, 10, -9, 6], [-34, -1, -23, -14], [16, 23, -32, 8], [47, 4, 40, 3], [-9, 0, -32, -5], [15, -10, 43, -4], [16, -22, 20, 0], [-17, 9, 1, 7], [41, 7, 32, 1], [-39, -5, -48, 7], [-24, 3, -20, -12], [26, -8, -16, 4], [22, -22, -9, -17], [-47, -3, -12, 1], [23, 10, 0, 15], [7, 15, -11, -5], [56, 7, -16, 4], [-18, 13, -16, -10], [-17, 17, -39, 3], [0, -6, 19, 13], [-30, -15, -20, 6], [22, -22, 27, -5], [2, 20, -33, 3], [-34, 3, 0, -2], [38, 11, -11, 22], [-29, 17, -11, 15], [52, -1, -4, 0], [-15, -21, -4, -7], [21, -8, 28, -11], [-11, -11, 19, -2], [-22, 19, -29, 3], [-32, 13, -5, 9], [-35, 24, -16, -7], [24, -20, 16, -16], [42, -18, 16, 10], [21, 15, -16, 17], [9, -3, 29, -15], [-9, -12, 23, 0], [-38, 5, -21, 11], [48, -6, 40, 12], [23, 3, 1, -9], [16, 9, -36, 14], [40, 7, 19, 17], [-5, -18, 16, -9], [0, -2, 1, 20], [-13, -5, -24, -17], [43, -11, 9, -5], [5, -16, 32, -11], [-22, 21, 8, 22], [-45, 5, -5, 4], [11, 14, 20, 15], [-4, -4, 19, -15], [2, -21, 29, -2], [20, -9, 40, 0], [27, -24, -4, 1], [15, -19, 31, 4], [-23, 1, 4, 13], [26, -6, 12, 18], [-8, -15, -7, 0], [-53, 21, -32, -9], [-18, -15, 9, -6], [-28, 24, -27, 4], [32, -34, 16, 0], [-24, -11, -24, 8], [-10, -9, -4, 6], [-36, 5, -31, -4], [17, 7, -25, 14], [-55, 2, -32, -15], [35, -7, 25, 15], [55, 1, -20, -1], [47, -4, 24, 3], [37, -7, 48, -3], [12, -18, 32, -2], [-14, -3, 8, -14], [-15, -7, -8, -9], [-52, 13, -32, -8], [-23, -12, -12, 1], [-34, -4, -23, -10], [9, -17, 21, -19], [-20, -1, -19, 20], [-8, 12, -56, 2], [-21, -19, 17, -9], [-36, 0, 16, -4], [38, 7, 15, 11], [3, 23, -16, 11], [-35, 11, -20, 5], [23, 9, 12, 7], [24, 19, 5, 4], [-15, -22, -4, 5], [-2, -3, -16, -18], [-1, -14, -1, -8], [-24, 3, 4, -6], [-14, -2, -52, -2], [-12, 29, 8, 4], [24, 4, 36, 0], [-19, -20, 47, -18], [15, 9, 4, -17], [37, -4, 53, 9], [2, 3, -12, -14], [77, -8, 20, 11], [-37, 26, -7, 11], [-9, -11, 15, -4], [-20, 7, 20, 0], [-4, 15, 15, 1], [-3, 26, -4, 11], [11, -2, 28, -1], [4, 17, -1, 9], [-30, -11, 19, -21], [6, -1, 8, -2], [-8, -18, 24, -24], [-7, 12, 4, -5], [37, -8, 36, 3], [35, 3, 4, 7], [1, -3, -8, -3], [-10, -12, -9, 7], [-17, -5, -24, -19], [-49, 20, -28, -5], [-42, 24, 0, 2], [31, 18, -44, 9], [-15, -4, 12, -7], [43, -1, -21, 4], [-19, 36, -11, 5], [-14, -11, 20, -2], [26, 5, -8, 10], [2, -21, -3, -14], [-21, 24, -20, 9], [-19, 9, -48, 9], [19, 14, -5, 0], [46, -6, 24, -14], [55, -3, 40, 11]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1250_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1250_2_a_l();".
// 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_1250_2_a_l(:prec:=4)
    chi := MakeCharacter_1250_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_1250_2_a_l();".
// 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_1250_2_a_l( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1250_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![16, 4, -9, -1, 1]>],Snew);
    return Vf;
end function;