
// Make newform 153.3.p.a in Magma, downloaded from the LMFDB on 13 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_153_p();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_153_p_Hecke();"
// 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_3_p_a();".
// 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_3_p_a();".
// 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, 0, 0, 0, 0, 0, 0, 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_153_p();"
function MakeCharacter_153_p()
    N := 153;
    order := 16;
    char_gens := [137, 37];
    v := [16, 3];
    // 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;

// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_153_p_Hecke();"
function MakeCharacter_153_p_Hecke( : Kf := false)
    N := 153;
    order := 16;
    char_gens := [137, 37];
    char_values := [[1, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0]];
    assert UnitGenerators(DirichletGroup(N)) eq char_gens;
    values := ConvertToHeckeField(char_values : pass_field := ISA(Type(Kf), Fld), Kf := Kf); // the value of chi on the gens as elements in the Hecke field
    F := Universe(values);// the Hecke field
    chi := DirichletCharacterFromValuesOnUnitGenerators(DirichletGroup(N,F),values);
    return chi;
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 := 3;
    raw_aps := [[0, 0, 1, 0, -1, 0, 0, -1], [0, 0, 0, 0, 0, 0, 0, 0], [3, 1, 1, 1, 1, 3, 2, -2], [-2, 1, -1, 2, -1, 2, 2, -1], [-5, 0, -3, 0, 0, -3, 0, -5], [0, 0, -2, 0, 0, 7, 0, -7], [2, 9, -4, -7, -8, 5, -7, -1], [-4, 13, 10, 0, -10, -13, 4, -6], [1, -2, 13, -4, 4, -13, 2, -1], [-3, 0, -18, 18, 0, 3, 0, 0], [4, -4, -11, -18, 3, 3, -18, -11], [-21, -21, 3, 6, -7, 7, -6, -3], [0, -26, 26, 0, -7, 18, 18, -7], [12, -24, 12, 7, -6, 0, 6, -7], [10, -11, 4, -11, 10, -3, 0, 3], [-12, 6, 11, 0, -11, -6, 12, -36], [-1, 0, 1, 9, -5, -16, -5, 9], [33, 2, 2, 33, 7, 11, -11, -7], [0, 3, 8, -25, 4, -25, 8, 3], [-4, -4, -6, 41, 17, -17, -41, 6], [3, -30, -28, -28, -30, 3, 20, -20], [-12, 17, -44, 41, 41, -44, 17, -12], [11, -11, -63, 10, -63, -11, 11, 0], [-36, 8, 0, -8, 36, -47, 2, -47], [-43, 35, -26, 26, -35, 43, 63, 63], [0, 22, -74, -9, -20, -9, -74, 22], [-38, 73, 58, -5, 0, 5, -58, -73], [22, -3, -38, -38, -3, 22, 39, -39], [-9, -1, 1, 9, -7, 24, 24, -7], [59, 21, 34, 43, 43, 34, 21, 59], [31, 0, -31, 15, 29, -10, 29, 15], [-37, -18, -33, 33, 18, 37, 50, 50], [-48, 41, -44, -24, 0, 24, 44, -41], [31, 31, -52, -15, -26, 26, 15, 52], [-55, -42, 122, -42, -55, -24, 0, 24], [-78, -31, -8, -122, -8, -31, -78, 0], [-119, -14, 0, 14, 119, 40, 16, 40], [41, 51, 51, 41, -94, -64, 64, 94], [50, -50, 94, -7, -19, -19, -7, 94], [85, 85, 12, 38, -92, 92, -38, -12], [-83, 74, -83, -105, -19, 0, 19, 105], [81, -79, 26, -63, -63, 26, -79, 81], [-110, -56, 0, 56, 110, 14, -50, 14], [-36, -40, -36, -27, 27, 36, 40, 36], [-65, -70, -70, -65, -20, -50, 50, 20], [100, -27, -21, 21, 27, -100, 112, 112], [-74, 53, -53, 74, 71, -110, -110, 71], [44, 91, 72, 0, -72, -91, -44, -138], [44, -129, 26, -69, 69, -26, 129, -44], [-19, 0, 19, -29, 17, 118, 17, -29], [-31, 131, -13, 13, -131, 31, 76, 76], [108, 153, -40, -63, 0, 63, 40, -153], [-13, -13, 60, 90, -128, 128, -90, -60], [-132, 107, 146, 107, -132, -21, 0, 21], [-157, -69, 27, 0, -27, 69, 157, 26], [104, 0, -104, -25, -36, -110, -36, -25], [119, -119, -50, -39, 137, 137, -39, -50], [0, 119, 40, 17, 202, 17, 40, 119], [-1, 32, -66, -66, 32, -1, 26, -26], [123, 100, 123, -20, 102, 0, -102, 20], [-79, 80, -31, 148, 148, -31, 80, -79], [-98, -48, 0, 48, 98, -78, 110, -78], [34, 1, -190, -35, 0, 35, 190, -1], [-119, -44, -161, -161, -44, -119, -110, 110], [153, -8, 8, -153, 214, 136, 136, 214], [156, 190, 16, 17, 17, 16, 190, 156], [28, 0, -28, 49, -280, -120, -280, 49], [74, -74, -50, 72, -185, -185, 72, -50], [7, 119, -119, -7, 72, 90, 90, 72], [62, 260, 62, 100, -17, 0, 17, -100], [300, 26, -110, 26, 300, -46, 0, 46], [18, 129, 78, 0, -78, -129, -18, -256], [-196, -65, -65, -196, 127, -48, 48, -127], [0, -153, -28, 154, 20, 154, -28, -153], [20, 89, -48, -48, 89, 20, -83, 83], [-232, -30, -232, 111, 136, 0, -136, -111], [79, -206, -9, 226, -9, -206, 79, 0], [69, -194, 151, -41, 41, -151, 194, -69], [36, 46, 46, 36, -37, 104, -104, 37], [-40, -60, -39, -252, 0, 252, 39, 60], [30, 56, -87, 17, 17, -87, 56, 30], [288, 67, -46, 67, 288, -56, 0, 56], [314, -157, -4, -9, 9, 4, 157, -314], [-303, 0, 303, -116, 27, -64, 27, -116], [221, -221, -247, 106, -30, -30, 106, -247], [224, -85, 18, 29, 0, -29, -18, 85], [43, 67, -67, -43, -51, -196, -196, -51], [211, 13, -155, -118, -155, 13, 211, 0], [105, -180, 346, 0, -346, 180, -105, -48], [-116, 356, 0, -356, 116, -112, 190, -112], [-303, 0, 303, 93, 135, 80, 135, 93], [-70, -70, -37, -248, -11, 11, 248, 37], [34, 2, 375, -119, -119, 375, 2, 34], [-126, 11, -98, 324, -98, 11, -126, 0], [-14, -202, -249, 325, -325, 249, 202, 14], [-171, -132, -132, -171, 96, 271, -271, -96], [0, 68, -55, -174, 4, -174, -55, 68], [-309, 214, -78, -156, -156, -78, 214, -309], [-90, 149, -222, 149, -90, -213, 0, 213], [-285, 285, 80, -85, -165, -165, -85, 80], [87, 87, 187, -94, -42, 42, 94, -187], [-116, 229, 378, 229, -116, -154, 0, 154], [-116, -213, -204, 0, 204, 213, 116, -232], [-31, 0, 31, 22, -180, -202, -180, 22], [104, 63, 63, 104, 199, 68, -68, -199], [0, -3, -120, -260, 348, -260, -120, -3], [221, 38, 221, 263, -235, 0, 235, -263], [-58, 80, -1, -710, -1, 80, -58, 0], [132, -68, 0, 68, -132, 212, 244, 212], [199, 8, 94, 158, -158, -94, -8, -199], [-4, -95, 119, -119, 95, 4, -126, -126], [8, -292, 212, 100, 0, -100, -212, 292], [-5, -425, 171, 171, -425, -5, -232, 232], [-25, -125, 125, 25, 188, -394, -394, 188], [-69, -421, 43, 0, -43, 421, 69, -356], [401, -327, -10, 10, 327, -401, -337, -337], [-30, 30, 58, 177, 345, 345, 177, 58], [-198, -263, 422, -315, 0, 315, -422, 263], [-182, 94, -94, 182, 163, -248, -248, 163], [4, 265, -598, 265, 4, 21, 0, -21], [-40, -300, -41, -290, -41, -300, -40, 0], [-19, -278, -278, -19, -75, 283, -283, 75], [-48, 48, -258, 96, -221, -221, 96, -258], [-5, -5, -547, 450, 60, -60, -450, 547], [-231, -146, 147, 480, 480, 147, -146, -231], [274, 345, 0, -345, -274, -158, 362, -158], [440, 341, -36, 36, -341, -440, -34, -34], [57, -178, 123, 123, -178, 57, 16, -16], [-404, -449, 30, -449, -404, 165, 0, -165], [436, 90, 181, 0, -181, -90, -436, 526], [-167, 0, 167, 299, 103, -576, 103, 299], [206, 27, 467, -467, -27, -206, 284, 284], [16, 16, -616, -223, -517, 517, 223, 616], [-275, 162, -275, -21, 97, 0, -97, 21], [30, 448, 266, 448, 30, 15, 0, -15], [82, 151, 0, -151, -82, -440, -186, -440], [-205, 0, 205, 140, 581, -14, 581, 140], [193, 216, 540, 540, 216, 193, -231, 231], [55, 640, 232, -250, 232, 640, 55, 0], [369, -217, -217, 369, 279, -434, 434, -279], [70, 317, -109, 109, -317, -70, 366, 366], [273, 314, 188, 188, 314, 273, -292, 292], [137, 457, -457, -137, -330, 402, 402, -330], [-389, -111, 420, 32, 32, 420, -111, -389], [-131, 476, 152, 476, -131, 268, 0, -268], [230, 176, -349, 263, -263, 349, -176, -230], [-169, -169, 24, 9, 741, -741, -9, -24], [468, -94, 94, -468, -181, 374, 374, -181], [-73, -352, -73, 133, -267, 0, 267, -133], [96, -328, 324, -328, 96, 374, 0, -374], [415, -84, -84, 415, 517, -385, 385, -517], [-266, 266, 280, 678, -253, -253, 678, 280], [0, 518, 32, 412, 62, 412, 32, 518], [-137, -137, -202, -271, 318, -318, 271, 202], [31, 100, -585, 126, -126, 585, -100, -31], [-413, -4, -4, -413, 606, 367, -367, -606], [614, 348, 370, -246, 0, 246, -370, -348], [177, 346, -348, 410, 410, -348, 346, 177], [-188, 212, 533, 0, -533, -212, 188, 66], [-222, -492, 304, 207, -207, -304, 492, 222], [41, -230, -920, 920, 230, -41, 39, 39], [828, -6, -258, -103, 0, 103, 258, 6], [-285, -331, -359, 324, -359, -331, -285, 0], [144, -577, 120, 0, -120, 577, -144, 526], [-560, 0, 560, 120, -45, 54, -45, 120], [-307, 307, -771, -556, 114, 114, -556, -771], [-498, 105, 178, 178, 105, -498, 291, -291], [-179, -736, 10, 60, 60, 10, -736, -179]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_153_p_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_153_3_p_a();".
// 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_3_p_a(:prec:=8)
    chi := MakeCharacter_153_p();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 3));
    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_3_p_a();".
// 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_3_p_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_153_p();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<2,R![1, 8, 20, 8, 8, -16, 4, 0, 1]>],Snew);
    return Vf;
end function;