
// Make newform 2450.2.a.be in Magma, downloaded from the LMFDB on 23 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_2450_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_2450_2_a_be();".
// 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_2450_2_a_be();".
// 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_2450_a();"
function MakeCharacter_2450_a()
    N := 2450;
    order := 1;
    char_gens := [1177, 101];
    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_2450_a_Hecke(Kf)
    return MakeCharacter_2450_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], [2], [0], [0], [0], [-2], [3], [8], [9], [-6], [5], [-8], [-3], [10], [3], [-6], [12], [-4], [-2], [-9], [10], [5], [6], [3], [-5], [0], [-11], [-12], [-10], [-15], [-8], [0], [-9], [2], [0], [-4], [-2], [-8], [-24], [12], [24], [20], [15], [-5], [-18], [17], [2], [-23], [-18], [20], [6], [15], [-22], [0], [-18], [-9], [-30], [11], [4], [3], [-2], [-6], [16], [21], [-17], [12], [14], [13], [6], [26], [9], [-24], [-8], [-2], [8], [-9], [-18], [-2], [18], [-7], [-30], [-4], [-3], [-29], [23], [12], [-27], [22], [-24], [25], [6], [-27], [-11], [42], [-34], [0], [0], [-3], [34], [-10], [-8], [-24], [6], [-3], [20], [34], [-12], [-3], [21], [-22], [25], [-2], [-15], [-10], [-19], [45], [-20], [-24], [-18], [30], [-16], [-5], [-42], [30], [50], [-36], [-4], [-15], [31], [34], [8], [-33], [-16], [-26], [45], [14], [12], [16], [12], [-30], [26], [-12], [-20], [18], [44], [-33], [10], [-54], [-40], [-21], [16], [27], [-26], [-36], [40], [3], [11], [42], [34], [-6], [12], [-54], [7], [30], [51], [0], [29], [4], [-43], [36], [18], [56], [0], [-23], [-25], [-21], [-28], [-48], [-8], [-10], [-8], [-42], [40], [-30], [51], [0], [10], [46], [41], [24], [-62], [6], [-10], [6], [-24], [42], [38], [28], [42], [-12], [12], [23], [-14], [-1], [54], [-24], [71], [-54], [39], [56], [-17], [24], [-23], [-6], [39], [5], [43], [-54], [60], [12], [-4], [11], [45], [25], [-24], [14], [57], [-3], [-17], [-30], [16], [-16], [-67], [-33], [76], [-63], [-34], [6], [-48], [-27], [-36], [2], [-20], [-10], [21], [-39], [-29], [-42], [20], [-45], [-56], [-42], [51], [14], [-18], [-24], [38], [22], [18], [7], [76], [6], [74], [-74], [-57], [32], [0], [30], [58], [6], [-34], [-2], [-23], [11], [-2], [19], [-36], [26], [35], [60], [-21], [47], [33], [50], [-2], [21], [-53], [-42], [-40], [-45], [0], [48], [45], [6], [40], [-6], [8], [-12], [-42], [58], [-41], [6], [35], [66], [-52], [55], [-54], [20], [-72], [28], [-87], [24], [-30], [-38], [45], [-34], [-6], [-33], [49], [15], [50], [58], [-90], [-44], [63], [26], [2], [40], [-51], [18], [32], [24], [53], [54], [-88], [36], [-82], [9], [14], [91], [-44], [51], [-84], [68], [-60], [-90], [8], [-14], [-60], [6], [20], [43], [-48], [67], [-88], [-27], [63], [42], [27], [60], [4], [6], [-51], [24], [-8], [22], [-84], [37], [-46], [-36], [-70], [81], [-60], [11], [52], [84], [72], [-35], [-51], [-77], [36], [30], [-56], [18], [-40], [-87], [-13], [-86], [-8], [-51], [-13], [-24], [96], [76], [-93], [-101], [80], [66], [74], [30], [-40], [-66], [-11], [-90], [6], [-73], [58], [21], [-38], [-12], [94], [-6], [-54], [86], [-23], [-6], [84], [13], [63], [-72], [90], [-38], [-48], [42], [-65], [-30], [30], [-54], [-46], [81]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2450_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_2450_2_a_be();".
// 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_2450_2_a_be(:prec:=1)
    chi := MakeCharacter_2450_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_2450_2_a_be();".
// 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_2450_2_a_be( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2450_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![-2, 1]>,<11,R![0, 1]>,<13,R![2, 1]>,<17,R![-3, 1]>,<19,R![-8, 1]>,<23,R![-9, 1]>,<37,R![8, 1]>],Snew);
    return Vf;
end function;