
// Make newform 48.11.e.d in Magma, downloaded from the LMFDB on 20 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_48_e();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_48_e_Hecke();"
// To make the coeffs of the qexp of the newform in the Hecke field type "qexpCoeffs();"
// To make the newform (type ModFrm), type "MakeNewformModFrm_48_11_e_d();".
// 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_48_11_e_d();".
// 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 := [531, 38, -37, -2, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [2760, 1732, -180, -4], [-840, -5444, -204, 260], [-176016, 3712, 9312, -256]];
    Rf_basisdens := [1, 31, 31, 31];
    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_48_e();"
function MakeCharacter_48_e()
    N := 48;
    order := 2;
    char_gens := [31, 37, 17];
    v := [2, 2, 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;

// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_48_e_Hecke();"
function MakeCharacter_48_e_Hecke(Kf)
    N := 48;
    order := 2;
    char_gens := [31, 37, 17];
    char_values := [[1, 0, 0, 0], [1, 0, 0, 0], [-1, 0, 0, 0]];
    assert UnitGenerators(DirichletGroup(N)) eq char_gens;
    values := ConvertToHeckeField(char_values : pass_field := true, Kf := Kf); // the value of chi on the gens as elements in the Hecke field
    F := Universe(values);// the Hecke field
    chi := DirichletCharacterFromValuesOnUnitGenerators(DirichletGroup(N,F),values);
    return chi;
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 := 11;
    raw_aps := [[0, 0, 0, 0], [-21, -1, 0, 0], [0, 4, -2, -1], [11278, -43, 5, -1], [0, 21, -189, -35], [68810, 860, -100, 20], [0, 4276, 2860, -236], [392182, 4171, -485, 97], [0, 366, -4590, -826], [0, -16812, -34494, -2947], [5446462, -130935, 15225, -3045], [-17753542, -244412, 28420, -5684], [0, 238792, 158308, -13414], [117672166, -291669, 33915, -6783], [0, -246700, -159940, 14460], [0, 81716, 437750, 59339], [0, 600237, 739875, 23273], [-296009686, 844692, -98220, 19644], [74341462, 2146431, -249585, 49917], [0, 478562, -803026, -213598], [1633567250, -1987632, 231120, -46224], [-49820642, 6895609, -801815, 160363], [0, -2981737, -651583, 388359], [0, 2016028, 5538400, 587062], [-9794088766, -3429508, 398780, -79756], [0, -29022964, -24778090, 707479], [-2767094834, 20158701, -2344035, 468807], [0, -14206175, 13117471, 4553941], [-5079939190, -1275036, 148260, -29652], [0, 24563096, 25070624, 84588], [-4529901314, -130675839, 15194865, -3038973], [0, -89552185, -83473543, 1013107], [0, 12444576, -72793332, -14206318], [-71403167066, -29345737, 3412295, -682459], [0, -25896876, 55506726, 13567267], [-76625787986, 164681013, -19148955, 3829791], [-30919534870, 460828764, -53584740, 10716948], [115761759766, 85214003, -9908605, 1981721], [0, -283642526, -43429250, 40035546], [0, -503503748, -377185022, 21053121], [0, -83474117, -299086283, -35935361], [60571129178, 676135612, -78620420, 15724084], [0, -264330248, -5472488, 43142960], [-33381474430, -1241531088, 144364080, -28872816], [0, 170924188, -71309258, -40372241], [30698724238, -291474683, 33892405, -6778481], [-314017714058, -579229049, 67352215, -13470443], [420669605566, -666094983, 77452905, -15490581], [0, 885991115, 106517837, -129912213], [695033891258, 1229619228, -142978980, 28595796], [0, 1382583644, -152449576, -255838870], [0, -10044428, 1056233596, 177713004], [-76175414686, -3465411968, 402954880, -80590976], [0, -1489662167, -1281791105, 34645177], [0, -2913294040, -457285336, 409334784], [0, -2637473630, -2855074034, -36266734], [0, -2225775364, -2338647790, -18812071], [1587999049630, 595568361, -69252135, 13850427], [1112878112282, 2097788196, -243928860, 48785772], [0, 3558130884, 2109254952, -241479322], [-658166758970, 5954437599, -692376465, 138475293], [0, -2115650772, -2481960234, -61051577], [1304508297526, 7174929303, -834294105, 166858821], [0, -3513008530, -3311517694, 33581806], [742181883506, 3566388868, -414696380, 82939276], [0, 6641546108, 2403527834, -706336379], [-1652588508122, -11037500537, 1283430295, -256686059], [2510294481698, 5911118668, -687339380, 137467876], [0, 9331805857, 8758190983, -95602479], [-4060246031254, -18640817684, 2167536940, -433507388], [0, -5404910544, -2095419264, 551581880], [0, 7363856442, 9232313718, 311409546], [9154963984222, -3459050247, 402215145, -80443029], [-2631334128934, -23182871908, 2695682780, -539136556], [-11443448578682, -1217258749, 141541715, -28308343], [0, 4370215976, -3523167256, -1315563872], [0, -22713497644, -11519198962, 1865716447], [-4950678330934, 22370707860, -2601245100, 520249020], [0, 22401364780, 24856628836, 409210676], [-6222369519310, 16261951216, -1890924560, 378184912], [0, -20503741133, -30039403691, -1589277093], [-2757232534726, 10581030124, -1230352340, 246070468], [0, -29585922076, -21499146484, 1347795932], [13958631539426, -24022716948, 2793339180, -558667836], [-2135655008018, 62603069061, -7279426635, 1455885327], [0, 51148254113, 43040781719, -1351245399], [0, -18300123564, -2613343308, 2614463376], [411256247570, 3713136, -431760, 86352], [0, -268512156, -670182, 44640329], [3470712244510, -58311004367, 6780349345, -1356069869], [0, 25777641535, 33219097897, 1240242727], [0, -14770744, 20561394008, 3429360792], [26541169644238, -54553018163, 6343374205, -1268674841], [0, -8221316439, -35245875609, -4504093195], [-7042617774410, 73434994983, -8538952905, 1707790581], [0, -45864077874, -54950414334, -1514389410], [0, 44911294588, -28149008198, -12176717131], [0, 93152753632, 32032428172, -10186720910], [4507774800550, -204933095205, 23829429675, -4765885935], [48522783989738, 120566379556, -14019346460, 2803869292], [-27638231566058, 157883197395, -18358511325, 3671702265], [0, -115413610220, -71246454950, 7361192545], [0, -47349848393, 43256307889, 15101026047], [0, 28776952304, 14509471748, -2377913426], [-43445373118970, -231725241601, 26944795535, -5388959107], [34384387036034, -4622155140, 537459900, -107491980], [0, -235644859847, -229682441465, 993736397], [0, -63107757728, -40936639880, 3695186308], [0, -79625459682, -69280495710, 1724160662], [67386529626290, -139079756592, 16172064720, -3234412944], [70130154821566, -91324357567, 10619111345, -2123822269], [7982019585722, 215289572148, -25033671180, 5006734236], [0, -123506468252, -68070756704, 9239285258], [17547319951462, -122168594601, 14205650535, -2841130107], [12008973530734, 6178331117, -718410595, 143682119], [0, 53222126604, -18133938036, -11892677440], [14079530354134, 148952213667, -17320024845, 3464004969], [0, 2874555738, -46242183546, -8186123214], [0, -145958992188, -125716217958, 3373795705], [0, 203570040067, -22374151091, -37657365193], [-3177458178790, -737237243052, 85725260820, -17145052164], [-44241164126398, -180963556228, 21042273980, -4208454796], [0, 131015259548, -76050960250, -34511036633], [0, 159964816101, -106489938045, -44409125691], [-27605723952842, 138981462075, -16160635125, 3232127025], [0, 52948892084, -66968062318, -19986159067], [239148352305530, -111306663580, 12942635300, -2588527060], [0, 138276056868, -162126976836, -50067172284], [123455582972974, 632000516877, -73488432195, 14697686439], [220851797574506, -363222778308, 42235206780, -8447041356], [-46803805786730, 430910697903, -50105895105, 10021179021], [0, -139101876254, 17622770398, 26120774442], [-9410393862050, -627504985471, 72965695985, -14593139197], [-220519660232230, 170835221676, -19864560660, 3972912132], [0, -232765294264, -218818911364, 2324397150], [5636456292866, 809081219072, -94079211520, 18815842304], [0, 569143068492, 174292759110, -65808384897], [-78324012926474, 1512939064587, -175923147045, 35184629409], [0, 392732950916, 658553509874, 44303426493], [0, 311333984824, 462652179796, 25219699162], [7289480820454, -1324922651541, 154060773435, -30812154687], [0, -205330593556, -683240047186, -79651575605], [-340839689718290, 1069937870365, -124411380275, 24882276055], [0, -806006774395, -411357156613, 65774936297], [338305303970858, 1528281935996, -177707201860, 35541440372], [0, -626091501838, -260860938178, 60871760610], [91044351075482, 327971310540, -38136198900, 7627239780], [0, 492237248992, 994409167588, 83695319766], [46746690982726, -1104133634125, 128387631875, -25677526375], [0, 873032062496, 699131306096, -28983459400], [111235241656202, 283894467388, -33010984580, 6602196916], [0, 721150059272, 911006182160, 31642687148], [325717892229814, 473773010011, -55089884885, 11017976977], [0, 124659067310, -445968756958, -95104637378], [574921955413414, 796322500603, -92595639605, 18519127921], [0, -507082761364, 240401110820, 124580645364], [-520285979192402, -126071721027, 14659502445, -2931900489], [0, 1196126896060, 510474530476, -114275394264], [-498724222043950, 688837198132, -80097348620, 16019469724], [0, 276341066292, 373397302458, 16176039361], [0, 84060323651, -986104382659, -178360784385], [0, -1164333334176, -593489214540, 95140686606], [-143292297540722, 4067852209869, -473006070915, 94601214183], [0, 890567832093, 941036485227, 8411442189], [0, 1368736160628, -87921380340, -242776256828], [0, -2119018340474, -589860356918, 254859663926], [-436979479411010, -206994857055, 24069169425, -4813833885], [831232236581306, 2874331529556, -334224596460, 66844919292]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_48_e_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_48_11_e_d();".
// 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_48_11_e_d(:prec:=4)
    chi := MakeCharacter_48_e();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 11));
    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_48_11_e_d();".
// 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_48_11_e_d( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_48_e();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,11,sign)));
    Vf := Kernel([<5,R![306009247334400, 0, 36397440, 0, 1]>],Snew);
    return Vf;
end function;