
// Make newform 8048.2.a.l in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_8048_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_8048_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_8048_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 := [-1, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [-1, 2]];
    Rf_basisdens := [1, 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_8048_a();"
function MakeCharacter_8048_a()
    N := 8048;
    order := 1;
    char_gens := [1007, 6037, 2017];
    v := [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_8048_a_Hecke(Kf)
    return MakeCharacter_8048_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], [0, -1], [-1, 1], [2, 1], [2, 1], [-1, -2], [2, 0], [1, 3], [0, -1], [-5, 1], [-1, -3], [0, -2], [-3, -1], [-8, -1], [-2, -1], [4, -2], [0, -4], [3, 2], [2, -3], [-3, 1], [-12, 2], [-4, -4], [-10, -3], [-10, -2], [-10, 0], [-3, -3], [-8, 4], [8, 0], [4, 2], [-13, 2], [-9, 3], [10, 5], [-5, -1], [-1, 5], [-15, 1], [14, 2], [8, 2], [5, 3], [1, 3], [11, 0], [1, -3], [-20, 0], [14, 2], [-9, 1], [-7, -6], [2, -2], [-3, 3], [-6, 1], [-5, -3], [5, 6], [9, 6], [12, 6], [4, -4], [-7, 5], [19, -4], [4, -9], [8, 4], [-20, -3], [15, 5], [-15, -6], [14, 2], [5, 0], [4, -6], [17, -5], [-22, -4], [-17, 4], [-2, -4], [-22, -4], [8, 0], [12, 0], [-27, 1], [3, 3], [0, 1], [-5, 14], [0, 3], [4, 4], [-10, 12], [15, 10], [-1, 6], [-5, 3], [15, -3], [-14, 4], [-17, 7], [16, 2], [0, 8], [-12, -5], [-5, 11], [0, -10], [13, -13], [8, -11], [15, -3], [4, 4], [-11, -11], [-19, 9], [18, 8], [1, 0], [-3, 8], [-41, 0], [10, -10], [-9, 7], [-14, -10], [3, -18], [-29, -3], [8, 14], [2, -8], [0, -10], [-12, 12], [12, 2], [-30, 2], [-5, -2], [-8, -1], [19, -5], [-6, -8], [-25, -3], [-10, -1], [3, -6], [-30, 4], [36, 4], [9, 0], [8, -17], [-25, -10], [14, 4], [32, -2], [35, -5], [8, 0], [9, 0], [30, 0], [-8, 8], [8, -13], [-27, -1], [28, 1], [43, -3], [18, 10], [20, 10], [7, 0], [10, 16], [9, 11], [-23, -13], [22, -12], [5, -5], [6, 1], [32, 4], [13, 5], [-8, 0], [-21, -11], [-10, -11], [-11, 12], [25, -4], [21, -3], [-5, -1], [18, -16], [6, -8], [-46, 2], [-4, 20], [-6, 4], [-9, 1], [4, -4], [11, 7], [13, -13], [23, 6], [27, 1], [29, -4], [-30, -14], [28, 13], [22, 8], [37, 1], [-10, 21], [27, -13], [14, 0], [24, 2], [12, 7], [-8, -10], [-24, -12], [-3, 16], [6, 17], [-27, -2], [-16, -8], [-27, -15], [-1, 19], [5, -22], [-18, 17], [-40, -3], [-31, 13], [-43, 0], [-2, -17], [-42, -8], [-14, -12], [44, -5], [-18, -14], [30, 9], [-3, 14], [31, -3], [-6, -4], [-15, 8], [47, 1], [11, 9], [-13, -9], [-43, -4], [23, -7], [28, 10], [33, 0], [58, -5], [-31, 12], [25, -16], [38, 2], [52, -6], [-8, -25], [-44, 12], [-5, -20], [6, 14], [15, 0], [-21, -5], [32, -13], [-18, -14], [6, 8], [15, 11], [-3, -7], [-12, 2], [-6, -19], [21, -18], [-21, 15], [-30, -1], [25, -11], [9, -7], [48, 0], [-61, 0], [9, -2], [-14, 17], [-20, -19], [-16, 7], [14, 4], [3, 11], [12, 11], [-33, -5], [-32, -4], [27, 17], [7, 18], [-45, 9], [20, -8], [6, 29], [-12, 25], [26, 9], [-46, 0], [-1, -3], [-11, 10], [-56, -7], [26, -16], [30, -12], [63, -3], [-67, 1], [18, 4], [10, 20], [30, -17], [11, 10], [26, 8], [44, -10], [-24, 18], [-22, 10], [21, 4], [-13, 7], [-44, 4], [-48, 4], [19, 13], [21, -16], [21, 10], [-28, 1], [21, -10], [40, -2], [4, -18], [-8, -6], [13, 17], [25, -5], [-25, 24], [24, -20], [55, -4], [56, 6], [-3, 5], [3, -15], [43, -12], [45, -3], [-23, 13], [16, 5], [-56, 1], [12, -6], [31, -3], [-28, -12], [-33, -14], [26, 0], [-24, -5], [-27, 2], [15, -4], [-16, 25], [-49, -11], [-27, 3], [-23, 7], [-19, 25], [8, 0], [-20, 2], [-52, 12], [48, -12], [-23, -24], [42, -12], [14, -18], [8, 4], [-60, 4], [-3, -33], [-33, -3], [6, -4], [-20, 15], [40, -6], [-70, -2], [-30, 0], [40, 6], [14, -18], [-18, -17], [-13, 8], [-45, -3], [6, 15], [-61, 9], [-25, -6], [-19, 31], [-38, 20], [-7, 6], [-36, 12], [12, -22], [32, -6], [-21, -17], [28, -2], [-21, -5], [-1, -18], [27, -1], [-18, -20], [6, 0], [46, -19], [-40, -16], [16, 4], [14, -16], [-69, -11], [9, -7], [-24, 12], [1, 36], [-30, -8], [41, -10], [36, -11], [-53, -15], [-4, 36], [-52, -10], [-65, -13], [28, -9], [-22, 4], [-7, -17], [12, -30], [37, 15], [-30, 8], [-1, 5], [-31, -13], [52, 1], [37, -9], [-50, -6], [25, -15], [-23, 25], [-29, -18], [34, 13], [56, -10], [24, 12], [11, -23], [-63, 6], [-71, -7], [15, -12], [16, -15], [-16, -11], [46, -13], [-25, -3], [38, -9], [66, 0], [46, -11], [38, 12], [-1, -6], [22, 0], [-3, 3], [-30, -6], [-11, 10], [8, -13], [-1, -9], [-2, 6], [82, -4], [-32, 13], [3, 6], [-64, 5], [-8, 15], [46, -18], [-19, 11], [10, 25], [-14, 31], [-20, 12], [-57, -2], [-22, -24], [38, -14], [-16, 9], [50, -12], [-33, 12], [-51, -13], [-12, 13], [-12, 38], [39, -5], [-8, -3], [-58, -12], [-37, -2], [-2, -41], [-55, 1], [12, -30], [-61, 4], [-2, -24], [-14, 35], [25, 23], [-24, -26], [50, 18], [28, 20], [17, 21], [-26, 1], [-19, -18], [-18, -24], [5, -15], [25, -7], [59, 14], [-52, -16], [-6, 41], [2, 18], [0, -2], [-32, -8]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_8048_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_8048_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_8048_2_a_l(:prec:=2)
    chi := MakeCharacter_8048_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_8048_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_8048_2_a_l( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_8048_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![-5, 0, 1]>,<5,R![-4, 2, 1]>,<7,R![-1, -4, 1]>,<13,R![-19, 2, 1]>],Snew);
    return Vf;
end function;