
// Make newform 8034.2.a.l in Magma, downloaded from the LMFDB on 20 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_l();".
// 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_l();".
// 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
        poly := [-4, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    inp_vec := Vector(Rfbasis)*ChangeRing(Transpose(Matrix([[elt : elt in row] : row in input])),Kf);
    return Eltseq(inp_vec);
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, 0], [-1, 0], [-2, 0], [1, 1], [-1, 1], [-1, 0], [5, 1], [-2, 0], [0, -2], [6, 0], [-2, -2], [-6, 2], [2, 0], [-2, -2], [-4, 4], [5, -1], [-8, 0], [8, -2], [7, -3], [-4, -4], [-1, -3], [-2, -6], [2, -6], [2, 0], [-2, -4], [1, 3], [-1, 0], [7, -1], [0, 4], [4, 0], [-7, 3], [12, -6], [-6, 0], [-5, 5], [11, 3], [2, 6], [1, 5], [-10, 8], [-11, -5], [13, -5], [-3, 5], [5, -7], [1, 3], [-10, -6], [6, -8], [-15, 3], [-4, -8], [-1, 3], [3, 5], [-6, 0], [12, -8], [-1, 1], [-13, -3], [12, 4], [18, -2], [5, 3], [-18, -4], [-2, 6], [6, 0], [-10, 8], [6, -10], [8, 10], [23, 1], [-18, 0], [-10, 4], [1, 9], [11, -7], [-17, 7], [-20, -2], [8, 4], [-19, -3], [5, -9], [-20, -4], [-20, 6], [-5, 5], [-8, -8], [1, -1], [2, -10], [-4, -6], [12, -6], [-9, 7], [3, -9], [-32, 0], [-10, 8], [3, 9], [0, 8], [-31, -3], [18, 6], [2, -4], [10, -2], [-21, 11], [-2, 2], [-10, -10], [17, 1], [4, -12], [-20, -6], [-3, -7], [10, 2], [-25, 1], [-15, 1], [8, 0], [8, 2], [18, -10], [10, 6], [-20, 4], [-13, 5], [-24, 8], [9, -3], [-1, -7], [10, 4], [-18, -2], [-11, 21], [-6, 4], [6, 8], [-23, 9], [-31, 5], [-6, 12], [-2, 4], [22, 2], [-5, -17], [-12, 4], [3, 3], [-18, 4], [7, 1], [-28, -4], [-8, 6], [-10, -12], [19, 5], [-11, 7], [18, -18], [-16, 6], [-12, -12], [0, 12], [-14, -8], [-14, 4], [-5, -7], [-31, 9], [24, -14], [14, -12], [-14, 6], [-8, 20], [-15, -11], [8, 0], [8, 4], [18, -20], [-40, 4], [3, -13], [25, -7], [-10, -10], [-36, -4], [-12, 16], [-16, -12], [-3, 23], [28, -2], [-29, 17], [-8, -12], [-25, 5], [16, 10], [30, -12], [-21, -1], [-12, 0], [21, 5], [14, -2], [-2, -10], [-12, 2], [13, -5], [-34, 14], [38, -8], [14, -8], [-21, 9], [-18, 6], [-12, -16], [4, 10], [51, 1], [8, 4], [-43, 5], [0, 4], [4, -26], [-28, 8], [13, 17], [30, -10], [19, -13], [-20, -6], [46, 4], [-36, -4], [28, 2], [-35, 1], [-2, 4], [33, -5], [-11, 19], [-16, -6], [42, -6], [-24, -12], [-8, 2], [-26, -2], [37, 9], [10, -24], [43, -5], [14, 12], [-33, 21], [-24, -2], [6, -22], [-15, 9], [-35, 21], [-28, 16], [-18, 0], [42, 2], [34, -6], [-6, 24], [20, -4], [29, -19], [-34, -2], [0, -16], [-4, -8], [55, 5], [30, 14], [-48, 8], [12, 20], [-8, 0], [22, -20], [9, 13], [8, -2], [-13, -13], [6, 2], [28, 8], [-7, -3], [-26, -2], [0, -6], [7, 21], [22, -10], [2, -8], [11, -7], [-35, 9], [-24, -4], [-25, 5], [-4, -12], [-13, 21], [-2, 28], [12, 20], [-23, 27], [8, -16], [-34, 6], [-39, 3], [-50, -8], [-10, 12], [0, 22], [12, -28], [22, 18], [16, -10], [36, 6], [-45, -9], [34, -24], [-10, 10], [26, -4], [38, -24], [-31, 7], [44, 2], [18, 0], [30, 16], [34, 16], [-4, -16], [21, -3], [20, -28], [11, -17], [10, -12], [-20, 0], [-37, 7], [23, 19], [4, 20], [43, 9], [-2, 0], [29, 7], [14, -32], [50, -14], [29, 5], [-35, 5], [-62, 6], [-21, 11], [58, -4], [-28, -14], [-2, 24], [-32, -4], [23, -3], [-74, 4], [48, 2], [36, 14], [-13, 31], [-27, -3], [-15, -23], [60, -16], [10, -2], [38, -22], [-14, -8], [23, 9], [62, -12], [-30, 30], [-22, -10], [68, -6], [22, 10], [34, -4], [13, -11], [16, -34], [-47, 19], [20, -2], [38, 14], [12, 10], [-10, 10], [28, -14], [-11, 7], [38, -8], [-8, 16], [-27, -7], [-42, -2], [-44, -12], [-46, -10], [43, -1], [-43, -5], [42, -10], [53, 3], [8, -4], [-34, -10], [-3, 3], [-10, 12], [11, -17], [-20, -14], [32, 6], [-12, 14], [53, -21], [21, 15], [-20, 6], [19, 15], [-6, 30], [-10, -30], [-60, 0], [48, -12], [-50, -14], [-48, 16], [0, -26], [28, -34], [-11, -1], [24, -32], [8, 8], [-38, 24], [-11, -25], [-4, 2], [-58, 2], [-38, 20], [16, 22], [-10, 10], [20, -6], [-22, 12], [26, 8], [10, 8], [-8, 0], [-26, 4], [62, -2], [-16, 8], [29, 11], [12, -16], [20, -4], [30, -4], [63, -9], [-36, -4], [37, -13], [-28, 8], [37, -15], [-12, 42], [28, -32], [-42, 0], [25, 5], [-4, -16], [52, -20], [-18, 6], [-12, 16], [14, 12], [-46, -6], [-28, 22], [0, 6], [-3, -15], [2, 4], [-7, -11], [-24, -14], [-13, 23], [-50, 0], [-56, -8], [-38, 6], [44, 12], [-6, 28], [-49, 29], [2, 36], [-65, 5], [5, -31], [-73, 17], [-43, 35], [-8, -12], [-12, 34], [-64, 2], [20, -16], [20, 16], [-22, 24], [-34, -6], [22, 14], [10, -38], [-9, -9], [-25, -13], [-24, 24], [11, 35], [-13, 3], [-4, 8], [-56, -8], [43, -25], [52, 18], [-26, 6], [18, 18], [5, -11], [-83, -9], [-45, -11], [-15, 3], [66, -12], [74, -20], [-60, -6], [-19, 29], [-18, -22], [77, -11], [-14, -10], [70, -20], [61, -3], [-31, -3], [4, -28], [1, 3]];
    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_l();".
// 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_l(:prec:=2)
    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_l();".
// 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_l( : 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![-2, -3, 1]>],Snew);
    return Vf;
end function;