
// Make newform 49.4.a.e in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_49_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_49_4_a_e();".
// 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_49_4_a_e();".
// 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 := [194, 36, -35, -2, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [-79, 100, 3, -2], [-182, 12, 11, -1], [-392, -265, 12, 11]];
    Rf_basisdens := [1, 57, 19, 57];
    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_49_a();"
function MakeCharacter_49_a()
    N := 49;
    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_49_a_Hecke(Kf)
    return MakeCharacter_49_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 := [[1, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, -1], [0, 0, 0, 0], [22, -6, 0, 0], [0, 0, 6, 1], [0, 0, -1, 9], [0, 0, -11, -4], [92, 8, 0, 0], [58, -14, 0, 0], [0, 0, -38, 4], [50, -6, 0, 0], [0, 0, -31, 3], [170, 70, 0, 0], [0, 0, -26, 32], [22, 36, 0, 0], [0, 0, 49, -20], [0, 0, 68, -27], [-524, -76, 0, 0], [548, -28, 0, 0], [0, 0, -37, -25], [-356, -188, 0, 0], [0, 0, 1, -8], [0, 0, -157, -75], [0, 0, -189, 91], [0, 0, 8, -7], [0, 0, 14, 132], [932, -20, 0, 0], [-314, -370, 0, 0], [-460, 238, 0, 0], [464, 140, 0, 0], [0, 0, 111, 56], [428, -20, 0, 0], [0, 0, 305, -284], [-398, 512, 0, 0], [1632, 204, 0, 0], [0, 0, -350, 183], [386, -314, 0, 0], [0, 0, -362, 152], [0, 0, 358, -233], [932, -412, 0, 0], [0, 0, 498, 83], [1884, 204, 0, 0], [-1280, 554, 0, 0], [170, -1092, 0, 0], [0, 0, -118, -28], [-964, 84, 0, 0], [0, 0, 152, 156], [0, 0, -129, 340], [0, 0, -50, 315], [-1560, -664, 0, 0], [1668, 1064, 0, 0], [0, 0, -75, -99], [0, 0, 521, 144], [0, 0, 593, 183], [2332, -412, 0, 0], [0, 0, 334, -543], [0, 0, 456, -380], [-3338, -440, 0, 0], [5728, 336, 0, 0], [0, 0, 633, 96], [0, 0, -532, 385], [0, 0, -673, -496], [0, 0, -232, -544], [0, 0, -655, 395], [-3422, -132, 0, 0], [-3982, -258, 0, 0], [898, -742, 0, 0], [-118, -34, 0, 0], [0, 0, -214, -689], [0, 0, -77, -237], [6224, -1364, 0, 0], [0, 0, 1860, 332], [7218, 512, 0, 0], [-7586, 490, 0, 0], [0, 0, 1138, -880], [162, -1126, 0, 0], [0, 0, -42, -743], [7470, 1142, 0, 0], [0, 0, 615, 79], [0, 0, 775, -712], [-1930, 952, 0, 0], [13532, 456, 0, 0], [0, 0, 515, -543], [0, 0, -572, 284], [3732, -1980, 0, 0], [2270, -2576, 0, 0], [-4584, 2346, 0, 0], [0, 0, -1538, -289], [4608, 3080, 0, 0], [0, 0, 393, -268], [0, 0, 822, -44], [4236, 1744, 0, 0], [1612, 3108, 0, 0], [4964, 1604, 0, 0], [0, 0, -1380, -132], [0, 0, -1082, 577], [0, 0, 739, -1361], [0, 0, -1065, 1036], [-2078, -5032, 0, 0], [-14642, -2310, 0, 0], [-14566, -972, 0, 0], [0, 0, -2039, 556], [-19046, -174, 0, 0], [-2890, -3646, 0, 0], [0, 0, 941, 1405], [0, 0, 77, -1204], [0, 0, 651, -407], [13168, 3480, 0, 0], [0, 0, -1555, 827], [0, 0, -1460, 416], [5034, -3758, 0, 0], [-20746, -1890, 0, 0], [0, 0, 2475, -1872], [10684, -1876, 0, 0], [-12102, 1618, 0, 0], [0, 0, 353, -1452], [0, 0, -3430, 1156], [-650, 1422, 0, 0], [11846, -1582, 0, 0], [0, 0, -2788, -361], [9508, -28, 0, 0], [0, 0, 1054, -61], [-1756, 2276, 0, 0], [0, 0, 959, 2176], [-13690, 3374, 0, 0], [-2190, 3130, 0, 0], [0, 0, 3254, 1176], [0, 0, -2474, 2544], [0, 0, 380, -1893], [11418, 4558, 0, 0], [12224, -1764, 0, 0], [11404, -2792, 0, 0], [-16182, 3122, 0, 0], [0, 0, -4101, 845], [0, 0, 3585, -1779], [0, 0, 2992, -1969], [0, 0, -335, -1036], [0, 0, 5046, 841], [-15056, -1602, 0, 0], [0, 0, 2525, 1360], [-33018, -664, 0, 0], [-26648, -720, 0, 0], [-20452, 3724, 0, 0], [0, 0, -2868, 1077], [0, 0, 962, -3188], [0, 0, 3922, 1307], [0, 0, 4065, -991], [0, 0, -2365, 2784], [4348, 5300, 0, 0], [3242, 8674, 0, 0], [0, 0, -2695, -2499], [-16476, -6916, 0, 0], [0, 0, -5390, -1912], [21596, 1044, 0, 0], [-11688, -8484, 0, 0], [-32864, 1912, 0, 0], [0, 0, 1143, 2097], [0, 0, -221, 2503], [0, 0, 2492, -699], [9206, -4430, 0, 0], [27638, 5628, 0, 0], [2676, 1456, 0, 0], [0, 0, 5737, -1412], [-3716, 10508, 0, 0], [0, 0, -2050, 140], [-11360, -9960, 0, 0], [0, 0, 6264, -817]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_49_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_49_4_a_e();".
// 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_49_4_a_e(:prec:=4)
    chi := MakeCharacter_49_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_49_4_a_e();".
// 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_49_4_a_e( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_49_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![-16, -1, 1]>,<3,R![784, 0, -74, 0, 1]>],Snew);
    return Vf;
end function;