
// Make newform 147.6.a.k in Magma, downloaded from the LMFDB on 30 December 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_147_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_147_6_a_k();".
// 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_147_6_a_k();".
// 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 := [-62, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    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_147_a();"
function MakeCharacter_147_a()
    N := 147;
    order := 1;
    char_gens := [50, 52];
    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_147_a_Hecke( : Kf := Kf)
    return MakeCharacter_147_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 := 6;
    raw_aps := [[-1, -1], [9, 0], [13, 7], [0, 0], [-569, 1], [-458, -9], [236, -148], [-1142, -27], [644, 308], [-1131, 45], [-1763, -768], [-9982, 855], [6852, -846], [-364, -2043], [11278, 604], [-14951, -1751], [-22507, 3917], [-22298, 2544], [17612, -4461], [50346, 1404], [16912, -5247], [-12649, 6834], [-31539, 1899], [-14726, 130], [4387, 1017], [78086, -12304], [15298, 17337], [-56059, -4567], [-83620, 27], [-105708, -8766], [-23011, -14382], [64237, -13889], [24730, -1826], [-142244, -4869], [24170, -22786], [251549, 14865], [-319112, 33378], [-452548, -3024], [109110, -17748], [72694, -14426], [-372944, 27418], [-272738, 41715], [-223804, 59102], [-303823, 34302], [78606, 113670], [485164, 47268], [-701578, 39186], [217849, 103005], [-259009, -35047], [-203798, -38049], [-225664, -16510], [540528, -20106], [684379, 122421], [-790947, 87345], [629446, -37856], [802870, 7282], [168635, 113477], [-821393, -37989], [-1144702, -100515], [21126, 60930], [-1047932, -187941], [-78909, -63297], [1884922, -63945], [2323604, 120026], [1765939, 127626], [-1449163, 43001], [609782, 82929], [-405631, -329508], [1207348, -348428], [1230574, 205920], [-1970188, -214498], [-813634, 327002], [-853721, -180420], [2121014, 168927], [-452374, 268281], [698854, -394166], [-1418474, -168236], [135982, 273501], [-426496, -239020], [-1265795, 719970], [3919260, -412650], [1187708, -358965], [30328, -406778], [634192, -41589], [-2751233, -190821], [-2801665, -274609], [2624364, 49734], [1461227, -382074], [4861914, 237798], [527498, 549585], [697048, 463018], [-385234, 80306], [-1572571, -744264], [2872311, 32463], [4279772, 291525], [3038508, 764262], [9465043, -74855], [1896662, -308902], [-3594410, 1467], [-5973004, 95895], [8589668, -13680], [-1558757, -1056335], [9720389, -295549], [440612, 56726], [8500004, 187221], [191377, -1417320], [10159755, -385713], [-9654032, -729806], [-651818, 1778650], [-6231083, -167004], [3288715, 32376], [-10170280, -424098], [2270850, -1046808], [-662192, -976047], [-2045869, -578169], [-16278410, -46610], [13998808, -134577], [-1528558, 1549688], [-14971405, 213509], [-2174784, -1088460], [-4900796, 321531], [-18586831, -46710], [13329253, 753085], [12172633, 488425], [-17853890, -189849], [-1868211, 2006073], [3729830, -255480], [2993542, 1808608], [-12077051, -73098], [-6488768, 1144569], [9053612, 5409], [-15295602, 775152], [-11006575, -2036406], [-11641174, 888336], [10243624, -1174088], [-1377665, -1713258], [608654, -416380], [21432862, 995694], [5515149, -1624383], [485332, -44546], [-6629582, 815130], [5478533, 163007], [6435080, -1435920], [-8722629, -1533303], [-20382506, 135855], [-12009252, -1520712], [-1992848, 3709179], [15600926, -1475002], [7145566, -4006338], [13707218, 255524], [-2765068, -1447950], [-4979466, 5011686], [18341570, -393039], [-18362480, 65842], [-3841138, 318453], [-451230, 3324258], [13402394, -283743], [-21943970, 2108908], [-11838251, -3067452], [-20475547, 1621613], [-6806188, -1941166], [-29856618, 37746], [8516303, 762678], [7343359, -2720705], [-44564294, 1933468], [-21928804, -449416], [34046567, 1262700], [-1249064, -2599125], [-9617101, 2987046], [-25928483, 1254553], [-3149147, -1173455], [18590086, 894996], [7818080, -346660], [4283693, 2531976], [-49171409, 2224374], [-13337988, 3282732], [35452220, -3340269], [5755975, 3100945], [24149176, -5493240], [-42077048, -620769], [-9268357, -1057956], [-9712965, 985455], [10949444, -1200789], [6856810, -2888906], [22693246, 4939360], [-14849863, 1321505], [2886218, 2968524], [26219152, 6051045], [33102335, 2317326], [30794060, -445486], [55480159, -2558304], [-27806703, -3375009], [40173632, -2310696], [66537334, 89866], [-48645137, 3451927], [-55919338, -2118634], [23931584, -704607], [-74178382, 1315092], [35298258, 5991876], [16053730, 150574], [19520611, -11217431], [-35256074, 3748023], [25052722, -7846008], [4166974, 1298640], [7749900, -8606034], [-111387913, -2155], [14125096, 9575640], [-13006759, 9257411], [78677940, 956952], [-66290786, -422958], [-20903860, -3860703], [-6031419, -7027191], [6344213, -613107], [18657307, 4350907], [-14208064, -6376300], [-11132924, 12231591], [-84641113, 669819], [-29949532, -8828704], [19477586, -5739754], [-16865022, 4239576], [18854066, -3563283], [42763690, -6235443], [67747442, 6269744], [3499073, 4923909], [-10654053, 7304949], [4438076, -10471590], [4249342, 10289998], [-132062312, 685498], [60383317, -8720382], [-18051544, -4237606], [-12694132, -5088777], [-1084040, 2877588], [360719, -13322574], [53205946, -6501620], [10203376, -11983149], [-6944020, 19910330], [-89759135, -3867810], [-31387273, -4515691], [-45831900, -7401960], [30710880, -923994], [83399488, -2819258], [-68079158, -7811019], [47603971, -10748838], [-47743174, 2461932], [-77898840, 8717184], [13797100, -4472000], [-31167191, -3315582], [3345824, -11656762], [-33148576, 1547544], [-49876488, 8690976], [-114315832, 8713827], [-182788742, 1134778], [-117671222, -3647684], [-342536, -11181303], [-103898401, 9038771], [-21542389, -11583625], [-13037788, 3469203], [-29661758, -9773385], [-52878789, 2287521], [71112385, -12034557], [-1209862, -12972387], [-48151401, 9612531], [145403092, -7484727], [-54345890, -15566967], [86509334, -6541324], [94669492, -2983881], [124865991, -4598991], [-8775372, 17929062], [-31092436, 9608976], [-9490025, -8183243], [-28409582, -3802731], [27510002, 13483062], [-60841709, 19407576], [-40098787, -18244128], [65039833, 9896391], [3088072, -13790628], [179323241, 3862343], [127168154, 11998995], [-15054400, -23023431], [-71347904, -2880872], [100564130, 5932802], [-218845117, -1515210], [-175301292, 4956210], [137030206, 16822557], [-96590846, -21118362], [-32770888, -18357538], [-104095909, -5313078], [124874007, -9244683], [-122429249, -3619122], [-66258864, 8746218], [-206416190, -8474138], [-120804973, -2203861], [-31869400, 32618522], [47986068, -14036904], [-9519322, 31737699], [-70837783, -9294829], [-151289150, 17715705], [295207710, -6312726], [192213664, 13738810], [84020692, 440577], [30787738, -716280], [-234798001, 5156105], [6684299, -1724013], [-225605577, -8422425], [86052080, 21855561], [10173080, 13395735], [5328043, 11229553], [46514116, -1847259], [-11712946, 34061366], [-196195240, 18060237], [86177746, 18231094], [-159280094, -15852848], [153953972, -25528366], [75687920, 22313136], [-14453820, -19257156], [-68831612, -7649703], [-129572751, -6456069], [216487420, 3429484], [-306955517, -7097148], [161233836, -28272150], [-230011550, 15829977], [60935636, -22738071], [-33477849, -8095167], [23075066, -31062951], [-102242252, 16685830], [-10477727, 3212082], [-33340960, -25433829], [120275788, -8615253], [-17655886, -32905018], [92782611, 4257657], [37573412, -11604525], [-298372097, -17308667], [-283974710, 462969], [57207116, 46752434], [32792444, 2714643], [-21895920, 38628846], [28604540, 13262490], [33589390, -40909502], [74570815, -2593548], [-288178685, -1183878], [-19887508, 25037853], [28567704, 33622200], [55912755, 51531111], [186689669, -28856466], [143011025, -366193], [-130327011, 16446375], [36724348, 35207901], [-75400762, 44478498], [237996978, 30562524], [-63573185, 59164285], [176252560, -2523228], [189112697, -28806813], [151484442, 12844368], [53653933, 36847281], [-202566580, 5824365], [-135586890, -5855976], [227441902, -28267256], [142984109, -32713627], [112378244, -57853276], [-8594862, 48554064], [-511205314, 7006644], [264710332, -4490918], [174928390, -47790500], [-213785056, 48513194], [-147760442, 29930193], [376748177, 13766799], [80119050, 15218586], [-58282930, 59663943], [356321675, 3397689], [208092805, -20749643], [-453016070, -5968863], [-212376262, 9035948], [-71370087, 1379583], [49608694, 31702983], [-268235722, -5420187], [238695752, -10990528], [163433592, 22334400], [-148520897, 28314873], [-172036874, -19950206], [189504364, -7642863], [-78890434, 56706470], [95076834, -13030002], [-22051888, -71581824], [62000800, 12621988], [207962830, 17843130], [-26520622, -43454650], [442048202, -22575], [-409896296, 19350510], [104166026, 11216025], [-164166108, -56351250], [-139295119, -30081528], [-395089118, -28339568], [47110471, -44946545], [130908208, -73109595], [167648930, -40279996], [-236876419, 44076711], [17848189, -22327155], [-423418134, -2305764], [125741438, -6388839], [-207882785, -9172019], [169871740, 24875058], [61466708, 42791000], [-277071172, -17784876], [-186061262, 16083484], [640351811, 10497929], [-76345181, 39167046], [-216072802, 21234192], [16013694, 36977058], [-159255296, -21455985], [28851913, 31515769], [145509475, 13497873], [-48275569, -57549961], [47122785, 15212637], [-51585142, -66680106], [-477635680, -636165], [-120160037, 21890281], [390132128, -46453486], [414282106, -44119311], [-629597916, 10545552], [50295946, 34404370], [-145621937, -14498981], [181812520, 35523063], [-110603922, 16421742], [610115421, -38878929], [-573402098, 34934004], [-401428186, -36791296], [-35578135, -13347001], [-403633908, 7833348], [189467974, -38460006], [-177740404, -23444812]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_147_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_147_6_a_k();".
// 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_147_6_a_k(:prec:=2)
    chi := MakeCharacter_147_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_147_6_a_k();".
// 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_147_6_a_k( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_147_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<2,R![-60, 3, 1]>,<5,R![-2778, -33, 1]>],Snew);
    return Vf;
end function;