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