
// Make newform 2601.2.a.n 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_n();".
// 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_n();".
// 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, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    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, -2], [3, 0], [-2, -2], [1, -4], [0, 0], [-3, 0], [0, -2], [6, 2], [1, 4], [1, -4], [-6, 2], [3, 0], [4, -4], [-4, -4], [6, -2], [1, 4], [1, 0], [8, 2], [-2, 4], [12, 0], [-4, -2], [6, 8], [-5, 4], [6, -4], [-15, 0], [-6, 0], [2, 4], [2, 4], [-7, -4], [12, 2], [2, 14], [11, 4], [-16, 2], [5, 0], [-1, 12], [-4, -4], [2, 8], [-10, 8], [2, 10], [3, -12], [-12, 10], [1, 8], [-8, -4], [8, 0], [5, -12], [4, -16], [18, -6], [6, -12], [12, -4], [10, 4], [6, 0], [2, -2], [0, 0], [-14, 8], [8, 2], [-13, 8], [-9, -12], [-6, -2], [-3, 0], [-12, -8], [4, -4], [6, -12], [-19, -4], [12, -6], [-13, -4], [-2, 0], [-4, -14], [-10, 16], [0, 8], [-24, -4], [-23, -4], [26, -4], [3, 0], [14, -10], [14, 10], [22, 0], [-12, 14], [5, 0], [-8, 10], [25, 8], [24, -12], [19, 12], [11, -8], [-24, 2], [-18, -12], [14, 8], [6, 16], [1, 8], [-12, -12], [2, 10], [-17, 12], [-6, -12], [-7, 12], [10, -10], [-6, 4], [4, -10], [16, 0], [-6, -24], [5, 0], [-16, 4], [18, 16], [22, 4], [3, 24], [3, 12], [32, -2], [30, -2], [-18, 2], [-11, 4], [15, 0], [31, 0], [24, -16], [4, 0], [-17, 12], [2, 14], [19, -4], [18, 12], [4, 32], [14, 20], [-21, -12], [-15, -24], [-18, 6], [-6, -4], [11, -20], [18, -6], [35, 12], [18, 16], [1, 0], [1, 16], [-37, -12], [-18, 2], [7, 0], [17, 0], [12, -22], [-26, -16], [-18, 12], [11, 28], [-38, -8], [-12, 6], [15, 12], [-10, 10], [1, 20], [18, -18], [1, 16], [-18, 12], [25, 12], [-6, 0], [-27, -12], [18, -4], [10, 0], [2, 16], [0, -24], [4, 8], [-7, -4], [8, 10], [24, 12], [-20, -28], [-1, 12], [-24, -12], [-18, -12], [0, -22], [-32, 20], [32, 16], [6, -22], [12, 4], [24, -12], [1, 24], [-21, -12], [-30, -14], [0, -16], [-5, -24], [26, -10], [1, -8], [47, 0], [26, 4], [37, -12], [20, -8], [4, 24], [23, 0], [24, 24], [52, 4], [-13, 24], [-46, -10], [6, 24], [-12, 16], [-17, -8], [28, -12], [15, 36], [14, 10], [-29, 24], [48, -14], [29, 16], [-36, 2], [60, -4], [-10, 40], [29, -12], [30, 0], [18, -26], [-10, 28], [-4, -2], [16, 12], [-39, -12], [33, -12], [8, -10], [-24, 6], [7, 12], [-18, 2], [-18, -2], [-5, -20], [9, 12], [8, -32], [24, 12], [-36, -24], [30, 12], [-23, -28], [-11, 28], [6, 22], [-38, -14], [-60, -6], [53, -12], [16, -12], [18, -10], [-7, -12], [-40, -10], [11, -4], [-12, -12], [-24, 8], [-11, -32], [-16, -20], [21, 36], [-8, 32], [-25, 4], [-28, 4], [-25, 4], [-6, 12], [14, 24], [-26, -16], [-42, 18], [-32, -2], [6, 48], [-1, 4], [24, 24], [26, -12], [6, 18], [18, -24], [43, -16], [-2, 40], [-7, 4], [-24, 36], [-3, 24], [22, -16], [-34, -4], [7, 12], [-12, 20], [-22, -32], [-25, 16], [-27, 36], [-62, 8], [-37, -8], [12, 0], [6, -38], [-61, 4], [13, -8], [-30, 32], [-4, 20], [30, 4], [24, 6], [-37, -12], [-2, 34], [30, 12], [1, 28], [-31, 12], [-27, -24], [26, 24], [-23, 24], [4, 16], [-73, 0], [-1, 4], [54, 12], [30, -14], [-32, 16], [36, -10], [-13, 20], [-28, 12], [42, 6], [38, -12], [-22, -26], [31, 32], [-12, -22], [-30, -14], [36, 8], [-30, 0], [-18, -4], [30, -36], [42, -22], [32, 20], [-6, 6], [66, -4], [45, -12], [6, 12], [48, 8], [17, 24], [38, -10], [-43, -16], [2, -32], [-2, 16], [47, -8], [-76, -8], [31, -20], [-20, -38], [10, 32], [12, 40], [36, 0], [12, 38], [-7, -24], [-30, 24], [18, -24], [43, 12], [-72, 0], [47, -24], [-22, -4], [-6, -44], [25, -8], [14, -10], [-30, -12], [4, 36], [16, 16], [2, -14], [6, -58], [-17, 36], [6, 10], [24, -12], [10, -26], [-1, -20], [-12, 56], [-9, 12], [-4, 20], [-49, 16], [-8, 16], [-6, 36], [40, 32], [22, 22], [20, 8], [-54, -18], [-8, -16], [-14, 0], [-31, 8], [40, -16], [24, -4], [20, 40], [-1, -40], [42, -34], [11, -60], [-29, 16], [50, 2], [56, -2], [12, -54], [-86, 2], [-84, 0], [46, 8], [-6, -44], [-42, -38], [-18, 50], [-12, -12], [14, -44], [16, -2], [-32, 24], [13, -28], [70, -8], [-19, -32], [-48, 4], [-12, -8], [8, 48], [-37, 32], [-28, 44], [72, -2], [3, -24], [26, -20], [-23, -12], [18, 22], [42, -2], [-15, 36], [-54, -12], [-37, -20], [-18, 2], [-51, 36], [33, 0], [-52, -20], [2, 44], [35, -12], [-48, -10], [-18, -16], [-32, 40], [14, 2], [-13, -24], [-27, 24], [16, 50], [-17, 28], [-22, -8], [-11, -48], [0, -34], [24, 12], [24, 6], [-12, 14], [-13, -60], [-3, -12], [4, 4], [-4, -8], [-12, 44], [18, -12], [-38, 14], [24, 30], [-61, -4], [29, -24], [60, -20], [-20, -2], [39, 36], [-78, 2], [66, 6], [-12, 50], [21, -36], [6, -46], [18, 8], [-3, -12], [90, -8], [0, -20], [66, 4], [-19, 20], [60, 28]];
    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_n();".
// 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_n(:prec:=2)
    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_n();".
// 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_n( : 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, 2, 1]>,<5,R![-8, 0, 1]>,<7,R![-3, 1]>],Snew);
    return Vf;
end function;