
// Make newform 1014.4.a.h in Magma, downloaded from the LMFDB on 22 December 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_1014_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_1014_4_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_1014_4_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_1014_a();"
function MakeCharacter_1014_a()
    N := 1014;
    order := 1;
    char_gens := [677, 847];
    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_1014_a_Hecke( : Kf := Kf)
    return MakeCharacter_1014_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], [-3], [7], [16], [-64], [0], [-9], [-72], [-92], [-113], [-224], [279], [387], [-260], [-112], [471], [-380], [-317], [-260], [-64], [-1141], [884], [1428], [282], [-478], [695], [-392], [-1268], [-1034], [-1541], [-92], [-1400], [-1653], [-296], [1959], [-1860], [2135], [-3088], [-2700], [-842], [1644], [903], [3968], [-1429], [-162], [740], [5984], [576], [4464], [-6258], [-502], [-5976], [-5301], [-72], [5091], [-3732], [2742], [8164], [7251], [7919], [-9392], [2483], [1820], [-5040], [3290], [5259], [10016], [9599], [4500], [-8090], [-1405], [-2196], [9956], [3863], [4780], [-8472], [2991], [-10138], [13887], [3631], [12336], [-10841], [-14316], [-12581], [-11044], [2088], [3842], [-3137], [3015], [-12164], [2296], [-15300], [4556], [-3508], [10348], [11492], [4307], [7203], [4272], [-2581], [-6032], [22959], [5500], [5354], [8808], [-14217], [11440], [-4277], [-8104], [9403], [-5364], [-22177], [-9745], [-308], [-10760], [31247], [16868], [7352], [-19146], [-6504], [1955], [-17501], [9534], [-14176], [5896], [5910], [-11425], [-3740], [-34328], [1043], [-17424], [3968], [-22716], [14958], [10890], [20946], [-17810], [-25384], [35670], [-5349], [-12544], [-24242], [26340], [-29244], [26203], [33052], [34027], [-19957], [14084], [-8104], [-44997], [-22797], [-39884], [-21124], [14832], [11076], [18276], [-24873], [-22029], [47222], [-8268], [45898], [-25576], [20340], [13551], [26488], [-17592], [635], [-48046], [58135], [-28068], [6459], [1616], [13411], [-22932], [12815], [8252], [-65917], [24292], [3110], [8136], [-41440], [-11177], [8554], [-22744], [-41785], [31558], [-14616], [54599], [-13260], [67135], [54060], [43108], [-4058], [-33328], [-23574], [-25681], [-20945], [2275], [-39844], [-42561], [-29920], [5567], [33271], [-66484], [-33969], [49588], [-54468], [-69609], [-64500], [74171], [-62706], [-3676], [81128], [74940], [56959], [-65756], [-31817], [-21736], [-63642], [82459], [33320], [37431], [45940], [-21516], [-41641], [58879], [-13644], [-35240], [4020], [68851], [107704], [-29604], [-28369], [10808], [9268], [-5966], [22427], [-44556], [-15860], [-54636], [-2756], [-57612], [-74845], [32779], [97356], [-57388], [51956], [-21316], [62292], [60038], [26770], [42212], [-45589], [39830], [-53572], [8238], [-115288], [54558], [95695], [-105572], [91020], [96803], [-110213], [-105513], [56824], [-13210], [-31073], [36000], [-133953], [-107933], [-63236], [40539], [-135808], [59666], [29892], [40648], [-78573], [-68909], [51504], [-49628], [-92520], [139888], [-15517], [-50316], [-77572], [24131], [65599], [36104], [82171], [-6378], [-153176], [-17697], [-18860], [-33482], [-112161], [117768], [-49985], [-135868], [34904], [-120745], [-96017], [16176], [139624], [-2108], [-94669], [93704], [113631], [143156], [5175], [-156228], [-118322], [-180465], [79624], [2596], [-43045], [-99108], [-136400], [-144958], [107995], [20888], [-136358], [157323], [96284], [88762], [-130541], [6064], [12528], [-51808], [-136277], [-126785], [-62921], [-54136], [88464], [-144796], [-36260], [32591], [-81422], [-108957], [14756], [109230], [106539], [-1225], [-92492], [135526], [25076], [-166565], [46640], [112660], [147054], [132916], [-88166], [-170493], [824], [29091], [36519], [64188], [-63156], [10551], [-38988], [120427], [-206169], [-54020], [29896], [17348], [-107654], [71958], [13516], [174519], [115128], [116044], [121564], [-130821], [-195312], [-198381], [175728], [-180216], [167858], [-174113], [19927], [103782], [22987], [-139284], [9074], [7600], [-105348], [-169212], [-25522], [6176], [-17852], [-10305], [-13585], [-131052], [220628], [171912], [-246086], [31152], [-53606], [-93924], [-98253], [-103994], [-62798], [-215720], [148379], [235023], [10316], [57910], [-48273], [-22148], [189240], [57127], [176931], [-247220], [94660], [-173629], [170163], [-200208], [-113288], [126114], [-126492], [-233381], [117607], [90012], [39984], [-72406], [-191725], [-52568], [-246825], [-30452], [-126604]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1014_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1014_4_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_1014_4_a_h(:prec:=1)
    chi := MakeCharacter_1014_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_1014_4_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_1014_4_a_h( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1014_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<5,R![-7, 1]>,<7,R![-16, 1]>],Snew);
    return Vf;
end function;