
// Make newform 114.8.a.c in Magma, downloaded from the LMFDB on 13 June 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_114_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_114_8_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_114_8_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_114_a();"
function MakeCharacter_114_a()
    N := 114;
    order := 1;
    char_gens := [77, 97];
    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_114_a_Hecke(Kf)
    return MakeCharacter_114_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 := 8;
    raw_aps := [[8], [-27], [-140], [-60], [3976], [1592], [-23682], [-6859], [-70370], [97502], [-234890], [146968], [-232282], [-409028], [-891710], [30862], [-374820], [-1548106], [3944928], [477232], [514206], [-4866382], [2043204], [-7822422], [-2747090], [5011972], [11990514], [-15831020], [-11671116], [25055950], [34875990], [41035020], [32648822], [1462572], [7261560], [-18908494], [-38368622], [-38216140], [38566236], [-1927614], [20316924], [-90123980], [17186726], [-22711650], [-38907080], [31500524], [-213254388], [-154286770], [257803964], [-220285810], [-84075942], [344605530], [-355672394], [-356122244], [-342185966], [-44216358], [169227402], [516570172], [122133358], [590977502], [-79458684], [260799498], [-534239400], [48018602], [109815878], [134388594], [758406608], [807941794], [666016256], [-433016414], [-489896406], [229169886], [821189764], [-408014296], [446873568], [645580232], [-557342916], [863277434], [-740466802], [571725574], [781791192], [-2771479984], [-2721654612], [643050734], [549201854], [3454725536], [1972605122], [-2664008926], [-2591936216], [425871652], [2199152108], [2334620702], [2849052706], [207570196], [-1606557236], [-745357278], [648996762], [1877901058], [795941840], [1695611882], [4744793512], [-348852520], [-3439986012], [-3976318822], [3572214884], [-8729507134], [5043596376], [981994826], [4421283372], [-6882877142], [47499530], [-1583788862], [-8246231982], [1558985788], [-9995683792], [-11080370454], [-7790115932], [-2427335042], [-87140304], [-1474552364], [8036060728], [3293903582], [-14601875530], [-13842371884], [-9733991484], [6412664980], [3135800238], [9582626714], [-1444509800], [-10616984622], [6268409780], [-16341551588], [12537490802], [16368556354], [9043079310], [13007726830], [6472566234], [3967725124], [4115894514], [23024028174], [13483951080], [-11698755204], [-12485534848], [7275235396], [1317807300], [-16014349028], [4058998590], [-8218783086], [14004406948], [-9592950348], [30232111576], [-27272359998], [28126854916], [-21307990300], [-38017003744], [-22634770188], [26219125616], [-38769478658], [-22369931530], [6114735218], [-40282345500], [49654274374], [50576597148], [-30701582252], [-22605455618], [-50184882768], [-48305443202], [11858022874], [-24538470746], [-12502060776], [4762607820], [-29561801092], [-55578043014], [-3176266762], [31245677946], [25091225682], [-21876659452], [9201245400], [-70599460874], [-62080211290], [-70948665956], [-45545280124], [57273160564], [-43250726530], [34893160098], [75390729744], [30463494500], [17219265676], [-85240118098], [71778179166], [-42504358286], [-26814057164], [38179197928], [-42033495018], [90066109784], [55082187174], [39250624238], [-19155001014], [69475949578], [55420279182], [54477661278], [-84785655830], [-101383971560], [-2468516686], [-36146945552], [114491999548], [-15184035568], [-146680702284], [57731422626], [-150727134460], [-107379891982], [140447858716], [132738415452], [81589116204], [-101658734244], [-36519978114], [-84733889784], [15326664510], [30010938044], [-122614000932], [-120762082740], [23716211630], [-180749041430], [80015963696], [-139892048684], [-103707901986], [-54825166214], [104367738540], [144383127410], [-151075712088], [183688012146], [-27518849236], [97748240730], [-51267676390], [112449811028], [-232131181842], [-85404509106], [95174963332], [-183930379412], [105444647952], [3053764292], [-58951384628], [73244826016], [58691600732], [-12383132814], [-138198215022], [254257026448], [-220150247300], [-52207927612], [48226935558], [177892576378], [277819552570], [107728823098], [-137035549102], [244845596008], [310465917656], [-226343371338], [-163754163736], [-320526002682], [-170380389818], [329792733982], [73599605364], [-253333691118], [87962143452], [-175703431914], [224428125508], [-74981717490], [-283141168830], [-242900271916], [16879254108], [-224769184908], [-235340315444], [-180153631890], [300581571116], [-176763938374], [165988226016], [-41734469676], [442456092244], [-23358844790], [-171910134696], [73554076872], [-182681156660], [376844348466], [61266417660], [144670109260], [123173571774], [-302490605718], [186979018434], [413893940596], [-302327813930], [-480522676824], [247797809004], [137640801726], [44594054524], [485613552308], [-304231405076], [-459197532214], [660447656488], [12920934572], [-480247170828], [503168509810], [42305750542], [402209417056], [-129800155748], [-509346704364], [249111369134], [-19224331332], [-475517438860], [12476924442], [-670393120858], [286303474430], [666652136160], [47327639498], [-220710004596], [311266207242], [711521381610], [-460755381396], [425820082736], [715384751474], [-521188209166], [-771707792600], [179821371570], [88652087478], [-118466085658], [462892775982], [223053722238], [-109905618440], [-137996536748], [-455116634536], [-540925261928], [-508532926070], [337358550942], [-388774694440], [-951254133208], [412922086116], [-140739883772], [854537876928], [-554504510754], [644063976566], [278526792232], [666962656864], [-245679803250], [660886010862], [-892360079482], [-759303803042], [-38645453788], [-940133841174], [278623664136], [419274771100], [243873117276], [-396351356696], [719474487518], [-41815575248], [324531140454], [1193868543752], [757771252058], [1116684756082], [397613440212], [900938763062], [-28618639368], [-1003450442150], [182297975098], [220121690124], [-110013423980], [-530667556], [-820965782422], [950627924820], [1107789523950], [709512274150], [636649675788], [987109412436], [-47036565482], [-131012944978], [1217704625252], [171137427758], [332550296212], [929884226134], [-715056516346], [682827632814], [577568035878], [-584614601946], [-1271452870082], [-116301340508], [15288417282], [-866795195844], [-1183761899804], [329618224888], [604016597254], [-1833466241132], [1512293760500], [1142613943610], [210492566278], [-294839954004], [1535751187492], [-32497650552], [-1576763998738], [1098661368622], [1129715774998], [1558599758680], [-327346942500], [-367559850316], [-1454443140226], [-408267429786], [-2126081958358], [-2246034017790], [-1683903300904], [-495427566026], [844132409938], [-1900471643396], [-962784624980], [154423703146], [-294577244244], [603306797588], [-1897047535660], [1108586166106], [-339418885524], [748006925652], [-830574307342], [-194158453314], [1095710943332], [1880507235726], [866208267416], [2140486678786], [2193048733292], [384310848838], [870335562714], [-2247165720308], [-661805692582], [2671186403540], [-2523781228538]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_114_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_114_8_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_114_8_a_c(:prec:=1)
    chi := MakeCharacter_114_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_114_8_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_114_8_a_c( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_114_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,8,sign)));
    Vf := Kernel([<5,R![140, 1]>],Snew);
    return Vf;
end function;