
// Make newform 192.6.a.r 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_6_a_r();".
// 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_6_a_r();".
// 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
        poly := [-31, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [0, 16]];
    Rf_basisdens := [1, 1];
    Rf_basisnums := ChangeUniverse([[z : z in elt] : elt in Rf_num], Kf);
    Rfbasis := [Rf_basisnums[i]/Rf_basisdens[i] : i in [1..Degree(Kf)]];
    inp_vec := Vector(Rfbasis)*ChangeRing(Transpose(Matrix([[elt : elt in row] : row in input])),Kf);
    return Eltseq(inp_vec);
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 := 6;
    raw_aps := [[0, 0], [9, 0], [-18, 1], [-60, 1], [100, 6], [-142, -6], [1338, 6], [-36, -10], [1920, -30], [-5106, 19], [5244, 5], [-6574, -84], [2082, 50], [2916, 130], [760, 198], [-4506, 71], [27548, 216], [31722, -48], [-18396, -488], [18832, -438], [-18918, 552], [72444, -295], [54636, 222], [-16278, -572], [34546, -60], [-106698, -801], [79692, 1311], [45596, -1212], [-12446, -1338], [-44862, 644], [-85356, -1489], [-163292, -912], [-98382, -330], [28812, -4592], [-178914, -2319], [-126156, -2367], [220666, -3876], [-71844, -1102], [193528, -840], [-7146, 1077], [-665580, 72], [623962, 1998], [-127488, 3288], [16530, 1848], [-40890, 4027], [306492, -3733], [490548, -3928], [-868476, -4853], [151788, -5670], [-280550, 5490], [-234342, 9876], [423168, -3588], [584242, 1764], [791892, 870], [228354, -20032], [872472, -2976], [-380226, 8643], [-215820, 627], [229562, -10914], [1257306, 1248], [917436, 4096], [-871626, -3033], [-756204, -2184], [-837096, 11172], [1642, -29592], [2211582, 1095], [-979908, -6140], [-1841086, -18552], [564596, -24546], [-1155958, 13584], [-1503630, -16124], [688496, 17610], [-132084, 29037], [-323150, -2376], [-4028220, -15802], [-751136, 12048], [-1459698, -18207], [41882, 33336], [1650762, -25502], [674794, 9276], [1545676, -17886], [-1546646, 8718], [1143528, 1626], [2480434, -19128], [-3184164, 1351], [2681172, -16050], [5632266, -17906], [-3267910, 31956], [3915414, -3], [3273492, -35077], [-883460, -49758], [-1108200, 49626], [1406148, 1273], [-4165316, 10068], [4696596, 20256], [2057088, 70242], [939774, -24177], [2649474, -48774], [1653204, 40278], [442034, -87522], [9223404, 654], [8997030, 27577], [2380908, 77310], [4087602, 6002], [6202188, -64732], [-8756718, 37896], [7378428, -33492], [-6556638, 40068], [-8362352, -90354], [-4509590, 4320], [3309972, 121223], [-5268510, 75888], [-3730230, 6072], [-4304724, 69912], [-11824044, 33329], [-477174, 15574], [2381292, -42234], [9912144, 48594], [-8284410, 14225], [8125380, 63324], [3185794, 184572], [4891394, 181968], [-4618242, -111019], [-11681580, -22878], [-2330580, 87602], [4937214, -173577], [-16266886, 40914], [-9041672, 57270], [-6709452, -219471], [1867810, -174], [-12381516, -124204], [15861480, -144516], [-1667076, 63665], [19851978, -8334], [2783298, 265062], [13328242, 68304], [-8039418, -175149], [-16013460, 16098], [31134294, 27537], [10374162, -16826], [4879428, -30910], [-14185770, 979], [895812, 202789], [1917196, 269964], [2224210, 199974], [-5419424, 12006], [13474722, -161004], [-21277230, -99854], [-2349852, 158638], [22692832, 177000], [14594330, 42648], [-5418030, -204072], [11052876, 46234], [-4593432, 193776], [12256500, -336250], [-23011584, -94476], [-6015900, -114891], [29878650, 25194], [-29856886, -41136], [2869974, -370987], [19878420, -137688], [26200434, -274566], [45158988, 3735], [-12540908, 170586], [14512938, -241510], [-11232024, -406152], [-24014772, -58351], [-19311390, 261288], [6836578, 206316], [-17329650, 28661], [-14655444, 247212], [10218042, 384804], [46644488, -183876], [2204458, 163392], [-46909716, 146221], [-1686630, 68608], [60930492, -10400], [-9372786, -63999], [32118060, 72055], [-33652534, 104940], [-30793908, 46265], [-18749060, -153978], [51290234, 189594], [36107274, -49936], [621264, -82896], [36949134, -446563], [-18057150, -524502], [16927524, -504968], [16140554, -354636], [51922944, -106704], [16882210, -599736], [43237516, 388464], [37360116, -364592], [-9246090, 640913], [-21369340, 418608], [-17084982, 296424], [54032770, 378168], [-44521246, -312054], [-14768382, 934664], [-34520, -58500], [-20441706, -841083], [-11129580, 518555], [-21163814, 583854], [-61755246, -542376], [-47140940, 284034], [-43628034, -31569], [24620724, 515479], [33908828, 358086], [8579418, -730100], [41469108, -659594], [-18226750, 218832], [-20698674, 269829], [80116380, -60849], [33895644, 10656], [-15105344, -225690], [-10001334, 959256], [109258236, -27007], [-20710374, -634154], [-71771896, 39528], [-11917818, -676683], [16712554, -930042], [-46935108, 437807], [16409850, -214806], [65107764, -839741], [88076652, -106194], [78281602, 421884], [-37119606, -430692], [-61903080, 884346], [64697436, -349829], [-47429828, -134700], [49160354, 407766], [-35042820, -179618], [-1488252, 1684243], [-32812566, -52248], [-23562060, 859174], [53203208, 626994], [13123778, 758844], [4750878, 203649], [-31056732, 1163802], [-637072, -1570302], [-42461076, 432654], [-49501140, 1244628], [19740132, 64377], [44928810, -1221756], [-57744846, -779168], [-68337040, -1036194], [56650908, 815629], [3698580, -1415868], [-27358692, -897724], [67655488, 1059108], [52808466, 217974], [77757906, -274492], [-93993552, 642954], [-48107958, -1118760], [-31448418, 805843], [-895548, 879492], [-34133094, 238590], [5017836, 709316], [16453254, 891459], [177969562, 221496], [-42783660, 775279], [14895588, -1727928], [108505162, 1002726], [98260442, -1151004], [115310970, -974526], [-155272524, -55396], [24306822, -764287], [-19794486, 961244], [-26520012, 1577146], [10204590, 936849], [12003514, 1311336], [11086212, 2483036], [-92910982, 651168], [-62930292, -1651455], [72650674, 94752], [106616220, 374871], [-23655452, 213018], [26970058, 2463264], [35715418, -1467120], [-168517756, 535524], [84652824, -1537638], [-109938324, -1040905], [98904208, -1958394], [-57528990, 361368], [-143100252, 482114], [43173120, -1253460], [-118100558, 68604], [-60598098, 437581], [100476180, 2052649], [-166119822, -54332], [-4120986, -989391], [113627508, 930768], [-214012758, 1021404], [70225100, -201264], [26276394, -1704420], [49214982, 2987997], [-147149388, 1790431], [28316070, 1933839], [54423300, 1044834], [-166345860, -525398], [38413018, 1163520], [-6381882, 2052193], [150660300, -1219003], [265760596, -739608], [145395732, 1496834], [-9669086, -2054460], [59314308, 438726], [51892530, -2869734], [95101104, 617958], [-18197438, 485424], [-50232528, 2044200], [-79492794, -3224785], [192965322, 1607102], [-32433492, -861226], [-156531480, -538236], [-190087766, 1463256], [-234173244, -1189932], [-90253144, 500622], [-70147598, 1214184], [117632034, 2216796], [193720596, 358776], [213178154, -87840], [69691662, -1472189], [136908348, -3198875], [16868706, -1285230], [249192706, -1989948], [-239929716, 1389510], [-72790092, -866742], [-72310240, 1129008], [174659502, 476225], [3680834, -1272690], [254100486, -136595], [-136651164, -331573], [-74412460, 3179676], [321779052, 720680], [188336356, 190770], [-83691750, -2283228], [-104168334, 1304380], [-120827302, 667632], [167566788, -14793], [-100900862, -683292], [-9774510, 2775826], [375445974, -981481], [-92812548, -2468549], [-161050434, -2114345], [70161468, -3655482], [118880826, -586494], [-167960100, -699932], [-277160, -566778], [-113071146, -1013045], [107481468, -1567286], [-99103558, 2831844], [20665230, 4046327], [25867044, -2133225], [386414754, -228876], [-60825510, 988824], [-228214224, -70764], [67770972, -138612], [-128666406, 1772702], [308849720, 1513164], [-353817646, -771852], [-219004134, -3581532], [170137328, -3324072], [10601188, -1154142], [86688948, 2766692], [303490426, -1689024], [315420990, -954213], [-309808908, 2068501], [156908314, -2137056], [-378071316, 1464834], [-273065484, -38026], [313559856, -2128344], [-535178682, 983775], [-48796140, 3468049], [-198146558, 1445250], [392071692, 518142], [261657632, 596856], [427374626, -1370880], [-312815382, 2776314], [-97836870, -4334820], [-415062234, -1624083], [-106409262, -4107658], [418290036, -3149183], [-32802462, -3232848], [923436, -2978642], [131793368, 1840752], [-107258820, -2506335], [487443802, -662802], [-306103620, 2562832], [221026520, -2881110], [385687970, 1429896], [-120094434, 2058317], [216477612, -1011984], [-94973700, -2199938], [-192342472, -3988164], [-95540214, 1231236], [271126932, 1853783], [197012994, -3033054], [297411060, -4326970], [-295970850, -4866719], [-74082646, 3316056], [-306951270, 1628418], [153824580, -4831153], [11187186, -6547398], [-502419114, 688487], [-116488812, -22859], [529323106, 2427510], [-131018838, -2805694], [-500515908, 1411494], [714972764, -554490], [250056034, -2200920], [153232302, 2263261], [121987668, 4166094], [-67341252, -2329062], [-572169254, 2239152], [161472606, 5033603], [268002752, -3245208], [-43240812, 5409421], [-252745494, -643862], [-547201904, -1118682], [-366160410, 784957], [157622386, -3412932], [-130061600, -3742068], [-451637340, 2368530], [498461018, -3240768], [401426430, 2942611], [-7291716, 5499042], [-118259382, 3246140], [493513092, -510170], [-455032032, -3612222]];
    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_6_a_r();".
// 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_6_a_r(:prec:=2)
    chi := MakeCharacter_192_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 6));
    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_6_a_r();".
// 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_6_a_r( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_192_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<5,R![-7612, 36, 1]>,<7,R![-4336, 120, 1]>],Snew);
    return Vf;
end function;