
// Make newform 1881.2.a.f in Magma, downloaded from the LMFDB on 07 December 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_1881_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_1881_2_a_f();".
// 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_1881_2_a_f();".
// 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, -4, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-3, -1, 1]];
    Rf_basisdens := [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_1881_a();"
function MakeCharacter_1881_a()
    N := 1881;
    order := 1;
    char_gens := [1046, 343, 496];
    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;

function MakeCharacter_1881_a_Hecke( : Kf := Kf)
    return MakeCharacter_1881_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]];
    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, 1, 0], [0, 0, 0], [-1, -1, 1], [0, 0, 1], [-1, 0, 0], [2, 1, -2], [-1, -1, 2], [1, 0, 0], [1, 2, -2], [-1, -2, -1], [-5, 0, -1], [-1, -2, 0], [-2, -1, -4], [-6, 1, -1], [-3, 1, -6], [2, -3, 1], [-2, 4, -5], [3, -1, -1], [-2, 3, 2], [-1, -3, 6], [1, -3, 4], [5, 3, 2], [-1, -1, 5], [1, 2, 1], [1, 4, 5], [-5, 1, 5], [4, -6, 1], [2, 0, 5], [1, 0, 3], [-3, 3, -5], [4, -8, 1], [-2, 4, -4], [-2, 1, -3], [-7, -3, 2], [2, 7, -6], [-2, 1, -3], [-10, 1, 0], [-8, 4, -5], [1, -5, 7], [-10, 3, -1], [-7, 6, 3], [-6, -1, 2], [1, 8, 1], [9, -11, -4], [-8, 2, -12], [-4, 1, -3], [-15, 5, -1], [1, 6, 0], [-9, 2, -5], [1, -10, 8], [-2, -11, 7], [-16, 4, -7], [5, 3, 1], [5, 1, 5], [-6, -9, 0], [-7, 6, 5], [-3, 4, 2], [-12, 7, -4], [-6, 14, -1], [9, -1, -1], [17, -1, -5], [-1, 17, -8], [6, 1, -7], [4, 5, 8], [3, 3, 4], [-5, -11, 5], [-8, 11, -11], [-3, -3, 10], [17, -6, -4], [8, -5, 4], [0, 12, -5], [-20, -4, 4], [-16, -3, -4], [15, -13, 1], [-12, 1, -2], [5, -8, 10], [-9, -5, -2], [13, -11, 21], [4, -2, -5], [-10, -10, 0], [-3, 4, -3], [10, -5, 14], [10, -11, 12], [27, 5, -1], [-12, -7, 6], [13, -1, 12], [-5, 4, 6], [3, -9, -6], [-6, -1, -1], [-5, -5, 3], [21, -6, 8], [20, -7, 12], [-11, 7, 1], [4, 12, -4], [-3, -17, 8], [-8, 2, -9], [1, 7, 6], [-11, 7, -9], [-4, -2, -2], [4, 9, -13], [-16, 10, -2], [4, -6, 7], [-17, 14, -18], [23, -10, 14], [5, -8, 17], [-5, 9, -8], [20, -10, -1], [21, -4, -6], [7, -21, 12], [-13, 18, -13], [-12, 19, -24], [14, -11, 6], [8, -17, 10], [6, 2, 11], [-21, 16, -10], [-7, -2, 7], [-23, 11, -17], [-30, 11, -2], [0, -11, 18], [0, -20, 5], [-7, 13, -15], [2, 4, 15], [-5, -18, 7], [26, -12, 27], [-36, 4, -3], [-33, 11, -9], [7, -2, 13], [8, -12, 1], [-15, 10, 1], [17, -1, 0], [-18, -2, 3], [-23, 0, -7], [0, -18, -3], [12, 16, -14], [6, 17, 2], [5, -15, 15], [0, 3, 4], [-4, -14, 3], [22, -17, 22], [-24, -7, 0], [30, 0, 19], [2, 6, 1], [-11, 9, -4], [19, -5, 6], [29, 3, -6], [24, 0, 17], [26, -6, 7], [1, 12, 15], [-21, -9, 11], [-22, -2, -2], [35, -4, 5], [3, -3, -2], [-7, -6, 3], [-12, -5, -7], [9, -3, -4], [-15, -4, -10], [10, -4, 9], [41, -3, 1], [15, -6, 2], [-13, 1, 11], [16, -22, 9], [-34, 0, -5], [15, 14, 7], [-5, 28, -12], [-35, 2, 2], [-35, -7, -1], [-16, -15, 1], [20, 9, -8], [15, -28, 18], [6, 3, -3], [5, 20, -20], [7, 2, -12], [-3, -20, 12], [9, 29, -19], [-21, -8, 10], [9, -10, -18], [-18, -2, -18], [29, -6, -6], [20, -21, 9], [13, -8, 22], [-20, -14, 10], [-16, -1, 14], [36, -9, 5], [17, 15, -10], [-6, 4, -5], [-34, 5, -12], [-3, -31, 23], [-2, -24, 16], [0, -12, 2], [-22, 10, 5], [20, 8, -10], [10, -15, -8], [40, -10, 34], [2, -30, 7], [-17, 6, -3], [-9, 26, -6], [-1, 14, 7], [35, -8, -4], [8, -12, 0], [14, -3, -3], [16, -16, -11], [-36, 11, 0], [-28, 4, -22], [5, 10, -10], [24, -25, -8], [-13, 3, -23], [-15, 6, -6], [-26, 1, -2], [48, -11, 5], [56, 1, 1], [-9, -9, -22], [2, -12, -16], [-36, 10, 10], [-28, 10, -10], [-57, 0, 4], [-4, -25, 17], [14, 8, 0], [42, 5, -3], [-7, 2, -9], [-23, -7, -5], [-34, 1, -24], [-13, 4, -13], [-18, 0, 16], [-2, -32, 19], [-22, 4, -1], [-14, 36, -23], [8, -4, 5], [-18, -16, 17], [25, -12, -2], [-30, -5, 16], [12, -31, 25], [-3, -4, -5], [-16, -9, 10], [-1, 15, -17], [-7, 3, -1], [3, 0, 8], [38, 11, -2], [24, 17, -18], [-24, -7, -15], [-51, 7, 1], [-27, 26, 0], [-19, 21, -19], [-23, 16, -12], [41, -6, 4], [21, 15, 10], [20, -15, 10], [7, -20, 2], [8, -10, 0], [3, 20, -11], [18, 5, -19], [23, -8, 23], [35, -27, 13], [-8, -22, 22], [-33, -1, -3], [-15, -13, -5], [10, -1, -14], [16, -22, -11], [34, 9, -11], [-46, 5, -34], [-36, -3, -9], [11, 8, 18], [-23, 15, 10], [28, 2, 32], [37, 0, 14], [45, -6, -10], [39, -13, 45], [41, -13, 21], [33, -5, 20], [11, 22, -6], [0, 18, -1], [-3, 27, 3], [24, 4, -1], [34, -32, -13], [29, -22, 29], [16, -13, 22], [-3, 10, -6], [-9, -3, 15], [-12, -7, -9], [-31, 25, -9], [11, -43, 22], [-28, 10, -2], [-45, -7, 11], [-56, -7, -2], [-24, 31, -29], [8, 11, -6], [15, -23, -11], [-12, -4, -19], [34, -9, -10], [19, 23, -6], [8, 25, -26], [-29, 11, 18], [12, -1, 6], [31, -13, -7], [62, -12, 24], [-11, 28, -8], [-25, 15, -30], [-41, 9, 12], [-29, 32, -17], [-3, -20, -4], [40, -5, 11], [-53, 7, -13], [-45, 20, -21], [-17, 26, -7], [34, 25, -21], [-35, 38, 1], [-3, 19, 3], [-27, 35, -37], [-19, -7, -15], [-36, 9, -32], [-35, 20, -12], [-44, -9, -16], [12, 10, 26], [8, 2, 23], [34, -5, 20], [-6, 25, 11], [-7, 2, 7], [20, -15, 0], [-25, 18, 3], [30, -15, -7], [-49, -6, 9], [-10, 35, -6], [-42, 16, -36], [36, -8, 27], [-29, 9, -18], [37, -12, 15], [0, -25, 29], [25, -29, -16], [14, 22, -22], [-7, 5, -22], [-19, -17, -8], [-30, 8, -9], [-60, 7, -8], [-11, 1, 1], [-13, 21, -28], [1, -4, 16], [22, -33, 38], [-5, -28, 13], [-32, 13, 13], [-9, 5, -13], [-42, 3, -3], [-13, -11, -5], [-11, 18, -2], [39, 13, -1], [-11, -16, -3], [20, 20, 7], [7, 24, -28], [-31, 16, 0], [-29, -17, -4], [-10, 4, -33], [-45, -3, 7], [-3, 12, -17], [-38, -2, 9], [15, -3, -11], [-25, 3, -35], [40, -5, -15], [35, -11, 28], [8, -28, -8], [-8, 34, -17], [7, -14, -1], [-26, -21, 0], [26, 0, 9], [21, -1, 5], [-4, 14, 18], [30, -11, 11], [41, 1, 8], [19, 0, 5], [-51, 7, -36], [20, 4, -11], [19, -16, 22], [16, 20, -16], [10, -13, 38], [56, 3, 17], [29, -32, 24], [8, -11, -1], [-2, 3, 17], [-36, 13, -36], [40, -27, 8], [0, -8, 16], [-6, -17, 24], [27, 14, 23], [1, -1, -20], [2, 10, 23], [27, -29, 6], [23, 16, -18], [54, -4, 26], [13, 4, -28], [-42, 0, -32], [42, -6, -7], [-20, 3, 25], [53, -12, 0], [-8, 24, -13], [30, 13, -16], [-50, 1, -16], [46, -15, 49], [-29, 22, -3], [-36, 18, -33], [-12, 25, -16], [43, -33, 2], [2, -31, -4], [-60, 19, -3], [-22, 5, -1], [-66, 13, -29], [3, 40, -30], [-23, 20, -5], [39, -18, -10], [-9, 32, -30], [6, 10, -31], [60, -8, 29], [28, -8, 10], [-60, 13, -13], [-36, 13, 22], [31, -18, 45], [-12, 36, -20], [24, -40, 16], [27, -24, -14], [26, -43, 17], [-31, -28, 20], [38, -5, 35], [41, -2, -11], [-34, -27, 7], [34, -14, 26], [55, 10, 16], [4, 14, -8], [31, -5, 33], [-56, 9, -19], [-14, -5, -28], [1, -27, 12], [8, 24, -5], [8, -35, -2], [1, 21, -18]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1881_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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