
// Make newform 160.6.a.b in Magma, downloaded from the LMFDB on 23 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_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_a_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, -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, -3], [-25, 0], [0, -31], [0, -58], [154, 0], [178, 0], [0, -216], [0, -589], [4110, 0], [0, -706], [7442, 0], [7270, 0], [0, 4005], [0, 1657], [32226, 0], [0, -7612], [26770, 0], [0, -11137], [0, -12098], [-18534, 0], [0, 19396], [0, 17585], [-107590, 0], [-108838, 0], [59198, 0], [0, 25247], [0, -8953], [-139614, 0], [-43046, 0], [0, 35189], [0, 59866], [-112158, 0], [0, -32948], [-174566, 0], [0, -77202], [-26502, 0], [0, -31687], [0, 91913], [595946, 0], [0, 67292], [217022, 0], [0, 204882], [864114, 0], [432522, 0], [0, 177808], [0, 101322], [0, 96231], [0, -251341], [-812410, 0], [846194, 0], [0, 12676], [1275710, 0], [0, 11390], [1648058, 0], [0, -116945], [-1937886, 0], [0, -223902], [-445702, 0], [1246470, 0], [0, 509601], [2454274, 0], [0, 4631], [0, 10570], [-2791686, 0], [-471582, 0], [0, -691150], [-665838, 0], [0, 404523], [-2361810, 0], [1145346, 0], [0, 171568], [0, -893391], [4681306, 0], [0, -75416], [0, 133871], [3972426, 0], [-179398, 0], [6145042, 0], [-2645026, 0], [0, 482956], [1472090, 0], [0, 1484186], [-6278534, 0], [0, 545648], [0, 515741], [7602406, 0], [-1569382, 0], [-562602, 0], [0, 1089819], [0, 1144559], [0, -894828], [0, -376051], [0, -25922], [0, 1786320], [0, -1805961], [2834270, 0], [2975258, 0], [0, -1728231], [-9836602, 0], [0, 772803], [-7057598, 0], [0, -519875], [10194686, 0], [0, 2712274], [1463578, 0], [0, -1159233], [-10272174, 0], [0, 3114596], [-4814410, 0], [0, 2343401], [-3079766, 0], [1155218, 0], [0, -3954544], [0, 1213158], [11600510, 0], [0, 2141869], [0, -2865067], [-1586654, 0], [0, 4372836], [-7464710, 0], [-10969414, 0], [-6527078, 0], [0, 3452245], [0, 1070534], [-3318910, 0], [16004390, 0], [0, -3488396], [0, -2561295], [11326666, 0], [0, 2930468], [0, 931963], [0, -6469122], [8328698, 0], [4482922, 0], [1321410, 0], [-7248966, 0], [0, -1113645], [14867298, 0], [-684390, 0], [0, 7331854], [7172650, 0], [0, -297261], [0, 4314811], [7108114, 0], [0, 1843724], [18692074, 0], [-22447278, 0], [0, -725460], [0, 227055], [39676378, 0], [-24458370, 0], [0, -6958163], [0, -4192943], [0, -1134813], [0, 6341470], [0, -2143428], [-38221226, 0], [-9374222, 0], [3048982, 0], [0, -6617601], [15833754, 0], [0, -1943163], [0, -6293950], [-43408998, 0], [0, -10379209], [0, 10388262], [13596818, 0], [-62656750, 0], [-35429286, 0], [0, -5271704], [37702422, 0], [0, 2653570], [62340106, 0], [0, 5314736], [-7215030, 0], [0, -6018654], [6770462, 0], [0, -8695053], [4416194, 0], [0, -834519], [0, 17016946], [12301186, 0], [-18691398, 0], [0, 266559], [-40168890, 0], [73121362, 0], [0, 10581789], [65098366, 0], [0, -7041346], [48916634, 0], [0, -1091587], [0, -11799314], [1567890, 0], [0, 7049771], [64822914, 0], [-62669890, 0], [13473346, 0], [55202402, 0], [0, 6434247], [-68159570, 0], [0, 12119394], [-6441502, 0], [-12191150, 0], [0, 17138564], [-19180902, 0], [0, 17302920], [0, 11542213], [29201850, 0], [0, -3494950], [26375778, 0], [20276970, 0], [0, 27278359], [0, -19128409], [0, 2173892], [-101195850, 0], [0, -9564747], [-83593182, 0], [0, 6918385], [-94205126, 0], [-7662230, 0], [0, -17733044], [71600530, 0], [0, -4321053], [0, 4654667], [120278906, 0], [-83804694, 0], [0, -6795256], [0, 18627909], [0, 14578914], [-53132966, 0], [0, 1638472], [0, -6995270], [-21467850, 0], [0, 5225113], [0, 23542813], [-22460954, 0], [83494146, 0], [0, -28447536], [0, -23576374], [0, -11397447], [0, 16984302], [0, -14685725], [93109550, 0], [-71285934, 0], [0, 34495864], [0, 6532861], [0, 33634574], [0, -3211788], [0, -39079669], [108841642, 0], [102202002, 0], [0, 27563485], [199371454, 0], [-75811334, 0], [0, -36401936], [-105572802, 0], [0, 27726627], [79070538, 0], [-53359142, 0], [0, -41654785], [0, -5423541], [98588710, 0], [-81170686, 0], [128642738, 0], [0, -48179904], [-42707170, 0], [104051898, 0], [0, -40681779], [128808354, 0], [-220690618, 0], [0, -11868673], [-71224846, 0], [0, 43575728], [200662618, 0], [0, -3898509], [0, -19350261], [-82008770, 0], [17263270, 0], [0, -26270414], [0, 45636439], [0, 15245938], [0, -58004083], [-284513938, 0], [0, 41754823], [0, 32456702], [-289452526, 0], [-100589718, 0], [0, -18113268], [89134214, 0], [-66010510, 0], [0, 51289563], [69696346, 0], [0, -5755946], [77647866, 0], [-304044014, 0], [0, -3098738], [188313554, 0], [0, 32165040], [0, 38727231], [29009186, 0], [311784858, 0], [0, -41242324], [0, 2316053], [0, -49546962], [267450922, 0], [0, -46435541], [-95895330, 0], [0, -48769688], [138218994, 0], [0, 30319455], [52706230, 0], [338747442, 0], [0, -41123323], [0, 70511089], [68993450, 0], [0, -49189128], [0, -40868074], [128321754, 0], [-112814746, 0], [0, 84526710], [381366482, 0], [137423250, 0], [0, -25837557], [33970306, 0], [-313113970, 0], [0, 81328608], [0, -2123003], [0, -10089239], [332718786, 0], [111764210, 0], [186053898, 0], [0, 34483452], [0, 41007313], [0, 56333686], [0, 89588271], [-142115214, 0], [-204435766, 0], [334679830, 0], [0, -67363155], [177765154, 0], [-155496662, 0], [-12057846, 0], [0, -112749050], [320325234, 0], [0, -96690768], [-452847350, 0], [0, -55870677], [0, -2551954], [-199163958, 0], [0, 51218154], [-51088262, 0], [240579810, 0], [0, -61741805], [237990870, 0], [-65877654, 0], [0, -48835060], [0, -75191286], [-175349798, 0], [0, -43739333], [-420231262, 0], [-683462, 0], [0, 87087521], [0, 115706404], [0, -76329413], [366079314, 0], [-171267318, 0], [0, 12500663], [-147680650, 0], [0, 11673642], [0, -61568592], [0, 47793131], [-362839526, 0], [0, 59179470], [390591882, 0], [0, -47344416], [0, 29871694], [-455734734, 0], [-313613274, 0], [591844962, 0], [-318450378, 0], [139437586, 0], [0, 113712573], [-155670318, 0], [0, 135410616], [0, 76977995], [0, -108879470], [-356042398, 0], [0, 65227869], [0, -135305175], [235383846, 0], [-625824694, 0], [0, -57623892], [0, -124207529], [0, 35398350], [305864866, 0], [0, -31081692], [591461850, 0], [0, -15454074], [-303318630, 0], [621697586, 0], [80902754, 0], [0, -104005135], [-578925918, 0], [-87828054, 0], [0, -121165602], [442628818, 0], [256832578, 0], [0, -14313807], [0, 174187876], [118962466, 0], [171470562, 0], [0, -60482767], [0, -50356454], [786446442, 0], [163164438, 0], [0, -150131480], [0, -30472223], [53490842, 0], [0, -10178445], [-62269966, 0], [-267952278, 0], [0, 8573641], [0, 48545100], [224606954, 0], [262537258, 0], [0, -25931067], [382426254, 0], [0, -6624686], [0, -67615640]];
    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_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_a_b(: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_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_a_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_160_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<3,R![-180, 0, 1]>],Snew);
    return Vf;
end function;