
// Make newform 160.6.c.b in Magma, downloaded from the LMFDB on 23 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_160_c();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_160_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_160_6_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_160_6_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, 0, 3, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, -8, 0, -4], [0, 22, 0, 6], [15, 0, 10, 0]];
    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_160_c();"
function MakeCharacter_160_c()
    N := 160;
    order := 2;
    char_gens := [31, 101, 97];
    v := [2, 2, 1];
    // 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_160_c_Hecke();"
function MakeCharacter_160_c_Hecke(Kf)
    N := 160;
    order := 2;
    char_gens := [31, 101, 97];
    char_values := [[1, 0, 0, 0], [1, 0, 0, 0], [-1, 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 := 6;
    raw_aps := [[0, 0, 0, 0], [0, 5, 1, 0], [0, 0, 0, 5], [0, 46, 1, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 664, 237, 0], [1686, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, -1882], [0, 1123, -1439, 0], [0, 3866, -1203, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 4674], [0, -12853, -1195, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 21187, 3117, 0], [-149286, 0, 0, 0], [0, 0, 0, 0], [137502, 0, 0, 0], [0, -6016, 13205, 0], [0, -27779, 10317, 0], [0, 0, 0, 7554], [0, 0, 0, 0], [0, -48796, 13433, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 38602], [0, 0, 0, 0], [0, 0, 0, 0], [0, 51641, -36967, 0], [0, -27820, 43437, 0], [0, 0, 0, 0], [0, 0, 0, 0], [-320402, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 214600, -47519, 0], [0, -270511, 10089, 0], [1066814, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 127086], [0, 0, 0, 0], [0, 0, 0, 0], [0, -208550, 113769, 0], [0, 0, 0, -121390], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, -60746], [0, -393019, -109195, 0], [0, 0, 0, 0], [0, -290057, 171589, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, -217237, 264969, 0], [2954614, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, -868268, -131039, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 680252, 290889, 0], [0, 0, 0, 529466], [0, 0, 0, 0], [4668498, 0, 0, 0], [0, 0, 0, -532458], [0, 0, 0, 0], [0, 0, 0, 361818], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 732857, 473997, 0], [0, 0, 0, -271010], [0, 0, 0, 0], [-4547802, 0, 0, 0], [0, 1616746, -40547, 0], [0, 1563733, 260649, 0], [0, 0, 0, 0], [0, 1692170, 325913, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, -814048, 628077, 0], [7230486, 0, 0, 0], [-5305398, 0, 0, 0], [0, -1027343, -731291, 0], [-13584202, 0, 0, 0], [0, 2260477, -293759, 0], [0, 0, 0, 0], [0, 630001, 940785, 0], [0, 0, 0, -584906], [0, 0, 0, 0], [0, 0, 0, 0], [0, -2392237, 544785, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 1575702], [0, -486982, -1145995, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 680702], [0, 381583, 1326013, 0], [0, 3527638, -369615, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, -1962342], [0, 0, 0, 0], [0, 0, 0, 0], [0, 4062455, -400311, 0], [0, 0, 0, 0], [0, 0, 0, 1909010], [-23476514, 0, 0, 0], [0, 0, 0, 0], [0, -2349310, -1664623, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, -3248674, -1608015, 0], [0, 0, 0, 0], [0, 0, 0, 0], [-29598198, 0, 0, 0], [-31382414, 0, 0, 0], [0, 0, 0, 0], [0, 3926875, 1812733, 0], [0, 0, 0, 0], [1066986, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, -861574], [0, -1800244, -2420395, 0], [0, -1560233, -2464815, 0], [0, 0, 0, -3267006], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 5830094, 2006157, 0], [0, 0, 0, 0], [0, 0, 0, -2164786], [0, 3403973, 2765273, 0], [0, -7039922, -1795671, 0], [0, -2288659, 2941181, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, -4704898], [0, 0, 0, 0], [31941798, 0, 0, 0], [0, -6369205, 2439597, 0], [0, 0, 0, 0], [0, -8754140, 1662973, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, -5270446, -3494415, 0], [0, 0, 0, 0], [0, 0, 0, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_160_c_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_160_6_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_160_6_c_b(:prec:=4)
    chi := MakeCharacter_160_c();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 6));
    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_160_6_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_160_6_c_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_160_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<3,R![55696, 0, 972, 0, 1]>],Snew);
    return Vf;
end function;