
// Make newform 8034.2.a.k 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_k();".
// 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_k();".
// 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], [4], [-1], [-3], [-1], [-3], [8], [-2], [8], [8], [-8], [0], [-8], [12], [9], [-6], [6], [-3], [2], [11], [10], [-6], [-10], [-12], [5], [1], [-11], [2], [0], [-17], [-4], [14], [1], [15], [-12], [13], [-14], [19], [-3], [7], [25], [-17], [-2], [6], [19], [8], [21], [-7], [2], [6], [-3], [-5], [4], [-12], [-17], [4], [-14], [-2], [-22], [-12], [-16], [-23], [-20], [-22], [-27], [-35], [-17], [36], [2], [-31], [-25], [-22], [22], [-7], [34], [9], [-14], [-22], [12], [9], [-17], [-8], [32], [25], [-28], [-15], [18], [30], [-14], [-39], [14], [-32], [-37], [4], [-4], [21], [0], [13], [13], [-8], [12], [-22], [30], [-32], [43], [2], [21], [-27], [32], [6], [-35], [-6], [-40], [19], [33], [-16], [12], [-18], [45], [10], [-1], [8], [33], [-44], [12], [-14], [-47], [-37], [46], [50], [42], [-52], [-48], [22], [23], [-11], [8], [-12], [12], [-28], [25], [-16], [-36], [-6], [44], [-29], [-19], [54], [-28], [-28], [8], [7], [-22], [5], [20], [-3], [8], [-12], [15], [-32], [-31], [-32], [-4], [-34], [51], [-34], [-14], [-20], [31], [26], [-26], [0], [-41], [18], [-39], [-4], [-8], [-32], [61], [-24], [21], [-32], [-22], [58], [42], [61], [-46], [37], [-29], [10], [-30], [12], [62], [-30], [-11], [16], [-29], [46], [-35], [-44], [-28], [33], [-39], [48], [70], [-34], [18], [-58], [12], [13], [-26], [64], [48], [-7], [-26], [2], [-12], [-32], [6], [37], [40], [51], [8], [-22], [21], [30], [-40], [37], [18], [26], [-35], [-13], [30], [1], [72], [15], [-56], [-50], [-37], [-48], [-24], [31], [-34], [-8], [30], [18], [38], [-66], [-6], [23], [-28], [-8], [-26], [54], [-21], [-68], [52], [-18], [14], [-66], [-57], [-58], [-29], [-4], [-70], [31], [-21], [-52], [-49], [34], [43], [2], [50], [53], [-5], [42], [-57], [-80], [52], [24], [-18], [33], [10], [-72], [78], [-73], [-27], [-13], [40], [18], [-14], [44], [45], [8], [-34], [34], [14], [-6], [4], [-19], [-48], [15], [60], [-68], [56], [-14], [-60], [15], [86], [24], [-75], [60], [-56], [68], [-37], [-9], [38], [13], [-68], [50], [-27], [24], [49], [28], [-38], [-36], [39], [83], [-16], [55], [-6], [60], [-76], [-36], [22], [-22], [10], [30], [-1], [-46], [4], [54], [55], [-60], [18], [74], [-22], [-16], [48], [0], [58], [72], [-26], [-18], [12], [72], [-33], [82], [26], [-18], [-41], [-80], [51], [8], [73], [40], [74], [78], [-13], [-16], [-44], [-38], [32], [30], [22], [58], [-80], [-39], [86], [-15], [36], [1], [18], [12], [26], [20], [62], [89], [86], [-29], [-3], [45], [-17], [-48], [40], [8], [-96], [-62], [18], [-82], [-66], [26], [87], [51], [88], [67], [-21], [-8], [68], [43], [18], [-68], [-56], [-75], [21], [-3], [43], [0], [76], [78], [57], [12], [63], [14], [-16], [-13], [33], [-4], [55]];
    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_k();".
// 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_k(: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_k();".
// 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_k( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_8034_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![-4, 1]>,<7,R![1, 1]>],Snew);
    return Vf;
end function;