
// Make newform 38.10.a.e in Magma, downloaded from the LMFDB on 25 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_e();".
// 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_e();".
// 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 := [2105804, -155839, -8016, -2, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [-62941, -12893, -47, 2], [3970, 57, -1, 0], [-470801, 22001, 179, -2]];
    Rf_basisdens := [1, 693, 21, 693];
    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, 0], [57, 0, 1, 0], [218, -1, 3, 1], [672, 20, 9, 1], [29748, 75, -121, -23], [-1568, 275, 238, -48], [168631, 20, -2050, 164], [-130321, 0, 0, 0], [724276, 885, -7382, -286], [2073202, 550, 852, -2317], [870276, -9775, 17818, 1575], [-261758, 59215, -20754, -2407], [2148182, -68935, 39302, 6677], [3472138, -40335, -6087, -12765], [-9150076, 15365, -132675, 26833], [-28392182, -211250, 200314, -5549], [-99211973, 255595, -37063, -23037], [-74655920, 201455, -215807, -40083], [-28773199, -305650, -770537, -58278], [850912, -669390, -627986, 94124], [33945965, -709870, -207296, -55158], [17015018, -62905, 402324, 39373], [343756056, -199770, -740496, -59700], [389375140, 1442325, 144650, 16075], [244332850, 247540, 756606, -183388], [-266844866, 588790, -3116060, 976246], [-317972322, -2204270, -5058048, 238154], [213632881, -949735, -2239589, -1181955], [-305575994, 1605440, 15038, -1105009], [319926484, -8971065, 1190848, -647677], [417922934, 4487505, -3303254, 2055599], [2712942110, -6725075, -4367837, 903487], [292882515, -5148130, -5937410, -1322934], [-950554686, -4189295, 20491245, 578447], [-3383382752, 2444385, -14296501, 2138173], [3052683382, -402020, -15331436, -1640936], [372300244, -20705560, 1547826, -719546], [5090414854, -202670, 33238018, 2861308], [4709133370, 21669075, 61800278, 3421939], [2084059208, -21458410, 71987794, 8336256], [2402457590, -24523975, 42989806, -9803859], [592783148, 5141990, 105904754, -4727128], [-4836969740, -18014410, -96578619, 2470855], [5322503678, -29236295, 67481656, -681197], [-4695347432, -33849750, 11565262, -8475118], [5247076784, 48904230, 106596153, 1191555], [23394669003, 7309795, 153627381, 7236959], [25110951040, -63426895, -41695532, -2009259], [-19869659537, 47696685, -182295513, -5069223], [1513136960, -11924985, -71274033, 35602917], [-47797240558, 43916935, 154134247, -20986409], [9636813628, -118350650, -188124487, 10651647], [55596025018, -66414375, -51407538, 3482625], [47269644638, 115349885, -338232609, 11913709], [-12744915362, -141460390, -317335394, -6290004], [-44852853972, -75432825, -62841483, 38656359], [-28649906730, 357603985, -10408836, -546961], [15402255128, 167903115, -70294078, 37072480], [-17814504026, -59776545, -16543095, -11073327], [16608353980, 50067090, 278111358, 25025622], [46615874088, -124080675, 512473935, 38135787], [-92475559864, -95961785, 178549726, -2924978], [52043473122, -482668875, 204459444, 63723861], [52097393808, -270401760, -679553717, -28475299], [-62974207679, -196027615, -253861793, 26575713], [-62241374080, 264685935, -48244304, 83559902], [102984863827, 423260400, 917145217, 98069192], [149475451558, 446480040, -860350878, -6615978], [-150662712742, -599905015, 492069059, -31083031], [251186146608, -245005055, 261846775, -174696161], [-174271931183, 451576445, -807386821, 189984953], [251019852968, -302727590, -703140227, 64013497], [112169039468, 1572623420, -243846052, 133845068], [-96242882240, -605261445, 28417990, 12210278], [-34979182465, 1267216385, 959152573, 64101873], [-252090181596, -1293637215, 948858562, 120835877], [224099562490, 1414512195, -2263333825, -159999125], [238607756082, 498329855, 3477759425, -65849983], [316779591106, 282967735, -1774293336, -205374049], [-433555772728, -230589665, 766023050, 210834921], [-318922004798, 224812150, -433520194, 255756612], [-361168159218, 1812547230, -671463694, -357647069], [-355543151492, -984049800, -781154908, -129832430], [-185871695478, 1041088425, -184539454, 74205775], [-468047566, -1940727005, -340749402, 305904395], [118301944108, -1510284475, -2232323943, -196222961], [12296523052, 1012582580, -786123372, 584509954], [75970268333, 2453307770, -3056382150, -609046730], [-317771878756, -2446917545, 555040839, -321509785], [-297359689028, 3313321745, 927421665, 265472209], [821078643998, -157451455, 4139557031, 32139221], [-598579217196, 1238566800, -2484195632, -665414680], [85288558558, -703824790, 2670029196, 509173966], [-445523031976, -1365640610, 1611032904, 331719710], [-400274188386, 3293100845, 2631444943, -65261325], [215642481928, 3085081375, 1131887294, -288952524], [639928374272, 2690193640, 241184872, 618641818], [547140286926, 273860585, -6504793132, -558870235], [-977110803235, -3591958565, 3287219451, -45261901], [-398427241666, 4970856915, -6155311413, 585525423], [858433243376, 202461180, 12214547348, -807970088], [1412110083106, 7941384455, -11545714035, 685946389], [-153853806018, -2203339465, -7054513062, -787447973], [-1786886437860, -4407927220, 2581326820, -651452760], [-1413655024632, -7855853520, -497763268, 340475140], [2386302966695, -2480319770, -6490218792, -834684706], [-2249416823608, -275044095, 13004997397, -583602451], [-655784173274, 7192154310, -8878646340, -1309579794], [-105185170842, 1032021285, 17891671320, -2063438571], [-1778016978846, 6393470110, -3499339748, -1148388512], [1312961097872, -342277110, 9775240812, 1213550424], [966846724986, 7465739035, -10593002699, 2000372527], [3203099973690, -4472690665, 3944257701, 221573827], [4172860772702, 2936524380, -633980818, -236836292], [-123411406196, 2241145645, 18125913823, -1548101651], [454261558588, -2871456780, -5725544332, 907859506], [-1035447717502, 9110702565, -2532282379, -2190000767], [3181899430784, 10709818290, -15159779103, -211236825], [756829873034, 8501756665, -961754723, 2018215867], [-1683739305687, -9299937535, 7376710847, 1614346961], [-3540864412872, -16908587215, 16941835822, -965493900], [5373154821488, -11485474710, 8537306970, -880019658], [-3076407491818, -244104890, -9700856296, -3369432519], [1447845422756, 3178007150, 6300445460, -3657191494], [1785151684746, 11649602275, -42243406029, -1811139637], [-2112179338068, -11282922980, -17200276798, -2909441328], [703862817088, 35783789140, -9782492710, -446318526], [-1461651363544, -5672553920, 37403971817, 5012554725], [-1822856387944, 1351723310, 11394923471, -4993528105], [-102825284134, -15790945500, 19916710720, 5738846126], [6393828070000, 9116088525, 5154137191, 768643601], [-888002112912, 33685484685, -19404669334, -1570314377], [-4253733822268, -34603980950, -10157259744, -2001090574], [-768082423928, -35820204675, -5318822931, -838036869], [-2282070079997, 7069217830, 22693326722, 3595873350], [-5229896707607, -7848935450, -31962322398, 3290571746], [-205044056560, 10540358975, -61139415452, -2952524694], [4419016921699, 14256535235, -42692796513, 5685490015], [-3312851763486, 24346166350, -43873928214, -7677217441], [8681515879041, 10037313100, -28929105954, -5470764016], [-1726752044027, 19626008485, 51619232381, -3172080171], [-9669571594470, 32498684275, 20869122681, 550386425], [10641089335428, 25076538430, 38314482089, -2214507939], [4825378178185, 22587017840, 6693542611, -2724418548], [-93669673676, -23710254645, -49815307642, -4939382570], [2371307351078, -11459701140, -21703741104, 2135528850], [8456847424366, 38414510010, 43817448944, -4790806190], [8406906800264, 16214078860, -89022923150, 9069321748], [12476369101128, 14237276285, 13150564579, -8710964697], [-3897179790474, -38548736705, 96840230886, 4602101597], [1720190953188, 30472260815, -30028860800, 6139835010], [-8109452474998, 45253006435, -40964808863, 8841901627], [-6028622471754, 65243294935, -13209926591, -10028070545], [12382608351096, 2373944280, -65108889770, -4109916166], [334400193159, -81894588340, 67708426049, -4470026788], [-1756735765898, 9078593670, -63131224420, -14044017320], [-12309967925180, -32200672015, -16886113130, -4728153180], [1007392790241, -14298603815, -18467610793, 5397924645], [9552401253253, -32714388630, 31594319920, 8342323370], [7248982438648, -24098186065, 153862987320, 10406472808], [-408731069670, 17049864080, 23401064850, 18819246766], [16150565618362, 1482836715, 143170774756, 10571382965], [3853250885232, 51018295500, -118392946152, -245580060], [9592341156756, -36951110800, -29331619936, -24983892064], [18709580995352, 77526555915, -10442364978, 10217279889], [-18781520220456, -64289507610, -38124058512, -12298140852], [3596605017296, -39023946195, -78779369428, 8039992339], [13644069665814, -34930866165, 176454089461, 19999729709]];
    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_e();".
// 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_e(:prec:=4)
    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_e();".
// 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_e( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_38_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,10,sign)));
    Vf := Kernel([<3,R![-337930956, 8791740, -39131, -226, 1]>],Snew);
    return Vf;
end function;