
// Make newform 1488.2.a.k in Magma, downloaded from the LMFDB on 15 April 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_k();".
// 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_k();".
// 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], [-1], [-1], [0], [-6], [0], [3], [-6], [0], [1], [-8], [-11], [8], [0], [4], [11], [-8], [-12], [7], [-4], [-10], [-14], [10], [1], [3], [1], [1], [7], [-1], [-12], [12], [6], [-4], [10], [4], [-17], [11], [-10], [18], [0], [8], [-3], [1], [-6], [4], [13], [-6], [-8], [-20], [-21], [-6], [0], [28], [-13], [-4], [-6], [-22], [30], [23], [-12], [30], [19], [27], [0], [-9], [10], [14], [26], [-34], [-22], [3], [34], [3], [-24], [-14], [18], [25], [28], [14], [-21], [13], [20], [6], [-19], [9], [-24], [-22], [-22], [-22], [39], [-31], [26], [26], [6], [7], [-28], [-38], [-18], [-33], [-1], [26], [-37], [-36], [26], [2], [-44], [-27], [1], [-8], [-24], [-14], [-30], [2], [2], [24], [-26], [-42], [-14], [-33], [-13], [40], [20], [-11], [37], [45], [-16], [26], [-43], [-35], [-32], [-24], [21], [-48], [-36], [29], [-8], [-22], [12], [-30], [-20], [42], [-4], [-6], [30], [16], [22], [-42], [-6], [-42], [-39], [-40], [-12], [41], [37], [-48], [32], [-6], [-54], [-54], [-4], [-28], [-6], [-12], [9], [-4], [-4], [-21], [6], [16], [-42], [-56], [32], [-7], [47], [26], [-37], [-7], [40], [-20], [57], [-50], [-33], [-28], [9], [-6], [-10], [35], [-32], [35], [32], [-9], [60], [62], [-20], [-10], [-10], [46], [37], [-33], [-21], [54], [-2], [-23], [0], [12], [31], [12], [-1], [-23], [42], [4], [16], [-21], [-16], [47], [-24], [-47], [54], [43], [30], [-5], [67], [45], [-27], [-44], [45], [-30], [-18], [68], [-12], [9], [49], [42], [32], [58], [-31], [10], [-54], [8], [-44], [0], [46], [34], [-36], [72], [-2], [-50], [-58], [-72], [11], [53], [48], [37], [-59], [52], [75], [-18], [13], [17], [12], [-36], [46], [29], [-50], [-37], [-57], [-6], [-52], [11], [-78], [-22], [28], [-38], [-67], [-11], [45], [32], [-52], [62], [81], [-61], [-33], [-17], [-57], [6], [-30], [-12], [-40], [-44], [29], [-19], [10], [12], [-84], [10], [82], [58], [72], [-68], [-82], [32], [-86], [80], [16], [-22], [-2], [55], [66], [-19], [-42], [-40], [31], [86], [5], [0], [-26], [30], [37], [50], [4], [-68], [-9], [11], [-18], [-92], [79], [73], [12], [16], [35], [29], [-1], [80], [-57], [-3], [-16], [-42], [25], [-86], [-64], [74], [-34], [64], [86], [91], [50], [28], [-90], [-45], [-44], [-64], [-27], [-24], [-65], [-42], [20], [16], [38], [29], [-7], [-2], [-2], [-69], [25], [4], [-27], [-26], [54], [16], [-56], [-80], [-25], [-35], [58], [-28], [31], [-17], [50], [-44], [-54], [-94], [10], [84], [-4], [-29], [19], [-8], [-34], [-12], [92], [-68], [-41], [72], [0], [70], [20], [15], [-68], [-28], [6], [99], [32], [1], [78], [-27], [-46], [90], [76], [-40], [-68], [-55], [98], [104], [-5], [85], [-72], [-47], [42], [-63], [-88], [58], [-48], [-33], [-93], [-78], [12], [78], [56], [4]];
    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_k();".
// 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_k(: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_k();".
// 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_k( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1488_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![1, 1]>,<7,R![1, 1]>],Snew);
    return Vf;
end function;