
// Make newform 1840.3.k.b in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1840_k();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_1840_k_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_1840_3_k_b();".
// 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_1840_3_k_b();".
// 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 := [225444, -89080, 19344, 6972, 165, -968, 346, 34, -10, -2, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [64951601035622166, 10197120293765962, 2768080292176325, 491894487341618, 1539918810175326, -6517813050410, -55776313196156, 2184040960024, 6940583162233, 18413999298], [3418363084066042, -326238370122746, -108581674614685, 107377324329566, 35789989530522, -7088796581670, -1072934217052, 430137087328, 78987068911, -3178911074], [1692482235453388, -1283490894627774, -146401588536315, -28895174126101, 18624554785488, -9673453676400, -662996871978, 207292153512, 36976343259, -27126561061], [-4897259103221374, -1283642065245148, -216158506360285, 56554416235853, -30214028316584, -24941366319520, -1238323970566, 725904561704, -90970570937, -61680118787], [20117555613991862, -14729541411749116, 912032566785975, 775382511035361, -75828656056898, -196255517839040, 12414624463218, 6293663580928, -217704046159, -468602611879], [-7220328774106298, -21178202332536396, 1218611249635355, 1232761568987581, -345681207607138, -218633353705920, 12765303556778, 7538944599648, -877397075979, -498310598539], [1565531822973306, -362194258629668, -125586360875135, 59463180686023, 9777674573986, -13274870104560, -310444293146, 712152635904, 13161849303, -41025221057], [-19230564880585838, 6060410005984514, 754716139973685, -219938936410664, -220963040069008, 76977727981220, 6675104951458, -2135744859512, -458127503999, 236841500106], [-139788745884593038, 32402773549134054, 11000674301597555, -3806813263174894, -1437169367927798, 493331069170170, 51027227704468, -19681413465312, -2989519571129, 1050188941786]];
    Rf_basisdens := [1, 5791009908414440, 251783039496280, 1447752477103610, 1447752477103610, 5791009908414440, 5791009908414440, 251783039496280, 1447752477103610, 5791009908414440];
    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_1840_k();"
function MakeCharacter_1840_k()
    N := 1840;
    order := 2;
    char_gens := [1151, 1381, 737, 1201];
    v := [2, 2, 2, 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;

// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_1840_k_Hecke();"
function MakeCharacter_1840_k_Hecke(Kf)
    N := 1840;
    order := 2;
    char_gens := [1151, 1381, 737, 1201];
    char_values := [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [-1, 0, 0, 0, 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 := [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, -1, 0, 0, 0, 0], [0, 0, 0, -1, 0, 0, 0, 0, 0, 0], [0, 0, 1, 1, 0, 0, 0, 0, 0, 0], [0, 0, -1, 0, 0, 0, 0, 0, -1, 0], [0, 0, 0, 0, -1, 1, 1, -1, 0, 0], [0, -1, 2, 0, 0, 0, 0, 0, 2, 0], [0, 1, 1, 2, 0, 0, 0, 0, 0, 1], [-5, 0, -2, 3, 2, -3, 1, 2, 1, 0], [-3, 0, 0, 0, -1, 8, -1, -1, 0, 0], [0, 0, 0, 0, 0, 0, -1, -4, 0, 0], [0, -1, -1, 10, 0, 0, 0, 0, -1, 4], [-6, 0, 0, 0, 9, -8, 2, -1, 0, 0], [0, -2, -3, -1, 0, 0, 0, 0, 1, -3], [-13, 0, 0, 0, -2, -1, 1, 2, 0, 0], [0, -3, 0, -19, 0, 0, 0, 0, 2, 1], [23, 0, 0, 0, -6, -6, 7, -1, 0, 0], [0, 0, 7, -4, 0, 0, 0, 0, -3, 4], [0, 1, 3, -18, 0, 0, 0, 0, -5, 4], [-18, 0, 0, 0, 11, -8, -10, -7, 0, 0], [21, 0, 0, 0, 0, 13, -7, -4, 0, 0], [0, -2, 3, 5, 0, 0, 0, 0, 7, 3], [0, -3, 6, 1, 0, 0, 0, 0, 0, -5], [0, -4, 5, -9, 0, 0, 0, 0, -5, 11], [0, 2, -9, -10, 0, 0, 0, 0, 9, -4], [-7, 0, 0, 0, 14, 34, -3, -1, 0, 0], [0, 4, 4, -25, 0, 0, 0, 0, 0, 1], [0, -9, -1, 0, 0, 0, 0, 0, 7, -4], [0, 1, 15, -8, 0, 0, 0, 0, 4, -7], [0, 3, -15, 12, 0, 0, 0, 0, 7, -8], [45, 0, 0, 0, 18, 29, 13, 2, 0, 0], [-2, 0, 0, 0, 15, -4, 8, 24, 0, 0], [0, -5, 4, -3, 0, 0, 0, 0, -3, -4], [117, 0, 0, 0, 17, 14, -15, 3, 0, 0], [0, -7, 0, 1, 0, 0, 0, 0, 1, -4], [11, 0, 0, 0, 29, 38, 5, 4, 0, 0], [0, -5, 11, 72, 0, 0, 0, 0, 9, -2], [52, 0, 0, 0, 31, -11, -13, 31, 0, 0], [102, 0, 0, 0, -26, -6, 12, 14, 0, 0], [27, 0, 0, 0, 24, 4, 17, 24, 0, 0], [86, 0, 0, 0, 7, -16, 16, -12, 0, 0], [0, -9, 3, -46, 0, 0, 0, 0, 2, 7], [0, -12, 8, 8, 0, 0, 0, 0, -6, -12], [1, 0, 0, 0, -38, 25, -5, -16, 0, 0], [118, 0, 0, 0, 6, 31, 30, -8, 0, 0], [0, -6, -17, -35, 0, 0, 0, 0, 23, -7], [-43, 0, 0, 0, -34, 56, 23, 11, 0, 0], [-12, 0, 0, 0, 26, -24, -32, -24, 0, 0], [0, 2, -13, 61, 0, 0, 0, 0, 17, -17], [0, 0, 21, -97, 0, 0, 0, 0, 5, 1], [123, 0, 0, 0, 0, -37, 21, -14, 0, 0], [65, 0, 0, 0, -19, 36, 27, -7, 0, 0], [0, 16, -14, 32, 0, 0, 0, 0, 8, -12], [0, 9, 26, -5, 0, 0, 0, 0, 9, -10], [-143, 0, 0, 0, -46, 67, 5, -12, 0, 0], [0, -7, 47, -75, 0, 0, 0, 0, -5, 17], [51, 0, 0, 0, 39, -12, -35, -1, 0, 0], [2, 0, 0, 0, 21, -34, 3, 6, 0, 0], [227, 0, 0, 0, -6, -33, 15, -22, 0, 0], [0, 14, 3, -71, 0, 0, 0, 0, -15, -5], [0, 5, 8, -31, 0, 0, 0, 0, 10, -17], [0, 5, 6, 29, 0, 0, 0, 0, 16, 9], [-195, 0, 0, 0, -24, -44, 3, -14, 0, 0], [-104, 0, 0, 0, 27, -26, 4, 30, 0, 0], [0, -14, 2, 100, 0, 0, 0, 0, 29, -5], [155, 0, 0, 0, 19, 34, 32, -31, 0, 0], [-5, 0, 0, 0, 19, -56, -37, 17, 0, 0], [0, -1, -27, 2, 0, 0, 0, 0, -14, 3], [217, 0, 0, 0, 54, -6, 27, 34, 0, 0], [57, 0, 0, 0, -29, 102, 65, -7, 0, 0], [-61, 0, 0, 0, 18, 57, -75, 16, 0, 0], [0, 12, 17, -61, 0, 0, 0, 0, -45, 27], [0, 9, -2, 35, 0, 0, 0, 0, 30, -29], [0, 0, 12, -72, 0, 0, 0, 0, 0, 30], [0, -10, -42, -61, 0, 0, 0, 0, -14, 3], [0, 13, -19, -46, 0, 0, 0, 0, -23, 22], [0, 12, 14, 67, 0, 0, 0, 0, 10, 39], [-4, 0, 0, 0, -56, 25, -28, 2, 0, 0], [0, -24, 18, 28, 0, 0, 0, 0, 28, -28], [-52, 0, 0, 0, 10, -34, -27, 34, 0, 0], [0, 20, -7, 103, 0, 0, 0, 0, -11, 9], [0, -3, 27, 44, 0, 0, 0, 0, -26, -3], [0, -16, -57, -47, 0, 0, 0, 0, 3, -5], [0, 28, -30, -14, 0, 0, 0, 0, -35, 11], [-303, 0, 0, 0, -70, 34, 62, -69, 0, 0], [-304, 0, 0, 0, -47, -87, 89, 15, 0, 0], [152, 0, 0, 0, -9, -44, 13, -14, 0, 0], [0, 3, -54, 33, 0, 0, 0, 0, -26, -11], [10, 0, 0, 0, 103, 36, -30, 50, 0, 0], [-142, 0, 0, 0, 106, -24, -22, 26, 0, 0], [0, -1, -20, 27, 0, 0, 0, 0, 4, 9], [0, -6, 12, 100, 0, 0, 0, 0, 48, -26], [311, 0, 0, 0, -44, 5, 1, 28, 0, 0], [-179, 0, 0, 0, 59, 58, 15, -1, 0, 0], [69, 0, 0, 0, -71, -98, 37, -21, 0, 0], [0, 6, -44, 90, 0, 0, 0, 0, 13, -45], [124, 0, 0, 0, 47, 40, -112, 18, 0, 0], [0, -6, 18, 34, 0, 0, 0, 0, -10, -6], [0, -28, -45, 25, 0, 0, 0, 0, 3, 37], [336, 0, 0, 0, -67, -30, 12, 62, 0, 0], [174, 0, 0, 0, -13, -113, 11, 35, 0, 0], [0, -27, -85, -90, 0, 0, 0, 0, 11, -18], [0, -19, -18, 165, 0, 0, 0, 0, -14, -5], [0, 30, -66, 98, 0, 0, 0, 0, -12, -10], [0, 2, 54, 85, 0, 0, 0, 0, 0, -11], [-17, 0, 0, 0, -94, -89, -25, -68, 0, 0], [-242, 0, 0, 0, -150, 153, 6, -44, 0, 0], [30, 0, 0, 0, -24, -14, 38, 126, 0, 0], [273, 0, 0, 0, 104, 114, -143, 34, 0, 0], [-258, 0, 0, 0, 14, -112, 101, 22, 0, 0], [240, 0, 0, 0, -84, 96, -22, -24, 0, 0], [0, 6, -18, -40, 0, 0, 0, 0, -52, 52], [0, 25, 69, 15, 0, 0, 0, 0, -7, 23], [0, 25, -26, 71, 0, 0, 0, 0, -19, 24], [0, 4, -19, 45, 0, 0, 0, 0, 5, 3], [0, 32, -39, -213, 0, 0, 0, 0, -73, 35], [0, 21, -40, 277, 0, 0, 0, 0, -26, -21], [33, 0, 0, 0, -66, 41, -47, -66, 0, 0], [474, 0, 0, 0, 41, -45, 3, 23, 0, 0], [0, 10, 36, 4, 0, 0, 0, 0, 28, -22], [0, -18, -42, 87, 0, 0, 0, 0, -14, -17], [369, 0, 0, 0, 78, -93, -95, 26, 0, 0], [0, -3, 30, -65, 0, 0, 0, 0, 70, 5], [690, 0, 0, 0, -43, 61, -13, 13, 0, 0], [-238, 0, 0, 0, -104, -124, 88, -24, 0, 0], [0, -17, 29, -224, 0, 0, 0, 0, -10, 7], [0, -6, 45, 64, 0, 0, 0, 0, 53, 0], [142, 0, 0, 0, 135, -130, -55, -10, 0, 0], [0, 29, -18, -98, 0, 0, 0, 0, -18, -38], [0, -9, -46, -51, 0, 0, 0, 0, -44, -37], [213, 0, 0, 0, -79, 2, 141, 71, 0, 0], [0, 15, -40, -339, 0, 0, 0, 0, 27, -8], [0, -30, -31, 33, 0, 0, 0, 0, 7, -55], [0, -1, -55, 22, 0, 0, 0, 0, 25, -72], [-30, 0, 0, 0, -130, -20, 1, -46, 0, 0], [0, 20, -22, -60, 0, 0, 0, 0, -58, 18], [0, -32, 105, 39, 0, 0, 0, 0, 23, -1], [0, -1, -26, -129, 0, 0, 0, 0, -2, 9], [0, -35, -63, -78, 0, 0, 0, 0, 37, 10], [-378, 0, 0, 0, -54, 56, 48, -9, 0, 0], [137, 0, 0, 0, 21, 32, -45, -97, 0, 0], [268, 0, 0, 0, 84, 94, 12, 34, 0, 0], [-273, 0, 0, 0, -76, -43, -135, -2, 0, 0], [0, 21, 102, 51, 0, 0, 0, 0, -24, 87], [197, 0, 0, 0, -14, -114, 133, -59, 0, 0], [0, 18, -137, 313, 0, 0, 0, 0, -37, -7], [-485, 0, 0, 0, 61, -4, 68, 11, 0, 0], [-33, 0, 0, 0, 216, -131, -133, -44, 0, 0], [-513, 0, 0, 0, 109, -62, 31, 27, 0, 0], [627, 0, 0, 0, -66, 227, -35, -32, 0, 0], [793, 0, 0, 0, 76, 56, 23, 56, 0, 0], [0, -16, 26, 142, 0, 0, 0, 0, -78, -16], [153, 0, 0, 0, 41, -284, 38, -39, 0, 0], [111, 0, 0, 0, -28, 215, -45, -66, 0, 0], [0, -11, 11, 66, 0, 0, 0, 0, 25, -4], [0, 4, 59, -167, 0, 0, 0, 0, 55, -9], [0, -32, 101, 129, 0, 0, 0, 0, 19, -25], [153, 0, 0, 0, -119, 2, 79, -37, 0, 0], [0, 21, -107, 220, 0, 0, 0, 0, 54, -21], [0, -42, 100, -73, 0, 0, 0, 0, 90, -17], [-394, 0, 0, 0, 125, 173, -97, 1, 0, 0], [0, -32, 14, -265, 0, 0, 0, 0, 36, 9], [309, 0, 0, 0, 102, -133, -29, 50, 0, 0], [0, -22, -74, -83, 0, 0, 0, 0, -98, 97], [0, 38, -47, 163, 0, 0, 0, 0, -4, 62], [0, 43, 22, -286, 0, 0, 0, 0, 80, -30], [-298, 0, 0, 0, -104, 206, 148, -9, 0, 0], [-212, 0, 0, 0, 136, 176, -262, 6, 0, 0], [0, -62, 53, 249, 0, 0, 0, 0, 77, -9], [376, 0, 0, 0, 156, -75, 116, -22, 0, 0], [0, -88, -9, -207, 0, 0, 0, 0, 25, 43], [-393, 0, 0, 0, 267, 64, 5, 33, 0, 0], [0, -44, 90, 330, 0, 0, 0, 0, 18, -24], [0, -31, 38, 402, 0, 0, 0, 0, 16, 26], [199, 0, 0, 0, 169, -118, -3, -16, 0, 0], [0, 6, 133, 221, 0, 0, 0, 0, -57, 43], [-224, 0, 0, 0, -63, 54, -6, -20, 0, 0], [-847, 0, 0, 0, -93, -122, 97, 15, 0, 0], [0, 1, -59, -53, 0, 0, 0, 0, 69, 27], [0, 13, -134, 143, 0, 0, 0, 0, -5, 20], [-31, 0, 0, 0, -62, -43, -35, 196, 0, 0], [0, -74, 117, -6, 0, 0, 0, 0, 67, 22], [-896, 0, 0, 0, 23, 67, -25, 61, 0, 0], [328, 0, 0, 0, -94, -184, -12, -124, 0, 0], [0, -49, 196, -418, 0, 0, 0, 0, -28, 42], [0, -53, -124, -281, 0, 0, 0, 0, 27, -22], [-327, 0, 0, 0, 71, -14, -182, -49, 0, 0], [0, 5, -29, 138, 0, 0, 0, 0, -65, 66], [358, 0, 0, 0, -67, -24, 70, 117, 0, 0], [578, 0, 0, 0, 0, 10, 260, 75, 0, 0], [343, 0, 0, 0, -246, 361, -87, -126, 0, 0], [28, 0, 0, 0, -184, 336, 158, -74, 0, 0], [0, 42, 36, -388, 0, 0, 0, 0, 44, -2], [-177, 0, 0, 0, -146, 144, 137, 49, 0, 0], [0, -54, -42, -278, 0, 0, 0, 0, 44, -6], [0, 28, -7, 197, 0, 0, 0, 0, 18, 84], [0, -42, 83, -223, 0, 0, 0, 0, -63, 39], [0, -22, -62, -24, 0, 0, 0, 0, 102, 32], [0, -28, 144, 46, 0, 0, 0, 0, 10, 20], [173, 0, 0, 0, 116, 451, 25, -68, 0, 0], [0, 20, -30, -343, 0, 0, 0, 0, -2, -39], [147, 0, 0, 0, 311, -344, -22, 161, 0, 0], [-642, 0, 0, 0, -204, 201, 10, 2, 0, 0], [0, -22, 39, 55, 0, 0, 0, 0, 37, -91], [0, -68, -72, -194, 0, 0, 0, 0, 34, -40], [1129, 0, 0, 0, -30, 7, -3, -76, 0, 0], [0, 68, 43, -89, 0, 0, 0, 0, 3, -21], [-230, 0, 0, 0, 166, -331, 174, 16, 0, 0], [240, 0, 0, 0, 22, 174, 5, 10, 0, 0], [484, 0, 0, 0, 13, 296, -96, -38, 0, 0], [-215, 0, 0, 0, -228, 291, 107, -22, 0, 0], [572, 0, 0, 0, -143, 124, 110, -72, 0, 0], [0, 57, -67, -124, 0, 0, 0, 0, -152, 7], [0, -72, 32, 122, 0, 0, 0, 0, 190, -44], [293, 0, 0, 0, -236, -76, 37, -121, 0, 0], [0, 12, 95, 53, 0, 0, 0, 0, 7, -29], [-389, 0, 0, 0, 212, 35, 115, 14, 0, 0], [461, 0, 0, 0, 167, 24, 131, -7, 0, 0], [0, -2, -60, 42, 0, 0, 0, 0, 109, 49], [-981, 0, 0, 0, 272, 337, -89, 100, 0, 0], [697, 0, 0, 0, 129, -522, -109, -103, 0, 0], [0, -58, 105, 291, 0, 0, 0, 0, -53, -23], [238, 0, 0, 0, 323, -394, -90, 137, 0, 0], [0, 26, -39, 67, 0, 0, 0, 0, -52, 138], [53, 0, 0, 0, 144, 11, -147, 164, 0, 0], [-69, 0, 0, 0, -139, -72, 63, -39, 0, 0], [0, 11, 65, 198, 0, 0, 0, 0, 124, 11], [788, 0, 0, 0, 62, 28, -203, 60, 0, 0], [0, -79, -30, -123, 0, 0, 0, 0, 21, -42], [-343, 0, 0, 0, 116, -24, 153, 1, 0, 0], [655, 0, 0, 0, -129, -184, 58, -89, 0, 0], [0, -34, -81, -614, 0, 0, 0, 0, 31, -10], [0, -66, 18, 30, 0, 0, 0, 0, -62, 40], [-242, 0, 0, 0, 54, 184, -348, 129, 0, 0], [0, -39, 102, 519, 0, 0, 0, 0, 42, 33], [0, -34, 97, -251, 0, 0, 0, 0, -81, 135], [0, -60, 42, 210, 0, 0, 0, 0, -88, 44], [0, -52, 91, 287, 0, 0, 0, 0, -69, 67], [-79, 0, 0, 0, -277, -40, 17, -193, 0, 0], [-828, 0, 0, 0, 33, -258, 68, 145, 0, 0], [0, -67, -46, -171, 0, 0, 0, 0, 18, -41], [529, 0, 0, 0, -143, 130, 113, 53, 0, 0], [477, 0, 0, 0, -180, 47, 109, 164, 0, 0], [1138, 0, 0, 0, 211, 12, -246, 158, 0, 0], [252, 0, 0, 0, 174, -86, 62, -26, 0, 0], [-303, 0, 0, 0, 2, 314, 90, 63, 0, 0], [-439, 0, 0, 0, -288, 235, 65, -76, 0, 0], [0, 59, 128, -29, 0, 0, 0, 0, -201, -4], [0, 66, -6, -393, 0, 0, 0, 0, 42, 27], [0, -53, -72, -302, 0, 0, 0, 0, -36, -62], [0, -42, -68, 450, 0, 0, 0, 0, -62, 54], [0, -58, -170, -62, 0, 0, 0, 0, -34, 68], [0, -54, 34, 780, 0, 0, 0, 0, -11, 51], [0, 18, 21, -577, 0, 0, 0, 0, -71, 111], [1082, 0, 0, 0, -46, 174, -148, 74, 0, 0], [-29, 0, 0, 0, -135, 380, -115, 69, 0, 0], [0, 24, -31, 360, 0, 0, 0, 0, 1, 20], [0, -30, -202, -100, 0, 0, 0, 0, -48, -132], [-86, 0, 0, 0, 15, -63, 47, 49, 0, 0], [1013, 0, 0, 0, -348, 41, 269, 148, 0, 0], [0, -29, 216, -294, 0, 0, 0, 0, 34, 34], [0, -35, 169, 462, 0, 0, 0, 0, 99, -76], [-333, 0, 0, 0, -284, 256, 183, -19, 0, 0], [0, -19, 123, -396, 0, 0, 0, 0, -5, -26], [190, 0, 0, 0, 484, 354, -78, 34, 0, 0], [0, 54, 243, 242, 0, 0, 0, 0, -115, 106], [0, 40, -111, -360, 0, 0, 0, 0, 217, -104], [0, 6, 111, 439, 0, 0, 0, 0, -9, 73], [0, 15, -39, 12, 0, 0, 0, 0, 59, 26], [-286, 0, 0, 0, -197, -393, 145, -149, 0, 0], [-331, 0, 0, 0, -47, 466, -49, 105, 0, 0], [0, 105, 34, -49, 0, 0, 0, 0, -160, 27], [0, -100, -19, -419, 0, 0, 0, 0, 82, 60], [0, 38, -173, 239, 0, 0, 0, 0, -67, 21], [457, 0, 0, 0, 90, -463, -221, 104, 0, 0], [669, 0, 0, 0, -40, 577, -313, -96, 0, 0], [37, 0, 0, 0, 4, 264, -173, 104, 0, 0], [-703, 0, 0, 0, -384, 26, -97, -209, 0, 0], [0, 32, 110, -70, 0, 0, 0, 0, -14, 40], [0, -31, -238, 255, 0, 0, 0, 0, 53, 84], [-365, 0, 0, 0, 332, 31, -213, -172, 0, 0], [0, -24, -56, 600, 0, 0, 0, 0, 4, 102], [0, -54, 117, 172, 0, 0, 0, 0, -101, 86], [0, 30, 140, 348, 0, 0, 0, 0, -186, -2], [1077, 0, 0, 0, 279, 14, -98, -61, 0, 0], [508, 0, 0, 0, 50, 560, -110, -105, 0, 0], [0, 33, -114, 203, 0, 0, 0, 0, -44, 51], [0, 16, 45, 187, 0, 0, 0, 0, -81, 55], [683, 0, 0, 0, -166, 424, -173, 54, 0, 0], [-463, 0, 0, 0, -144, 46, 253, -14, 0, 0], [0, 54, 86, -18, 0, 0, 0, 0, 96, -32], [0, -13, -86, 307, 0, 0, 0, 0, -188, 13], [-378, 0, 0, 0, -306, 24, -218, -86, 0, 0], [0, -25, 315, -538, 0, 0, 0, 0, 54, -91], [-1178, 0, 0, 0, -58, -873, 118, 120, 0, 0], [0, 22, 16, 129, 0, 0, 0, 0, 12, 125], [0, -76, -16, 650, 0, 0, 0, 0, 162, 162], [-810, 0, 0, 0, 408, -391, -102, 12, 0, 0], [1439, 0, 0, 0, 133, 56, 241, -95, 0, 0], [-218, 0, 0, 0, -38, -263, 158, 150, 0, 0], [0, 20, 51, 191, 0, 0, 0, 0, -42, 26], [0, 15, 101, 462, 0, 0, 0, 0, -29, -4], [0, 14, 156, -818, 0, 0, 0, 0, 20, -24]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1840_k_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1840_3_k_b();".
// 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_1840_3_k_b(:prec:=10)
    chi := MakeCharacter_1840_k();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 3));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(1999) - 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_1840_3_k_b();".
// 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_1840_3_k_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1840_k();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<3,R![-2, 45, 19, -18, -1, 1]>],Snew);
    return Vf;
end function;