
// Make newform 8034.2.a.d in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_8034_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_8034_2_a_d();".
// 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_8034_2_a_d();".
// 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_8034_a();"
function MakeCharacter_8034_a()
    N := 8034;
    order := 1;
    char_gens := [5357, 1237, 5773];
    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_8034_a_Hecke(Kf)
    return MakeCharacter_8034_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], [-1], [-2], [-5], [-5], [1], [-7], [-6], [4], [6], [-6], [-2], [-6], [-6], [-12], [-9], [0], [-8], [-13], [-4], [-1], [-2], [-6], [10], [-2], [-5], [1], [15], [20], [4], [7], [4], [-18], [-13], [-19], [18], [11], [2], [-9], [7], [5], [7], [7], [-10], [22], [15], [-8], [-11], [-9], [-26], [-12], [-11], [-5], [-8], [-26], [-5], [-6], [18], [26], [-18], [-10], [-24], [11], [-30], [-10], [23], [-17], [-5], [-36], [4], [21], [23], [-12], [16], [-17], [-12], [-21], [22], [12], [4], [-9], [-27], [16], [2], [-35], [-32], [17], [42], [-18], [-26], [-21], [22], [-14], [-15], [4], [-12], [35], [42], [31], [-1], [16], [-36], [-18], [-18], [12], [-37], [28], [-7], [-7], [-22], [22], [-29], [-38], [14], [11], [-27], [6], [-26], [34], [27], [12], [-49], [-26], [3], [-44], [-36], [26], [29], [-5], [14], [-28], [-12], [-24], [-18], [-30], [35], [-9], [-4], [-42], [-26], [8], [-25], [0], [24], [14], [24], [-51], [29], [22], [-24], [-12], [-4], [29], [-4], [-13], [-24], [-39], [4], [46], [-35], [20], [33], [58], [-42], [8], [-41], [-34], [-22], [-38], [-31], [-46], [4], [0], [-37], [-32], [-15], [-16], [32], [28], [15], [22], [19], [28], [30], [-16], [12], [15], [26], [65], [55], [64], [-14], [32], [16], [-50], [-39], [2], [41], [-50], [9], [32], [10], [-9], [17], [-56], [-54], [-54], [30], [2], [28], [-15], [-30], [24], [12], [-35], [-10], [8], [-24], [16], [66], [43], [72], [-21], [54], [-36], [-37], [46], [-72], [-15], [62], [46], [43], [15], [20], [63], [-60], [-5], [-46], [36], [55], [20], [-6], [-25], [34], [18], [-60], [-60], [50], [40], [-44], [-19], [-42], [-70], [-14], [-34], [-59], [-20], [42], [-30], [-42], [-52], [-75], [36], [-71], [42], [56], [-19], [-17], [-4], [-63], [42], [-55], [-30], [22], [33], [-65], [-30], [61], [-2], [20], [-70], [32], [-31], [-6], [-72], [8], [-1], [-69], [-37], [28], [-10], [-34], [18], [59], [34], [-18], [38], [52], [-6], [-54], [41], [84], [7], [12], [22], [40], [2], [-48], [-57], [10], [16], [35], [-58], [36], [26], [-1], [-15], [-54], [-83], [8], [-38], [-27], [-50], [9], [-32], [-4], [32], [-87], [43], [80], [53], [-66], [-34], [-36], [80], [-30], [28], [28], [40], [-29], [68], [60], [-6], [-45], [4], [30], [38], [72], [38], [48], [-94], [10], [-10], [-40], [-94], [66], [-8], [81], [-52], [-68], [50], [-69], [-52], [73], [-4], [49], [84], [44], [-58], [73], [64], [-40], [42], [84], [-22], [70], [-20], [12], [57], [-74], [47], [-96], [1], [-18], [72], [6], [-80], [70], [67], [-66], [-73], [51], [-45], [29], [48], [56], [-48], [64], [-60], [-90], [38], [58], [62], [-17], [17], [64], [13], [-13], [28], [36], [-65], [-88], [-90], [-38], [-39], [-25], [73], [-25], [46], [-6], [-96], [-53], [-62], [85], [26], [-62], [21], [33], [52], [47]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_8034_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_8034_2_a_d();".
// 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_8034_2_a_d(:prec:=1)
    chi := MakeCharacter_8034_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_8034_2_a_d();".
// 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_8034_2_a_d( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_8034_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![2, 1]>,<7,R![5, 1]>],Snew);
    return Vf;
end function;