
// Make newform 136.4.a.a in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_136_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_136_4_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_136_4_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
        poly := [-3, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [0, 2]];
    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_136_a();"
function MakeCharacter_136_a()
    N := 136;
    order := 1;
    char_gens := [103, 69, 105];
    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_136_a_Hecke(Kf)
    return MakeCharacter_136_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 := 4;
    raw_aps := [[0, 0], [2, 1], [-6, -2], [-18, -3], [-10, -13], [-42, 12], [17, 0], [16, 38], [22, 25], [-198, 26], [58, -37], [-70, -90], [-30, 4], [320, 18], [-248, -60], [118, -28], [288, -86], [-174, -146], [764, -16], [-438, 151], [-190, 44], [86, 173], [-512, -226], [-422, -332], [18, -56], [-242, 180], [-24, 216], [-534, 481], [258, 86], [-990, -48], [-2092, 6], [-710, 61], [-406, -316], [930, -347], [-1314, 344], [-988, 82], [982, 232], [3550, 11], [-1046, -177], [1098, -358], [-312, 202], [850, 818], [424, -500], [-814, -800], [194, -470], [-1486, 723], [4430, -445], [2748, 258], [3590, 471], [390, 1096], [-2270, -332], [-3648, 344], [-1550, 1304], [-4308, -388], [1138, -756], [-3172, 494], [-5270, -286], [3056, -960], [-6310, 350], [-4038, 728], [-4714, -853], [2830, -72], [3324, -1128], [-4350, 1211], [-5822, -4], [3554, 2030], [-4912, -630], [-2494, 264], [-162, -449], [-3314, -844], [1698, 2368], [-2460, -1462], [10526, -103], [5566, 2468], [-6854, -1047], [8292, 414], [12054, 336], [4194, 414], [5426, 1000], [4490, -1088], [-4858, -3305], [-7010, -1316], [166, -3435], [-8222, -196], [-6886, -569], [-556, 4008], [-9070, 184], [5562, 308], [-4210, -900], [-392, -2484], [1656, 3026], [-7622, 2675], [1782, -1023], [-8136, 3062], [-8570, -2313], [14478, 1325], [-538, -2528], [-4030, 2580], [572, -3412], [-12230, 2378], [-302, -783], [-12170, -1156], [6544, -3802], [4730, -600], [9662, -577], [-19822, -668], [22272, 786], [17362, -1552], [-368, 956], [-782, -1044], [13794, 1751], [926, 1344], [130, -2892], [-7714, 4983], [-5388, 1498], [5426, 2936], [15890, 713], [3528, -7864], [-3934, 7726], [-11756, -1508], [5014, -5788], [-22894, 1720], [11898, -1554], [-9022, 797], [10534, 647], [-3930, -580], [6106, -8122], [1266, 927], [-17536, 2788], [13342, -580], [5000, 4338], [-13118, 1235], [2410, -253], [-8554, 7224], [6298, -7196], [5650, -3388], [-1146, 2488], [27802, 149], [5566, 6924], [-2846, 9052], [-12518, -4943], [-1366, 2942], [-1490, -5283], [11558, 7907], [31638, 920], [-18666, 457], [-11318, -7986], [4450, -3204], [-9744, 2338], [26808, -732], [-30302, -5994], [-22782, 3608], [-6964, 448], [-14214, 7367], [17574, -1285], [-9970, -4087], [-9960, -184], [20594, -1280], [24746, -3432], [-43646, 3638], [2570, -12243], [-15974, -3068], [-8396, 7042], [-12632, -2690], [-34766, 2832], [23322, 3431], [22834, 7159], [1618, 1298]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_136_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_136_4_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_136_4_a_a(:prec:=2)
    chi := MakeCharacter_136_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 4));
    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_136_4_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_136_4_a_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_136_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<3,R![-8, -4, 1]>],Snew);
    return Vf;
end function;