
// Make newform 6048.2.a.bd in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_6048_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_6048_2_a_bd();".
// 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_6048_2_a_bd();".
// 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 := [-4, -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_6048_a();"
function MakeCharacter_6048_a()
    N := 6048;
    order := 1;
    char_gens := [4159, 3781, 3809, 2593];
    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_6048_a_Hecke(Kf)
    return MakeCharacter_6048_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, 0], [0, -1], [1, 0], [0, 2], [-5, 1], [1, -2], [2, -2], [1, 3], [-7, -1], [1, -1], [2, -1], [10, -1], [-3, 4], [-2, 1], [-1, 3], [-3, -2], [2, -4], [-11, 3], [-1, 1], [-2, -2], [-6, -1], [0, 1], [9, -3], [-12, 4], [-10, 0], [-9, 1], [-4, 8], [-4, -5], [0, 2], [-16, -1], [11, -3], [2, 2], [-2, 8], [5, -7], [-2, 1], [1, 7], [1, -6], [-8, 3], [-4, -6], [-20, 2], [-17, -1], [4, 2], [-3, 10], [10, 2], [-1, 3], [-3, -9], [0, -4], [-11, -5], [-6, -8], [16, -4], [-12, 2], [6, -2], [20, -3], [-2, 0], [15, -11], [12, -13], [-3, 9], [0, 1], [14, 6], [4, -10], [-22, -1], [-18, 2], [8, 3], [-14, -4], [-26, -2], [-17, -2], [11, -4], [6, -14], [1, 11], [7, -16], [-13, -5], [-23, 9], [-10, 5], [-12, 3], [4, -9], [-22, -4], [-18, 10], [6, -8], [10, -6], [-15, 4], [-2, 0], [-16, 0], [8, -18], [7, -9], [-6, 2], [12, 8], [-17, -5], [-6, 15], [-14, 1], [-8, 4], [-4, 9], [-22, 6], [-12, 4], [8, 7], [20, -5], [-6, 9], [25, 6], [-20, 6], [-24, 5], [-24, -3], [25, -5], [-7, 7], [0, -4], [31, 2], [6, 0], [21, 3], [18, 9], [19, 7], [-4, 8], [-7, 1], [22, -12], [2, 2], [6, 10], [40, -5], [-32, 6], [20, 6], [18, -2], [19, -9], [28, -2], [18, -8], [43, -5], [-36, 2], [-16, 8], [20, -10], [-10, 0], [-8, 7], [16, 11], [13, -1], [-23, 5], [4, 0], [-27, -1], [6, 18], [36, -5], [35, -2], [-4, -14], [-12, 1], [14, 6], [18, -16], [-4, -6], [14, 8], [-21, -7], [2, 1], [-14, -8], [38, 2], [14, -23], [13, 9], [-37, -2], [34, -8], [-17, -5], [-24, -3], [-5, 15], [3, -20], [24, -1], [-24, -1], [16, -6], [-2, -11], [-2, -1], [20, -4], [18, 5], [30, -6], [44, -8], [-32, 16], [-25, -2], [-22, 0], [0, -5], [18, 15], [3, -19], [-13, 10], [-12, 5], [30, 10], [-7, -5], [-29, 3], [15, -4], [0, -12], [-13, 12], [19, -11], [-25, 19], [-8, -14], [-1, 3], [36, 9], [-11, -20], [44, -10], [19, -8], [-29, 11], [-6, 19], [-8, 14], [8, 0], [1, -7], [-22, -5], [-12, -4], [-22, 4], [27, 0], [-20, 1], [14, -8], [19, 8], [-15, -3], [-6, -23], [-3, -15], [12, -15], [-3, -3], [7, -13], [-26, 20], [38, 10], [25, -18], [24, -3], [25, 9], [64, 0], [-16, -16], [38, -16], [7, -18], [6, 16], [22, 15], [-55, 8], [54, 7], [-20, 4], [-18, -1], [-2, 24], [-39, 5], [-9, 17], [-26, 1], [24, 2], [-24, 14], [24, -23], [-8, 13], [18, 11], [13, 8], [16, -16], [47, -13], [14, 14], [32, -6], [-4, 24], [22, 3], [0, -22], [28, 10], [-40, 0], [-6, 12], [-23, 1], [-34, 26], [-18, 21], [10, -16], [14, 12], [15, -5], [32, -10], [-27, -15], [10, -3], [-25, 9], [64, 1], [-15, 10], [-33, 21], [32, 17], [-53, -5], [-47, -7], [-66, 6], [-22, 27], [34, -22], [16, 23], [-36, -12], [40, -10], [-28, -10], [-10, -10], [40, -6], [46, -4], [-50, -12], [-43, 13], [-56, -4], [-6, -2], [54, -16], [-29, 28], [38, 8], [-19, 3], [36, 4], [-20, -24], [-56, 13], [-46, 12], [-1, 21], [14, 16], [-14, 21], [-22, -11], [-33, -18], [62, -1], [-26, 7], [-4, 15], [-17, -23], [-8, -16], [-16, 20], [66, -13], [-11, -13], [-25, -5], [-3, -12], [22, -28], [-55, -12], [48, -6], [41, 0], [50, -11], [46, -1], [40, -12], [-34, 9], [-27, -20], [-46, 0], [10, 12], [23, 21], [14, -38], [50, 0], [51, 12], [13, -11], [-20, 4], [-31, 17], [-24, -6], [-16, -6], [-8, -20], [13, -13], [-18, 4], [31, -32], [21, -19], [68, -14], [13, -14], [-40, 0], [-8, -18], [-56, 16], [-30, 4], [26, 19], [-20, 21], [34, -30], [-20, 6], [-20, -22], [-21, 2], [14, 16], [-19, -3], [-6, -20], [-20, 26], [26, -4], [-12, 8], [-48, -7], [-71, 14], [29, -18], [26, 12], [53, 16], [-46, 0], [0, -2], [38, -15], [18, 24], [8, 7], [50, -2], [53, -11], [-10, 18], [-17, 13], [-11, -24], [16, 17], [-20, 42], [40, 4], [-17, 22], [11, -7], [-55, 17], [-20, 35], [10, 25], [36, -12], [-16, -17], [-38, 10], [32, 18], [52, 7], [-3, -4], [41, -17], [-10, -24], [46, -22], [-26, 19], [28, 23], [-64, 9], [37, 2], [2, -6], [-24, -24], [-21, 9], [-1, 33], [-49, 11], [-26, -16], [17, -9], [-35, 1], [-20, -12], [34, -16], [26, -26], [50, -17], [-20, -4], [-56, -4], [58, -24], [-56, -10], [2, -2], [18, -2], [57, 5], [-69, 12], [-20, 0], [-57, 20], [28, -34], [-6, 14], [-82, 4], [-49, -7], [57, 9], [-7, 35], [25, -22], [-51, 19], [-41, 1], [-17, -3], [-52, 18], [-46, 21], [-61, 10], [-64, 10], [0, -34], [8, -3], [24, -18], [4, 4], [-13, 13], [-22, 22], [23, 9], [76, -2], [-53, -8], [11, -16], [-46, 8], [1, -27], [-16, -16], [-43, -6], [2, 34], [67, -13], [31, -35], [40, -34], [35, -36], [56, -2], [12, 25], [-24, 8], [-20, 30], [-34, -8], [-24, 24]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_6048_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_6048_2_a_bd();".
// 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_6048_2_a_bd(:prec:=2)
    chi := MakeCharacter_6048_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_6048_2_a_bd();".
// 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_6048_2_a_bd( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_6048_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![-4, 1, 1]>,<11,R![-16, -2, 1]>,<13,R![16, 9, 1]>,<17,R![-17, 0, 1]>],Snew);
    return Vf;
end function;