
// Make newform 2592.2.a.h in Magma, downloaded from the LMFDB on 17 December 2025.
// 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_h();".
// 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_h();".
// 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 := 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]];
    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], [4], [2], [5], [-2], [-3], [-1], [6], [-2], [4], [-8], [1], [7], [-2], [-4], [-5], [0], [13], [-8], [3], [-8], [-12], [-10], [-11], [12], [-6], [-5], [8], [-2], [-2], [-16], [-3], [13], [-18], [18], [20], [20], [16], [18], [-12], [2], [6], [-3], [4], [-2], [-28], [14], [-3], [14], [-21], [-6], [-23], [21], [-5], [-6], [0], [12], [-14], [-18], [28], [30], [9], [-18], [13], [18], [4], [-25], [1], [16], [35], [14], [0], [-22], [-1], [-20], [-6], [-32], [5], [25], [-4], [8], [-30], [1], [8], [27], [-31], [-7], [-18], [16], [-7], [-18], [-22], [-7], [-21], [-24], [24], [-3], [12], [-32], [-33], [10], [-15], [-11], [-13], [3], [-9], [6], [40], [19], [-20], [12], [-45], [-21], [28], [5], [15], [-6], [-22], [12], [32], [2], [-28], [15], [8], [42], [-20], [-32], [30], [-34], [-49], [6], [52], [18], [-30], [10], [-42], [36], [24], [17], [-55], [-50], [-28], [-28], [14], [4], [30], [-10], [-5], [28], [40], [30], [13], [-36], [-7], [24], [-54], [-6], [-58], [-28], [27], [-39], [42], [20], [-11], [-36], [16], [60], [-38], [-40], [-27], [60], [44], [19], [-34], [14], [55], [30], [32], [52], [46], [-1], [-14], [19], [-18], [32], [0], [40], [-43], [-48], [31], [-55], [43], [-28], [-47], [51], [31], [52], [-41], [10], [18], [-62], [8], [3], [5], [-6], [44], [37], [35], [49], [29], [18], [30], [12], [-56], [9], [-44], [-43], [62], [-48], [-46], [4], [21], [62], [3], [-22], [-54], [72], [62], [-40], [-14], [-20], [26], [-57], [16], [2], [26], [-66], [39], [2], [51], [36], [72], [-6], [-49], [8], [-28], [45], [-28], [-2], [42], [43], [-12], [-6], [-14], [-15], [-72], [-4], [36], [13], [56], [57], [-4], [-2], [30], [-55], [-28], [-5], [-23], [18], [20], [44], [-61], [-6], [-17], [-12], [68], [-58], [55], [-59], [-42], [-14], [10], [-42], [23], [-30], [-38], [-44], [-28], [-49], [36], [-33], [27], [67], [36], [30], [14], [6], [-84], [4], [1], [58], [28], [44], [-40], [-38], [12], [60], [-78], [-52], [24], [-52], [-86], [32], [-72], [43], [9], [-40], [-29], [-18], [27], [53], [-8], [-22], [-6], [-47], [-81], [39], [20], [38], [28], [-8], [-92], [13], [-25], [-28], [30], [71], [23], [-48], [-52], [38], [56], [-52], [34], [63], [84], [-23], [52], [22], [4], [65], [2], [60], [0], [54], [84], [84], [58], [-46], [-38], [39], [68], [29], [53], [-17], [-84], [38], [-11], [36], [-85], [36], [12], [62], [26], [87], [2], [14], [-27], [42], [30], [1], [20], [-21], [-23], [92], [-90], [-52], [16], [32], [-25], [-28], [-15], [79], [86], [54], [16], [-51], [17], [52], [82], [33], [-8], [-54], [-10], [20], [14], [13], [-45], [76], [103], [58], [39], [57], [-2], [2], [-46], [2], [-67], [52], [16], [-28], [16], [51], [2], [4], [-87], [-38], [-20], [-60]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2592_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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