
// Make newform 162.8.c.c in Magma, downloaded from the LMFDB on 27 December 2024.
// 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_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_162_8_c_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 := [1, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    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)
    N := 162;
    order := 3;
    char_gens := [83];
    char_values := [[0, -1]];
    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]];
    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, 105], [937, -937], [5943, -5943], [0, -68], [5400, 0], [-48382, 0], [0, -642], [-125934, 125934], [0, 161275], [-414286, 0], [0, -627474], [-570590, 570590], [538698, -538698], [-356283, 0], [0, -2910828], [-2684168, 2684168], [0, -2681078], [3705480, 0], [-153151, 0], [7579288, -7579288], [9345999, -9345999], [-4033602, 0], [5754097, -5754097], [8879223, -8879223], [0, 2655652], [-21123387, 0], [-18421342, 0], [0, -18628482], [-2583799, 0], [0, 41928315], [1266618, -1266618], [0, -23056124], [0, 23826633], [-45049337, 45049337], [0, -35257532], [-65500900, 0], [0, 52808982], [-110732955, 110732955], [11942739, 0], [-79522576, 0], [-6023148, 6023148], [0, 58584955], [168414453, 0], [-101669263, 0], [0, 86382022], [-41617304, 41617304], [209315244, -209315244], [0, -332918726], [-79542846, 0], [0, 146900490], [30305530, -30305530], [-147026880, 0], [0, -367776084], [325856550, -325856550], [339029478, 0], [-2507785, 0], [52858504, -52858504], [539551776, -539551776], [0, -65856542], [0, -35258322], [114259448, 0], [0, 155462766], [-382299173, 382299173], [444886671, -444886671], [550888210, -550888210], [0, 496793254], [0, -251161671], [482914090, -482914090], [-486934638, 486934638], [459968562, 0], [-652503329, 652503329], [0, -1917909896], [1431511940, 0], [0, -139859328], [-1775919471, 1775919471], [-1053011860, 0], [0, 2330121588], [0, 150421873], [0, 911432292], [753482152, -753482152], [2728918098, 0], [1846991837, 0], [-1500659909, 1500659909], [1316898876, -1316898876], [-271215882, 0], [2150613577, -2150613577], [984188361, -984188361], [0, 2567482429], [697866921, 0], [-3070659894, 3070659894], [-1742540272, 0], [0, -1010538219], [0, -1560872246], [-1636632234, 0], [0, -528525525], [-4507074324, 0], [3604535192, 0], [-2247138700, 0], [-4267406096, 4267406096], [-718311321, 0], [0, -5711547279], [6360004668, -6360004668], [0, 4749503404], [-895938154, 0], [-6427642569, 6427642569], [6897406194, 0], [0, -8505640182], [7036795765, -7036795765], [0, 9168810016], [1898144678, 0], [0, 10080097314], [2077970212, -2077970212], [-8916187345, 0], [-1879049922, 1879049922], [0, 2305200532], [5738668560, 0], [0, -7368753747], [12453982329, -12453982329], [0, 5532070306], [-11178842093, 11178842093], [-16003726674, 16003726674], [-970052148, 0], [-209761244, 209761244], [16579209069, 0], [9789010084, -9789010084], [-10860469596, 0], [-8010583703, 8010583703], [0, -16717306874], [-9357021304, 0], [0, 15831832524], [0, 15053991799], [6814477514, 0], [0, 3422686272], [0, -9623704001], [24679619766, 0], [0, 24626037856], [0, 4463286477], [2564959842, 0], [3958204322, 0], [15851022834, -15851022834], [0, 15745335943], [2156397120, 0], [29570339738, 0], [-3119819136, 3119819136], [14394172690, -14394172690], [4732009896, -4732009896], [0, 4837345240], [19088971452, 0], [0, 33636320014], [-28125557676, 0], [19994410226, 0], [0, -32267621604], [-11523224762, 11523224762], [-5897089446, 5897089446], [4376792261, 0], [30302382108, -30302382108], [26139715427, 0], [0, -24243946347], [25775453073, -25775453073], [-22228767828, 0], [0, 3094103569], [16262076753, 0], [0, 4422563754], [37384685562, -37384685562], [-12447310993, 0], [-28433512844, 28433512844]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_162_c_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_162_8_c_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_162_8_c_c(:prec:=2)
    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_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_162_8_c_c( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_162_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,8,sign)));
    Vf := Kernel([<5,R![11025, -105, 1]>],Snew);
    return Vf;
end function;