
// Make newform 192.12.a.q in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_192_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_192_12_a_q();".
// 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_192_12_a_q();".
// 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_192_a();"
function MakeCharacter_192_a()
    N := 192;
    order := 1;
    char_gens := [127, 133, 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_192_a_Hecke(Kf)
    return MakeCharacter_192_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 := 12;
    raw_aps := [[0], [243], [5370], [-27760], [-637836], [-766214], [3084354], [19511404], [15312360], [-10751262], [-50937400], [-664740830], [898833450], [957947188], [-1555741344], [-3792417030], [-555306924], [-4950420998], [-5292399284], [-14831086248], [13971005210], [3720542360], [-8768454036], [-25472769174], [-39092494846], [-9310781526], [48575052512], [-225595713276], [69451179514], [-359664575694], [250273055864], [97891780812], [-155014706262], [1126265370436], [1384580812362], [-698601450208], [-2131269853958], [163564486972], [-8809425240], [730851575394], [-3923714421540], [-2279308973150], [3387088726656], [-4929207776254], [-6357850272342], [-3785535410272], [-179493837380], [2225684379704], [415847834940], [-18124772488334], [-18764059878], [-17625242631984], [-890116982734], [24228041356548], [7804917351426], [16595574775368], [-28523590257006], [23379994087976], [30364120269058], [15974859435594], [-28704507156044], [-48175396168278], [-25735029040676], [34604265524376], [12606588910058], [81824296913634], [34011469184548], [-59943948292558], [-97868505351324], [142789606547098], [144245920772994], [-124349284943496], [-160109534089768], [34725822875218], [146500203674500], [64341851639808], [39890033609466], [-106551979242806], [34144491481698], [53334901088234], [101287654153404], [157928472303826], [513171359936640], [-74924767954222], [-368335241090320], [111247830230916], [-88331413841262], [-9420937722310], [697133548616898], [-187941271733848], [-320006635626996], [-150382370364240], [176546273555504], [860958181676292], [-601209457412516], [1092030351829704], [-876371101334814], [-371989239852150], [973507481712628], [-1746062781765590], [-174624425985380], [-1583649005842494], [975797917848204], [1924274391870426], [-1611320399461196], [-2532503285394046], [3115075841122404], [-2207230435400238], [3411585709398408], [-1575452477398774], [-505592119502056], [1983747166907074], [-1930986428345862], [-947688701475164], [1005926522765312], [1131443807632530], [868305558659068], [-1376364875369256], [-2552758540391838], [-926792107209060], [1903318977724498], [4929900506581730], [-430293314013702], [3812440532297652], [-4037287750902356], [4712672943685602], [-866706096098606], [26266614058368], [-5680181884175392], [1623115878038218], [-3647940323190644], [6760448268703752], [26483336560376], [-7373643624794558], [6209832596186874], [-8861954082034942], [2950474409673642], [-13554522166415156], [15992249482082994], [9458590804847370], [10799627434960948], [11041089876780186], [12610352980858976], [786172343593716], [5925892982962570], [21020885793462840], [19837829468018002], [7966388437568826], [15974892909578980], [-4029257485765728], [-9769575093688790], [16258292298256914], [-16606117429647572], [-19131414356441544], [10725166653853684], [-28224866626031568], [18355082826013760], [-11012509124864814], [8363567050915322], [-22294170304617630], [37803832630940892], [4795681030490394], [33741958118885504], [-35858687142537900], [-12002334917621406], [-4426868496055080], [-37916708594080408], [-57600280458878], [7035218914614770], [-13683066346126326], [-20867877644988876], [43321549659971482], [61898855996524584], [-59456551648533862], [26121771539998712], [40972592810939466], [-29050978742193740], [73950101045550234], [12851211568257632], [-30770326113449270], [4867276861531400], [-66250008587571396], [46992779590122514], [-43718422033413414], [-37173650350909488], [-63283189582399830], [-25131310316782454], [71766794335592236], [43501961665276442], [-31575190205097216], [78153256556596802], [584867308546884], [29326799954985532], [114725429284591794], [-124749906820108884], [44364383610990906], [-38701375524845614], [-25280358000068246], [92946264072139266], [-118510164885612312], [80704789081784322], [155137596983924648], [189425889091716418], [-80404666215468574], [-194512569561303948], [-36267602202286110], [-147601141337531464], [-17983370202913668], [245216661611093178], [-189066286410006284], [149090803733447858], [24634054221738], [128663175680808080], [-22947146672884044], [-199039501350243816], [8463690470903738], [25357162960188728], [-226534485261064062], [-350720195537631528], [57480967603440978], [37215526806612946], [-53927729950346128], [218169256596366450], [-380914090762375384], [335419764117401004], [-71900245276829870], [280193116514043498], [-63535374862583184], [-281865445173238144], [-267789482952372924], [-254329240197940550], [-54456755233215476], [268673600398308056], [-187405619635787622], [-415049744220705356], [302640903260506464], [-459073914578361838], [142133133768388362], [-62210982507069756], [-111331068305310792], [230876385326482764], [-368696070337116044], [36748174434530768], [-645797444078571158], [-216615264931402062], [449669039276902344], [-223622334716320888], [-576501882331083060], [-279213123169530044], [440915544388523088], [-26130638692028150], [-699551742161992158], [90538933214884440], [-481549578192124006], [184621303294521042], [630979763091050268], [-233560259699929022], [-126809206771191404], [-194852937743039862], [876370806945939242], [812045213668716152], [299055303522626700], [371241649241849458], [-854647847257328966], [-123060392681316846], [685014984276002572], [362759879734162434], [664563856092363978], [-166105057993741340], [321635282269051194], [1112347718563418506], [-155642185797887396], [-1122061776605762422], [509412722850571112], [1007928184524089426], [71968517875692848], [-483983942729063772], [-464151471669900230], [-631889005114786534], [-623432360264613540], [-619213031856076560], [-285228416860651936], [-859932402046570200], [-897173543059521566], [-717291166408466156], [161133481125336240], [1219101007190464658], [-357365189670860118], [1868170331611036832], [1286527030720736130], [807836208443388354], [1636639912799383644], [1870216084915228938], [1813863775239094596], [1851809960115681322], [-981408548734770990], [-2082672779361104488], [-1720703724609572934], [-612994190716256220], [-1572627238676851748], [510281865590253146], [-120453934861278], [15192882075744632], [-890730891203861316], [677529054481947652], [-593243114021244286], [-1520060577011916396], [-1589562447562958246], [-69971709179496984], [-1860853308387437342], [134853070780172112], [1426832561006316954], [-720171956971750350], [432876052703726812], [-221064294312858744], [-2761918686836314054], [-2812980248190936132], [-1829226412520424528], [-1550889483928340350], [-1964252535605949678], [-1457452719826739780], [-3080081533851666550], [2441687998652935074], [-162290519201227768], [-1124564690107172118], [-2941966959933316174], [1228749955233837820], [1591134529495886212], [-1814500159041446112], [-4239858752715888486], [-3762437926461675782], [2425319243974409586], [-3234177293591528680], [-140151952575007764], [-238936035732896828], [-32764594960319868], [1294049121957741562], [-1251988642476310974], [1153428863684137658], [1953959796094914344], [5079435715408269298], [1174119799525195290], [-3471572618165179254], [-653932658656941088], [-3287974529946603966], [-2067288790032226980], [-1580714990270326478], [5889941608844545348], [-3258492283761670560], [-2441047836708018342], [-3585646333015498916], [-6631429266836880838], [4059348713022707250], [4613335128978493064], [4988294911703665234], [2273623873498051146], [-6049895375043677184], [-3283436125656096444], [-3360155163277965918], [3714403848276287256], [2203788239432237506], [5760823127043089274], [2927511105787413072], [5202701106207670596], [-4180611401373403316], [3132797379588730490], [6683114760508033266], [5113200035210844656], [3228162282877252106], [-1323844645625851524], [-9359349974945579756], [-6460049525503315920], [-2710417144331600646], [-8110065773214896896], [-3630956106089678870], [-8153377180322153556], [-6304326448519379232], [-4948624225973923486], [-3924698535405340542], [-4465293981413555254], [7907445325225780338], [8155850330320705002], [10682375842877588192], [-3919789660791249246], [4588826428695804508], [-8502787672725203928], [-939395724091248136], [-9362180583347524766], [-717452170483577132], [3671876128256864976], [5757292136871561794], [534375151926608154], [-2258678401923775932], [-4116845892096177620], [9871593505575901368], [-1943940422796578902], [499507381328478680], [3848447736693211434], [15140856358861714900], [1827016601541499626], [5630777033064670522], [-12644755342370430606], [1811154401922382280], [-3620513072172553350], [-3434452585385782806], [-6252381255078271600], [-4399176367863243014], [-14857306465435362174], [-5424066481289070068], [-4373078750563583364], [-4217610023906544526], [-17464418679207309846], [-6092328969411307740], [3992189947850532604], [6715645306316154746], [8537397336078716466], [8506088532993142656], [-10003457796462437584], [352731723000101730], [3807561697580393544], [9605809694571481362], [1155880902462658018], [15408566150204655312], [17410405260649145316], [-16802974031724281446], [12082689563400779154], [13064328531515147340], [14414036895378228330], [-5290193597767838876], [567534879035334024]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_192_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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