
// Make newform 2601.2.a.w 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_w();".
// 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_w();".
// 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_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], [-2, 1, 0], [0, 0, -1], [-2, -2, 2], [2, 3, -2], [0, 0, 0], [0, -1, 0], [-4, -1, -1], [0, -1, -1], [3, -2, 3], [-1, 1, -4], [-2, 1, -4], [5, -3, 4], [7, 1, -1], [6, -2, -2], [3, -4, 5], [-1, 2, -1], [-3, -7, 1], [-7, 3, 1], [-7, -5, 3], [1, -6, 4], [-3, -2, 6], [5, 7, -2], [2, 0, 6], [-2, 1, -5], [-8, 5, -8], [-11, -3, 3], [-8, 4, -4], [0, -3, 7], [-2, -5, 6], [-12, 5, 3], [1, 7, -1], [-5, 3, 3], [-10, 1, -1], [-2, -4, 7], [2, -2, 11], [-3, 3, -6], [-1, 1, 2], [3, 15, -8], [2, -9, 5], [7, 8, 2], [-1, -7, 0], [-14, -7, 7], [5, 13, -6], [10, 13, -8], [3, -10, 15], [-7, -6, 8], [-7, -8, 0], [-2, 12, -11], [21, -3, 9], [2, -2, -7], [3, 16, -11], [1, 4, -16], [2, 0, 5], [-5, 0, -15], [-7, 4, 4], [17, 0, 0], [-7, 12, 3], [-13, -10, 10], [-22, -3, 6], [-2, 2, 6], [0, 1, -5], [-2, 1, 0], [9, 4, -4], [-1, -11, -4], [6, 8, -8], [-11, 5, 2], [-1, -8, -10], [-10, -4, -8], [-1, 5, 13], [1, -8, 11], [4, -9, 3], [-15, -1, 5], [6, -3, -7], [-7, 4, -9], [15, 6, 0], [3, -7, -10], [-19, 8, 2], [5, -10, -1], [6, -6, 5], [-8, 8, -10], [-2, 15, 4], [-12, 0, -2], [22, -3, -9], [-6, -15, 7], [-3, 10, 2], [-17, 12, -5], [-9, 14, 3], [1, 7, 0], [15, 7, 1], [-28, -12, 8], [2, 2, -19], [-5, -1, -16], [7, -9, 17], [-4, 9, 14], [9, -13, -3], [12, 8, -14], [3, -6, 9], [19, -10, 9], [1, -17, 1], [-15, -5, -5], [-3, -23, 18], [-25, 10, -14], [-1, 19, -1], [-6, 3, 2], [3, -18, 16], [-1, -3, 11], [-6, 4, 13], [11, 23, -24], [-9, -3, 4], [4, -1, 5], [13, -15, -5], [-2, -16, -6], [-3, -8, 18], [-9, 12, -15], [-16, 16, -2], [-3, 9, -28], [-10, 5, 10], [12, -10, 3], [5, -16, -1], [8, -11, 13], [7, -20, 5], [6, -12, 8], [20, -7, 9], [-5, 12, 7], [13, -14, -9], [-22, 11, -16], [-14, 11, -25], [13, 1, 7], [16, 3, 0], [-6, 2, -16], [-29, -2, -6], [9, -5, -3], [-5, 7, -14], [1, -10, 17], [-3, -18, 7], [1, 8, -28], [-7, 17, -4], [2, -11, 29], [-27, 6, -7], [18, 8, -1], [-16, 8, -7], [7, -15, 16], [15, 5, -12], [-38, -1, -1], [5, 15, -6], [-13, -19, 11], [-17, 8, 17], [-23, 16, 9], [23, 7, -9], [-15, -9, -16], [-31, 7, -18], [16, -17, -1], [-5, -20, 21], [-16, -2, -16], [-31, -9, 11], [-13, -5, 0], [34, -1, 17], [22, -14, -4], [22, -12, 3], [-16, 7, -1], [-5, 23, -9], [-5, -5, -4], [15, -10, -16], [-16, 17, 7], [5, -11, 33], [-14, -24, 9], [14, -4, 9], [5, -4, -23], [3, 24, -18], [8, 14, -19], [-32, 13, -22], [-13, -32, 20], [0, -1, -17], [14, -8, 17], [-25, 12, -33], [3, 24, 0], [-20, 1, -16], [-13, -7, -12], [33, 9, 6], [-3, 18, -6], [1, 8, -11], [-30, 7, 10], [9, -8, -15], [-39, -5, 7], [14, -6, 19], [-2, 2, 24], [-14, -27, 15], [-27, -13, 8], [12, 2, 0], [15, 1, -21], [15, -21, -10], [9, 10, 3], [26, -4, 10], [7, 13, 19], [-13, 35, 3], [32, 4, -14], [35, 15, -16], [-14, 24, -1], [-22, -6, 1], [17, 34, -18], [-17, -13, 10], [7, -1, 20], [-29, 5, -8], [5, 41, -30], [18, -10, 34], [-12, 12, 27], [-33, -17, 7], [-7, 29, 8], [14, 27, -21], [28, 29, -15], [5, -8, -3], [-20, -19, 6], [-37, 0, -9], [-23, 4, -14], [24, 40, -30], [7, -30, 31], [10, -22, 9], [10, -26, 15], [1, -10, -17], [2, -1, -17], [-39, -1, -16], [15, -15, 13], [-22, 28, -4], [-15, 0, 17], [-39, 11, -16], [-38, -1, -3], [-23, 2, 19], [10, 26, 0], [9, 15, -26], [14, 1, 22], [21, 6, 10], [37, 8, -18], [6, -4, 4], [-4, -9, 13], [26, -20, 7], [11, -5, 32], [5, -3, 14], [-18, 31, 11], [-11, -13, 22], [22, -27, -1], [-19, 22, -12], [9, -14, -20], [-38, 16, -1], [-9, -39, 19], [37, -18, 23], [-2, 1, -21], [17, -5, -22], [20, -26, 33], [-29, -11, 4], [-6, 28, -22], [31, 2, 1], [-5, -3, 23], [-16, 13, -18], [1, -25, 22], [-25, 7, 5], [-12, -44, 39], [3, -10, -30], [23, -26, -8], [-8, -39, 1], [11, 2, 7], [-24, 4, -36], [43, 14, 7], [21, 7, -28], [4, 15, 10], [-29, -2, -30], [-53, 19, 6], [25, 16, -23], [-10, -12, -25], [11, 20, 1], [28, 7, -5], [-23, 36, -15], [-45, -26, 9], [28, 11, 2], [-28, -8, 10], [-21, 20, -10], [-16, 24, -17], [0, -17, 0], [10, 21, 8], [-27, -28, 20], [-21, 3, -9], [-15, 13, -22], [46, -12, -10], [5, 31, -9], [-30, -3, 15], [28, -22, 9], [47, -15, 8], [-1, 34, -11], [0, 18, -17], [13, 28, -31], [-6, -6, -39], [-32, 8, 5], [-10, -22, 33], [16, 10, -10], [-6, -34, 26], [-24, 33, 18], [-27, 21, -3], [-1, 26, -10], [-7, 41, -31], [-16, 24, 17], [1, -20, -34], [15, -23, 5], [3, 33, -39], [46, -6, 8], [38, 35, -31], [10, -21, 2], [-25, -27, 22], [23, -20, 15], [14, 14, 11], [-22, 42, -12], [10, -40, -10], [12, -23, 31], [-19, -25, 29], [39, 19, -6], [-1, 21, 1], [38, 4, 16], [14, -16, 11], [19, -18, 0], [15, 36, -45], [14, 13, -8], [-8, -29, 32], [-3, -24, 35], [-24, -4, -14], [47, 16, -3], [-23, -32, 2], [-33, 0, 18], [-5, 21, 6], [8, 56, -35], [0, 25, 10], [-20, 13, -6], [-2, -9, 19], [11, -13, -14], [14, -7, 52], [27, 29, -27], [29, -26, 39], [5, 0, -2], [-7, -23, -27], [-31, 33, -11], [-16, -1, -40], [-21, 31, -32], [-25, -46, 31], [-1, 1, -15], [-16, -26, 28], [9, 39, -9], [6, 21, -12], [10, -4, 26], [-51, 1, -22], [-29, -28, 9], [11, 34, -42], [3, 35, -7], [-27, 13, -21], [38, -3, -19], [-22, 3, 3], [21, 6, -41], [68, -4, 7], [-44, -11, -8], [48, 2, -3], [36, -10, -19], [38, 7, -24], [-10, 25, 0], [22, 30, -6], [-3, 27, 18], [20, 4, 6], [-36, -17, -5], [-1, 20, -17], [-18, 8, 39], [47, -33, -4], [-10, -29, 4], [29, 16, -16], [11, 23, -24], [7, -39, 16], [27, 29, -43], [2, -17, 0], [-23, -31, 1], [31, 43, -34], [-5, 11, 14], [22, 48, -30], [-13, 4, -1], [11, -31, 53], [19, -27, -2], [-6, -43, 41], [16, 27, -27], [-6, 37, -10], [61, -5, 7], [28, -34, 9], [24, 21, -8], [2, -7, 33], [3, -19, 20], [29, 27, 1], [10, 38, -2], [28, 3, 3], [28, -18, 9], [4, -3, -35], [56, -5, 27], [-33, 1, 21], [59, -4, 3], [-18, 35, -62], [55, 1, 3], [-1, -24, 0], [46, 12, -3], [30, -15, 7], [-3, 31, -23], [12, -43, -12], [-9, -39, 25], [-13, 7, 17], [-39, -15, 13], [-17, -4, 24], [-3, -29, 13], [-17, 43, -4], [23, -17, -9], [-3, -2, -11], [36, -17, 33], [13, 20, -26], [-67, 9, 6], [-8, -13, 36], [-21, -1, -18], [-14, 32, 20], [15, 18, 30], [-55, -2, -3], [49, -15, 29], [-17, 27, -24], [70, -10, 15], [19, 38, -41], [17, 52, -16], [3, -27, 50], [11, -14, -27], [-34, -20, 7], [9, 25, 24], [-26, 30, -47]];
    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_w();".
// 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_w(:prec:=3)
    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_w();".
// 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_w( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2601_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<2,R![-1, -3, 0, 1]>,<5,R![1, 9, 6, 1]>,<7,R![-1, -3, 0, 1]>],Snew);
    return Vf;
end function;