
// Make newform 2601.2.a.r 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_r();".
// 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_r();".
// 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 := [-3, -1, 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 := [[0, 1], [0, 0], [0, -1], [2, -1], [-3, 0], [-1, -1], [0, 0], [-1, 3], [0, -1], [-3, -3], [-1, 2], [-4, 2], [-6, 0], [-7, 2], [-3, 0], [-9, 3], [-6, 0], [5, -6], [8, 2], [-6, 4], [5, -2], [2, 4], [9, -5], [6, -4], [-4, -3], [9, -2], [2, 0], [3, 4], [5, 4], [0, 5], [-1, -6], [0, 2], [-12, 6], [8, 5], [6, -2], [5, 0], [8, -1], [-13, -2], [-21, 1], [3, 2], [0, 9], [-13, -4], [9, 1], [-7, 12], [0, 3], [-1, 2], [-16, 3], [-16, -5], [-3, -6], [8, -8], [-18, 6], [-3, 4], [2, -5], [9, 3], [-6, -9], [-9, -5], [15, -7], [8, -15], [-4, 0], [6, -15], [20, 0], [12, 6], [-4, 7], [-27, 5], [-4, 6], [9, -14], [2, -1], [11, 5], [15, 1], [11, -2], [-3, 0], [18, -3], [20, 2], [-1, 4], [-13, 2], [3, -3], [15, -12], [5, -2], [18, -1], [-25, 6], [-21, 4], [2, -13], [-18, 3], [-28, 0], [2, -10], [3, 14], [-3, 5], [2, -5], [-6, 8], [2, 6], [-18, -3], [15, -12], [-19, 3], [6, 7], [-16, -3], [-9, -12], [-9, 2], [-24, 16], [5, -8], [5, -5], [-7, 14], [0, -12], [-12, -2], [-15, 2], [-19, 5], [5, 14], [21, -7], [9, 12], [-15, 12], [-25, -1], [11, -12], [-4, -10], [21, 0], [11, -20], [-13, 17], [-3, -3], [-16, -6], [3, -20], [21, -6], [39, 2], [20, -9], [32, -12], [-3, -3], [3, 19], [-16, 8], [-9, -12], [23, -9], [-39, 2], [38, -4], [17, -1], [-13, 8], [-15, -6], [11, -24], [-31, -4], [-21, 4], [11, -13], [15, -16], [-10, -10], [27, 8], [-6, 10], [-4, 14], [-3, -6], [-7, 18], [27, -18], [-10, 18], [-18, -14], [5, 0], [39, -10], [44, 2], [24, 11], [-28, 7], [3, 7], [-13, 1], [-24, -9], [-13, -15], [-18, 7], [23, 1], [-39, -9], [-4, -19], [-42, -3], [45, -8], [12, -5], [-28, 13], [-36, 9], [3, 15], [6, 12], [-13, 19], [-25, -7], [41, -10], [-24, -3], [-3, 12], [-16, 21], [21, 6], [11, 2], [8, -16], [-21, 1], [-31, 3], [45, 0], [14, -14], [47, 2], [-16, 13], [-12, -6], [-34, 18], [-18, 30], [-57, 4], [42, -12], [5, -22], [-43, 10], [-37, 2], [-9, 21], [44, 9], [-27, 16], [-4, 2], [54, -2], [-45, 12], [-3, -8], [17, -22], [26, -18], [15, -6], [6, -7], [15, 7], [2, 16], [-25, 27], [20, -22], [6, 2], [39, -2], [-13, -19], [-6, 0], [24, -9], [20, -12], [26, -18], [21, -24], [-7, -11], [6, 24], [-18, -10], [-7, 26], [35, -13], [-21, -9], [-36, 18], [18, -16], [2, 6], [17, 1], [39, -6], [-19, 6], [33, 4], [-16, -13], [15, 24], [-18, 9], [14, -6], [6, 9], [-16, 3], [2, -27], [29, -6], [30, 0], [-7, 8], [9, -26], [-22, 0], [12, 22], [-51, -3], [6, -10], [-24, 14], [17, -9], [-37, 7], [-22, 19], [12, -15], [-24, -4], [-19, -6], [-9, -22], [-1, -10], [0, 18], [-28, -7], [15, 5], [9, -10], [-58, 6], [15, -12], [-30, -13], [-13, 2], [47, 14], [33, -31], [26, -12], [-16, 28], [6, -15], [-28, -4], [26, 12], [18, -19], [-7, 28], [-30, -7], [3, 8], [-1, 5], [-33, 30], [26, -29], [5, -25], [11, 23], [35, -31], [20, -4], [-19, -6], [12, -30], [29, 17], [14, -22], [-15, 35], [-42, 18], [44, -8], [-42, 20], [32, 15], [17, -2], [9, 24], [50, 7], [21, -6], [-49, 0], [15, 26], [33, 6], [9, 12], [-39, -5], [-39, -11], [38, -35], [-24, 33], [56, -8], [33, -21], [-39, -4], [-13, 21], [-55, 13], [45, 0], [-46, -6], [-6, 9], [-16, -3], [20, 0], [3, 8], [53, -7], [-6, -27], [-19, 3], [-33, 29], [21, -14], [15, 18], [-49, 0], [3, 10], [32, -40], [-15, 2], [-45, -10], [-25, -1], [-33, 33], [5, 15], [-28, -26], [-69, 4], [23, -16], [15, 30], [23, -8], [41, -8], [23, -10], [15, -24], [0, -3], [-49, 21], [66, -6], [56, -5], [-12, -3], [8, 9], [-36, 24], [-31, -22], [12, -12], [-37, 32], [-7, 36], [47, 19], [-3, -21], [48, -3], [17, 0], [-39, 6], [-36, -6], [-46, 29], [-31, 30], [-39, 36], [72, 6], [-19, -2], [-49, -10], [-24, 3], [-31, -9], [29, -6], [-27, -6], [6, -23], [-66, 11], [66, -12], [-12, 6], [-61, 7], [0, -14], [-18, -30], [60, 3], [14, -23], [83, -2], [75, 8], [-4, 13], [44, 12], [-27, 37], [50, 5], [21, 21], [-21, 33], [8, 10], [44, 18], [21, 3], [21, 28], [14, 20], [21, -23], [5, -3], [42, -18], [3, 36], [-49, -10], [-6, 23], [-10, -4], [18, -33], [68, -18], [35, -31], [-40, 22], [51, -8], [23, -21], [-63, 7], [-24, 16], [-52, 1], [-39, -21], [-1, 35], [-67, -4], [9, 7], [29, 15], [0, 20], [-10, 38], [51, 17], [-1, 16], [36, 8], [-39, 29], [59, 5], [32, -18], [24, -6], [8, -29], [-39, -12], [20, -17], [-39, 0], [-69, 7], [-22, 18], [-16, 21], [27, -24], [24, -46], [29, -16], [9, -9], [21, 6], [3, -28], [14, -25], [-66, 6], [36, -28], [68, -19], [-21, 16], [-3, -6], [15, -4], [5, 26], [-48, 15]];
    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_r();".
// 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_r(: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_r();".
// 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_r( : 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, -1, 1]>,<5,R![-3, 1, 1]>,<7,R![-1, -3, 1]>],Snew);
    return Vf;
end function;