
// Make newform 1288.2.a.l in Magma, downloaded from the LMFDB on 19 April 2024.
// 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_l();".
// 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_l();".
// 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 := [1, -3, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-2, -1, 1]];
    Rf_basisdens := [1, 1, 1];
    Rf_basisnums := ChangeUniverse([[z : z in elt] : elt in Rf_num], Kf);
    Rfbasis := [Rf_basisnums[i]/Rf_basisdens[i] : i in [1..Degree(Kf)]];
    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)
    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+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, 0], [0, 0, -1], [2, -2, -1], [-1, 0, 0], [-1, -1, 1], [0, -2, 0], [4, 2, -1], [0, 0, 0], [1, 0, 0], [3, 1, 1], [2, 4, -1], [8, -2, 0], [2, -4, -4], [-2, -2, -4], [0, 2, -1], [-6, 4, 4], [-6, -2, 3], [0, 4, 7], [-1, -5, 1], [0, 0, 4], [2, 0, 6], [5, -3, -1], [-2, -2, 0], [6, 0, 5], [2, 2, 9], [2, 4, 2], [0, -4, 0], [2, 2, 8], [-2, 4, -6], [-2, 0, -4], [-6, 2, 0], [6, 4, 5], [-4, 6, 0], [2, -2, 3], [6, -4, -8], [2, -10, -4], [-2, 0, -1], [2, -10, 2], [2, 4, 11], [14, 4, 0], [-2, 2, -4], [-4, -6, -9], [-6, 6, 0], [6, 4, -2], [-6, 4, -4], [4, 4, 0], [-18, 6, 0], [6, 2, -3], [10, 2, -2], [-6, 12, 5], [-1, 5, 1], [6, -6, 0], [-4, 2, -5], [-8, 12, 8], [-2, -4, 4], [7, 11, 1], [2, -4, -4], [2, -10, -13], [-7, -5, 7], [2, 0, -10], [-10, 6, -6], [-4, 4, 9], [-20, 2, 5], [-2, 10, 1], [6, -16, -11], [-3, -9, -13], [-16, 4, 6], [18, 4, 6], [22, -14, -8], [-12, 10, -2], [16, -2, 8], [-5, -1, 1], [26, 2, 0], [6, 12, 0], [-9, 11, -7], [6, 6, -12], [14, -4, -10], [8, -6, 8], [2, 8, 6], [-4, -2, -4], [8, -20, -8], [-18, 16, 4], [0, -8, 4], [-20, 8, -1], [20, -12, -9], [2, 10, 2], [-15, -1, -5], [0, 10, 10], [18, -12, 4], [-16, -8, -2], [0, 8, -4], [18, -18, -10], [12, 8, 12], [4, -12, -4], [0, 8, 10], [18, 2, -6], [-12, 2, 2], [14, -2, 1], [-14, 6, -10], [5, -9, 3], [-18, 2, 0], [6, 12, 8], [26, -2, -6], [8, 10, 4], [-14, 2, -12], [-12, 18, 16], [26, -2, -1], [-4, 2, 6], [10, 10, 8], [-20, -6, -4], [0, 10, -1], [6, 16, -6], [0, -6, 4], [-2, 10, 8], [13, 1, 15], [0, 10, -20], [2, 2, 18], [36, 2, 1], [2, -20, -8], [4, 0, 0], [-14, 2, -3], [-5, 13, 13], [4, 0, -5], [-14, 14, -6], [0, -2, -7], [8, 10, -12], [26, 0, 2], [-12, 2, 13], [-4, -8, 4], [-2, -14, 7], [-12, 24, 12], [9, -19, -9], [-9, -13, 5], [20, 2, 20], [18, -12, -18], [22, 0, -15], [-16, 22, 5], [-4, 8, -18], [4, -22, 11], [-18, -4, -2], [-26, -4, -3], [-13, -15, 1], [-14, 26, 2], [0, -20, 12], [16, -6, -6], [-18, 10, 8], [-24, 6, -4], [-14, 20, 4], [28, 12, -7], [-16, -4, -28], [11, -15, -7], [-14, 4, -5], [-6, 2, -4], [-8, 8, -1], [40, -4, -4], [-31, 25, 15], [7, -5, -19], [2, -28, 4], [-20, 2, 13], [-14, 28, 17], [8, -16, 6], [-16, 2, 2], [-18, 18, 6], [-24, 8, 6], [30, 0, -10], [-30, -6, 12], [0, -4, -20], [10, 0, -8], [-20, -10, -18], [18, 12, -6], [38, -26, -12], [24, 2, 22], [-12, -12, 16], [-2, -24, 6], [-46, 0, 1], [-6, 20, -3], [-20, -8, 8], [-26, 8, 12], [6, -6, 22], [12, -4, -7], [22, -10, -16], [34, 2, -2], [2, -12, 6], [-34, 32, 14], [6, -14, -28], [-28, 4, 17], [3, 13, -7], [-20, 8, -10], [5, 3, 27], [-2, -22, -21], [32, 10, 6], [-12, -20, -8], [-8, -12, -24], [28, 6, 20], [-19, -7, 11], [-36, 12, 9], [34, 4, -6], [28, -2, 4], [12, -24, -13], [22, -6, -13], [-10, 20, 16], [-4, 18, -7], [-34, -8, -4], [2, -6, 5], [-6, 22, 18], [-14, 12, 12], [-18, -18, -12], [-14, 10, -20], [-11, 15, -1], [-28, -2, -1], [15, -15, 1], [10, -32, 2], [25, 1, -9], [24, -28, -16], [4, -6, 1], [12, -22, -21], [6, 18, 4], [10, -24, 2], [-6, 14, -8], [10, -4, -8], [-22, -4, 14], [14, -22, 2], [10, -24, 2], [2, 14, 8], [42, -2, 3], [5, 3, -17], [0, -24, -15], [-22, -2, -12], [16, -20, 14], [0, 16, 12], [-2, 0, -16], [-22, -6, -18], [-1, 15, 13], [-25, 17, 1], [-18, 22, 2], [26, -2, -8], [54, -8, 5], [-16, 2, 6], [0, 28, 10], [-2, -16, 19], [46, 14, -12], [-50, 12, 5], [-22, 0, -15], [18, -4, 28], [50, 0, 4], [-26, -4, 9], [-36, -4, 9], [22, 14, -16], [-12, -24, 12], [32, -16, -8], [4, 10, -14], [-20, -4, 17], [41, 1, -1], [14, 24, -13], [-50, 8, 6], [10, 14, 24], [-4, -14, 28], [0, -16, 20], [4, 10, -26], [10, 8, -6], [29, -15, 3], [12, 8, 4], [-12, 14, 10], [24, 12, 31], [14, -16, -8], [28, -4, -24], [-44, -2, 14], [-4, -20, 13], [25, 1, -1], [42, -12, -4], [-30, 0, -12], [-7, 9, 11], [52, -14, -9], [-7, 25, -21], [-60, -10, 0], [32, -22, -1], [0, 28, 16], [-29, 37, 25], [18, -4, 16], [-26, -6, 2], [-20, 4, -21], [34, -42, -12], [42, 14, 16], [-6, 36, -1], [12, 12, -5], [-48, 0, -18], [26, -4, -8], [10, 8, -32], [16, -16, -11], [54, -24, -14], [-2, 24, -20], [-22, -18, -26], [-7, -5, -25], [12, -8, 26], [38, 0, 24], [8, 14, -15], [18, 10, 2], [20, -22, -4], [30, -22, -9], [34, 6, 5], [-38, 28, -1], [-32, 10, 16], [32, -40, -4], [-24, 8, 10], [-20, 32, 4], [-30, -8, -38], [-38, -10, 14], [26, 2, -23], [-16, -16, -12], [26, -20, -18], [-20, 22, 15], [20, -18, 20], [46, -16, 10], [-20, 36, -8], [25, -15, 15], [20, 28, -15], [-16, -8, -23], [16, 20, 36], [-38, -18, -9], [-2, 4, 14], [-22, -18, 20], [24, -22, -24], [26, 16, 22], [20, 4, -26], [-22, 4, -24], [-54, 30, 7], [-14, -6, 32], [12, -6, -23], [1, -19, -21], [50, -8, 10], [-31, 7, -1], [34, -12, 14], [14, 8, -1], [-14, 6, 33], [-3, -7, -21], [-8, 40, -13], [22, 8, 22], [10, -4, -15], [-28, -18, -2], [-6, 30, 16], [-37, 9, 25], [-52, 26, 4], [78, -12, -6], [0, 24, 12], [-42, -8, -38], [52, 12, -12], [-26, 4, 6], [-20, -12, 2], [-14, -10, -42], [-32, -10, -5], [-2, -16, -41], [2, 24, 26], [-39, -5, -1], [-24, 16, -10], [18, -8, -16], [52, -22, 0], [-10, 38, 0], [24, 4, 8], [31, -39, -23], [-8, 28, 0], [-24, 14, -10], [16, -10, -36], [44, -32, -20], [-35, -15, 11], [-10, 36, -15], [6, 28, -8], [28, -30, -4], [-37, 23, -3], [-6, -36, 16], [10, 38, -18], [-12, 20, 25], [-42, -14, 16], [-20, 14, -14], [-2, -2, 16], [-30, 52, 6], [-32, -2, 13], [50, -26, 4], [12, -16, -5], [-14, 10, 5], [12, -14, 38], [-20, -20, 1], [-8, -42, 26], [34, -22, -10], [18, 8, 24], [12, -28, -32], [28, 12, 23], [-8, 0, 0], [-70, -4, -4], [19, 15, 21], [16, -12, 14], [14, 12, 2], [40, -26, -22], [18, -6, -20], [2, -18, -29], [-3, -19, -25], [-30, 8, 18], [-14, 6, -4], [-14, -36, -9], [-26, 14, 16], [17, -5, 3], [-20, 26, 24], [7, 9, -15], [37, 25, 19], [-60, 34, 5], [6, 36, -26], [12, -12, -19], [48, -10, -10], [-22, -24, -24], [4, -28, 6], [-64, 34, 15], [-48, -6, -22], [-6, -20, -42], [-12, 24, 12], [52, 8, 12], [32, -50, -16], [18, -12, -20], [-30, 2, -4], [0, 18, 3], [-10, 22, -35], [4, 16, -28], [10, -32, 14], [-26, 16, -7], [26, 30, 28], [-8, 16, 7], [56, 2, -4], [-8, 26, -24], [49, 9, -9], [-18, 12, -10], [-10, 2, 7], [-16, 0, -47]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1288_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1288_2_a_l();".
// 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_l(:prec:=3)
    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_l();".
// 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_l( : 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, -4, 0, 1]>,<5,R![34, -8, -4, 1]>],Snew);
    return Vf;
end function;