
// Make newform 2601.2.a.bd in Magma, downloaded from the LMFDB on 16 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_2601_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_2601_2_a_bd();".
// 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_2601_2_a_bd();".
// 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 := [2, 0, -4, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 1, 0, 0], [-2, 0, 1, 0], [0, -3, 0, 1]];
    Rf_basisdens := [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_2601_a();"
function MakeCharacter_2601_a()
    N := 2601;
    order := 1;
    char_gens := [290, 2026];
    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_2601_a_Hecke(Kf)
    return MakeCharacter_2601_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 := [[0, 1, 0, 0], [0, 0, 0, 0], [1, -1, 0, -1], [-2, 1, 0, 0], [1, 1, 1, 1], [-1, 0, -1, -2], [0, 0, 0, 0], [-3, -2, -1, 2], [3, -1, 0, 3], [2, 0, -3, 0], [-2, -1, 4, 1], [-6, -1, -2, 0], [3, 1, -2, -3], [1, 2, -1, 4], [-2, -2, -4, 2], [-2, 0, 4, -2], [-6, 1, 2, 0], [-6, 1, -4, 2], [2, 2, 1, 0], [-6, 2, -3, 0], [-2, -4, 4, -6], [0, 0, -2, 3], [-2, -4, 4, 2], [-4, 2, 4, 3], [4, -3, -2, 1], [0, -3, -2, -1], [-7, 4, 4, 2], [5, 7, 2, -3], [-4, -1, -4, 1], [7, -1, -3, 1], [-11, 0, -3, 4], [1, 1, 7, -3], [-6, -6, 2, 1], [0, -4, 2, -1], [-2, 2, -4, -7], [-4, 8, 3, -4], [-9, -4, 2, -6], [2, 5, 4, 5], [-1, -1, -1, -5], [9, -3, 0, -3], [-2, 2, 0, -6], [-4, -4, 8, -1], [-2, -1, 0, -8], [2, 4, -4, 0], [9, 1, 0, 7], [8, 5, 0, -1], [2, 4, 2, -2], [1, 8, -3, -8], [-1, 5, -2, 9], [8, 4, 5, 10], [3, -5, 9, 3], [-4, -2, -6, 2], [6, 8, 0, -5], [-4, 10, -2, 3], [-8, 3, -10, -4], [-4, 11, 6, 4], [-7, 1, 0, 7], [-7, 4, -5, -2], [-14, -1, -6, 1], [0, 4, -4, 11], [-8, 10, 2, -5], [-12, 3, -2, 0], [-2, -2, -13, -4], [-4, 0, 1, 0], [-8, -8, -2, 0], [14, 2, 11, -10], [1, -2, 6, -8], [-4, 2, -2, 9], [-4, 6, -7, 8], [-1, 8, -9, 2], [2, -12, 0, 9], [4, 14, -8, -5], [6, -1, 0, -6], [-4, -6, 9, 2], [6, -3, -10, -8], [8, -2, 12, -6], [-8, 3, -4, -12], [4, -9, 6, -3], [13, 3, -2, 7], [-15, -12, 10, -6], [-8, -8, 13, -10], [1, 8, 2, -6], [-2, 4, -3, -6], [3, 4, 2, -10], [4, -7, 2, -15], [10, -4, -6, 0], [0, -18, -8, 6], [5, -14, -1, 6], [2, -5, -16, 0], [-12, 6, 3, 8], [14, 3, -4, 8], [-5, 1, 3, -3], [16, -10, -4, -5], [-18, -3, -6, 1], [2, 11, 14, -1], [13, -1, -3, -5], [12, -5, 16, 11], [-5, -1, -16, -15], [0, 0, -1, -10], [-10, 3, -6, 0], [-2, 16, -6, -11], [14, 5, 6, -2], [14, 1, 4, 11], [-4, -17, 2, 9], [-8, 1, -16, 1], [11, -14, 0, 4], [-24, 3, 4, 7], [10, 1, -10, -7], [2, -3, -10, 2], [2, -4, -10, -12], [-8, 7, -12, -18], [13, 6, 8, 18], [6, -4, -3, 12], [12, 8, 0, 11], [3, -6, -10, -12], [-3, -17, 5, 1], [4, -5, 8, 13], [-18, 4, -16, -11], [1, -17, 9, 7], [-2, 0, 6, -13], [-13, 0, -13, 4], [-14, 16, 8, 2], [5, 7, 8, -13], [-11, -11, 10, -3], [4, -5, 2, 13], [16, 11, -4, 11], [-2, -5, -6, 17], [-15, -5, 24, -3], [6, -16, 10, 4], [-34, 4, -5, -10], [15, -4, 11, 0], [4, 10, 10, 2], [-6, -24, 6, 10], [3, -6, 4, -6], [6, -18, -12, -4], [-7, -2, 11, 2], [4, -7, 14, -19], [16, -7, -2, 5], [16, 2, -2, -4], [-7, -3, -5, 1], [10, -5, -4, 3], [5, 5, 4, -9], [10, 8, -6, 7], [-11, -5, -19, -1], [0, -4, 9, 10], [-7, 7, -17, -1], [-16, 8, 10, -9], [-4, 2, 17, -10], [-16, -12, -15, 2], [-16, 19, -6, -4], [-8, -7, 26, 2], [-2, 10, 12, 10], [17, -8, 12, 12], [-9, 21, -1, -9], [0, -17, 2, 18], [-15, -11, -7, -3], [-11, -14, 2, -24], [-9, 27, 3, 1], [20, -6, 8, 2], [-22, -8, -9, -6], [2, -6, 11, -16], [20, 7, 6, -13], [13, -4, -7, -2], [-18, 5, -12, 5], [2, 9, -2, 16], [5, -7, -16, -1], [4, -4, -6, -8], [-32, -8, -10, 7], [0, 5, -12, 7], [26, -6, 13, 2], [-18, -16, 8, 7], [-25, 24, 11, 8], [5, -9, 18, 17], [-15, 26, -2, -6], [-35, 0, 3, 8], [-11, 3, 2, 17], [-8, -7, -10, -17], [17, 13, 13, -15], [13, 4, 7, -10], [-11, 2, 0, 20], [-1, -12, -12, 10], [10, 4, 13, -4], [-26, -6, -4, -14], [4, -11, 0, 8], [-18, -10, 12, -3], [14, -7, 14, 9], [-36, -7, 10, 6], [29, -20, -7, -2], [-4, -3, 24, -8], [10, -4, -1, -10], [-6, 4, -6, -2], [8, -20, -9, -16], [-9, 16, 24, 10], [-20, -1, -12, -10], [23, -1, -5, -11], [-6, -4, 13, 18], [-2, 0, 26, -14], [-40, -15, 8, -7], [32, 0, 7, 16], [-2, 11, 6, 15], [-31, 9, -5, -17], [28, -1, 0, -11], [21, -10, -23, -10], [-33, -4, 5, -2], [-4, -10, 22, 5], [-2, -1, 18, -9], [-2, 2, -9, -12], [-8, -12, 10, 13], [5, -21, 4, -7], [8, -4, 3, -10], [-20, 13, 10, 14], [-14, 7, -4, -29], [4, -11, 14, 10], [24, -3, 10, 5], [-5, 7, 22, 1], [8, -1, 22, 23], [-15, -14, 17, -8], [-4, 12, 18, -16], [3, 27, 2, 17], [28, 0, -6, 6], [17, -4, 17, -2], [-10, 9, 8, 6], [8, 21, 0, 4], [-16, 9, -22, -14], [42, -16, -12, -3], [0, 2, -17, -22], [7, 11, -21, -11], [9, -21, 6, 19], [-15, 2, 7, 4], [4, 0, 9, 14], [-29, -4, -13, 20], [-16, -22, 0, 9], [-18, 2, 1, -2], [2, -6, 6, -10], [-8, 16, -2, 20], [6, -14, -2, -12], [26, -10, -16, 5], [5, 1, -9, 3], [-15, -15, -26, 5], [12, -3, 26, -14], [15, 25, 7, -3], [2, 20, 8, 16], [-15, -4, 1, -20], [35, 4, 5, -10], [-25, -7, -8, -19], [-5, 21, -14, -5], [-14, -5, 6, -19], [17, 15, 11, -7], [-5, -4, 0, -16], [-20, -36, 18, -7], [13, 14, 4, 0], [-26, 2, 33, 2], [4, -3, 28, 5], [22, 16, -12, 21], [-26, -8, -22, 17], [-4, -3, 8, -24], [-14, 12, -20, -1], [-2, -16, -32, 9], [-25, -23, -7, 21], [34, -14, -5, 4], [20, -1, 16, -6], [52, 0, -4, 7], [-8, -16, 10, 18], [-36, -12, 10, -2], [-25, 27, 2, 5], [-17, -2, 7, 2], [22, 27, -20, 0], [4, 8, 22, -6], [-6, 15, -8, 22], [-18, -16, -10, -6], [28, -23, -28, -17], [-15, -2, 0, -14], [27, -6, 10, -2], [6, -8, 2, -8], [-6, 22, -17, 4], [25, -14, 7, -10], [32, -7, 22, 24], [3, -20, -10, 2], [13, 16, -8, 10], [-4, -14, -14, -7], [-8, 1, -26, 11], [36, 14, 14, -3], [10, -30, -11, 10], [-18, -18, -1, 0], [16, 16, 12, -7], [-12, 3, -12, 29], [4, -2, -6, 1], [-8, 8, -27, -6], [-3, -22, -5, 16], [8, -9, -42, -1], [-25, -7, -9, 17], [43, -3, -7, -9], [18, -26, -22, -3], [7, 7, 7, -37], [-16, -15, -6, -1], [17, 11, 18, -21], [-24, 26, 6, 14], [-28, -9, -6, 11], [-7, 1, 46, 5], [-26, -32, 9, -6], [-31, -20, -12, 16], [-8, 9, -28, 5], [-14, -36, 4, 1], [11, -37, -2, -5], [-8, 10, 30, 8], [26, 34, -10, 6], [-6, 7, -12, 32], [-6, -18, 6, -33], [-48, -13, 12, -4], [16, -36, -12, 12], [-14, 12, 33, -2], [0, 8, 5, 42], [15, -1, -40, 5], [-29, 36, 9, -2], [4, 8, -6, -5], [-7, 2, -2, 12], [26, 2, -34, -3], [-15, -3, 2, -5], [-6, -4, -16, 19], [28, -11, -20, -14], [36, -16, 0, -13], [44, 1, -22, -6], [30, -2, 10, 20], [25, 20, -1, 12], [12, 22, -25, 2], [-1, 12, -5, 24], [-46, 7, -4, 17], [26, 18, 8, -32], [6, 30, 24, -18], [17, 27, -4, 39], [-12, -1, -12, -15], [3, 5, 7, -9], [10, -16, -12, 16], [-14, 26, 24, 13], [-14, -22, -10, -7], [35, -1, -3, 5], [-7, -2, -7, -6], [1, -1, -19, -9], [12, -3, -20, 0], [-9, 12, 9, 0], [23, 22, -4, 2], [28, 6, 4, -28], [19, -3, 7, 5], [-27, 10, -5, -14], [56, 7, 2, -14], [-1, 35, -9, -11], [2, 23, 12, -19], [27, 6, 5, -30], [-9, -19, -17, 23], [4, 10, 34, 6], [29, 6, -1, -6], [-4, 16, -6, -16], [32, 14, 14, -18], [-14, 9, -22, 3], [5, 2, 2, 22], [-8, 6, 32, 15], [-36, 0, -16, 5], [-18, -4, -27, 20], [19, -15, 15, -5], [-30, 21, -16, -27], [-38, 34, 18, 3], [-1, 21, 29, -9], [24, -11, -2, -22], [-40, 6, -23, -10], [23, 10, -16, 20], [-13, 26, -4, -28], [29, -1, 14, 21], [32, 10, -21, -6], [-16, -17, -28, -7], [4, 21, 26, -24], [-8, 28, 16, -6], [25, -37, -27, -1], [20, 12, 22, 17], [-12, -26, -7, -8], [-8, -16, 6, 28], [73, 11, -1, -7], [16, 8, 11, 22], [9, 26, 1, 28], [30, -19, 0, 7], [19, 6, 6, 20], [-19, -5, -35, -9], [16, -8, 2, 18], [-44, 46, 26, 10], [25, -23, 10, 39], [-46, 8, 14, -6], [-29, 3, 12, 9], [-15, 30, -9, 2], [38, 10, 11, 4], [-10, -21, -18, 34], [0, -17, -8, 18], [6, -5, -28, 23], [-23, -1, -36, 17], [-28, 0, 2, 9], [-23, 16, 12, -22], [18, 3, 10, 15], [20, -15, 18, -5], [-16, -24, 22, -4], [6, -46, -2, -16], [24, -1, 18, 37], [10, 21, 34, -4], [-10, -11, -14, 28], [8, -21, 2, -34], [-7, -26, 20, 12], [-32, -24, 1, -4], [6, -19, 10, -32], [16, -26, -8, -3], [-14, -4, -19, 24], [0, 1, -14, -27], [-3, -4, 2, 48], [-57, -13, -3, 15], [30, 11, 12, -20], [22, 17, -36, -4], [20, 11, -16, 9], [-4, 3, 20, 7], [21, 0, -5, 8], [-44, -2, 14, 10], [31, 41, -10, -9], [-22, -2, -44, -14], [-39, 11, -11, -19], [-2, 14, -10, 33], [14, 19, -14, 35], [22, 11, 22, 43], [-3, 31, -12, 3], [-38, 20, 36, 16], [10, 19, 6, -10], [36, -27, -24, -9], [-12, 38, -17, -16], [-35, 13, -14, 1], [11, -16, 4, 14], [45, 15, 5, -3]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2601_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_2601_2_a_bd();".
// 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_2601_2_a_bd(:prec:=4)
    chi := MakeCharacter_2601_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_2601_2_a_bd();".
// 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_2601_2_a_bd( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2601_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<2,R![2, 0, -4, 0, 1]>,<5,R![1, 12, -2, -4, 1]>,<7,R![2, 16, 20, 8, 1]>],Snew);
    return Vf;
end function;