
// Make newform 2280.2.a.p in Magma, downloaded from the LMFDB on 23 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_2280_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_2280_2_a_p();".
// 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_2280_2_a_p();".
// 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, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [-1, 2]];
    Rf_basisdens := [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_2280_a();"
function MakeCharacter_2280_a()
    N := 2280;
    order := 1;
    char_gens := [1711, 1141, 761, 457, 1921];
    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_2280_a_Hecke(Kf)
    return MakeCharacter_2280_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, 0], [-1, 0], [3, 1], [1, -1], [3, -1], [0, 2], [1, 0], [-2, 2], [3, -1], [0, -4], [1, 1], [-3, -3], [3, 1], [-2, 2], [4, -2], [-6, -2], [0, 2], [6, -2], [0, 0], [8, 2], [0, 0], [4, 0], [5, -3], [-7, 1], [0, -6], [14, -2], [0, -4], [0, -2], [-2, 0], [20, 0], [3, 5], [-2, 8], [-10, -2], [4, 6], [12, 0], [-8, -6], [5, 7], [-4, 8], [-22, 0], [-2, -6], [4, 2], [5, -5], [-1, 3], [-8, -2], [14, 2], [-12, 0], [18, 2], [0, 0], [-8, -6], [6, 8], [-5, -3], [-2, 4], [-3, 3], [-14, -4], [12, -4], [-1, 3], [2, -2], [-12, -2], [-13, -1], [1, -13], [-14, 8], [-22, 2], [13, 3], [-6, -8], [8, 2], [0, 0], [-31, 1], [-20, 0], [2, 4], [-6, -4], [-11, -5], [-27, -1], [-5, -1], [-16, 8], [8, -8], [6, 12], [-20, 6], [-21, -1], [0, 2], [-11, -5], [2, -12], [-6, 14], [3, -1], [8, 0], [6, 6], [-3, -3], [-10, 12], [-4, -2], [1, 11], [-18, 6], [-3, -5], [18, -6], [-17, -7], [2, -6], [-4, -4], [37, -3], [-33, 3], [8, -4], [6, -16], [-6, -14], [6, 12], [8, -8], [1, -15], [10, -14], [-18, 4], [2, -6], [-2, 0], [34, 6], [12, -10], [-38, 2], [-40, 2], [-8, -14], [10, 10], [16, 0], [-47, 1], [-7, 11], [-12, 12], [-36, 2], [4, 12], [-8, 14], [-3, -11], [20, -2], [-4, 16], [-30, 2], [-28, 6], [0, -14], [-1, 1], [5, 7], [-10, -12], [0, -4], [-36, -4], [0, 4], [6, -4], [-4, 6], [26, -8], [44, -2], [-16, 12], [2, 16], [30, 4], [-8, 4], [20, -2], [9, -5], [8, 0], [16, 14], [40, 0], [-2, 20], [20, 2], [-16, 12], [20, 12], [31, 3], [-24, -14], [1, 11], [-8, -8], [28, -8], [-8, -16], [-24, 0], [10, 8], [-24, -6], [3, -9], [4, 0], [34, 4], [-7, -5], [-12, -12], [44, -6], [4, 0], [20, 4], [-12, 6], [30, 12], [18, 8], [16, -8], [-6, 4], [21, 11], [2, 0], [-12, 4], [14, 12], [2, 10], [36, -10], [-30, -14], [-18, 16], [7, 5], [-4, 4], [7, -21], [-26, 16], [50, -2], [-32, -14], [-23, -7], [-20, 0], [-20, 14], [-17, -15], [15, 3], [18, 18], [12, 0], [35, -9], [46, -2], [10, -12], [20, -14], [6, 4], [12, -2], [-26, -6], [31, -5], [24, 16], [-45, -9], [-2, -12], [-9, -15], [-4, -6], [-28, 4], [12, 20], [-12, -10], [-12, 0], [-26, -4], [2, -8], [25, 3], [36, 12], [14, 2], [20, -18], [13, 7], [-5, -1], [-28, -16], [-36, 10], [-38, -4], [-32, -12], [25, 9], [15, -3], [-32, 8], [-34, -8], [-6, 28], [-14, 22], [28, 0], [-5, -3], [-26, 20], [-12, 20], [56, 0], [5, 13], [67, 1], [2, -10], [60, -6], [26, 0], [19, -11], [-2, -14], [-4, -24], [48, -12], [3, 25], [-28, -6], [16, -10], [-9, -15], [7, -19], [-22, 6], [20, 20], [44, -12], [14, -4], [-6, -8], [-20, 20], [0, -14], [-36, 10], [9, 15], [-32, 18], [36, 8], [48, 10], [-56, 10], [30, -10], [-16, -12], [-34, 8], [-53, -1], [28, -2], [0, 16], [-53, -1], [50, 0], [-8, -20], [4, -6], [18, 12], [2, -6], [-56, 2], [6, 34], [9, 25], [-23, 11], [12, 0], [56, -10], [-28, -18], [-9, -7], [-24, 24], [32, -16], [62, 2], [6, -24], [-9, -11], [9, -33], [30, 4], [48, -6], [-44, 4], [-31, -15], [40, -6], [40, 12], [28, 2], [-8, 0], [-5, 15], [22, -4], [24, 0], [16, 22], [-22, -26], [-21, -23], [-4, -18], [24, -6], [-16, -16], [-64, -8], [-2, 30], [29, -3], [52, 16], [-6, -4], [-3, 3], [6, -12], [-14, -10], [-70, 8], [-69, -1], [18, 10], [36, 4], [-22, 16], [55, 9], [20, -12], [-58, -4], [60, 6], [-24, -24], [-28, -2], [3, -17], [-40, -4], [-32, -22], [-34, -20], [-24, 4], [0, 28], [-8, 28], [-36, 18], [-26, 8], [20, -26], [-6, -2], [48, -4], [-2, 38], [36, 8], [-30, 4], [4, 18], [-8, 6], [-25, -27], [71, 3], [-46, 12], [9, 17], [12, -16], [8, 18], [20, 12], [-28, 22], [66, -6], [-38, 14], [42, -16], [4, -20], [-9, -5], [-30, -8], [26, 10], [44, 18], [-40, -2], [27, 29], [69, 11], [40, -6], [4, 4], [12, 6], [-56, -6], [68, 4], [-56, -8], [-59, -9], [11, 7], [-2, 36], [14, 6], [-24, -14], [15, -31], [12, -8], [36, -4], [13, -3], [44, 20], [-28, -2], [-10, -30], [7, 1], [30, -12], [-26, -20], [45, 5], [-27, 21], [-4, 6], [-47, 3], [38, 0], [4, -28], [-84, 0], [30, -14], [0, 2], [45, 7], [-64, -4], [-24, 34], [16, 26], [1, 31], [17, 3], [-26, -22], [67, -1], [-32, -12], [-85, -1], [-52, 4], [22, -20], [-46, -4], [-68, -2], [-40, -20], [-38, -12], [27, -1], [36, -20], [-12, 22], [-63, 9], [2, -14], [-47, 15], [25, 17], [56, -18], [56, -4], [-66, 14], [0, -6], [0, 26], [6, -14], [-32, 20], [6, -24], [16, 16], [-19, -19], [27, 31], [14, -22], [-34, -6], [-49, -5], [62, -4], [8, -20], [-82, -4], [-10, 6], [35, 13]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2280_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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