
// Make newform 162.11.d.d in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_162_d();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_162_d_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_162_11_d_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_162_11_d_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 := [161859, 34356, -31616, -5392, 2477, 260, -82, -4, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0, 0], [-57465, -6492, 6275, 432, -211, -6, 2, 0], [431997408168, 28839704256, -28122112960, -945290272, 450282296, 13438472, -4259056, -6736], [-463512000, 884063664, 127639232, -80967040, -6141520, 2362304, 94304, -26944], [-606875544888, -119327084172, 113195424340, 11865395680, -5691779540, -268154120, 88776484, 25180], [9345624, -17321976, -4049728, 2507000, 286400, -108904, -5656, 1616], [-14884222608, 28995159168, 2297506176, -1457406720, -110547360, 42521472, 1697472, -484992], [25749860040, -47236696128, -12625563672, 7873873344, 808250040, -310292784, -13007232, 3716352]];
    Rf_basisdens := [1, 13746, 45423657, 45423657, 45423657, 574983, 5047073, 5047073];
    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_162_d();"
function MakeCharacter_162_d()
    N := 162;
    order := 6;
    char_gens := [83];
    v := [5];
    // 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_162_d_Hecke();"
function MakeCharacter_162_d_Hecke(Kf)
    N := 162;
    order := 6;
    char_gens := [83];
    char_values := [[0, -1, 0, 0, 0, 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, -1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 26, 1, 26, 0, 0], [11278, 11278, 0, 0, 0, 0, 0, -1], [0, 0, 35, 3766, 0, 0, 0, 0], [0, 68810, 0, 0, 0, 0, -20, 20], [0, 0, 236, 0, -236, 73832, 0, 0], [-392182, 0, 0, 0, 0, 0, -97, 0], [0, 0, 0, -91988, -826, -91988, 0, 0], [0, 0, -2947, -763022, 0, 0, 0, 0], [0, -5446462, 0, 0, 0, 0, -3045, 3045], [-17753542, 0, 0, 0, 0, 0, -5684, 0], [0, 0, 0, -4094500, 13414, -4094500, 0, 0], [117672166, 117672166, 0, 0, 0, 0, 0, -6783], [0, 0, -14460, 4156680, 0, 0, 0, 0], [0, 0, -59339, 0, 59339, 9200542, 0, 0], [0, 0, 0, 17244994, 23273, 17244994, 0, 0], [296009686, 296009686, 0, 0, 0, 0, 0, -19644], [0, -74341462, 0, 0, 0, 0, 49917, -49917], [0, 0, -213598, 0, 213598, 14573468, 0, 0], [1633567250, 0, 0, 0, 0, 0, -46224, 0], [-49820642, -49820642, 0, 0, 0, 0, 0, 160363], [0, 0, -388359, 24181890, 0, 0, 0, 0], [0, 0, -587062, 0, 587062, 120006236, 0, 0], [9794088766, 9794088766, 0, 0, 0, 0, 0, 79756], [0, 0, 707479, -610238698, 0, 0, 0, 0], [0, 2767094834, 0, 0, 0, 0, 468807, -468807], [0, 0, 4553941, 0, -4553941, -214632602, 0, 0], [-5079939190, 0, 0, 0, 0, 0, -29652, 0], [0, 0, 0, -599834040, -84588, -599834040, 0, 0], [4529901314, 0, 0, 0, 0, 0, 3038973, 0], [0, 0, 0, -2025653386, 1013107, -2025653386, 0, 0], [0, 0, -14206318, -1434500972, 0, 0, 0, 0], [0, 71403167066, 0, 0, 0, 0, -682459, 682459], [0, 0, 0, -1033681550, -13567267, -1033681550, 0, 0], [-76625787986, -76625787986, 0, 0, 0, 0, 0, 3829791], [0, -30919534870, 0, 0, 0, 0, -10716948, 10716948], [-115761759766, 0, 0, 0, 0, 0, -1981721, 0], [0, 0, 0, -1923084012, 40035546, -1923084012, 0, 0], [0, 0, 21053121, -9515609190, 0, 0, 0, 0], [0, 0, -35935361, 0, 35935361, 6387492850, 0, 0], [60571129178, 0, 0, 0, 0, 0, 15724084, 0], [0, 0, -43142960, 1080484832, 0, 0, 0, 0], [0, -33381474430, 0, 0, 0, 0, 28872816, -28872816], [0, 0, 40372241, 0, -40372241, -823232890, 0, 0], [-30698724238, 0, 0, 0, 0, 0, 6778481, 0], [0, 314017714058, 0, 0, 0, 0, -13470443, 13470443], [420669605566, 420669605566, 0, 0, 0, 0, 0, -15490581], [0, 0, 129912213, -5414496774, 0, 0, 0, 0], [0, 695033891258, 0, 0, 0, 0, -28595796, 28595796], [0, 0, 255838870, 0, -255838870, 1969665316, 0, 0], [0, 0, 0, 21439920216, 177713004, 21439920216, 0, 0], [76175414686, 76175414686, 0, 0, 0, 0, 0, 80590976], [0, 0, 34645177, 0, -34645177, 31525180414, 0, 0], [0, 0, 0, 19980213312, -409334784, 19980213312, 0, 0], [0, 0, 36266734, 67723908668, 0, 0, 0, 0], [0, 0, 18812071, 0, -18812071, -55713681398, 0, 0], [-1587999049630, 0, 0, 0, 0, 0, -13850427, 0], [-1112878112282, -1112878112282, 0, 0, 0, 0, 0, -48785772], [0, 0, -241479322, 55934663932, 0, 0, 0, 0], [0, 658166758970, 0, 0, 0, 0, 138475293, -138475293], [0, 0, 0, 58223910922, 61051577, 58223910922, 0, 0], [-1304508297526, 0, 0, 0, 0, 0, -166858821, 0], [0, 0, 0, -80215224388, 33581806, -80215224388, 0, 0], [-742181883506, -742181883506, 0, 0, 0, 0, 0, -82939276], [0, 0, -706336379, 73224068354, 0, 0, 0, 0], [-1652588508122, -1652588508122, 0, 0, 0, 0, 0, -256686059], [0, 2510294481698, 0, 0, 0, 0, -137467876, 137467876], [0, 0, 0, 212299838130, -95602479, 212299838130, 0, 0], [4060246031254, 4060246031254, 0, 0, 0, 0, 0, 433507388], [0, 0, 551581880, -62424863696, 0, 0, 0, 0], [0, 0, 311409546, 0, -311409546, -214724519220, 0, 0], [9154963984222, 9154963984222, 0, 0, 0, 0, 0, -80443029], [0, -2631334128934, 0, 0, 0, 0, 539136556, -539136556], [11443448578682, 0, 0, 0, 0, 0, 28308343, 0], [0, 0, 0, -55613608960, -1315563872, -55613608960, 0, 0], [0, 0, 1865716447, -317506536922, 0, 0, 0, 0], [-4950678330934, 0, 0, 0, 0, 0, 520249020, 0], [0, 0, 0, -587556457192, -409210676, -587556457192, 0, 0], [0, -6222369519310, 0, 0, 0, 0, -378184912, 378184912], [0, 0, 0, -685981592538, -1589277093, -685981592538, 0, 0], [2757232534726, 2757232534726, 0, 0, 0, 0, 0, -246070468], [0, 0, 1347795932, 0, -1347795932, 545631026120, 0, 0], [13958631539426, 0, 0, 0, 0, 0, -558667836, 0], [-2135655008018, -2135655008018, 0, 0, 0, 0, 0, 1455885327], [0, 0, 1351245399, -1062706160034, 0, 0, 0, 0], [0, 0, -2614463376, 0, 2614463376, -120238433664, 0, 0], [-411256247570, -411256247570, 0, 0, 0, 0, 0, -86352], [0, 0, 44640329, -998171606, 0, 0, 0, 0], [0, -3470712244510, 0, 0, 0, 0, -1356069869, 1356069869], [0, 0, 1240242727, 0, -1240242727, -769973009534, 0, 0], [0, 0, -3429360792, -418027518768, 0, 0, 0, 0], [-26541169644238, 0, 0, 0, 0, 0, 1268674841, 0], [0, 0, 0, -746810964326, -4504093195, -746810964326, 0, 0], [0, 7042617774410, 0, 0, 0, 0, 1707790581, -1707790581], [0, 0, -1514389410, 0, 1514389410, 1285493376996, 0, 0], [0, 0, 0, 407688419870, 12176717131, 407688419870, 0, 0], [0, 0, 10186720910, 0, -10186720910, 992886136148, 0, 0], [-4507774800550, 0, 0, 0, 0, 0, 4765885935, 0], [48522783989738, 0, 0, 0, 0, 0, 2803869292, 0], [-27638231566058, -27638231566058, 0, 0, 0, 0, 0, 3671702265], [0, 0, -7361192545, 0, 7361192545, -1871861154790, 0, 0], [0, 0, 0, 705928816302, 15101026047, 705928816302, 0, 0], [0, 0, -2377913426, 400541417324, 0, 0, 0, 0], [0, 43445373118970, 0, 0, 0, 0, -5388959107, 5388959107], [34384387036034, 0, 0, 0, 0, 0, -107491980, 0], [0, 0, -993736397, 5534240795894, 0, 0, 0, 0], [0, 0, -3695186308, 0, 3695186308, -1063773455896, 0, 0], [0, 0, 0, -1700663431604, 1724160662, -1700663431604, 0, 0], [-67386529626290, -67386529626290, 0, 0, 0, 0, 0, 3234412944], [0, -70130154821566, 0, 0, 0, 0, -2123822269, 2123822269], [7982019585722, 0, 0, 0, 0, 0, 5006734236, 0], [0, 0, 0, 1836962436572, -9239285258, 1836962436572, 0, 0], [17547319951462, 17547319951462, 0, 0, 0, 0, 0, -2841130107], [-12008973530734, 0, 0, 0, 0, 0, -143682119, 0], [0, 0, -11892677440, -173575609184, 0, 0, 0, 0], [0, -14079530354134, 0, 0, 0, 0, 3464004969, -3464004969], [0, 0, -8186123214, 0, 8186123214, 929717694396, 0, 0], [0, 0, 0, 3091412736502, -3373795705, 3091412736502, 0, 0], [0, 0, 37657365193, -291482408062, 0, 0, 0, 0], [0, -3177458178790, 0, 0, 0, 0, 17145052164, -17145052164], [44241164126398, 44241164126398, 0, 0, 0, 0, 0, 4208454796], [0, 0, -34511036633, -1065980240074, 0, 0, 0, 0], [0, 0, -44409125691, 0, 44409125691, 1578757747878, 0, 0], [-27605723952842, -27605723952842, 0, 0, 0, 0, 0, 3232127025], [0, 0, 19986159067, 0, -19986159067, -1167537996158, 0, 0], [-239148352305530, -239148352305530, 0, 0, 0, 0, 0, 2588527060], [0, 0, -50067172284, 0, 50067172284, 2789569653816, 0, 0], [123455582972974, 123455582972974, 0, 0, 0, 0, 0, 14697686439], [0, 220851797574506, 0, 0, 0, 0, 8447041356, -8447041356], [46803805786730, 0, 0, 0, 0, 0, -10021179021, 0], [0, 0, 0, -151710548172, 26120774442, -151710548172, 0, 0], [0, 9410393862050, 0, 0, 0, 0, -14593139197, 14593139197], [-220519660232230, 0, 0, 0, 0, 0, 3972912132, 0], [0, 0, 0, 5302790610036, -2324397150, 5302790610036, 0, 0], [0, 5636456292866, 0, 0, 0, 0, -18815842304, 18815842304], [0, 0, 65808384897, 0, -65808384897, 5630810686374, 0, 0], [0, 78324012926474, 0, 0, 0, 0, 35184629409, -35184629409], [0, 0, 0, -14830608854130, -44303426493, -14830608854130, 0, 0], [0, 0, -25219699162, 0, 25219699162, 10548818933540, 0, 0], [-7289480820454, 0, 0, 0, 0, 0, 30812154687, 0], [0, 0, -79651575605, -14645426469154, 0, 0, 0, 0], [0, 340839689718290, 0, 0, 0, 0, 24882276055, -24882276055], [0, 0, 65774936297, 0, -65774936297, 11319620357246, 0, 0], [338305303970858, 0, 0, 0, 0, 0, 35541440372, 0], [0, 0, -60871760610, 7599841249692, 0, 0, 0, 0], [-91044351075482, -91044351075482, 0, 0, 0, 0, 0, -7627239780], [0, 0, 83695319766, 22024522987260, 0, 0, 0, 0], [0, -46746690982726, 0, 0, 0, 0, -25677526375, 25677526375], [0, 0, -28983459400, 0, 28983459400, -17416787453104, 0, 0], [0, 111235241656202, 0, 0, 0, 0, -6602196916, 6602196916], [0, 0, -31642687148, 0, 31642687148, 21168009254584, 0, 0], [-325717892229814, 0, 0, 0, 0, 0, -11017976977, 0], [0, 0, 0, -8610948144676, -95104637378, -8610948144676, 0, 0], [574921955413414, 574921955413414, 0, 0, 0, 0, 0, 18519127921], [0, 0, -124580645364, -3028852461672, 0, 0, 0, 0], [520285979192402, 0, 0, 0, 0, 0, 2931900489, 0], [0, 0, -114275394264, 14765447405232, 0, 0, 0, 0], [-498724222043950, 0, 0, 0, 0, 0, 16019469724, 0], [0, 0, 0, -8605662393050, -16176039361, -8605662393050, 0, 0], [0, 0, 178360784385, 19742567927346, 0, 0, 0, 0], [0, 0, -95140686606, 0, 95140686606, -16336836254292, 0, 0], [0, 143292297540722, 0, 0, 0, 0, 94601214183, -94601214183], [0, 0, 8411442189, 0, -8411442189, -22399823917290, 0, 0], [0, 0, 0, -3230964522056, 242776256828, -3230964522056, 0, 0], [0, 0, -254859663926, 19763561172404, 0, 0, 0, 0], [436979479411010, 0, 0, 0, 0, 0, 4813833885, 0], [-831232236581306, -831232236581306, 0, 0, 0, 0, 0, -66844919292]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_162_d_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_162_11_d_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_162_11_d_d(:prec:=8)
    chi := MakeCharacter_162_d();
    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_162_11_d_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_162_11_d_d( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_162_d();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,11,sign)));
    Vf := Kernel([<5,R![93641659454165993505423360000, 0, -11137953219298983936000, 0, 1018764391219200, 0, -36397440, 0, 1]>],Snew);
    return Vf;
end function;