
// Make newform 162.4.c.j in Magma, downloaded from the LMFDB on 24 April 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_4_c_j();".
// 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_4_c_j();".
// 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, -1, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 0, 1, 0], [0, 3, 0, 3], [0, 6, 0, -3]];
    Rf_basisdens := [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_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, 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 := 4;
    raw_aps := [[2, -2, 0, 0], [0, 0, 0, 0], [0, 6, 1, 0], [-8, 8, 2, -2], [18, -18, 8, -8], [0, -5, 14, 0], [-60, 0, 0, -11], [-4, 0, 0, 22], [0, 90, -4, 0], [162, -162, -7, 7], [0, 124, 36, 0], [-217, 0, 0, 2], [0, 96, -44, 0], [304, -304, -6, 6], [-192, 192, 36, -36], [204, 0, 0, -76], [0, -504, 32, 0], [-371, 371, -18, 18], [0, 52, -138, 0], [570, 0, 0, -8], [425, 0, 0, -96], [220, -220, -50, 50], [132, -132, 60, -60], [-384, 0, 0, -89], [382, -382, -56, 56], [-708, 708, -176, 176], [0, 1060, 60, 0], [-84, 0, 0, 260], [821, 0, 0, 174], [0, -384, -261, 0], [-412, 0, 0, 174], [0, 402, 292, 0], [1620, -1620, -193, 193], [0, -764, 268, 0], [0, 2070, -289, 0], [952, -952, 252, -252], [0, -551, 246, 0], [-64, 0, 0, -64], [0, -438, 696, 0], [1950, -1950, -39, 39], [3264, 0, 0, 236], [2114, 0, 0, -136], [606, -606, -32, 32], [0, -1595, -396, 0], [-1842, 0, 0, -155], [140, 0, 0, 256], [0, 1696, -622, 0], [1564, -1564, -18, 18], [294, -294, 348, -348], [0, -1649, -510, 0], [2472, 0, 0, -733], [0, -3948, -564, 0], [-305, 305, 236, -236], [-1722, 0, 0, 104], [0, 4584, -39, 0], [-2904, 2904, -20, 20], [1878, 0, 0, -901], [-5740, 0, 0, -114], [70, -70, 192, -192], [2664, -2664, 293, -293], [0, -4484, 168, 0], [0, 2610, -55, 0], [4412, 0, 0, 492], [0, 6756, -80, 0], [-539, 539, 356, -356], [-1086, 1086, 919, -919], [-860, 860, 790, -790], [0, -602, 712, 0], [0, 2370, 1092, 0], [-1682, 1682, -544, 544], [7344, -7344, -88, 88], [594, 0, 0, -180], [5056, -5056, 996, -996], [0, 1714, 512, 0], [116, 0, 0, 1700], [0, 6234, -1160, 0], [-7620, 7620, -1076, 1076], [-5929, 0, 0, -138], [0, 492, -95, 0], [0, 3439, 532, 0], [0, -8628, -216, 0], [5707, -5707, -838, 838], [1380, 0, 0, 1036], [-313, 0, 0, -1980], [-2396, 2396, -2880, 2880], [-840, 840, 1812, -1812], [4392, 0, 0, -60], [4615, -4615, 468, -468], [-1260, 1260, -868, 868], [0, -2696, -3136, 0], [-588, 0, 0, -1216], [-3594, 3594, -2112, 2112], [-796, 0, 0, -1532], [0, 10674, 224, 0], [0, -15032, 1242, 0], [-3996, 0, 0, 1464], [0, 60, 1732, 0], [2712, 0, 0, 1948], [13016, 0, 0, -1146], [-16543, 0, 0, -982], [-9380, 9380, -168, 168], [-7350, 0, 0, 1537], [0, 10632, 564, 0], [-19428, 19428, 325, -325], [0, 352, 2728, 0], [-14965, 0, 0, 72], [16554, -16554, -344, 344], [-22992, 0, 0, -1037], [0, -540, -4492, 0], [-9263, 9263, 1416, -1416], [0, 2080, -98, 0], [5582, 0, 0, -2184], [0, 9888, -563, 0], [-6464, 6464, -732, 732], [-21160, 0, 0, 140], [21636, -21636, -853, 853], [0, -16868, -828, 0], [-5922, 0, 0, -456], [0, 15228, 1820, 0], [-6738, 6738, 4468, -4468], [0, 4345, -42, 0], [19741, -19741, -1268, 1268], [10740, -10740, 796, -796], [5688, 0, 0, -3540], [1420, -1420, -2754, 2754], [6270, 0, 0, -1081], [9535, -9535, -2954, 2954], [-12906, 0, 0, -1620], [-15608, 15608, -1458, 1458], [0, -3890, -4728, 0], [-12004, 0, 0, 192], [0, 6960, -444, 0], [0, 24040, -1286, 0], [2738, 0, 0, -504], [0, 588, -1815, 0], [0, 7429, -1948, 0], [486, 0, 0, 3393], [0, -11576, -3882, 0], [0, -3714, -4725, 0], [18012, 0, 0, 4723], [11432, 0, 0, -3528], [-3606, 3606, -4997, 4997], [0, -3452, 512, 0], [-9870, 0, 0, -2528], [-17374, 0, 0, 376], [4326, -4326, -8076, 8076], [-34886, 34886, -1344, 1344], [-13260, 13260, -3813, 3813], [0, -10124, -4760, 0], [5502, 0, 0, 1036], [0, 17137, 2074, 0], [-21648, 0, 0, 2108], [2372, 0, 0, 172], [0, 27330, -3452, 0], [-10400, 10400, 604, -604], [9186, -9186, -5508, 5508], [3332, 0, 0, 5262], [34836, -34836, 1293, -1293], [24335, 0, 0, 1448], [0, -6498, 815, 0], [12282, -12282, 3708, -3708], [-29196, 0, 0, 531], [0, -19136, 3702, 0], [-23562, 0, 0, 4404], [0, 19080, -5548, 0], [18516, -18516, 4240, -4240], [-5632, 0, 0, 966], [-2099, 2099, 4014, -4014]];
    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_4_c_j();".
// 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_4_c_j(:prec:=4)
    chi := MakeCharacter_162_c();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 4));
    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_4_c_j();".
// 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_4_c_j( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_162_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<5,R![81, -108, 135, -12, 1]>],Snew);
    return Vf;
end function;