
// Make newform 2592.2.a.c in Magma, downloaded from the LMFDB on 20 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_c();".
// 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_c();".
// 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_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], [-1], [-2], [2], [1], [-3], [-2], [6], [-1], [8], [1], [2], [-10], [4], [10], [4], [9], [14], [10], [-9], [-10], [12], [-11], [-2], [6], [12], [16], [5], [17], [2], [14], [9], [20], [-21], [-12], [17], [4], [-2], [-21], [0], [14], [18], [-9], [11], [-16], [-2], [-2], [6], [-7], [-15], [12], [-5], [-18], [29], [-12], [15], [6], [-2], [9], [-16], [-21], [0], [0], [7], [3], [14], [14], [10], [34], [-2], [-34], [24], [-10], [-8], [-14], [18], [13], [25], [-29], [-40], [-7], [12], [19], [28], [12], [-14], [-37], [-30], [-28], [-28], [-42], [16], [-34], [-6], [0], [18], [18], [30], [13], [12], [11], [36], [5], [-20], [27], [-30], [-15], [-32], [-17], [-22], [6], [-15], [48], [20], [-35], [-36], [6], [34], [-30], [-31], [23], [34], [-36], [10], [-45], [1], [-14], [-6], [14], [-8], [-24], [-22], [-42], [-39], [31], [-9], [-18], [39], [37], [16], [23], [-8], [-22], [38], [22], [-42], [13], [44], [46], [-35], [42], [20], [54], [-8], [-30], [-42], [-27], [-25], [43], [54], [21], [18], [38], [2], [24], [38], [-15], [43], [-14], [-24], [21], [-4], [-5], [58], [-38], [-58], [-45], [52], [-59], [-28], [38], [-59], [26], [36], [-5], [45], [14], [26], [30], [-5], [56], [-22], [55], [22], [-42], [55], [22], [-7], [34], [63], [-22], [-22], [15], [14], [-54], [-50], [28], [10], [26], [14], [15], [-42], [-6], [64], [-42], [38], [-23], [44], [15], [5], [50], [57], [4], [24], [5], [18], [-66], [-44], [-4], [-47], [-46], [10], [-15], [-64], [68], [-13], [54], [-24], [38], [30], [6], [-36], [-42], [-14], [-34], [-2], [54], [28], [16], [57], [-7], [-12], [15], [-73], [-18], [9], [58], [-57], [-2], [-32], [0], [41], [34], [-18], [16], [19], [17], [-16], [27], [-31], [58], [-58], [24], [-65], [36], [-16], [17], [-17], [4], [60], [-40], [-56], [33], [4], [24], [31], [-22], [46], [13], [-54], [42], [-15], [-8], [-87], [-21], [64], [-57], [-18], [-28], [43], [62], [-34], [-46], [-56], [-26], [-18], [30], [-24], [-19], [6], [58], [-31], [-74], [-12], [-50], [-60], [-16], [-29], [66], [84], [-58], [-49], [88], [66], [-29], [-78], [42], [-22], [34], [-26], [-37], [-16], [34], [34], [-28], [-15], [37], [-58], [12], [5], [-38], [19], [-32], [71], [-78], [93], [56], [-80], [23], [-94], [-25], [-53], [42], [-15], [-75], [-36], [-18], [-22], [2], [85], [-75], [-34], [-28], [-92], [79], [-78], [88], [-38], [-30], [-38], [48], [-21], [-68], [65], [30], [-76], [23], [-18], [-81], [87], [41], [28], [9], [14], [62], [-72], [-19], [74], [-64], [-85], [-53], [-78], [2], [92], [39], [-94], [-27], [-38], [23], [1], [-102], [-70], [93], [31], [-38], [-91], [-79], [-6], [-32], [7], [-25], [78], [36], [-5], [43], [32], [64], [1], [52], [62], [26], [-68], [-48], [23], [-37], [48], [-43], [-16], [-60]];
    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_c();".
// 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_c(:prec:=1)
    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_c();".
// 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_c( : 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![2, 1]>,<11,R![-2, 1]>],Snew);
    return Vf;
end function;