
// Make newform 8048.2.a.j in Magma, downloaded from the LMFDB on 07 June 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_j();".
// 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_j();".
// 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
        Kf := Rationals();
    end if;
    return [Kf!elt[1] : elt in input];
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]];
    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], [1], [2], [-1], [-3], [3], [-2], [0], [3], [6], [-4], [8], [-12], [-7], [-3], [12], [-8], [-5], [9], [-4], [-10], [0], [-3], [-2], [14], [6], [-6], [-10], [2], [-3], [-6], [-7], [-18], [12], [0], [-14], [-14], [2], [0], [5], [-16], [8], [-10], [10], [21], [-16], [-28], [-29], [14], [-7], [3], [2], [2], [10], [-9], [23], [12], [-23], [30], [-17], [28], [-1], [-32], [-6], [-28], [21], [-8], [0], [12], [10], [18], [-30], [13], [15], [1], [-24], [-22], [39], [9], [-22], [10], [6], [-12], [-18], [18], [-11], [12], [-4], [18], [33], [-12], [8], [32], [-4], [-22], [-1], [15], [11], [20], [10], [16], [23], [4], [-46], [-26], [22], [0], [18], [-20], [41], [39], [-42], [-38], [44], [17], [9], [44], [24], [-21], [-3], [-25], [-14], [28], [2], [20], [-13], [-16], [12], [-29], [-52], [-5], [18], [22], [-22], [-29], [-20], [-36], [18], [-38], [-24], [1], [-8], [-26], [36], [-4], [19], [-5], [13], [-40], [36], [-28], [50], [36], [-44], [-46], [-8], [36], [-18], [-22], [-21], [20], [21], [34], [-33], [22], [12], [-13], [6], [34], [-14], [9], [52], [-8], [9], [43], [15], [-20], [-44], [0], [-11], [7], [11], [44], [-27], [-35], [-24], [42], [9], [-58], [35], [-29], [-2], [48], [47], [-32], [38], [-12], [-45], [42], [-8], [35], [33], [-37], [-15], [-20], [30], [-69], [38], [-41], [52], [-41], [62], [27], [20], [60], [-4], [24], [-50], [27], [33], [-8], [-11], [46], [16], [-64], [25], [27], [15], [65], [-51], [8], [44], [-61], [40], [-48], [72], [-47], [24], [12], [-33], [23], [-63], [-32], [-46], [63], [-31], [-78], [-18], [-58], [46], [-26], [2], [-75], [-51], [54], [-24], [-34], [76], [31], [18], [56], [40], [16], [-69], [-73], [-1], [9], [66], [-20], [66], [30], [12], [3], [52], [11], [46], [-42], [-26], [55], [-48], [-10], [-31], [33], [-10], [20], [-20], [-31], [18], [3], [-49], [-23], [27], [30], [-14], [64], [8], [36], [16], [30], [54], [-83], [6], [-66], [-48], [-52], [28], [6], [38], [15], [-64], [66], [58], [30], [-52], [69], [19], [28], [21], [-30], [-39], [-18], [22], [45], [56], [-54], [-20], [-68], [86], [-26], [-93], [-8], [-34], [30], [21], [-40], [68], [-30], [-56], [64], [8], [19], [-2], [65], [-67], [-14], [-66], [-58], [72], [-9], [12], [80], [22], [68], [52], [-16], [68], [-3], [50], [62], [-22], [50], [-27], [31], [68], [-92], [68], [53], [-76], [-33], [-29], [-65], [-11], [72], [-59], [-50], [81], [0], [-71], [18], [-48], [40], [31], [-25], [-38], [-16], [48], [-19], [-53], [-61], [71], [-58], [36], [17], [-21], [24], [-91], [-72], [0], [-1], [-50], [-59], [66], [-3], [-38], [-90], [5], [-62], [-7], [67], [2], [16], [9], [-60], [-33], [-32], [-30], [-88], [-10], [-60], [87], [93], [-74], [6], [-26], [-79], [102], [33], [0], [32], [-72]];
    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_j();".
// 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_j(:prec:=1)
    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_j();".
// 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_j( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_8048_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![-1, 1]>,<5,R![-2, 1]>,<7,R![1, 1]>,<13,R![-3, 1]>],Snew);
    return Vf;
end function;