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


// To make the newform (type ModFrm), type "MakeNewformModFrm_289_3_e_e();".
// 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_e(: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_e();".
// 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_e( : 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, 0, 12, 48, 72, 56, 28, 8, 1]>,<3,R![2312, -544, 1184, -624, 484, -304, 100, -16, 1]>],Snew);
    return Vf;
end function;