
// Make newform 38.10.a.c in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_38_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_38_10_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_38_10_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
        poly := [85948, -4552, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [-1, 3, 0], [-3043, 24, 1]];
    Rf_basisdens := [1, 1, 3];
    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_38_a();"
function MakeCharacter_38_a()
    N := 38;
    order := 1;
    char_gens := [21];
    v := [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_38_a_Hecke(Kf)
    return MakeCharacter_38_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 := 10;
    raw_aps := [[-16, 0, 0], [1, 1, 0], [162, 2, 1], [-4439, -14, -10], [18656, -386, -43], [52727, -204, 67], [-209697, 858, -564], [-130321, 0, 0], [-308209, 5110, 3289], [-3279673, -13893, -3628], [454876, -29685, 8839], [-763030, 3757, 14761], [-4299860, 13925, -15333], [-7459546, 106246, -9441], [19632122, 15016, 44215], [2923543, -299391, -106356], [5475433, -71558, 55609], [-42281260, 143100, -21479], [-96025103, -461027, -162254], [26040758, 583150, 105562], [-185980615, 492830, -464234], [-106740674, 517415, 65849], [143497154, -44200, 330414], [145896548, 2108807, 726611], [-128317382, 2792874, 1872892], [63206202, -1578298, -1518942], [14382666, -1978098, -160922], [701376663, 8546018, 111947], [-189450263, 6298789, -2035626], [599284838, -2527559, -81323], [-1055878666, 9702419, -8215417], [2357040130, 9142084, 1871763], [1255608491, 30254436, -990382], [1506545594, 20379734, -236249], [-3584748498, 21210474, -2393605], [-3903756678, 29215636, 3939324], [-3888443782, -59480408, 4917044], [-12099671668, 18036498, 8767866], [4061040648, -44520441, -2588431], [-1977733290, -54713586, 18608774], [6432373412, 66851909, -1671925], [-13638580142, -10146858, -6101754], [9714882821, -99776424, -33306236], [-5597475446, -47498267, -29224185], [1118523412, 108097380, 13369438], [-26346755, -21718648, 18852396], [785723773, -243986654, -35717591], [-2240989218, -51294221, 12781219], [10435948261, 27020978, -49974825], [6324344452, 17585234, 37438593], [-30205274048, -58135676, 19412397], [3598984437, -343131132, -1555388], [18124973420, 417513721, 19877619], [9247503720, 110448302, -87925217], [-6068739396, -196439650, 27247730], [31294863738, -85899414, 149586261], [22951469766, -486635211, -101549833], [-49800135785, 241657656, 3479467], [-74482243794, 613473368, 115106913], [17608324756, 105384488, -46732626], [-23783460520, 285781100, -259385781], [-161183049111, 221859930, 34759587], [127692137172, 482171883, 90454743], [18363530961, 86784856, -130900406], [-53132048477, -530654614, -16612085], [37582829129, 733939772, -200887397], [-24309444461, -857466103, -1211392], [-26439908452, -1002161672, 123013284], [-87946226100, -52650266, -429362685], [-317934531432, 79970744, -143641185], [-204741153449, -1450326218, 188442135], [66951417143, -189404278, 812790348], [-342568887852, -784496992, -145467084], [-129636041411, 354940706, 285805991], [-303316102975, 176875880, -510860837], [-58012419342, -794953631, -684610685], [-36397809864, 3460532784, -56058439], [47333145418, -3840192832, -524395167], [479310628368, -315799427, 247470461], [348165152592, 2862425993, -702704695], [358272986308, -534318626, 1307497294], [742945361659, 440897033, 196680988], [207984187710, -467502858, -1491162964], [-155197637758, -380385717, -918321329], [-104625942296, 1428502607, -937655855], [-282365419416, 579049258, 1030354651], [152353608362, 1942528398, -828073592], [443521092173, -1661072460, -1059411274], [903427737578, -894750596, -39471835], [-272517513106, 3251830084, 2479117475], [-1473762135196, -3254274474, 96392355], [-763085477620, 513075576, 98848], [201900580118, 1210703950, -1354740730], [-801669401340, 4354182050, -1142113126], [1425983491974, 5561725844, -58283669], [-1639630966833, 1081951008, 1052455927], [-1550497648230, -820499166, 1115225676], [-861999612716, 8538177027, 2768697675], [1321917097115, -11067914100, -2974499159], [708574509440, -11838713808, -1983480639], [-1813407140780, -7496518524, 2218077772], [-2274387652698, -11835458624, 1210431553], [522137630824, -3794211989, 4532010229], [1631361237888, -8530096700, -1545380836], [1359970199084, 7075255056, -2490648632], [-1459214231973, -14519035262, -2629496702], [-776380094250, 21380102748, 1551127411], [-499663081334, 6799694102, 448464834], [3793686313768, 9984634159, 354694215], [373415277672, -15592670152, -8447808546], [1108355394506, 19885976472, -660442470], [4353164889780, -5533325734, 2063500281], [-544313156188, -7956468706, 2437342309], [-1144594304570, 19390784562, 7685521636], [-232479951546, 21447393430, 560822391], [-82192101622, 6237921278, 5547984296], [1844244283784, -18467830136, -1177204913], [-2053861559683, -12709173668, -8330928912], [-2546638693306, 5322196970, 9632298159], [-2010516093669, -15349983862, -5176586085], [-3317580404663, -3482960940, 4657446985], [-829574549280, -80156876, 3593166150], [-417889330983, -5599368971, 8730496240], [-1086238598932, 24312832218, -8030699886], [1754643796968, -9115146852, 537658513], [-3660710610312, -11680527910, -5739778484], [-1290190999986, -29392654428, 252249656], [860492039553, -13212394322, 6254185162], [-494654490815, 21005590482, -5161220820], [-9018251688316, -12084515146, -5759255392], [3689235929214, 6727168810, 11642929991], [5200626413860, 19988291715, 10973063939], [2991708452656, 30278893814, -88949762], [-13100038187912, -12477958350, 2946430179], [9887906081711, -37674895132, -8185628990], [-5654663424639, 56329234016, 19060953850], [-875669635483, -9038584132, 7060426019], [-10898648208667, -18281019092, 1622665289], [18883872427, 17800634077, 24793695332], [-2863825082435, 42146143174, 18027741644], [7961912540015, -35730345484, 6873013223], [1722643901998, -64881108296, -16932836251], [10079442955867, -7849912846, 29861470280], [10688996700973, -17587136769, 22267569800], [-15776483528207, -69517322702, 6012955927], [-8571638075380, 3654527098, -23366783952], [7310168405258, -9398516458, 6779089630], [4366990512376, -24084723074, 1049656980], [-4841382497148, 38727291932, -6474667517], [13077452640994, -20743501367, 15484654721], [-11775301082623, 30426656464, 12712676611], [15771533523464, -11643098950, -22743107727], [-10396588287556, -33844047818, -22611089139], [3050358071922, -65211362624, -7378497908], [-1373593025385, 24938868373, -1020550044], [3972333121788, 115620184176, 29633325062], [17820221460261, -41193465236, 20936058313], [24212072142927, 14655616118, 11143332715], [19256532864713, -46441220754, -17802581794], [7028170577859, -82161739586, 36552324607], [2823899648720, -39207061456, 31612657180], [-19227884039894, 106700119719, 17516294701], [-22988100415104, 40121743812, -43786093020], [15568009115172, 108919976288, 12718545840], [2119435959940, 123817269261, -42836950011], [-15877420828894, -191779342168, 17591949150], [-10887973430464, -181117114511, 36167714251], [16151937549030, -41324194120, 68499011909]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_38_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_38_10_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_38_10_a_c(:prec:=3)
    chi := MakeCharacter_38_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 10));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(997) - 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_38_10_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_38_10_a_c( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_38_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,10,sign)));
    Vf := Kernel([<3,R![2320596, -40968, -3, 1]>],Snew);
    return Vf;
end function;