
// Make newform 30.16.a.f in Magma, downloaded from the LMFDB on 11 February 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_30_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_30_16_a_f();".
// 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_30_16_a_f();".
// 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_30_a();"
function MakeCharacter_30_a()
    N := 30;
    order := 1;
    char_gens := [11, 7];
    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_30_a_Hecke(Kf)
    return MakeCharacter_30_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 := 16;
    raw_aps := [[128], [2187], [78125], [-3067456], [-41360748], [-395658562], [-1610570886], [2285021780], [-11300532672], [-73954639530], [268626459752], [-1012332655546], [2158036546602], [-374267777692], [-3231654074376], [-7594347998802], [-27220596777660], [5269415220902], [-68276399830036], [-81719695973448], [49561588147178], [193168663420520], [187748261995068], [364870150917210], [898381749982274], [283903599306702], [298486410203648], [917434415029044], [-823883820142810], [2164771881764538], [8806704068395784], [-9367927256045748], [5828274945433554], [-10969409242649140], [13335403340070750], [-18505178760481648], [-31450203756151906], [-59287347886121812], [36433634206046064], [17067185676151878], [132549475091249820], [-122459249666115298], [20068056481321152], [239484078656769458], [-286905155470004226], [-214194306713879200], [-349385294945629948], [-301392218121745672], [-480144702866454516], [414103122556881470], [546836290439961618], [-1145915411928114240], [261778869256074002], [1248495298831073652], [-239247711412270806], [-67866122331376512], [2431880221732336230], [1769104409793391352], [11968636922316134], [-2308346761153632198], [-2126415366469409932], [1607798590758664158], [-1908718728914723956], [-2596820326348771848], [-2452286430588492262], [-7191810230785840986], [-7487446247963313748], [-7006045689555706846], [-1087054101873606876], [-2867889411158465050], [17377515149693738298], [-11923053803715705960], [-4948812147761617336], [28109347970363168678], [-10727914746104041780], [-8516051794317369432], [45456480164361104910], [-35226605426363093026], [-36707711059085850798], [-59064740894542337110], [-11450631305489219220], [20814792462204003902], [-36039328287168508848], [-44702492997185496382], [19792136468204330960], [20380642445838443508], [34018957781970151650], [158344016648477731994], [-49104049743060856698], [-98691077081302570312], [-30192583158327963636], [-111195771145651824480], [-53289262421706382096], [-271446536739155804748], [-89433085789902550300], [-101356853842063821552], [-88866675548353032810], [-78902554914075794598], [-191913562901517093772], [-344054990156038860298], [622452750712945330124], [549947402566567795494], [660748972259041922988], [641938837012534349130], [3985764385135719452], [-534283060187296291966], [-847583380171656926796], [-301600326381344036742], [-160539759651993523800], [408864823565313916202], [-791780412706189674856], [1155895975823325357638], [-41343059547578805486], [1426833942884267727980], [1241402671410038418752], [944072111888633246802], [-324966158250475479892], [1595782926745839634224], [2214481772383424750598], [1415819967171035555340], [1498800963899367557102], [-1449859231037129633422], [-2978469190852905310866], [-1676677868984354005932], [1067534780396400857252], [-3138166160516286164298], [-1006994259746098356610], [762891293743076047680], [-4417545063976447496416], [4396624916188927429118], [-977740761930009744940], [2772037946412868937808], [2067411836318240683352], [-5239896336729363049306], [-2451420693861552469398], [-3178133367061412909470], [-2815479960686472629922], [-3498735672603681771796], [-713892125792357376426], [2232802990123352168490], [-762183905792499240148], [-9576019064665622435298], [-3941153567819637716272], [9687950584597810156884], [-2447957070618548817130], [-14053188607122930012840], [5240398113207130228598], [-16207303401567148494606], [-9403575545498192615860], [14595206841099433680888], [6382716221919470872334], [17603065726493290280802], [-20832442549773011363332], [21246262970180347941504], [-5609468438739472162156], [-17215589725508814728448], [-21717759583552019992720], [31811341308353207255970], [3204022237715148764954], [20166760768457254548102], [3062920508178883761324], [31179378816859605577698], [-28747651571392735523536], [-23234967875831526237948], [-52338670000681832314566], [27125971083644235684768], [-4423936013732201114248], [-38866508263279890580426], [37749459317732438051090], [-50892772184753728130562], [21964604700453397930980], [64538762960024048538902], [-22307146077503377361448], [22613648597052669188618], [-46831160758153808826040], [53785707768549647201850], [-63234666489506687887348], [-45467928484405088383698], [73444565864869558487888], [51491911182626838009830], [88510714820317873106504], [40704536820020475499452], [-44055861796021265869642], [93117182647342047635874], [75243361033144490637048], [-4162008169963839123810], [102359743790755910935214], [-30615392372742971667172], [3205502886338238193370], [31154906062027326862752], [128983173352915169048498], [131856040774705512698388], [-80758066840069563066748], [3208945759546457996502], [-67351102180025723087796], [14970784415838040229058], [2326292611136846254802], [47781018055527563644238], [15490536499200298402314], [-163425872991412514224272], [292854631157114068469670], [23313442773235715310152], [-225457818907292295459946], [118672506849469686190850], [-46898933184503725008060], [188837853757789108813734], [-220287372222589034414680], [80404756639436721623868], [80952883889496553004010], [-132274599498869707453348], [370023777571660781998274], [244721150898202899871902], [-9970577965969201943152], [-36697765958430954498156], [-14165704171565734495320], [-277532878391377410313798], [-21711502624638345477016], [84868927668050936830002], [349470360244325882536464], [231005965617378658444278], [-450481171433196490335298], [-324880984548428219566000], [-426547732992473179621710], [-233767682703337618772872], [-167393485410922076214516], [-76323108228890989960930], [-327061976312094257956782], [176733552263764661109360], [267532665190017536513024], [602773329259438526421252], [-673187164550715365393602], [514290310664975510904740], [-779755715935851292006648], [173785822495282076780202], [437999730432005864353268], [-245433183724281717262296], [-273852106801724078653390], [118344505325279468209758], [669470754354756201657300], [-688541328374659273961448], [1142692559274675511463628], [783718884380275086526652], [-358074432986070482024992], [305793336035509508436950], [95205916817792667605898], [-156395430442530357096360], [-346589370487821797625736], [-1669308989503517918474148], [-673352299485366461268580], [974147594162313874183368], [-706390576901830282056226], [2018278661471027684716002], [1397937351904634433841344], [1306384611067023788280890], [-1299072815376397420415562], [1636782964110719192969580], [-1980678977265596998270498], [1426734744092055560884484], [-1099970979342035144422146], [-1320633940128886996040806], [861934477533016523161688], [-769708601017353796936836], [-841180849190097195865570], [2100506846173268572033358], [893063043950313636792474], [-3050402811825173323396300], [-130385364440247900834810], [2337507426533430824912202], [-902394786595932062221372], [3358754370704468313925518], [-586724978237456980297498], [3386021021231935365612524], [392634247649074637230298], [-2577353559217188951817960], [4244472476416215255282434], [-1484584252471028074782832], [1486019681381440441258404], [-1476421325376311338163290], [1769254136319936872931002], [-1231902653042466345155748], [-5368288834843409560573272], [446311557157528648234352], [-1214835224049352729954176], [5220384984729167393904302], [-2367749550334118312509036], [930169366750792830955152], [-2154870516053984661955822], [4246472158391662227292734], [-6926777291889798636150880], [6201455741405492282684610], [-4750290805854343845695898], [-1253086269109652499695556], [-702779315654609943284862], [-1650930478907611595777148], [2357607082383862996472318], [-2713698168929043514502250], [-5531288012995431983054248], [-6298231729637268540583122], [7477072620249240251036820], [9229341400253225809815404], [-1259766912041276922354742], [-2790573522754787415443226], [4667452676631225607753400], [1612395578977001991783948], [1763345661832375152583052], [-4351570724130909325094686], [5711231124140145143242884], [-4900527772261636850941930], [6392897896068479027111160], [-13145052130669232795978602], [14435094653613612489426888], [12779821467411114087292830], [3977527361694472944575202], [-3904152502524686967460132], [-11554990555911532298803296], [-6745378879921729053822790], [-258432614643788582057700], [-8498104823918097557844048], [11828057897275697861457938], [6322808777949821554913970], [-2298634142889896713551148], [-7149625637587922688317446], [5578095380752661821839702], [2078148945969430482236408], [-1923782279845843028230302], [764652304866608429014802], [11911703447696472371073620], [-2978059857701849966626252], [1549377033707574017231544], [9232379403037529970656238], [7251529026699941800374902], [-13312335009965773557839946], [13418127000834993538057160], [-14992017775849078402292292], [6210192306429278075950652], [7154326412509365422558964], [-20782095887475728804247370], [98527824311178241697178], [15109211063893805347078202], [18496527933623850899250104], [-17631244773401079135017242], [-30841527548341030800615726], [-25208339626896066425748210], [-14503353501457518991364848], [-18985380559120440315645882], [2094100978888475423901660], [-6203353391839272947804098], [-5947726679748308450487676], [21058955128366686804634752], [-6519964208202780957420306], [317425533947366287080452], [5599842190616599919188634], [2076234621610762697668902], [-10944104959967691743535832], [-21274005674959872160355890], [-26400068980608876095481342], [-31588747184523807998092800], [1695539065805629466075652], [8973296363677647681319914], [21055534014680230311094128], [30074281643385644397689654], [20394449334838344537491802], [44260259661958203795212424], [-6594277277520548114410860], [27568032114172882169370764], [1985370962255222763704378], [19436119698948595150087734], [-33036822648406704755475952], [20505404613013420621528202], [-13378514421566271534756948], [19816151059001021356505660], [-19129339397376489461375592], [17442152451057528097271550], [-62955360111584415022340848], [-38117439310493881818687106], [10160943346949842583085420], [-4484752802226324557395248], [-75703958829636247382564542], [-38729985280214063602446510], [-57402900417116315378468086], [5444931298714185368084502], [-51635445805312931062137582], [-36288379064543595586508176], [-14941511032723160337580806], [-54724098482148488436607660], [20571305442488540559991488], [44360669641507622029473752], [-20137835066394659937503866], [44808167242590935955619268], [-24394721581946495511541896], [2839740840667757233195010], [78926588831259357004058958], [-11167111901985753837936300], [-59969014940379409137403156], [-58106476521157818055588248], [-2135285004091515504443062], [11711459709567455132118680], [-58376697969851054938992630], [85025176144284844497560252], [33249420635473966003908702], [97988785162604420023241750], [-26242036183485974866291302], [41867762417592612530759864], [399817328523704987076834], [-57883702431806774399866290], [-100754526521221204283608048], [41561776237697187902924174], [73790614234932137456801202], [116029621726481385738104348], [-14720882261886417303056820], [-16985080450813259933502382], [-102460268181878550535435746], [59393612031902205405286308], [-140344821287705367042735148], [33642459252091108395937994], [-89334704573024752671071898], [61431863496936962074033920], [-23155119457914572642135296], [-27345615865188512809875126], [-16327596144877488749031552], [83695113227251645425243990], [13876971491508823338712214], [68937528930055846374573384], [76411672910102444018020260], [-73988254696674472706585302], [80395589162425324492986294], [-149290346109077717340180612], [-24900711657153022268524470], [57224196709165927803422252], [-98605570091471593297471800]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_30_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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