
// Make newform 1288.2.a.k in Magma, downloaded from the LMFDB on 22 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_1288_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_1288_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_1288_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
        poly := [-2, 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_1288_a();"
function MakeCharacter_1288_a()
    N := 1288;
    order := 1;
    char_gens := [967, 645, 185, 281];
    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_1288_a_Hecke( : Kf := Kf)
    return MakeCharacter_1288_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], [0, 1], [-2, -1], [-1, 0], [2, 0], [0, 2], [4, 1], [2, 0], [-1, 0], [0, 6], [2, -1], [2, -6], [6, 0], [8, 0], [6, 1], [2, 2], [8, -5], [-6, -3], [6, 4], [-4, 6], [2, 6], [2, -6], [2, -2], [8, 5], [0, -11], [8, -2], [8, -4], [4, -4], [-6, -8], [-14, -2], [0, 2], [8, -3], [2, -6], [-4, 11], [6, -8], [-16, -6], [2, 3], [8, 2], [-6, -9], [4, -4], [16, 4], [-2, 13], [0, -4], [-22, 4], [6, 4], [0, 16], [0, 4], [10, 5], [14, 0], [-18, 5], [12, -12], [-8, 14], [-4, -7], [-6, 12], [-2, 12], [-10, 6], [4, 0], [-2, -5], [-16, -6], [-2, 2], [2, -20], [6, -9], [-12, -1], [-6, 5], [20, 1], [16, -6], [20, -6], [-10, 8], [8, -2], [28, -4], [-2, -6], [14, 6], [-8, -10], [-2, 24], [2, -20], [-4, -18], [2, 0], [0, -6], [-26, -8], [22, 2], [-26, -4], [-6, -10], [-16, -16], [0, -3], [2, 21], [0, 16], [0, -24], [-10, -14], [0, 4], [8, 20], [30, 4], [28, -4], [0, 4], [4, -12], [20, -16], [20, 16], [-8, 4], [8, -15], [2, 4], [32, 10], [8, 2], [22, -4], [2, 4], [-6, -12], [-8, -12], [2, -6], [-12, -1], [14, -16], [-28, 8], [18, -2], [-14, -7], [-14, 8], [-14, -12], [14, 18], [-14, 2], [18, 4], [6, 4], [18, -1], [18, 16], [8, 20], [10, -15], [12, 0], [-18, 13], [-16, -8], [20, 19], [-30, 10], [-26, 2], [26, 15], [-20, -4], [-18, 11], [-12, -18], [10, -6], [-34, -2], [6, 4], [-2, -26], [-36, -7], [6, -13], [-14, -6], [22, 5], [-14, 4], [-24, -15], [-20, 6], [-8, -18], [28, -4], [-20, -16], [8, -22], [-12, -18], [10, 8], [12, 15], [-4, -22], [-8, -14], [4, -13], [0, -28], [-10, -15], [-12, -12], [18, 10], [14, -6], [-14, 12], [20, 15], [-14, -3], [12, -10], [-26, -8], [-4, 20], [-46, 6], [46, 2], [0, 14], [4, -14], [-20, 8], [-2, 18], [20, 2], [36, 0], [-56, 4], [0, 8], [6, 2], [6, 25], [-8, -31], [52, -4], [-14, 16], [-32, 8], [14, -5], [8, -18], [-6, 12], [-10, 28], [-2, -6], [24, 20], [10, -29], [-4, 2], [54, -2], [-48, 4], [-14, -5], [-22, 12], [-20, -8], [-20, -8], [-48, 6], [42, 8], [-32, 3], [-50, 4], [-10, 16], [4, -15], [14, 7], [-38, 6], [10, -25], [-8, -4], [-44, 5], [-22, 28], [24, -12], [32, -26], [24, 2], [12, 8], [-12, 25], [-8, -4], [12, 6], [-6, -14], [-6, -4], [-26, 27], [-60, -3], [44, 16], [-46, -18], [8, -40], [-46, 4], [-18, 12], [-8, -12], [-26, 24], [24, 4], [-24, -13], [28, -18], [-8, 39], [-32, -14], [-36, -6], [-36, -10], [-30, 8], [-2, 40], [14, 18], [-4, -28], [-2, 4], [24, 30], [-12, -39], [22, 10], [12, 8], [-10, -45], [-8, -40], [0, -39], [-22, -27], [-2, -36], [6, 12], [14, -23], [14, 11], [-26, 2], [0, -40], [64, 0], [22, -18], [16, 23], [42, -18], [-12, 35], [20, 6], [16, -24], [14, 40], [22, 12], [60, -8], [22, -14], [42, 22], [8, 4], [28, 20], [34, 21], [18, 32], [26, -4], [18, 40], [40, 23], [-38, 12], [-30, 16], [-40, -12], [6, 4], [-40, 13], [18, -14], [54, -2], [2, 17], [-52, -6], [-36, -22], [10, 26], [-22, -36], [-14, -39], [16, -4], [-32, 34], [6, -17], [-20, -11], [-68, 2], [-6, 40], [-2, -28], [42, -21], [54, -14], [-2, 24], [-50, 0], [-12, -40], [2, -34], [70, 4], [-78, 7], [0, -40], [4, -14], [-68, -1], [8, 29], [16, 19], [14, 36], [24, -4], [-20, -26], [48, 24], [14, 48], [0, 2], [42, 25], [-16, 20], [-14, -44], [58, 9], [14, -32], [14, -22], [-44, 30], [-46, -2], [-32, -21], [28, 19], [44, 6], [-24, -25], [14, 8], [-26, -6], [10, 30], [-56, 2], [64, 4], [18, -18], [12, 31], [0, 20], [-60, 19], [-54, 14], [-26, -22], [56, -6], [30, -16], [10, -25], [-56, 9], [42, 8], [-12, -11], [30, 34], [-40, 9], [-26, -48], [4, 22], [-20, -18], [34, 32], [4, 34], [-56, 16], [-14, -8], [-12, -22], [16, 10], [28, -2], [4, 40], [-6, 49], [16, -9], [78, 8], [-24, -46], [-4, 50], [6, -4], [30, 38], [24, -34], [-38, -8], [-52, 16], [32, -32], [-58, -2], [-6, -34], [-32, -20], [-46, -36], [-16, -31], [46, -16], [-4, -22], [22, 6], [50, -22], [16, -20], [4, -29], [-20, 0], [-22, 28], [-8, -22], [-6, 32], [-12, -1], [-40, -24], [-28, -31], [-40, 1], [34, -16], [-14, 47], [-10, 6], [-56, 26], [-6, 64], [-58, 12], [42, 1], [-20, 26], [0, -56], [-34, -8], [40, -18], [6, -36], [32, 12], [-32, 16], [-28, -21], [18, -46], [-26, -22], [24, -2], [8, 27], [-4, 16], [44, 14], [24, 14], [4, 0], [26, 22], [-56, 19], [12, 2], [-38, 47], [50, 16], [38, -4], [26, -38], [12, -19], [-10, 20], [14, -24], [-32, 24], [-36, -4], [10, -58], [68, -16], [-76, -12], [-2, 17], [32, -27], [-44, -28], [-2, -18], [-54, 1], [-84, 12], [40, 41], [-50, -26], [-4, -50], [-18, 64], [-26, 16], [28, -25], [18, -29]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1288_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1288_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_1288_2_a_k(:prec:=2)
    chi := MakeCharacter_1288_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_1288_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_1288_2_a_k( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1288_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![-2, 0, 1]>,<5,R![2, 4, 1]>],Snew);
    return Vf;
end function;