
// Make newform 192.8.a.h in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_192_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_192_8_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_192_8_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_192_a();"
function MakeCharacter_192_a()
    N := 192;
    order := 1;
    char_gens := [127, 133, 65];
    v := [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_192_a_Hecke(Kf)
    return MakeCharacter_192_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 := 8;
    raw_aps := [[0], [-27], [530], [120], [7196], [9626], [18674], [-7004], [-63704], [-29334], [87968], [-227982], [-160806], [-136132], [-1206960], [398786], [-1152436], [2070602], [4073428], [-383752], [3006010], [-4948112], [9163492], [7304106], [-690526], [-13266702], [4868248], [-7918596], [4930298], [2317074], [-22511936], [13589524], [714618], [-17881572], [20039074], [-40763416], [-55470166], [1803444], [5992728], [-125630598], [-48649788], [49754754], [111324480], [-134786494], [-39755694], [-103320776], [179474660], [285310816], [27479796], [85656242], [104906650], [-27718384], [-295271022], [302885260], [41463554], [420007096], [-156477350], [-271490512], [98031842], [-404838934], [-241438676], [195051954], [102082116], [304912776], [647440842], [148934538], [-968290340], [165423666], [1124551404], [255382890], [345150626], [-811306536], [-776624816], [-1667904830], [1250065420], [1433738880], [-731612782], [-1190591078], [-2446377870], [1836634986], [2778538932], [-1166249870], [-290479408], [2206505938], [99756360], [818947660], [-2462406206], [-2761354054], [-1483079014], [-1425912976], [-1995789468], [566385056], [-1236092264], [749612412], [3656423172], [-2193895608], [-4248654774], [-370617094], [-6336450532], [4007922858], [3660460852], [-5256297478], [5019854276], [2804950090], [-6104541876], [-302864446], [2423700188], [-6855380942], [147202536], [7158843562], [4083334880], [6810805426], [3951609114], [10783545596], [11044348936], [-5937968894], [8249448084], [-6491445064], [1044060762], [-11112564828], [1701049570], [-7459384478], [5804728754], [7269028028], [-11729799356], [9887431434], [14328441490], [-17360709968], [-12773966424], [-6124190102], [-10533521804], [7553916376], [-13127324976], [5721255874], [16377144458], [-6596342782], [6241259154], [-16932756316], [-12557859094], [-2518596646], [-27076006084], [-27008869950], [12388298312], [22856233036], [8687419850], [11679172344], [-2254521950], [-4966046166], [-15403923732], [4612253344], [-35750464134], [-24830856430], [-9379955708], [5989397576], [-1765682788], [-41823154064], [-37165770776], [25657994210], [-5753525286], [46059907194], [93470916], [11728910538], [-16478577352], [18843582684], [-42666068430], [4345270248], [13623873760], [43278776882], [11380984466], [43608173570], [12217860876], [16800984330], [-51080543560], [-5256251270], [-5463461200], [-20300162326], [-2298378452], [-31210050510], [35497779928], [30337518394], [-16668313984], [13251186772], [-39787007982], [42676135482], [22983912624], [51997034082], [11604820970], [-87233521932], [-61813847270], [4141395840], [62222748034], [-84237870564], [40456774820], [10520868458], [68137568052], [101462609114], [51287178706], [-55935816118], [16194806594], [90428295672], [-109090665062], [-65036324752], [53872433314], [-47681361374], [-17277207300], [-9411335862], [-91422970816], [28964218644], [56104074362], [-115630575844], [146116830066], [-30898829022], [-55655347736], [-125525383124], [60145618712], [-45324827302], [8912685200], [121731083698], [-112352870808], [105747933738], [-111168985550], [-1898142840], [-96345716478], [-79637904976], [-47509111260], [-184202508830], [-189122589078], [129397927392], [27194605656], [192677719868], [-87935626182], [-137725866172], [69758026880], [96006521530], [158375548380], [6284415152], [-243342472270], [119431258850], [-120186595220], [5703390040], [-69735677052], [-199381547252], [-161244489608], [-200546399974], [82431932274], [-276371985880], [197323039648], [74192720820], [-196138849348], [81535930832], [256429025994], [270920567490], [318478760696], [-31998033350], [309134922138], [-74430308508], [193327008802], [-255930497428], [-285421829646], [37371071626], [-163870140224], [232344079380], [-221344781998], [-15658748502], [-211016569118], [-33570940364], [21924141178], [-198956049334], [37011558988], [211537882834], [-276948538150], [231396664804], [-114822273494], [186552509920], [-253486468718], [113265838088], [-60971188596], [-66832412918], [-69155921030], [78897847844], [396978248800], [138374199256], [258502374664], [519604036498], [-279806780324], [-215768542544], [-36677237710], [348960809826], [76127209256], [-211879289182], [175792622906], [133194077316], [27674683786], [406903656732], [290618370714], [-544944573334], [-375494631520], [-493416653502], [179967402828], [33841172692], [18626698682], [-450467528294], [77370521840], [-361024791580], [-74502108564], [-64674655966], [665099706108], [-372229033094], [128122883144], [-204323693486], [429653512944], [-294426093150], [506881706594], [-608934808780], [30900465304], [608540379482], [300333695556], [172601352768], [802693124546], [-643170977742], [141035330660], [451085168554], [300926697898], [-448258613408], [584599906714], [-549748392942], [-264560935788], [679379425068], [-831986965664], [424862700210], [491083381562], [-540176311926], [499384653696], [107848499028], [-620451775908], [74010856812], [829714175978], [55047106338], [-494168423782], [-124101322416], [732800131394], [816076088202], [335938700178], [645644660472], [258003227498], [203708005940], [608324677362], [581682928316], [-739343359920], [587745177538], [474467811924], [-352067969734], [716156418458], [-794275156752], [-135152989790], [98782441898], [-899974420064], [140231279356], [-1014954846062], [740852257608], [-394065836846], [-463453496838], [969355015536], [-1261702150100], [-608955581644], [1130440684506], [1147083575034], [749677943224], [1140573276202], [-54838555148], [-805020796164], [-193272809200], [-559541510782], [-1331176673144], [-1177959098486], [-420919545180], [-839181927456], [81550772962], [827029016274], [-16863975478], [-424159368438], [-451720135750], [352696633896], [1886682482850], [463504575860], [-932398963368], [1478868930384], [-953018247614], [1607439034508], [-488555302656], [-1272372288638], [675148846994], [1225938882588], [1796255649060], [510626542632], [1211543451754], [353387465376], [-1203401128614], [487760687548], [453856677314], [-1137952396598], [1573195943874], [1939496809840], [-17138325334], [-380607916174], [-2090733649256], [1395985973114], [514578789906], [-1225173266300], [1858475145492], [160905824882], [207769241378], [194540561068], [2266998921524], [623887855194], [462534975098], [744675829440], [1246102399544], [-1963969950030], [825275903720], [-332559414230], [2008196779186], [212147454608], [-1198473068276], [-131782759430], [-305298408230], [636537839396], [-278684139414], [-1444935018708], [-28123417208]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_192_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_192_8_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_192_8_a_h(:prec:=1)
    chi := MakeCharacter_192_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 8));
    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_192_8_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_192_8_a_h( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_192_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,8,sign)));
    Vf := Kernel([<5,R![-530, 1]>,<7,R![-120, 1]>],Snew);
    return Vf;
end function;