
// Make newform 8280.2.a.ba in Magma, downloaded from the LMFDB on 20 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_ba();".
// 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_ba();".
// 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 := [-6, 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, 1], [0, 1], [-2, -1], [3, -1], [0, 1], [1, 0], [3, 2], [-3, -2], [1, 3], [-3, 2], [4, -2], [4, -1], [-5, -1], [1, 0], [2, 1], [-7, -1], [1, 2], [-6, 1], [0, 0], [13, 1], [4, 2], [-6, 2], [15, 0], [-4, -4], [5, -5], [0, 1], [-1, 3], [8, 5], [-6, -2], [4, 2], [13, 0], [14, -1], [-2, -4], [15, -3], [-2, 2], [4, 1], [8, -4], [0, -4], [-12, 2], [2, 5], [-4, -4], [6, -4], [14, 0], [11, -4], [2, 2], [-16, 4], [4, -4], [12, -2], [5, -4], [8, -9], [10, -6], [-4, -7], [9, 5], [-1, 2], [7, 4], [-14, -2], [12, -1], [13, -3], [9, -5], [10, 5], [10, -2], [-11, 9], [4, -1], [11, 6], [-28, -2], [24, 0], [11, 6], [-8, 9], [-6, 5], [-1, -9], [10, 4], [-4, 4], [-3, -11], [26, 2], [4, 8], [-6, -10], [7, 4], [4, -9], [-4, -1], [12, 0], [-13, -1], [2, -2], [0, -5], [21, 8], [11, 5], [16, 6], [22, 3], [-9, 7], [-10, 1], [-28, 1], [11, 2], [17, 10], [19, 5], [6, -4], [8, 1], [30, -4], [20, 6], [-4, 12], [5, 15], [11, -3], [6, -4], [2, -5], [0, -2], [18, 4], [4, 1], [6, 0], [13, -8], [-8, -1], [8, -2], [-9, -9], [-16, -4], [14, -9], [-4, 11], [-17, 1], [-18, 9], [18, 3], [-4, -1], [-18, 0], [-8, -1], [5, 1], [20, 9], [-26, 4], [18, 5], [14, -9], [-5, 4], [9, -11], [19, 5], [29, 0], [0, -16], [28, 3], [-15, -1], [-13, -6], [-22, -13], [-34, -6], [7, -3], [3, 5], [-7, -8], [13, 14], [-6, -16], [0, 6], [-15, 11], [-3, -12], [-30, -4], [10, -16], [26, 6], [-11, -18], [-2, -8], [-42, -4], [-6, 3], [-12, 15], [-6, 4], [-13, -1], [4, -10], [28, -6], [19, -16], [-38, -2], [-6, 3], [16, -2], [6, -12], [-20, -3], [-32, -6], [-15, -3], [-17, -7], [-9, 16], [-32, 0], [4, 4], [-12, -1], [-12, 8], [-1, -2], [2, 0], [-33, -7], [-16, 0], [50, -3], [10, -6], [-19, 10], [-5, 1], [32, 13], [2, -19], [-10, 5], [54, 0], [-18, -3], [9, -15], [20, -7], [-6, -3], [9, -19], [-17, 2], [-9, 24], [-38, -9], [-18, 8], [-8, 7], [-41, -10], [6, -8], [-5, 9], [-8, 21], [10, -18], [-34, 4], [-6, -8], [-6, -17], [6, 16], [-38, -5], [16, 1], [-18, 7], [-34, -14], [38, -13], [14, 15], [-5, 16], [14, -20], [6, -8], [4, -14], [12, -4], [-14, -8], [15, -8], [18, 9], [2, 20], [-21, -12], [43, 9], [6, 23], [27, 14], [34, 12], [9, 10], [51, -3], [-18, -7], [21, -4], [-18, -18], [-39, 4], [-22, 4], [19, 2], [-2, -21], [4, -15], [-2, 0], [-37, 2], [-21, 13], [-14, -20], [2, -11], [-6, 0], [-51, -2], [-39, -4], [43, 11], [49, -10], [14, -14], [8, 18], [-24, 8], [-2, 4], [8, -7], [12, 21], [34, 8], [-7, -5], [-18, 6], [-54, 2], [13, 13], [-34, 14], [-18, 5], [-15, 16], [22, -23], [-34, 0], [-10, 17], [-14, -14], [-29, 3], [1, -29], [55, 4], [-17, 3], [-12, -20], [26, -9], [-6, -7], [-6, 4], [-1, -15], [-4, 10], [31, 12], [-23, 21], [-9, -17], [66, -4], [-36, 3], [46, 9], [-4, -3], [29, 6], [-2, -15], [-30, -3], [-18, -20], [10, 5], [-28, -10], [-32, -8], [-14, -3], [-21, 4], [-29, 17], [-10, 8], [14, 6], [12, 6], [-6, -12], [-67, 3], [-36, -10], [74, 5], [32, 3], [20, 20], [16, 7], [-6, -3], [-43, -16], [-54, -8], [29, 15], [-27, -9], [-16, 22], [-28, -13], [-16, 6], [-52, -5], [-42, -13], [34, 10], [10, 15], [-52, 3], [-20, 12], [24, -7], [34, 19], [-4, 14], [9, 7], [42, -19], [-25, -24], [-25, 6], [1, -21], [6, -16], [-14, 3], [-55, -11], [12, 28], [6, 10], [-9, -29], [46, 3], [-34, 15], [-14, -21], [-60, 12], [-11, -1], [37, -12], [-10, 23], [5, 4], [26, 3], [8, 12], [12, -16], [22, 0], [-30, 26], [-44, 18], [29, -3], [-58, -2], [42, 16], [-40, -10], [22, -17], [-21, 15], [-21, 8], [-25, -26], [-18, 5], [62, -12], [-19, 21], [-39, 8], [-56, 13], [21, -16], [-31, 1], [62, -5], [2, -4], [0, 19], [34, -2], [30, 17], [22, -22], [11, -35], [-39, 2], [6, 8], [0, 22], [-22, -2], [30, -18], [-36, -5], [51, -3], [-56, -12], [-29, -22], [51, -10], [54, 2], [-56, -6], [-68, 2], [-18, -19], [-49, 4], [-50, -14], [25, -1], [0, -30], [-42, 10], [6, -4], [14, 6], [-4, 6], [2, -13], [-16, 14], [78, 2], [-7, 4], [16, 17], [1, -5], [45, -17], [40, 5], [-66, 2], [17, -2], [-32, 1], [56, -3], [-35, -1], [46, 16], [72, -8], [40, -4], [33, 10], [23, -16], [-30, -4], [-57, -9], [23, -3], [-3, -4], [-27, 16], [-17, -9], [-32, -14], [-44, -14], [18, -2], [-16, -1], [18, -15], [60, -12], [-16, -22], [-3, 5], [-48, -8], [-42, -24], [-40, 11], [-3, -7], [-16, 18], [4, 3], [2, 18], [66, 1], [30, 18], [4, 5], [-64, 14], [24, 10], [-19, -2], [-70, -6], [55, 16], [-8, -36], [58, -12], [-10, -14], [-45, 1], [36, 1], [6, 11], [47, 6], [70, 0], [-26, 24], [-18, -2], [50, 10], [68, 1], [-5, -4], [20, 30], [31, -22], [76, 1], [58, -12], [-8, -15], [-39, 0], [-10, -22], [24, -9], [-16, -17], [18, -19], [0, 10], [18, -10], [-31, -24], [-9, 26], [14, -12], [1, 3], [11, 21], [-53, -14], [-20, -37], [-28, 6], [49, -10], [-28, 10], [-16, -5], [-6, 7], [19, 19], [4, -15], [14, -22], [80, -4], [-30, 13], [0, 20], [-48, -4], [3, 4], [33, -5], [19, 0], [24, 16], [12, -13], [-38, -14], [32, 7], [32, -26], [-15, 35]];
    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_ba();".
// 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_ba(: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_ba();".
// 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_ba( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_8280_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<7,R![-5, -2, 1]>,<11,R![-6, 0, 1]>,<13,R![-2, 4, 1]>,<17,R![3, -6, 1]>],Snew);
    return Vf;
end function;