
// Make newform 8018.2.a.c in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_8018_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_8018_2_a_c();".
// 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_8018_2_a_c();".
// 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, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    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_8018_a();"
function MakeCharacter_8018_a()
    N := 8018;
    order := 1;
    char_gens := [2111, 1901];
    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_8018_a_Hecke(Kf)
    return MakeCharacter_8018_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], [1, 1], [-1, 2], [2, 0], [-4, -1], [5, 0], [1, -2], [1, 0], [-7, 2], [-3, 3], [-4, 9], [4, -6], [1, 4], [-5, 3], [7, -2], [4, 4], [9, -3], [3, 0], [11, -6], [5, -1], [-1, 6], [8, -6], [-1, 5], [7, -2], [13, 0], [-17, 4], [-10, 9], [3, 3], [2, 6], [-11, 4], [-4, 15], [-6, 3], [-9, 0], [0, 0], [-10, -1], [6, -9], [-5, 0], [-1, 0], [12, -18], [2, -7], [2, 2], [15, -6], [19, -2], [-4, 12], [-10, 8], [1, 0], [-1, 0], [5, 0], [17, 2], [21, -3], [9, 6], [-6, 6], [10, -9], [-4, -7], [-4, 2], [-13, -4], [-19, -1], [-5, 0], [13, -24], [5, -10], [-5, -3], [-11, -5], [31, -6], [23, -7], [4, -21], [-5, -8], [8, 6], [0, 0], [-24, 12], [-1, -21], [-26, 7], [-5, -8], [28, -15], [5, -15], [26, -12], [6, 12], [-16, -10], [-5, 3], [16, -2], [4, -27], [14, -28], [-2, -3], [-12, 6], [5, 12], [18, 3], [14, -10], [27, -12], [-1, -21], [21, 3], [16, 6], [13, -20], [3, -24], [-18, 9], [-3, 24], [-9, -6], [-28, 8], [25, -26], [13, -11], [25, -12], [6, -9], [-22, -3], [29, -10], [26, -4], [-15, -3], [-26, 27], [-37, 9], [23, -28], [-5, -8], [-15, 3], [31, -18], [7, -30], [-37, 9], [7, 10], [10, -12], [1, 0], [-11, 7], [27, -24], [-31, -1], [2, 8], [13, -8], [2, 18], [30, -27], [23, -40], [-7, -22], [18, 9], [-1, -4], [-19, -15], [-29, 28], [-8, 6], [5, 27], [-26, 12], [9, -27], [-18, 30], [-29, -3], [-1, 23], [-5, -15], [-1, 11], [-8, 18], [17, 2], [20, -31], [26, -18], [-32, 19], [6, -21], [-5, -2], [-13, 24], [41, -4], [7, 18], [41, 2], [-13, 36], [25, -38], [-42, 18], [20, -10], [-8, 6], [-30, 30], [49, 6], [13, 28], [10, 9], [0, 18], [-24, 18], [19, -17], [5, -19], [-22, 11], [-4, 36], [9, -30], [-5, 37], [19, -2], [-23, 0], [-26, -12], [48, 0], [-23, 16], [2, -1], [-34, 36], [-21, 3], [8, -27], [-31, 0], [3, 6], [-6, 15], [-28, 35], [-36, -18], [2, 21], [30, 18], [19, -11], [31, 0], [-8, 25], [-16, -1], [25, -38], [-16, -9], [28, -18], [-14, 36], [51, 6], [-34, 24], [-57, 6], [-1, 0], [-13, -19], [-17, 28], [42, -18], [16, 30], [-6, 33], [-65, 1], [4, 4], [-44, 22], [-23, 39], [29, -42], [-15, -27], [-9, -12], [-35, 49], [35, -9], [-8, 22], [25, 7], [9, -3], [-21, 3], [29, -28], [38, 18], [-9, 15], [40, -32], [-13, 48], [55, -18], [22, 13], [-11, -17], [17, -13], [25, -12], [23, -42], [-11, -5], [-11, 36], [42, 9], [-30, 42], [29, -10], [-4, 17], [-29, -21], [-44, -17], [40, -27], [4, 24], [28, -60], [-40, 23], [2, -9], [-15, -6], [5, 0], [35, -28], [24, 0], [24, -42], [-9, -9], [-35, 12], [-24, 63], [15, -21], [2, -10], [42, -12], [4, -15], [-36, 33], [-47, 24], [-9, -33], [35, -30], [19, -47], [67, -2], [37, 0], [6, 36], [-62, 22], [13, -42], [-68, 12], [-32, 22], [26, -51], [8, -48], [40, -50], [15, -18], [-13, 54], [57, -18], [-45, 30], [-29, 7], [-11, 22], [-7, 24], [27, -12], [7, -30], [-1, 18], [-35, 42], [-18, 27], [-5, 12], [-3, 48], [-10, -13], [-3, -18], [7, 27], [14, 2], [18, 3], [12, 30], [63, -21], [-29, -15], [16, -24], [56, -13], [31, -39], [16, 37], [34, 0], [-8, 10], [-17, 22], [-21, -18], [-27, -18], [62, 8], [1, -21], [-11, -11], [51, -36], [-10, -19], [-66, 6], [26, -18], [-16, -21], [-10, 11], [12, -27], [38, -58], [20, 21], [-35, 33], [28, -5], [-44, 30], [61, -8], [-11, -12], [-8, -32], [-20, -2], [27, -12], [-39, 0], [35, -37], [1, -48], [37, 19], [-43, 20], [8, -30], [4, -11], [-11, -45], [-28, 3], [29, 17], [-28, -21], [-72, -6], [2, -9], [-65, 6], [-47, 6], [-56, 34], [39, 27], [-29, -36], [-48, 27], [26, -45], [67, -41], [-9, -36], [-65, 28], [-47, 12], [28, 7], [-33, 0], [73, -27], [-7, 12], [60, -57], [-10, 2], [43, -15], [-19, 62], [-64, 23], [-7, 27], [-82, -3], [-53, 1], [37, -17], [82, 0], [-60, 9], [11, -43], [-23, 6], [-25, 0], [14, 5], [61, -41], [-4, 14], [-40, -22], [-11, 43], [-66, 3], [20, 17], [25, -8], [-28, -4], [-38, 84], [-48, 57], [39, 6], [-31, 6], [17, 0], [-40, 41], [-32, -15], [-19, -28], [-54, -3], [30, -12], [47, -18], [-54, 39], [49, 19], [-6, -12], [-14, 64], [-30, 24], [63, -12], [26, -4], [-10, -24], [-10, 26], [-50, -18], [-87, 0], [-5, 12], [-44, 12], [-47, 24], [64, -2], [-47, 36], [-12, 48], [-16, 20], [34, 15], [12, -33], [-3, 42], [-3, -3], [-50, 19], [61, -36], [20, -67], [45, 15], [18, -24], [-40, 39], [41, -76], [10, 4], [16, -36], [-2, -3], [-24, 21], [25, 6], [-6, 45], [40, 18], [-21, 27], [2, 50], [-61, 27], [18, 18], [19, -50], [-31, 44], [42, -57], [-45, 0], [60, -9], [-7, -25], [53, 0], [59, -10], [50, -7], [18, -36], [71, 2], [64, 25], [78, -9], [-5, 21], [29, -22]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_8018_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_8018_2_a_c();".
// 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_8018_2_a_c(:prec:=2)
    chi := MakeCharacter_8018_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_8018_2_a_c();".
// 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_8018_2_a_c( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_8018_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![1, -3, 1]>],Snew);
    return Vf;
end function;