
// Make newform 2352.2.a.bb in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_2352_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_2352_2_a_bb();".
// 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_2352_2_a_bb();".
// 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 := [-2, 0, 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_2352_a();"
function MakeCharacter_2352_a()
    N := 2352;
    order := 1;
    char_gens := [1471, 1765, 785, 2257];
    v := [1, 1, 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_2352_a_Hecke(Kf)
    return MakeCharacter_2352_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, 0], [-1, 0], [2, 1], [0, 0], [-2, -2], [0, 1], [-2, -3], [-4, 2], [-2, 2], [0, -6], [-8, -2], [-4, -4], [-2, -1], [8, 0], [-4, 2], [-2, 8], [-8, -2], [4, -7], [8, 0], [-2, -2], [-4, 5], [8, 4], [-4, 8], [2, 9], [-12, -3], [2, -1], [-8, 2], [-6, 6], [0, 8], [6, 0], [4, -8], [-4, -8], [-4, -6], [-4, -4], [-10, 0], [-4, 4], [-4, 7], [8, -4], [-4, -2], [-2, 1], [2, 14], [0, 7], [-18, -2], [2, -16], [2, 0], [0, 4], [20, 4], [8, -4], [0, -14], [8, -5], [-20, 6], [6, 2], [-12, 7], [0, 6], [-26, 3], [-22, 2], [6, -17], [16, 2], [-6, 0], [-4, 6], [12, -2], [-6, -5], [20, 6], [12, -10], [-16, 1], [10, -8], [20, 8], [0, 12], [-10, -10], [12, -13], [-6, 7], [10, -18], [0, 0], [26, 8], [12, 8], [-8, 12], [0, 10], [20, 9], [-4, 6], [12, -3], [-8, 2], [18, 8], [22, -6], [8, -13], [-8, -8], [-30, 6], [-10, 0], [-2, -16], [14, -3], [-4, 12], [8, -2], [12, -22], [4, -12], [-10, 10], [0, -20], [-8, -16], [30, -5], [18, -9], [-4, 4], [14, -16], [-12, 12], [10, 24], [-24, -2], [4, 2], [-12, -20], [-8, -1], [24, 2], [22, 5], [-2, -10], [-8, -3], [8, -28], [-8, 4], [-4, 18], [12, 20], [-20, 20], [28, -2], [-28, 6], [-12, -2], [0, 2], [-34, 6], [12, -25], [4, 8], [14, -11], [2, -10], [-28, 0], [-8, -2], [-8, 0], [16, 8], [0, 18], [16, 3], [8, 20], [14, 2], [-24, 4], [0, 8], [-14, -3], [8, -5], [-2, 1], [-12, -16], [-22, 15], [-30, 0], [4, -12], [10, 0], [8, 4], [-6, -18], [16, 9], [-52, -2], [12, -17], [-14, 21], [36, -2], [38, 6], [-8, -20], [-18, 5], [-24, -4], [4, 18], [24, 12], [46, -6], [4, -32], [34, -19], [-16, -7], [-34, 7], [-6, 10], [-30, -16], [12, -16], [12, -32], [36, 10], [-8, -16], [-12, 8], [-36, -1], [22, 0], [-38, -1], [-30, 14], [4, 33], [46, -2], [-4, -4], [32, 0], [18, -9], [-12, -24], [8, 6], [-24, -2], [12, 27], [-24, 24], [-20, 16], [36, 16], [-22, 23], [-2, -6], [-10, 33], [-22, -8], [-20, 12], [4, 12], [-16, 16], [-12, 11], [-18, -6], [-4, -12], [-22, -29], [18, 6], [-42, 1], [20, -8], [-12, 32], [-46, -15], [-52, -6], [38, -8], [-8, -28], [-40, -11], [28, 15], [20, 12], [-10, -31], [24, 16], [-18, -34], [22, -16], [-4, -22], [-16, -8], [-10, -21], [-4, 36], [52, 12], [-60, -6], [48, 3], [12, -40], [-22, 23], [46, 6], [0, 10], [-48, 0], [8, 42], [-14, -24], [-16, 12], [-52, -4], [-20, -28], [10, -3], [-14, 14], [40, 22], [2, 42], [-8, -24], [20, -38], [-12, -8], [-34, 16], [20, -22], [0, -20], [12, -29], [-18, 8], [-10, 2], [-56, 4], [-2, -18], [-28, 24], [-48, -8], [14, 16], [30, 19], [-44, -6], [48, 6], [-24, 22], [60, -4], [-14, 2], [-38, 16], [2, -13], [6, -10], [52, -5], [-6, 19], [10, -34], [44, -8], [-12, -18], [18, -13], [0, -29], [-32, -16], [-42, -2], [40, -7], [12, -1], [30, -7], [-28, 0], [54, 8], [38, -19], [28, 16], [8, -18], [-12, -9], [-20, -24], [36, 27], [0, 4], [-52, 11], [-48, -2], [-38, 18], [-38, 24], [-22, -16], [-24, -14], [16, 40], [36, 4], [40, -12], [-28, 33], [-36, -28], [30, 26], [-54, 0], [42, 8], [32, -30], [18, 13], [22, -24], [-28, 20], [4, 2], [-8, -10], [-2, 40], [-6, -17], [-40, 24], [-6, -27], [40, -30], [4, -24], [-40, -27], [32, 14], [-20, 4], [-26, 30], [-12, 4], [-24, 20], [-34, -26], [56, 13], [-6, -42], [-30, 8], [0, 24], [-8, -10], [28, -2], [32, -8], [46, 14], [28, 13], [-12, 20], [22, -18], [44, -15], [-44, -26], [-20, 38], [-12, -48], [-18, 33], [36, -16], [-6, -8], [36, 9], [-8, -52], [4, 18], [6, -6], [-40, 26], [6, -8], [16, -14], [24, -2], [72, 6], [-40, -8], [56, -10], [-24, 12], [2, 13], [28, 43], [16, -50], [6, -40], [28, 30], [42, -3], [-48, -24], [-56, -2], [-38, 2], [24, 9], [0, 0], [24, 40], [-10, 33], [36, 22], [-46, -8], [14, 0], [24, -24], [54, 16], [-14, -33], [64, 12], [-20, -4], [6, -16], [-42, 26], [-54, 8], [-26, 11], [22, -6], [-26, -6], [52, -12], [-12, 16], [26, 41], [32, 16], [42, 16], [-18, 26], [20, 10], [-6, 18], [-50, 0], [32, -10], [-58, 24], [28, 0], [58, -2], [-8, 9], [-10, -31], [-4, -47], [38, 17], [10, 48], [-16, 48], [54, -8], [12, 20], [-24, -8], [-68, -16], [16, 31], [-28, 0], [12, -14], [-36, -28], [-10, -57], [6, 26], [-12, -26], [-10, -46], [16, -28], [-72, 8], [2, -29], [-20, 8], [-72, -10], [36, -29], [-2, 24], [60, 4], [-34, 23], [18, 45], [8, 4], [-54, -8], [-18, -40], [-12, 24], [56, -14], [-40, 19], [-48, 2], [-26, 14], [48, 20], [-4, 4], [-34, -9], [-58, 14], [-40, 30], [-2, 57], [-4, 14], [48, 30], [4, -5], [-6, -6], [-52, -16], [-24, 19], [66, -25], [-10, 22], [-36, -14], [-4, 32], [84, -6]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2352_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_2352_2_a_bb();".
// 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_2352_2_a_bb(:prec:=2)
    chi := MakeCharacter_2352_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_2352_2_a_bb();".
// 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_2352_2_a_bb( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2352_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![2, -4, 1]>,<11,R![-4, 4, 1]>,<13,R![-2, 0, 1]>,<17,R![-14, 4, 1]>],Snew);
    return Vf;
end function;