
// Make newform 153.4.a.f in Magma, downloaded from the LMFDB on 20 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_153_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_153_4_a_f();".
// 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_153_4_a_f();".
// 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 := [-10, -14, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-9, -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_153_a();"
function MakeCharacter_153_a()
    N := 153;
    order := 1;
    char_gens := [137, 37];
    v := [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_153_a_Hecke( : Kf := Kf)
    return MakeCharacter_153_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 := 4;
    raw_aps := [[-2, 1, 0], [0, 0, 0], [-2, -2, 1], [-4, 4, -4], [-8, -10, -3], [14, -6, 13], [-17, 0, 0], [-44, -10, -5], [-44, 22, -11], [-38, 24, 28], [-56, 20, 14], [14, 68, 18], [-230, -30, 7], [-52, 10, -91], [-204, 112, -14], [-242, 116, 24], [76, -12, -38], [18, -72, -38], [-476, 24, -48], [384, -192, 4], [-322, 172, 24], [-48, -132, 174], [472, 136, -18], [-422, -128, 106], [270, -408, -62], [-342, -76, -138], [-416, -22, -131], [976, -10, 217], [582, 92, 62], [-862, -106, 153], [-1608, -330, 211], [-96, 178, -309], [-374, -148, -264], [-64, -408, -38], [-2122, -164, 208], [-1048, -432, -120], [1830, 74, -263], [-380, -52, 522], [468, -546, 241], [-506, 614, 293], [924, -724, -238], [794, 604, -316], [-388, -16, -322], [58, 720, 404], [1158, -58, -151], [2524, 516, -324], [468, -644, -478], [-2136, 1550, 215], [1680, 402, -45], [2190, 144, -96], [2074, 1170, -545], [-2364, -660, 496], [1926, -24, 342], [-492, 632, -280], [282, 432, -210], [376, -1344, 56], [-1970, 2, -1105], [3192, -762, -365], [-734, 836, -116], [6274, 528, -458], [1180, 428, 178], [4690, -252, 802], [-1764, -496, 704], [-3472, -152, -856], [-2722, -1376, 802], [-5030, -928, -32], [868, 1142, -577], [-2082, -412, 664], [1684, -360, -688], [-2346, 862, 67], [2102, -984, 1376], [-3424, 2208, 284], [1448, -880, -852], [5774, 40, 1668], [872, 340, -412], [1420, 1652, -288], [-6126, 1244, -178], [5194, 880, -646], [4002, -998, 1587], [2138, -3210, -417], [-8668, -416, -920], [4646, -486, 229], [2808, -744, -504], [1506, 1210, -343], [-2368, 3552, -284], [-11504, 208, 106], [9182, -200, -676], [-3934, -194, -1665], [-2958, -2000, -468], [-6512, -1712, -1032], [-8496, -2232, 762], [6876, -722, 1777], [464, -1188, -246], [5296, -424, 454], [1992, -3920, 230], [3228, -2086, 707], [-4542, 1564, 1962], [-182, 226, 1359], [-14140, 1184, 280], [-3858, 1524, 630], [1888, -5004, 372], [-3870, -712, 2504], [4388, -1612, -70], [-14366, 2480, 422], [-880, 1300, 152], [-2590, 4846, -685], [-11332, 288, 1912], [4498, -1380, -1280], [-5356, 4896, 902], [-6518, -1120, -3760], [-3116, 3536, 2002], [-3530, 2994, -3351], [4342, 168, 796], [-284, 1828, -1990], [1840, 3558, 1587], [1634, -5066, 1473], [-5240, -1740, 1928], [3100, -6184, 3022], [5622, -2770, 3041], [2568, -4968, -130], [5734, -274, 4111], [-8330, -1876, -944], [-9258, 5178, 675], [13688, -1486, -2605], [9764, 840, -2984], [-20694, 12, 774], [8514, -1652, 4712], [-596, 2314, -1817], [-5792, 3720, -2352], [10998, 1320, -2788], [6324, -3658, -557], [1600, 792, -4208], [6464, -660, -1506], [2454, -3946, -293], [-12426, -856, 180], [23906, 1038, 4291], [-2458, 2656, -742], [-5704, 5604, -1376], [-1166, -460, 2990], [10762, -4846, 151], [12296, -1376, -1174], [-21546, 3622, -2039], [15664, -552, 4760], [2256, -6630, -1509], [9830, 5680, -1640], [-3380, -7750, 163], [-17818, 4896, -1044], [23246, -9128, 344], [4844, -4040, 1328], [21604, 2860, 328], [-23702, -956, -916], [5422, -504, -2092], [25260, -4698, 2799], [-5412, 890, -6877], [4520, -3824, 4498], [-5828, 10926, 857], [-3720, -6402, -4221], [-5838, 4790, 1337], [-21390, -3400, 760], [6042, 4560, -3936], [-2180, -8392, 1288], [6582, 428, -4194], [6864, -7294, -1327], [-6780, 11492, -1738], [-17002, -432, -3844], [7364, 9906, -6301], [8508, 1572, 2472], [-32946, 4064, 2584]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_153_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_153_4_a_f();".
// 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_153_4_a_f(:prec:=3)
    chi := MakeCharacter_153_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 4));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(997) - 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_153_4_a_f();".
// 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_153_4_a_f( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_153_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![-34, -6, 5, 1]>,<5,R![-466, -59, 8, 1]>],Snew);
    return Vf;
end function;