
// Make newform 4.10.a.a in Magma, downloaded from the LMFDB on 18 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_4_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_4_10_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_4_10_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_4_a();"
function MakeCharacter_4_a()
    N := 4;
    order := 1;
    char_gens := [3];
    v := [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_4_a_Hecke(Kf)
    return MakeCharacter_4_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 := 10;
    raw_aps := [[0], [228], [-666], [-6328], [-30420], [-32338], [590994], [34676], [1048536], [4409406], [-7401184], [10234502], [18352746], [-252340], [-49517136], [-66396906], [-61523748], [35638622], [181742372], [90904968], [-262978678], [-116502832], [-9563724], [611826714], [-259312798], [1565549766], [377094824], [-2177171316], [1508114702], [-1453545486], [2436793472], [-1433578140], [930903498], [4843158956], [8532694134], [-7145151400], [-3382387522], [-901514620], [4056052968], [-1027601586], [14847209748], [25326997910], [-16165599552], [-1801886014], [-18697917402], [28988997128], [-19798972876], [-67876825120], [54560580804], [46395169094], [-391388886], [90653840496], [-67766317966], [54716262300], [-34089989886], [-71736053688], [2316102318], [80466212240], [-165643908874], [25717723866], [43312567484], [-48347327610], [137970582932], [-204451356168], [-174184416262], [-84246776226], [-288776811412], [135029772242], [-39190343940], [-45881779330], [529589509218], [-45489271896], [245166676208], [-160289709994], [-355772343268], [-497007817344], [-594268284186], [-118575136978], [-527597710830], [-89687206054], [926538081156], [1226924410886], [-956151121104], [74284069682], [-166517995912], [641581356636], [-277232914494], [755228037386], [915740166510], [-635894424496], [617286487860], [277942362336], [-499400167384], [2062408293900], [-1219121486764], [1804298344632], [-203239213794], [-693093244086], [-1979559486676], [-2958993335746], [3275255805956], [-3764047394610], [2349868527252], [2667012654330], [-1723424732452], [1558564754498], [-2166226815636], [3562436548818], [1544068310040], [-1052773495270], [-4474705746592], [-6018616101178], [2161908043434], [-4169235770740], [4100365614392], [1871876798082], [-1341661665436], [-4943672484408], [2671390140462], [5500888739316], [1069367027318], [-4965673777246], [-2757390044922], [-5055280567092], [-2554141162732], [-8115520572450], [-2043939389914], [12423132718416], [-5374335694696], [128617519358], [13672589407940], [13158138050856], [-2086817962384], [5546599185878], [-1134509892678], [-2616018781438], [-53315438490], [-3307830934924], [-3868732816578], [7395256886634], [8928026222924], [-10553356281834], [-9160303545352], [-24409596202020], [9120505612382], [6075746579592], [16791715149110], [-27770698320102], [1854051098876], [8721418022496], [27622167739406], [-10018626813198], [9437017481684], [-3756353305032], [23679500941484], [19002986679312], [5569915092824], [35429330866338], [-24559193495062], [20051649283662], [-15129512809452], [21875058913914], [-33223929603832], [37143028994796], [14687195711058], [21874564829592], [42008880149216], [2697043219526]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_4_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_4_10_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_4_10_a_a(:prec:=1)
    chi := MakeCharacter_4_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 10));
    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_4_10_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_4_10_a_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_4_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,10,sign)));
    Vf := Kernel([],Snew);
    return Vf;
end function;