
// Make newform 1155.2.a.v in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1155_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_1155_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_1155_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 := [4, 4, -5, -2, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, -1, -2, 1], [2, -5, -2, 1], [-8, 1, 4, -1]];
    Rf_basisdens := [1, 2, 2, 2];
    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_1155_a();"
function MakeCharacter_1155_a()
    N := 1155;
    order := 1;
    char_gens := [386, 232, 661, 211];
    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_1155_a_Hecke(Kf)
    return MakeCharacter_1155_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, -1, 0], [-1, 0, 0, 0], [1, 0, 0, 0], [1, 0, 0, 0], [1, 0, 0, 0], [2, 1, 1, 1], [2, 0, 1, -1], [-2, 0, -1, -1], [4, 2, 1, -1], [2, 1, 0, 2], [-2, 1, -1, 1], [4, -1, 3, 1], [2, 1, 3, 3], [-2, -3, -4, 0], [-2, -3, -1, 1], [2, 0, -3, -1], [2, -1, 4, 0], [2, 0, 3, 1], [0, 4, 2, 2], [2, 1, 1, 3], [4, 0, -2, 0], [0, -1, 3, -1], [6, 2, 3, -1], [-4, -3, -2, -2], [-4, -1, 0, 0], [0, -2, -2, -4], [-10, -1, 2, 2], [8, -1, 5, 1], [0, 1, 1, -5], [6, 0, -1, 5], [6, -1, 4, 0], [-2, -1, 5, 3], [2, -4, 2, -2], [-6, 2, 0, -2], [4, 0, 4, -2], [-10, -2, 4, 2], [-4, -3, 0, 0], [2, -3, 3, -3], [2, -2, -4, -2], [2, 0, -6, -6], [2, 5, 5, 3], [-2, 0, -4, -4], [-4, 0, 0, 4], [12, 4, 4, 2], [14, 2, 8, 4], [-8, -4, -4, -4], [-2, 0, -10, 0], [-14, -1, 0, 0], [6, 0, 3, 3], [12, 3, 3, 1], [4, 3, 1, 7], [-6, -5, -4, -4], [-18, 2, 0, 0], [-12, -4, -12, -4], [16, 7, 5, -1], [-10, 0, -12, -2], [-4, -5, -2, 6], [6, 4, -1, -5], [12, -4, -2, -4], [-4, -4, -6, -4], [-2, -1, 1, -1], [-2, -8, -9, 1], [-8, 2, -4, -4], [8, 6, 6, -2], [4, -3, 2, 2], [2, 2, -4, -4], [-12, -4, 3, 5], [14, -3, -6, 0], [10, 4, 8, 2], [-6, -4, 1, 3], [6, 2, -6, -2], [-14, -7, -12, -8], [-2, 5, 6, 2], [6, -1, 6, -4], [0, 0, -3, -9], [2, 3, -13, -3], [8, -5, -1, -7], [-6, 2, -16, 0], [0, 1, -9, -7], [10, -2, 0, 4], [-10, 5, -6, 2], [30, 2, 7, 5], [0, 2, 6, 6], [-18, 2, 2, -2], [-18, 2, 1, -3], [4, 0, -6, 6], [8, -1, -7, 3], [2, -3, 10, 4], [8, 4, -8, -10], [4, 6, 4, 4], [0, -2, -6, -10], [6, 3, -3, 7], [-16, -2, -8, -4], [2, -5, 2, -6], [-8, -2, 9, -1], [14, 2, 3, -5], [8, 1, -4, 0], [-4, 3, 8, -8], [-8, -10, -10, 2], [0, -3, 9, 11], [6, 3, 2, -2], [2, 6, 6, 2], [14, -4, -2, 0], [2, 9, 6, 8], [-8, -7, -3, 5], [-14, 0, -4, -12], [-10, -3, -3, 7], [-2, -2, -12, -4], [4, 6, 12, -4], [-18, 2, -1, 1], [0, 6, 4, 16], [16, 6, -6, -8], [14, -2, 12, 4], [-4, -4, -6, -2], [-16, 0, -11, -5], [-6, -4, 8, 8], [10, 3, 4, 0], [-24, -2, -2, -2], [-6, 0, 11, 1], [2, 1, 0, 8], [-4, 3, -1, 5], [14, -9, -8, -2], [10, 4, 1, 3], [12, -4, -4, -12], [8, 4, -2, 6], [10, -1, 8, 6], [-18, -2, -7, -5], [-10, -5, -4, 0], [-30, -9, -18, -6], [-4, 4, 12, 6], [6, -4, -2, 8], [18, 8, 18, 4], [-8, -4, -1, -7], [6, -2, -6, -6], [-12, -14, -14, 0], [-6, -4, -11, -13], [-6, 2, -10, 2], [-24, 4, -8, -4], [-22, -6, -2, 2], [-8, 4, -16, -6], [10, -2, 14, 8], [-18, 7, 2, 0], [-14, -5, -7, -1], [2, -4, 8, -6], [-14, 2, 2, 6], [14, -5, 2, -6], [18, -3, -1, 3], [-2, 4, -4, 0], [2, -1, 9, 3], [28, 4, 5, 7], [14, 7, -2, 4], [-12, -9, 8, 0], [0, 6, -6, 6], [-26, 0, 7, 3], [-34, 1, 7, -3], [-24, 2, -22, -6], [-10, -6, 4, 10], [6, -10, 4, -4], [18, 11, -3, -3], [-18, -11, -7, -3], [-8, 8, 3, -7], [-6, -4, 16, 0], [-6, -3, 4, 8], [-38, -3, -12, -4], [-10, -8, -3, -9], [-16, -10, 12, 8], [0, -6, 11, -7], [-20, -14, -18, 0], [-24, 3, -7, -5], [0, 1, 7, -3], [-14, -11, -8, 0], [12, 7, 7, 13], [26, 5, 14, -2], [10, 5, -6, -4], [-4, 6, 0, 8], [-34, -2, 6, -6], [8, 5, 17, 9], [6, 8, -6, 6], [0, -6, 8, -4], [-2, -10, -16, 4], [-8, 0, 12, -12], [8, 2, -6, 14], [-18, -10, -14, -6], [-2, 8, -11, 7], [-4, -16, -11, -1], [0, 9, 8, 4], [-2, 5, -6, -4], [-14, 9, 8, 8], [-4, 7, -5, -11], [26, -1, 11, -3], [-22, 0, -12, 4], [22, 2, -4, -10], [16, 8, -2, 6], [-16, 7, -12, 4], [20, 9, 1, -3], [26, 8, 14, 2], [-10, -4, -6, 10], [12, -1, 11, 9], [6, -4, 3, -15], [-6, -2, -4, 6], [-10, -7, -2, 0], [6, 4, 7, 3], [-4, -9, -2, -10], [18, 4, 10, -2], [10, -5, 18, 2], [6, 4, 10, -10], [-10, 1, 11, -3], [46, -2, 8, 2], [-2, 1, -8, -6], [-2, -9, 1, -1], [-14, -5, 6, 20], [36, 3, 14, 6], [-12, -18, -14, -2], [-10, 17, 5, 7], [12, 4, -20, -8], [22, 10, 6, -6], [-26, -5, -20, 0], [-28, -12, -8, -2], [-28, 8, 6, 6], [14, 14, 3, -7], [26, 4, 10, -6], [22, 4, -2, -4], [8, -11, 15, 1], [-6, 3, -3, -5], [18, 6, 11, 19], [12, 1, -21, -3], [-20, 5, 1, 3], [-6, -5, 19, 13], [20, 14, 14, -6], [2, 1, -14, -2], [16, -9, 7, -7], [30, 8, 14, 8], [-32, -3, -31, -11], [-18, 5, -14, -8], [22, -3, -10, 6], [10, 0, 7, 7], [-24, -1, 1, 11], [-2, -2, -8, 12], [24, 6, -4, 12], [4, -2, -14, 6], [24, 6, -12, 4], [-10, 6, -17, -13], [-32, -8, -6, -10], [-22, -8, -15, -21], [-2, -6, 13, 3], [14, 1, -9, 1], [-36, 4, 4, 0], [10, 9, 16, 0], [40, 1, -7, 9], [26, -4, 4, -6], [24, 10, -14, -8], [18, 15, 17, 17], [-12, -4, 16, 4], [-4, -3, 17, 19], [6, -2, 11, 1], [-6, 3, -14, -6], [6, -6, 13, 7], [-6, -3, -3, -5], [36, -5, -5, 1], [-12, 4, 16, 6], [-14, 5, 6, 6], [-2, -10, -22, 0], [30, 4, 23, 17], [26, 3, 21, 17], [-24, 11, -3, 7], [10, 7, 23, 5], [-18, 4, 6, 2], [24, 1, 0, 8], [-2, 3, 16, 0], [0, -11, -17, 5], [14, 4, -4, -4], [20, 8, 10, 14], [-8, 5, 0, 0], [8, 15, 5, 5], [6, 3, -5, 19], [-44, -4, -10, -2], [-48, -8, -7, 3], [38, 0, -10, 2], [-8, -7, -15, -17], [8, -4, 24, -4], [10, -10, -11, 13], [-40, -4, 10, 14], [42, 10, 22, 20], [38, 12, -13, -19], [2, -17, -19, -1], [10, 1, 27, 9], [16, 5, -25, 1], [-2, 4, 2, -10], [28, -8, -10, -10], [-42, -7, -17, -5], [-14, 8, 10, -14], [38, 3, 23, 9], [0, 9, 7, 9], [-32, 12, -16, 4], [-4, 10, -14, 4], [-12, -6, -12, 2], [-4, 2, -2, -14], [-28, 7, -3, -9], [-8, 0, -20, -8], [-12, 0, -24, -8], [-20, 8, -4, 10], [-36, 7, 9, 3], [-8, 5, -11, -7], [8, 2, -3, 11], [12, 10, -5, -7], [-8, 3, -7, 11], [-20, -10, 7, 13], [4, -1, -15, -5], [22, 3, -1, -3], [-6, -7, 4, 6], [-18, -8, -10, -4], [16, -5, 1, 15], [-6, -1, 14, -12], [-6, 1, -27, -5], [-8, 11, 5, -11], [-46, -10, -31, -13], [-32, -22, -30, -2], [58, -7, 12, 0], [22, 10, 10, 14], [-30, 9, -22, -4], [22, 10, 22, 20], [0, -3, -17, -31], [-48, -14, -2, 12], [-30, 3, 9, 7], [-30, -6, -12, -8], [-10, -2, 12, 4], [24, 10, -8, -16], [-54, -11, -32, -24], [12, 11, -3, -15], [-28, -3, 19, -3], [-8, -5, -9, 9], [22, 0, 26, 14], [26, 0, -7, 5], [-18, -2, -10, -28], [10, 16, 6, -4], [24, 8, 8, -12], [-10, -18, -23, -5], [-14, -2, -12, -24], [-20, 5, 7, 13], [22, 19, 27, 9], [-24, -17, -19, 3], [14, 4, 9, 19], [-22, 1, -25, 3], [-24, 2, -4, 0], [-6, 8, -5, -15], [-2, -9, 2, -2], [4, -1, 17, 19], [10, -3, 9, 23], [24, -16, -16, -8], [-8, -19, 5, -1], [10, -4, 39, 3], [22, -2, -8, 16], [-20, -5, -25, -11], [38, 1, -5, 13], [-10, 0, -18, -14], [-18, -18, -23, -25], [-24, 12, 10, 22], [18, -1, 21, 7], [-34, 2, -14, 6], [32, -8, -9, -15], [34, -9, -14, 4], [-16, 10, 18, 4], [-4, 8, -26, -10], [-54, -7, -6, -2], [-42, 11, -12, 4], [-34, -4, 4, 0], [-18, 6, -11, 15], [54, 13, 12, 4], [-32, 5, -11, -5], [52, -2, 10, -6], [0, 14, 22, 10], [-22, -4, 12, 2], [-34, -3, -14, -12], [-2, 6, 3, 3], [-24, -13, -5, 5], [-24, 0, -10, 6], [-46, -1, -12, 4], [-32, -6, -4, -6], [-10, 27, -1, 7], [-2, -25, -5, -5], [-16, -5, 4, -20], [6, 0, 25, 3], [-12, 8, -28, 0], [-36, 7, 7, -7], [10, 4, 7, -13], [26, -11, 19, -7], [-4, -2, -15, -1], [60, 9, 8, -8], [32, 6, -6, 6], [36, 18, 22, -6], [30, 16, 13, -1], [10, -18, -10, -6], [22, 21, 17, 11], [-42, -3, 6, 14], [36, 4, -18, -2], [-30, -3, -2, 0], [46, 6, 0, -10], [-14, 2, -34, -10], [-48, 4, 7, 5], [30, 19, 4, 6], [-22, -2, -3, -13], [-26, 0, -5, -7], [-30, -9, 20, 4], [20, 13, 11, 1], [-30, -7, -27, -19], [26, 0, -15, 5], [0, -9, -3, 3], [-68, 6, -2, -4], [-10, 9, 14, -2], [30, 15, 4, 12], [8, -6, 0, -2], [-12, -7, -23, -17], [28, 2, 8, 28], [44, 3, -5, 7], [48, -8, -4, 6], [56, 7, 4, -4], [10, 5, 4, 0], [2, 9, 18, -14], [-16, -9, 13, 7], [18, 14, 8, 2], [36, 3, 13, 7], [52, 0, 24, 2], [12, 6, 5, 3], [-70, -9, -29, -15], [20, 5, 22, -2], [20, -13, -23, -5], [-36, 4, -11, -5], [-2, -3, 34, 8], [0, 0, -18, -18], [74, -3, -1, 5]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1155_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1155_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_1155_2_a_v(:prec:=4)
    chi := MakeCharacter_1155_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_1155_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_1155_2_a_v( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1155_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<2,R![2, 8, -5, -2, 1]>,<13,R![-8, 24, -14, -4, 1]>,<17,R![4, 4, -11, -6, 1]>],Snew);
    return Vf;
end function;