
// Make newform 1728.4.f.g in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1728_f();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_1728_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_1728_4_f_g();".
// 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_1728_4_f_g();".
// 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 := [10000, 0, -2100, 0, 341, 0, -21, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0, 0], [81150, 0, -21483, 0, 1023, 0, -63, 0], [0, -42600, 0, 4323, 0, -363, 0, 3], [0, -10000, 0, 4061, 0, -341, 0, 21], [-8883, 0, 0, 0, 0, 0, -6, 0], [-192550, 0, 44671, 0, -3751, 0, 181, 0], [0, -1222200, 0, 116281, 0, -7161, 0, 241], [0, -30000, 0, 18183, 0, -1023, 0, 63]];
    Rf_basisdens := [1, 17050, 11000, 31000, 341, 8525, 170500, 11000];
    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_1728_f();"
function MakeCharacter_1728_f()
    N := 1728;
    order := 2;
    char_gens := [703, 325, 1217];
    v := [1, 1, 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_1728_f_Hecke();"
function MakeCharacter_1728_f_Hecke(Kf)
    N := 1728;
    order := 2;
    char_gens := [703, 325, 1217];
    char_values := [[-1, 0, 0, 0, 0, 0, 0, 0], [-1, 0, 0, 0, 0, 0, 0, 0], [-1, 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 := 4;
    raw_aps := [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 1, 0], [0, 0, 0, -2, 0, 0, 0, 1], [0, -8, 0, 0, 0, -1, 0, 0], [0, 1, 0, 0, 0, 3, 0, 0], [0, 0, 0, 63, 0, 0, 0, -3], [0, 0, 5, 0, 0, 0, -6, 0], [153, 0, 0, 0, -3, 0, 0, 0], [0, 0, -16, 0, 0, 0, 0, 0], [0, 0, 0, 2, 0, 0, 0, 2], [0, 1, 0, 0, 0, 21, 0, 0], [0, 0, 0, -54, 0, 0, 0, -18], [0, 0, 34, 0, 0, 0, -30, 0], [-225, 0, 0, 0, -21, 0, 0, 0], [0, 0, 80, 0, 0, 0, -26, 0], [0, -40, 0, 0, 0, 27, 0, 0], [0, -45, 0, 0, 0, 9, 0, 0], [0, 0, 39, 0, 0, 0, 36, 0], [54, 0, 0, 0, -18, 0, 0, 0], [43, 0, 0, 0, 44, 0, 0, 0], [0, 0, 0, -196, 0, 0, 0, 27], [0, -80, 0, 0, 0, -44, 0, 0], [0, 0, 0, -423, 0, 0, 0, -21], [155, 0, 0, 0, -50, 0, 0, 0], [0, 0, -128, 0, 0, 0, -26, 0], [0, 0, 0, 146, 0, 0, 0, 27], [0, 120, 0, 0, 0, -71, 0, 0], [0, -260, 0, 0, 0, -78, 0, 0], [0, 0, 0, 711, 0, 0, 0, 69], [0, 0, 0, 376, 0, 0, 0, -68], [0, 48, 0, 0, 0, 188, 0, 0], [0, 0, 0, 1737, 0, 0, 0, -21], [0, 0, 365, 0, 0, 0, -78, 0], [0, 0, 256, 0, 0, 0, 170, 0], [0, 0, 0, -884, 0, 0, 0, 49], [0, -452, 0, 0, 0, 66, 0, 0], [0, 0, 389, 0, 0, 0, 102, 0], [549, 0, 0, 0, 57, 0, 0, 0], [0, 0, 400, 0, 0, 0, -118, 0], [0, -400, 0, 0, 0, -170, 0, 0], [0, -365, 0, 0, 0, 57, 0, 0], [-1557, 0, 0, 0, 39, 0, 0, 0], [-907, 0, 0, 0, 94, 0, 0, 0], [0, 0, -880, 0, 0, 0, -19, 0], [0, 0, 0, 398, 0, 0, 0, -25], [0, 0, 695, 0, 0, 0, -150, 0], [0, 0, 0, -2342, 0, 0, 0, -54], [0, 560, 0, 0, 0, -162, 0, 0], [0, -340, 0, 0, 0, 312, 0, 0], [0, 0, 0, 198, 0, 0, 0, -174], [1692, 0, 0, 0, -84, 0, 0, 0], [2869, 0, 0, 0, 54, 0, 0, 0], [0, -672, 0, 0, 0, -162, 0, 0], [0, 0, 0, 1674, 0, 0, 0, -18], [-2196, 0, 0, 0, -228, 0, 0, 0], [0, 0, 656, 0, 0, 0, -27, 0], [0, 0, 0, 1330, 0, 0, 0, 259], [0, -604, 0, 0, 0, -210, 0, 0], [0, 0, 0, -4176, 0, 0, 0, -192], [0, 0, 638, 0, 0, 0, 318, 0], [0, 0, 1200, 0, 0, 0, -297, 0], [0, 0, 762, 0, 0, 0, -18, 0], [-2079, 0, 0, 0, -27, 0, 0, 0], [5767, 0, 0, 0, 146, 0, 0, 0], [0, 0, -560, 0, 0, 0, 44, 0], [0, 0, 565, 0, 0, 0, 294, 0], [-3013, 0, 0, 0, 486, 0, 0, 0], [0, 160, 0, 0, 0, -764, 0, 0], [0, -1415, 0, 0, 0, -123, 0, 0], [0, 0, 0, 6084, 0, 0, 0, -84], [2727, 0, 0, 0, -189, 0, 0, 0], [0, 0, 0, -8368, 0, 0, 0, -91], [0, -391, 0, 0, 0, -1047, 0, 0], [0, 0, 215, 0, 0, 0, 516, 0], [-1350, 0, 0, 0, 162, 0, 0, 0], [0, 0, -384, 0, 0, 0, 305, 0], [0, -1412, 0, 0, 0, -78, 0, 0], [0, 0, 0, -10944, 0, 0, 0, 192], [-7319, 0, 0, 0, -286, 0, 0, 0], [0, -1624, 0, 0, 0, -135, 0, 0], [0, 1385, 0, 0, 0, 969, 0, 0], [-15723, 0, 0, 0, -39, 0, 0, 0], [-4592, 0, 0, 0, -526, 0, 0, 0], [0, 0, 0, -8998, 0, 0, 0, -94], [0, 480, 0, 0, 0, 1026, 0, 0], [0, 0, 0, -45, 0, 0, 0, 105], [12076, 0, 0, 0, 338, 0, 0, 0], [0, 0, 480, 0, 0, 0, 505, 0], [0, 0, 0, 7468, 0, 0, 0, 211], [0, -120, 0, 0, 0, 955, 0, 0], [-4986, 0, 0, 0, 462, 0, 0, 0], [0, 0, 0, 1996, 0, 0, 0, 27], [0, 200, 0, 0, 0, -1369, 0, 0], [0, 0, -270, 0, 0, 0, -1152, 0], [4617, 0, 0, 0, 909, 0, 0, 0], [0, 0, 1504, 0, 0, 0, -1097, 0], [0, 0, 0, 3735, 0, 0, 0, 645], [0, 0, -969, 0, 0, 0, 522, 0], [0, 305, 0, 0, 0, 1149, 0, 0], [0, 0, -123, 0, 0, 0, -864, 0], [0, 0, -1920, 0, 0, 0, 37, 0], [0, 3200, 0, 0, 0, 170, 0, 0], [0, 0, 0, 1611, 0, 0, 0, 417], [0, 0, -1355, 0, 0, 0, -966, 0], [-3863, 0, 0, 0, 756, 0, 0, 0], [0, -2360, 0, 0, 0, 415, 0, 0], [0, 0, 0, -1476, 0, 0, 0, -444], [5364, 0, 0, 0, 852, 0, 0, 0], [17876, 0, 0, 0, 10, 0, 0, 0], [0, 0, 0, 10654, 0, 0, 0, -567], [0, 3939, 0, 0, 0, -153, 0, 0], [0, 0, 0, 17235, 0, 0, 0, -39], [0, 0, -1635, 0, 0, 0, 216, 0], [0, 0, 0, 2644, 0, 0, 0, -1103], [0, 0, 0, -20142, 0, 0, 0, -234], [0, 0, -2586, 0, 0, 0, 1746, 0], [19638, 0, 0, 0, -546, 0, 0, 0], [0, 0, 2960, 0, 0, 0, -388, 0], [0, 1920, 0, 0, 0, -1034, 0, 0], [0, 4995, 0, 0, 0, -261, 0, 0], [21031, 0, 0, 0, 98, 0, 0, 0], [0, 0, 4240, 0, 0, 0, 621, 0], [0, -2480, 0, 0, 0, -594, 0, 0], [0, 0, -3770, 0, 0, 0, -66, 0], [0, 0, -2048, 0, 0, 0, -143, 0], [0, 5785, 0, 0, 0, 363, 0, 0], [-7488, 0, 0, 0, -624, 0, 0, 0], [0, 0, 0, -16670, 0, 0, 0, -470], [0, -1268, 0, 0, 0, -1770, 0, 0], [0, 0, -2230, 0, 0, 0, 966, 0], [-6543, 0, 0, 0, -1227, 0, 0, 0], [0, 0, 0, 9110, 0, 0, 0, 1193], [0, 5073, 0, 0, 0, -1053, 0, 0], [0, 0, 0, -28845, 0, 0, 0, 345], [-12013, 0, 0, 0, 772, 0, 0, 0], [0, 0, 400, 0, 0, 0, -3024, 0], [0, 0, -3603, 0, 0, 0, 810, 0], [0, 0, -160, 0, 0, 0, 2798, 0], [0, 0, 0, -20178, 0, 0, 0, 714], [0, 0, -1550, 0, 0, 0, -2658, 0], [0, 0, 2640, 0, 0, 0, -1485, 0], [0, 0, 0, 19942, 0, 0, 0, -401], [0, -1000, 0, 0, 0, -3051, 0, 0], [0, -205, 0, 0, 0, 2175, 0, 0], [7902, 0, 0, 0, 6, 0, 0, 0], [0, 5889, 0, 0, 0, -729, 0, 0], [0, 0, 0, 39402, 0, 0, 0, -66], [0, 0, -1625, 0, 0, 0, -1668, 0], [17487, 0, 0, 0, 699, 0, 0, 0], [0, -1103, 0, 0, 0, 1191, 0, 0], [0, 0, 0, 28215, 0, 0, 0, 1125], [0, 0, -4667, 0, 0, 0, 1176, 0], [-4392, 0, 0, 0, 1128, 0, 0, 0], [0, 0, 943, 0, 0, 0, -3162, 0], [24498, 0, 0, 0, 714, 0, 0, 0], [0, 0, 0, -8354, 0, 0, 0, 1486], [0, 0, 0, 18720, 0, 0, 0, 960], [-17381, 0, 0, 0, -1258, 0, 0, 0], [0, 0, 2912, 0, 0, 0, -359, 0], [0, -2520, 0, 0, 0, 559, 0, 0], [0, 0, 0, 22671, 0, 0, 0, -51], [0, 0, 0, 17876, 0, 0, 0, 227], [0, 6632, 0, 0, 0, 539, 0, 0], [0, 0, 0, -3636, 0, 0, 0, 2004], [-1557, 0, 0, 0, 2631, 0, 0, 0], [0, 0, 0, 28316, 0, 0, 0, 1289], [0, 5028, 0, 0, 0, 1818, 0, 0], [29, 0, 0, 0, 1048, 0, 0, 0], [0, 0, -2720, 0, 0, 0, 3105, 0], [0, 2096, 0, 0, 0, -1576, 0, 0], [0, -900, 0, 0, 0, 2934, 0, 0], [-9783, 0, 0, 0, -579, 0, 0, 0], [19757, 0, 0, 0, 1296, 0, 0, 0], [0, 0, 0, 5528, 0, 0, 0, -1243], [0, 0, 0, 49446, 0, 0, 0, 402], [0, 0, -1330, 0, 0, 0, -1158, 0], [0, 0, -400, 0, 0, 0, -1187, 0], [0, 0, 0, -18934, 0, 0, 0, -43], [0, -6140, 0, 0, 0, -276, 0, 0], [0, 0, 0, -28744, 0, 0, 0, 407], [0, 6320, 0, 0, 0, 676, 0, 0], [0, 2436, 0, 0, 0, -1422, 0, 0], [0, 0, 0, -37863, 0, 0, 0, 75], [-38754, 0, 0, 0, 438, 0, 0, 0], [0, 0, 2000, 0, 0, 0, 998, 0], [0, -8493, 0, 0, 0, -1503, 0, 0], [0, 0, 3799, 0, 0, 0, 2346, 0], [-1969, 0, 0, 0, 970, 0, 0, 0], [-9963, 0, 0, 0, 1161, 0, 0, 0], [-13475, 0, 0, 0, -810, 0, 0, 0], [0, -11040, 0, 0, 0, 710, 0, 0], [0, 0, -1865, 0, 0, 0, -1056, 0], [0, 0, 7088, 0, 0, 0, -1945, 0], [0, -4280, 0, 0, 0, 243, 0, 0], [0, 0, 0, -16371, 0, 0, 0, -537], [-3827, 0, 0, 0, -1000, 0, 0, 0], [0, -8629, 0, 0, 0, -2397, 0, 0], [0, 0, 0, -11259, 0, 0, 0, 2367], [-3996, 0, 0, 0, -1548, 0, 0, 0], [0, 0, 2416, 0, 0, 0, 1333, 0], [0, 0, 0, -34994, 0, 0, 0, -1097], [0, 11, 0, 0, 0, 2787, 0, 0], [119, 0, 0, 0, 34, 0, 0, 0], [0, -3056, 0, 0, 0, -2078, 0, 0], [0, 0, -3520, 0, 0, 0, 1620, 0], [0, 0, 0, 27700, 0, 0, 0, -3159], [0, 9240, 0, 0, 0, 325, 0, 0], [0, 0, 0, -6741, 0, 0, 0, -2127], [0, 0, 4535, 0, 0, 0, -96, 0], [263, 0, 0, 0, 304, 0, 0, 0], [0, 0, 1632, 0, 0, 0, -4509, 0], [0, 0, 0, 29504, 0, 0, 0, -2137], [0, 12440, 0, 0, 0, 1151, 0, 0], [79038, 0, 0, 0, 534, 0, 0, 0], [-4003, 0, 0, 0, 958, 0, 0, 0], [0, 0, 0, -3634, 0, 0, 0, 1782], [0, 0, 0, 62235, 0, 0, 0, 225], [3510, 0, 0, 0, -306, 0, 0, 0], [0, 0, 640, 0, 0, 0, -4482, 0], [0, 1835, 0, 0, 0, 69, 0, 0], [0, 0, 0, -178, 0, 0, 0, 270], [0, 0, 0, -27918, 0, 0, 0, 54], [0, 0, 0, 45898, 0, 0, 0, -54], [0, -4360, 0, 0, 0, -6713, 0, 0], [0, 1555, 0, 0, 0, 8337, 0, 0], [0, 0, 0, 27423, 0, 0, 0, -1491], [-51201, 0, 0, 0, -453, 0, 0, 0], [0, 0, 0, 17408, 0, 0, 0, 2781], [0, 8248, 0, 0, 0, -2997, 0, 0], [0, -10183, 0, 0, 0, 1059, 0, 0], [0, 0, 5950, 0, 0, 0, -6528, 0], [0, 0, 0, -35948, 0, 0, 0, -1728], [0, 0, 0, -9711, 0, 0, 0, 1923], [0, 0, 8167, 0, 0, 0, -966, 0], [-28881, 0, 0, 0, 2667, 0, 0, 0], [-9439, 0, 0, 0, 324, 0, 0, 0], [0, 0, -4560, 0, 0, 0, 7263, 0], [0, -4640, 0, 0, 0, 3178, 0, 0], [11196, 0, 0, 0, 4668, 0, 0, 0], [0, -14720, 0, 0, 0, 864, 0, 0], [0, 0, 1485, 0, 0, 0, -2070, 0], [0, 0, 0, 22444, 0, 0, 0, 1153], [0, -6135, 0, 0, 0, 4977, 0, 0], [0, 0, 0, 10053, 0, 0, 0, 4191], [-28467, 0, 0, 0, 1329, 0, 0, 0], [0, 0, 0, 48206, 0, 0, 0, -1063], [0, -6192, 0, 0, 0, -5428, 0, 0], [0, 0, 10630, 0, 0, 0, 2472, 0], [26676, 0, 0, 0, -684, 0, 0, 0], [0, -9828, 0, 0, 0, 990, 0, 0], [0, 0, 0, -32553, 0, 0, 0, 789], [-88335, 0, 0, 0, 1605, 0, 0, 0], [-23569, 0, 0, 0, -4454, 0, 0, 0], [0, 0, -5520, 0, 0, 0, -1817, 0], [0, -3384, 0, 0, 0, -1063, 0, 0], [0, 4635, 0, 0, 0, 9513, 0, 0], [0, 0, 10238, 0, 0, 0, -5586, 0], [0, 0, -2400, 0, 0, 0, -8576, 0], [38972, 0, 0, 0, -494, 0, 0, 0], [0, 0, 0, -24662, 0, 0, 0, 1861], [0, 10520, 0, 0, 0, 3565, 0, 0], [0, -6975, 0, 0, 0, -1701, 0, 0], [0, -5869, 0, 0, 0, -2811, 0, 0], [0, 0, 0, -11178, 0, 0, 0, 450], [0, 0, 13850, 0, 0, 0, 1794, 0], [0, 0, 24560, 0, 0, 0, 837, 0], [0, 0, 0, 10764, 0, 0, 0, 5268], [0, 0, -166, 0, 0, 0, -744, 0], [0, 0, 20320, 0, 0, 0, -459, 0], [0, 995, 0, 0, 0, 501, 0, 0], [0, 0, -2057, 0, 0, 0, 6414, 0], [-42658, 0, 0, 0, 3736, 0, 0, 0], [0, 0, 0, -19654, 0, 0, 0, -4867], [43288, 0, 0, 0, 134, 0, 0, 0], [0, 0, 0, -90502, 0, 0, 0, 131], [0, -2120, 0, 0, 0, 1637, 0, 0], [0, -5060, 0, 0, 0, 210, 0, 0], [-17152, 0, 0, 0, -218, 0, 0, 0], [0, 2208, 0, 0, 0, 8370, 0, 0], [81477, 0, 0, 0, 1689, 0, 0, 0], [0, 0, 0, -34108, 0, 0, 0, -1288], [-17352, 0, 0, 0, -1752, 0, 0, 0], [0, 4305, 0, 0, 0, -5067, 0, 0], [0, 0, 11343, 0, 0, 0, -5148, 0], [107865, 0, 0, 0, 1485, 0, 0, 0], [54853, 0, 0, 0, -2026, 0, 0, 0], [0, 0, 4160, 0, 0, 0, 2476, 0], [0, 0, 0, 74608, 0, 0, 0, 567], [0, 0, 0, 87453, 0, 0, 0, 711], [0, 0, 6448, 0, 0, 0, -4617, 0], [0, 640, 0, 0, 0, -7606, 0, 0], [0, 0, 0, -72306, 0, 0, 0, -1350], [0, -3520, 0, 0, 0, 10430, 0, 0], [0, 9732, 0, 0, 0, 7200, 0, 0], [0, 0, -7600, 0, 0, 0, 4806, 0], [0, 0, 0, 44620, 0, 0, 0, 619], [0, 0, -6960, 0, 0, 0, 235, 0], [0, 8304, 0, 0, 0, -2170, 0, 0], [0, 0, 6749, 0, 0, 0, 5736, 0], [67813, 0, 0, 0, -1296, 0, 0, 0], [0, 0, -25440, 0, 0, 0, 2042, 0], [0, 0, 0, 56774, 0, 0, 0, 2414]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1728_f_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1728_4_f_g();".
// 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_1728_4_f_g(:prec:=8)
    chi := MakeCharacter_1728_f();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 4));
    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_1728_4_f_g();".
// 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_1728_4_f_g( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1728_f();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<5,R![14400, 0, -252, 0, 1]>,<7,R![133225, 0, 746, 0, 1]>,<23,R![20088, -306, 1]>],Snew);
    return Vf;
end function;