
// Make newform 50.8.a.h in Magma, downloaded from the LMFDB on 25 August 2026.
// To make the character of type GrpDrchElt, type "MakeCharacter_50_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_50_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_50_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_50_a();"
function MakeCharacter_50_a()
    N := 50;
    order := 1;
    char_gens := [27];
    v := [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_50_a_Hecke( : Kf := Kf)
    return MakeCharacter_50_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], [43], [0], [974], [87], [14828], [-35571], [20615], [22218], [-5760], [302942], [-199366], [-668523], [-143212], [-338316], [-1094322], [-2135520], [-1939318], [-3348751], [3005652], [-3048397], [5485130], [5205933], [-832665], [5314754], [13733622], [-6708892], [5779959], [-2605330], [2992743], [14989214], [-8234268], [49230069], [9654575], [44928000], [5611502], [-28699126], [-77211367], [-107904876], [99601608], [-64439925], [48930842], [112024242], [92470733], [-46143306], [168967820], [69704897], [-265619452], [-208790556], [102101060], [-197185962], [-239330880], [260673857], [321445377], [57992814], [-59050902], [-537531840], [105110462], [15579104], [103808862], [-21310927], [312994158], [354146219], [300594402], [-432709462], [-333299076], [-607932973], [184987139], [1253373639], [91646990], [-1007166522], [295862610], [-508303396], [827555858], [-94643035], [629504538], [-70301850], [150320564], [1009262157], [-464820115], [-2063980005], [995249492], [1426618962], [-1729871587], [2325485480], [796391253], [-1096250415], [-1103249431], [3731747772], [232407428], [1700969124], [-336266430], [1416462734], [-528726588], [-4420632580], [152718588], [2895254250], [1997404917], [3573052763], [-205525408], [676741499], [-899648196], [-7460003112], [4631040345], [3524593292], [-6767117581], [5177512029], [3913844103], [369767730], [8345290667], [-3289229536], [-679245082], [-9687163266], [-4568032420], [-9137227858], [-3582783318], [2424161588], [586612884], [3427023678], [-10766105355], [-9857494048], [4913658458], [5462805264], [-2796533877], [10758182507], [785548092], [12283285700], [11018553630], [-9114798496], [-5482517332], [-13448053060], [-316805142], [12706410272], [7926368864], [-3650389563], [22956118565], [23740340808], [15250852844], [22201817874], [-22233759150], [20475953612], [-12586779678], [-5647209052], [-898050291], [-994682140], [-4528284480], [884542418], [17494201509], [27580976735], [-5597161512], [-20885582476], [-6850789938], [-36719455117], [2282662164], [34932788684], [-24617274828], [-34369099750], [32121829470], [-9392008261], [13423230012], [-13825525296], [-10991077887], [656209184], [34776247767], [-11932500471], [28566350538], [22058984282], [-27942531436]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_50_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_50_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_50_8_a_h(:prec:=1)
    chi := MakeCharacter_50_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(997) - 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_50_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_50_8_a_h( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_50_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,8,sign)));
    Vf := Kernel([<3,R![-43, 1]>],Snew);
    return Vf;
end function;