
// Make newform 8280.2.a.k in Magma, downloaded from the LMFDB on 24 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_k();".
// 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_k();".
// 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], [-4], [2], [2], [-8], [-1], [4], [8], [8], [4], [-10], [-8], [-6], [-10], [10], [2], [-2], [2], [16], [12], [-10], [-8], [-12], [-14], [-12], [2], [-2], [4], [-2], [-6], [-20], [2], [16], [4], [-16], [-16], [6], [-10], [-6], [12], [6], [-18], [16], [-28], [8], [-12], [14], [-18], [22], [2], [28], [18], [0], [-8], [-16], [-26], [-26], [14], [6], [8], [-2], [8], [10], [-12], [8], [-28], [6], [-34], [0], [-6], [-4], [-8], [-16], [-34], [14], [18], [-26], [0], [30], [8], [28], [-32], [-12], [-24], [8], [-24], [-20], [12], [-4], [-4], [-42], [-20], [0], [-44], [22], [-26], [2], [-40], [30], [12], [-30], [4], [14], [8], [34], [46], [-30], [12], [44], [-10], [-20], [-8], [-6], [-2], [16], [-14], [48], [10], [2], [-6], [-24], [-20], [18], [-10], [-50], [-14], [-40], [20], [-48], [-4], [44], [20], [-34], [-18], [46], [30], [40], [-20], [8], [24], [52], [-14], [12], [-26], [-10], [-36], [52], [-38], [22], [-8], [-36], [38], [28], [-4], [-24], [-24], [-46], [-32], [14], [32], [28], [10], [-24], [16], [10], [34], [-42], [-24], [2], [-48], [-4], [16], [-30], [-44], [60], [-46], [-10], [20], [36], [62], [-46], [-48], [54], [42], [-6], [58], [-14], [14], [8], [-48], [-24], [68], [-38], [38], [-12], [18], [24], [30], [32], [54], [-22], [16], [46], [-40], [64], [20], [-44], [18], [32], [26], [60], [54], [22], [-20], [52], [-24], [50], [22], [24], [-24], [66], [52], [-30], [22], [54], [-34], [-18], [-74], [-32], [-32], [-48], [-74], [32], [-10], [-74], [14], [-6], [-52], [44], [56], [2], [-18], [42], [28], [60], [16], [-24], [-36], [26], [8], [-50], [66], [6], [2], [22], [-6], [62], [34], [-52], [-30], [-44], [42], [36], [-2], [-38], [-38], [26], [14], [2], [60], [-24], [50], [-28], [-24], [-46], [-58], [20], [-56], [68], [8], [-26], [36], [22], [-20], [-58], [-24], [-36], [-30], [-28], [54], [32], [-14], [50], [-44], [54], [46], [16], [-88], [18], [-24], [-12], [-88], [62], [-40], [-26], [-16], [62], [68], [70], [46], [-24], [-40], [-22], [66], [18], [84], [-48], [32], [8], [48], [-8], [54], [-62], [-36], [-48], [24], [6], [10], [58], [16], [36], [-68], [80], [22], [14], [-10], [14], [-26], [58], [-12], [76], [-10], [-2], [38], [68], [-24], [22], [-28], [-78], [-12], [70], [2], [-50], [36], [-4], [-22], [0], [-32], [-28], [-12], [24], [60], [62], [-30], [34], [14], [-62], [-76], [12], [58], [-56], [-94], [-46], [-20], [92], [62], [-98], [54], [6], [-48], [-18], [80], [60], [96], [-74], [6], [8], [-58], [2], [98], [20], [-48], [-44], [-32], [-18], [-20], [-72], [-2], [66], [-82], [-50], [76], [0], [76], [-4], [-10], [-30], [-22], [94], [-84], [-8], [-104], [-56], [-38], [60], [-82], [24], [-66], [44], [68], [-54], [-26], [-58], [-68], [-40], [-20], [46], [94], [-32], [76], [-16], [-26], [106], [-66], [10], [-64], [60], [-12], [-78], [-62], [-72], [98], [-74], [4], [100], [-82], [22], [76], [-20], [-36], [-32], [40], [60], [-18], [30], [-64], [58], [-20], [52], [64], [-62], [-44], [-2], [-68], [-108], [-70], [0], [-108], [68], [-62], [30], [-30], [20], [48], [32], [-24], [-54], [-10], [-22], [-12]];
    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_k();".
// 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_k(: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_k();".
// 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_k( : 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![4, 1]>,<13,R![-2, 1]>,<17,R![-2, 1]>],Snew);
    return Vf;
end function;