
// Make newform 560.6.a.h in Magma, downloaded from the LMFDB on 13 January 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_560_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_560_6_a_h();".
// 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_560_6_a_h();".
// 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
        Kf := Rationals();
    end if;
    return [Kf!elt[1] : elt in input];
end function;


// To make the character of type GrpDrchElt, type "MakeCharacter_560_a();"
function MakeCharacter_560_a()
    N := 560;
    order := 1;
    char_gens := [351, 421, 337, 241];
    v := [1, 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_560_a_Hecke(Kf)
    return MakeCharacter_560_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]];
    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], [17], [25], [49], [715], [331], [-1699], [1718], [3950], [4579], [-6756], [-16518], [18876], [-2258], [537], [-10984], [25956], [39188], [-4416], [31880], [-5018], [27977], [-37644], [-17216], [-63175], [-29250], [149189], [-83742], [105377], [-122754], [219196], [96682], [187288], [-176894], [-199078], [-471583], [-72054], [-385334], [542957], [370953], [754172], [303840], [186271], [92504], [-736368], [481620], [-189531], [22597], [998117], [-854644], [1258184], [706581], [616330], [-190842], [-1130942], [1673770], [-630942], [372476], [867010], [-1944981], [-1185013], [33669], [27043], [-2149186], [-2670525], [-250514], [-1058988], [-2850246], [-1891406], [-1042318], [-2303087], [1675944], [-94663], [-953536], [-3888244], [-2936356], [1703773], [1191105], [-3383303], [-1331846], [-5827856], [2474305], [-4618509], [58606], [-7042978], [-1468938], [-7484137], [170320], [-4286848], [-3383172], [-5180289], [8767786], [-270154], [-4855503], [2985759], [8287835], [6243066], [7495086], [-3809572], [7671563], [9538452], [-7450224], [-3366980], [-4055014], [-7315852], [-9768953], [-3756888], [2890479], [-13223301], [3473986], [-6450877], [8438202], [9455006], [-1431446], [10181251], [-17690798], [-18274799], [-1528968], [-9100882], [430119], [7652480], [-21840384], [13950403], [-22912068], [16912716], [-19008657], [16607899], [-5936102], [-17327624], [13982935], [11426251], [-12312624], [14309345], [-5345048], [6225682], [15788794], [-25045301], [1280197], [-11379807], [-17054239], [22149398], [-10106819], [18399300], [24805646], [-1197084], [31717078], [31823674], [22785302], [18596636], [27704584], [-24115042], [-12620704], [6018760], [-23690144], [11058326], [-3075728], [18901829], [-18145784], [-21735023], [18680796], [2247776], [-37329304], [-26186962], [39195656], [3039354], [15993651], [-3631864], [-43328747], [62467501], [10215534], [-36012856], [-25129274], [-19121665], [32910766], [-14168666], [816780], [-19498009], [-33034635], [3239676], [46320788], [-27784008], [-6309600], [-52031342], [42867754], [14627952], [40270086], [17503076], [29982921], [-15257575], [-76935948], [22177502], [11116750], [-80505135], [-48657840], [42932492], [82310511], [-93330721], [65143556], [-63673811], [-76691451], [-90027930], [-8468182], [51864470], [-13357094], [38523282], [2326469], [80543270], [43147200], [30147430], [96619828], [82908476], [90355002], [16885172], [-21751987], [-35890646], [-16323608], [72200078], [-48268068], [-110556926], [-87200070], [3723218], [-34626030], [119769453], [-20756866], [-38556995], [-59499954], [121255977], [52056531], [112688789], [60839908], [74270200], [83678582], [-58049032], [-33333311], [53133261], [-134308355], [-125361528], [-59782080], [-67877503], [144924610], [62530512], [-151217752], [110575713], [-38835874], [-167341953], [-9026118], [-142036224], [-85434166], [-94670795], [41380870], [-5063498], [165729926], [106885072], [-80316984], [4040698], [51963335], [-28045706], [100923020], [-120844405], [166943831], [11889422], [9409722], [-63476128], [-47730769], [79089078], [74998370], [115844869], [147811734], [-73550576], [-100825626], [81464464], [-94354756], [25254929], [106039108], [16971010], [5319761], [237178748], [199463090], [65360161], [177196058], [-76139491], [-193879535], [53660688], [-65898282], [202413325], [241748387], [224300042], [-164672522], [-39022904], [-69383992], [-182402723], [-275366137], [-5068656], [-82053460], [34579542], [-160920576], [47018814], [-28509725], [-99382420], [135308257], [-165559571], [350295322], [61445271], [-92851592], [-24055575], [-139874990], [-83564538], [87658632], [83119320], [-364302012], [128157576], [-140142185], [-15252978], [185179618], [-103784090], [-262012840], [-195897390], [233677707], [176862101], [-360767235], [134226710], [-120935000], [-79110142], [366284884], [184787054], [197088936], [256552193], [51527156], [29959728], [96231196], [-331195010], [254387212], [-112224542], [297802971], [-217971332], [-21374183], [-5650343], [372809598], [-487567442], [286637185], [-320517642], [-47705252], [400800598], [384427919], [256402830], [-489652228], [254939310], [-476163240], [-84371046], [-168188839], [299378316], [-218612420], [177851109], [-2878847], [-211495731], [-70980902], [-177030234], [189169758], [-79868922], [-214695518], [-6769588], [23158020], [35566128], [-418543665], [-519088772], [-261934170], [231631169], [83962306], [607838253], [-341004321], [41632004], [88100700], [149748255], [232358670], [363065578], [152052168], [-531358137], [139458495], [-328785722], [-552288757], [-193371334], [244402826], [-34740536], [-487159942], [612956216], [39658701], [-206679093], [627944947], [-101234900], [-293737873], [-259871903], [152179917], [303646365], [-442220300], [-333728629], [111834176], [482974832], [-584216472], [566113739], [-573646974], [131693120], [-278496288], [660040558], [147823937], [83096740], [57809658], [77980102], [2830855], [103033684], [-11479964], [-22871879], [-361248738], [-221428950], [-730687244], [-160478642], [-587667128], [721936499], [-259705564], [-87513626], [-838755555], [-259026367], [810210506], [-439997514], [-101836], [457540843], [-59442151], [-174504484], [904575066], [701805272], [261300604]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_560_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_560_6_a_h();".
// 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_560_6_a_h(:prec:=1)
    chi := MakeCharacter_560_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_560_6_a_h();".
// 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_560_6_a_h( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_560_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<3,R![-17, 1]>],Snew);
    return Vf;
end function;