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


// To make the newform (type ModFrm), type "MakeNewformModFrm_289_3_e_h();".
// 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_289_3_e_h(:prec:=8)
    chi := MakeCharacter_289_e();
    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_289_3_e_h();".
// 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_289_3_e_h( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_289_e();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<2,R![1, 8, 20, 8, 8, -16, 4, 0, 1]>,<3,R![2312, -2176, 368, -528, 556, -128, 36, -8, 1]>],Snew);
    return Vf;
end function;