
// Make newform 8036.2.a.g 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_g();".
// 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_g();".
// 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 := [-3, -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_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], [1, 1], [1, 1], [0, 0], [1, 0], [5, 0], [3, -4], [3, -3], [-1, -1], [8, 1], [-7, 3], [4, -2], [1, 0], [-7, -2], [10, -2], [-5, 1], [1, -3], [1, 4], [-5, 3], [-3, -4], [-7, 0], [-12, -2], [-3, 6], [-3, 5], [7, -7], [-1, -2], [10, -1], [2, 6], [2, 4], [15, -4], [7, 0], [-15, -3], [9, -3], [11, 2], [-10, 4], [-5, 0], [0, 8], [-8, -4], [5, -4], [3, -6], [7, -7], [10, 0], [4, -4], [5, -8], [5, -3], [-9, 4], [0, -7], [7, -1], [9, -6], [24, 2], [-14, -3], [-10, -5], [2, -6], [-9, 6], [19, 0], [13, -2], [-20, -1], [19, 0], [-7, -2], [-5, 0], [16, -12], [-9, 16], [6, -4], [-2, 3], [-13, 2], [11, -4], [-12, 12], [10, -4], [-24, 2], [-1, -10], [-6, 16], [4, 2], [-6, -5], [-17, 1], [-2, -6], [-9, -2], [0, 3], [7, -9], [-16, 6], [1, -2], [0, 9], [18, 0], [-5, 2], [19, -3], [7, -12], [-15, 15], [-14, -4], [23, -6], [-11, 6], [2, -13], [-3, 4], [-31, 7], [-20, -2], [4, 9], [-12, 14], [14, 1], [28, 3], [-9, 1], [27, -2], [-13, 21], [-13, -8], [-6, -15], [19, -12], [3, -15], [30, -12], [3, 8], [15, -14], [4, -16], [6, 6], [-8, 1], [1, 10], [9, -17], [21, 10], [26, -5], [-15, 16], [27, -12], [-12, 23], [-17, 10], [-9, -9], [17, -2], [-24, -2], [25, 6], [3, -21], [-23, 12], [24, -1], [-19, 3], [-4, 2], [-19, 14], [-20, -11], [27, -8], [12, -5], [-6, 25], [-13, 14], [16, -10], [-32, 0], [16, 10], [1, -16], [8, -2], [13, -12], [-31, 11], [3, 0], [19, -16], [-38, -5], [15, 4], [27, -12], [22, 2], [38, -12], [34, 5], [-5, 5], [21, -16], [2, 23], [14, 4], [-11, 25], [-20, 16], [14, 7], [8, -16], [-10, 5], [-2, 15], [15, 10], [3, 1], [48, 3], [12, 17], [-20, -8], [29, 10], [-22, 1], [-19, 10], [23, 6], [26, -9], [-2, -3], [9, 11], [-45, -2], [-22, 6], [21, 13], [12, 6], [2, -10], [-8, -7], [-42, 17], [-23, -10], [17, -22], [-27, 10], [-40, -1], [-11, -4], [24, -28], [6, -17], [15, 7], [16, -4], [-7, 16], [-20, -19], [23, 2], [3, 9], [-29, -5], [29, -4], [7, 0], [21, -24], [-51, -6], [25, -7], [37, -4], [3, -23], [-39, -7], [0, 9], [15, -12], [-43, 6], [-4, 8], [-48, -1], [42, -9], [8, -24], [-3, -20], [-29, 2], [-30, -6], [-13, 25], [18, 16], [0, 30], [19, -10], [3, -16], [-18, -8], [-10, 19], [-29, 22], [48, -6], [-11, 35], [-9, 21], [1, 17], [-18, 28], [3, -2], [22, -12], [-58, 1], [-26, -19], [42, 4], [11, 3], [11, 13], [18, 9], [-8, -4], [32, -10], [18, 8], [51, 3], [-25, -6], [-50, 2], [14, 18], [1, -29], [20, -26], [43, -11], [-3, -3], [-13, 14], [26, 7], [53, -11], [-40, -2], [-14, 3], [4, -5], [-1, 2], [-9, 36], [-6, 6], [-22, 12], [-4, 10], [-34, -15], [9, 13], [-6, -11], [1, -25], [3, 22], [14, 10], [6, 4], [-37, -16], [37, -8], [-54, -1], [17, -37], [-14, 6], [4, 10], [27, 8], [-54, 9], [-55, -8], [-53, 16], [-15, 7], [-26, 29], [-34, 30], [12, 25], [-56, 10], [2, -1], [-29, -3], [-18, -21], [-34, 11], [31, -32], [-18, 9], [40, -24], [-8, 28], [-9, 21], [13, 11], [17, 5], [31, -19], [-17, -5], [30, 0], [63, -2], [65, 4], [-10, 6], [-63, -6], [48, -6], [34, -1], [-1, 15], [-19, 9], [-7, 28], [54, 10], [9, -21], [4, -29], [0, 29], [21, -8], [11, -6], [3, 6], [-25, -10], [63, -14], [-12, -6], [-68, 12], [-51, 26], [-34, -12], [-9, -15], [-51, -12], [-33, 31], [-3, -37], [10, 5], [35, -14], [-30, -19], [12, -35], [50, 1], [-9, 30], [18, -6], [24, 0], [5, -10], [-18, 23], [35, -8], [-12, 26], [58, -19], [0, -4], [-21, -16], [-31, 3], [41, -17], [-9, 12], [19, -24], [-73, 4], [57, 4], [-28, 16], [3, -2], [-51, 3], [-28, 40], [74, -9], [35, -13], [41, -41], [-48, 33], [-17, 3], [-25, 13], [-8, -7], [-7, 22], [18, -11], [17, -8], [-9, 18], [-17, -8], [23, 12], [-39, 20], [-17, -23], [1, -34], [-30, 33], [-15, 12], [20, -35], [2, 10], [-38, 32], [13, 25], [-3, -3], [24, 10], [-12, -8], [-48, 19], [1, -14], [-39, -15], [-25, -15], [53, -8], [4, 12], [-23, 4], [-41, 38], [-21, 2], [-20, -15], [29, -4], [-50, -1], [-48, 24], [-31, -4], [-43, 1], [2, -34], [-21, 36], [-45, 0], [-5, -1], [-15, 20], [-4, -13], [-60, -2], [35, -27], [-2, 2], [-15, 21], [-39, 32], [36, -17], [3, 4], [-18, 20], [-39, 26], [-8, -28], [18, 19], [-3, 34], [-15, 6], [-32, 15], [-45, 37], [-60, 9], [-39, 20], [-31, 0], [-3, 36], [-56, 7], [32, -21], [-3, -4], [46, -14], [-4, -8], [24, -6], [29, -34], [-27, -24], [53, -10], [25, -15], [33, 2], [-69, 1], [-39, 30], [40, -3], [53, -28], [-7, -17], [42, -11], [-20, 21], [18, 21], [-36, -10], [34, -38], [31, -6], [30, -30], [-43, -22], [50, -6], [-3, -30]];
    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_g();".
// 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_g(:prec:=2)
    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_g();".
// 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_g( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_8036_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![-1, -3, 1]>,<5,R![-1, -3, 1]>,<11,R![-1, 1]>],Snew);
    return Vf;
end function;