
// Make newform 128.6.a.a in Magma, downloaded from the LMFDB on 03 May 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_128_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_128_6_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_128_6_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_128_a();"
function MakeCharacter_128_a()
    N := 128;
    order := 1;
    char_gens := [127, 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_128_a_Hecke(Kf)
    return MakeCharacter_128_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 := 6;
    raw_aps := [[0], [-6], [-94], [-244], [358], [770], [670], [-1030], [-2828], [762], [-4992], [3562], [858], [-12786], [-3560], [9114], [8246], [-4414], [29986], [-49572], [-24370], [65176], [39378], [11134], [478], [-53670], [194444], [-65690], [110394], [-196414], [-107696], [-286254], [383722], [200126], [215922], [109300], [289746], [540410], [395836], [551442], [-469806], [-729502], [-532048], [195934], [683794], [-186868], [-496510], [26496], [-1061814], [1134226], [-768210], [419784], [880414], [16278], [-1262574], [-402084], [115786], [1323752], [971802], [-2006802], [-742770], [1226386], [2827338], [772052], [3154858], [-3508614], [2985398], [136114], [4012950], [2718346], [992274], [-2393716], [3417880], [-2863574], [2605030], [1763328], [3329386], [2268858], [-5339202], [3653674], [95090], [1163842], [1593352], [-4291266], [-829164], [3674766], [-4550338], [-1536294], [-5823926], [-6250856], [-4730198], [-2070144], [-4440260], [-600130], [1078658], [7930820], [4302130], [1803722], [10309046], [-12438686], [4252210], [-3855742], [4774986], [4670138], [-8719570], [-243838], [5703878], [9273426], [-4394076], [14087070], [-4334032], [5904706], [-6252098], [-13020074], [10551940], [426366], [19332546], [-18812580], [11705706], [-8708142], [753922], [1559518], [-14718262], [16233246], [-18646830], [-14620222], [-14601142], [10632504], [-2226780], [-13517574], [-11300790], [24726140], [25331816], [11845298], [-10023254], [22851134], [-2861526], [24993410], [19610322], [-2737830], [-23467242], [25477930], [-24091180], [-14369570], [-11510222], [29230956], [-2352838], [29469978], [37726966], [-13502240], [43505066], [1467410], [-10847846], [-11174892], [26507438], [8056392], [-3324012], [-24644610], [-19383698], [-7546598], [1027498], [23228890], [24353452], [26995886], [5595582], [-5996476], [22278352], [30585258], [32371454], [-48974462], [53333646], [3533610], [65142460], [10946078], [-39587960], [38250222], [-51436410], [-72655750], [22849436], [-24252718], [28020832], [3060570], [4799874], [26159422], [-4455096], [14450802], [-35125102], [31400186], [5152570], [26762560], [7578226], [79453950], [12437674], [22715930], [22173082], [-67559266], [47566322], [4306738], [89139458], [34220124], [46011650], [-57454600], [22046122], [49725298], [-27494394], [-2971350], [-108250304], [71146666], [6995918], [52135270], [-44107138], [-46073438], [-11758076], [24875230], [-62760228], [-72701846], [25426632], [70220446], [-72205404], [-22592262], [34989938], [-2868444], [41783166], [-97797576], [-17040710], [-94619254], [89955422], [127289648], [43760428], [-52029074], [9056522], [-83489542], [64140704], [-23292098], [108136622], [151138456], [43527806], [-144259102], [106334862], [48540636], [-109098270], [12490814], [-45455684], [53931634], [-134590286], [-3979292], [97485632], [95397090], [-12804002], [-7694136], [168518442], [-27497102], [4432828], [18527470], [160870810], [57317474], [3846962], [62203014], [-99628278], [-39197238], [-74175808], [-81369094], [116077466], [-27468694], [174183582], [-126025518], [-190017926], [175799070], [-31927562], [-123896326], [-81292798], [112662506], [240407086], [-188939728], [-177631614], [36518372], [-26256322], [125776722], [180364206], [120586554], [143896352], [116935820], [-148297692], [-11295038], [-79547810], [-21096824], [-14189666], [-15850470], [-33173516], [146821666], [-6669206], [-40642998], [-96987714], [-178927578], [-219251894], [168373122], [-115420736], [7387858], [-19277442], [16840978], [-68215606], [157178850], [31335240], [-168398382], [227219950], [-178058082], [-368665994], [-319125518], [179225652], [-38983574], [-90282584], [80327106], [249459198], [170618434], [-73393252], [-281061330], [-321123454], [-362201024], [-187091646], [37283858], [303722642], [286420490], [70098090], [-216690640], [-222298326], [139250270], [17988954], [236820542], [-67309792], [2886898], [233526850], [-163833990], [247805888], [104935362], [-230227634], [-386167674], [175523258], [96588242], [179491806], [-133799848], [97374082], [-120636694], [113538954], [331114684], [-92151774], [-241729798], [-188402398], [-274253034], [-256225080], [-134086862], [301241002], [-438775606], [370759650], [-138288840], [217958546], [-450103282], [-442119312], [171466254], [-486885570], [185089044], [85593274], [-347308530], [405287976], [-563494858], [363190186], [7211678], [31376162], [254713276], [-187809574], [531466258], [144321142], [-435327048], [542979306], [-272759708], [-83121830], [-412950910], [445754496], [-343566734], [-232981794], [469105738], [460020922], [2555610], [-550990540], [-616548558], [601446826], [334202604], [522006808], [-265782566], [641241686], [629907808], [-34002878], [-486020982], [392752726], [51041554], [731013476], [140005930], [-236935184], [610803466], [48049950], [-226313238], [612598986], [396937086], [179956536], [493582266], [65835618], [-344850228], [-184576894], [413764158], [360409442], [384221330], [679961250], [-227334198], [-84888122], [-632239894], [839596286], [297794786], [-519444896], [65438492], [31310430], [-659510364], [-431074046], [-82690374], [-139025320], [-418881882], [-191514822], [460834962], [200189098], [-444876642], [-121634706], [407699220]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_128_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_128_6_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_128_6_a_a(:prec:=1)
    chi := MakeCharacter_128_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 6));
    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_128_6_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_128_6_a_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_128_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<3,R![6, 1]>,<5,R![94, 1]>],Snew);
    return Vf;
end function;