
// Make newform 74.4.a.c in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_74_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_74_4_a_c();".
// 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_74_4_a_c();".
// 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 := [-45, -26, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-17, -3, 1]];
    Rf_basisdens := [1, 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_74_a();"
function MakeCharacter_74_a()
    N := 74;
    order := 1;
    char_gens := [39];
    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_74_a_Hecke(Kf)
    return MakeCharacter_74_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 := [[-2, 0, 0], [1, 1, 1], [2, 3, 1], [2, -4, 1], [26, 5, -4], [35, -9, 2], [6, -8, 6], [78, 8, -6], [-53, -9, 10], [-105, -5, -10], [16, 1, -25], [-37, 0, 0], [-143, -55, -35], [204, -82, -24], [64, 32, -37], [-202, 38, 27], [446, 34, -80], [122, -115, -75], [-54, -77, 35], [-54, -170, -39], [60, -29, -138], [111, 159, 80], [-364, 22, 55], [156, 92, 192], [442, -56, 58], [-1114, -134, -155], [-304, 141, 161], [707, 121, 186], [246, 124, -130], [62, 248, -92], [1118, 58, -87], [686, 122, -136], [1120, -71, 145], [1341, -21, 50], [506, -208, 67], [272, 150, -190], [186, 298, -115], [-170, 644, 364], [924, -795, -45], [-686, -410, 39], [1212, -22, -240], [1444, 290, 393], [-228, -163, 3], [1276, 84, -322], [-1938, -166, -227], [-1152, 500, 122], [1958, 39, 470], [-3960, 284, -161], [256, -438, -394], [-3636, 312, 249], [-817, -363, -152], [2144, 153, 33], [-804, 608, -382], [24, 188, 630], [1106, -668, -774], [-92, 200, 715], [2284, -564, 190], [-4592, 778, -29], [2730, -1121, -205], [468, 1064, -280], [3648, 434, 646], [-684, 878, 64], [1747, -1317, -621], [439, -821, 124], [1358, -694, -146], [984, 1420, 390], [-6812, -492, -354], [5324, 299, -914], [6288, -1646, -128], [-956, 10, 1116], [-1996, 618, -774], [930, -1382, -1203], [-7402, -222, 748], [1368, -132, 107], [-825, -413, -1057], [6528, -2008, 28], [79, 1923, 1508], [-2692, 1720, 1261], [1874, -1910, -82], [1956, 718, 1206], [3421, -723, 467], [-459, 1045, -1144], [6872, 1360, -150], [6591, 335, -1013], [-4173, 1123, 100], [2178, 1011, 1364], [-378, 592, 1086], [6510, 298, 526], [-1002, -2968, -408], [-4757, -1845, 90], [580, 1448, 986], [-2627, 2541, -914], [-2748, -1060, 1632], [853, -2993, -1338], [-2998, -1806, -476], [-7656, 2731, 1053], [-4046, -2628, -151], [-17274, -822, 693], [13094, -1118, -78], [-8230, 1837, -155], [-1904, -1726, 1014], [-9922, 297, -701], [12266, 776, 1076], [-17980, -712, 32], [3709, -147, 875], [5146, -1526, -236], [9002, -2156, 98], [-15036, 423, 1166], [4306, 2786, 2373], [-944, 2037, 2389], [13561, 173, 580], [3884, -1420, 1269], [14501, 1537, 1751], [4446, -1899, 1908], [2559, -9, -1348], [-3755, -935, 657], [7694, 574, -1510], [-11623, -851, 488], [-2849, -2601, -2892], [-4609, -3349, -2407], [4937, -199, -2716], [6973, 3885, 665], [1642, -2456, 273], [-9568, -504, 2450], [-2184, -2312, -3372], [-19278, -81, 1511], [4342, 2285, 2253], [-14956, 2250, 661], [-6604, -1605, -2307], [-10786, -1166, -575], [-10890, 2641, 424], [1184, 4748, -59], [-7354, 526, -635], [-9750, -1773, 3657], [699, 7155, 2503], [16566, 3944, 2000], [-5328, 4122, -1541], [-10380, -5662, -1259], [-11855, -1023, 3612], [-3314, 4062, -2698], [-2302, -3, -2928], [-2302, 5670, 3199], [-304, -1192, -5016], [4674, 4490, 4430], [19053, -2699, -404], [10236, -3586, -470], [10018, 971, 3609], [-3342, -1652, -2442], [9802, 4464, 174], [25644, -7332, -384], [-13970, 3072, -268], [21888, -2965, -3561], [1168, -2372, 1472], [19126, 2318, -3035], [-25490, -668, -1238], [18260, 1052, -990], [-17772, 7756, 1666], [3548, -6329, -3249], [-51, 6845, 95], [15516, 706, 100], [10324, 504, -2604], [6660, -661, 2024], [-8268, 3669, -3407], [15570, 617, -5555], [8454, -2744, -2086], [-31004, -2998, 2415], [9723, -1509, 2638], [35658, -2608, -2376]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_74_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_74_4_a_c();".
// 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_74_4_a_c(:prec:=3)
    chi := MakeCharacter_74_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_74_4_a_c();".
// 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_74_4_a_c( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_74_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<3,R![251, -54, -4, 1]>,<5,R![-210, -209, -7, 1]>],Snew);
    return Vf;
end function;