
// Make newform 1008.3.cg.p in Magma, downloaded from the LMFDB on 23 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1008_cg();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_1008_cg_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_1008_3_cg_p();".
// 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_1008_3_cg_p();".
// 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 := [529, -230, -153, -18, 78, -2, -7, -2, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0, 0], [-1034839, -193196, 469674, 213594, -71462, -33756, 873, 4244], [-1188686, 796111, 623641, 94716, -96948, -38294, 6667, 3371], [3637, -207, 1608, 488, -414, -222, 41, 33], [-816983, 378248, -31292, 324398, -30829, -27942, -4954, 6088], [3514676, 215444, -974856, -443336, 173218, 70064, -1812, -6546], [2603393, 2146717, -162453, -997968, -29696, 121832, 30909, -11533], [10829159, -3864944, -3003654, -1365974, 916372, 215876, -5583, -45244]];
    Rf_basisdens := [1, 658490, 329245, 2045, 329245, 329245, 329245, 658490];
    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_1008_cg();"
function MakeCharacter_1008_cg()
    N := 1008;
    order := 6;
    char_gens := [127, 757, 785, 577];
    v := [6, 6, 6, 5];
    // 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_1008_cg_Hecke();"
function MakeCharacter_1008_cg_Hecke(Kf)
    N := 1008;
    order := 6;
    char_gens := [127, 757, 785, 577];
    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], [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 := [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [1, -1, 0, 0, 0, 0, 1, 0], [-1, -1, -1, -1, 1, 0, 0, 0], [-5, 6, 0, 0, 0, -1, -2, -1], [-1, 3, 0, -1, 0, 2, -1, -1], [-2, -5, -2, -2, -1, 1, 0, -1], [-6, 4, 3, 1, -2, 5, 0, 0], [1, 10, -1, -2, -4, 4, 1, 2], [-9, -2, -5, 0, 1, -3, 0, 0], [3, 7, 0, -6, 0, 3, 0, 4], [1, -30, 0, -9, 0, 9, -1, -2], [8, -14, 2, 4, -6, -6, 2, 2], [10, 6, 5, -1, -1, 3, -4, 4], [-1, 0, 3, -6, -2, -2, 3, 0], [-1, 4, 0, 0, 0, -16, -6, -3], [-3, -9, -6, 16, -3, -8, 0, 0], [4, -8, 0, -8, 0, -8, 12, 0], [-2, 6, 4, -2, -5, -14, -4, -2], [-49, 3, 5, -28, -1, 3, -1, 1], [-10, -15, -4, 34, -2, -17, 0, -1], [-2, -43, -2, 27, -8, -23, 6, 12], [7, -12, -1, 3, 3, -7, -4, -4], [8, -10, -6, -4, 4, -12, 8, 0], [-46, 107, 4, 7, -12, -10, -7, -7], [-16, -16, 4, -28, 2, 14, 0, -4], [12, -18, -15, 13, 10, -7, 14, 0], [0, 79, -1, 5, -4, -3, 2, 4], [16, -7, 0, 0, 0, 11, -18, -9], [-123, 3, -5, 30, 1, -3, -5, 5], [31, -14, -20, 25, 4, -12, 6, -6], [11, -11, -12, 11, 8, -5, 3, 0], [0, -4, 0, 0, 0, -42, 8, 4], [-2, 2, 5, -19, -15, 43, 12, 12], [-16, 86, 2, -10, 8, 6, 12, 24], [97, -93, -4, 2, 5, -23, -12, -6], [4, 16, 8, 64, 4, -32, 0, 4], [-4, -88, 2, 40, 8, -44, 0, 0], [85, -145, 7, -18, -21, 43, -11, -11], [-89, 60, 21, -22, -14, 6, -17, 0], [16, -33, -20, 10, 25, -33, 14, 7], [-57, 89, -2, 3, 6, -8, 21, 21], [-7, -22, 1, 18, 4, -20, 5, 10], [9, -3, 0, 0, 0, -4, -12, -6], [-3, 7, 25, 8, -5, 15, 3, -3], [-28, -24, 8, -36, 4, 18, 0, -4], [204, 4, 10, -18, -2, 6, 0, 0], [-81, 166, 1, -26, -3, 53, -2, -2], [29, 12, 0, -26, 0, 13, 0, -17], [49, -20, 42, -37, -28, 19, 19, 0], [27, 72, -7, -14, -28, 28, -13, -26], [54, -14, -20, 44, 4, -12, 6, -6], [-153, -146, -8, -10, -4, 5, 0, 15], [-55, 64, 3, -13, -9, 29, 52, 52], [-287, 126, -33, -2, 22, -46, 13, 0], [46, -44, -16, 8, 20, -60, -20, -10], [-73, -103, 18, 78, 9, -39, 0, -48], [100, -41, 3, 50, -2, 54, -16, 0], [320, -315, 24, -12, -30, -7, 14, 7], [-163, -15, -15, -24, 3, -9, 9, -9], [-132, -104, 18, 12, 9, -6, 0, 10], [-25, -2, -15, -10, 45, 5, 22, 22], [-116, 174, -17, 23, 51, -63, 24, 24], [-18, -10, 8, -84, 4, 42, 0, 0], [84, -37, -18, -18, 12, -42, -22, 0], [-18, 17, 3, -134, 12, 128, 12, 24], [38, 154, -7, 37, -28, -23, -24, -48], [213, -34, -60, 72, 12, -36, 10, -10], [276, -233, 36, -18, -45, 79, -50, -25], [36, -60, 8, -10, -24, 28, 4, 4], [40, 27, 10, 158, 5, -79, 0, -23], [-38, 96, 6, 74, 24, -86, 26, 52], [-43, -7, -12, -22, -6, 11, 0, 48], [33, -126, -10, -77, -40, 97, -13, -26], [-36, 32, -25, -29, 5, -15, -42, 42], [11, -30, -45, 74, 30, 14, 19, 0], [-64, 65, -12, 6, 15, 165, -14, -7], [-89, 30, -72, 21, 48, -75, -19, 0], [-33, 94, 17, -8, 68, -26, -1, -2], [-209, -217, 8, 72, 4, -36, 0, -16], [-64, 144, -14, 10, 42, -34, -44, -44], [-453, 1, 40, -23, -8, 24, 15, -15], [32, -85, -20, 10, 25, -15, 86, 43], [-37, 87, 8, 61, -24, -114, 3, 3], [-60, 59, 111, -62, -74, 86, 16, 0], [20, 69, -7, -23, -28, 37, -6, -12], [-97, -29, -95, 66, 19, -57, -9, 9], [16, 139, 8, 36, 32, -52, -32, -64], [-150, 334, 18, -42, -54, 102, 2, 2], [22, -38, 35, -59, -7, 21, 52, -52], [11, 0, 15, -6, -10, 14, -1, 0], [-70, -109, -26, 102, -13, -51, 0, -13], [83, -125, -40, 20, 50, -51, 44, 22], [68, -11, 40, -59, -8, 24, 27, -27], [10, -24, 11, 93, 44, -115, -32, -64], [-218, 400, -4, 48, 12, -100, 28, 28], [-181, 85, -12, -74, 8, -90, 3, 0], [46, -56, -40, 76, -20, -38, 0, -62], [-182, 50, -27, 47, 18, 11, 64, 0], [-65, 90, 24, 11, 96, -59, 17, 34], [-370, -28, -40, -14, 8, -24, 12, -12], [359, -383, 52, -26, -65, -63, 100, 50], [-227, -281, -50, 4, -25, -2, 0, -4], [-14, -278, -14, 130, -56, -102, 42, 84], [258, -232, 44, -22, -55, 66, -8, -4], [-109, -75, -12, 112, -6, -56, 0, 46], [-92, 239, 34, -79, -102, 192, 13, 13], [-166, 104, -48, 40, 32, -24, -74, 0], [600, -594, -8, 4, 10, -124, -20, -10], [-107, 180, 22, -66, -66, 154, 78, 78], [-396, 169, -96, 87, 64, -41, -6, 0], [448, -418, 0, 0, 0, 68, -60, -30], [-244, -28, -70, -90, 14, -42, 0, 0], [-106, -156, 2, -176, 1, 88, 0, -52], [-61, -16, 25, 102, -5, 15, 26, -26], [698, -687, -4, 2, 5, -77, -26, -13], [182, -484, -5, 9, 15, -23, 110, 110], [-156, -208, -52, -128, -26, 64, 0, 0], [36, 303, -19, 48, -76, -10, 2, 4], [189, -29, -95, 60, 19, -57, -9, 9], [4, 21, -32, -54, -16, 27, 0, 49], [75, 38, 110, -168, -22, 66, 6, -6], [-116, 71, 27, 32, -18, 68, -8, 0], [149, -157, 36, -18, -45, 146, 52, 26], [332, -100, 117, -81, -78, 75, -54, 0], [534, 35, 10, -14, -2, 6, -31, 31], [40, 6, -24, -176, -96, 224, 8, 16], [-234, 78, -66, -16, 44, -104, 34, 0], [1, 158, 28, 61, -84, -94, -104, -104], [-489, 276, 18, -15, -12, 9, -51, 0], [-208, 236, -36, 18, 45, -122, -92, -46], [274, -62, 20, -136, -4, 12, 70, -70], [-16, 537, 14, 83, 56, -111, -12, -24], [-706, -58, -80, 26, 16, -48, 26, -26], [-129, 72, 93, 22, -62, 146, 47, 0], [357, -760, -8, -52, 24, 96, 30, 30], [-208, -292, -20, 4, -10, -2, 0, -64], [-124, -50, -20, 28, -10, -14, 0, 94], [-364, 717, -2, 16, 6, -34, 7, 7], [638, -629, 44, -22, -55, -75, 26, 13], [-8, 68, 16, 50, -48, -84, -20, -20], [-17, -277, 4, 122, 16, -130, 9, 18], [-270, 244, 8, -4, -10, -226, 60, 30], [125, 40, -25, -129, 5, -15, -50, 50], [140, 159, 36, 226, 18, -113, 0, -17], [-426, 884, 34, -106, -102, 246, 36, 36], [199, -221, 38, -11, -114, 60, -101, -101], [248, 206, 44, -388, 22, 194, 0, -86], [184, -110, 42, -170, -28, -114, 64, 0], [-68, -454, 24, -76, 96, 28, 20, 40], [-16, -260, -14, 346, -56, -318, 44, 88], [17, -165, -27, -180, 81, 333, 77, 77], [-616, 12, 15, 263, -3, 9, -6, 6], [-902, 528, 144, -192, -96, 0, -58, 0], [322, -260, 84, -42, -105, -116, -40, -20], [447, 63, 75, -42, -15, 45, -33, 33], [-66, 48, 7, 63, 28, -77, 52, 104], [-475, 182, -69, -32, 46, -124, 65, 0], [-165, 288, -28, 18, 84, -64, -14, -14], [-823, -758, 40, -44, 20, 22, 0, 25], [-96, 770, 36, 152, 144, -224, 24, 48], [-361, 65, 115, 96, -23, 69, -19, 19], [-105, 36, -80, 171, 16, -48, -68, 68], [642, -279, 51, -93, -34, -25, -50, 0], [814, -718, 32, -16, -40, 80, -160, -80], [102, 163, 22, 174, 11, -87, 0, 39], [59, -43, -112, 56, 140, -155, -144, -72], [-218, -97, -24, -70, -12, 35, 0, 145], [195, -42, -60, -166, 12, -36, 18, -18], [528, -275, -111, 98, 74, -50, -52, 0], [-275, 304, -16, 8, 20, -359, -74, -37], [278, -548, 10, -100, -30, 210, 12, 12], [0, -470, 2, -242, 8, 238, -4, -8], [103, -3, 136, -68, -170, 364, -64, -32], [75, 145, 48, 266, 24, -133, 0, 22], [12, 52, -4, -108, 12, 212, -84, -84], [-562, 122, 175, -235, -35, 105, -52, 52], [-755, 638, -32, 16, 40, -154, 202, 101], [108, -248, -8, -102, 24, 196, 16, 16], [-29, -30, 66, 127, -44, 215, 133, 0], [50, 339, 0, -305, 0, 305, -50, -100], [280, -481, -34, -29, 102, 24, -147, -147], [139, 21, -20, 31, 4, -12, -29, 29], [-233, 140, 9, 130, -6, 142, -41, 0], [-530, 450, -144, 72, 180, -236, 16, 8], [221, 189, -58, -14, -29, 7, 0, 26], [518, -634, -80, 40, 100, 150, 152, 76], [-78, -158, 30, 184, 15, -92, 0, -110], [-142, 167, 28, -32, 112, -24, 86, 172], [506, 366, 8, -144, 4, 72, 0, -148], [198, -47, 78, 206, -52, 310, -52, 0], [-631, -40, 95, 27, -19, 57, 78, -78], [-98, -382, 22, -234, 88, 190, 54, 108], [-423, 224, -57, 14, 38, -62, -63, 0], [801, -969, -108, 54, 135, 4, 228, 114], [530, 624, 40, 192, 20, -96, 0, 54], [-618, 643, -72, 36, 90, -163, -122, -61], [50, 144, -24, 58, -96, -10, -2, -4], [364, -666, 10, 200, -30, -390, -42, -42], [-431, 256, 27, -68, -18, -32, -63, 0], [-91, 47, -164, 82, 205, -79, -76, -38], [-222, 348, -7, 31, 21, -69, 82, 82], [-798, 316, -186, 90, 124, -158, 42, 0], [-4, 158, 180, -364, 90, 182, 0, -18], [664, -1244, -30, 178, 90, -386, -144, -144], [-163, -265, 22, 574, 11, -287, 0, -124], [-228, 24, -48, -138, 32, -202, 148, 0], [-53, 1425, -18, -215, -72, 251, 89, 178], [-802, 52, -10, -216, 2, -6, -56, 56], [-46, -174, -76, 212, -38, -106, 0, -52], [23, -154, -28, 493, -112, -437, 33, 66], [547, -984, 53, -102, -159, 257, -4, -4], [-569, 4, 85, -338, -17, 51, 30, -30], [1180, -551, 45, -175, -30, -115, -48, 0], [534, 599, -10, -150, -5, 75, 0, 75], [205, 26, 168, -53, -112, 171, -145, 0], [897, -957, -100, 50, 125, -237, 20, 10], [-592, -266, 228, -472, 114, 236, 0, 98], [69, 126, -25, 286, -100, -236, -19, -38], [597, -149, -65, 142, 13, -39, 123, -123], [111, -528, -8, 109, -32, -93, -95, -190], [-16, -34, -5, 95, 15, -195, 56, 56], [181, -142, -15, 134, -60, -104, -151, -302], [52, -825, -11, -60, -44, 82, -30, -60], [298, -689, -50, 35, 150, -120, -7, -7], [288, -144, -90, 46, 18, -54, 108, -108], [1186, -576, 54, -106, -36, -34, 2, 0], [-360, 344, -168, 84, 210, -256, -136, -68], [432, -129, -24, -85, 16, -117, -190, 0], [1, 948, 35, -324, 140, 254, -71, -142], [-288, 327, 104, -52, -130, -365, 26, 13], [-194, -208, -48, 444, -24, -222, 0, 34], [1095, 150, 110, -71, -22, 66, -106, 106], [-106, 94, 64, -32, -80, 390, 88, 44], [130, -402, -13, 35, 39, -83, 116, 116], [372, 381, -66, 558, -33, -279, 0, 75], [-434, 221, -60, 304, 40, 224, -48, 0], [-116, 321, -21, -132, -84, 174, 158, 316], [-1342, 4, 90, -186, -18, 54, 32, -32], [989, -1817, 87, -50, -261, 187, 13, 13], [140, -217, -36, 18, 45, -449, 118, 59], [-238, 224, -51, -99, 34, -167, -244, 0], [239, 191, -92, -194, -46, 97, 0, 44], [12, -1416, 2, -124, 8, 120, -16, -32], [544, -884, 32, -258, -96, 548, -140, -140], [-1747, 798, -39, 76, 26, 24, 125, 0], [-733, 1572, 34, -103, -102, 240, -38, -38], [-444, -203, 86, -270, 43, 135, 0, 155], [-720, 774, -48, 24, 60, 58, -156, -78], [30, -112, -210, 256, 42, -126, 28, -28], [263, -119, -190, -111, 38, -114, 43, -43], [-1743, 956, 51, -164, -34, -96, -135, 0], [-1848, 1908, 40, -20, -50, 198, -80, -40], [-531, 1073, -4, -25, 12, 46, -19, -19], [273, 59, -102, -430, -51, 215, 0, -112], [-43, 919, 12, -69, 48, 45, 19, 38], [514, -577, -48, 24, 60, 183, 78, 39], [52, 344, -74, -84, -37, 42, 0, 366], [128, -267, 16, 28, -48, -40, 43, 43], [-811, 435, 42, -413, -28, -357, -31, 0], [628, -692, -36, 18, 45, -44, 92, 46], [-384, -247, -340, 37, 68, -204, 111, -111], [-506, -617, -152, 130, -76, -65, 0, 41], [627, -1183, 24, -135, -72, 294, -23, -23], [80, -228, -324, 64, -162, -32, 0, 16], [1910, -966, -249, -35, 166, -367, -144, 0], [-1623, 54, -65, 342, 13, -39, -80, 80], [425, -865, -29, 18, 87, -65, -43, -43], [1490, -216, -180, 204, 36, -108, 144, -144], [-549, 815, 236, -118, -295, 43, -296, -148], [-265, 142, 0, -155, 0, -155, -19, 0], [-290, 224, -24, 12, 30, -360, 108, 54], [551, 451, -20, 176, -10, -88, 0, -80], [-6, 137, 0, 303, 0, -303, 6, 12], [534, -1145, -64, 159, 192, -382, -51, -51], [124, 20, 168, -262, -112, -38, -52, 0], [-94, -47, -27, 395, -108, -341, 148, 296], [-1216, 1135, -104, 52, 130, -475, 58, 29], [71, -286, -50, -541, -200, 641, 29, 58], [483, -156, 69, 236, -46, 328, -125, 0], [552, 592, -104, 136, -52, -68, 0, 144], [-1165, 1177, -24, 12, 30, -129, -48, -24], [322, -414, 48, -84, -144, 216, -134, -134], [-451, 719, -118, 49, 354, -216, -53, -53], [-340, 200, 240, 90, -160, 410, 100, 0], [-24, -1886, 0, 28, 0, -28, 24, 48], [55, 79, -56, 28, 70, -332, -324, -162], [-350, -257, -180, -160, 36, -108, 185, -185], [23, -51, -20, -494, -10, 247, 0, -54], [299, -379, 121, -24, -363, 169, 23, 23], [-786, 712, 128, -64, -160, 498, 276, 138], [415, 322, 32, 610, 16, -305, 0, -125], [-17, 74, 11, 206, 44, -228, -5, -10], [370, -374, -6, 64, 18, -134, -378, -378], [133, 51, -110, -61, 22, -66, -95, 95], [1191, 1241, 10, 106, 5, -53, 0, 40], [588, -434, -201, 607, 134, 339, 146, 0], [-129, 389, 47, 368, -141, -689, -37, -37], [2491, -1248, 3, 46, -2, 50, 7, 0], [-6, 298, 7, 185, -21, -363, -272, -272], [-266, 76, -270, -80, 180, -440, -66, 0], [102, 361, -31, -470, -124, 532, -40, -80], [-249, 237, -140, 70, 175, -303, -116, -58]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1008_cg_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1008_3_cg_p();".
// 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_1008_3_cg_p(:prec:=8)
    chi := MakeCharacter_1008_cg();
    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_1008_3_cg_p();".
// 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_1008_3_cg_p( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1008_cg();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<5,R![913936, 195024, -48268, -13260, 2861, 390, -53, -6, 1]>,<11,R![17875984, -5597872, 1934780, -129100, 26749, 1702, 527, 22, 1]>,<13,R![2408704, 0, 429344, 0, 19817, 0, 262, 0, 1]>],Snew);
    return Vf;
end function;