
// Make newform 1014.3.f.h in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1014_f();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_1014_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_1014_3_f_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_1014_3_f_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 := [5635876, 275384, 6728, -6736, 5053, 82, 2, -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, 1, 0, 0, 0, 0, 0, 0], [-561922481148, -589968133288, 914252484693, -13767350850, -167602931, -175318185, 125878448, -4081829], [2064275292409594, 744039515950798, 25228071565329, -699596394446, 452388400182, 263049796262, 9646046383, -207487050], [132247184234574, 61427229206294, 38906811708291, 372305475560, 30851132578, 24877044110, 13656504841, 186368592], [19380524092, 473587124, -473888448, 747057527, 5777701, 140781, -140821, 99170], [-378059897144086, -10968766639812, 6206066365669, 16756634760889, -237335849778, -3261499808, 3991178383, 5690069035], [30969513538197086, 1200974352327728, 24023479541963, -43834774990983, 11542895672784, 440871714386, 4995591495, -15163829403]];
    Rf_basisdens := [1, 1, 28390156409030, 965265317907020, 50803437784580, 23917570690, 965265317907020, 965265317907020];
    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_1014_f();"
function MakeCharacter_1014_f()
    N := 1014;
    order := 4;
    char_gens := [677, 847];
    v := [4, 3];
    // 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_1014_f_Hecke();"
function MakeCharacter_1014_f_Hecke(Kf)
    N := 1014;
    order := 4;
    char_gens := [677, 847];
    char_values := [[1, 0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 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, -1, 0, 0, 0, 0, 0], [0, 0, 0, -1, 0, 0, 1, 0], [0, -1, -1, -1, 0, 0, 0, 0], [-1, 0, 1, 0, 0, 1, 2, 0], [0, 0, 0, 0, 0, -2, -4, 0], [0, 0, 0, 0, 0, 0, 0, 0], [6, 1, 1, -7, 1, 1, -6, 0], [-6, 2, -6, -1, 1, 0, 1, 1], [-2, 0, 20, 0, 2, 0, 2, 0], [-10, 2, 0, 5, 0, -2, -2, 3], [-21, 1, -3, 17, 1, 0, 1, 1], [4, 0, -4, 0, 0, 5, -17, 0], [3, -1, -10, -10, -3, 0, -3, -3], [20, -2, 2, -19, -1, -2, -20, 0], [40, 0, -40, -2, 2, 2, -6, -2], [11, -1, 0, -18, 0, 1, 15, -3], [6, 0, -6, 4, -4, -2, -12, 4], [21, 3, 0, 18, 0, -3, -22, -4], [11, 3, -31, -43, 1, 0, 1, 1], [32, -2, 8, -20, -4, 0, -4, -4], [15, 0, -15, -1, 1, 6, -24, -1], [-12, 0, 0, -34, 0, 0, 39, 5], [14, 8, -18, -30, -2, 0, -2, -2], [67, 0, -67, -1, 1, 2, -77, -1], [34, 5, -36, -74, 4, 0, 4, 4], [-7, 6, 37, 2, 5, 6, 7, 0], [48, -10, -22, -39, -9, -10, -48, 0], [38, -4, 0, 2, 0, 4, 0, 2], [-106, 3, -40, 63, 3, 0, 3, 3], [-6, -12, 0, 11, 0, 12, -14, -3], [-16, 9, -84, 13, 3, 9, 16, 0], [-40, 2, 0, -36, 0, -2, 42, 6], [-111, 0, 111, 2, -2, -1, 123, 2], [-8, 5, 0, -20, 0, -5, 39, 19], [49, 1, 18, -34, 3, 0, 3, 3], [-26, 0, 26, 3, -3, -10, 7, 3], [40, 21, 0, -5, 0, -21, 5, 0], [45, 0, -45, 5, -5, 11, -13, 5], [40, 0, -40, 4, -4, 8, -60, 4], [40, -16, 4, -46, 6, -16, -40, 0], [18, -18, -60, 2, -20, -18, -18, 0], [68, 13, -121, -75, 7, 13, -68, 0], [108, 0, 0, 44, 0, 0, -58, -14], [-28, 0, 28, -9, 9, 14, -26, -9], [23, -14, -37, -63, 3, 0, 3, 3], [-42, 15, -64, 27, 15, 15, 42, 0], [-12, -12, 0, -46, 0, 12, 57, 11], [108, -10, -108, -203, -13, 0, -13, -13], [-98, 16, -42, 44, 12, 0, 12, 12], [-57, 0, 57, -20, 20, 44, -108, -20], [-16, -12, 100, -2, 18, -12, 16, 0], [206, -4, 54, -154, 2, 0, 2, 2], [185, 0, -185, 5, -5, -13, -200, 5], [44, -8, -52, -28, -16, -8, -44, 0], [31, -6, -157, -20, -11, -6, -31, 0], [86, 2, 0, 82, 0, -2, -86, -4], [-52, 14, 0, 184, 0, -14, -164, 20], [-183, 0, 183, -3, 3, 19, 103, -3], [-85, -12, 25, 82, 3, -12, 85, 0], [115, 0, -115, 10, -10, -15, -145, 10], [-22, -23, -156, 29, -7, -23, 22, 0], [-8, 0, 8, -1, 1, 31, 116, -1], [5, 0, -5, 28, -28, -25, 6, 28], [-70, 8, -156, 66, 4, 8, 70, 0], [236, 8, 0, 150, 0, -8, -145, 5], [-51, 17, -34, 18, -1, 0, -1, -1], [-185, 19, -143, 36, 6, 0, 6, 6], [-164, 0, 153, 188, -24, 0, 164, 0], [70, 22, 0, 126, 0, -22, -110, 16], [56, 0, -56, 35, -35, -27, -55, 35], [-144, -9, 171, 329, -14, 0, -14, -14], [-110, 0, 110, 0, 0, 24, 136, 0], [-126, 41, 0, 134, 0, -41, -109, 25], [-268, -16, 0, -99, 0, 16, 129, 30], [-15, -19, -53, -44, 6, 0, 6, 6], [-200, 44, -80, 104, 16, 0, 16, 16], [110, -9, -167, -91, -19, -9, -110, 0], [-48, 0, 48, 4, -4, -19, -66, 4], [70, 0, -70, 3, -3, -39, 112, 3], [91, -26, -140, -246, 15, 0, 15, 15], [-80, 16, 0, -112, 0, -16, 108, -4], [48, -8, 101, 77, -24, 0, -24, -24], [-106, -56, -106, 42, -42, 0, -42, -42], [-69, -15, 265, 111, -42, -15, 69, 0], [76, 54, 134, -91, 15, 54, -76, 0], [248, 26, 0, -160, 0, -26, 172, 12], [-95, 0, 95, 19, -19, -80, -77, 19], [-48, 44, 127, 155, 20, 0, 20, 20], [-133, -5, -166, -16, -17, 0, -17, -17], [-173, 0, 173, -9, 9, 71, 193, -9], [18, -22, -244, -36, 18, -22, -18, 0], [-20, 0, 20, -16, 16, 12, 168, -16], [282, -58, 46, -195, -41, 0, -41, -41], [14, 4, -520, 12, -26, 4, -14, 0], [88, -22, -180, -261, -7, 0, -7, -7], [-62, 34, 0, -2, 0, -34, -16, -18], [-321, 3, 84, 386, 19, 0, 19, 19], [-74, -20, 0, -125, 0, 20, 132, 7], [-298, -20, 0, -262, 0, 20, 276, 14], [-16, 0, 16, -33, 33, 34, 266, -33], [-558, 7, 0, 18, 0, -7, 5, 23], [453, 0, -453, -2, 2, -1, -133, -2], [224, -16, -240, -214, -10, -16, -224, 0], [124, -38, 456, -90, -34, -38, -124, 0], [122, -4, 104, -84, -38, -4, -122, 0], [-416, -19, -435, 8, -27, 0, -27, -27], [522, -50, 154, -354, -14, 0, -14, -14], [-44, 0, 44, 25, -25, -77, -302, 25], [248, 2, 0, 68, 0, -2, -82, -14], [-92, 64, 0, 137, 0, -64, -102, 35], [224, -14, 0, 156, 0, 14, -118, 38], [-319, 10, -572, -250, -3, 0, -3, -3], [155, 39, 436, 258, 23, 0, 23, 23], [-165, 0, 165, 27, -27, -31, 29, 27], [-293, 0, 293, -33, 33, 1, 121, -33], [226, -17, -429, -175, -51, -17, -226, 0], [569, -41, 507, -69, 7, 0, 7, 7], [192, -2, -536, -210, 18, -2, -192, 0], [-356, 22, 0, -176, 0, -22, 224, 48], [104, -58, 0, -144, 0, 58, 172, 28], [625, 0, -625, 13, -13, -2, -24, 13], [94, 35, 463, -120, 26, 35, -94, 0], [38, -4, 0, 36, 0, 4, 10, 46], [498, 0, -498, -6, 6, 2, 22, -6], [51, 9, 221, 206, -36, 0, -36, -36], [120, -46, -202, -114, -6, -46, -120, 0], [-276, 0, 276, -4, 4, 60, 223, -4], [24, -84, -348, 22, -46, -84, -24, 0], [-226, 17, 484, 273, -47, 17, 226, 0], [-81, 34, 246, 251, 76, 0, 76, 76], [176, 0, -176, 19, -19, -46, -229, 19], [-98, -14, -522, -484, 60, 0, 60, 60], [242, 2, -516, -134, -108, 2, -242, 0], [30, -18, 0, 552, 0, 18, -574, -22], [-175, 0, 175, -59, 59, 42, -63, -59], [-37, -24, 171, 254, -46, 0, -46, -46], [-601, -28, 15, 627, -11, 0, -11, -11], [323, 0, -323, 10, -10, -45, -148, 10], [88, -66, 158, -62, -26, -66, -88, 0], [-542, -14, 0, -245, 0, 14, 232, -13], [389, 15, 383, 15, -21, 0, -21, -21], [-269, 4, 291, 565, -5, 0, -5, -5], [-104, 48, -28, 96, 8, 48, 104, 0], [148, 0, -148, -24, 24, -28, 188, -24], [409, -19, -37, -413, 4, -19, -409, 0], [290, 0, -290, 20, -20, -30, -296, 20], [399, 0, -399, -28, 28, 56, 185, -28], [255, 12, -309, -302, 47, 12, -255, 0], [-106, -58, 0, 60, 0, 58, -81, -21], [196, -26, -48, -218, -26, 0, -26, -26], [-108, 67, 195, 310, -7, 0, -7, -7], [-327, -52, 233, 324, 3, -52, 327, 0], [-204, -39, 368, 237, -33, -39, 204, 0], [-356, 34, 0, 64, 0, -34, -50, 14], [368, 2, -712, -390, 22, 2, -368, 0], [464, -82, 0, 24, 0, 82, -24, 0], [436, -32, 0, -56, 0, 32, 16, -40], [90, -17, -437, -503, -24, 0, -24, -24], [-383, 31, 0, -52, 0, -31, 73, 21], [61, 108, 173, 99, 13, 0, 13, 13], [-332, 0, 332, 8, -8, -88, -332, 8], [120, 16, -476, -154, 34, 16, -120, 0], [734, 50, 178, -557, 1, 0, 1, 1], [72, -42, 0, -60, 0, 42, 12, -48], [-87, -87, -66, 82, -61, 0, -61, -61], [-166, 0, 166, 30, -30, -54, -166, 30], [-38, -16, 0, 202, 0, 16, -204, -2], [183, -34, 0, 412, 0, 34, -402, 10], [-726, 0, 726, 7, -7, -5, -103, 7], [-819, 2, 1013, 794, 25, 2, 819, 0], [478, 12, 494, 24, -8, 0, -8, -8], [-83, 0, 83, -7, 7, 7, -248, -7], [-260, 64, 768, 150, 110, 64, 260, 0], [-73, -76, 200, 249, 24, 0, 24, 24], [232, -8, -336, -124, -108, -8, -232, 0], [277, 103, 0, -194, 0, -103, 259, 65], [-645, 0, 645, 4, -4, -103, 594, 4], [383, 0, -383, 48, -48, 21, -463, 48], [338, -32, -250, -369, 31, -32, -338, 0], [564, -36, 0, 214, 0, 36, -217, -3], [74, 0, -74, -41, 41, -18, 107, -41], [644, 38, -444, -670, 26, 38, -644, 0], [1047, 57, 0, -150, 0, -57, 234, 84], [319, -8, 183, -165, 29, 0, 29, 29], [-48, 0, 48, 8, -8, -230, 40, 8], [-18, 65, 401, -13, 31, 65, 18, 0], [-250, 106, 32, 217, 33, 106, 250, 0], [528, -70, 400, -129, 1, 0, 1, 1], [-111, 0, 111, -73, 73, 8, -148, -73], [302, 0, -302, 68, -68, -88, -856, 68], [-112, -141, 0, -105, 0, 141, 75, -30], [318, 20, 146, -116, -56, 0, -56, -56], [-562, -35, 0, 18, 0, 35, -13, 5], [-769, 0, 769, -7, 7, -68, 777, -7], [-710, 24, 236, 688, 22, 24, 710, 0], [292, 32, 88, -236, -56, 32, -292, 0], [985, -38, 502, -491, 8, 0, 8, 8], [0, 14, 469, -82, 82, 14, 0, 0], [-7, 0, 7, 8, -8, -5, 267, 8], [-580, -46, 0, -412, 0, 46, 482, 70], [-782, 0, 782, -45, 45, 69, 412, -45], [-24, 23, 0, 576, 0, -23, -467, 109], [471, 68, 868, 429, -32, 0, -32, -32], [224, -119, 0, 39, 0, 119, -199, -160], [540, 0, -540, 22, -22, 206, -334, 22], [607, -95, 0, -514, 0, 95, 467, -47], [-257, 81, 97, 266, 88, 0, 88, 88], [396, 84, 0, -24, 0, -84, 92, 68], [-214, 57, 289, 487, 16, 0, 16, 16], [-28, -50, 592, -10, 38, -50, 28, 0], [-243, 25, 71, 367, -124, 25, 243, 0], [-1230, -12, 0, -380, 0, 12, 526, 146], [1794, -6, 0, 68, 0, 6, -39, 29], [64, 0, -64, -104, 104, 86, -204, -104], [-280, -24, -836, -480, -76, 0, -76, -76], [383, 0, -383, 51, -51, 49, 8, 51], [-164, 4, 0, 414, 0, -4, -445, -31], [-501, 147, 0, -18, 0, -147, 13, -5], [-470, -10, -1106, -616, -20, 0, -20, -20], [-261, 0, 261, -71, 71, 26, -571, -71], [515, 106, 0, -424, 0, -106, 558, 134], [685, 0, -685, -14, 14, -151, -620, -14], [-798, -75, -279, 541, -22, 0, -22, -22], [-743, 153, -401, 324, 18, 0, 18, 18], [-206, -80, 36, 410, -204, -80, 206, 0], [81, -60, -573, 11, -92, -60, -81, 0], [-25, -19, 0, -242, 0, 19, 49, -193], [832, -2, 0, 524, 0, 2, -464, 60], [-300, 95, -120, 251, 49, 95, 300, 0], [404, 0, -404, -38, 38, 0, 594, -38], [-958, 119, -129, 850, 108, 119, 958, 0], [-536, -151, 0, 268, 0, 151, -369, -101], [96, 250, 312, 143, 73, 0, 73, 73], [314, 129, 367, -479, 165, 129, -314, 0], [716, -147, 0, -708, 0, 147, 543, -165], [-386, -98, 474, 878, -18, 0, -18, -18], [82, 0, -82, 34, -34, 109, -508, 34], [-1211, 0, 1211, 0, 0, -41, 495, 0], [212, -58, 516, -220, 8, -58, -212, 0], [-1134, -36, 0, -22, 0, 36, -8, -30], [102, 16, -854, -1006, 50, 0, 50, 50], [-74, 28, -896, 0, 74, 28, 74, 0], [-10, -34, 0, -462, 0, 34, 254, -208], [-185, 12, -762, -636, 59, 0, 59, 59], [-800, 153, -883, -163, 80, 0, 80, 80], [556, -62, 864, -472, -84, -62, -556, 0], [15, 0, -15, 79, -79, -83, -119, 79], [682, 0, -682, -120, 120, 94, 180, -120], [381, 247, 455, -86, 160, 0, 160, 160], [-254, 84, 860, 214, 40, 84, 254, 0], [550, 0, -550, 22, -22, -217, -1180, 22], [339, 12, 1131, 679, 113, 0, 113, 113], [-354, 0, 354, 8, -8, -174, 116, 8], [-20, 60, 823, -76, 96, 60, 20, 0], [1140, -102, 0, -748, 0, 102, 690, -58], [100, 0, -100, -64, 64, -42, -756, -64], [528, -36, 0, 152, 0, 36, -172, -20], [118, -214, 126, -27, 35, 0, 35, 35], [52, 20, 1438, -26, -26, 20, -52, 0], [-153, 103, -796, -593, -50, 0, -50, -50], [-744, 98, 1608, 866, -122, 98, 744, 0], [544, 10, 0, 1016, 0, -10, -940, 76], [366, -142, -305, -573, -98, 0, -98, -98], [-889, 70, 0, 276, 0, -70, -166, 110], [729, 0, -729, 84, -84, 71, -1019, 84], [234, -102, 0, 56, 0, 102, 13, 69], [-793, -104, 527, 1429, -109, 0, -109, -109], [-1083, 225, 12, 970, 125, 0, 125, 125], [1194, 0, -1194, -95, 95, -82, -711, -95], [483, 28, -581, -388, -95, 28, -483, 0], [619, -107, 493, -525, -94, -107, -619, 0], [-385, 23, -143, 208, 34, 0, 34, 34], [1060, 0, -1060, -12, 12, 57, -129, -12], [-440, -112, -296, 600, -160, -112, 440, 0], [772, 76, 0, -142, 0, -76, 297, 155], [-482, -90, -990, -465, -43, 0, -43, -43], [242, -238, -6, -96, -152, 0, -152, -152], [-115, 0, 115, -79, 79, 175, -40, -79], [-753, 0, 753, 55, -55, 218, 312, 55], [138, -132, 1020, 10, -148, -132, -138, 0], [-1674, -108, 0, 498, 0, 108, -640, -142], [980, 0, -980, 9, -9, 102, -1319, 9], [744, -150, 0, -464, 0, 150, 262, -202], [1228, 186, -47, -1304, 29, 0, 29, 29], [1378, 0, -1378, -83, 83, -150, -1575, -83], [-670, 90, 220, 492, 178, 90, 670, 0], [1673, 47, 0, -86, 0, -47, 130, 44], [479, 207, -188, -630, -37, 0, -37, -37], [307, 0, -307, -40, 40, -195, -254, -40], [457, 76, -1491, -678, 221, 76, -457, 0], [-758, -32, 0, 372, 0, 32, -266, 106], [722, 110, 0, 938, 0, -110, -924, 14], [-582, -25, -949, -401, 34, 0, 34, 34], [-1190, 0, 1190, 26, -26, -206, -154, 26], [400, 47, 0, -748, 0, -47, 785, 37], [-490, 125, 615, 527, -37, 125, 490, 0], [456, 82, 0, 832, 0, -82, -818, 14], [542, -189, 847, -383, -159, -189, -542, 0], [-472, 20, 0, -340, 0, -20, 470, 130], [969, 0, -969, -72, 72, 7, -926, -72], [-53, -116, -2235, 91, -38, -116, 53, 0], [828, 0, -828, -5, 5, -115, 734, -5], [-310, -74, 1076, 458, -148, -74, 310, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1014_f_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1014_3_f_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_1014_3_f_h(:prec:=8)
    chi := MakeCharacter_1014_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(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_1014_3_f_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_1014_3_f_h( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1014_f();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<5,R![5253264, -632592, 38088, 11916, 4065, -282, 18, 6, 1]>,<7,R![4426816, -117824, 1568, 1672, 6817, -154, 2, 2, 1]>],Snew);
    return Vf;
end function;