
// Make newform 300.3.f.b in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_300_f();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_300_f_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_300_3_f_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_300_3_f_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 := [256, 0, 320, 0, 192, 0, 100, 0, 53, 0, 25, 0, 12, 0, 5, 0, 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, 0, 0, 0, 0, 0, 0], [-128, 0, -160, 0, -96, 0, -17, 0, -25, 0, -8, 0, -1, 0, -1, 0], [-336, 0, 248, 0, 24, 0, -67, 0, 5, 0, 16, 0, -3, 0, 5, 0], [-3296, 0, -2120, 0, -1176, 0, -593, 0, -321, 0, -176, 0, -81, 0, -17, 0], [-804, 0, -552, 0, -271, 0, -180, 0, -81, 0, -35, 0, -16, 0, -5, 0], [9280, 0, 8640, 0, 4896, 0, 2805, 0, 1533, 0, 680, 0, 357, 0, 165, 0], [0, 832, 0, 1760, 0, -1384, 0, 241, 0, 193, 0, 192, 0, 97, 0, 41], [32704, 0, 25920, 0, 11040, 0, 6971, 0, 3763, 0, 1432, 0, 843, 0, 267, 0], [0, 9152, 0, 7200, 0, 3168, 0, 1815, 0, 1135, 0, 440, 0, 231, 0, 71], [0, 1984, 0, 1536, 0, 704, 0, 479, 0, 215, 0, 88, 0, 47, 0, 15], [-56128, 0, -43200, 0, -20832, 0, -11783, 0, -5727, 0, -2488, 0, -1367, 0, -407, 0], [0, -53312, 0, -38272, 0, -19904, 0, -10257, 0, -4761, 0, -2984, 0, -1217, 0, -353], [0, -9920, 0, -8544, 0, -4264, 0, -2207, 0, -1167, 0, -512, 0, -303, 0, -103], [0, -99392, 0, -62976, 0, -27904, 0, -15537, 0, -7289, 0, -3048, 0, -1889, 0, -449], [0, 48064, 0, 54016, 0, 21408, 0, 10175, 0, 5847, 0, 2872, 0, 1295, 0, 527], [0, 56000, 0, 39936, 0, 19408, 0, 9995, 0, 5139, 0, 2248, 0, 1051, 0, 427]];
    Rf_basisdens := [1, 64, 304, 304, 76, 2432, 2432, 2432, 2432, 512, 2432, 9728, 2432, 9728, 9728, 4864];
    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_300_f();"
function MakeCharacter_300_f()
    N := 300;
    order := 2;
    char_gens := [151, 101, 277];
    v := [1, 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_300_f_Hecke();"
function MakeCharacter_300_f_Hecke(Kf)
    N := 300;
    order := 2;
    char_gens := [151, 101, 277];
    char_values := [[-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [-1, 0, 0, 0, 0, 0, 0, 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, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, -1, 1], [0, -1, 0, -1, 1, 0, 0, 1, 0, 0, 2, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 2, 1, -1], [0, 0, 0, 0, 0, 0, -1, 0, -1, 2, 0, 3, -3, 0, 3, -1], [0, 2, 3, -3, -1, -5, 0, 3, 0, 0, 2, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, -3, 0, 3, -6, 0, 2, 4, 4, -2, 1], [-4, 4, 4, 0, 3, 0, 0, -8, 0, 0, -3, 0, 0, 0, 0, 0], [0, 2, 11, -3, -5, -1, 0, 3, 0, 0, -2, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 3, 0, 9, -4, 0, -7, 5, 2, -7, 1], [-6, -4, -6, -2, -2, 2, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 4, 0, -4, -24, 0, 8, -4, 4, -8, 8], [0, 0, 0, 0, 0, 0, 3, 0, -3, -12, 0, 4, 4, -6, -4, -3], [0, 0, 0, 0, 0, 0, 2, 0, 22, 0, 0, 1, 1, 4, 1, -2], [0, 5, 4, 1, -5, -4, 0, -1, 0, 0, -6, 0, 0, 0, 0, 0], [-26, -4, -2, 2, -4, -2, 0, 14, 0, 0, 6, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, -2, 0, 2, -6, 0, -2, -8, 10, 2, 8], [0, -6, 12, -2, -2, 4, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 6, 0, -11, -8, 0, -6, 18, 4, -6, 2], [0, -6, -9, 17, -1, 15, 0, -17, 0, 0, -18, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 10, 0, -10, -18, 0, 14, 4, -10, -14, 0], [-14, -4, -6, -2, 20, 2, 0, 2, 0, 0, -22, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, -4, 0, -33, 12, 0, 12, -24, 4, 12, -8], [-28, 0, -4, -4, 1, 4, 0, -12, 0, 0, -5, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 8, 0, -8, 11, 0, -1, -20, 3, 1, 11], [0, 0, 0, 0, 0, 0, -12, 0, 12, 18, 0, 2, 20, 6, -2, -6], [-54, -8, -4, 4, -2, -4, 0, 28, 0, 0, 6, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, -11, 0, -25, 14, 0, 11, -31, -8, 11, -3], [0, 0, 0, 0, 0, 0, 4, 0, -4, -7, 0, 5, 12, -15, -5, -11], [0, 9, -26, 7, 5, 10, 0, -7, 0, 0, -2, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 1, 0, 31, -10, 0, -11, 19, -8, -11, 9], [0, -12, 13, 9, -5, -35, 0, -9, 0, 0, -14, 0, 0, 0, 0, 0], [88, 4, 4, 0, 1, 0, 0, -8, 0, 0, -1, 0, 0, 0, 0, 0], [0, 8, -33, 7, 9, 11, 0, -7, 0, 0, 2, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, -7, 0, -3, 12, 0, -21, -57, -2, -21, -5], [0, 0, 0, 0, 0, 0, 10, 0, -10, -26, 0, -18, -20, -18, 18, -8], [0, 0, 0, 0, 0, 0, -5, 0, 5, -2, 0, -26, -12, -4, 26, -9], [0, 0, 0, 0, 0, 0, -12, 0, -16, 20, 0, -7, -67, -4, -7, -8], [0, 25, 6, -25, -3, -34, 0, 25, 0, 0, 22, 0, 0, 0, 0, 0], [-66, 16, 20, 4, -18, -4, 0, -20, 0, 0, 22, 0, 0, 0, 0, 0], [0, 2, 4, -10, 2, -32, 0, 10, 0, 0, 12, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 6, 0, -83, -12, 0, -22, 14, 0, -22, 6], [0, 0, 0, 0, 0, 0, -6, 0, -74, 12, 0, -1, -37, 0, -1, -6], [0, 28, 37, -15, -25, -3, 0, 15, 0, 0, -10, 0, 0, 0, 0, 0], [0, 0, -17, 7, 5, -45, 0, -7, 0, 0, -2, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, -26, 0, 26, 95, 0, -29, 28, -5, 29, -31], [0, 0, 0, 0, 0, 0, 20, 0, -20, 28, 0, 8, -40, 8, -8, 28], [-10, 12, 34, 22, 26, -22, 0, 42, 0, 0, -4, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 11, 0, 47, -22, 0, -7, 59, 0, -7, 11], [0, -22, 18, -12, 8, 30, 0, 12, 0, 0, 20, 0, 0, 0, 0, 0], [42, 8, 28, 20, 40, -20, 0, 44, 0, 0, -20, 0, 0, 0, 0, 0], [0, 41, -14, -21, -3, -6, 0, 21, 0, 0, 18, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 11, 0, -35, 2, 0, -15, -21, 24, -15, -13], [0, 0, 0, 0, 0, 0, 27, 0, -27, 98, 0, 34, 12, -32, -34, -5], [132, -12, -20, -8, -41, 8, 0, 0, 0, 0, 33, 0, 0, 0, 0, 0], [0, 12, 19, 15, -23, 23, 0, -15, 0, 0, -38, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, -11, 0, 23, 12, 0, 21, -15, -10, 21, -1], [-90, -16, -30, -14, -24, 14, 0, -10, 0, 0, 10, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 10, 0, -10, -94, 0, -2, -48, 26, 2, 36], [0, 0, 0, 0, 0, 0, 2, 0, -26, -12, 0, -31, 5, -8, -31, 10], [0, 0, 0, 0, 0, 0, -46, 0, 46, -40, 0, -24, 60, 8, 24, -38], [0, -34, -34, 36, 16, 70, 0, -36, 0, 0, -20, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, -6, 0, 97, -20, 0, -30, 30, -32, -30, 26], [0, 0, 0, 0, 0, 0, 14, 0, -74, 4, 0, -5, -17, 32, -5, -18], [0, 34, 115, -51, -49, -33, 0, 51, 0, 0, 2, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 2, 0, -41, -8, 0, -6, 18, -4, -6, 6], [0, 0, 0, 0, 0, 0, 22, 0, -22, -28, 0, 32, -24, 12, -32, 34], [-118, 12, -2, -14, 48, 14, 0, -66, 0, 0, -62, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 3, 0, -21, 26, 0, 13, -65, 32, 13, -29], [0, 52, 32, -20, -32, 108, 0, 20, 0, 0, -12, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 10, 0, -10, -83, 0, 5, -24, 9, -5, 19], [0, 0, 0, 0, 0, 0, 23, 0, 7, -4, 0, -55, -43, 42, -55, -19], [0, 16, -81, 23, 21, -17, 0, -23, 0, 0, -2, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 29, 0, -29, 36, 0, 28, -52, 22, -28, 51], [48, -48, -72, -24, -19, 24, 0, 24, 0, 0, -5, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 11, 0, 141, -16, 0, -51, -3, 6, -51, 5], [-82, 20, 44, 24, -26, -24, 0, 32, 0, 0, 50, 0, 0, 0, 0, 0], [78, -8, -32, -24, -40, 24, 0, -56, 0, 0, 16, 0, 0, 0, 0, 0], [0, 39, 18, -7, -25, -114, 0, 7, 0, 0, -18, 0, 0, 0, 0, 0], [-54, -20, -26, -6, 62, 6, 0, 22, 0, 0, -68, 0, 0, 0, 0, 0], [0, -24, 64, -32, -4, 40, 0, 32, 0, 0, 28, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, -10, 0, 49, 40, 0, 14, -106, 20, 14, -30], [0, -48, 65, -31, 7, 73, 0, 31, 0, 0, 38, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 44, 0, -44, -260, 0, 32, -32, -24, -32, 20], [130, 40, 92, 52, 38, -52, 0, 76, 0, 0, 14, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, -4, 0, -69, 52, 0, 104, -52, 44, 104, -48], [8, 12, 24, 12, -29, -12, 0, 12, 0, 0, 41, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, -6, 0, 6, 173, 0, 37, -24, 73, -37, 67], [0, 0, 0, 0, 0, 0, -36, 0, 36, -50, 0, -10, 60, 2, 10, -34], [0, -22, -52, 30, 22, 16, 0, -30, 0, 0, -8, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 60, 0, -60, 31, 0, 59, -60, -1, -59, 59], [0, 17, 164, -3, -89, -96, 0, 3, 0, 0, -86, 0, 0, 0, 0, 0], [0, 34, 29, -73, 5, -187, 0, 73, 0, 0, 78, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, -63, 0, 63, 64, 0, -24, 44, 58, 24, -5], [-84, 32, 72, 40, 27, -40, 0, 56, 0, 0, 13, 0, 0, 0, 0, 0], [-74, -16, -36, -20, 22, 20, 0, -28, 0, 0, -42, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, -72, 0, 72, -82, 0, -22, 48, 74, 22, 2], [142, 40, 36, -4, 6, 4, 0, -92, 0, 0, -10, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, -28, 0, 28, -44, 0, -28, 28, 0, 28, -28], [0, 0, 0, 0, 0, 0, -24, 0, 28, 60, 0, 103, -77, 12, 103, -36], [0, 0, 0, 0, 0, 0, 34, 0, -34, -16, 0, 44, 24, -48, -44, -14], [-694, 36, 48, 12, 18, -12, 0, -36, 0, 0, -6, 0, 0, 0, 0, 0], [0, -78, -169, 1, 123, 131, 0, -1, 0, 0, 122, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, -40, 0, -269, 28, 0, -84, -168, -52, -84, 12], [0, 0, 0, 0, 0, 0, 32, 0, -32, 162, 0, -38, -20, -82, 38, -50], [0, 0, 0, 0, 0, 0, 17, 0, 119, -90, 0, -57, 213, -56, -57, 73], [0, 64, -16, 56, -52, 92, 0, -56, 0, 0, -108, 0, 0, 0, 0, 0], [90, 104, 128, 24, 92, -24, 0, -136, 0, 0, -68, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 4, 0, -4, -273, 0, -33, 8, -49, 33, -45], [0, 0, 0, 0, 0, 0, -47, 0, -29, 48, 0, -73, -217, -46, -73, -1], [0, 0, 0, 0, 0, 0, -3, 0, 261, -18, 0, 43, 97, -24, 43, 21], [0, 40, -115, -35, 55, 85, 0, 35, 0, 0, 90, 0, 0, 0, 0, 0], [0, -14, 93, -33, -23, 25, 0, 33, 0, 0, 10, 0, 0, 0, 0, 0], [122, 16, 42, 26, 98, -26, 0, 46, 0, 0, -72, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 70, 0, -70, -2, 0, -74, -100, -114, 74, -44], [0, 0, 0, 0, 0, 0, -11, 0, 11, 284, 0, 12, 100, -66, -12, -77], [0, 0, 0, 0, 0, 0, 28, 0, 52, -72, 0, -51, 165, -16, -51, 44], [0, 47, 108, 35, -95, -92, 0, -35, 0, 0, -130, 0, 0, 0, 0, 0], [438, 12, 10, -2, 48, 2, 0, -30, 0, 0, -50, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, -38, 0, 97, 16, 0, 178, 130, -60, 178, 22], [0, 0, 0, 0, 0, 0, -44, 0, -340, 40, 0, -37, -157, -48, -37, 4], [0, 0, 0, 0, 0, 0, -8, 0, 8, -14, 0, -78, -12, -50, 78, -58], [0, 66, -81, 89, -37, -29, 0, -89, 0, 0, -126, 0, 0, 0, 0, 0], [340, 72, 52, -20, 121, 20, 0, -204, 0, 0, -141, 0, 0, 0, 0, 0], [94, -84, -114, -30, -142, 30, 0, 78, 0, 0, 112, 0, 0, 0, 0, 0], [0, -84, 34, 62, -6, 34, 0, -62, 0, 0, -68, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, -12, 0, 12, 211, 0, -49, 36, -61, 49, -73], [0, 0, 0, 0, 0, 0, -5, 0, -155, 12, 0, -121, -157, 2, -121, -7], [0, -126, 121, 19, -7, 25, 0, -19, 0, 0, -26, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 67, 0, -67, 380, 0, 36, -116, 18, -36, 85], [0, 98, -117, -51, 35, -137, 0, 51, 0, 0, 86, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, -7, 0, -21, 60, 0, 197, 17, 46, 197, -53], [14, -8, 36, 44, -126, -44, 0, 148, 0, 0, 170, 0, 0, 0, 0, 0], [350, -16, -32, -16, 152, 16, 0, -16, 0, 0, -168, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, -30, 0, -358, 52, 0, 93, -63, -8, 93, -22], [0, 0, 0, 0, 0, 0, 64, 0, -64, 42, 0, 22, -128, 22, -22, 86], [0, 0, 0, 0, 0, 0, 32, 0, -332, -68, 0, 23, 227, -4, 23, 36], [-794, -88, -146, -58, 126, 58, 0, 2, 0, 0, -184, 0, 0, 0, 0, 0], [0, 156, -9, -53, -47, 59, 0, 53, 0, 0, 6, 0, 0, 0, 0, 0], [-212, 44, 80, 36, -83, -36, 0, 20, 0, 0, 119, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, -30, 0, 30, -39, 0, -3, -76, 133, 3, 103], [0, 0, 0, 0, 0, 0, -104, 0, 104, 344, 0, -52, 128, 28, 52, -76], [-166, 64, 108, 44, 46, -44, 0, 4, 0, 0, -2, 0, 0, 0, 0, 0], [0, -8, -44, -60, 56, 168, 0, 60, 0, 0, 116, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, -67, 0, 95, 128, 0, 23, -361, -6, 23, -61], [0, 0, 0, 0, 0, 0, 35, 0, 383, -70, 0, -1, 209, 0, -1, 35], [0, -8, 243, -61, -87, -53, 0, 61, 0, 0, -26, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 113, 0, -113, -70, 0, 34, -92, -100, -34, 13], [0, 0, 0, 0, 0, 0, 9, 0, 169, 20, 0, 15, -45, 38, 15, -29], [254, -52, -174, -122, 32, 122, 0, -262, 0, 0, -154, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, -54, 0, 54, 26, 0, 18, 92, 34, -18, -20], [0, 0, 0, 0, 0, 0, 155, 0, -155, 106, 0, 106, -244, 40, -106, 195], [0, 0, 0, 0, 0, 0, 26, 0, -26, 0, 0, 132, 80, 0, -132, 26], [0, -20, -66, 50, 18, -138, 0, -50, 0, 0, -32, 0, 0, 0, 0, 0], [0, -14, 153, 27, -83, -143, 0, -27, 0, 0, -110, 0, 0, 0, 0, 0], [114, -8, 8, 16, -254, -16, 0, 64, 0, 0, 270, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, -56, 0, -245, 64, 0, 4, -188, -48, 4, -8], [-1264, -32, -28, 4, -41, -4, 0, 76, 0, 0, 45, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 18, 0, -18, -552, 0, -12, -56, 8, 12, 26], [0, 0, 0, 0, 0, 0, 47, 0, 61, 50, 0, 127, -23, 144, 127, -97], [0, 0, 0, 0, 0, 0, -42, 0, 42, 157, 0, -63, -28, 49, 63, 7], [0, -39, 174, -105, -15, 254, 0, 105, 0, 0, 90, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 119, 0, 331, -190, 0, -97, 473, 48, -97, 71], [0, 0, 0, 0, 0, 0, -41, 0, 41, -392, 0, 40, 52, 70, -40, 29], [0, -104, -111, 25, 95, -67, 0, -25, 0, 0, 70, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, -75, 0, 273, 40, 0, 147, 27, -110, 147, 35]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_300_f_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_300_3_f_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_300_3_f_b(:prec:=16)
    chi := MakeCharacter_300_f();
    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_300_3_f_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_300_3_f_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_300_f();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<7,R![65536, 0, -188416, 0, 12032, 0, -224, 0, 1]>],Snew);
    return Vf;
end function;