
// Make newform 2601.2.a.z in Magma, downloaded from the LMFDB on 25 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_z();".
// 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_z();".
// 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 := [[1, -1, 0], [0, 0, 0], [1, 1, -1], [-1, 2, -1], [-1, 2, 1], [-5, -1, 1], [0, 0, 0], [-1, 0, -3], [-1, -1, -2], [2, -3, 5], [-4, -1, 2], [1, 0, 5], [-6, -2, 1], [-8, 2, -2], [0, 1, -5], [8, 1, 0], [3, 6, -3], [-3, -1, -3], [-6, 0, 4], [5, 4, 0], [5, 1, -2], [-1, -2, 4], [0, -9, 3], [0, -7, 2], [-5, 0, 2], [4, -4, -3], [0, 9, -5], [0, -6, 3], [-1, 3, -3], [-10, 1, -3], [4, -4, 7], [-8, 6, -8], [15, -1, 2], [-7, -7, -1], [5, 1, -6], [0, -4, 0], [-4, 5, -4], [5, -9, 6], [-2, -6, 13], [-7, 7, 3], [-13, -5, 3], [-5, 9, -10], [1, 8, 0], [-3, -7, -3], [-4, -10, 4], [-10, 11, -1], [-7, -2, -2], [8, -6, 3], [-3, 13, -8], [-10, 2, -13], [5, 4, -9], [-9, 0, 9], [-1, -8, 7], [-2, 8, -3], [10, -9, 7], [6, -7, 11], [5, 1, -9], [-6, 0, -5], [4, -13, 13], [0, 8, -10], [7, -3, -10], [-2, 12, -2], [5, -5, 7], [-8, 11, -6], [10, 8, -5], [9, 5, -10], [-1, -3, 12], [14, 1, 7], [6, -1, -4], [-1, -5, -14], [-19, 9, -7], [-3, 9, 0], [-15, 3, 1], [-28, 2, -7], [-8, -11, 18], [-18, 4, 1], [13, -4, 15], [17, 10, -8], [-5, 14, 9], [19, -3, -10], [4, 0, -8], [-2, -8, -3], [-10, -5, -9], [11, -3, -6], [-18, -3, -2], [-4, -2, -18], [5, 12, -1], [-4, 10, 10], [15, 13, -8], [7, -15, 8], [-8, 1, -22], [-11, -18, 16], [-11, 9, -19], [19, 10, -10], [6, 10, 11], [-14, -11, 8], [-1, -11, 0], [11, -14, 9], [5, -2, -5], [-7, 3, 6], [9, 21, -8], [7, 1, -7], [-21, 9, 6], [9, 2, 14], [1, 5, 7], [9, 0, 7], [10, -8, -7], [24, 4, -8], [-17, 10, -16], [-29, 3, -1], [-13, 4, 1], [-3, -13, 3], [7, 8, 9], [20, 10, -5], [11, -1, -10], [15, 9, 6], [0, -9, 19], [6, -1, -4], [26, -2, 15], [-10, -22, 25], [15, 3, -17], [-13, -13, 14], [10, 15, -5], [-4, -24, 26], [-2, -23, 0], [10, 3, 13], [-13, 6, 9], [8, -18, 20], [-6, -9, 1], [2, 14, -1], [8, 3, 9], [-9, -11, 22], [4, -16, -2], [-18, -14, 17], [1, -20, 17], [-4, 17, 11], [-5, 12, -29], [-9, 1, 5], [-6, -8, 22], [-13, 14, -5], [2, 21, 3], [-37, 0, -13], [-26, -3, 14], [-8, 3, -20], [7, 30, -4], [-28, 0, 5], [0, 22, -34], [-14, 11, 0], [26, 4, 16], [7, 6, 7], [-1, 26, -1], [0, -11, -8], [23, -5, 4], [-5, 7, 2], [22, 10, -12], [-5, 5, -24], [-16, 13, -23], [29, -11, 6], [-20, -9, 11], [-1, -10, 22], [-5, -2, 23], [15, -17, 37], [-25, 16, -17], [-5, -20, 8], [12, -26, 13], [-26, -11, -4], [-10, 10, -32], [18, 13, 8], [9, 9, -20], [18, -15, 3], [8, -7, -5], [3, -27, 37], [-13, 8, 1], [-28, 15, -24], [5, 8, 2], [12, -10, -1], [13, 19, -12], [-16, -31, 25], [2, 2, 5], [-29, 12, -13], [11, -2, -26], [-21, 12, -18], [-21, -3, -5], [-6, 28, -11], [-22, -6, 14], [1, 29, -12], [24, -19, 21], [-7, 9, 15], [-11, 13, -18], [-39, -7, 11], [29, -6, 21], [20, -18, -10], [-7, 6, 15], [-21, -6, 3], [0, 19, -20], [18, -2, -17], [-4, -26, 7], [5, 4, -5], [-13, 14, 16], [9, 21, -24], [16, 6, -20], [11, -19, -4], [26, -2, 16], [6, -26, -4], [-4, -13, 31], [-6, 23, 2], [7, 7, 0], [33, -3, 24], [-11, -38, 38], [-49, -24, 15], [8, -13, 32], [5, 14, -8], [8, -20, -2], [-22, 1, -3], [-47, -3, -2], [-12, -1, 18], [14, -19, -1], [7, 0, 7], [21, -7, -13], [12, -1, 26], [-4, 5, 17], [-4, -20, 4], [-14, -28, 15], [1, -20, 9], [-10, 30, 17], [-23, 5, 22], [6, 43, -11], [5, 2, -2], [-16, 1, 1], [12, -29, 37], [-20, -2, 15], [-25, 7, -23], [-4, 21, 0], [-9, 5, -37], [13, 1, -15], [6, -19, 5], [-22, -20, 4], [-35, 1, 2], [-2, 9, -11], [-2, 35, -33], [36, -18, -15], [-6, -12, 28], [8, 27, -6], [-13, -15, -3], [-18, 16, -14], [-20, 26, -42], [-40, -12, -3], [-3, -15, -18], [-14, 23, -29], [-12, -9, 6], [-12, -17, -7], [48, -8, 4], [28, -11, 20], [-12, 35, 0], [44, 3, 8], [43, -6, -11], [9, -14, -25], [-20, 26, -8], [-20, 0, -5], [10, 12, -10], [17, 22, -8], [36, 32, -19], [-18, -7, 24], [4, -7, -5], [-13, -3, 23], [-25, 29, 11], [25, 23, -30], [-35, -41, 29], [-2, -8, 9], [41, 1, -3], [-7, 24, 0], [20, 3, -27], [59, -6, 9], [0, 2, 21], [2, 1, 25], [15, 7, -10], [5, -7, -11], [-26, -32, 21], [5, -17, -8], [-14, -15, 22], [36, -24, 30], [17, -11, 25], [7, -23, 2], [-6, 17, 12], [20, -6, 27], [26, 27, -34], [17, 2, -4], [-27, 20, 11], [-15, -6, 13], [-21, -36, 18], [19, -9, -11], [25, -23, 20], [-9, 2, -46], [1, 7, -4], [29, -18, 3], [-1, 37, 3], [11, -20, 31], [20, -28, 37], [25, 0, -8], [-19, -21, 15], [20, 2, -4], [-7, 1, 0], [-62, 10, 3], [14, -12, 44], [28, 10, -33], [-1, 2, -22], [-28, -31, 10], [-6, -16, 36], [1, 25, -1], [-38, 31, -3], [-1, 45, -10], [-9, -6, -3], [21, 22, -8], [-19, 17, -16], [-7, 27, 8], [37, 1, -21], [41, 11, -2], [-11, -21, -2], [-28, 29, 11], [-22, -17, 30], [-15, 9, 34], [5, -8, -17], [38, 10, 3], [-5, -37, 1], [1, 26, -21], [38, 37, -14], [20, -23, 58], [11, 43, -41], [23, 27, -13], [15, -26, 4], [6, -20, -25], [65, -8, 6], [-55, -16, -1], [-39, 21, -30], [9, 46, -46], [31, 9, 4], [-36, -6, 19], [41, -22, -2], [23, -22, -4], [-13, 43, -23], [-31, 12, 3], [29, 58, -36], [3, -25, -31], [11, 18, 18], [20, 15, -34], [-28, -11, 30], [44, -8, 28], [52, -11, 9], [36, 12, 6], [26, 54, -25], [2, -9, -12], [49, -8, 30], [-19, -25, 10], [-12, -51, 34], [-45, -40, 33], [3, -25, 29], [17, 3, 20], [16, -38, 8], [-29, 23, -6], [-16, -10, 19], [44, 29, -25], [10, 1, -13], [14, -31, 22], [-62, -14, 11], [-76, -11, 1], [17, -28, 23], [-7, -18, 8], [-22, -16, 32], [50, -36, -18], [60, -11, 13], [-20, -28, -2], [12, 14, -4], [28, 24, -14], [-10, 33, 21], [-10, 12, -39], [-28, -25, 16], [-39, 30, 0], [25, -2, 9], [-21, 20, -1], [-3, -35, 14], [26, -18, -28], [-27, 10, -59], [-49, 9, -15], [44, -28, 19], [23, -47, -5], [11, 1, -45], [3, -4, 0], [-37, -40, 23], [44, 30, -24], [9, 19, -29], [-64, 10, -17], [84, -5, -8], [1, -4, 3], [5, -3, 9], [-21, -47, 28], [-21, -43, 18], [-38, 27, -49], [23, 0, -16], [-34, 10, -29], [-7, 40, -15], [-11, 21, -52], [13, -27, -17], [-34, 18, -39], [52, -1, 12], [-31, -4, -2], [2, -1, 26], [-1, 47, -10], [14, -9, 5], [11, -33, 9], [-31, 11, -32], [-22, -19, 38], [-54, -14, -11], [30, 53, -40], [-24, -45, 13], [-31, 19, -14], [40, -22, 12], [-7, 16, 3], [-37, 9, 3], [-36, -7, -28], [-3, 20, 14], [14, -36, -16], [14, 17, -1], [-6, -31, -10], [-29, 32, -24], [50, -13, -13], [-15, -19, 23], [33, -6, 15], [27, 3, 24], [69, -10, -6], [-50, 19, 23]];
    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_z();".
// 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_z(: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_z();".
// 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_z( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2601_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<2,R![3, 0, -3, 1]>,<5,R![3, 0, -3, 1]>,<7,R![1, -6, 3, 1]>],Snew);
    return Vf;
end function;