
// Make newform 42.12.a.c in Magma, downloaded from the LMFDB on 14 March 2026.
// To make the character of type GrpDrchElt, type "MakeCharacter_42_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_42_12_a_c();".
// 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_42_12_a_c();".
// 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_42_a();"
function MakeCharacter_42_a()
    N := 42;
    order := 1;
    char_gens := [29, 31];
    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_42_a_Hecke( : Kf := Kf)
    return MakeCharacter_42_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 := [[-32], [243], [1080], [16807], [454950], [333386], [329448], [-4876828], [-4054050], [64835934], [64240136], [439691690], [1147482084], [682653668], [2242598340], [1692909282], [-856900848], [328162910], [-6834378088], [18096946722], [4621386710], [-24901224268], [24895768956], [25356289956], [-40168146010], [-38362406004], [-149730930136], [4767758214], [118872893846], [286460529978], [296611325876], [-92825677692], [512233075782], [-310347107884], [51367859874], [-1005261113992], [-607339848394], [-2166942862960], [-2460908374980], [-1735635845652], [642109641834], [-4809894147430], [-609548391438], [-2079037535914], [1600108231266], [7694465203280], [9485914916996], [4981111884824], [6624581465304], [14016664183706], [-18484379564250], [-3868108670058], [9950038030886], [-6983638527312], [7475861593260], [-6239953013922], [-35477863178352], [40258087185440], [19761881775890], [-47630916444882], [9899077718348], [-34828509640020], [14934481961132], [29744456943804], [32555626905002], [-43562245331814], [-75607393803988], [-37410970464406], [145856985330066], [-77406644200450], [57943379214792], [-127790830886718], [138847310586176], [-231485192095762], [-149701170508756], [-8934809559048], [-298086024607866], [-257090010042346], [-326597337781290], [291270850131374], [177337142917032], [-77982971842462], [295962822539058], [-203620077334150], [-20921963481832], [63612099116994], [311808461032962], [155704678863674], [205056602509092], [268403414779340], [345017018707728], [-236438498640420], [42461271150464], [816784950490770], [225504490307300], [345852379014840], [-1091646553035600], [-861160951019256], [-1387390801109164], [77513360891546], [78212625726488], [-711681392002974], [-2140391582951952], [1492168612348326], [-1328765744022904], [405539015875850], [1736501646975144], [-725753623914408], [-3198418956472566], [2390902409269202], [-1088285294855584], [-3081347042120386], [1159252622406894], [-2212862346109732], [-3668954940000196], [-405851477245218], [4796632050263108], [1953837714242100], [5275210413827142], [3800374811058102], [2545102252196126], [3270000521700158], [1308767911084164], [-2304216922390422], [-6002624916944716], [-2827451704829634], [-6526007524985170], [-6753893366462016], [1610222790637544], [4067993383251866], [-3046989887998432], [2785063648854018], [-11961181622448352], [1479084317535422], [-2760275608815276], [11208987123522074], [3904636044181476], [11536613559995732], [-6228923269138404], [-14713882093625190], [11250072463483964], [-9159311630800518], [16939240533704276], [4454859638754918], [18647036592070034], [-13685453915390940], [19787373740416838], [12638018089226628], [-10086415263994780], [-7238560532022642], [-17631349201723402], [-26919721527173280], [-9906154141171228], [23449302015490188], [17668450439064644], [7350791897824962], [-29197999072586032], [29229509555396580], [6275120003686226], [21244565569971552], [43620062897791758], [-11638186199853030], [-25363224716204404], [49651897828600356], [-3917585295720138], [47764866253225392], [34427692635303368], [-3639301903746418], [-44628024104142514], [10771278793029180], [38117625439921470], [17933813672765174], [40315143198711834], [28793464316883878], [-48542335649329240], [-73646981858807664], [8348351900088272], [-33269941095629082], [43714798578337952], [-71913492719756554], [-57482946787545076], [87683840004142932], [20493268937220626], [-80235255426807864], [-20918763018531570], [-32010052147964316], [26950336555253582], [-13590257362955572], [-48106236804698026], [-96565656630344856], [36543180731125430], [141152072816004486], [117271604369001260], [53623198764005412], [18276281704935174], [-3327237460531632], [146931836692601150], [119344663191611210], [98810198089176516], [31320264331422276], [-47653229528830758], [86013497796266984], [36862825764445730], [136501754336629574], [4066473389614812], [-161246115779101188], [-146955847133131000], [75129429429125838], [18678187184039610], [34738328510921060], [114842921992425506], [-82942611601411392], [-235173866913586336], [8772377036132532], [-220537336391561460], [17050743907520882], [-160532862294195640], [-143735308530089472], [-112815518454249042], [-18170083279788018], [65508611943594590], [-231212904451910920], [-226023891781009302], [-189586404469422448], [273484520882583060], [-209036166780783910], [396722133302229588], [-217975326456217290], [-178699939484644120], [-19162803681432870], [-7088095742052394], [-218223702447597556], [46738463662424744], [-70873864573445670], [-211225389287377036], [247352586639417216], [-168498763674657850], [-440809531374216630], [206575520537785242], [-51128410448470248], [253662477818750514], [365823911711084204], [-26465208798165616], [-466415418304696966], [-175735494370345740], [175131085477147788], [-335356756550857240], [378474214947831960], [278829804231163592], [-169567756604697042], [401657707328754158], [2853003807511080], [-601440256233808806], [-572957309542762426], [431602010824260348], [-430268648150130474], [108440450634664370], [738191741277652052], [90823521197887236], [54288348737706002], [-782546680608804220], [294623733363957618], [657405301317797258], [-709030008178077490], [469041291509038512], [216949590358017188], [474352115788745442], [521641854367530216], [815149468543599584], [-284143480209459786], [358649772179376014], [-608291013702400180], [-1011655279932104218], [974635142710235480], [-31446809316995266], [-933332315223595048], [965470150265679774], [-761835140307248998], [-452191094800055746], [291481347406957320], [-575531264913167784], [33016095054305324], [1523333166375902352], [-667472708915539330], [-1129394740325403052], [-774277324229271630], [-1990257656538257422], [-567297052312750566], [-744435683068279720], [1367070498915294780], [-366940874122891542], [-1197541856141736972], [-618149972498564034], [651368185330804680], [-282911434191274522], [1367967879428020476], [-228488007602237080], [756250562661319824], [2484342364912983312], [703289029004047868], [-35424615875531014], [1041281409212280798], [1365294277822359836], [-776688777985835274], [2326504928487082568], [788173341910808330], [-1487164140108148662], [1533267808003040930], [1579001323241963106], [656764043783610098], [-3004983808526856264], [522716128781472462], [-2716163866628266794], [-371600741409714172], [263170196427659310], [3241806263799256406], [-2482887337433067180], [-1696241570433995370], [-2416891639553939650], [2096899345034317758], [-1150507103708717788], [755376186226248998], [221562965434636548], [-971891792261053288], [-847009381368453102], [2445337436740647086], [-171001166876215288], [-3532848561961822372], [-2055062142337241238], [824941771205498406], [-3297929285472219922], [2576232667731319638], [-789484691127882208], [-4667627459767967640], [-344568195962433232], [183286306927958400], [-3024430371073283866], [5486510177541878220], [-3642267783531546658], [47821346253399872], [4224336501742565198], [47522180054921550], [-2108136853781043936], [-925633016435438752], [-6021881348262998658], [6306177221286172470], [3258432476503381442], [58740394684201844], [2247482548500994104], [4454806895575972044], [3193236481360088060], [2866878094679805494], [1889569927021029834], [-1773298239251062792], [-5774635019831348242], [354641557566533328], [1491698990227210416], [-6721757758654011564], [-1125229379596913718], [-3017995183798658022], [-7624534244012111794], [3347245040358367164], [6742320213203324130], [3130467615838931934], [-3732496374874446844], [-8240704412316416698], [-7794119822897116632], [2416462293931008428], [-4256797295173047730], [-3888184788787892814], [-3957079828067576332], [3364333362108654714], [-572676946010805270], [3221048299435289576], [1956450475514265338], [-47848991560087836], [6165713469328597350], [2313530073365755754], [-1885451095810101720], [9408343596109754486], [465385208551626564], [-10315353215453566614], [9787323959536765808], [-4286113924431954006], [9051596869177012940], [477305120666347680], [2512422120951880880], [8065924438862788226], [-2070464253057409120], [-2881717956683577636], [47629514153711246], [126175434335337432], [-9636204127874453322], [-6911883625034292484], [10747690585054382082], [11711680128331222274], [-7950745424259882520], [-14363393263774094064], [9054052546064740784], [-4618325952879549186], [-8951274438234871474], [-12801386160553777014], [15321952423632738644], [-10256275123847980812], [-3905289179991438792], [-7836300188700930664], [14090114585905956554], [6739375770797711586], [-12498981436609921396], [-6785047336700946696], [-11486676647134784686], [2447316815563293366], [6478021288112701770], [7170495951677767484], [10792603200857697926], [6705435594965238312], [16244189447602787790], [18094068291875069984], [-6127794238497409872], [-4654696232160636372], [-9966318129287228754], [370597247395734062], [4076763018304786242], [14076542808669396396], [-8441855117853906742], [2844772525603192812], [13983115892404725714], [-11707151603041569186], [-16787212040725559404], [22040635811058988812]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_42_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_42_12_a_c();".
// 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_42_12_a_c(:prec:=1)
    chi := MakeCharacter_42_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_42_12_a_c();".
// 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_42_12_a_c( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_42_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,12,sign)));
    Vf := Kernel([<5,R![-1080, 1]>],Snew);
    return Vf;
end function;