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