
// Make newform 8030.2.a.u in Magma, downloaded from the LMFDB on 20 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_8030_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_8030_2_a_u();".
// 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_8030_2_a_u();".
// 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, 2, -4, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 1, 0, 0], [-2, -1, 1, 0], [1, -3, -1, 1]];
    Rf_basisdens := [1, 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_8030_a();"
function MakeCharacter_8030_a()
    N := 8030;
    order := 1;
    char_gens := [1607, 2191, 881];
    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_8030_a_Hecke(Kf)
    return MakeCharacter_8030_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, 0, 0], [0, 0, 0, 1], [1, 0, 0, 0], [-3, 0, 0, 0], [-1, 0, 0, 0], [1, 2, 0, -1], [0, 2, -1, -2], [-5, 0, 1, -1], [1, -2, -2, 2], [2, -2, 1, -1], [2, -4, 0, 2], [2, 2, 4, 1], [-3, 0, 2, 2], [0, -3, 0, 0], [-2, 3, 3, 0], [2, 1, 0, -2], [-3, -1, -6, -2], [1, -4, -3, -4], [-8, 3, -4, -6], [0, -6, -1, 4], [-1, 0, 0, 0], [-9, 3, 1, 1], [-5, 5, 1, -2], [4, 1, 1, -4], [-7, 3, -4, -2], [-8, 2, -1, 0], [6, -1, 2, 6], [-8, -4, 2, -2], [3, 2, 1, -2], [-6, 4, 1, -3], [0, 3, 4, 3], [-4, -4, -5, -5], [-3, -2, -1, 4], [-12, 4, -3, -7], [3, -3, 3, -3], [1, 5, 0, 3], [-7, 1, -2, 2], [2, -3, -5, -2], [5, -8, 4, 6], [-7, 8, 3, 4], [-6, 1, 5, 0], [-1, -3, 7, 1], [-1, -5, 3, 1], [-3, 7, 4, 6], [0, -2, 0, 4], [-2, -1, 3, 0], [7, -11, 2, 10], [-1, -6, -8, 3], [-13, 1, -7, -8], [-8, -8, -1, 6], [1, -2, -1, 12], [9, -7, -3, 5], [6, -11, -1, 5], [-2, 5, 9, 6], [2, 3, 0, 7], [-4, 9, 11, 2], [12, -15, -2, 2], [6, -10, -1, 5], [1, -2, -2, -5], [-2, -6, -8, 7], [-5, -6, 0, 0], [-16, 5, 0, -3], [12, 1, 2, 3], [-11, 11, 5, 4], [6, 3, -5, 9], [4, -8, 2, 3], [5, 8, 1, -7], [2, -9, -6, 4], [-6, -12, -4, 5], [4, -1, 4, 0], [8, 10, -3, -3], [-12, 17, 1, -7], [3, -4, -8, 2], [-5, 7, 9, -2], [-14, 6, 7, 0], [-10, 12, 9, 5], [7, 9, 4, 2], [16, -7, 2, -1], [0, -6, -1, -1], [15, -5, -5, 1], [-3, 12, 4, 3], [-15, -8, -6, -2], [-4, -6, -10, 5], [0, 12, 4, -11], [9, 7, -5, -2], [5, -18, 7, 9], [-4, 5, -1, 6], [6, -4, 0, -7], [10, 0, -3, -6], [12, 7, 2, 15], [-14, 4, 4, -2], [-7, 14, 11, -2], [6, -5, 3, -3], [0, 0, -4, -1], [-1, 9, -7, -7], [-7, -9, -14, 0], [17, -4, -3, -9], [3, -17, -9, 8], [-4, 2, -3, 8], [4, 11, -2, -5], [13, -3, -9, 3], [-4, -4, -6, -3], [-3, 19, 0, -12], [16, -2, -9, -2], [-6, 17, -1, 2], [-16, 6, 9, 3], [1, 0, -4, -11], [-22, 13, 5, 3], [3, 1, 1, 0], [-13, 4, 4, 1], [10, 3, 12, -2], [5, -19, 1, 18], [17, 3, 3, 12], [17, 4, 5, 15], [2, -1, 1, 14], [19, -2, 1, 6], [-6, -15, 3, 1], [-1, 6, 12, 6], [-9, -11, 13, -1], [8, 13, 2, -20], [21, -5, -5, -3], [9, -2, 10, 16], [5, 0, -8, 13], [-18, 0, 0, -15], [-16, 8, -6, 0], [11, -3, 2, 7], [-9, -13, -7, 2], [11, 0, -12, 1], [-5, -9, 4, -2], [-28, 5, 5, -7], [25, 12, 3, -9], [-8, 2, -2, -8], [-5, 15, 12, 3], [0, -5, 0, -12], [-6, 0, -10, -6], [-10, -13, 3, -4], [-7, 23, -2, -12], [-3, 8, 3, 20], [-5, 2, -6, -13], [4, -5, -9, -22], [-21, 11, 0, -9], [-2, -11, 1, 12], [6, -9, 14, 13], [-7, -15, 0, 3], [6, 0, 2, -4], [-4, -2, -5, -33], [2, 14, -8, -11], [-2, -27, 4, 7], [-29, 0, -7, -18], [3, 3, 5, -2], [-28, 18, 1, -10], [8, -16, 10, 5], [2, 23, -2, -7], [-30, 16, 9, 7], [-17, 33, -6, -22], [8, 11, -2, 17], [5, 18, 10, -17], [-6, 25, 5, -7], [16, 3, 5, 9], [-31, 7, 5, -3], [7, 7, 4, -16], [-6, -9, 5, -12], [6, -9, -13, -16], [-11, -4, 0, -13], [3, 2, -4, 22], [19, -8, 6, 2], [3, 10, -6, -17], [-34, 5, -4, 1], [15, -16, -14, 0], [-4, 0, -6, -17], [8, -16, -6, -8], [5, 11, 6, 4], [-17, -25, -10, 26], [-4, 6, 4, -5], [-8, 12, -7, -7], [10, -7, -7, -8], [-17, 26, -2, -7], [-17, 9, 10, 1], [-4, 23, -5, -7], [26, -30, 2, 16], [8, -8, -8, 12], [-23, -11, 3, 13], [-18, 1, -19, -13], [-3, -13, -14, 2], [-11, 11, -4, -14], [11, 13, 11, -5], [-17, -5, -1, -4], [-8, -6, 4, 10], [4, -11, 2, -5], [-19, 4, -12, -23], [5, 11, 24, 8], [9, -2, 9, 32], [6, 23, 10, -25], [-6, 19, 12, -3], [-34, 9, -8, -9], [7, 16, -14, -6], [-12, 3, -12, -18], [1, -9, 5, 8], [-22, 3, 14, 11], [-27, 9, -14, -9], [-15, 19, 13, 11], [-8, 7, 1, 1], [-17, 4, -12, -24], [-4, -18, 4, -5], [2, -5, -11, -17], [-7, 34, -7, -22], [10, 12, -6, 4], [-31, 24, -16, -25], [38, -26, -4, 10], [-17, 16, 5, -2], [7, 7, 9, 30], [-7, -7, 13, 0], [33, 11, 2, -6], [-9, 2, 10, 24], [-29, 12, 6, -8], [25, -12, -12, -5], [15, -17, -13, 2], [-24, 4, 6, 21], [0, -5, 7, -13], [28, -23, -1, 5], [-32, -14, 3, 4], [2, -5, 11, 32], [29, -14, 14, 11], [-13, 12, -3, -12], [-14, 25, -10, -12], [20, 6, -13, 9], [-32, 2, -16, -21], [45, 10, -1, -2], [24, 9, 8, -8], [1, -13, 4, 18], [7, 12, 9, -22], [18, 1, 2, 14], [-24, -19, -7, -1], [0, 33, 12, -24], [-16, 32, 8, -9], [20, 18, -5, 2], [-31, 8, 14, -9], [-4, -3, -3, 16], [19, -34, -15, 11], [-12, 38, 6, -20], [29, 1, 6, -8], [9, -1, -11, -16], [-9, -2, -2, -13], [-2, -11, -3, 21], [-3, 4, 21, 18], [28, -9, 13, 22], [16, -6, 9, -6], [-14, 12, -5, 10], [9, -40, 0, 17], [-25, -15, 15, -7], [8, -20, 2, 2], [-15, -1, 16, 3], [23, -23, -11, 1], [-36, 4, -19, -26], [16, -15, 1, -14], [6, -20, -19, -11], [-2, -24, -1, 3], [4, 27, 15, -12], [-14, -4, 10, 28], [-16, -18, -3, -2], [-3, -15, 5, 20], [-16, 31, 21, -9], [15, 2, -9, 23], [-23, 1, -13, -6], [36, 2, 6, -3], [48, -24, -4, 6], [31, -4, -6, 2], [32, -5, -19, 3], [14, -19, -3, 2], [16, 18, 9, -22], [13, -4, -4, 17], [34, -22, 4, 19], [-40, 30, -13, -29], [14, -32, -2, -4], [-20, -9, 1, -21], [-10, -19, 4, 14], [-5, -13, 22, -1], [13, -11, 4, -9], [-21, 25, -6, -23], [12, -2, 15, -11], [-4, 3, 13, 14], [51, -12, 8, 13], [26, 4, 19, 23], [13, 4, 18, 17], [17, -19, -6, 7], [0, 3, 2, -24], [21, 5, 32, 9], [33, -32, -23, -10], [-6, -9, 2, 13], [40, -19, 12, 19], [11, 10, -16, -8], [3, -4, -12, -8], [-14, -5, -14, 12], [16, -15, 14, 7], [-28, -1, -23, -19], [-14, 20, 6, 8], [-48, 7, 1, 7], [16, 3, 12, 20], [33, 7, 4, 23], [-24, -18, -13, 12], [-25, 26, -14, -27], [9, -26, -19, 5], [-34, 21, -10, -11], [3, -16, 0, 18], [4, 17, 0, -20], [-7, 31, -8, -20], [-39, 40, 18, 9], [-12, -22, -14, 13], [28, 2, 15, -1], [-22, 29, 7, 2], [0, -19, -28, -8], [36, -14, 8, 32], [4, -6, -2, -2], [-9, -17, 5, 8], [-26, -20, -3, -3], [-12, -7, -15, 8], [16, -31, -3, -5], [2, 2, -5, -26], [13, 7, -16, -3], [-20, 1, -10, -18], [-7, -16, -26, -10], [41, 7, -6, 2], [25, -23, -13, -18], [-36, 30, 26, 6], [9, -1, -5, -17], [18, -5, -18, 14], [-11, -15, -14, 1], [-31, -14, 15, 13], [7, 6, 28, 1], [-28, 9, -17, -7], [-18, -1, -11, 3], [10, 2, -21, 6], [1, -1, 24, 2], [-2, 15, 11, 35], [13, -10, 16, 24], [15, 12, 16, 13], [-4, 11, 5, -1], [31, -23, 4, 13], [-25, 10, 0, 2], [-3, 4, -15, -29], [37, -14, 16, 23], [-36, -6, -7, -8], [-8, -1, -3, 10], [-60, 13, -4, -20], [19, 15, -7, -1], [55, -5, -3, 16], [-17, 10, 4, 7], [-25, -4, -19, -34], [2, -2, 5, 13], [21, -24, -16, 13], [34, -44, -6, 5], [19, -15, 4, -11], [19, 8, 23, -4], [-6, -20, -8, -14], [2, -9, 0, 18], [-58, 13, 10, 9], [3, 31, -1, -31], [19, -30, 12, 5], [-43, -9, 13, -13], [-1, -12, -13, -25], [1, -25, 17, 14], [5, 1, -25, 1], [-15, -9, -10, -15], [-32, 16, 19, -12], [-5, -1, 19, 3], [-16, 28, 1, -7], [6, 22, 8, -7], [-5, 7, -22, -17], [-43, -4, -5, 17], [-2, 20, -9, 6], [-39, 18, -30, -38], [-21, 9, 35, 1], [-30, -7, -3, 9], [-19, -24, -14, -9], [12, 3, 28, 14], [6, 21, 14, 12], [-12, 27, 11, 18], [-29, 3, -18, -12], [46, -18, 25, 26], [44, 13, 0, -10], [36, -31, 6, 17], [-15, 28, -9, 2], [-20, 0, -1, 5], [-17, -16, -23, -14], [45, -19, -17, 12], [-16, -5, -30, -23], [25, 4, 23, 14], [-32, -25, 15, 4], [33, -13, -27, -3], [-42, 17, -15, -11], [-19, 22, -9, -1], [-33, -13, -5, -29], [45, 13, 18, 3], [-3, -25, 0, 34], [-13, -1, -11, 11], [-31, 11, -10, -20], [45, 21, -5, -3], [-8, -26, -33, 5], [-12, 24, 2, 13], [5, 1, -9, 5], [-36, 18, -3, -32], [3, 0, 19, -5], [33, -11, -32, 6], [13, 6, -4, -8], [12, -18, 21, 26], [-38, -15, 9, 13], [3, -26, 6, 4], [43, 16, -2, 27], [11, -25, 4, 45], [-51, 2, 5, -20], [-39, -8, 8, 23], [1, -24, -24, -29], [-43, 12, -19, -26], [-16, 8, 21, 12], [-11, -33, -4, 22], [-12, 26, 9, 16], [-12, 6, -33, -25], [34, -4, 6, -12], [24, 8, -12, 9], [0, -29, 14, 15], [65, -22, -6, 10], [3, 6, -14, -5], [32, -9, 3, 19], [6, 14, -27, -15], [-18, 3, -11, -14], [-17, 34, -8, -6], [52, 2, 17, 6], [14, 29, 3, -16], [-43, -10, 10, 2], [33, 10, -9, -1]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_8030_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_8030_2_a_u();".
// 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_8030_2_a_u(:prec:=4)
    chi := MakeCharacter_8030_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_8030_2_a_u();".
// 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_8030_2_a_u( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_8030_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![5, -3, -5, 1, 1]>,<7,R![3, 1]>],Snew);
    return Vf;
end function;