
// Make newform 8280.2.a.n in Magma, downloaded from the LMFDB on 12 May 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_n();".
// 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_n();".
// 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
        Kf := Rationals();
    end if;
    return [Kf!elt[1] : elt in input];
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], [1], [-2], [0], [-2], [6], [0], [-1], [0], [0], [-8], [-12], [-2], [8], [-10], [14], [2], [2], [2], [-6], [0], [-4], [-10], [-12], [0], [14], [4], [18], [10], [8], [-18], [-10], [4], [-2], [16], [-12], [-8], [-16], [10], [-18], [18], [-20], [-10], [-6], [-16], [-4], [-4], [-20], [-2], [-6], [10], [-22], [8], [-26], [-24], [4], [16], [-14], [6], [-2], [-6], [-8], [2], [28], [-10], [-4], [-4], [-12], [14], [2], [0], [-10], [-20], [32], [-24], [10], [-38], [-30], [-26], [-28], [38], [24], [8], [32], [-12], [0], [20], [-4], [40], [12], [-20], [8], [-26], [-28], [-16], [0], [22], [-42], [2], [8], [-14], [-44], [-30], [44], [-42], [24], [38], [-6], [-14], [-8], [20], [-6], [-28], [-40], [-14], [46], [0], [30], [4], [42], [10], [-26], [40], [28], [6], [-10], [26], [-42], [-8], [20], [-24], [4], [-12], [28], [14], [-14], [-50], [-30], [40], [-20], [36], [-12], [-36], [-30], [-12], [-14], [10], [28], [-4], [54], [54], [48], [-12], [14], [20], [4], [-16], [4], [-18], [32], [42], [4], [-40], [-18], [-16], [48], [22], [10], [-54], [36], [-22], [-32], [-24], [56], [-14], [4], [-32], [-26], [38], [-16], [16], [-6], [54], [0], [34], [6], [42], [10], [30], [-2], [24], [-8], [-4], [-12], [38], [-2], [4], [46], [-24], [-6], [24], [10], [-14], [60], [-38], [8], [-32], [-52], [-4], [-54], [-28], [6], [-28], [42], [-66], [-64], [12], [32], [6], [6], [40], [-72], [6], [36], [42], [-30], [18], [-46], [-58], [-38], [40], [-32], [-8], [54], [56], [-34], [42], [6], [-42], [68], [-20], [-28], [50], [-54], [38], [32], [48], [40], [64], [-12], [66], [8], [38], [54], [6], [-14], [-10], [-2], [-2], [46], [20], [58], [28], [-42], [44], [-6], [18], [-70], [70], [-50], [10], [24], [-24], [-54], [-56], [-56], [2], [-2], [-48], [-72], [-68], [64], [46], [4], [42], [64], [10], [-40], [12], [30], [4], [-6], [76], [-10], [46], [76], [-6], [70], [0], [-4], [78], [56], [-44], [32], [-58], [-72], [22], [-40], [2], [-4], [-54], [14], [56], [-48], [18], [82], [-50], [16], [0], [40], [-4], [60], [36], [-6], [-38], [20], [-32], [-72], [26], [34], [-2], [-40], [4], [20], [48], [46], [66], [-26], [-70], [74], [30], [-32], [-92], [-6], [6], [38], [-12], [64], [10], [-60], [-62], [-48], [-46], [74], [-14], [60], [-16], [-18], [-64], [8], [-12], [-84], [-60], [20], [-42], [-90], [-18], [-50], [-46], [36], [36], [-34], [-56], [-42], [34], [-76], [-32], [-18], [-42], [-30], [34], [68], [34], [8], [36], [56], [-62], [46], [-96], [22], [-42], [34], [-68], [-32], [88], [16], [-42], [100], [12], [62], [6], [-6], [-38], [-24], [72], [-44], [20], [22], [42], [-22], [90], [12], [32], [-36], [-12], [30], [32], [42], [-8], [-22], [92], [-36], [-30], [-26], [34], [-84], [-104], [20], [-22], [94], [-4], [-28], [-48], [18], [18], [-82], [10], [-8], [-12], [4], [34], [10], [16], [-14], [26], [52], [92], [30], [38], [-60], [76], [60], [-72], [-36], [-80], [54], [-2], [40], [-26], [4], [76], [-20], [58], [20], [-34], [-12], [-100], [-46], [-40], [56], [36], [54], [-18], [-102], [12], [-76], [0], [-24], [-10], [-34], [-14], [72]];
    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_n();".
// 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_n(:prec:=1)
    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_n();".
// 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_n( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_8280_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<7,R![2, 1]>,<11,R![0, 1]>,<13,R![2, 1]>,<17,R![-6, 1]>],Snew);
    return Vf;
end function;