
// Make newform 2592.2.a.s in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_2592_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_2592_2_a_s();".
// 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_2592_2_a_s();".
// 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_2592_a();"
function MakeCharacter_2592_a()
    N := 2592;
    order := 1;
    char_gens := [2431, 325, 1217];
    v := [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_2592_a_Hecke(Kf)
    return MakeCharacter_2592_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], [1, -1], [1, 2], [0, -2], [4, 0], [3, 1], [-5, 2], [5, -1], [4, -2], [7, 2], [5, -3], [-1, 3], [-4, -2], [-7, -3], [-3, -2], [5, 3], [2, -4], [0, -2], [11, 1], [3, -1], [8, 2], [1, -2], [-3, -4], [15, -1], [-4, 4], [-4, 2], [1, -4], [8, 0], [1, 5], [15, -2], [-1, -1], [-9, 2], [3, 5], [-1, -4], [4, -4], [-7, 1], [-3, 0], [12, 0], [-4, 6], [15, -1], [9, -2], [-2, 8], [2, -4], [13, -1], [1, -7], [-15, 3], [-1, 0], [6, 0], [3, -7], [7, 0], [-12, -4], [1, 4], [-3, -1], [-12, 2], [0, 12], [-5, -4], [15, -2], [-1, -1], [9, -4], [-12, -4], [3, 5], [-17, 0], [-21, -2], [-1, 5], [-1, -4], [11, -7], [-5, -4], [-1, 6], [-8, 4], [3, -3], [17, 6], [-26, 0], [-31, 1], [-3, 4], [4, -6], [-1, 6], [7, 8], [19, 5], [5, -2], [-24, 4], [16, -10], [-29, -3], [-21, -1], [-16, 2], [-7, -10], [-21, -6], [-19, -5], [-20, -8], [-3, -9], [-8, -4], [-23, 5], [-9, 3], [30, 4], [-9, 10], [18, 0], [-6, 8], [10, 8], [-9, 1], [4, 6], [3, -3], [1, 0], [-11, 3], [-24, 2], [3, 11], [-24, -2], [-31, 1], [25, -6], [-1, 11], [-12, -6], [-9, -6], [-9, -7], [-16, 4], [-7, -8], [-3, 3], [0, -4], [17, 0], [-15, 3], [-1, -12], [-7, 14], [5, -12], [-12, 12], [-11, -11], [-12, 10], [-5, 0], [8, -16], [-21, 1], [-7, -2], [-14, 0], [33, 1], [-1, -17], [-42, 0], [-9, 14], [-17, -8], [12, 10], [-9, -5], [-33, -6], [8, 10], [28, -8], [19, -14], [13, -1], [28, 0], [-28, 2], [23, 3], [-3, -2], [23, 2], [-19, -1], [8, 4], [-23, -2], [0, 10], [20, 8], [3, 13], [13, 5], [-3, 19], [0, -4], [-33, -6], [32, 10], [-7, 0], [33, -5], [-48, 2], [-3, -5], [10, 0], [-23, 4], [-27, 3], [8, -12], [3, 12], [-32, -6], [47, -2], [-21, 3], [9, 6], [-5, -19], [25, 14], [31, -5], [17, 4], [-19, -11], [12, -2], [16, 16], [19, -12], [-7, -7], [-29, -5], [31, 0], [16, -10], [33, 5], [35, -2], [30, 0], [53, -3], [-25, 12], [48, 0], [16, -10], [1, -1], [20, -12], [-43, -4], [-28, 0], [9, -20], [-23, 14], [-29, -4], [-23, 4], [-40, 0], [33, 4], [41, -3], [-1, 4], [15, -12], [28, -8], [-36, 2], [16, -12], [17, 1], [-7, -8], [47, 7], [32, 2], [15, 22], [33, -3], [-15, 3], [-7, -7], [-9, -12], [5, -9], [-1, 14], [16, 12], [-9, -18], [-55, -6], [-49, 3], [-9, -2], [40, 12], [57, 5], [11, 12], [-39, 8], [24, 4], [-5, -3], [-23, -17], [55, -4], [20, 20], [13, 23], [9, 8], [-1, 17], [7, -9], [17, -6], [36, 10], [33, 13], [-32, 0], [3, 11], [12, -16], [39, 3], [12, 2], [-1, 30], [7, -25], [40, -8], [-21, 1], [-35, -13], [8, 4], [-15, 2], [40, 2], [-21, -7], [-33, -8], [37, -8], [18, -8], [-36, -6], [31, 5], [-18, -8], [-8, 26], [-29, -15], [3, 15], [23, -12], [-20, -2], [-9, -6], [7, -7], [20, 18], [25, -20], [29, 3], [-9, -14], [-31, 6], [-44, 8], [-1, 0], [-33, 7], [-23, 6], [24, -16], [25, 17], [-19, 6], [16, 14], [-7, 11], [-15, 17], [-1, -13], [5, -5], [27, -24], [7, -9], [-54, 4], [-32, 14], [1, -12], [-23, -15], [14, 0], [27, 2], [-30, 8], [-39, -8], [-13, 1], [27, 24], [-39, 4], [-5, 9], [3, 6], [-12, -4], [-19, 13], [-41, 12], [28, -6], [-64, -8], [25, 1], [7, 23], [-8, -10], [33, -5], [-57, -8], [9, 9], [-28, 6], [-33, -1], [-28, 10], [-23, -16], [-11, -17], [0, 12], [-56, -6], [33, -17], [19, 1], [7, 4], [39, -6], [39, 13], [-1, 24], [-68, 6], [-8, -4], [-9, 10], [34, -16], [-18, -8], [39, -15], [31, -1], [-4, -14], [-77, 0], [-71, 4], [-55, 13], [-13, -5], [-20, 0], [28, 20], [-6, -24], [-1, 10], [-7, 10], [-6, -12], [5, -2], [17, 20], [-55, 4], [1, 17], [-5, -14], [-30, -8], [-12, 6], [5, -23], [29, 19], [10, -32], [-19, 23], [-16, -14], [23, -10], [3, -3], [9, 26], [66, 0], [51, 5], [36, 20], [25, -8], [13, 23], [-11, -2], [33, 8], [22, -20], [1, 15], [28, 20], [-47, -10], [-45, 14], [-50, -12], [16, -2], [9, -5], [-44, 4], [-15, -31], [-21, -6], [55, -13], [-4, -10], [-21, -11], [22, -4], [56, 18], [24, -22], [-15, 22], [-75, 0], [-23, -8], [-56, -4], [15, 6], [-25, 27], [-8, -24], [9, 1], [-25, 8], [44, -8], [1, -23], [-7, 22], [-13, 6], [-42, -8], [29, 25], [7, 7], [33, 6], [-10, -4], [-9, 10], [-41, 23], [-41, -6], [31, 16], [24, -22], [-19, -9], [39, 10], [-70, 0], [-2, -28], [35, -16], [49, 8], [21, -1], [35, -21], [-23, -14], [13, 4], [6, 40], [-33, 25], [1, 2], [44, 14], [-80, -4], [19, 13], [32, -10], [-31, 9], [-35, 24], [-4, 26], [23, -29], [33, 21], [8, 14], [-17, -22], [-69, 11], [-32, 10], [68, 12], [-3, 3]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2592_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_2592_2_a_s();".
// 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_2592_2_a_s(:prec:=2)
    chi := MakeCharacter_2592_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_2592_2_a_s();".
// 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_2592_2_a_s( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2592_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![-1, 1]>,<7,R![-5, -2, 1]>,<11,R![-5, -2, 1]>],Snew);
    return Vf;
end function;