
// Make newform 144.12.a.f in Magma, downloaded from the LMFDB on 05 June 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_144_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_144_12_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_144_12_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_144_a();"
function MakeCharacter_144_a()
    N := 144;
    order := 1;
    char_gens := [127, 37, 65];
    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_144_a_Hecke(Kf)
    return MakeCharacter_144_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 := 12;
    raw_aps := [[0], [0], [-2862], [-9128], [668196], [2052950], [-1604178], [230500], [-43012728], [141745194], [-233221904], [278269694], [1181577510], [-856975172], [-1664054928], [3851181666], [10339000596], [185948102], [-2915010572], [12662314200], [-15201270694], [36644027488], [-9217637028], [-30573828810], [145701815906], [55990373202], [43967678872], [-149243933916], [1209122102], [275810573934], [-54829242128], [769884878412], [-390519407034], [-51410226884], [1398152209698], [421187206120], [-1279389205594], [472790863540], [1046276664984], [1461501724122], [-423853426404], [1831364429390], [-2944975046976], [6253925439938], [6662780004978], [7065300309688], [3119021047300], [-13424356217840], [9959199906060], [-11912996102626], [-19658754767610], [300145664592], [8825045703698], [1540363511988], [2367000167166], [1692689382072], [32498328969306], [-8845001866304], [41684692290926], [-31377066111306], [-39701112943796], [-37147292141166], [58293859900516], [-33826182305976], [76906207556138], [-45994262716278], [-112182097300292], [-62919189291406], [134319876720084], [64987352165414], [-60639780562146], [19595437889976], [-102499775294528], [89164507582382], [261503569554508], [138948140935296], [183753130390866], [19493174570294], [233383694188014], [-158513211326326], [-282880390257972], [496374589940510], [397676989829808], [-149631852906862], [105727846909288], [33108843596148], [186449175017118], [55246208296730], [-7958255059206], [556636965712384], [90431585997084], [491081065324416], [-200848870675016], [74524011193764], [-679790361744476], [-323785496900952], [52627193392842], [860352232300038], [-888718611973796], [-409513462911802], [199315595276404], [-1349036835195366], [-2543162367249540], [-2741741368763274], [-2767772239331540], [694652892690626], [-904959060206652], [-1415401288356402], [2221445936780424], [-2809686593075062], [767540141090896], [1470311661092606], [-1227362734966842], [1008090438781084], [2980511445149128], [-3591537428794914], [1786870083540052], [766508119253784], [256438061049978], [-3632704875031428], [524024478713678], [-3223470233326750], [-608104820236878], [163384066186308], [2574863519070532], [6951024549707274], [-1641909916265794], [7031549911837392], [9651454767385384], [5387058295086662], [-6232121245122860], [3051316336180248], [-3929906199270272], [5246624538781262], [-4831773654396042], [-6552299014934782], [-2313216589501134], [14718212451338404], [-2504583660667446], [12940040635068006], [4704101193232060], [-11229554006177886], [-8537320572879416], [10209087431930196], [2257851938398118], [-20509858316064744], [13600896659335694], [-10391025714009066], [-13314188344710740], [8383312755242784], [-15149326822729258], [2862423495799470], [4517150484630916], [1468016828107848], [-20955764236475684], [1935786283468848], [33503476875771688], [16574829325065918], [-11159594246369926], [-20867605514109990], [32440271842566684], [-36119940830845578], [435846310992760], [-4012425576747612], [-42719098639779666], [-37287455306263704], [44710117906076272], [-11697575461596418], [12786737343497234], [39603094306242498], [-26316610850234988], [15836212905939782], [-68610916058901768], [28258944840087194], [-62849529484712096], [25355150137989558], [-8930021957199284], [16609073673997170], [-20959292130246440], [65037649679481686], [-36307256182665392], [57482358014158956], [-62046471599876674], [37885133204404902], [-53530397611701840], [1102665127425570], [-99835456356631738], [81899902763101204], [-37005896958681478], [36220561704457344], [22888759755252482], [60297879583719108], [78124000798294084], [51366325887365706], [138887376518275884], [34272781988270598], [-67395538300855918], [-58150314810698650], [57213090758275902], [-183104855885271240], [48510500732391546], [90032780822638336], [-48367692549080914], [-72402532475607646], [-39466784023571196], [-68886076258047798], [-58738299450238736], [94210046547545772], [-160551560777118426], [63360352398506332], [82959425385642674], [-174414562353651870], [-27012752233105592], [18673419777562548], [145041433925475384], [-158595551079572230], [-69157115211565376], [-153862567262535186], [254908643044968936], [41258832267071178], [-264656872393108258], [-311917303205809496], [118440829617849630], [149044430624587072], [120157716184001820], [82131759341696846], [-125021362333554954], [96318608101391808], [-264350632922230376], [-75877942961572380], [-154724804722403338], [-19783036101185660], [-81472143565189520], [-525673448831559258], [3811466894113564], [-156182483968797168], [-323090693409582670], [13936851431465058], [-310946497780754412], [-188454376679199048], [436504820654402748], [195500065847123692], [-266654172324139304], [61470924238783862], [-461703045755348658], [268530502961508552], [482858319252830320], [506461224629190636], [260555746945583260], [398336351922945936], [-17672344606256986], [25748691382294398], [620376770817688536], [-458113241883269158], [19690850997497754], [552757450527625788], [-385788064082426578], [-404101716791145908], [441503060205077010], [499931126942193002], [-972907270319163152], [-589964113730462004], [-1036897358008007362], [411213645589915430], [874515871739376702], [-1113157464896557292], [665711327936694042], [707115840363939222], [-136804694339739572], [-1061341583569978734], [1203656797107787766], [28073491573285828], [-679901062845517942], [-415397001864934544], [-1142141152014186670], [384892535411143336], [-644395675381852428], [589202957998444550], [-1347999087351199462], [-129790232231725188], [255097225188099648], [260007621846637528], [-839222682662944728], [1052375481578350622], [-932441300637403172], [1136569260656449008], [-389002090993717582], [6131706018952482], [814369671740960296], [716450250349854], [-814678782993829926], [-1530101878825178916], [-946363715757856170], [-1588567763205871164], [-1617396076067885194], [-1425349214781215094], [536984046098855440], [1340196883194230370], [715394641952203956], [-140888588780498348], [1595762915446507226], [2711979692955752634], [-1559190160033408352], [-1519814975772176388], [-1907763863507510036], [1892113343466928994], [1423882911317096772], [550184099932354550], [364500659285496936], [-783135235770592546], [-2356012457450212752], [-2712384942349092030], [809767750608751230], [2583215698139291380], [-1917746032967500968], [2864130721966717562], [754841531823338844], [765355211142195168], [-273619260158471230], [772330990937714766], [657096067053745540], [168205596575275274], [2165283174830643306], [-3531449145344642768], [-2346269269009691034], [2754573789786154514], [1716212429616375124], [1489845181254063916], [1296654147867224160], [-302938706450912526], [-3782554528408112266], [3688782801190567722], [-2551996665599895056], [-2987667081775474740], [-4859882630146553348], [2093499797420422548], [-1806165962466332698], [2658502804998513438], [770156846339995322], [-2221998349156127264], [-848319612149572882], [-1395748801453849290], [-583411510585850382], [-2744474849993374472], [-1067622900597614358], [550544000630280588], [-3781568060864020258], [-630046793008118372], [4074386927072177520], [-5203945131378995934], [6040342856970845140], [-6623222502265089382], [105513044149822554], [-3852882974498196416], [-2203839692346150130], [-2273195680763018634], [-7607130622133249952], [2508181608456173988], [-2705963932905684210], [-5191723735375048056], [4605467904641492894], [530322534329671206], [-4401787904728984080], [2873257953566653908], [2709871848951032980], [-2831732700619043590], [-1929184759656399366], [-1145680664786191016], [-2809223039714931190], [2743157404390570380], [-1289606680986658244], [-5710890560070894192], [7429170476168536482], [4235631656247164488], [-6844067157016610650], [-7874910295488422244], [8171835331200598368], [-2271640278499552414], [11163096124703453070], [1461706190334408170], [7755388364443672746], [-4616022223738088442], [11065404252347717032], [-1319608118711182626], [-8429968695937196876], [5022650987603492184], [-1207959575814802688], [10720985369831157902], [-7190776657763225684], [11928163273720192224], [7174509622789004546], [-7871656709889887598], [5726294488682488260], [4127243968259787364], [2341103681357890920], [3896816187573140234], [8816451479676165520], [-9126829601270747226], [8961573955795331068], [7202809344711184578], [-791131923664189498], [12412129737839974110], [2571367010497996096], [-7252394374774561770], [482497057531607634], [-17494632037204070024], [6843364730326905014], [7014673254622283982], [9522483964928481604], [-359609049650948436], [16381036510559439026], [-2516449914842687262], [-16397327826048207852], [6731800669026304180], [-4897465572055963270], [4441171903107254010], [10858654652373239616], [-5907957339661115816], [-10495933633754382546], [-13893410413868205816], [5002065734998066506], [-9152837332206645058], [10074125889815393232], [-12244097511166606092], [-713308724365014502], [21845700672494069466], [2121532671814607196], [11711526081345203958], [4370468977943521900], [5300762815547787240]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_144_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_144_12_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_144_12_a_f(:prec:=1)
    chi := MakeCharacter_144_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 12));
    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_144_12_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_144_12_a_f( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_144_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,12,sign)));
    Vf := Kernel([<5,R![2862, 1]>],Snew);
    return Vf;
end function;