
// Make newform 8034.2.a.i in Magma, downloaded from the LMFDB on 24 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_i();".
// 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_i();".
// 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], [0], [0], [2], [1], [-2], [8], [0], [-2], [10], [0], [2], [-4], [6], [-6], [12], [2], [-10], [6], [0], [0], [0], [8], [2], [6], [-1], [12], [-20], [-2], [-4], [12], [-10], [20], [18], [10], [-18], [24], [12], [-10], [-20], [10], [12], [-4], [-16], [-4], [-16], [4], [2], [22], [-26], [16], [12], [16], [6], [-4], [-30], [2], [14], [-12], [-16], [0], [22], [-24], [10], [30], [-2], [-14], [12], [16], [24], [-20], [-16], [-14], [10], [-10], [-14], [-28], [10], [-2], [20], [2], [4], [-26], [20], [12], [4], [-24], [10], [-22], [-28], [-18], [-18], [4], [-38], [-8], [14], [6], [-4], [-14], [-28], [-12], [0], [-10], [-20], [16], [16], [16], [48], [-10], [8], [-22], [16], [28], [8], [-14], [-44], [40], [6], [-12], [-20], [-14], [-18], [-18], [14], [-30], [14], [16], [12], [-24], [0], [26], [-40], [-18], [-36], [-12], [-54], [-16], [-26], [30], [-2], [-54], [4], [50], [-50], [-16], [-26], [6], [-8], [-6], [-8], [46], [-28], [-48], [-36], [-28], [0], [30], [34], [10], [18], [54], [2], [-8], [2], [-12], [-32], [-6], [-2], [14], [0], [32], [0], [16], [40], [58], [-42], [-28], [40], [-26], [58], [-12], [-54], [12], [-18], [-54], [-38], [20], [24], [-52], [-50], [-28], [44], [48], [36], [-30], [-46], [-14], [-28], [4], [-36], [40], [-14], [46], [-36], [34], [-50], [-24], [32], [20], [-34], [-46], [40], [-38], [24], [8], [-32], [42], [52], [6], [10], [-4], [24], [-38], [-12], [-58], [34], [-16], [28], [4], [26], [-20], [68], [26], [44], [-58], [-36], [-24], [16], [32], [32], [36], [-4], [42], [-22], [8], [6], [-32], [-12], [0], [-30], [-6], [-30], [-42], [-70], [-10], [58], [-16], [-54], [10], [-32], [36], [-16], [-54], [-46], [20], [54], [-44], [78], [-34], [-50], [2], [14], [-64], [-2], [-16], [-48], [46], [38], [76], [0], [-74], [76], [62], [76], [-40], [-50], [62], [-84], [-58], [34], [24], [70], [26], [34], [-46], [-48], [-26], [-20], [68], [34], [72], [76], [-44], [-32], [-34], [28], [-14], [12], [-6], [-36], [-10], [54], [-52], [-18], [-46], [34], [-78], [-28], [-78], [-80], [-24], [-10], [64], [34], [82], [-32], [62], [-4], [26], [-22], [62], [16], [30], [70], [52], [-84], [-18], [58], [-80], [-4], [78], [-20], [-48], [60], [28], [38], [-56], [-70], [74], [-48], [-30], [-12], [0], [6], [78], [-36], [18], [-58], [-6], [22], [54], [96], [-90], [20], [-26], [0], [18], [-10], [12], [-40], [10], [26], [80], [2], [48], [-24], [-34], [34], [-78], [-18], [-6], [60], [-30], [42], [-22], [-46], [-34], [70], [-48], [-64], [-26], [-78], [28], [-100], [-22], [-28], [-94], [-32], [30], [-20], [-6], [-50], [-48], [58], [-40], [-34], [-48], [14], [20], [-2], [74], [-96], [-16], [54], [18], [-80], [80], [78], [40], [10], [58], [94], [12], [100], [12], [60], [24], [70], [-12]];
    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_i();".
// 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_i(: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_i();".
// 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_i( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_8034_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![0, 1]>,<7,R![0, 1]>],Snew);
    return Vf;
end function;