
// Make newform 8032.2.a.b in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_8032_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_8032_2_a_b();".
// 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_8032_2_a_b();".
// 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_8032_a();"
function MakeCharacter_8032_a()
    N := 8032;
    order := 1;
    char_gens := [6527, 3013, 257];
    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_8032_a_Hecke(Kf)
    return MakeCharacter_8032_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], [1], [-3], [2], [2], [7], [-4], [-5], [2], [5], [6], [5], [-10], [2], [-6], [6], [-14], [-5], [-8], [-1], [1], [9], [10], [-4], [-9], [8], [8], [6], [13], [-20], [-3], [0], [0], [6], [-10], [4], [-22], [6], [-5], [-19], [-10], [-4], [16], [1], [-20], [-4], [-18], [-7], [-6], [2], [22], [-25], [-1], [-20], [-24], [12], [-23], [8], [16], [-24], [-14], [-4], [-27], [-26], [2], [27], [5], [18], [-24], [0], [9], [-8], [-31], [-2], [-16], [24], [-38], [-12], [28], [26], [-8], [-32], [-24], [-10], [27], [6], [-8], [12], [14], [30], [-12], [-12], [-39], [24], [-25], [38], [22], [-1], [11], [-11], [18], [42], [19], [-7], [5], [7], [29], [-32], [0], [-3], [-14], [6], [25], [-8], [2], [-20], [-24], [14], [-50], [2], [-20], [7], [9], [28], [-20], [-7], [-24], [13], [44], [-20], [-16], [8], [-43], [18], [-42], [-9], [26], [-30], [44], [-20], [35], [40], [4], [10], [47], [13], [18], [-5], [-13], [-50], [-12], [22], [-16], [-13], [12], [8], [18], [-2], [-12], [-9], [32], [3], [12], [-32], [40], [6], [-46], [-7], [-54], [12], [-13], [-39], [56], [-5], [-45], [58], [10], [-28], [-21], [-37], [-20], [-13], [-33], [62], [-31], [47], [61], [22], [12], [31], [-46], [56], [0], [24], [21], [29], [53], [-54], [-24], [-38], [-43], [17], [-26], [19], [7], [30], [56], [-34], [-31], [-58], [-18], [-61], [29], [-15], [-53], [56], [19], [-16], [27], [-20], [71], [1], [34], [26], [15], [-48], [56], [-17], [51], [7], [-20], [-28], [30], [44], [63], [-20], [-44], [30], [7], [36], [65], [-56], [30], [14], [42], [12], [7], [28], [-28], [11], [12], [13], [-50], [32], [-44], [27], [-77], [-57], [78], [66], [-20], [48], [56], [-12], [44], [36], [72], [41], [-26], [-14], [28], [46], [4], [-35], [-10], [78], [34], [-68], [6], [-36], [-32], [12], [-44], [65], [-53], [-54], [-4], [64], [18], [2], [10], [57], [5], [8], [-87], [64], [-34], [-9], [-30], [18], [15], [2], [-56], [-31], [-23], [-2], [69], [89], [-35], [32], [66], [5], [-76], [-1], [11], [1], [84], [-70], [-15], [-11], [32], [26], [56], [66], [-61], [68], [-23], [-60], [-3], [8], [-78], [2], [-88], [-33], [-4], [-26], [-36], [39], [47], [-70], [22], [-6], [-20], [-85], [-84], [78], [-36], [-56], [28], [5], [-82], [45], [3], [48], [64], [85], [0], [-32], [-59], [-6], [50], [-44], [-38], [-27], [-31], [86], [68], [-80], [57], [32], [-36], [2], [-9], [50], [48], [15], [-74], [0], [-56], [66], [-19], [34], [75], [-36], [-64], [-5], [-52], [61], [-64], [34], [32], [13], [97], [-60], [-96], [41], [-83], [-31], [54], [34], [67], [-50], [-45], [-50], [-74], [-46], [-34], [28], [89], [-26], [-18], [-4], [-28], [6], [-83], [-16], [-18], [0], [39], [28], [-7], [-40], [-4], [-45], [49], [-28], [73], [68], [-24]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_8032_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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