
// Make newform 448.8.a.e in Magma, downloaded from the LMFDB on 06 February 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_448_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_448_8_a_e();".
// 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_448_8_a_e();".
// 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_448_a();"
function MakeCharacter_448_a()
    N := 448;
    order := 1;
    char_gens := [127, 197, 129];
    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_448_a_Hecke(Kf)
    return MakeCharacter_448_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 := [[0], [-18], [-160], [343], [5704], [-1388], [-31434], [-19966], [77136], [193374], [26356], [-204346], [-663050], [-335920], [-1119812], [-112782], [536154], [1170264], [3890660], [-2505344], [-1435070], [-176536], [-6211622], [-4729062], [-2129562], [-5660320], [14025748], [-2072892], [6872470], [22743718], [25183376], [-17418734], [44997186], [42686494], [-41936406], [7600872], [-84619788], [15485640], [44889340], [102899580], [50177980], [132768572], [-143976808], [91703278], [110905098], [161688060], [1747716], [48306360], [205296434], [281107988], [308493130], [131783432], [279724582], [124213470], [383682034], [-454838688], [-81905156], [241677264], [20256194], [-224402070], [-579760982], [-96936888], [-623961950], [483165560], [-488640506], [589516194], [-496907152], [-800789458], [936814224], [318551148], [1477782098], [763542984], [362182424], [-493378870], [1767116888], [-1834548], [1744621174], [-2114735620], [-1912126962], [-1257510242], [1162443190], [-1162120606], [-1814874776], [-1997741618], [-3340726920], [383408460], [-2186234542], [1484191174], [1313923428], [1456491472], [3403736186], [3443522292], [1217907424], [79414860], [-5135067868], [691852768], [-1842329300], [-4748544618], [-2419431806], [-4417218494], [3488752512], [2783739458], [-2466239282], [-352044554], [7440852136], [3057269218], [2883787590], [-4700760742], [4063234392], [-2069557510], [5568279808], [3796636998], [-3962348074], [5550824218], [243355728], [-3892272978], [2226981790], [-7461822404], [-127961402], [-11005201824], [12232589608], [-12086222150], [11627471676], [14238140172], [-9509179118], [9298384806], [14205922998], [11380519940], [2051495108], [2801599048], [-11752836920], [-12768232264], [-8948260792], [-11224092634], [-3065417538], [-13391122402], [2075292296], [10298883722], [-6692695044], [15629117206], [-3312997022], [17988381170], [-9562186200], [-16556211116], [31047321160], [-11125503036], [11228303332], [-13411019490], [-33063816802], [18609621448], [20123121294], [35575191306], [488662972], [-36673158796], [-9619541308], [13697407632], [9668636968], [5569162166], [3101655778], [11672886648], [41551154960], [15014277210], [-30605983664], [46759664442], [10391532730], [-305164428], [54841232800], [7316336696], [41382177758], [-35284238892], [19268569980], [-5280589804], [-7301966304], [-9941729302], [64266147956], [-5845205886], [42035826916], [-7736088794], [-65336181456], [-3915499304], [75377974712], [-61293249426], [29323323262], [49675934298], [77553627248], [-25403420436], [-76665070230], [-11698804142], [61753095010], [-6886052260], [18690044162], [35032047356], [51558826588], [-87746293644], [14413936188], [64200951234], [-47748857362], [19968019902], [44449340026], [-53827303272], [-68340609014], [-42400927892], [81934019976], [54924875898], [7520749522], [40545739336], [-123651031140], [-26996122088], [-79245441330], [40160804982], [-54096055234], [59339307120], [-127341590552], [-137730269334], [-1905895944], [-98750576626], [-20808477456], [171517756734], [6659633496], [173413821142], [-133539624770], [-3062604952], [48766812626], [82879270440], [-93091899550], [-164231281362], [32444453034], [-63216769624], [143571561536], [74322505016], [-222590929946], [-216218917290], [-83504418128], [188901259370], [47182703890], [113038863296], [162695010230], [21090952634], [-171173917524], [-241060402240], [165422444848], [-131464221790], [30292419904], [199395333898], [74011966698], [-75161666340], [-18453640688], [5776221410], [125694283072], [-186295718352], [213836002274], [28500699522], [272366802064], [29749561946], [-11145889368], [156685475244], [284102501630], [-320867845594], [242885389664], [96184858734], [-73724916712], [144741717576], [24400752032], [-103452162392], [-234213208666], [-172159053530], [-300268406446], [-57612702758], [-224138464236], [318198439214], [165252298268], [-131028553392], [-293960637166], [373783081568], [100518798546], [-372008164016], [120496224016], [-11887534990], [-145270727858], [176946204618], [-388321953192], [-255956869912], [309405753412], [-497715720680], [-352645358670], [-445172292496], [-4275302110], [125477641738], [272273123620], [568522589810], [414152936634], [490613895114], [-237535134298], [-527114064414], [-332176804246], [590465884636], [-14783322400], [-140494971156], [-534383192498], [375282583646], [-411522608034], [-45092888666], [195526523392], [-353361836856], [-337951538464], [108306931354], [474888231008], [-175162535104], [-231866095344], [294891306802], [-603325692216], [-702925696058], [80780420938], [545798335576], [311906033472], [-285129635558], [155244943982], [116003571840], [-121151391398], [-693414517694], [20581782470], [75780838018], [-368639328920], [-340950909832], [-99321063034], [-376472041394], [833073965696], [-314408105038], [212078531472], [280270818782], [-352970129966], [200540954182], [-456667619476], [-35385277658], [343152625876], [-609389986030], [223009734966], [-203078482542], [516857668042], [-147876539876], [268372548202], [351967542342], [60120463548], [392927600672], [497650575766], [-180859969648], [168659646332], [766359196056], [543278274296], [-273679344008], [45474639870], [544129137450], [757264698922], [217775713932], [-117493528886], [1181562179186], [714032597044], [1021530817290], [469764447666], [197550951808], [-389058180102], [162936714082], [-772656146384], [-1469760693740], [164083959874], [392284402566], [130357935900], [-982143282112], [-36539398314], [202722862380], [-185277050674], [933435667024], [986031403514], [1356684675688], [-606771993278], [-976388851374], [-772605617448], [312686651418], [287730757446], [291333139774], [-1294711277652], [263849991510], [-610752557112], [-227900449710], [614382289566], [-386385423576], [911511656552], [1558691379168], [-481652514356], [380267063740], [-1677503652418], [44031923024], [491574181620], [-1142884625722], [-1534496803592], [-1598233263630], [-35068441916], [822298415654], [-86925217772], [387357281510], [-737566494520], [119451032562], [998114278608], [1538791355486], [648154380308], [1595268071060], [443185320810], [-514748616162], [-1949463135866], [1071534853710], [1386721364858], [243902203038], [1669752481800], [-1835259836268], [648333769850], [-1354592555260], [-312250513112], [-1090166185372], [2231739010566], [2113477909248], [1054644129510], [1669408029896], [-1931565963312], [422460799574], [-1014156615402], [-628772800384], [-996073085456], [-14522595078], [1276545439638], [145461805356]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_448_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_448_8_a_e();".
// 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_448_8_a_e(:prec:=1)
    chi := MakeCharacter_448_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_448_8_a_e();".
// 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_448_8_a_e( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_448_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,8,sign)));
    Vf := Kernel([<3,R![18, 1]>],Snew);
    return Vf;
end function;