
// Make newform 196.6.a.f in Magma, downloaded from the LMFDB on 03 May 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_196_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_196_6_a_f();".
// 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_196_6_a_f();".
// 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_196_a();"
function MakeCharacter_196_a()
    N := 196;
    order := 1;
    char_gens := [99, 101];
    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_196_a_Hecke(Kf)
    return MakeCharacter_196_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 := 6;
    raw_aps := [[0], [16], [-16], [0], [-76], [-880], [1056], [-1936], [936], [-3982], [-1568], [4938], [15840], [-16412], [20768], [-37402], [-21136], [2992], [-45836], [-49840], [56320], [40744], [-112464], [-64256], [2272], [110000], [84128], [13948], [22594], [94786], [140624], [242352], [172886], [167376], [-404602], [445192], [172496], [167484], [-206624], [339856], [519540], [-830000], [301608], [-484462], [-183018], [904288], [-494428], [389824], [79024], [1259792], [-772618], [-1425072], [-1148576], [278096], [-357632], [-84832], [2197712], [475904], [-1594010], [-1315578], [-1008656], [-2057616], [-2070992], [-953216], [-2858400], [-1987602], [394580], [2196062], [4027188], [1964688], [-3345216], [-2295128], [-2938688], [-414458], [2571108], [2567328], [3378090], [2197712], [-3476706], [1684320], [4404752], [3066006], [1320352], [-2915104], [-7062528], [-7738116], [-5624574], [5915162], [-7211952], [5220920], [-5815376], [7538784], [-6596600], [-9966660], [-2942700], [-4351424], [-5184944], [-7416800], [6473456], [9109870], [-5637764], [3710718], [-5261168], [-2809290], [-8197068], [3697216], [8252816], [6312768], [-6929760], [-11009152], [333696], [1759274], [-14614202], [2315440], [14715216], [10755502], [-18109680], [-3876768], [-5825566], [-6469892], [4180016], [12715934], [-11871024], [13997788], [9800368], [-1804814], [-6474038], [23406432], [491936], [-7864208], [6925468], [15930552], [10015248], [3796186], [10348448], [15113120], [5661744], [1734832], [-4967088], [-16623750], [16769456], [-8341498], [-20698976], [-32552388], [-16464464], [-21644640], [-20259184], [19475808], [8662032], [15595560], [9445986], [-25786624], [-33329756], [-9279072], [20239756], [12697936], [15139344], [-8159712], [-26564736], [-39053520], [38397116], [-2784870], [-7718216], [21973232], [-10813714], [37113632], [-11903608], [164912], [11326018], [37476048], [-1335972], [42329232], [43821888], [-6229674], [-58901024], [-28193600], [-37956292], [-26505942], [23528384], [7401328], [71108160], [-57738032], [28835082], [-50521152], [24292256], [-31675952], [71283278], [22213488], [-80189450], [6997408], [-84181696], [58918156], [-39094252], [-27261168], [77384692], [23078336], [52237438], [-70923854], [40304000], [-58071552], [-37922434], [4371488], [52350320], [-66064768], [59120496], [92253552], [99767200], [-12234948], [29337946], [6064784], [78138654], [47680176], [-25148696], [36051312], [-93769984], [-67987552], [7909000], [-18728160], [106092864], [42172274], [22452298], [-125832960], [-160830], [-24280048], [-59373072], [-61548454], [-44585728], [-135461984], [-129590208], [-36815196], [11012418], [97620688], [19000168], [-97033750], [31375536], [38065280], [51622048], [87710854], [116752780], [-79505728], [16910620], [102973552], [114623168], [-75764578], [56462208], [-74195616], [142903552], [89396208], [-124634444], [150964792], [-7903698], [-23298880], [112484208], [66863104], [-4978512], [-139744924], [171923930], [-59091824], [-6137808], [202086368], [-770704], [177252988], [9124016], [-49328400], [115639392], [-216844144], [-14495106], [6308736], [6710924], [-138647894], [-40501488], [143898316], [64767296], [-200279024], [10710656], [125079488], [89189924], [93990094], [-41576678], [217210224], [-86668736], [-175588192], [-13336928], [111131504], [-143494736], [16133184], [-37834414], [-247627578], [-45690464], [293612352], [-199628802], [-63843472], [44423478], [143698544], [91020798], [-89097008], [172579072], [93239504], [-109413744], [-65636912], [214169824], [-115157790], [-170747720], [-148550580], [241579812], [-101504866], [37813940], [149833712], [-257650776], [12264406], [-367177536], [-368276262], [-187717794], [-68870836], [-324268208], [248686592], [70157456], [382069688], [-55903232], [-106433426], [-33224752], [-107510842], [-398653200], [-125878424], [-168245638], [-378389280], [384974316], [126894576], [-146046912], [-298994806], [-16416994], [196299666], [115083936], [-298710896], [176374748], [239917936], [479799154], [397701568], [108893120], [-403069920], [-215829274], [-416425098], [112468048], [-96352224], [-323890126], [281870028], [-490365936], [90967636], [138735168], [243259824], [33915024], [225506282], [-227559682], [179633696], [-343925626], [-16396864], [483412704], [180166448], [-78816782], [-142242376], [209482262], [-446886528], [290492784], [127774636], [79316848], [219122694], [-30834672], [274860344], [-341415382], [-54870540], [-148168240], [-462228184], [-451732666], [-209601920], [373733614], [-291947920], [-428922032], [263462144], [-428159776], [512519392], [506504592], [-310442406], [-77771232], [-171188446], [539161040], [225221376], [-158125944], [350035824], [239200940], [-698752224], [-305367250], [726558640], [162008540], [687086032], [117145720], [-646935674], [-528271392], [-179662560], [473417228], [-363440550], [147027056], [671951554], [-542435080], [-544012832], [-159147120], [58586528], [464148478], [-470536638], [260936720], [410613648], [-753968512], [45008634], [495591956], [220085140], [18268470], [231971856], [-318937608], [37640608], [-79250336], [266688576], [272056082], [234418096], [738898488], [-218335920], [190942048], [-152618384], [-381508500], [-80507130], [610340560], [201271136]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_196_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_196_6_a_f();".
// 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_196_6_a_f(:prec:=1)
    chi := MakeCharacter_196_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 6));
    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_196_6_a_f();".
// 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_196_6_a_f( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_196_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<3,R![-16, 1]>],Snew);
    return Vf;
end function;