
// Make newform 162.7.d.f in Magma, downloaded from the LMFDB on 17 April 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_7_d_f();".
// 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_7_d_f();".
// 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 := 7;
    raw_aps := [[0, 0, 0, 4, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 95, -25, 0], [0, 1, 1, 0, 0, 0, 0, 0], [0, 0, 0, 991, 0, 0, -290, 290], [-959, 959, -362, 0, 362, 0, 0, 0], [0, 0, 0, 1795, 0, -1795, 0, -193], [2561, 0, 0, 0, 547, 0, 0, 0], [0, 0, 0, 0, 0, 6385, -2600, 0], [0, 0, 0, -5672, 0, 0, 9805, -9805], [10024, -10024, 2826, 0, -2826, 0, 0, 0], [-5050, 0, 0, 0, 2303, 0, 0, 0], [0, 0, 0, 0, 0, 33629, -23146, 0], [0, -46235, -14799, 0, 0, 0, 0, 0], [0, 0, 0, 60168, 0, 0, 2502, -2502], [0, 0, 0, 20681, 0, -20681, 0, 36874], [0, 0, 0, 0, 0, -72788, 16858, 0], [0, -152264, -32409, 0, 0, 0, 0, 0], [502243, -502243, -5307, 0, 5307, 0, 0, 0], [0, 0, 0, -242831, 0, 242831, 0, 65072], [131456, 0, 0, 0, -38535, 0, 0, 0], [0, 212179, -131623, 0, 0, 0, 0, 0], [0, 0, 0, -388866, 0, 0, 133176, -133176], [0, 0, 0, 43270, 0, -43270, 0, 245729], [0, -905432, 93770, 0, 0, 0, 0, 0], [0, 0, 0, 136307, 0, 0, 109304, -109304], [-1318304, 1318304, -118608, 0, 118608, 0, 0, 0], [0, 0, 0, -162106, 0, 162106, 0, -132338], [-310705, 0, 0, 0, 199200, 0, 0, 0], [0, 0, 0, 0, 0, 883227, 3285, 0], [510509, 0, 0, 0, 416361, 0, 0, 0], [0, 0, 0, 0, 0, -97513, 850436, 0], [0, 0, 0, -1537412, 0, 0, 146917, -146917], [-1413170, 1413170, 406934, 0, -406934, 0, 0, 0], [0, 0, 0, 0, 0, -1311704, 970099, 0], [0, -360272, 649908, 0, 0, 0, 0, 0], [-4395566, 4395566, 228813, 0, -228813, 0, 0, 0], [-1712404, 0, 0, 0, -143950, 0, 0, 0], [0, 0, 0, 0, 0, 712197, 688272, 0], [0, 0, 0, -1455060, 0, 0, -474927, 474927], [0, 0, 0, 634694, 0, -634694, 0, 1265296], [2725874, 0, 0, 0, -136894, 0, 0, 0], [0, 0, 0, -6040807, 0, 0, 1081160, -1081160], [-2830259, 2830259, -793998, 0, 793998, 0, 0, 0], [0, 0, 0, -1538834, 0, 1538834, 0, 871511], [-2148844, 0, 0, 0, 211624, 0, 0, 0], [5268469, -5268469, -52655, 0, 52655, 0, 0, 0], [0, -4913453, 149301, 0, 0, 0, 0, 0], [0, 0, 0, -678891, 0, 0, 3588078, -3588078], [9045799, -9045799, -1075584, 0, 1075584, 0, 0, 0], [0, 0, 0, 5818760, 0, -5818760, 0, 1531765], [0, 0, 0, 0, 0, 1462356, -3658440, 0], [0, -16298360, -1735523, 0, 0, 0, 0, 0], [0, 0, 0, 8271611, 0, -8271611, 0, 1851904], [0, 0, 0, 0, 0, -3243756, -4246017, 0], [0, 0, 0, 12795002, 0, 0, 429350, -429350], [0, 0, 0, 4415213, 0, -4415213, 0, -980381], [-21194287, 0, 0, 0, -1248909, 0, 0, 0], [0, 1377052, -1836552, 0, 0, 0, 0, 0], [0, 0, 0, 9145201, 0, 0, -1934999, 1934999], [23254090, -23254090, -1660578, 0, 1660578, 0, 0, 0], [0, 0, 0, 0, 0, -30368015, 1650103, 0], [18733502, 0, 0, 0, -4569672, 0, 0, 0], [0, 0, 0, 0, 0, -4743184, 8186942, 0], [0, 30232693, 86578, 0, 0, 0, 0, 0], [0, 0, 0, -15405907, 0, 0, -6608455, 6608455], [0, 14387773, 5341427, 0, 0, 0, 0, 0], [-22305122, 22305122, -4280800, 0, 4280800, 0, 0, 0], [0, 0, 0, 0, 0, -15756903, -466806, 0], [0, -19656296, 8633140, 0, 0, 0, 0, 0], [0, 0, 0, -17957351, 0, 0, -9977576, 9977576], [0, 0, 0, -19637523, 0, 19637523, 0, -9558198], [0, 23967160, 11061534, 0, 0, 0, 0, 0], [-49124876, 49124876, 5166742, 0, -5166742, 0, 0, 0], [16205948, 0, 0, 0, -11742250, 0, 0, 0], [0, 0, 0, 0, 0, 11567345, 16722614, 0], [0, 0, 0, 16376789, 0, 0, 2717918, -2717918], [-3684166, 0, 0, 0, 16445013, 0, 0, 0], [0, 0, 0, 0, 0, -64674880, 6935597, 0], [-67040, 67040, 12867431, 0, -12867431, 0, 0, 0], [0, 0, 0, 0, 0, 47774208, 6809886, 0], [0, -71045729, -940856, 0, 0, 0, 0, 0], [0, 0, 0, -6716738, 0, 6716738, 0, -27355660], [34890437, 0, 0, 0, 6849270, 0, 0, 0], [0, 18463480, -1398366, 0, 0, 0, 0, 0], [0, 0, 0, 44130276, 0, 0, 21089490, -21089490], [0, 0, 0, -44439027, 0, 44439027, 0, 6673362], [0, 25912312, -21088413, 0, 0, 0, 0, 0], [0, 0, 0, -47485697, 0, 0, -11836358, 11836358], [-7879820, 7879820, -23373650, 0, 23373650, 0, 0, 0], [0, 0, 0, -2658850, 0, 2658850, 0, 29890708], [0, 0, 0, -2825955, 0, 0, 37653270, -37653270], [28390190, 0, 0, 0, -3251204, 0, 0, 0], [0, 0, 0, 0, 0, 125908831, -8846912, 0], [61384255, -61384255, -6174819, 0, 6174819, 0, 0, 0], [0, 0, 0, -135962706, 0, 135962706, 0, 9250158], [0, 0, 0, 0, 0, -119637097, -624610, 0], [0, 0, 0, -83069621, 0, 83069621, 0, 19323818], [12608867, 0, 0, 0, -18598863, 0, 0, 0], [48995261, 0, 0, 0, 727340, 0, 0, 0], [0, -56804816, -1089210, 0, 0, 0, 0, 0], [0, 0, 0, -66916346, 0, 66916346, 0, 23694107], [0, 0, 0, 0, 0, 89082654, -6206874, 0], [0, 0, 0, -11800183, 0, 0, -33649819, 33649819], [210647566, -210647566, 2969924, 0, -2969924, 0, 0, 0], [117209639, 0, 0, 0, 14647194, 0, 0, 0], [0, 0, 0, 57915197, 0, 0, -11050618, 11050618], [0, 0, 0, 229600786, 0, -229600786, 0, -11532217], [0, 0, 0, 0, 0, 235366084, -8187770, 0], [0, -35789735, -23055348, 0, 0, 0, 0, 0], [-137218679, 137218679, 16471805, 0, -16471805, 0, 0, 0], [83288216, 0, 0, 0, 7477770, 0, 0, 0], [0, 0, 0, 0, 0, -177416854, -28814851, 0], [0, 83991274, 67771848, 0, 0, 0, 0, 0], [14690168, 0, 0, 0, -19111768, 0, 0, 0], [0, 0, 0, -48179990, 0, 0, -10640903, 10640903], [130749820, -130749820, 29159748, 0, -29159748, 0, 0, 0], [0, 0, 0, 209325909, 0, -209325909, 0, -50838564], [0, 0, 0, 0, 0, 77497549, 3507646, 0], [0, 0, 0, 72762779, 0, 0, 91833056, -91833056], [-478491662, 478491662, -11461953, 0, 11461953, 0, 0, 0], [0, 218392807, 34613366, 0, 0, 0, 0, 0], [0, 0, 0, -75531193, 0, 0, -100305370, 100305370], [0, 0, 0, -220868094, 0, 220868094, 0, -78709650], [0, 229073587, 11282679, 0, 0, 0, 0, 0], [0, 0, 0, 46948655, 0, -46948655, 0, -49416797], [0, -80590937, 61688096, 0, 0, 0, 0, 0], [0, 0, 0, -49206825, 0, 49206825, 0, -11025234], [0, 382705837, -39446271, 0, 0, 0, 0, 0], [317316058, -317316058, -39510114, 0, 39510114, 0, 0, 0], [87153500, 0, 0, 0, -115434384, 0, 0, 0], [0, 0, 0, 0, 0, 266320140, -60995508, 0], [-21739589, 21739589, -73757659, 0, 73757659, 0, 0, 0], [368215940, 0, 0, 0, -54569772, 0, 0, 0], [0, 0, 0, 0, 0, 102947454, -55817571, 0], [245681095, -245681095, 36859894, 0, -36859894, 0, 0, 0], [0, 0, 0, 3900870, 0, -3900870, 0, -20122929], [179789569, -179789569, -26857869, 0, 26857869, 0, 0, 0], [0, 0, 0, 0, 0, -33589860, -46140975, 0], [0, 0, 0, -420400436, 0, 420400436, 0, -63512167], [58238120, 0, 0, 0, 12509352, 0, 0, 0], [0, 0, 0, 147078053, 0, 0, 79986209, -79986209], [679050022, -679050022, 40780606, 0, -40780606, 0, 0, 0], [0, 0, 0, -260052995, 0, 260052995, 0, -23293888], [-113485036, 0, 0, 0, -61963928, 0, 0, 0], [0, 0, 0, -207426243, 0, 0, 276676338, -276676338], [0, -312930722, -73768344, 0, 0, 0, 0, 0], [0, 0, 0, -140791122, 0, 0, -13545939, 13545939], [-354032108, 354032108, 7657754, 0, -7657754, 0, 0, 0], [0, 0, 0, 306522475, 0, -306522475, 0, -14538220], [549178876, -549178876, 116743007, 0, -116743007, 0, 0, 0], [0, 0, 0, 249445229, 0, -249445229, 0, 144951538], [803270354, 0, 0, 0, -39876530, 0, 0, 0], [0, 0, 0, 0, 0, -93507415, -155228500, 0], [0, -602058200, -74405002, 0, 0, 0, 0, 0], [0, 0, 0, 463764189, 0, 0, -32479866, 32479866], [75567827, 0, 0, 0, -116701815, 0, 0, 0], [0, 0, 0, 307941171, 0, 0, 109147791, -109147791], [857179673, 0, 0, 0, 17462318, 0, 0, 0], [0, 0, 0, 0, 0, 59817640, 208144333, 0], [0, 0, 0, -411462303, 0, 0, -206684172, 206684172], [0, 0, 0, -132363990, 0, 132363990, 0, -146287125], [-189646571, 189646571, 157738065, 0, -157738065, 0, 0, 0], [0, 0, 0, -254836455, 0, 254836455, 0, 74840064], [0, 0, 0, 0, 0, -127611797, 216878014, 0], [0, 0, 0, -789209086, 0, 0, 57261530, -57261530], [657559955, 0, 0, 0, 159310857, 0, 0, 0], [0, 644628958, -10863657, 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_7_d_f();".
// 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_7_d_f(:prec:=8)
    chi := MakeCharacter_162_d();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 7));
    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_7_d_f();".
// 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_7_d_f( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_162_d();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,7,sign)));
    Vf := Kernel([<5,R![717201875390625, 0, -1181025562500, 0, 1918029375, 0, -44100, 0, 1]>],Snew);
    return Vf;
end function;