
// Make newform 2450.2.a.bc in Magma, downloaded from the LMFDB on 24 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_bc();".
// 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_bc();".
// 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], [1], [0], [0], [-6], [-4], [0], [-2], [3], [-3], [-8], [4], [-9], [7], [0], [6], [6], [-5], [-5], [-6], [-16], [2], [3], [15], [14], [-15], [-1], [15], [11], [-6], [-8], [0], [-12], [10], [15], [-4], [-22], [4], [-3], [0], [-24], [-11], [-6], [-2], [6], [4], [-10], [-28], [-12], [-14], [12], [12], [-2], [12], [0], [21], [-15], [-2], [-8], [-6], [-4], [12], [5], [18], [8], [-12], [-28], [22], [-9], [-17], [-6], [24], [35], [4], [-34], [-15], [-30], [14], [15], [13], [0], [17], [30], [-22], [28], [-21], [-9], [-32], [-18], [13], [-15], [-12], [16], [0], [-22], [21], [-21], [18], [-28], [-25], [19], [18], [27], [6], [-22], [26], [12], [6], [12], [46], [23], [16], [12], [-14], [14], [-3], [20], [3], [48], [6], [-41], [-8], [12], [-9], [22], [-3], [-31], [18], [-19], [-34], [26], [-39], [-4], [28], [-42], [-50], [-12], [-43], [-48], [21], [16], [-18], [19], [-15], [-2], [30], [-46], [6], [-32], [-27], [-2], [-57], [52], [-21], [25], [18], [14], [21], [-28], [6], [3], [-60], [-35], [0], [6], [39], [-28], [14], [-19], [30], [24], [-23], [60], [-26], [40], [-9], [38], [-30], [41], [-47], [-17], [12], [-26], [30], [-36], [39], [-32], [44], [-25], [-18], [20], [-24], [-10], [3], [-60], [-6], [-31], [-26], [-66], [24], [57], [-20], [-58], [-53], [12], [42], [10], [36], [-15], [-44], [34], [-9], [-47], [-57], [30], [-2], [67], [-51], [48], [24], [29], [22], [-15], [-56], [3], [11], [48], [-66], [17], [-24], [4], [-2], [-10], [-15], [-43], [-21], [-23], [24], [42], [54], [36], [-56], [32], [-31], [72], [42], [35], [0], [-40], [72], [-56], [57], [33], [37], [-24], [-30], [-37], [23], [30], [38], [-35], [63], [-26], [-64], [-24], [-14], [78], [-30], [31], [-60], [-59], [16], [14], [32], [14], [-64], [-72], [65], [29], [42], [-39], [-16], [72], [1], [-37], [-60], [-74], [24], [-56], [-6], [-3], [21], [-84], [-30], [-62], [45], [-14], [54], [-30], [-52], [68], [-18], [74], [-33], [-64], [52], [-36], [-5], [36], [16], [15], [-90], [-57], [7], [63], [31], [24], [-42], [-10], [-81], [-80], [-68], [51], [43], [24], [31], [-76], [71], [72], [6], [-46], [-72], [10], [57], [-22], [69], [26], [-54], [91], [8], [76], [60], [-15], [-10], [18], [42], [79], [-17], [72], [-48], [-2], [16], [-3], [-73], [41], [-24], [96], [66], [-84], [15], [-14], [42], [87], [60], [23], [-32], [12], [40], [77], [-42], [-8], [69], [-30], [40], [64], [-30], [-54], [32], [-6], [26], [9], [12], [7], [72], [4], [-21], [-10], [68], [43], [69], [62], [24], [36], [-100], [-6], [-74], [58], [-9], [-4], [33], [85], [54], [-95], [-24], [45], [-26], [-68], [-81], [41], [36], [-82], [66], [-84], [56], [34], [30], [90], [-64], [78], [51], [-9], [32], [-51], [12], [74], [-102], [-12], [-81], [16], [90]];
    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_bc();".
// 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_bc(: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_bc();".
// 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_bc( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2450_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![-1, 1]>,<11,R![6, 1]>,<13,R![4, 1]>,<17,R![0, 1]>,<19,R![2, 1]>,<23,R![-3, 1]>,<37,R![-4, 1]>],Snew);
    return Vf;
end function;