
// Make newform 1088.2.a.v in Magma, downloaded from the LMFDB on 20 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1088_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_1088_2_a_v();".
// 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_1088_2_a_v();".
// 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], [-2, 0, 1], [2, 2, -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_1088_a();"
function MakeCharacter_1088_a()
    N := 1088;
    order := 1;
    char_gens := [511, 69, 513];
    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_1088_a_Hecke(Kf)
    return MakeCharacter_1088_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], [1, -1, 0], [0, 1, 1], [-1, 0, 1], [3, 1, 0], [2, 1, -1], [1, 0, 0], [2, -2, 0], [-1, 0, -3], [4, -1, -1], [-3, -2, 1], [4, -1, -1], [2, 2, -2], [-2, 0, -2], [0, 2, 2], [2, -2, 2], [-2, 4, 2], [8, -5, -1], [-4, 4, 0], [-11, 2, 1], [6, -4, 0], [3, 4, -3], [2, 0, 2], [2, 1, 3], [-2, -4, 0], [-6, 1, -1], [0, 0, 0], [1, 5, 2], [4, 1, -3], [-2, 6, -2], [10, 0, -2], [5, -3, -2], [6, -7, -1], [5, 3, -4], [-6, -4, -4], [-2, -4, -2], [6, 0, 4], [3, -1, 2], [-11, 4, -1], [0, -5, -1], [6, -6, 0], [0, -5, -1], [-8, -2, -2], [10, -2, 2], [0, -3, -3], [5, -8, -1], [-5, 3, 2], [18, -10, -4], [-1, 3, -6], [-2, 1, 3], [-6, -2, -6], [-20, -2, 2], [-2, 2, 2], [0, 0, 0], [6, -1, 1], [-6, 4, 2], [-12, 9, 5], [-12, 6, 2], [4, 11, -5], [-10, 0, -4], [-5, -3, -4], [-14, 4, -4], [20, 2, -2], [-15, 0, -1], [-2, 2, 10], [16, 1, 1], [-10, 4, -6], [6, 0, 4], [-1, 7, 6], [-6, -2, 2], [6, 4, 0], [-6, -6, 8], [-13, -2, -1], [2, -7, 7], [1, -1, 0], [18, -4, 2], [-2, 5, 7], [20, -5, -5], [-10, -6, 2], [10, 0, 0], [-1, 1, 8], [34, 1, -1], [3, 8, 1], [10, -5, -7], [-3, 2, 9], [4, 0, -4], [-6, -8, 0], [-6, 3, 9], [-14, -2, -6], [20, -8, -4], [-10, -10, 4], [-19, -4, -5], [-21, -2, 7], [18, -2, -8], [-9, -9, 2], [23, 2, 7], [2, -8, 0], [10, -2, 10], [-16, -4, 4], [-16, 7, -5], [-7, -7, -2], [-6, -7, 7], [-6, -16, 2], [6, -16, -4], [31, -3, -4], [14, 5, -5], [-26, 2, 0], [-2, 4, -8], [-4, 4, -8], [18, 0, -8], [-7, -2, 5], [18, -8, -8], [2, 2, -2], [-9, -5, 2], [-6, 2, -8], [-10, 8, 12], [9, -17, 0], [4, 18, -2], [-8, 3, -1], [-8, -2, -10], [-2, -6, 10], [26, -4, -4], [4, -11, -7], [21, -1, 4], [15, 1, 4], [-6, -3, -5], [-8, -13, 7], [-11, -14, 1], [8, -2, -2], [-2, 6, 6], [30, -2, 4], [5, 2, 5], [-15, 6, 9], [22, -11, -1], [-26, -3, -5], [6, -7, 7], [-2, 1, 3], [13, 11, 4], [-18, -10, 6], [30, 8, -4], [1, -11, 6], [-4, 17, 5], [-21, 8, 1], [11, 3, -6], [6, 0, 4], [3, -8, -3], [0, -7, 9], [6, 2, 2], [22, 4, 10], [4, 4, 8], [-12, 5, -7], [-10, -16, 4], [20, -8, 4], [9, -16, -5], [3, 17, -8], [27, 8, -3], [-28, 14, 2], [-2, 2, 2], [-22, -4, 4], [-12, -3, 9], [5, 11, -4], [-6, -3, 7], [2, -14, -8], [2, 4, -10], [-18, 16, -4], [13, 6, -11], [-35, 2, -7], [40, 5, -3], [26, -16, -8], [-8, -13, 15], [12, 14, 2], [-22, 17, 7], [23, -18, -1], [-14, 17, 3], [14, -4, 6], [-10, 4, 8], [5, 5, 10], [-40, 3, -1], [-2, 14, -8], [-18, -3, -17], [-8, 16, -8], [-23, -5, 8], [40, -1, 3], [-30, 16, 8], [-2, -4, 6], [10, -7, -1], [4, 11, 11], [-36, -2, -6], [6, 4, 8], [1, 14, -3], [22, 16, -12], [-9, 9, 8], [-30, 18, 4], [14, 5, -9], [9, -7, -6], [2, 0, 8], [2, 14, 10], [-4, 1, -3], [22, 4, 0], [16, -12, -4], [-24, 11, -1], [7, -4, -7], [10, 12, -4], [-18, -9, 1], [-28, 6, -6], [30, -11, -9], [4, 4, -8], [30, -2, -4], [38, -12, -8], [28, -10, 2], [38, -20, -8], [-18, -7, 11], [31, -6, 3], [-14, 2, 12], [3, -10, 3], [-10, -6, -6], [-8, 4, -12], [34, -20, -12], [11, 6, -5], [10, 5, -13], [6, 8, 4], [-23, 4, -5], [10, 0, 8], [-35, 8, 11], [-36, 4, 0], [-30, 21, 11], [22, -4, 16], [7, 10, -17], [-2, 0, -14], [35, -7, -12], [6, -6, 10], [-7, -5, -4], [-26, 6, 8], [-14, 7, 5], [-40, 8, 0], [-18, -22, 4], [-22, 2, -2], [28, 15, -9], [29, -15, -14], [2, -6, 8], [-5, 13, -8], [-36, -2, -6], [-24, 6, 6], [-2, 13, -1], [-2, -2, 6], [-23, -4, 11], [29, -22, -11], [-21, 13, 16], [-38, -8, 2], [-14, -10, -12], [6, 12, 8], [2, 22, -14], [-6, 16, 14], [-26, 8, 4], [14, -15, 3], [40, 0, 8], [0, 1, 9], [-7, 3, 4], [20, 1, 13], [-18, 15, -7], [17, -24, -9], [-20, 6, 18], [4, -3, 1], [8, -25, -5], [-10, 8, 12], [12, 20, -8], [6, 22, -2], [-38, -4, 4], [19, 15, 2], [-18, 4, -16], [16, -5, 15], [16, 6, 6], [-26, -4, 16], [-18, 6, 16], [-6, 12, 12], [10, 10, -8], [-14, -4, 14], [-30, 29, 11], [2, -3, -9], [14, 16, 6], [8, -22, -6], [33, 8, -9], [31, -10, -9], [10, -2, -6], [-3, -3, -10], [8, 20, -4], [2, 20, -4], [-28, -5, -13], [2, 20, 10], [-6, -1, -3], [44, -13, 3], [-31, -13, -4], [-42, -5, -3], [-49, 1, -12], [24, -5, -17], [-4, -7, -3], [4, -8, 12], [10, 17, 7], [39, -9, -10], [-54, 12, -2], [-22, 1, -13], [30, -15, 3], [-25, 2, 3], [9, -15, -6], [-7, 23, 0], [10, -8, 16], [0, 6, 14], [20, 19, -13], [-16, 28, -4], [22, -16, 12], [-53, 16, 1], [-8, -11, 5], [-54, 4, 4], [30, -6, 8], [-12, -16, 20], [-30, 4, -12], [38, 2, 0], [-7, 0, 15], [-6, 10, 6], [2, -20, -12], [-81, -1, -2], [34, -14, -2], [-6, -16, 16], [24, -8, -8], [2, 30, 2], [-26, 8, 12], [-23, 15, 4], [15, -7, 12], [73, 6, 1], [36, -3, 1], [8, 3, -1], [28, 27, -13], [45, 2, 9], [44, 10, -2], [-25, -7, 16], [-5, -1, -10], [10, 22, -6], [-58, 14, -2], [-54, 26, 14], [-66, -6, 4], [-2, -2, -10], [-14, 4, 4], [-20, 19, 3], [8, 16, -8], [-46, -7, -9], [-13, -7, 12], [24, 21, -3], [4, -12, -24], [-7, 10, 1], [0, 15, 27], [-58, 4, 2], [-30, 24, 0], [38, -4, -8], [25, 12, 3], [-26, 9, 19], [-42, -3, -13], [-6, -6, 8], [21, 9, 14], [-22, -22, 6], [-30, 24, 22], [-20, -9, 15], [10, -22, 14], [12, -10, 2], [-13, 1, 12], [-6, -6, 4], [46, -24, -4], [4, 27, 3], [-8, -10, 6], [-26, 20, 8], [18, 0, 18], [19, -7, -8], [-25, -12, -7], [58, 5, 3], [36, -14, -10], [-12, 15, -1], [37, 5, 18], [3, 28, 1], [30, -5, -19], [-34, -20, 16], [-38, -16, 0], [44, 13, 9], [10, 16, 0], [5, -16, 23], [18, -10, 18], [27, -31, -4], [-33, -14, 3], [38, -12, -2], [22, -15, -21], [45, 1, -10], [24, -20, 12], [-26, -6, -14], [-48, -11, -11], [48, -6, 2], [0, 6, -26], [26, -8, 6], [26, 14, -6], [-36, 42, 6], [18, 0, 24], [19, 7, -2], [-6, -15, 15], [20, -13, 3], [-10, 21, 11], [-20, 28, 0], [-62, 18, -2], [-22, -24, 0], [57, 22, -11], [46, -23, -5], [-18, 9, -17], [-30, 16, 10], [9, 5, -18], [-2, 12, 0], [54, 9, -13], [56, -2, -10], [-11, -11, -34], [-6, 28, -12], [-12, -9, 15], [-9, 2, -9], [65, 6, -3], [-30, 28, 20], [-16, 14, -10], [-22, 34, 14], [-16, 19, 15], [-31, 30, 17], [58, 14, 0], [30, 10, 2], [-34, 4, -8], [-27, -1, -8], [30, 0, 4], [40, 8, -8], [-17, -4, -3]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1088_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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