
// Make newform 5929.2.a.u in Magma, downloaded from the LMFDB on 16 December 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_5929_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_5929_2_a_u();".
// 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_5929_2_a_u();".
// 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, -3, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-2, 0, 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_5929_a();"
function MakeCharacter_5929_a()
    N := 5929;
    order := 1;
    char_gens := [1816, 2059];
    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_5929_a_Hecke( : Kf := Kf)
    return MakeCharacter_5929_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 := [[0, -1, 0], [-1, 1, -1], [-2, 0, -1], [0, 0, 0], [0, 0, 0], [1, 1, 1], [-1, 1, -4], [3, 1, -2], [0, -5, 2], [1, -4, 3], [-3, 0, 1], [0, 4, -2], [3, 1, -3], [0, 1, 1], [1, -3, 6], [3, -3, -3], [0, -1, -5], [4, -6, 4], [0, -2, 2], [-3, 5, 2], [2, 1, -1], [1, 2, 5], [-5, -5, 2], [5, 0, -1], [-15, -1, 1], [-2, 3, 2], [2, 1, -4], [10, 0, 1], [6, 4, -1], [-3, 1, 4], [4, 3, 3], [-7, 4, 3], [6, 13, -7], [-5, 8, -10], [1, 2, 8], [-5, -7, 11], [-13, -2, 2], [-1, 6, 4], [-7, -8, 9], [9, 3, 3], [0, 5, -7], [-18, 1, -1], [-7, 12, 0], [11, 1, -5], [-2, -3, 8], [-3, 4, 1], [-8, -2, 2], [3, -8, 8], [-4, -12, 11], [-23, -2, 2], [-11, -2, -4], [-5, 2, -9], [20, 1, 5], [-9, -7, 12], [1, 0, 5], [8, 7, -10], [-1, 0, 15], [15, -6, 4], [4, -9, -7], [-10, 4, -9], [-2, 15, -6], [-11, -8, 8], [-8, -6, 5], [-4, 6, -7], [5, -7, 18], [-12, -7, -5], [7, -12, 6], [1, 11, -4], [9, 0, 7], [13, -10, 0], [-9, 1, -17], [2, 13, -20], [9, 8, -3], [-13, -8, 10], [-7, 3, -14], [5, -3, -5], [-1, -4, 13], [4, -4, -2], [-2, 9, -7], [3, -2, 1], [7, 2, -16], [4, -15, 12], [-9, 16, -2], [12, -6, -2], [-6, -23, 6], [2, 18, -11], [-25, -10, 8], [-5, 3, -8], [7, -9, -2], [11, 4, 11], [10, 11, 6], [-17, 10, -21], [-8, -7, 7], [-1, 6, 0], [-7, -10, -7], [-15, -3, -7], [-2, 17, -12], [0, 13, 4], [-19, 11, -4], [-1, 20, -13], [-11, -2, -14], [4, -14, 15], [-20, -2, 7], [-14, 1, -10], [-1, -13, 6], [1, -5, -10], [4, 11, 13], [-15, -14, -1], [0, 7, -9], [6, -14, 11], [17, -7, 29], [12, 18, -16], [4, -12, 4], [-22, -6, -2], [-6, 19, -9], [13, -16, 3], [20, 22, -16], [-10, 14, -24], [-7, -7, 3], [30, -5, 2], [-6, -10, 3], [0, -14, 12], [41, -1, -2], [-23, 13, -9], [-8, 0, 0], [-7, -21, 22], [-7, -6, 15], [-22, -22, 7], [-1, 10, 3], [3, -3, -18], [4, -13, 5], [7, 4, 15], [6, -4, 25], [4, 4, -9], [-18, 15, 0], [19, -20, -6], [-17, 5, 12], [-21, -1, 1], [6, -29, 6], [-1, 20, -26], [-6, 12, 11], [10, 10, -3], [-25, -14, 3], [21, -13, 1], [2, -29, 1], [-24, -6, -5], [22, 8, 10], [-2, 25, -30], [-23, 23, 9], [0, -8, -5], [18, -13, 5], [-17, 5, -1], [35, -7, 15], [-5, -21, 14], [-13, 0, -10], [-14, 18, -11], [-3, -10, 0], [-12, -6, -9], [1, 28, -9], [16, 11, -15], [-36, -10, 5], [26, 7, -8], [20, 3, 9], [-16, 13, -16], [-14, 9, 16], [-10, 15, -7], [23, -17, -10], [-19, -23, 19], [-13, 28, 5], [12, -23, 4], [-13, 29, 9], [-10, 13, -26], [-6, -14, 9], [-25, 23, -6], [-6, 13, -12], [-2, 1, -17], [24, 15, -16], [4, -23, 15], [-19, -3, -9], [17, 18, -26], [17, 0, 24], [28, -20, -3], [11, -25, 1], [-18, 0, 9], [-15, -6, 12], [10, -12, 4], [-22, 2, 19], [-5, 25, 5], [17, -6, -11], [-27, 17, -12], [10, 28, -20], [2, 15, -27], [19, 13, -16], [-30, 8, 8], [-49, -1, -5], [20, 28, -12], [3, -20, 21], [12, -13, -20], [-1, 8, 25], [-5, 30, -7], [20, -7, -11], [34, 17, -12], [-13, 15, 8], [7, -18, 18], [-18, -24, 8], [5, 9, 6], [-19, -9, -7], [-10, 3, 5], [26, 10, 3], [3, -1, -18], [29, -17, -18], [23, 3, 17], [9, 23, -25], [10, -8, -15], [7, 33, -14], [-11, 24, -33], [-14, 8, -25], [-36, 10, 4], [15, 12, -21], [17, -5, -6], [18, 35, -27], [-19, 29, -29], [18, 21, -12], [3, 16, 23], [-39, 12, 12], [3, -18, 32], [29, -14, 18], [-5, -3, 10], [-30, 4, -9], [-28, 20, -22], [15, 6, -13], [17, 41, -15], [-22, -42, 24], [-5, 6, 12], [24, -22, 33], [-10, -4, -6], [1, -7, -24], [20, -15, 26], [19, -9, 36], [-44, 14, -23], [-1, 13, -7], [-4, 29, -40], [-42, 17, 14], [-8, 20, -6], [-12, -20, 6], [-9, -31, 11], [3, 5, -2], [-10, -5, 5], [-13, -3, -13], [15, 15, -32], [-27, -24, 25], [27, 5, -24], [-48, -2, -5], [-10, 18, -17], [-14, 25, -10], [-23, 13, -21], [27, -19, 34], [15, -14, 10], [32, 12, 5], [-9, 7, 3], [12, -24, -8], [-34, 9, 8], [36, -23, 17], [22, -4, -12], [20, 17, -5], [34, -8, 9], [28, -6, -2], [10, -3, 28], [3, 15, 14], [21, 3, -30], [-23, 14, -22], [-8, -25, 24], [51, -8, 26], [-14, -30, 24], [-10, 25, -32], [-33, -22, -2], [13, -19, 27], [-7, 37, -5], [14, 39, -21], [-25, 9, -10], [7, 7, 1], [-32, -13, -2], [-19, 22, -2], [29, -16, 50], [-39, -11, -12], [-6, 7, -5], [16, 34, -7], [2, 15, 20], [-26, 8, -17], [-16, 27, 7], [0, 4, -1], [0, -17, 24], [-22, 20, -8], [-35, -8, 11], [7, -18, -17], [-31, -6, 9], [19, -14, 3], [7, 20, -5], [-15, -2, 25], [-3, -19, 24], [-14, -21, 19], [40, -7, -6], [-4, -20, -2], [18, 43, -45], [-6, 28, -43], [-17, 27, 12], [28, 10, 23], [-36, 4, -32], [6, -34, -10], [-53, 15, -32], [17, -2, 12], [-3, 21, -13], [2, -25, 31], [-27, 29, -18], [-1, 10, 12], [-17, 0, -31], [-8, -43, 35], [1, -34, 16], [-7, 18, -15], [-30, 30, 17], [-7, 2, 0], [-9, -30, -1], [-52, 5, -1], [-19, 27, -15], [-1, -13, 26], [7, -25, 2], [28, 25, 8], [-38, -24, 18], [21, 12, 3], [18, 11, -27], [-17, -9, -10], [-31, -37, 37], [2, -10, 32], [-39, -4, 7], [35, 10, 0], [16, -32, 23], [-10, 17, -6], [-56, -9, 0], [8, -28, 14], [-48, -17, -7], [15, -9, -17], [-14, -43, 21], [-23, -27, 19], [13, 34, -12], [-38, 23, -32], [4, -18, -31], [-31, -7, 8], [43, -9, 23], [0, -42, 12], [4, -5, -16], [-64, -16, -1], [34, -11, 2], [59, 7, -9], [60, 17, -10], [-33, -11, -25], [17, -31, 28], [-27, 4, 13], [26, -2, 16], [-2, 32, -28], [8, -33, -3], [7, -36, 27], [-6, 8, 17], [45, 29, -16], [-11, -1, -50], [29, -25, 1], [-16, -2, 38], [-14, 16, 11], [18, 14, 25], [-26, 14, -30], [-26, -51, 46], [-40, -5, 9], [-9, -13, -21], [-45, 26, 3], [-22, 6, -29], [15, -15, -1], [0, -32, -12], [12, -33, 2], [80, -2, -8], [-47, -40, 15], [20, -16, 58], [34, 27, 5], [-13, 1, -33], [-33, -41, 6], [29, -19, 0], [1, -20, -35], [-37, -46, 22], [-13, 16, -45], [16, 30, -3], [-10, 26, -18], [9, 10, -33], [-8, -20, -3], [-13, 16, 43], [-33, 3, 7], [-10, 6, -33], [2, 15, -7], [-53, -23, 24], [32, -36, -9], [6, -1, -22], [3, -8, -39], [6, 32, -29], [20, 23, -46], [31, -12, 12], [17, -36, 11], [-42, 1, 10], [36, 8, 19], [-17, 32, 27], [17, 36, -43], [18, -45, -11], [-38, -1, 8], [12, -32, 24], [30, 26, 8], [28, -9, 47], [-12, 10, -6], [-59, -20, -2], [13, -33, -30], [29, 0, 11], [52, -4, 14], [22, -17, 29], [-33, -10, 22], [-64, -2, 3], [29, -14, 1], [7, 7, 7], [52, -30, 1], [24, 39, -13], [23, -23, 28], [-20, 12, -65], [-48, 8, -31], [13, -44, 39], [-11, 42, -55], [-7, 14, 3]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_5929_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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