
// Make newform 162.8.c.m in Magma, downloaded from the LMFDB on 12 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_162_c();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_162_c_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_8_c_m();".
// 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_8_c_m();".
// 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 := [6724, 82, 83, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [6724, -83, 83, -1], [-181548, 369765, -2241, 27], [6669, 0, 0, 54]];
    Rf_basisdens := [1, 6806, 6806, 83];
    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_c();"
function MakeCharacter_162_c()
    N := 162;
    order := 3;
    char_gens := [83];
    v := [2];
    // 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_c_Hecke();"
function MakeCharacter_162_c_Hecke( : Kf := false)
    N := 162;
    order := 3;
    char_gens := [83];
    char_values := [[0, -1, 0, 0]];
    assert UnitGenerators(DirichletGroup(N)) eq char_gens;
    values := ConvertToHeckeField(char_values : pass_field := ISA(Type(Kf), Fld), 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]];
    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 := 8;
    raw_aps := [[-8, 8, 0, 0], [0, 0, 0, 0], [0, 24, 1, 0], [-440, 440, 1, 1], [-3615, 3615, 8, 8], [0, -4280, -20, 0], [12852, 0, 0, 20], [18524, 0, 0, 70], [0, 29814, 20, 0], [137640, -137640, 230, 230], [0, -122792, 285, 0], [-35530, 0, 0, -868], [0, -247260, -14, 0], [-412640, 412640, -318, -318], [463854, -463854, 840, 840], [-691056, 0, 0, -245], [0, -794460, 1016, 0], [1510984, -1510984, 240, 240], [0, 941080, -1842, 0], [-1697220, 0, 0, -5860], [447545, 0, 0, -4824], [184960, -184960, 3320, 3320], [4676025, -4676025, -3240, -3240], [-456480, 0, 0, 9314], [-679895, 679895, -14776, -14776], [2180280, -2180280, 15217, 15217], [0, -11760080, -5268, 0], [5326515, 0, 0, -18680], [-1381210, 0, 0, 41820], [0, -11303004, -23550, 0], [-41246800, 0, 0, 4089], [0, -524595, 42376, 0], [-4743096, 4743096, 46910, 46910], [0, 16827304, 78500, 0], [0, 37804560, -65863, 0], [-16499024, 16499024, -93225, -93225], [0, -9707540, 89064, 0], [-38336740, 0, 0, 95456], [0, 25798074, 46800, 0], [12419688, -12419688, -75405, -75405], [-17082315, 0, 0, -133640], [-15857872, 0, 0, 124160], [-74877360, 74877360, 161980, 161980], [0, -100764725, -68880, 0], [-110676960, 0, 0, 25835], [90847568, 0, 0, -73535], [0, -78629396, 76870, 0], [136756360, -136756360, -9408, -9408], [-132331092, 132331092, 154920, 154920], [0, -5741582, 351480, 0], [81913968, 0, 0, -373490], [0, -86476710, 71364, 0], [181213714, -181213714, 96040, 96040], [167952960, 0, 0, 336448], [0, -21073404, 901200, 0], [-103140186, 103140186, -61100, -61100], [-384277680, 0, 0, 38890], [49745720, 0, 0, 256575], [-181239920, 181239920, -6216, -6216], [337427940, -337427940, -510820, -510820], [0, 48648460, 482442, 0], [0, -480800928, 264110, 0], [564218660, 0, 0, 420660], [0, -584852610, 587788, 0], [-258323165, 258323165, 559000, 559000], [11143416, -11143416, -545255, -545255], [-217089800, 217089800, -370150, -370150], [0, -506844050, 1339016, 0], [0, 633973119, -1049640, 0], [1392799726, -1392799726, -34340, -34340], [-451192092, 451192092, 1829930, 1829930], [-1176433290, 0, 0, 67992], [-301727240, 301727240, 2149671, 2149671], [0, 970144780, -735500, 0], [518010464, 0, 0, 1114340], [0, 847585428, 2159860, 0], [563006640, -563006640, -342113, -342113], [44653160, 0, 0, 236388], [0, -531147360, -1658924, 0], [0, 149548369, 1151840, 0], [0, 1761751500, -1710096, 0], [-1567771136, 1567771136, 2019880, 2019880], [1324210590, 0, 0, -2861104], [-951149275, 0, 0, 1380600], [-1573513496, 1573513496, 103155, 103155], [109723476, -109723476, -4472400, -4472400], [838563660, 0, 0, 2164062], [-1420772975, 1420772975, 1500216, 1500216], [-1885223760, 1885223760, 743783, 743783], [0, 2134535080, 3337003, 0], [-2520129753, 0, 0, -3089840], [758365950, -758365950, 3765816, 3765816], [723277280, 0, 0, 7416016], [0, -2301443805, -3848584, 0], [0, -208304600, -7250850, 0], [728197110, 0, 0, -4522860], [0, -278555880, -1864061, 0], [683773740, 0, 0, 8826632], [-4218403660, 0, 0, 315588], [299459180, 0, 0, 687560], [-1386579860, 1386579860, 8035044, 8035044], [-4582583424, 0, 0, 3105785], [0, 2576510583, -3411000, 0], [-3013230120, 3013230120, 6163948, 6163948], [0, -1892567876, 6245360, 0], [-320648290, 0, 0, -6611784], [1233059601, -1233059601, -2606600, -2606600], [2433769488, 0, 0, -9195970], [0, -3259771410, 11882168, 0], [-721636307, 721636307, 852840, 852840], [0, -389774480, -14074192, 0], [-2355156250, 0, 0, 9307008], [0, 2694676236, -2637170, 0], [-5851945988, 5851945988, 8869320, 8869320], [2179654760, 0, 0, 7788455], [-4210134180, 4210134180, -8261626, -8261626], [0, 4240150240, -13737780, 0], [2576307384, 0, 0, 683640], [0, -259452840, 21142085, 0], [-2329609065, 2329609065, -1835792, -1835792], [0, -7778941898, 4769460, 0], [10214091235, -10214091235, 5145008, 5145008], [3083045448, -3083045448, -7235990, -7235990], [-5512602780, 0, 0, 14397840], [-11397406400, 11397406400, 4762980, 4762980], [734100120, 0, 0, -20181125], [6345865972, -6345865972, -13394320, -13394320], [-659078820, 0, 0, 17818176], [-6548117120, 6548117120, -18574839, -18574839], [0, -1467436550, -23039148, 0], [2765897804, 0, 0, -6320100], [0, 7581219504, 3072540, 0], [0, -5318943440, -29219335, 0], [2503500050, 0, 0, -13452168], [0, -6746403000, 23295816, 0], [0, 2091565759, -3629600, 0], [-13506928704, 0, 0, 16666410], [0, 8438264320, -19938144, 0], [0, 18044723904, 4801485, 0], [19226957760, 0, 0, 372062], [18700965236, 0, 0, 4884750], [18772819680, -18772819680, 6279694, 6279694], [0, 11293149640, 14157121, 0], [1974799008, 0, 0, -22346080], [15627714482, 0, 0, 6375400], [-9060340020, 9060340020, -32764524, -32764524], [23309949610, -23309949610, -11539992, -11539992], [10653283236, -10653283236, -16771500, -16771500], [0, -15795460760, -20177200, 0], [10606378644, 0, 0, -25795600], [0, 10223154670, -930592, 0], [10062690660, 0, 0, -30093080], [-3603103180, 0, 0, -53382626], [0, 9956551848, 50028580, 0], [-32486839460, 32486839460, -6711094, -6711094], [5519510310, -5519510310, -16684032, -16684032], [-12446227744, 0, 0, 20901285], [13696093560, -13696093560, 5799660, 5799660], [-2590854325, 0, 0, 36500504], [0, -6810362760, -47096467, 0], [-1292287281, 1292287281, 59267040, 59267040], [10166768424, 0, 0, 58501740], [0, 20446246840, 67788327, 0], [17161534935, 0, 0, 65618232], [0, -19581479904, -10224310, 0], [34100527278, -34100527278, 7178200, 7178200], [40674713672, 0, 0, -19835385], [4069581040, -4069581040, 7676772, 7676772]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_162_c_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_162_8_c_m();".
// 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_8_c_m(:prec:=4)
    chi := MakeCharacter_162_c();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 8));
    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_8_c_m();".
// 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_8_c_m( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_162_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,8,sign)));
    Vf := Kernel([<5,R![57247740225, 11484720, 241569, -48, 1]>],Snew);
    return Vf;
end function;