
// Make newform 33.14.a.a in Magma, downloaded from the LMFDB on 23 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_33_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_33_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_33_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_33_a();"
function MakeCharacter_33_a()
    N := 33;
    order := 1;
    char_gens := [23, 13];
    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_33_a_Hecke(Kf)
    return MakeCharacter_33_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 := [[140], [729], [48740], [487486], [-1771561], [-18388304], [-96233254], [-14954652], [153804394], [5219010534], [1183811728], [-17672200362], [-19461739306], [-3412304904], [-100327719050], [275469097716], [-267676863080], [563486626260], [1080842815700], [-1150562265222], [-345914515454], [-2004080959294], [-3336732240564], [-5696238036294], [-6550114593202], [20022479158390], [8502303668252], [26073994105716], [-2658708838544], [-37604862081582], [-69327879420238], [-53197048899732], [121036733331910], [103706831285236], [-29406796841486], [-48657862283542], [-231547949024518], [144315133664188], [417920392609620], [417434593367094], [489549312586608], [382068865953010], [281802760715278], [626550935447542], [-660081515439034], [-1450474435736964], [-1861391228003400], [2644720951459000], [3074274770386404], [-2986232723054238], [-1866367174039362], [-311969862901140], [5251759647536782], [-2463500912392408], [2415142902357746], [-1680246644901632], [-587926359559732], [369154168234574], [3443193798172348], [1735594272544842], [1722437241827176], [-9329108844968478], [-18579482327184100], [11021897594256018], [24463392998876858], [7280138890452920], [4919407238843836], [-3617068421267662], [20313536074195196], [-11609126730140400], [19389379127983818], [-14589509936005444], [-50434244543620928], [6414032856887176], [6858295510475716], [52786486399686826], [65721625274058420], [-104942163872731790], [21475875099672022], [157660905817499142], [82025706547294624], [-55969531539052970], [177267305249750640], [-50659785384198806], [-67666913237108150], [170873399174150480], [213667466268334], [331394726325946494], [-265757181687137934], [-4274968177852436], [-25639816785746412], [369707481579680104], [-517794582889114012], [172055552695976108], [131941023625279052], [226739910249298964], [-86707040581737684], [557567876318044998], [-480021409954171312], [-307366789607686952], [625426496454747068], [597922604150795882], [-94827380856626860], [742364019149057490], [972969798374761244], [-488742029588423874], [1095819720008133968], [-1820874505068063086], [579051919061986322], [-1680395497885010038], [-218412099734590030], [-89181869871518884], [1198321185270768018], [2572482362321500772], [1237975764729439336], [-315859976174877378], [1628662972134150308], [-1204086910427786966], [-2583008758477027576], [2907200574310327076], [-3292697437310673854], [-2981489485322741578], [-619017096126064290], [1077003921003374320], [-477335520207287524], [4372190113382947954], [-2417226509541691438], [-1888289926106974926], [-558550898357705580], [-1545849105375903024], [-6425379087968791528], [4385663363281933436], [1756847885489937952], [-1973672045761924834], [1914325050952632690], [-9699493690328117146], [-1831145382936995292], [483944647222955680], [-12861184955018289020], [6970439217641964822], [12111067271476987288], [11338653590130710750], [-421753644810308304], [9622968141925018348], [-10107364028602925666], [-983113408002475810], [12034664455922547524], [-5603203378587116330], [116059524370784196], [-1144384005985897338], [525917803430721552], [-10215376989469415870], [-16790407486256477348], [-9981649834298541884], [-19093145163162925860], [21240317467486967850], [21453896641159104142], [627433594591455846], [11458007156407779962], [8370332434817962926], [-16630907891935218324], [-25429704779503778122], [5783219127863746402], [-41218230675456380216], [-43321725808756569618], [-25249168511303349150], [19039965224368190560], [36364288262729253920], [-15505172907678742138], [-57041368210940569560], [-29044067434606969364], [-29372790202586827526], [15604512686678772940], [42145932993180367826], [-59191788845394668656], [50728289354781028522], [-43248124551366712588], [-55172792254909408256], [34742639726551240718], [20673160742442967456], [51833937439556301032], [-1715108378187301940], [-79051850895321485154], [114390829452921173526], [14409744732512769546], [-44315047660702271520], [71484143563276400868], [-118867123600871135340], [-12786130089809955034], [-98447293450324274480], [76304130530357584406], [57835479357470337620], [-113454440410412923596], [99266469632635390212], [98798092916802501924], [-5178685873997936766], [-570030202587163606], [112901425914046354066], [167433344899604550798], [118579315432324458664], [-139372630636927737630], [-186806386071933013122], [-39762221654277130206], [-204205162104466747454], [98464165440573210568], [-255388500420061683856], [-20705848065962515380], [-133739653001667991740], [-118956504605190450582], [-219550944878447094668], [120112080919563513966], [-72634571200556155920], [258052653109525377144], [-20706206578593610924], [223897501581874651884], [-89547737927818306954], [-136507740092345011654], [-180832282340680255806], [374905996515839612706], [-460479888137496699624], [275871295826819931316], [155041365408488202954], [-253411533929923394658], [154895677687600261760], [-19499891974585407588], [-300194397371676389488], [-189149436857484180342], [160622509411429368318], [-634102834055133473438], [22927234773903486812], [52396748257655709790], [-663427368863422430792], [336975530611319842390], [-197728801242287920502], [171860032236820068796], [-179629565739930579880], [-443432508550013052558], [30843912333284954274], [-130636433839265922784], [-334299284333162842642], [-715004244166275750508], [117890904118057610696], [208527101586663582024], [480198424036566406914], [-448816258584898380190], [-758693428395315453372], [-684804213424256120092], [887408192408047076908], [254453372724391720644], [-1200877132020371982628], [-262766222826465293060], [-18784728349240283978], [-192767599626635917866], [-410685425726346521770], [198570442092962239938], [-382020512547994909780], [-873827597174485560074], [-2508891530842881288], [406218455996227295088], [-1367751201722339863850], [-53786027417909525474], [-937022772159037604172], [1189325346339345891920], [-140667789084150284784], [1317645374798006714070], [-261319529378808148700], [-554812622642384577360], [-223284924058209740718], [1972914693344014613252], [-811923135200470080834], [-712221363935165146870], [490598881319881597116], [799820282728814637550], [1738375179322617500378], [-274680736030297181638], [951036636120462033284], [1488321380612549123748], [-1145598183862809961796], [-303340955064289990670], [1013558253229850688588], [524239683721732874864], [2313502476063794244836], [1041485950161002822788], [218745402656378405096], [-541767026125513059428], [3078560271672023579370], [-725353312357523870130], [549209773069115786742], [-1572127135965888400796], [495025223518652539442], [3203657836361010420964], [-564978506628224164976], [-521969661352200823926], [-604131139732029063348], [548773703747689555680], [1060516205166098694202], [-2368428051022472737964], [503912199354859799180], [-1306990600952399789460], [4565533680616994496584], [3234206311968501306846], [739354330763693529930], [510303956177949240766], [-3994244151277076277916], [10290338247044718092], [173022296355869299642], [-1338396827849045598588], [1179909767932935958494], [2946462021921262070286], [-5448450243457975866048], [-1746517400965285177116], [-3080717886865887529984], [-627529719660093467874], [-4720922097554587477156], [-5273637947873109386376], [2554187845840403000834], [3386634725779662377500], [4287969644704427868536], [-236669870637413526974], [-8300351938354641246098], [-2586453422556701267420], [-3066754136986097742314], [-5235953453486863378766], [2521918065417166394276], [651041414520507419018], [-8493980832963610306], [-4889617867354696724772], [8865109542284262370004], [-6361061200953063635868], [5038367549515348229942], [5247624079974736406572], [9135224634465236469948], [328309815619403794166], [4568387823128216231204], [310665722190105380568], [3894428521725771427932], [7261205616023006505826], [-5650226857653007811902], [12495228040741710069658], [11686982589781080652706], [1633630669269808829474], [11017879634785804512942], [-5680623840378904219206], [300286605261992791424], [-9378287000431005381572], [11047626167682462799916], [-13060253371993782546998], [10295461515262936053956], [-1949960126596749224700], [13770117719994018553092], [-6017527245017030942824], [4054722756375295082034], [14471713055925813496044], [-8299325524945621224606], [-10804430816894444536412], [3814744341628344290406], [-7167442969071670706670], [-3588823252910662794452], [18720227149457694520558], [-7192196716921001401754], [2926720982639674633580], [-3158511434963721190614], [12317655586397539622514], [-12776657115153921983452], [12402355822167757307124], [-9323933857903623506342], [-10892633608919307262134], [12560550420347839081274], [12026612323922083272918], [-25363722484237544581680], [-14602614914801037115788], [7753312433166961596296], [-16167374018929512064306], [3701092054611486718210], [27368000004685522909366], [-4558467385708396415972], [18595000776007854565492], [-13397586593112437325262], [1411312045633495856766], [-8086838368628607244386], [27621917644167797721284], [9026492049218292755214], [-16886142722440952545222], [-5136670221630037255694], [8202393051897741771064], [-6094890869106556656306], [29469692792266937964408], [-5926785437545338920698], [22073286600227348035280], [4124987693237255371702], [-20854728281329078797370], [3541714601952069697544], [7203577438221295547968], [-2152777559160759048476], [25230427429631061987870], [5607020313559492890886], [20570228663333129973542], [11269665402178475106246], [8490874708250884062940], [33545460309381270701302], [-2571193986475752710428], [-26359284605106408827314], [-2676412855099049095818], [22891330962725519826558], [-28462345431310220926918], [5314374233033261399646], [-40378577033796318561162], [41531793404764845336494], [-21899443286827949192716], [-230968401095710704572], [-25998412772948182676622], [-14633815890062032917478], [-10521714260931972486868], [3177480301813037162828], [49636267993210941591650], [-4453536410205116181792], [28736960364785016433300], [-21969136079271685657980], [-1163620531093256859794], [4813548695083074170700], [-43339907179378531750856], [45881189976077051574748], [-1179009162022689149670], [-37995427785613445073628], [-16630385468182798628522], [-20625612911027460281940], [15551285352496944076692], [10578498162564433987886], [-18073064037908981807396], [-59206936275319922486512]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_33_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_33_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_33_14_a_a(:prec:=1)
    chi := MakeCharacter_33_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(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_33_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_33_14_a_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_33_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,14,sign)));
    Vf := Kernel([<2,R![-140, 1]>],Snew);
    return Vf;
end function;