
// Make newform 245.6.a.a in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_245_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_245_6_a_a();".
// 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_245_6_a_a();".
// 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_245_a();"
function MakeCharacter_245_a()
    N := 245;
    order := 1;
    char_gens := [197, 101];
    v := [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_245_a_Hecke(Kf)
    return MakeCharacter_245_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 := [[-8], [-1], [-25], [0], [-453], [969], [-1637], [1550], [-1654], [-4985], [-1192], [-11018], [1728], [-10814], [-26237], [25936], [4580], [12488], [-15848], [51792], [-4846], [62765], [23644], [147300], [8343], [11878], [132439], [136842], [109485], [-200934], [330692], [-43982], [-99748], [-258930], [-498430], [-245803], [85478], [193026], [157783], [265659], [183660], [635048], [-226613], [46476], [204972], [953020], [-223523], [-1014801], [-999797], [851120], [1092696], [765905], [1210938], [-278262], [352998], [-1558094], [1219630], [-405792], [652442], [118827], [-1488011], [-1895801], [821853], [2095998], [-394571], [321422], [-2232588], [-3656558], [-1889618], [2693290], [1574679], [4055760], [4906283], [-3453364], [-4234660], [1864604], [-4815015], [-1213757], [5904417], [-4842890], [-270360], [3136477], [-1877033], [-3203566], [6272090], [724986], [-875985], [-832668], [-5921152], [682776], [5416673], [-1985990], [-1069738], [4592457], [1960655], [-3514831], [1452110], [4242398], [7560124], [1240647], [-1850568], [7775552], [-8377156], [-6155910], [7215132], [-13669927], [10068648], [-9806151], [8262575], [3594918], [13296913], [2503266], [1882542], [-8214870], [16115487], [-8505438], [13219079], [-1891152], [4905866], [13636695], [2223448], [4884836], [19878473], [4278696], [-9489252], [-5863853], [-2666705], [4466290], [7477568], [4397509], [28403555], [-19601184], [-2603443], [-29886928], [-12146982], [-4538450], [-19332951], [-16639237], [-18040917], [23389065], [22903698], [-18074463], [11798936], [2576502], [38433960], [12422190], [-7920666], [-14898342], [13874020], [12549996], [-28600198], [-40960752], [13050436], [-25359472], [19859482], [-19934448], [-11069535], [32568200], [-31568977], [36799728], [18845252], [-12511964], [-34234418], [26202748], [-8011138], [46012609], [-37582848], [-22206617], [-1763475], [-18114566], [-7944520], [10762018], [58372627], [53469166], [-54702210], [6561700], [30715007], [42017097], [21398284], [-41942560], [-13741588], [-59772172], [-11254074], [26596598], [-9107284], [18881990], [22033892], [54597679], [3615425], [65018648], [-50039006], [86245466], [-25233823], [-62707412], [-18924348], [-4915311], [-19457073], [-17050304], [5695723], [43325119], [-66190890], [51708758], [9674498], [34667690], [26414290], [42513103], [-44608590], [-20054884], [30830710], [-88064232], [-49964288], [-24665842], [53958976], [27214043], [4019310], [54471148], [-37360678], [-25175832], [-98996138], [50364506], [75944122], [111079870], [17227485], [20473006], [-9950637], [-42231130], [80136959], [41146735], [-91870937], [46929372], [-12774124], [105986650], [131339992], [-133995143], [-49941], [-138243737], [62406900], [78651416], [35622705], [-62952102], [-69468544], [-141705792], [104676059], [-162378770], [62388529], [183970450], [-175938232], [-124107882], [125554965], [39878186], [-111829318], [5191098], [4197792], [-91837360], [-117121266], [-68102465], [87990702], [-14353972], [192251833], [-117222727], [15425626], [104578682], [-19720000], [97862269], [-190312702], [-220765750], [82443825], [6636418], [27287176], [40368626], [-101925732], [93930872], [122277479], [-236983780], [11850198], [-186191341], [84273052], [10668530], [157172257], [155632198], [155355039], [-29561243], [45336528], [40820698], [5731043], [-9877873], [-13003074], [12602322], [189904400], [32732560], [-102938583], [118514913], [-37302004], [233834208], [-189509734], [187274820], [106186898], [-260784991], [44095740], [-114516257], [76940059], [-12666918], [-65516405], [229485576], [-220395063], [205921782], [-172864238], [-11986520], [23088200], [-149802924], [-78937056], [333203835], [4754382], [60090306], [-167897278], [-341664460], [62684710], [61086687], [-166852621], [-167584635], [227386618], [-335044628], [-195659442], [181093576], [186501326], [148783048], [-192538575], [-264970276], [262862892], [332119656], [-27788498], [-56813488], [413361710], [18820269], [399429812], [61019583], [-325433275], [403042674], [368065678], [-399633637], [-190891834], [127857732], [367934390], [-121092053], [-271603974], [-143128580], [-57525742], [127780372], [-306907342], [226718763], [330563948], [155921032], [408746577], [308754739], [-25260095], [274038654], [456457410], [118318158], [-7026958], [-130602734], [-51559488], [-85470252], [-362158788], [-3160785], [211805548], [383825506], [-170861277], [-134485154], [-13224203], [169261287], [-495403240], [590280276], [397325075], [-52703262], [233817602], [334130160], [-407165373], [-109306831], [51347530], [-131297507], [-200604642], [-2344694], [-270484448], [194398122], [-38791060], [-207623241], [61604087], [-205511767], [-326942604], [-212118627], [679340705], [58773239], [96785325], [414678548], [111259247], [1467736], [77522940], [619592260], [466631187], [-107215198], [63268300], [-393998904], [456222682], [-539123537], [477506700], [170002838], [53409702], [636389927], [143334724], [117092460], [-83832601], [-233632498], [-449384154], [818166532], [592582442], [256410088], [-411656465], [246589028], [-716805502], [-38899521], [-231216915], [783071398], [158463662], [-238489180], [-334066771], [779081643], [618161036], [1659330], [880498028], [154075080]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_245_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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