
// Make newform 74.6.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_6_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_6_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 := [-140, -77, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 2, 0], [-52, -1, 1]];
    Rf_basisdens := [1, 1, 2];
    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 := 6;
    raw_aps := [[-4, 0, 0], [-3, 1, -1], [-14, 0, 0], [31, -7, 9], [107, 11, 17], [-274, 22, -16], [80, -106, -6], [-1492, 24, -34], [-934, 18, 96], [-598, -330, -4], [-4948, -40, -238], [-1369, 0, 0], [2715, 656, 101], [-2758, 816, -124], [6327, -407, -807], [12941, 742, 495], [-5868, 2386, -542], [-11180, -2, -650], [1984, 372, 412], [-5671, -433, -2121], [-437, -3172, 1181], [-42804, 4670, 1546], [-48735, 1945, -6209], [-19880, -336, -1034], [8816, -4550, -3366], [64335, 11350, -7343], [-68518, 6536, -1184], [70188, -4220, 8092], [42004, -3344, -1350], [48482, 2666, 4676], [-11631, -12241, 3527], [48836, -9458, 7422], [71146, 8852, 12], [-114588, -4940, 6176], [101735, -18250, 1277], [69200, 4320, -9120], [156067, 5110, -3903], [-43566, -23678, 22180], [74640, 4960, 20138], [-23099, 11426, -12621], [-381554, 11768, -2620], [-320799, -18990, 5003], [-430616, -13562, -11730], [-92438, 13520, 33280], [137551, 29714, 10589], [-622402, 15084, 10820], [-431413, -15653, -4963], [-498001, 46733, 8025], [15104, -17812, -34790], [232395, -14870, 33545], [364534, -31164, 14496], [-1127930, -17620, 20704], [-173158, -17046, -38716], [398050, -47774, 91812], [-53268, 9718, 13246], [826179, 92981, -47095], [-448390, 91744, -57604], [1455449, -229, -8185], [625180, 14720, -23206], [-393716, 46528, -44814], [506504, 78278, -74070], [262918, 6388, -97068], [-1375937, 81775, -74083], [-474116, -115744, 95922], [-222002, -37898, 78760], [252350, -103096, 136968], [1062742, -90954, 125652], [-355373, -32536, -66795], [-2741950, 1292, 56712], [-1203202, 133248, 28972], [2051104, -159534, -58446], [-875863, -63997, 118551], [3253760, 39676, 24428], [1884465, -164662, -17801], [1103767, -76573, 82793], [196828, 157444, 13038], [-1694452, -6152, -50638], [490287, 140418, -178847], [2195730, -96406, 62556], [-72656, 299270, -148198], [1473407, -327345, -43767], [-2165036, -102512, 82074], [-2633646, -225716, 190504], [-1457395, -329672, 48343], [953152, 203054, -190606], [-831279, -46311, 270675], [-358432, -261008, 239398], [-1185458, -6136, -223444], [-2869010, -194026, -46456], [2737966, 183916, 19616], [-2512698, -84854, -171228], [3781754, 235684, -167308], [2722016, -151326, -104434], [-4823708, -27680, -184964], [-1913092, 132340, -108646], [3408668, -117400, 111558], [-2512747, -217394, -118357], [-2555397, -48736, 213973], [2640558, -322862, 267612], [2288100, -147036, 701146], [3250104, 402912, -239650], [1190398, -1264, 120988], [-8923126, 133044, -531452], [-5456620, -19542, -566234], [-4050065, -881057, 376793], [1717244, 226136, -553174], [-2899452, -25528, 246594], [6194847, 308500, -211267], [2875401, -286609, -177793], [4803130, -310984, -370208], [511644, 470148, -559078], [-656621, 181154, -101667], [-5731323, 12948, -232453], [5724399, 56243, -67187], [6555840, -194068, 244246], [6063283, 319728, 221993], [-6037782, 436476, -59024], [4569168, -798238, -92430], [-4469368, -639688, -11090], [3031817, 515317, 472443], [5442136, -287044, 259782], [8860255, 534264, -693051], [8417713, -132330, 711935], [-14296286, -158780, 212468], [-18183356, 169812, -110744], [4892928, 431738, -773222], [6834504, -363510, -68974], [-707969, -796971, 615177], [-14084848, -746070, 265770], [10427451, -266114, 147237], [-8226065, -1496905, 794885], [835565, -75349, 514847], [-3453495, 551995, -1102221], [-19960302, 470934, 12948], [3681825, -687324, 893271], [-11278546, 487054, 180328], [14580819, -354570, -447543], [-20117797, 189007, 337933], [-2406256, 318998, -886406], [10540130, 495116, 474016], [1453823, -444025, 30433], [17810773, 690086, -734345], [3922144, 76692, 1283108], [-11892026, -904318, 767780], [-9001832, 1589510, -522958], [-18544508, -157620, 338692], [-8115006, 381984, 477584], [11354024, -790282, 193242], [-18439316, -1373934, 594354], [11973744, 1931276, -1019180], [4398754, -793212, 1276764], [17651866, 1592944, -966792], [-4880236, -863930, -1209162], [9374385, -904189, 1241267], [-10380904, 446746, -1055082], [26973530, -190352, -693180], [2343754, 340130, 1323260], [-24853278, -938480, -332468], [-15203431, -849732, 666083], [13897238, -965228, -104852], [24934448, -959068, -613670], [13737889, 1055520, -327713], [-17959938, 114444, -2706144], [36783088, -502988, -290256], [-5205748, -983068, 1429194], [-8577351, -517281, 352531], [-9876942, 1108682, 307252], [5142794, 1108778, 1011204]];
    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_6_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_6_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, 6));
    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_6_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_6_a_c( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_74_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<3,R![468, -429, 8, 1]>],Snew);
    return Vf;
end function;