
// Make newform 2178.4.a.c in Magma, downloaded from the LMFDB on 03 June 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_2178_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_2178_4_a_c();".
// 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_2178_4_a_c();".
// 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_2178_a();"
function MakeCharacter_2178_a()
    N := 2178;
    order := 1;
    char_gens := [1937, 1333];
    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_2178_a_Hecke(Kf)
    return MakeCharacter_2178_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]];
    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 := [[-2], [0], [-6], [-18], [0], [42], [30], [60], [186], [42], [16], [-74], [150], [-264], [-306], [-126], [-492], [6], [-524], [-390], [-984], [354], [1116], [-744], [1406], [1218], [200], [528], [-894], [408], [-1734], [1068], [3156], [2340], [1878], [-894], [-2126], [2360], [2640], [378], [-1380], [-1222], [-354], [3180], [3162], [-1856], [1128], [-3832], [-6504], [1762], [6918], [2184], [-108], [1932], [-4752], [6864], [-7902], [4206], [-5154], [4722], [1320], [-8490], [8244], [666], [-38], [-8490], [7400], [-10944], [9444], [9738], [11832], [-9144], [3728], [-6486], [1856], [8538], [9354], [11882], [4716], [-8892], [-11556], [-1298], [14568], [11342], [-8622], [5772], [11532], [-9996], [3726], [9272], [-1608], [9384], [-4088], [-3528], [18880], [-4824], [5226], [-10788], [2400], [18162], [-12084], [846], [-5496], [2454], [12564], [2986], [-10980], [-4998], [-19422], [840], [13914], [15726], [11088], [-5452], [20392], [14844], [1100], [-4326], [14622], [528], [14506], [-1164], [-10086], [21060], [19892], [-23154], [-830], [-14118], [7144], [-8742], [-22992], [-16776], [-13736], [6838], [-36330], [30732], [-18126], [29256], [15882], [-30150], [42672], [33306], [31232], [-19956], [18830], [6846], [20622], [-2646], [-24784], [30438], [15786], [-19200], [-13772], [20232], [34652], [9234], [-39906], [-36], [-26568], [-36966], [-49944], [45450], [-31638], [53700], [-22116], [50226], [-38288], [49770], [-39372], [53598], [39156], [-10726], [16896], [28944], [3584], [-2352], [-18516], [-39642], [-26178], [-5934], [63160], [-19428], [-5186], [-3702], [-37758], [42894], [69654], [-12148], [-39372], [47328], [-30026], [-44652], [27880], [-64278], [-30120], [-44400], [26760], [36074], [53730], [4224], [48726], [-8178], [-32902], [-39696], [-21444], [16518], [46856], [-12780], [-11826], [29356], [25236], [53382], [44224], [17424], [-59712], [37798], [3954], [-41742], [77922], [63678], [28014], [50706], [-51108], [67448], [37104], [-17286], [-31320], [-54162], [45810], [82920], [89966], [-65208], [67710], [-106626], [-8048], [95160], [-46190], [-11922], [66324], [32142], [36456], [-41592], [117664], [-114302], [36426], [11232], [58480], [-58104], [5916], [82344], [-99666], [11022], [38382], [9106], [48726], [48900], [-72682], [-18096], [67926], [-99948], [-112650], [89532], [53610], [-118206], [-10044], [86380], [-21642], [-18888], [101220], [48282], [21890], [-89404], [-98642], [94242], [-106656], [-105392], [-101256], [-11010], [130776], [-2640], [83880], [85408], [37416], [134322], [-39372], [49098], [16382], [-137742], [69712], [73962], [-45870], [-134748], [-65790], [39240], [138690], [83478], [-90848], [-40350], [43884], [-46056], [-5412], [121086], [-58818], [-67176], [37348], [-93458], [170616], [-166034], [75510], [45042], [110472], [18558], [155598], [83824], [48792], [-53448], [-82560], [-51192], [81250], [51042], [-113460], [-48134], [-27690], [79000], [-139878], [-64942], [-173252], [169144], [120744], [28242], [-24474], [109962], [149526], [136752], [103752], [-190824], [-73294], [-80982], [-169594], [157986], [-201742], [109236], [-184266], [-166120], [9858], [17004], [-96910], [69608], [-133896], [-43878], [-125496], [-42730], [-87174], [-25398], [-78882], [762], [-750], [21024], [125442], [114198], [-122466], [196242], [51882], [-21000], [-75260], [116278], [-28674], [-93558], [-151068], [111540], [-57184], [-68424], [-154854], [-110958], [5614], [-47448], [-89232], [-168384], [-173358], [-155748], [140994], [-241620], [83754], [59526], [14448], [-186], [-81704], [-94498], [114864], [-76290], [-63178], [-117978], [-147036], [-167384], [-205482], [-7188], [52614], [227124], [88976], [-188118], [-51618], [150252], [266262], [144324], [-175530], [273102], [-113434], [166782], [109996], [-24576], [225456], [-14346], [-245520], [160428], [-167616], [-58578], [5064], [150608], [184644], [-140352], [-45858], [-2562], [62154], [-300096], [-132874], [175314], [-222576], [-53754], [-31192], [308520]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2178_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_2178_4_a_c();".
// 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_2178_4_a_c(:prec:=1)
    chi := MakeCharacter_2178_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_2178_4_a_c();".
// 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_2178_4_a_c( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2178_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<5,R![6, 1]>,<7,R![18, 1]>,<17,R![-30, 1]>],Snew);
    return Vf;
end function;