
// Make newform 2352.4.a.bc 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_4_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_2352_4_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_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], [2], [0], [18], [33], [-68], [-25], [-92], [92], [-25], [-213], [94], [67], [-278], [-400], [-744], [-734], [-555], [642], [973], [785], [822], [424], [-734], [-270], [-417], [1644], [-551], [-402], [-1889], [-554], [-2956], [795], [-908], [3272], [234], [836], [-6], [-532], [-4070], [-4747], [2402], [-2925], [60], [3184], [1612], [5736], [-4970], [-763], [-5374], [-878], [670], [4700], [1734], [-3036], [7110], [-4808], [-7091], [-1992], [-1517], [8016], [4169], [9102], [-7993], [-6288], [-8015], [2093], [996], [5522], [510], [-2364], [-2423], [8375], [-9651], [-7080], [5158], [-13385], [14328], [5349], [-12734], [-3287], [-11946], [-4433], [12360], [-10376], [-16382], [-9659], [7524], [-13151], [9150], [11816], [-13087], [-3612], [-3493], [2354], [-13146], [13380], [5353], [21685], [-3724], [24166], [25118], [-6162], [12619], [-8937], [-12784], [13746], [-6076], [-3977], [5873], [-11438], [25866], [12069], [-392], [-27884], [-4069], [-23586], [-7822], [4096], [-24601], [16231], [1404], [-22248], [-32483], [16180], [24358], [26658], [20701], [-12839], [21815], [24286], [-15173], [-13742], [34764], [-31241], [27622], [-30544], [31668], [11562], [3144], [10926], [35224], [38322], [18089], [2412], [8611], [10560], [7808], [18910], [9290], [-39428], [-37051], [21450], [-1523], [-1324], [22457], [50146], [-32841], [-13176], [20594], [-992], [-21459], [27344], [-50226], [4152], [53727], [-29741], [-55995], [61096], [31184], [-7098], [-10380], [-7403], [13827], [-32632], [41077], [11382], [-66136], [-35825], [21563], [11176], [24841], [20152], [45510], [-4236], [54110], [-27743], [-61191], [25422], [23081], [48666], [35680], [10608], [2432], [53928], [46027], [-34954], [10066], [-4576], [55478], [52305], [41630], [-16214], [55698], [-27606], [-13832], [10482], [40748], [-29524], [58239], [24600], [16652], [13104], [13864], [18015], [-20232], [61676], [-80616], [-23354], [53205], [-46381], [-77602], [-21264], [25334], [-4822], [17472], [49486], [-60775], [-7470], [-7427], [59452], [44417], [-21050], [-86065], [2778], [43973], [95838], [35204], [-101766], [41470], [-52841], [33139], [88246], [-66456], [-44440], [-27979], [27514], [-21312], [-632], [-32059], [-61084], [-88186], [44325], [23416], [-84288], [119009], [-10319], [12006], [94782], [-42899], [-93024], [-795], [56779], [53478], [-61793], [-75830], [-42362], [-109500], [35862], [-70229], [-125908], [20405], [21849], [-81870], [44140], [-96614], [34735], [-53173], [44676], [-12552], [-116495], [119406], [127551], [-38156], [85314], [-24039], [48586], [-8733], [119070], [-99972], [132692], [32522], [124628], [42203], [-129746], [-16569], [63608], [-104106], [42145], [-3754], [137466], [-2364], [-124740], [-39261], [77069], [82410], [-6647], [10664], [-110917], [-165728], [-163402], [-155918], [46856], [108232], [-50639], [67202], [-131620], [134353], [-182430], [-18317], [-12697], [20550], [-3655], [-77674], [42905], [22505], [33035], [96732], [-5694], [-34239], [116682], [165359], [-173962], [81205], [51226], [-155390], [-156020], [-63667], [-8221], [-55473], [37488], [-4356], [-109685], [-12574], [-84006], [222601], [23564], [-205942], [-132454], [-134228], [-190766], [-97710], [219408], [-42009], [-151890], [-11418], [-27032], [-54804], [-40278], [-57886], [171762], [42786], [67542], [-99441], [64190], [7920], [92607], [13630], [153232], [-17021], [121842], [-83786], [42137], [92217], [-59356], [-67116], [-149818], [-119572], [-248351], [-76364], [-126028], [-203992], [94320], [78508], [112692], [103201], [-124306], [191413], [-205930], [124265], [70486], [52596], [168777], [97670], [-87358], [199628], [158002], [213137], [55218], [45510], [-75808], [-70968], [-34566], [-43942], [147079], [-51706], [3244], [-255357], [-158748], [-26286], [-184164], [261040], [-192700], [243345], [-106134], [147926], [-85681], [-248964], [-245908], [107412], [-201457], [-251880], [123426], [106974], [131694], [38642], [-217152], [-86996], [-170128]];
    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_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_2352_4_a_bc(: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_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_2352_4_a_bc( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2352_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<5,R![-2, 1]>,<11,R![-18, 1]>],Snew);
    return Vf;
end function;