
// Make newform 2352.4.a.h in Magma, downloaded from the LMFDB on 23 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_4_a_h();".
// 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_4_a_h();".
// 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 := 4;
    raw_aps := [[0], [-3], [-4], [0], [26], [-2], [36], [-76], [114], [6], [-256], [-86], [-160], [220], [308], [258], [264], [-606], [520], [286], [530], [44], [1012], [-768], [-222], [320], [-592], [-1782], [230], [-1718], [2444], [1996], [-1746], [1804], [-2814], [792], [2778], [-2880], [-1060], [1440], [-1210], [-1618], [-4018], [3382], [-4302], [-2640], [-3396], [3480], [-1504], [-5122], [1630], [2522], [-3022], [3480], [-3496], [5058], [-3596], [-2424], [3634], [-2970], [-7028], [528], [4300], [-4580], [-2266], [-7926], [4132], [-3622], [10254], [8178], [-9932], [-6546], [-12176], [-8210], [-6908], [-10248], [-274], [10010], [1998], [12842], [-10400], [15586], [-8066], [5222], [-10920], [-1650], [11858], [-17894], [2088], [-13532], [6344], [9948], [-20144], [-10530], [5548], [-2152], [19780], [-23052], [-13364], [-9766], [-3768], [1618], [-5768], [-8114], [-7816], [18278], [-24960], [-10892], [20022], [-10370], [-8992], [12318], [-26026], [-18332], [-10572], [24822], [-6620], [15956], [-30802], [12714], [-5822], [28510], [21864], [17862], [-6068], [7734], [19902], [12160], [3088], [-10178], [5840], [14414], [12608], [22606], [-5952], [-14138], [-12616], [-12292], [20784], [-13574], [32308], [-2390], [-28020], [-34006], [6310], [-16524], [-36662], [42000], [28388], [-23918], [-2346], [-51876], [11372], [38764], [11212], [-1458], [38608], [-7376], [24878], [26148], [-18350], [-57510], [33364], [26892], [-31970], [-19728], [21400], [4754], [-52882], [27312], [-3630], [50906], [486], [-28618], [-24536], [-30564], [43904], [29534], [30504], [2506], [50468], [27324], [-478], [8628], [18722], [-41736], [-47730], [46372], [73030], [-6440], [-56558], [20746], [-10348], [35016], [-61302], [-6276], [-13762], [46362], [-71104], [-12732], [16154], [-25768], [39654], [-46638], [-69548], [-9776], [26040], [17042], [11850], [32772], [40034], [-62220], [30832], [2604], [-60036], [-47714], [-26664], [33996], [34194], [82262], [-57490], [-13328], [28106], [-20400], [-20500], [86202], [26784], [83066], [13456], [96454], [21254], [80220], [9112], [16490], [17140], [80896], [-21950], [-90806], [-30666], [-112040], [-14962], [2660], [88784], [-21958], [40128], [-7620], [48272], [-40000], [83288], [-81198], [3214], [19428], [-68954], [-46526], [-55392], [-67014], [-66110], [70964], [56456], [-13506], [-25588], [-92754], [-92578], [-878], [-21476], [-78980], [138946], [-60412], [-31536], [75694], [90578], [-66012], [-128126], [-3832], [110586], [37424], [-78334], [18490], [-74978], [-67632], [132648], [51428], [72752], [122050], [-22260], [4574], [-64270], [121418], [-58960], [97960], [86346], [-84804], [-79162], [16896], [7654], [-121424], [-104360], [-91164], [-138968], [-113836], [-78714], [23894], [83572], [-70806], [55384], [-57734], [-80042], [74726], [-95634], [-51118], [-120216], [-119482], [26158], [117596], [67698], [-55822], [162092], [33450], [-167158], [-61034], [-157420], [82342], [99160], [-29848], [1394], [92954], [-83576], [-10612], [-175482], [-73778], [-53554], [142142], [73336], [-69632], [34544], [110600], [79014], [-177192], [-199942], [-41416], [-6898], [-120762], [59508], [-56848], [42326], [-145622], [-16618], [-86484], [152824], [-44672], [217980], [188310], [-14902], [-13848], [-149554], [145276], [138416], [-41220], [-83526], [139702], [-152562], [-17752], [93454], [185810], [-8324], [20454], [7980], [-145948], [-206034], [-232290], [16196], [-64154], [-133814], [-194608], [91802], [-18804], [179562], [132198], [197364], [67394], [-182952], [86730], [115872], [57210], [63636], [137664], [134192], [168342], [944], [-79780], [96062], [20636], [77370], [73772], [251758], [112050], [-157624], [-162644], [-228928], [-9770], [150050], [219738], [246012], [-57584], [45068], [-122600], [173130], [93138], [-8924], [49200], [185758], [5118], [33270], [40308], [-50890], [-256660], [24178], [-219032], [271836], [-213252], [870], [-15166], [229182], [292004], [-54282], [99584], [178094], [319782], [145788], [316524]];
    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_4_a_h();".
// 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_4_a_h(:prec:=1)
    chi := MakeCharacter_2352_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 4));
    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_4_a_h();".
// 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_4_a_h( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2352_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<5,R![4, 1]>,<11,R![-26, 1]>],Snew);
    return Vf;
end function;