
// Make newform 162.10.c.b in Magma, downloaded from the LMFDB on 29 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_10_c_b();".
// 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_10_c_b();".
// 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 := false)
    N := 162;
    order := 3;
    char_gens := [83];
    char_values := [[0, -1]];
    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 := 10;
    raw_aps := [[-16, 16], [0, 0], [0, -870], [952, -952], [56148, -56148], [0, -178094], [-247662, 0], [315380, 0], [0, -204504], [3840450, -3840450], [0, 1309408], [4307078, 0], [0, -1512042], [-33670604, 33670604], [10581072, -10581072], [16616214, 0], [0, -112235100], [33197218, -33197218], [0, 121372252], [-387172728, 0], [255240074, 0], [-492101840, 492101840], [457420236, -457420236], [-31809510, 0], [673532062, -673532062], [-1057718982, 1057718982], [0, -795866024], [-1974134772, 0], [-1344647410, 0], [0, -2706802674], [1199600768, 0], [0, -2786145252], [-2882330058, 2882330058], [0, -2156411180], [0, -7545477750], [4313083048, -4313083048], [0, 4231572802], [828448004, 0], [0, 2854998552], [17669017266, -17669017266], [-586732140, 0], [-5433956458, 0], [-32329244352, 32329244352], [0, 12939916606], [8810897958, 0], [-24853394680, 0], [0, 46516300108], [-46634730464, 46634730464], [-26586730308, 26586730308], [0, -39990726470], [6533375274, 0], [0, 56677299600], [-4614914162, 4614914162], [68019386652, 0], [0, 93595760382], [94040095416, -94040095416], [122724427950, 0], [-164257407088, 0], [-65013397238, 65013397238], [-52096444122, 52096444122], [0, 90699183556], [0, -72556898694], [181977113108, 0], [0, 89829518088], [-5513937914, 5513937914], [19480554402, -19480554402], [106801000468, -106801000468], [0, 175776423982], [0, -83302636668], [-321367902590, 321367902590], [-407688457314, 407688457314], [-560078988120, 0], [-376056463088, 376056463088], [0, 81224458666], [202729151900, 0], [0, 47681602176], [189794662170, -189794662170], [400237219118, 0], [0, -876185839122], [0, -572299984730], [0, -416692614660], [1190433985018, -1190433985018], [-436455134928, 0], [448430049074, 0], [659702920840, -659702920840], [-948506603484, 948506603484], [-611762940990, 0], [379032618742, -379032618742], [890062477458, -890062477458], [0, -1328521649744], [1656376397748, 0], [1079731180320, -1079731180320], [1605486047528, 0], [0, -793629275532], [0, 1969508923180], [-542230355016, 0], [0, 1692147528930], [2975959460682, 0], [-1079894255956, 0], [-2021673615298, 0], [2626119837052, -2626119837052], [3484820127438, 0], [0, 2770913613036], [670382371590, -670382371590], [0, -2671233315932], [-659284138942, 0], [-1049465239788, 1049465239788], [-1311883953966, 0], [0, 3376028300520], [-2638803841562, 2638803841562], [0, 5159389404832], [-537353626426, 0], [0, -4633581879978], [-3062671313420, 3062671313420], [-54692849608, 0], [4780679546238, -4780679546238], [0, -4104842552804], [-5492629724472, 0], [0, -4159943034414], [-2152945882740, 2152945882740], [0, -8639782534262], [2907884393566, -2907884393566], [-4268219834118, 4268219834118], [-769165099956, 0], [-1386484613012, 1386484613012], [-5511859848738, 0], [-2431522040870, 2431522040870], [-2708898248880, 0], [-526646689688, 526646689688], [0, 2780092868866], [-2365576289980, 0], [0, -13139774626344], [0, 7294364410768], [-16301969136682, 0], [0, 9689446243398], [0, -12132873232130], [-16864650951066, 0], [0, 6001159578892], [0, 14315504363202], [-10989330977430, 0], [21544361627852, 0], [-5717478970902, 5717478970902], [0, 10052437891336], [22958121262428, 0], [-15727726682530, 0], [8521678548600, -8521678548600], [1831603068106, -1831603068106], [620072354022, -620072354022], [0, 5715810374020], [20259551636064, 0], [0, 91457250802], [17315004551922, 0], [13878128084564, 0], [0, -17658551034168], [-12392374416428, 12392374416428], [13810380634608, -13810380634608], [856606346840, 0], [-12916914336930, 12916914336930], [-3678673359382, 0], [0, -44514500834382], [19954325186412, -19954325186412], [7132015155834, 0], [0, -2841758123528], [-39030869592468, 0], [0, 21755586348462], [-46499831376024, 46499831376024], [-15520906240288, 0], [42633356836282, -42633356836282]];
    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_10_c_b();".
// 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_10_c_b(:prec:=2)
    chi := MakeCharacter_162_c();
    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_162_10_c_b();".
// 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_10_c_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_162_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,10,sign)));
    Vf := Kernel([<5,R![756900, 870, 1]>],Snew);
    return Vf;
end function;