
// Make newform 8036.2.a.h in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_8036_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_8036_2_a_h();".
// 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_8036_2_a_h();".
// 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 := [-1, -3, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-2, 0, 1]];
    Rf_basisdens := [1, 1, 1];
    Rf_basisnums := ChangeUniverse([[z : z in elt] : elt in Rf_num], Kf);
    Rfbasis := [Rf_basisnums[i]/Rf_basisdens[i] : i in [1..Degree(Kf)]];
    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_8036_a();"
function MakeCharacter_8036_a()
    N := 8036;
    order := 1;
    char_gens := [4019, 493, 785];
    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_8036_a_Hecke(Kf)
    return MakeCharacter_8036_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, 0], [1, -1, 0], [0, 2, -2], [0, 0, 0], [-2, 2, -4], [1, -1, 3], [-1, 0, -1], [3, -2, -1], [1, -1, -2], [-4, 2, 0], [4, 4, -4], [-7, -3, 1], [1, 0, 0], [-1, 4, -1], [1, -5, -1], [6, 2, 2], [2, 4, -4], [10, -2, 0], [-6, -4, 4], [4, 2, -6], [4, -4, 4], [4, -6, 6], [6, -4, 0], [1, -5, 7], [-1, -5, 4], [-5, 3, 0], [2, 10, -2], [-9, -4, -1], [2, -4, 0], [3, 3, 6], [-13, 3, 3], [14, 0, 0], [2, 6, -4], [4, -2, -8], [10, -6, 4], [-2, 12, 0], [11, 0, 3], [3, -7, 6], [9, 2, -7], [0, -2, -6], [6, -10, -6], [3, -5, 8], [-2, 4, -2], [8, 14, -8], [7, -2, 11], [-1, 13, -3], [10, -4, 0], [6, 4, -2], [-4, -12, 0], [3, 7, -12], [10, 4, -2], [6, 2, -10], [-8, -14, 4], [8, -2, -6], [-5, -5, 8], [-10, -16, 8], [-10, 6, 10], [-10, 6, 4], [7, -5, 18], [16, 2, 4], [4, -10, 12], [2, 16, -16], [4, -12, 12], [-13, 10, -9], [5, -4, 9], [-6, -14, 10], [4, -10, 8], [-5, 11, 10], [-16, 6, 2], [18, -4, 16], [8, -4, -2], [-7, -7, 1], [-4, -12, 12], [-3, 6, -3], [13, -1, -10], [-3, 15, 8], [9, 1, -3], [22, 4, 4], [23, 3, -9], [-6, 2, -8], [4, 0, 2], [-4, -8, 16], [4, -8, 12], [-14, 4, -4], [1, 3, 20], [1, -3, -7], [3, -9, -6], [10, -4, -12], [-2, 10, -4], [-2, 2, -16], [4, 4, -4], [9, -17, 0], [-5, -16, 15], [1, -5, 10], [16, 2, 8], [3, 25, -20], [-9, 21, -3], [1, -9, -13], [10, -4, 26], [-15, 2, 13], [8, -4, 8], [-2, -14, 8], [-5, 9, 5], [-21, 2, 3], [-12, -18, 14], [-9, 15, 4], [-11, -14, 5], [-5, 5, 5], [-13, 7, 11], [-3, -16, -7], [30, 4, 0], [-25, 7, -2], [13, 2, -15], [26, 6, -10], [-15, 17, -7], [28, 6, -2], [-5, -23, 25], [0, -8, -20], [6, 16, -14], [-10, 14, -10], [8, -2, 28], [-8, 2, -6], [-2, 14, 6], [2, 6, 4], [23, 5, 5], [-15, 17, -23], [12, 10, 10], [16, 12, -16], [3, 2, 7], [8, 12, -18], [-17, 11, -13], [23, 4, 3], [-8, 2, 6], [-14, 14, -16], [-18, 2, -4], [-8, 6, 2], [31, 12, -1], [12, 22, -6], [18, -6, 6], [10, 22, -16], [-34, -6, 8], [11, -18, 3], [-32, 8, 6], [18, -16, 2], [-6, 16, 0], [17, 15, 4], [-4, -2, 24], [0, -20, 14], [-16, 16, -38], [24, 0, 8], [15, 7, -18], [20, -10, 28], [-22, 4, -16], [-7, 3, 7], [-11, 21, -39], [19, 12, -13], [-8, -6, 22], [-9, -25, 24], [1, -13, 31], [-8, 18, 16], [-21, 5, -18], [-13, -17, 3], [-12, -2, 12], [-15, -22, 9], [-28, -20, 18], [6, -24, 18], [16, 12, -18], [-1, -25, 8], [17, 2, 5], [-7, -24, 17], [-2, 6, -20], [20, -18, -2], [-8, 2, -18], [5, -31, 21], [-5, 18, -37], [-26, 0, -4], [14, 10, -2], [25, 5, -2], [-3, -21, -13], [10, 8, 8], [3, 7, 11], [-30, 2, 8], [-28, 4, -4], [16, -6, 18], [13, -23, 29], [-8, -18, 8], [1, 5, 25], [14, 42, -26], [-14, -2, -18], [-33, 5, 1], [-20, -20, -2], [-26, -16, 6], [33, -4, 9], [-30, -14, 6], [-4, -16, -8], [2, 12, -18], [6, 16, 0], [-14, 12, -26], [15, 27, -12], [12, -20, 12], [14, -8, 24], [-8, -6, 6], [-39, 4, -7], [31, -16, 15], [-27, -17, -1], [2, 16, -24], [-24, -2, -8], [12, -6, 14], [-27, 25, -2], [4, 12, -30], [24, -4, 18], [-1, -23, 9], [-7, -15, 9], [20, -20, 20], [-33, 5, 8], [-6, 16, -20], [-24, 10, -18], [-2, -10, 30], [-20, 26, -18], [18, -16, 44], [-14, -14, 16], [-52, -8, 4], [-32, 24, 12], [20, -8, -16], [36, -8, -12], [-30, -22, 12], [-22, 2, -36], [-11, -12, 9], [-1, 6, 27], [13, -15, 13], [17, -23, -22], [3, -7, 13], [-11, 39, 2], [-19, -23, 18], [12, -8, -12], [35, -19, 17], [15, -15, -7], [-14, -14, 34], [-47, 9, -11], [53, 2, -3], [4, -16, 28], [19, -7, 20], [-7, -33, 28], [19, 7, 6], [26, -6, 0], [-36, 2, -12], [-26, 16, -52], [15, -31, 12], [15, -36, -9], [-20, -28, 0], [31, 30, -17], [-24, -34, 18], [-51, -8, 9], [8, -12, 18], [-17, 1, 17], [25, 4, -3], [-24, -30, 20], [-13, 13, 16], [5, -7, 24], [15, -8, -9], [-29, -27, 22], [10, 8, -26], [45, -4, 17], [17, -28, -19], [30, 6, -4], [-20, 12, -40], [-26, -50, 34], [-28, -32, 18], [-7, 28, -11], [-8, 38, -34], [-14, 28, 12], [-35, 13, -11], [-36, 18, -4], [35, -25, -1], [7, 5, 41], [-22, 2, -16], [-24, 38, -2], [38, -2, 2], [40, 4, -6], [-19, -1, 16], [43, -6, -5], [-8, 16, 2], [10, -6, -2], [-32, -4, 0], [55, 13, -3], [-42, -2, 10], [32, -16, -6], [14, -12, 24], [13, -25, 4], [23, -19, 17], [42, 34, -20], [32, -2, 4], [-38, 24, 18], [14, 10, -6], [40, 14, -10], [17, 12, -11], [15, -11, 13], [14, 2, -20], [19, 37, -15], [-9, -3, 4], [-16, -22, 4], [-20, -30, 32], [-5, -8, 27], [-6, -34, 22], [43, 35, -29], [-7, 21, -14], [-11, -36, 1], [22, 26, -10], [-40, -4, -18], [20, -4, 8], [17, 11, -8], [-44, -34, 26], [3, 10, 27], [-33, 23, 11], [-37, -16, 15], [30, 0, -26], [14, -10, 10], [-7, 23, 6], [-31, -28, 5], [40, 8, -18], [-40, 10, -14], [5, 6, 13], [-16, -2, 28], [-26, 22, 12], [-9, 23, 11], [14, 4, -8], [34, 16, -12], [23, -30, 19], [-24, 0, -28], [-3, -14, -11], [20, 36, -10], [-6, 24, -36], [-12, 12, 2], [-19, -10, -7], [-51, 7, -10], [33, 7, 0], [-2, 6, -2], [-40, -10, 0], [-33, -31, 33], [-16, -34, -8], [-14, 26, -16], [15, -9, -30], [-38, -12, 20], [-24, -28, 38], [11, -9, 6], [59, -13, 7], [12, 28, -12], [-15, 3, 18], [7, -7, 5], [36, -8, 0], [15, -26, 39], [27, -14, 27], [42, 10, -18], [20, 12, -8], [18, 16, 10], [1, 21, -48], [46, -10, 6], [-26, 26, -50], [9, -34, -7], [3, -36, 31], [1, -27, 33], [-13, 44, -45], [22, 16, -34], [1, -33, 46], [17, -17, -4], [20, -14, -14], [21, -43, -12], [-29, -8, 19], [31, -37, -5], [-12, 32, 8], [-23, -25, 40], [15, 13, 30], [-32, 14, 12], [70, 30, -18], [-12, -4, -30], [10, -38, 36], [28, -20, 8], [-24, 2, -6], [9, -8, 25], [33, 21, -24], [-37, -4, -25], [43, 6, -25], [16, -4, -28], [-7, 30, -27], [32, -32, 20], [10, -38, 38], [8, 26, -16], [-27, 1, 24], [20, -12, 52], [8, 32, 16], [2, -38, 40], [-15, 55, -1], [-6, -8, -48], [36, 2, 0], [-5, 49, -22], [14, 38, -16], [-31, 3, 23], [-22, -42, 12], [-11, 19, -10], [14, -10, 16], [10, -30, 18], [-16, -42, 18], [49, -9, 26], [19, 35, 0], [-8, 32, 0], [-1, 9, 24], [1, 14, 9], [34, -42, 12], [45, -13, 11], [-32, -22, 12], [26, 4, 10], [23, -37, 26], [18, 48, -12], [-10, 10, 10], [-34, -22, 2], [-26, 6, -16], [-15, -23, -11], [-13, 26, -21], [-33, 12, -33], [8, -34, 22], [-11, -7, 49], [-7, -11, 12], [61, -23, -11], [5, 39, -44], [4, 14, -8], [-18, -18, 14], [26, -8, -18], [-46, 26, 10], [7, 29, 5], [21, -2, 5]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_8036_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_8036_2_a_h();".
// 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_8036_2_a_h(:prec:=3)
    chi := MakeCharacter_8036_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_8036_2_a_h();".
// 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_8036_2_a_h( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_8036_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![3, 0, -3, 1]>,<5,R![8, -12, 0, 1]>,<11,R![-136, -24, 6, 1]>],Snew);
    return Vf;
end function;