
// Make newform 2023.2.a.a in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_2023_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_2023_2_a_a();".
// 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_2023_2_a_a();".
// 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_2023_a();"
function MakeCharacter_2023_a()
    N := 2023;
    order := 1;
    char_gens := [290, 1737];
    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_2023_a_Hecke(Kf)
    return MakeCharacter_2023_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], [-3], [-4], [1], [0], [-2], [0], [-7], [-4], [-3], [-7], [-10], [0], [-2], [3], [-3], [-9], [-8], [-8], [-2], [-6], [-6], [-1], [-8], [-2], [2], [-7], [16], [9], [2], [-4], [-19], [9], [20], [-7], [2], [-14], [-18], [1], [20], [-6], [-16], [-22], [-23], [15], [-16], [10], [-15], [9], [-6], [-9], [2], [12], [-24], [30], [-16], [-10], [17], [-5], [18], [-5], [12], [15], [-31], [10], [31], [4], [-13], [16], [-36], [24], [-12], [23], [-15], [-4], [21], [27], [24], [-1], [32], [28], [13], [12], [-16], [-1], [-26], [-7], [3], [-14], [-40], [-12], [-36], [10], [-22], [-2], [-9], [-20], [10], [-12], [39], [-4], [-18], [11], [-23], [-22], [16], [-17], [42], [18], [-16], [7], [34], [27], [-15], [-38], [-45], [28], [-28], [-3], [28], [-4], [19], [42], [-8], [-1], [-9], [46], [8], [-20], [-8], [34], [-36], [-38], [-5], [38], [4], [40], [20], [-8], [-26], [-49], [18], [-14], [36], [-34], [-29], [-14], [-16], [43], [-20], [30], [-50], [-24], [-48], [-26], [34], [-24], [18], [28], [0], [-44], [11], [54], [-12], [21], [9], [-24], [-46], [-31], [-12], [6], [32], [24], [-35], [16], [22], [-20], [-18], [-15], [-20], [30], [21], [-38], [0], [14], [6], [26], [-36], [-34], [-3], [52], [40], [-38], [-28], [-54], [16], [59], [-62], [-24], [37], [-62], [-15], [50], [-62], [-5], [8], [55], [12], [69], [-4], [22], [-12], [-66], [12], [-28], [14], [-8], [42], [-18], [-29], [71], [0], [6], [-32], [-37], [7], [-6], [60], [32], [18], [11], [25], [-70], [3], [-53], [-73], [-14], [-65], [-6], [-53], [50], [-52], [21], [-39], [48], [29], [-29], [-43], [4], [-6], [61], [26], [-8], [28], [0], [-8], [-55], [-13], [-22], [8], [18], [66], [-40], [-2], [-22], [60], [-26], [-32], [26], [51], [-18], [28], [-38], [22], [22], [-16], [-72], [61], [22], [13], [0], [18], [-52], [2], [3], [0], [-78], [3], [-64], [58], [-30], [3], [-19], [-20], [-45], [78], [15], [-78], [-76], [-28], [24], [18], [46], [-18], [10], [-65], [-62], [-40], [-42], [-7], [-64], [10], [-69], [-40], [2], [70], [55], [32], [86], [-15], [52], [-57], [-58], [-14], [-54], [-72], [54], [-28], [60], [-27], [43], [-39], [15], [51], [28], [-33], [-38], [-48], [-40], [11], [93], [42], [-48], [-10], [18], [78], [2], [74], [75], [12], [-3], [-67], [69], [-11], [-31], [90], [-13], [-55], [-63], [12], [27], [-68], [48], [-54], [-12], [81], [-64], [-6], [25], [-64], [44], [24], [-87], [87], [31], [-69], [28], [82], [-64], [-34], [-30], [51], [50], [-7], [-49], [21], [68], [-62], [90], [77], [-65], [-14], [74], [3], [-60], [23], [-20], [2], [22], [-89], [8], [-17], [-60], [26], [94], [-49], [2], [51], [-51], [-27], [-84], [-33], [-34], [88], [-55], [96], [98], [-16], [-18], [-27], [-98], [38], [-42], [49], [104], [44], [-54], [-37], [55], [-24]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2023_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_2023_2_a_a();".
// 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_2023_2_a_a(:prec:=1)
    chi := MakeCharacter_2023_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_2023_2_a_a();".
// 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_2023_2_a_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2023_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<2,R![1, 1]>,<3,R![3, 1]>],Snew);
    return Vf;
end function;