
// Make newform 8.14.a.a in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_8_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_8_14_a_a();".
// 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_8_14_a_a();".
// 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_8_a();"
function MakeCharacter_8_a()
    N := 8;
    order := 1;
    char_gens := [7, 5];
    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_8_a_Hecke(Kf)
    return MakeCharacter_8_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 := 14;
    raw_aps := [[0], [-12], [-4330], [-139992], [-6484324], [-22588034], [-23732270], [325344836], [921600632], [-3865879218], [-2253401440], [18250384566], [34422845322], [-17192501444], [-67371749904], [-87281218426], [540214518668], [-51276568850], [25519930676], [-1387500699032], [-819049441238], [-4030935615344], [4180823831428], [2677027798266], [-14039464316446], [-6223917768714], [-21175583325944], [18789477764220], [-9951589885346], [20887939279794], [-62681385160064], [-6977730369932], [-57859073050518], [-39349776972516], [-43136980208282], [219598601739512], [66186593278414], [-247621634047212], [-60522552199608], [-282356531046498], [-165617503462044], [852134378532102], [930990211078080], [417869880633026], [-1174203967946538], [95247776240872], [761636580380164], [-1626729168154016], [1508946710412372], [1696439261285494], [1278193529257034], [-1101376647891536], [915325039975218], [5683008808406860], [-7409375527236350], [4448301602552360], [-3995250671424386], [5587776441544784], [-901343381801498], [12483587193375418], [-5479800440950804], [4616300543507382], [-22239248511134748], [15117251814397464], [8365310594718042], [-9344246041695762], [39246592158512348], [-30172741549239534], [-40270127658027732], [-43641831236719218], [-30812199315161630], [-40692577097755128], [-10618968059598800], [74122115139003590], [46013123846195660], [-73697018443030656], [70372590398889110], [-107600840184242434], [-38572231952962734], [-53463860575757766], [104339635650829332], [-70317250778907082], [64043749861803376], [-112484277810660110], [-31497791764483944], [114104169731378956], [-78675836568968254], [235679051053891754], [-233464644035366338], [-143911385421793264], [-272837806372946172], [361843944457029472], [333934085425416328], [-17953361538160644], [421622813254335396], [353512658534454744], [-595546645108089426], [-618807178118253590], [-397661418042761060], [406842283198767438], [-281720878091108716], [1234002523533317918], [1422606567696349412], [-450796602901477798], [713748015001596300], [1284474629083672898], [-58069012858158628], [-1397161955540687854], [523230597768786360], [-1512213639885875462], [-1703137667289486880], [-608885050415692810], [593916804298447818], [1004956355841830524], [-73534906690817960], [2826546064566678914], [-1577305986210535308], [-1787095201905555032], [3345057291599568894], [-1698020265799885116], [-1728150803508452506], [-1823765031399237854], [-3091375049773902538], [314496406397019068], [-448311069041195164], [3217044301650372462], [-3213278389035241258], [-2516281783428473584], [-1202835653761577928], [-1798744798707659506], [-2142606212258601388], [-5345504907135992440], [3426932441774772144], [1777693162802917958], [4610167106317223962], [4062610188096316418], [-2770905328280952810], [4819060029416102212], [-813420550684648882], [-6030688558394923382], [3207877131532655164], [-10841776609028233338], [-3623680231817469928], [5786703258276327052], [-8108709360379807250], [-15323610837835339416], [9911387680007218982], [-3723697333479534342], [-3078107916465590484], [-4681380955157924128], [-3278687833446615714], [-8024367473056424270], [-20792473310463129820], [26119066395228843352], [-25519049561855431652], [-16295057926934358832], [-2259631630242886664], [-13876788162096638942], [12793785800278415370], [-10075789313779840866], [16667249635829780580], [27905952984509522394], [40637652965402952680], [3916478133115708764], [8917577291719647378], [-30335379663256178376], [-49008538481573504672], [-15744839281159861898]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_8_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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