
// Make newform 160.6.a.c in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_160_a();"
// 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_a_c();".
// 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_a_c();".
// 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 := [-21, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [-2, 4]];
    Rf_basisdens := [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_a();"
function MakeCharacter_160_a()
    N := 160;
    order := 1;
    char_gens := [31, 101, 97];
    v := [1, 1, 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;

function MakeCharacter_160_a_Hecke(Kf)
    return MakeCharacter_160_a();
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, -1], [-25, 0], [0, 3], [0, 26], [506, 0], [-1838, 0], [0, 112], [0, -103], [-4530, 0], [0, -198], [338, 0], [-6330, 0], [0, -985], [0, 219], [-15486, 0], [0, -396], [-16750, 0], [0, 741], [0, 2346], [-20806, 0], [0, 3788], [0, -5765], [-18310, 0], [49978, 0], [153598, 0], [0, -11651], [0, -11091], [156386, 0], [-179814, 0], [0, 9103], [0, 16838], [-109982, 0], [0, -9844], [394074, 0], [0, -29126], [121402, 0], [0, 9971], [0, 1371], [-554966, 0], [0, -23124], [-803138, 0], [0, -37354], [-548974, 0], [-705622, 0], [0, 11264], [0, -34954], [0, 48837], [0, -30527], [486150, 0], [-1434414, 0], [0, 908], [1166750, 0], [0, 56610], [532602, 0], [0, -1715], [-1288286, 0], [0, 30214], [1151802, 0], [-1680730, 0], [0, 72187], [1655426, 0], [0, 50957], [0, 126990], [-1360454, 0], [-1797438, 0], [0, -14850], [956498, 0], [0, 222841], [4433710, 0], [-2238526, 0], [0, 182464], [0, 165603], [3879194, 0], [0, -15488], [0, 124637], [-3498294, 0], [-510822, 0], [-1757678, 0], [-2559106, 0], [0, 10908], [4759450, 0], [0, 29678], [-1722406, 0], [0, -28576], [0, 281647], [-829754, 0], [-6958438, 0], [-6580202, 0], [0, 86753], [0, 242133], [0, -217604], [0, -273017], [0, -460446], [0, 442120], [0, -381467], [-7887650, 0], [10749978, 0], [0, 235843], [-1579002, 0], [0, -81679], [3878658, 0], [0, 383775], [-6258914, 0], [0, 90142], [11753882, 0], [0, -439851], [4723794, 0], [0, -58852], [6249430, 0], [0, 570187], [15993226, 0], [-83598, 0], [0, -932552], [0, -871006], [9252830, 0], [0, -769137], [0, 714271], [8357314, 0], [0, -465212], [8776570, 0], [-11728806, 0], [-8894982, 0], [0, -475785], [0, 821162], [-1302590, 0], [-13329050, 0], [0, 190492], [0, 194195], [-5426486, 0], [0, -40156], [0, -1338639], [0, 495994], [285562, 0], [-10630038, 0], [-18662270, 0], [-6189734, 0], [0, 1119745], [-2897918, 0], [11124890, 0], [0, 747762], [-27312150, 0], [0, -1429447], [0, -430743], [30756114, 0], [0, -341868], [15278346, 0], [-13935982, 0], [0, -1907860], [0, 1034045], [39999322, 0], [-7299810, 0], [0, 227119], [0, 287219], [0, 1050369], [0, 2104250], [0, 2215076], [25290294, 0], [-32086638, 0], [29205142, 0], [0, 324613], [3736986, 0], [0, -638641], [0, -460690], [38601018, 0], [0, 1102597], [0, -1825774], [-49546638, 0], [-24467630, 0], [-6097734, 0], [0, -294272], [-2520938, 0], [0, -3361770], [22147434, 0], [0, 1193968], [49496970, 0], [0, -2740722], [-1150818, 0], [0, -1016711], [53506754, 0], [0, 897707], [0, 531278], [-56869406, 0], [43444698, 0], [0, -414387], [-978170, 0], [1349778, 0], [0, 2064223], [-44626274, 0], [0, 2952282], [-7971814, 0], [0, -1905809], [0, 933858], [28097810, 0], [0, 2113897], [57340066, 0], [-24686370, 0], [-44490846, 0], [52023138, 0], [0, -2072651], [-61657490, 0], [0, 219942], [-19772478, 0], [38028370, 0], [0, -3132588], [53967642, 0], [0, 3274040], [0, -3049], [114455930, 0], [0, 50870], [-87340478, 0], [-10789590, 0], [0, -760987], [0, -3306003], [0, 4991836], [37634710, 0], [0, -1470289], [-94091742, 0], [0, -180045], [65273306, 0], [53114090, 0], [0, -2848652], [-13441710, 0], [0, 5382809], [0, 405929], [14893946, 0], [16237514, 0], [0, 6292152], [0, 7118543], [0, 2178702], [-22445574, 0], [0, -7058704], [0, -8744690], [-121577770, 0], [0, 7921091], [0, -5685529], [-155202234, 0], [33408994, 0], [0, 7521752], [0, -1118802], [0, 3956371], [0, -6822094], [0, -349975], [-129707730, 0], [-77891566, 0], [0, -7232648], [0, -1179353], [0, -454718], [0, 5128356], [0, 860977], [-57394422, 0], [15565202, 0], [0, -5086665], [-39484066, 0], [81813114, 0], [0, -4367928], [164799998, 0], [0, -9378911], [73427082, 0], [-48153638, 0], [0, 1805485], [0, -5370807], [-193868890, 0], [-56555134, 0], [120856722, 0], [0, 1482488], [-173979490, 0], [-35772102, 0], [0, 7808447], [229240546, 0], [37686342, 0], [0, 2468869], [55162706, 0], [0, -508176], [37589082, 0], [0, -13497863], [0, 7336793], [-33207170, 0], [246081990, 0], [0, 11829198], [0, -13731147], [0, -9129146], [0, -13695801], [160819182, 0], [0, -4405779], [0, 8788346], [165053746, 0], [-17951542, 0], [0, -8409004], [-18034586, 0], [-86092110, 0], [0, 5851801], [-181922886, 0], [0, -4015958], [104176634, 0], [-127143214, 0], [0, 10015306], [-73354414, 0], [0, -6043080], [0, 16024677], [115869474, 0], [-2999078, 0], [0, 14431588], [0, 3013671], [0, 6174194], [108426058, 0], [0, 5677913], [-75541730, 0], [0, -5030904], [-34108494, 0], [0, 13135885], [327793590, 0], [-69228878, 0], [0, 4710359], [0, -10350317], [387130090, 0], [0, 12438176], [0, 3912258], [-293215334, 0], [32523334, 0], [0, -9471430], [-374760622, 0], [-342515310, 0], [0, 3907281], [-112619966, 0], [409344110, 0], [0, -17995816], [0, 18905639], [0, 7611147], [-242604126, 0], [-51420110, 0], [327025162, 0], [0, -23797964], [0, 12398011], [0, -2873782], [0, 8765957], [-44625614, 0], [-35658294, 0], [372949430, 0], [0, -13666505], [-122496734, 0], [-76515798, 0], [-15194166, 0], [0, -4708830], [-79399374, 0], [0, 26527816], [10021130, 0], [0, -1009639], [0, -27756342], [-72536982, 0], [0, 1921302], [-4943558, 0], [161658850, 0], [0, 15050345], [-36651690, 0], [453753354, 0], [0, -6487420], [0, 12168582], [-346519302, 0], [0, 12445969], [-379185278, 0], [85148218, 0], [0, 16628467], [0, -13612748], [0, -1645671], [-276659214, 0], [428468778, 0], [0, -9820059], [609513430, 0], [0, -13140714], [0, -17650696], [0, -15402863], [-347572006, 0], [0, 13997850], [84920938, 0], [0, -17089128], [0, -16369718], [105749554, 0], [166614406, 0], [217728418, 0], [-150635338, 0], [66252114, 0], [0, -10471849], [-19080622, 0], [0, -11330592], [0, 5717505], [0, 24329590], [-693470942, 0], [0, -7013457], [0, 27554955], [-727203834, 0], [275129994, 0], [0, -5021396], [0, 16341517], [0, 39057530], [315158434, 0], [0, 30239084], [-30308390, 0], [0, 8384218], [379990810, 0], [-30454414, 0], [365854146, 0], [0, 6493795], [-102289502, 0], [261655466, 0], [0, -3940406], [-254845198, 0], [317523138, 0], [0, -6430149], [0, 8417668], [344530914, 0], [-235892702, 0], [0, 29910891], [0, 4868038], [-649760502, 0], [-290147882, 0], [0, -18467880], [0, -12953821], [57579258, 0], [0, -26141255], [-219754126, 0], [296897738, 0], [0, -37529333], [0, -31497780], [330169066, 0], [796728042, 0], [0, -35209929], [208508334, 0], [0, -27434018], [0, -1407960]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_160_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_160_6_a_c();".
// 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_a_c(:prec:=2)
    chi := MakeCharacter_160_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 6));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(2999) - 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_a_c();".
// 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_a_c( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_160_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<3,R![-340, 0, 1]>],Snew);
    return Vf;
end function;