
// Make newform 4018.2.a.bq in Magma, downloaded from the LMFDB on 23 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_4018_a();"
// To make the coeffs of the qexp of the newform in the Hecke field type "qexpCoeffs();"
// To make the newform (type ModFrm), type "MakeNewformModFrm_4018_2_a_bq();".
// 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_4018_2_a_bq();".
// 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 := [1, -6, 5, 8, -5, -2, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0], [1, -4, -1, 1, 0, 0], [-3, 6, 7, -5, -2, 1], [-5, 5, 8, -5, -2, 1], [-5, 13, 10, -11, -3, 2]];
    Rf_basisdens := [1, 1, 1, 1, 1, 1];
    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_4018_a();"
function MakeCharacter_4018_a()
    N := 4018;
    order := 1;
    char_gens := [493, 785];
    v := [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;

function MakeCharacter_4018_a_Hecke(Kf)
    return MakeCharacter_4018_a();
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 := 2;
    raw_aps := [[1, 0, 0, 0, 0, 0], [1, 0, 1, 1, -1, 0], [2, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 0], [-1, 2, -1, 0, 0, 0], [1, 0, -1, 1, -1, 0], [3, -1, 0, 0, 1, -2], [1, 2, -1, -1, 1, 0], [2, 1, 1, 0, -2, 1], [0, 1, 1, 2, 1, 1], [-1, -1, -2, -3, -1, 3], [-4, -2, -2, 0, 0, 2], [-1, 0, 0, 0, 0, 0], [1, 0, 1, -3, -1, -1], [-3, 1, 0, -4, -1, 0], [-3, -3, -4, -4, 2, 2], [2, 0, -2, -6, 1, 6], [5, -1, -2, -1, 2, 1], [-3, 3, 4, 0, 2, -2], [3, -3, 0, 2, -1, -3], [3, -1, 0, -1, 1, 1], [0, 0, 0, 2, -2, 2], [4, 4, 0, 2, -3, -2], [2, -3, -1, -1, 2, -2], [0, 8, 4, 4, 2, -4], [-3, 3, 2, 0, 3, 2], [4, -2, 2, 2, -4, 2], [3, -6, -1, 1, -3, 1], [-2, 2, 2, -2, -1, -1], [-4, 5, 1, 4, 0, -1], [4, -3, -3, 0, 2, -3], [1, -5, -4, -3, 0, -1], [1, 1, 0, -6, 3, 1], [0, 0, 2, -5, 1, 0], [-10, 1, -1, 2, 3, -3], [-8, -5, -3, -2, 4, -2], [-1, 1, -2, 2, -5, 2], [2, -4, -2, -4, 4, 6], [2, -1, 1, 5, 0, 2], [8, -6, 2, -1, 1, 6], [-9, -5, -2, -4, -6, 2], [9, -3, 0, -4, -5, 4], [-4, 0, 0, -2, 0, 6], [0, 1, -3, -8, 8, -2], [-2, -4, -2, -4, 4, 4], [-9, 3, 0, 4, 1, 0], [1, -4, 3, -4, 2, -4], [1, 3, -2, -6, 5, 1], [15, 1, 2, 4, 1, -6], [7, -9, -4, 0, 1, 0], [2, -4, -4, 2, -4, -2], [-10, -1, -1, -2, -2, 4], [10, 0, 0, 0, -2, -6], [11, -5, 4, -4, 2, -7], [-6, 5, -5, 1, 2, 6], [-7, 11, 4, 2, 3, -3], [4, 2, 2, -11, -1, 0], [-6, -2, 6, 9, -4, 0], [2, 4, 6, 2, 4, 2], [5, 9, 4, 4, 1, -5], [-3, -7, -2, -5, 0, -5], [5, -1, 2, 18, -7, -2], [-1, 3, -6, -5, 6, 1], [-11, -1, -2, 2, 7, -4], [5, -3, 2, -2, 7, 4], [-7, 0, -3, -12, 8, 0], [3, -3, 0, 2, -2, -4], [-10, 8, 8, -4, 8, -2], [-11, 6, 1, 4, 4, 0], [-6, 0, 2, 11, 1, 2], [-8, -6, 0, -6, -8, 2], [1, 2, 7, 3, -7, 5], [-13, 5, 4, -5, 3, 1], [7, -6, -3, 11, -1, -3], [10, 0, 2, 2, 6, 0], [2, -9, -1, -1, 4, 4], [2, -4, 0, 10, 4, -8], [-15, 1, -2, 12, 3, -6], [14, -9, 1, 0, -2, -5], [-5, 11, 10, 4, 9, -7], [-12, 2, -4, 7, -11, -2], [2, 1, -1, -4, 1, -5], [-8, -11, -5, 2, 0, 11], [-5, 3, -10, 2, -1, 3], [-3, -1, -6, -8, -1, 10], [3, -8, 3, -7, -3, -5], [-11, 2, -3, 7, -5, 5], [-2, 1, 3, 8, 2, 10], [-19, 3, 0, -2, 2, -1], [-9, 7, -2, -2, -5, 5], [1, 13, 8, 4, 2, -5], [-7, 1, 6, 4, -1, 0], [13, -2, -5, -1, 1, 5], [13, -10, -3, 9, -11, 1], [2, 10, 4, 10, 1, -5], [0, -8, -12, -10, -4, 6], [-3, 15, 6, 4, -1, -10], [7, -9, -8, -2, -3, 2], [9, -11, 4, 6, -8, -3], [-4, 10, -6, -2, -4, 0], [-8, 1, -5, -2, 3, 1], [3, -9, -4, -4, -6, 2], [11, 7, 0, 0, 9, -4], [-4, 9, 3, -6, 2, 3], [12, 8, 12, 16, -7, -11], [-15, 1, -12, 0, -1, 10], [-11, -5, 2, -2, -3, 4], [10, -10, 2, 4, -4, -2], [-5, 0, -1, 3, -9, -5], [-1, -7, -6, -8, -7, -4], [-8, 10, 4, 11, 10, -14], [15, -6, -3, -13, -7, 7], [16, 5, -3, -14, 4, -7], [24, -10, -2, -4, -5, 0], [7, 1, -4, 1, 9, 8], [-5, -10, -11, 8, 1, 11], [-3, -9, 2, 2, -1, -10], [19, 1, 10, 8, -9, 3], [-7, -6, -5, -8, -8, -6], [7, -11, 12, 18, -14, -8], [-5, 3, 0, -1, 6, 5], [-4, 4, -2, -4, -8, -2], [17, 5, 10, 6, -2, -7], [-4, 6, 2, -2, 9, -5], [3, -17, 4, 4, 3, -4], [-9, -8, 5, 5, -11, -9], [-11, -7, -8, 2, -16, 6], [-6, -1, 11, 11, 8, -6], [8, 11, 5, 13, 2, 0], [1, -9, 0, 0, -10, 3], [-1, 18, 21, 7, 5, -11], [-12, 10, 2, 4, 8, -8], [17, 6, 5, 4, 3, -7], [-13, 0, 7, 16, -4, -10], [9, -7, -4, 17, 1, 5], [2, 10, 12, 7, -2, -6], [-1, -2, -11, -15, 5, 2], [-4, -14, -2, -10, 5, 4], [22, -2, -4, -5, 3, -2], [-12, 3, -1, 2, -12, -6], [12, -2, 16, 13, -13, -4], [-13, 10, 3, 5, 3, -1], [-2, -10, 0, -14, 2, -8], [-16, 2, -10, 4, -9, 5], [-17, -1, -2, 2, -14, 11], [-9, -3, 4, 0, -11, -6], [10, -12, 2, 13, -9, -8], [9, 7, 12, 2, 1, -11], [2, -8, 4, 11, 9, -2], [9, 2, 1, -9, -5, 15], [-12, 0, -4, -2, -2, 10], [4, 16, 18, 4, 0, -10], [-7, 0, -1, 10, -4, 14], [13, 17, 6, 2, -5, -14], [-17, 8, -1, -5, 9, -3], [-16, 17, 3, -10, 4, 11], [17, -3, 2, -16, 3, 17], [4, -3, -13, -13, 8, 18], [8, 2, -6, -10, -2, 16], [-11, 7, -2, -11, 8, 13], [4, 2, 24, 6, -6, -12], [5, -13, 4, 15, 1, 4], [1, 0, -5, -18, 1, 1], [5, 4, -5, 3, -7, 4], [2, -2, -18, -10, 12, 14], [2, 8, -16, -17, 4, 14], [11, 3, -14, -16, 7, 7], [-21, -2, -5, 13, -13, 12], [6, -16, -12, -2, -16, 6], [5, -5, 4, 16, -9, -16], [12, -1, 5, 18, -3, -7], [3, 7, 2, 10, 10, -11], [0, -2, -10, -4, -4, 2], [-17, -5, -4, -3, 1, -4], [-20, 3, 9, 19, 6, -16], [1, 1, 6, 4, 7, -16], [4, 2, 6, -22, -3, -1], [31, -2, 1, 5, -9, -1], [5, -11, -2, 2, -5, -6], [5, -4, -3, -11, 13, -2], [-5, 2, 1, -17, -1, 3], [5, 11, 12, 19, -4, -5], [-4, 10, 12, 2, -7, -11], [12, 6, 4, 30, -2, -4], [-18, 6, -8, 6, -2, -2], [8, 0, 6, 14, -9, -16], [6, 2, 6, 12, 0, -18], [12, 12, 6, 1, 11, 4], [-6, 14, 6, -6, -4, -6], [-6, -15, -5, -7, -12, 2], [-10, 4, 8, -10, 8, 4], [-6, -8, -6, -16, 3, 13], [-1, -10, 13, 1, -1, -7], [19, -3, -6, -5, 2, 5], [-5, 8, -1, 9, 7, -13], [22, -2, -4, -17, 6, 16], [-24, -5, -17, -18, 6, 16], [-15, -1, -10, 12, -4, 6], [-7, -15, -20, -16, 3, 12], [25, 5, 4, 8, 7, -2], [-14, 16, 16, 8, -2, -8], [-15, -15, -20, -8, 11, 1], [-11, 14, 3, -19, 9, -8], [8, 10, 8, 18, -2, -4], [-9, 10, 7, 13, 1, -6], [21, -11, 4, -16, 3, 12], [-2, -10, 4, -4, 8, -8], [-18, 12, -2, -10, 7, -5], [16, 11, 15, 6, -12, 13], [-8, 8, 4, -10, -11, 14], [-2, -7, -21, -4, -2, -2], [-3, -14, 5, 5, -11, 8], [6, 12, 14, 22, -2, -18], [32, -10, -8, -3, -9, 0], [8, -2, -20, -18, 12, 2], [-6, 0, -2, -19, -14, 10], [-7, 3, 8, 16, -5, -21], [-16, 24, -10, 8, 0, 8], [15, 1, 8, 8, 9, -9], [18, -2, 10, -8, 10, 10], [-13, 7, 0, 6, 2, -4], [-28, -4, -6, -11, 8, -6], [19, -21, 0, 4, -21, 11], [-27, 0, -1, 8, -1, -9], [37, -11, 2, 21, -10, -11], [-27, 1, 8, -6, -12, -2], [6, 10, -2, 2, -4, -14], [-5, 12, -5, -1, 7, 21], [7, -3, 0, 4, -19, 14], [17, -6, -13, -19, -1, 19], [-4, 12, -8, 2, 8, 12], [9, -17, 4, -6, 1, 2], [5, 7, 12, 1, -9, -4], [3, -11, 2, 3, 5, 18], [5, -7, -16, 0, 3, 14], [-6, 22, 6, 6, 6, -6], [19, -19, 0, 26, -7, 8], [6, -23, -5, 12, 7, 17], [30, 2, 16, -4, -8, 0], [-2, 14, 8, -8, 6, -12], [12, -17, -3, 20, 3, 1], [11, -6, -1, 11, -1, -14], [-19, 11, 6, 24, -1, -18], [-5, 12, 7, -13, -7, 5], [-2, 8, 0, 2, 14, 4], [-14, 2, -18, -23, 14, 4], [0, -10, 0, 21, -14, -2], [11, 20, 23, 5, 1, -24], [-22, -8, 4, -10, -4, 4], [21, -15, -12, -23, -11, 18], [23, 24, -7, 1, -1, 5], [9, 13, -8, 11, -3, 7], [29, 9, 10, 31, -13, -10], [9, -3, -4, 7, -1, -1], [-1, -18, 1, -11, -5, 8], [6, -6, 0, -22, 2, -12], [-18, -8, 20, 20, -3, -15], [-1, 23, 0, -18, 1, -6], [27, -22, -5, -9, -15, 16], [-4, -15, -19, -11, 0, -6], [-8, -20, -20, -20, -12, 18], [31, -17, -6, 6, -4, -2], [19, 11, -14, 0, 13, 10], [7, 4, -5, -17, 3, 4], [3, 9, -14, -21, 13, -1], [-2, 8, 4, 7, 17, 4], [16, 8, 2, -14, 9, 7], [-13, 3, -2, -12, 9, 11], [-27, -4, -7, 3, -5, 3], [-19, 16, -3, -32, 0, 14], [1, 21, -2, -6, -11, 12], [8, 12, 2, 8, -10, 2], [-7, -11, -2, -4, 9, 15], [28, 13, 9, 14, -6, -7], [-3, -17, -4, -10, 7, 22], [-29, 7, -10, 23, 3, -5], [-32, 2, 2, 6, -11, -11], [12, -6, 16, 16, -11, 15], [-17, 16, -1, -10, -13, -3], [23, -1, 2, -14, 13, 4], [9, -21, -16, -6, -9, 14], [-2, 12, -2, 4, 2, 8], [-34, 22, 14, -7, 6, -8], [-1, -1, -10, -16, 2, 21], [-21, 9, 2, -2, -3, 20], [-2, 5, -7, 8, 14, -10], [-13, -15, -10, -4, -15, 3], [-10, -14, 0, 18, -6, 2], [-18, -10, 14, 32, -10, 10], [-9, -1, -2, 14, -3, -22], [-34, 4, 16, 22, -7, -21], [28, 14, 2, 16, 3, -2], [19, -4, 3, 2, 5, 13], [-1, -9, -14, 3, 0, 15], [-9, 18, 5, -28, -2, -2], [39, -1, 12, 4, -11, 8], [-29, 15, -14, -12, 13, 2], [26, 6, -10, -10, 15, 2], [35, -6, 5, -13, -3, -2], [33, 5, 2, -8, 13, -10], [-1, 5, 2, 13, -1, 17], [-9, -4, -9, -14, 8, 14], [17, -5, 6, 3, 13, -4], [-34, 9, -3, 14, 3, -3], [-22, -2, -6, 22, -10, 12], [-17, 11, -2, 7, -1, -14], [26, 18, 4, -4, -6, 4], [-16, 10, -4, -32, 1, 10], [-9, -12, 5, -8, -15, 1], [23, -30, 9, 16, -22, 14], [-16, 3, -9, -7, -10, 6], [19, -6, 1, 0, 18, 0], [-5, -1, -14, -3, 7, 12], [-25, -8, -7, -31, -1, -3], [-6, -4, -24, -30, 8, 24], [33, -15, 12, -9, -3, -9], [-26, 10, 2, 25, -5, -18], [15, 7, 0, 1, 3, 10], [10, -11, 21, 31, -18, -10], [18, -8, 4, -10, 12, -22], [-26, -14, -24, -16, 7, 8], [9, -1, -10, 5, 11, 12], [25, 9, 14, 6, 2, 7], [9, 1, 10, 8, -17, 7], [10, 19, -3, 4, -6, 17], [5, 17, 18, -8, 19, -10], [-25, 3, 14, 24, -4, -22], [7, 11, 2, -36, -7, 2], [23, -10, -21, -6, -17, 5], [12, -12, 2, -4, 10, 24], [-5, -16, -13, -2, -10, 22], [14, -22, -22, -8, 0, 12], [7, -35, -8, -19, -9, 17], [27, 0, 13, 17, -13, -10], [-2, -12, 12, 0, -6, -14], [23, 0, 9, -5, 1, 8], [24, 2, -8, -20, 11, 15], [19, 13, 26, 9, -15, 9], [-13, -3, -4, 10, -19, -2], [9, -1, 10, 26, -25, 5], [-12, 8, -18, -8, 1, 19], [25, -24, 3, 11, -13, -7], [-11, -12, -13, -5, -7, -8], [20, 6, 6, -32, 10, -6], [8, 4, -14, -8, 4, 2], [13, -2, 11, 41, -11, 1], [31, 3, 10, 26, -14, -3], [15, -24, -17, 3, -9, -7], [26, -18, 14, 6, 2, -6], [-22, -2, -18, -22, 9, 8], [3, 14, 31, 9, -11, -12], [16, 30, 8, 0, 2, -22], [-5, 23, 12, 8, 2, 22], [-21, -1, 16, 12, -13, -15], [-7, 4, -15, 10, 0, 0], [24, 5, 7, -5, 8, 0], [-21, 21, -10, -2, -1, 9], [-29, 17, 8, -1, 4, -11], [6, 2, 24, 6, 14, -20], [-18, -6, -8, -8, 14, -4], [-29, 22, 1, -19, 3, 7], [5, 11, -6, 26, -13, -4], [17, 16, 7, 10, 25, -3], [-5, 4, -5, -17, 33, -9], [3, 22, 1, -1, 23, 8], [12, 3, 23, 24, -2, -34], [5, 8, 11, 11, 19, 12], [-30, 19, -15, -4, 20, -5], [17, 12, -17, -17, 7, 25], [7, 1, 20, 26, -20, -4], [1, -5, 6, -16, 25, 6], [5, 21, 26, 13, -5, 2], [-37, -7, -6, -26, -8, 0], [-7, -3, -2, 27, -23, -17], [-26, -20, 0, -6, 9, -1], [18, 2, 2, -23, -19, 20], [-7, 16, 1, -21, -19, 3], [-20, 26, 16, 0, 12, -4], [-24, -13, -7, -13, -20, 10], [-12, 7, -3, -13, 4, 24], [-15, -29, -10, -12, 9, -10], [30, -28, 4, -14, 0, -4], [-5, 7, -14, 7, -7, -4], [32, 2, 2, -10, 12, -28], [29, -10, 11, 5, -7, -8], [-4, 26, 10, 12, 8, -22], [6, -8, -26, 8, -2, 10], [13, 8, -19, -11, -1, 12], [49, -4, 1, 5, 1, 13], [7, -5, -18, 2, 1, 6], [4, -11, 33, 22, -22, -12], [-13, -1, -8, -14, -1, -14], [-1, 2, -25, -18, 20, 22], [-41, 25, 18, 4, 16, -11], [23, -14, -3, -11, 15, -3], [-11, 3, 6, 12, -17, -21], [12, 21, 29, -9, -14, -4], [-8, 24, 14, 6, 6, 22], [-27, 14, 21, 15, 9, -3], [-19, 11, -2, 14, -8, -2], [-4, -10, 16, 18, -3, -18], [7, 7, -4, -8, 29, -5], [19, -3, 6, -15, -13, 2], [13, 13, 8, 2, -9, 0], [25, -5, -4, -14, 6, 5], [39, -11, 2, -18, -7, 8], [11, 2, -3, 3, 23, 3], [-3, 26, 15, 18, 11, -17], [-13, -20, -21, -9, 7, 4], [-13, -21, -40, -6, 14, 21], [-2, 4, -2, -3, 0, 24], [35, 8, -5, -27, 13, 7], [26, 9, -3, 10, 5, 11], [-14, 6, 0, -22, 31, 1], [-4, -2, 0, -16, -18, 10], [46, -4, -6, 17, -11, 0], [24, 32, 24, 12, -4, -24], [4, 8, -14, 10, -8, -6], [26, 15, 7, -9, 14, 6], [35, -31, 6, -4, -5, -15], [33, 8, -3, 15, 17, 3], [7, 34, 19, 11, -3, -4], [-1, -1, -22, -7, 5, 24], [35, 11, -16, -30, 7, 12], [-30, 12, 8, 16, 16, -2], [-9, 29, -6, -25, 10, 7], [6, -37, -5, -6, 1, -1], [11, -19, -2, 20, -11, 7], [23, -22, -7, 5, 17, -4], [-5, -35, -12, -10, -19, 16]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_4018_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_4018_2_a_bq();".
// 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_4018_2_a_bq(:prec:=6)
    chi := MakeCharacter_4018_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 2));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(2999) - 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_4018_2_a_bq();".
// 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_4018_2_a_bq( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_4018_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![4, -104, 20, 44, -10, -4, 1]>,<5,R![-158, 248, -68, -68, 50, -12, 1]>,<11,R![-398, -300, 498, 8, -50, 0, 1]>],Snew);
    return Vf;
end function;