
// Make newform 1488.2.a.g in Magma, downloaded from the LMFDB on 12 March 2026.
// To make the character of type GrpDrchElt, type "MakeCharacter_1488_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_1488_2_a_g();".
// 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_1488_2_a_g();".
// 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_1488_a();"
function MakeCharacter_1488_a()
    N := 1488;
    order := 1;
    char_gens := [559, 373, 497, 1057];
    v := [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_1488_a_Hecke( : Kf := Kf)
    return MakeCharacter_1488_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], [-1], [3], [1], [0], [2], [0], [1], [6], [0], [-1], [8], [-3], [-8], [0], [-12], [9], [8], [4], [9], [-4], [10], [6], [-6], [-7], [15], [7], [3], [11], [15], [-20], [12], [6], [4], [-6], [-20], [-13], [1], [-6], [18], [0], [8], [3], [17], [18], [-20], [-17], [-26], [0], [-4], [3], [6], [-16], [-12], [27], [-12], [-30], [-26], [-10], [-9], [4], [-18], [25], [-27], [-16], [3], [-2], [14], [30], [14], [-6], [-27], [-2], [-25], [-32], [-18], [-6], [29], [12], [-34], [33], [17], [12], [38], [19], [3], [-24], [26], [-30], [-26], [-27], [39], [22], [-18], [-14], [-39], [-12], [-6], [-38], [-13], [13], [18], [9], [12], [-2], [2], [-36], [21], [39], [8], [-8], [26], [-30], [22], [-2], [-24], [-14], [-6], [-30], [21], [-25], [8], [36], [15], [-17], [-39], [-16], [6], [19], [-31], [16], [-24], [19], [-16], [12], [5], [24], [-2], [12], [-30], [-20], [18], [4], [30], [-10], [0], [38], [54], [46], [42], [-19], [24], [28], [15], [-17], [-48], [16], [42], [-22], [-30], [-12], [-60], [22], [-12], [33], [-12], [4], [-1], [38], [0], [-30], [-40], [-48], [-55], [-23], [42], [1], [45], [40], [44], [7], [-6], [59], [36], [39], [-30], [-58], [49], [-16], [-27], [-16], [-27], [4], [6], [60], [6], [-58], [-34], [-3], [-39], [-9], [58], [14], [65], [-24], [60], [-23], [-60], [-9], [-53], [-22], [-60], [16], [-39], [0], [47], [40], [-63], [42], [-57], [38], [13], [-45], [-29], [-57], [20], [-51], [30], [34], [36], [-28], [43], [-41], [-6], [64], [-42], [17], [-54], [-18], [24], [36], [16], [34], [-70], [12], [24], [-14], [-6], [-14], [24], [23], [69], [0], [5], [9], [-60], [-25], [10], [33], [-7], [4], [36], [-10], [17], [30], [1], [75], [-6], [-68], [-81], [-46], [-2], [44], [-74], [5], [19], [-57], [80], [-52], [42], [63], [-59], [33], [11], [13], [42], [-46], [36], [-56], [84], [33], [39], [42], [60], [44], [-30], [-50], [42], [72], [52], [14], [48], [70], [24], [16], [74], [42], [35], [30], [-31], [-6], [-24], [87], [34], [-69], [-16], [-30], [18], [-19], [66], [-68], [-4], [51], [61], [-18], [20], [-83], [91], [36], [0], [-73], [57], [1], [48], [61], [-81], [-16], [-42], [-31], [70], [-64], [-6], [-42], [-32], [6], [9], [2], [-44], [-6], [-57], [76], [-16], [33], [-8], [83], [54], [-36], [96], [-42], [-69], [-19], [-18], [-78], [-39], [67], [-28], [9], [-38], [-10], [24], [16], [-96], [51], [19], [2], [60], [57], [95], [-78], [20], [66], [-78], [-26], [36], [-44], [-51], [-35], [-88], [10], [12], [44], [-36], [-75], [16], [-96], [38], [-68], [15], [4], [-60], [14], [-69], [-32], [9], [6], [43], [50], [42], [4], [24], [44], [45], [6], [-56], [-61], [-63], [24], [-17], [42], [-81], [72], [2], [96], [-3], [11], [-6], [60], [-66], [88], [-36]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1488_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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