
// Make newform 2601.2.a.l 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_l();".
// 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_l();".
// 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
        Kf := Rationals();
    end if;
    return [Kf!elt[1] : elt in input];
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 := [[2], [0], [-1], [2], [-3], [-5], [0], [-1], [-7], [6], [-4], [-10], [9], [1], [12], [12], [-6], [-2], [4], [-8], [0], [6], [-4], [-2], [-8], [-4], [-19], [-11], [0], [-1], [11], [11], [-18], [14], [2], [-16], [-5], [24], [-23], [23], [12], [14], [14], [4], [3], [-16], [-20], [15], [15], [-18], [-15], [8], [-18], [-18], [6], [2], [-31], [-13], [4], [30], [-2], [6], [12], [-16], [16], [10], [7], [-22], [4], [-15], [18], [-6], [2], [30], [14], [12], [-6], [-12], [-7], [5], [4], [-5], [0], [-25], [-28], [-20], [14], [-15], [10], [-16], [-30], [21], [22], [-4], [16], [-9], [-20], [-35], [36], [18], [14], [-30], [8], [16], [20], [37], [-32], [-12], [-30], [-40], [-26], [-17], [18], [-18], [-29], [15], [-44], [-10], [-9], [22], [-7], [28], [9], [-29], [-40], [48], [16], [-13], [4], [10], [19], [12], [-32], [1], [20], [13], [28], [-28], [-20], [-23], [8], [-9], [34], [39], [-34], [-29], [-14], [-58], [-20], [-38], [-6], [46], [-21], [-9], [46], [-47], [15], [27], [-26], [30], [-44], [8], [33], [-48], [-18], [-21], [-60], [38], [-40], [6], [18], [17], [-15], [-17], [-41], [-5], [16], [9], [9], [55], [-27], [36], [28], [-6], [50], [-24], [38], [-39], [38], [-48], [-20], [-44], [-41], [26], [-33], [10], [56], [-44], [42], [16], [61], [-12], [-55], [-23], [-38], [-52], [16], [30], [-15], [-4], [46], [48], [-30], [0], [47], [8], [1], [48], [3], [-32], [29], [6], [-30], [-50], [62], [-26], [15], [21], [-19], [60], [11], [70], [-16], [0], [16], [32], [22], [1], [-39], [-38], [-67], [-40], [51], [-9], [-21], [-7], [16], [-25], [-23], [30], [-11], [50], [-44], [-50], [6], [10], [-10], [-10], [23], [-34], [-42], [-6], [-28], [-56], [-31], [-21], [-2], [52], [-22], [36], [12], [61], [-5], [28], [22], [59], [54], [49], [-35], [-38], [-60], [30], [-40], [-58], [30], [-84], [-42], [-18], [-13], [52], [63], [-39], [-34], [7], [48], [-81], [12], [84], [-43], [-52], [81], [-48], [-26], [-3], [-56], [-20], [34], [62], [-66], [-58], [-16], [-74], [75], [23], [2], [7], [-38], [47], [62], [-18], [-26], [54], [32], [67], [6], [-33], [36], [80], [-84], [21], [-8], [33], [84], [-66], [-2], [-27], [-11], [51], [38], [-43], [57], [60], [-21], [-37], [-42], [69], [20], [-49], [33], [54], [-27], [92], [0], [4], [11], [-30], [-34], [44], [27], [24], [-66], [-11], [78], [-12], [33], [21], [17], [-24], [76], [14], [-52], [15], [66], [48], [-32], [-93], [64], [-101], [80], [53], [-57], [84], [44], [47], [-40], [9], [53], [-2], [66], [-22], [76], [49], [50], [87], [-48], [-52], [-92], [44], [-56], [82], [38], [34], [9], [14], [-98], [-70], [62], [-48], [9], [-99], [18], [78], [80], [-20], [17], [-18], [65], [-88], [-9], [66], [-56], [-16], [-9], [64], [-94], [-64], [60], [-7], [25], [27]];
    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_l();".
// 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_l(:prec:=1)
    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_l();".
// 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_l( : 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, 1]>,<5,R![1, 1]>,<7,R![-2, 1]>],Snew);
    return Vf;
end function;