
// Make newform 64.8.a.e in Magma, downloaded from the LMFDB on 06 May 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_64_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_64_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_64_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_64_a();"
function MakeCharacter_64_a()
    N := 64;
    order := 1;
    char_gens := [63, 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_64_a_Hecke(Kf)
    return MakeCharacter_64_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 := 8;
    raw_aps := [[0], [12], [210], [-1016], [1092], [-1382], [14706], [-39940], [-68712], [102570], [-227552], [-160526], [10842], [-630748], [-472656], [1494018], [2640660], [-827702], [-126004], [1414728], [980282], [3566800], [5672892], [-11951190], [8682146], [10079538], [-3747992], [-17985564], [-12257030], [16594962], [-1168256], [-7923828], [-315654], [39203780], [21886050], [29415448], [-60554966], [57085292], [87726504], [-8569542], [18804060], [59962498], [-93986112], [-35194558], [-102985326], [-83637560], [-97401028], [14645728], [-184540884], [8754610], [-119556198], [-396209040], [-256606318], [-73477548], [-202701054], [-154254072], [624018330], [387983248], [-453952286], [333769962], [537694772], [-335600142], [215028956], [-792061512], [-118457398], [50730954], [273756932], [-91851214], [-1367004684], [-1131432470], [-44839518], [-398280600], [-1634717456], [1546331458], [-1056882220], [-224909952], [-1017882030], [1475652634], [274912242], [-1634272150], [-1112798100], [-922528142], [981507888], [2849979602], [1056218680], [1823254932], [1848459330], [-2980660294], [2527807578], [890290768], [2656667196], [-1300933920], [1074466024], [-783344028], [-623187940], [2709270648], [-3499434870], [-1376833158], [-2861538748], [-5344671062], [-3371346964], [5611058874], [6696895452], [1968501450], [1029257492], [3311792066], [-559410684], [-3024589518], [5632460760], [340791722], [-3854196896], [-9222445262], [6536112666], [1365585380], [-1540786952], [-4540181118], [11405383052], [12639339144], [10500443418], [9648179580], [6582986338], [-8546489758], [-8713048206], [14610865572], [-14734767268], [-1315018422], [-664028270], [-4950344880], [-8811008936], [149413738], [-4708057300], [-1696762392], [-10664999312], [-6228758846], [-8383341558], [-11864884990], [-5566800942], [134611196], [7415475114], [-14154174630], [-26370790108], [-8062640382], [23420185528], [5557221396], [-28425575990], [-10403565240], [18058024738], [-6340342614], [12148877300], [28711114848], [-24602117126], [-12537766638], [19309723292], [-32026812936], [2337034436], [-22034303472], [14327739160], [13127971170], [-38762629414], [-20627937222], [-21170525604], [21487568202], [-39262517816], [-56264662908], [-8434369614], [22422959448], [-34672761632], [29647405234], [25204552850], [-38304931902], [-28613746860], [19612034698], [-2603909112], [-17628345478], [40734593680], [41253294570], [-27206017228], [-36077870862], [38998034728], [-14282848070], [52450122304], [7265419212], [19062457618], [71883292986], [61513380048], [-54709387230], [72293908714], [44375799212], [19586264090], [-72547143552], [6587199362], [-57010802748], [47431522172], [93201751338], [40810514796], [45141655002], [97393786322], [46721325898], [-3265908414], [-82977485112], [37095064410], [-18435887792], [-70643591006], [-88482466270], [-31373989020], [145489180554], [-133547098880], [40579541772], [78517662330], [43530649412], [-9151955854], [-7800874782], [-95098568552], [7333113396], [22516052520], [-91193713318], [126816224944], [-116621470158], [172647572184], [-85118113302], [87317232178], [37457154040], [-21181027710], [-173507770352], [-52005656964], [70138986850], [10114036842], [140715315360], [-132168579416], [200783968932], [-67735365062], [165695367260], [172732301248], [57396093882], [-97474716028], [96757425744], [-36909717070], [-145695907422], [7514785140], [-116421627672], [-171892612068], [-158260609708], [-20626746872], [140763918490], [-81289527438], [-202234656360], [-200870257376], [174760865772], [84862482980], [-19916849232], [-263710614326], [-48948622398], [129854917704], [291081125690], [210950395098], [152791812540], [31348744738], [8281203956], [62565032754], [15700548746], [-51864624512], [147853885836], [-179296587950], [-142905561302], [-313323755934], [-290037000340], [205482728250], [-96747264438], [133763912852], [-322266468462], [187077952858], [357045760316], [115688864042], [348346478560], [179908527506], [-315472831112], [124472220756], [-19606769270], [313259827322], [-235815981828], [-125551921632], [211839280168], [-48492908616], [-66158581742], [106794433796], [148458003408], [-494945614798], [226143599394], [-41261198120], [-369907091550], [414465613818], [58856594076], [556398038922], [-7270073148], [587366400538], [-449140242390], [-188460621152], [63420509058], [-527888120940], [-105178495924], [118114493882], [-390063868326], [490291066960], [-553223098308], [655645606772], [237584641826], [365745391716], [475960905850], [90690209400], [-90946936622], [59974301328], [494575795170], [-62548578078], [674074004972], [-386276037336], [-260270932390], [490769665500], [-125735174592], [465970891202], [-424250190030], [-206633891908], [-358267609174], [81770425578], [-391564544672], [-812488054758], [681118966802], [-242124775540], [-315818034508], [41464150944], [-82403955342], [-180814252742], [-709411293366], [-522841175360], [-316683783348], [-1019896095868], [368061944436], [534410175850], [-566715653598], [-560810745958], [288720141424], [84906558658], [-563029563894], [356792336850], [-764499178232], [192125264298], [-875698696980], [-262085411342], [-557885774044], [-282104534352], [111181495554], [897365109452], [1170045749306], [-353227546662], [-776302744112], [-780069575390], [-122470235478], [954226282080], [182432454372], [1029608418066], [1376781587448], [110041109074], [799526803962], [348888747024], [-142765520460], [407897781356], [-487157108518], [-690371459526], [652281191368], [693825221162], [-375202383828], [368309716580], [1120039859568], [-1307697300030], [805416122488], [232108358794], [574806444540], [-26766212832], [-196567115038], [-159616571310], [400704899786], [1338057814218], [967136870202], [-1604628975656], [-18361844574], [-459359359060], [-257582978712], [-769207799312], [1046255246914], [723508132052], [-206872492416], [-1328148964990], [-335041625262], [-668233459260], [-781071089284], [19509318168], [1383481551722], [-659699331680], [-1436478333990], [100758459812], [1508879472258], [816810404170], [543595773762], [-810926668976], [-1216609318614], [-461567373390], [-666528424472], [-1743647911046], [1298443822482], [2029635768092], [1833591575820], [-280430443918], [1817453147874], [1608458516532], [-1963432441108], [-2182294637734], [-1148104773702], [-1568589117120], [-988542510776], [809549234226], [874485553368], [557781133290], [2616857237554], [25883011824], [627472431060], [-52110226438], [-1351693640166], [-1187921108868], [748110462570], [601440810932], [-1322158032840]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_64_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_64_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_64_8_a_e(:prec:=1)
    chi := MakeCharacter_64_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_64_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_64_8_a_e( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_64_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,8,sign)));
    Vf := Kernel([<3,R![-12, 1]>],Snew);
    return Vf;
end function;