
// Make newform 8280.2.a.x in Magma, downloaded from the LMFDB on 18 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_8280_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_8280_2_a_x();".
// 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_8280_2_a_x();".
// 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 := [-2, 0, 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_8280_a();"
function MakeCharacter_8280_a()
    N := 8280;
    order := 1;
    char_gens := [2071, 4141, 4601, 1657, 3961];
    v := [1, 1, 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_8280_a_Hecke(Kf)
    return MakeCharacter_8280_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, 0], [-1, 0], [-1, 2], [0, 1], [2, -1], [1, 1], [-6, -1], [1, 0], [5, -1], [-1, 0], [1, -6], [-3, -3], [-2, -4], [2, 3], [-1, -3], [-1, -9], [0, 1], [-7, -6], [7, 5], [-2, 3], [0, 12], [-7, 3], [12, -2], [4, 10], [3, 5], [-10, 6], [-5, 1], [-6, -1], [-9, -7], [-4, -11], [16, 0], [0, -2], [-9, -6], [-2, 3], [-10, -8], [-3, 0], [2, 12], [6, -3], [-16, -4], [14, 4], [-12, 6], [-10, 3], [4, 10], [10, -2], [-6, -6], [1, 14], [-2, -12], [12, -8], [-8, -6], [0, 4], [-3, -1], [6, -15], [-2, 12], [10, 1], [-11, -1], [-5, -5], [7, 8], [2, 12], [-8, 3], [-3, -16], [-1, -7], [-6, 7], [-20, -8], [7, 10], [6, 1], [-21, -2], [-14, 4], [4, -6], [-13, -2], [-2, 17], [-2, 5], [3, 0], [12, 4], [-20, 4], [-1, -9], [-6, 18], [-16, -4], [-30, -6], [17, 2], [0, -25], [6, 19], [-20, -6], [15, -8], [-14, -14], [-6, -7], [-11, 7], [15, -18], [2, 18], [-2, 17], [-13, 1], [-30, 7], [24, 5], [-33, 7], [1, -18], [-25, 3], [12, 6], [12, 9], [-20, 0], [-12, -22], [12, -4], [-1, -23], [45, -1], [-10, -6], [8, -7], [-4, 20], [-14, -16], [14, -5], [4, 10], [17, 4], [0, -9], [18, -16], [-13, -3], [-12, 20], [0, 1], [20, 1], [37, -4], [-16, 13], [4, 9], [-12, 13], [-18, 22], [20, -9], [5, 27], [-2, -29], [2, -12], [-34, -11], [-12, 21], [-17, -11], [9, 0], [5, 8], [3, 10], [-4, 0], [-38, -5], [1, -2], [31, -5], [-28, 9], [-6, 14], [9, -20], [25, 7], [-17, -9], [9, -10], [-8, -18], [-48, -4], [-15, 9], [-5, -2], [-34, 4], [-2, 6], [42, -8], [-51, -2], [-38, -6], [-10, 2], [18, -5], [-40, 5], [2, 2], [21, -2], [-12, -12], [-4, 20], [37, -3], [8, 6], [26, -23], [20, 6], [-18, 16], [24, 13], [-8, 30], [23, 19], [5, 23], [25, 18], [28, -6], [-32, -4], [-38, -7], [28, 4], [-7, 12], [-14, 0], [43, 2], [40, 4], [46, -1], [18, 18], [-3, 21], [11, 26], [-6, -15], [10, -13], [26, -15], [-14, 6], [32, 11], [-19, -9], [-44, -1], [-6, 11], [-21, 18], [-25, -22], [-45, 13], [-2, -21], [-18, 28], [-6, 13], [21, -5], [-38, -20], [1, -17], [54, -3], [-28, -22], [38, 16], [-26, -12], [-18, 11], [34, -16], [14, 9], [-10, 23], [30, 3], [26, -10], [52, 7], [4, -27], [13, -11], [2, 8], [-46, 2], [2, 42], [-6, -14], [-14, 12], [23, 9], [0, 17], [22, -10], [25, -11], [1, 23], [28, 11], [-5, 18], [26, -6], [41, -11], [-33, 2], [-4, 25], [11, 6], [10, -10], [5, -1], [-4, 0], [7, -13], [42, -1], [-22, -35], [14, -26], [53, -5], [-47, 0], [14, 0], [-44, 7], [22, 12], [-21, 13], [-23, -25], [25, 33], [-21, -16], [-18, 22], [-12, -6], [-28, 4], [12, -46], [4, 33], [60, 7], [18, 2], [-47, 1], [-8, 2], [-6, -28], [15, 15], [10, 6], [8, -9], [3, 27], [4, -19], [24, 16], [16, 43], [6, 20], [-9, 12], [-7, -11], [-35, 14], [-23, 38], [16, -34], [-16, -27], [-2, -7], [10, -12], [25, 28], [-12, 4], [-61, 8], [29, 20], [33, -18], [38, 12], [-12, -11], [22, -13], [18, 5], [-33, 0], [-4, -29], [-34, 13], [18, 20], [-12, -37], [68, -6], [8, 8], [34, 5], [41, -19], [35, 6], [-38, -20], [42, -10], [-18, 26], [10, 22], [35, -7], [8, 42], [-14, 25], [12, 1], [-56, 16], [14, 13], [-32, 21], [17, -37], [-30, 32], [-11, -42], [1, 37], [44, -18], [10, -25], [-8, 48], [36, 15], [-24, 17], [30, -36], [-34, 21], [-48, 17], [-32, 16], [-68, 11], [2, 3], [0, -28], [59, 9], [32, -3], [39, -11], [9, 43], [15, -24], [24, 6], [-8, 51], [39, 14], [-30, 4], [50, -20], [-1, -7], [20, 27], [-12, -17], [-14, 7], [36, -24], [-1, -51], [-1, 6], [40, -23], [-63, -16], [4, -47], [12, 20], [-16, -28], [10, 14], [26, 30], [-8, 2], [-23, -40], [78, 6], [-50, -16], [-22, -14], [-36, -35], [45, -3], [27, -23], [-45, 26], [-30, 3], [-34, -24], [7, -49], [-27, -40], [40, -9], [19, 23], [-13, 34], [-56, 1], [-38, 20], [20, -27], [-42, 8], [-20, 39], [-26, 2], [5, -8], [-3, 37], [22, -10], [16, -50], [-10, 46], [-2, 10], [-30, -17], [-31, 28], [4, -28], [17, 19], [7, 10], [6, -16], [-72, -14], [-12, -4], [74, -11], [-17, 13], [10, 18], [-1, 44], [-40, 18], [30, -42], [-26, -10], [-86, 2], [8, -64], [16, 31], [40, -34], [10, 28], [-23, 16], [44, -37], [-13, -8], [-7, 25], [-2, -67], [50, 6], [-21, -27], [32, 17], [4, -43], [79, 8], [-26, 6], [-52, -6], [-12, 4], [-7, -39], [43, 40], [10, -24], [-31, -30], [15, 19], [-25, 55], [5, 28], [-5, 44], [26, 50], [-22, -28], [4, 20], [-72, 7], [-44, -37], [-44, 20], [-12, 2], [65, 0], [30, 28], [-28, 46], [-40, -41], [-11, -37], [36, -22], [-24, -9], [8, 14], [16, 11], [32, 48], [-32, -5], [56, 0], [-16, -6], [-77, 5], [-22, -34], [41, 1], [-32, 0], [34, -4], [-6, -22], [41, 3], [44, 41], [2, 71], [41, 28], [-22, -32], [-2, -40], [34, 2], [54, 8], [-44, 9], [49, 26], [-40, -40], [75, -22], [-6, 63], [-66, 8], [2, 51], [-33, -30], [-58, 24], [12, 33], [12, 15], [-20, 29], [-34, -42], [-20, -30], [-63, 27], [-13, 30], [52, 42], [-81, 16], [-35, 51], [27, 46], [-42, -3], [56, 12], [19, 20], [48, -6], [-12, -5], [44, -23], [9, 9], [16, -33], [-34, 20], [48, -22], [-68, 11], [34, -20], [12, 28], [-83, -15], [29, 22], [33, -31], [-48, -40], [46, 29], [-2, -14], [-72, -17], [-12, 44], [-77, -4]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_8280_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_8280_2_a_x();".
// 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_8280_2_a_x(:prec:=2)
    chi := MakeCharacter_8280_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(3457) - 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_8280_2_a_x();".
// 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_8280_2_a_x( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_8280_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<7,R![-7, 2, 1]>,<11,R![-2, 0, 1]>,<13,R![2, -4, 1]>,<17,R![-1, -2, 1]>],Snew);
    return Vf;
end function;