
// Make newform 162.5.d.d in Magma, downloaded from the LMFDB on 02 May 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_5_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_5_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 := [1, 0, 0, 0, -1, 0, 0, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0, 0], [0, 0, 3, 0, 0, 0, 3, 0], [0, 1, 0, 0, 0, 0, 0, -1], [0, 0, 6, 0, 0, 0, -3, 0], [0, 0, 0, 1, 0, 1, 0, -1], [0, 3, 0, 2, 0, -1, 0, 1], [0, 1, 0, -1, 0, 2, 0, 3]];
    Rf_basisdens := [1, 1, 1, 1, 1, 1, 1, 1];
    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 := [[1, -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 := 5;
    raw_aps := [[0, 0, 0, -2, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 22, -5, 0], [0, 13, -13, 0, 0, 0, 0, 0], [0, 0, 0, 59, 0, 0, -10, 10], [-143, 143, 14, 0, -14, 0, 0, 0], [0, 0, 0, 116, 0, -116, 0, 31], [-31, 0, 0, 0, -43, 0, 0, 0], [0, 0, 0, 0, 0, 35, 200, 0], [0, 0, 0, -37, 0, 0, -295, 295], [-896, 896, 54, 0, -54, 0, 0, 0], [-2350, 0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, -203, -266, 0], [0, -755, -177, 0, 0, 0, 0, 0], [0, 0, 0, -510, 0, 0, -594, 594], [0, 0, 0, 421, 0, -421, 0, -262], [0, 0, 0, 0, 0, 530, -358, 0], [0, 1036, -351, 0, 0, 0, 0, 0], [3019, -3019, 1131, 0, -1131, 0, 0, 0], [0, 0, 0, -3757, 0, 3757, 0, 592], [-448, 0, 0, 0, 1455, 0, 0, 0], [0, 3751, -53, 0, 0, 0, 0, 0], [0, 0, 0, 450, 0, 0, -408, 408], [0, 0, 0, -1309, 0, 1309, 0, 2041], [0, -11576, 310, 0, 0, 0, 0, 0], [0, 0, 0, -1391, 0, 0, 2704, -2704], [8392, -8392, -984, 0, 984, 0, 0, 0], [0, 0, 0, 8824, 0, -8824, 0, 2846], [11135, 0, 0, 0, 1500, 0, 0, 0], [0, 0, 0, 0, 0, -5424, 405, 0], [-17863, 0, 0, 0, -453, 0, 0, 0], [0, 0, 0, 0, 0, 1717, -3764, 0], [0, 0, 0, -13345, 0, 0, 941, -941], [-650, 650, -2846, 0, 2846, 0, 0, 0], [0, 0, 0, 0, 0, -5515, 4271, 0], [0, 14608, -3348, 0, 0, 0, 0, 0], [13342, -13342, 2091, 0, -2091, 0, 0, 0], [-7228, 0, 0, 0, -5450, 0, 0, 0], [0, 0, 0, 0, 0, 9663, 8976, 0], [0, 0, 0, 32859, 0, 0, 1581, -1581], [0, 0, 0, -3662, 0, 3662, 0, 6224], [-39646, 0, 0, 0, -2066, 0, 0, 0], [0, 0, 0, 20587, 0, 0, -7160, 7160], [-10283, 10283, 2646, 0, -2646, 0, 0, 0], [0, 0, 0, 15785, 0, -15785, 0, -10157], [10364, 0, 0, 0, -3616, 0, 0, 0], [40429, -40429, 1295, 0, -1295, 0, 0, 0], [0, 5239, 2943, 0, 0, 0, 0, 0], [0, 0, 0, 29349, 0, 0, 3894, -3894], [13711, -13711, 1236, 0, -1236, 0, 0, 0], [0, 0, 0, 4165, 0, -4165, 0, 4445], [0, 0, 0, 0, 0, -45444, 8760, 0], [0, -10400, 3803, 0, 0, 0, 0, 0], [0, 0, 0, -24347, 0, 24347, 0, 17144], [0, 0, 0, 0, 0, -37251, -9921, 0], [0, 0, 0, 9016, 0, 0, -6050, 6050], [0, 0, 0, 60034, 0, -60034, 0, 4511], [60653, 0, 0, 0, -9831, 0, 0, 0], [0, 10036, -10464, 0, 0, 0, 0, 0], [0, 0, 0, -17962, 0, 0, 33521, -33521], [121090, -121090, 906, 0, -906, 0, 0, 0], [0, 0, 0, 0, 0, -15676, -31189, 0], [36686, 0, 0, 0, 12216, 0, 0, 0], [0, 0, 0, 0, 0, 69322, -10058, 0], [0, -42539, -6346, 0, 0, 0, 0, 0], [0, 0, 0, 2566, 0, 0, 14365, -14365], [0, 9493, 11533, 0, 0, 0, 0, 0], [19294, -19294, 20800, 0, -20800, 0, 0, 0], [0, 0, 0, 0, 0, -113043, 11442, 0], [0, -121424, -3340, 0, 0, 0, 0, 0], [0, 0, 0, -90001, 0, 0, 11288, -11288], [0, 0, 0, -46575, 0, 46575, 0, 29538], [0, 83080, -32502, 0, 0, 0, 0, 0], [-70172, 70172, -11134, 0, 11134, 0, 0, 0], [-61588, 0, 0, 0, -29750, 0, 0, 0], [0, 0, 0, 0, 0, 185197, -5522, 0], [0, 0, 0, 5377, 0, 0, -44258, 44258], [1622, 0, 0, 0, 651, 0, 0, 0], [0, 0, 0, 0, 0, -33077, -29603, 0], [-11000, 11000, 34201, 0, -34201, 0, 0, 0], [0, 0, 0, 0, 0, 143274, -43506, 0], [0, 121711, -12724, 0, 0, 0, 0, 0], [0, 0, 0, 17798, 0, -17798, 0, -6140], [-121651, 0, 0, 0, -16110, 0, 0, 0], [0, 38080, 55134, 0, 0, 0, 0, 0], [0, 0, 0, -19542, 0, 0, 45570, -45570], [0, 0, 0, -23979, 0, 23979, 0, -35502], [0, -148544, 19629, 0, 0, 0, 0, 0], [0, 0, 0, -91285, 0, 0, -17158, 17158], [-167660, 167660, -35590, 0, 35590, 0, 0, 0], [0, 0, 0, 46534, 0, -46534, 0, -35116], [0, 0, 0, 4065, 0, 0, 19470, -19470], [-53410, 0, 0, 0, 38492, 0, 0, 0], [0, 0, 0, 0, 0, -90799, 18248, 0], [106735, -106735, -27189, 0, 27189, 0, 0, 0], [0, 0, 0, 57648, 0, -57648, 0, 129606], [0, 0, 0, 0, 0, 14623, 60190, 0], [0, 0, 0, -87721, 0, 87721, 0, 28378], [-68461, 0, 0, 0, 35031, 0, 0, 0], [-127819, 0, 0, 0, 37840, 0, 0, 0], [0, 63712, 14970, 0, 0, 0, 0, 0], [0, 0, 0, 22949, 0, -22949, 0, 20911], [0, 0, 0, 0, 0, -163620, -41898, 0], [0, 0, 0, 175978, 0, 0, 3709, -3709], [-105914, 105914, -26684, 0, 26684, 0, 0, 0], [296327, 0, 0, 0, -30762, 0, 0, 0], [0, 0, 0, -333947, 0, 0, 42046, -42046], [0, 0, 0, 174149, 0, -174149, 0, 118471], [0, 0, 0, 0, 0, -146266, 65390, 0], [0, -98495, -4092, 0, 0, 0, 0, 0], [243133, -243133, 68815, 0, -68815, 0, 0, 0], [-193768, 0, 0, 0, -77970, 0, 0, 0], [0, 0, 0, 0, 0, 209185, -27803, 0], [0, 614386, 23568, 0, 0, 0, 0, 0], [-45352, 0, 0, 0, 3688, 0, 0, 0], [0, 0, 0, -294427, 0, 0, 4457, -4457], [-218300, 218300, -54396, 0, 54396, 0, 0, 0], [0, 0, 0, -78789, 0, 78789, 0, -21732], [0, 0, 0, 0, 0, -9535, -22258, 0], [0, 0, 0, -45275, 0, 0, -150296, 150296], [-357242, 357242, -68127, 0, 68127, 0, 0, 0], [0, -254801, -81902, 0, 0, 0, 0, 0], [0, 0, 0, 85279, 0, 0, -46490, 46490], [0, 0, 0, -167892, 0, 167892, 0, -55650], [0, -264293, -35559, 0, 0, 0, 0, 0], [0, 0, 0, -273272, 0, 273272, 0, 4943], [0, 892447, -7844, 0, 0, 0, 0, 0], [0, 0, 0, 195579, 0, -195579, 0, -154026], [0, -183239, -122877, 0, 0, 0, 0, 0], [-50054, 50054, -96222, 0, 96222, 0, 0, 0], [598340, 0, 0, 0, -12504, 0, 0, 0], [0, 0, 0, 0, 0, 30816, 123324, 0], [-460649, 460649, 25399, 0, -25399, 0, 0, 0], [250220, 0, 0, 0, -53964, 0, 0, 0], [0, 0, 0, 0, 0, -545403, 106149, 0], [-124145, 124145, 147074, 0, -147074, 0, 0, 0], [0, 0, 0, 259497, 0, -259497, 0, 187947], [-496463, 496463, 8277, 0, -8277, 0, 0, 0], [0, 0, 0, 0, 0, 259995, -198675, 0], [0, 0, 0, -395299, 0, 395299, 0, 32017], [4520, 0, 0, 0, 141768, 0, 0, 0], [0, 0, 0, -553322, 0, 0, 163069, -163069], [-239786, 239786, 79298, 0, -79298, 0, 0, 0], [0, 0, 0, -46669, 0, 46669, 0, -23384], [184316, 0, 0, 0, -20368, 0, 0, 0], [0, 0, 0, -245115, 0, 0, 63402, -63402], [0, 57286, -169752, 0, 0, 0, 0, 0], [0, 0, 0, 98133, 0, 0, -179547, 179547], [1228948, -1228948, -16586, 0, 16586, 0, 0, 0], [0, 0, 0, 100085, 0, -100085, 0, 322900], [-37352, 37352, -142871, 0, 142871, 0, 0, 0], [0, 0, 0, 47989, 0, -47989, 0, 186818], [-1014502, 0, 0, 0, 72410, 0, 0, 0], [0, 0, 0, 0, 0, -78905, 285100, 0], [0, 542320, 146626, 0, 0, 0, 0, 0], [0, 0, 0, 950457, 0, 0, -60066, 60066], [159743, 0, 0, 0, 76755, 0, 0, 0], [0, 0, 0, -236538, 0, 0, -125121, 125121], [22049, 0, 0, 0, 167746, 0, 0, 0], [0, 0, 0, 0, 0, 86147, 79913, 0], [0, 0, 0, 185835, 0, 0, 105804, -105804], [0, 0, 0, 160065, 0, -160065, 0, 61155], [-39263, 39263, -238605, 0, 238605, 0, 0, 0], [0, 0, 0, 54879, 0, -54879, 0, -297816], [0, 0, 0, 0, 0, 617399, -166498, 0], [0, 0, 0, 770932, 0, 0, -119150, 119150], [-698785, 0, 0, 0, -42717, 0, 0, 0], [0, 12034, -195039, 0, 0, 0, 0, 0]];
    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_5_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_5_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, 5));
    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_5_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_5_d_d( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_162_d();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,5,sign)));
    Vf := Kernel([<5,R![32015587041, 0, -392928084, 0, 4643487, 0, -2196, 0, 1]>],Snew);
    return Vf;
end function;