
// Make newform 74.4.c.a in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_74_c();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_74_c_Hecke();"
// 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_c_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_74_4_c_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 := [44100, -11550, 12895, 3005, 1944, 157, 48, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0], [39927249180, 15096834055, 11047848851, 2694757026, 367759321, 46810062, 2985827, 1161547], [-1219624350, 1270074215, 2825845, 179938098, 10397849, 4414201, -212957, 98747], [-26942923645, 284259150, 11745885, 833723184, 43219617, 18348033, -313216, 410451], [-102366278700, 70661757290, -36053963593, 5158399873, -1552858600, 470238386, -60008240, 5600523], [396175255350, -507256534355, -203985740113, -84651611946, -9768593357, -1632820752, -41841439, -39157703], [-118628497260, 50114967155, -32824442807, -8006436282, -2644841047, -139078134, -8871239, -7343719]];
    Rf_basisdens := [1, 1, 50470839930, 1201686665, 1201686665, 8411806655, 50470839930, 7210119990];
    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_c();"
function MakeCharacter_74_c()
    N := 74;
    order := 3;
    char_gens := [39];
    v := [2];
    // 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;

// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_74_c_Hecke();"
function MakeCharacter_74_c_Hecke(Kf)
    N := 74;
    order := 3;
    char_gens := [39];
    char_values := [[0, 0, -1, 0, 0, 0, 0, 0]];
    assert UnitGenerators(DirichletGroup(N)) eq char_gens;
    values := ConvertToHeckeField(char_values : pass_field := true, Kf := Kf); // the value of chi on the gens as elements in the Hecke field
    F := Universe(values);// the Hecke field
    chi := DirichletCharacterFromValuesOnUnitGenerators(DirichletGroup(N,F),values);
    return chi;
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, -2, 0, 0, 0, 0, 0], [0, -1, -1, 0, 0, 0, 0, 0], [0, 0, -2, 0, 0, 0, 0, 1], [0, 1, 1, 0, 1, 0, 1, 1], [10, -4, -2, 4, 2, 2, 0, -2], [0, -3, -14, 0, -2, 0, -2, 1], [-1, 0, 1, -8, 0, -4, 2, 0], [0, -5, -18, 0, -2, 0, -2, -3], [-11, 6, 6, -6, -7, -6, 0, 6], [41, 19, -11, -19, 1, 11, 0, -11], [2, -32, -16, 32, -6, 16, 0, -16], [104, 32, -76, -13, -3, 14, 4, -6], [0, -14, 23, 0, -15, 0, -15, -7], [54, 20, 15, -20, 2, -15, 0, 15], [38, 20, -16, -20, 22, 16, 0, -16], [24, 0, -24, -19, 0, -22, -21, 0], [77, 0, -77, 103, 0, -29, 8, 0], [0, -86, -44, 0, -1, 0, -1, -28], [0, -49, 96, 0, 16, 0, 16, 45], [0, 101, -249, 0, 25, 0, 25, 31], [-1, -26, -53, 26, -3, 53, 0, -53], [0, -69, 78, 0, 12, 0, 12, 35], [287, 0, -287, -17, 0, -26, -46, 0], [-566, 0, 566, -10, 0, -59, 7, 0], [651, 103, -38, -103, -13, 38, 0, -38], [-164, 265, 16, -265, -52, -16, 0, 16], [495, 186, 38, -186, -37, -38, 0, 38], [0, 35, 937, 0, 14, 0, 14, -12], [-474, 0, 474, -278, 0, 18, -13, 0], [-1322, 0, 1322, -7, 0, 48, -35, 0], [18, 0, -18, 145, 0, 35, 59, 0], [77, 0, -77, -37, 0, -56, 32, 0], [-106, -47, -49, 47, 34, 49, 0, -49], [397, 0, -397, -45, 0, 64, 24, 0], [395, -49, 123, 49, 31, -123, 0, 123], [0, -375, 667, 0, 61, 0, 61, 19], [744, 0, -744, -122, 0, 42, 53, 0], [-1585, 0, 1585, 143, 0, 54, -62, 0], [0, 63, 948, 0, -78, 0, -78, 99], [-1086, 0, 1086, 250, 0, -218, 15, 0], [-2722, -112, -56, 112, -14, 56, 0, -56], [0, -212, 1862, 0, 12, 0, 12, 25], [1451, 146, -182, -146, -17, 182, 0, -182], [-1478, -99, 171, 99, -170, -171, 0, 171], [824, 0, -824, 302, 0, 68, -139, 0], [169, -166, -142, 166, 37, 142, 0, -142], [378, 408, 173, -408, -82, -173, 0, 173], [803, -82, -8, 82, -9, 8, 0, -8], [0, -405, 1286, 0, -258, 0, -258, -247], [0, -306, -3018, 0, 83, 0, 83, -194], [-750, 621, 137, -621, 198, -137, 0, 137], [260, 0, -260, -135, 0, -137, 89, 0], [0, -5, 2466, 0, 5, 0, 5, 322], [3728, 68, -161, -68, -104, 161, 0, -161], [-2930, 0, 2930, -278, 0, -99, -5, 0], [0, -449, 2918, 0, -66, 0, -66, 17], [-1604, 192, 102, -192, -142, -102, 0, 102], [621, 0, -621, 703, 0, 253, 128, 0], [0, 128, -4776, 0, 94, 0, 94, -243], [1929, 0, -1929, 68, 0, 372, -120, 0], [0, 655, -663, 0, -6, 0, -6, -28], [0, 310, 2508, 0, 331, 0, 331, 112], [-702, 156, -77, -156, -262, 77, 0, -77], [-1664, 0, 1664, -1103, 0, 227, 85, 0], [2274, 0, -2274, 1202, 0, 71, -337, 0], [1103, 0, -1103, -644, 0, -385, 182, 0], [-2937, 0, 2937, 699, 0, 139, -214, 0], [0, -2, 5545, 0, 325, 0, 325, -53], [276, 568, -567, -568, 216, 567, 0, -567], [-6091, 0, 6091, -836, 0, 21, -20, 0], [3074, 0, -3074, -366, 0, -707, 71, 0], [4816, -188, -340, 188, -148, 340, 0, -340], [0, -357, 64, 0, -514, 0, -514, 167], [0, -120, -2628, 0, -624, 0, -624, -37], [-4683, 0, 4683, 499, 0, -678, -244, 0], [0, 601, -7653, 0, -53, 0, -53, 1], [0, -420, -694, 0, -186, 0, -186, -769], [-1084, 961, 216, -961, 528, -216, 0, 216], [-5787, 394, -175, -394, 171, 175, 0, -175], [-5216, 0, 5216, -1094, 0, -143, -147, 0], [573, 0, -573, 63, 0, -278, 12, 0], [-3600, -515, 822, 515, -520, -822, 0, 822], [0, -1009, -2462, 0, 212, 0, 212, 807], [6983, 863, -146, -863, -105, 146, 0, -146], [0, 1019, -3486, 0, 530, 0, 530, -467], [5512, -744, 164, 744, 548, -164, 0, 164], [0, 443, 3906, 0, -89, 0, -89, 676], [0, 1568, -7749, 0, 488, 0, 488, 82], [3793, 0, -3793, -277, 0, -317, 346, 0], [0, -1671, -2485, 0, 163, 0, 163, -103], [-2482, -256, 1208, 256, -182, -1208, 0, 1208], [1583, 0, -1583, 939, 0, 141, 314, 0], [3093, -1882, -552, 1882, -79, 552, 0, -552], [-5286, 112, -230, -112, 78, 230, 0, -230], [0, 471, -11078, 0, -706, 0, -706, 101], [5885, 0, -5885, -425, 0, 917, 44, 0], [2349, 0, -2349, -504, 0, -707, -480, 0], [0, -321, 9102, 0, 1023, 0, 1023, -516], [0, 1487, 12745, 0, -146, 0, -146, 880], [5411, -497, 45, 497, -33, -45, 0, 45], [-3544, 764, -970, -764, 468, 970, 0, -970], [-10023, 0, 10023, -1248, 0, -61, 120, 0], [8950, 8, -293, -8, -178, 293, 0, -293], [-275, -793, 100, 793, 677, -100, 0, 100], [-10429, 0, 10429, -1401, 0, 294, 610, 0], [-6231, 0, 6231, -17, 0, 127, 338, 0], [0, -949, -2999, 0, -354, 0, -354, -164], [6931, -1581, -652, 1581, -637, 652, 0, -652], [0, 1699, 5360, 0, 220, 0, 220, 1485], [-3749, 0, 3749, 732, 0, 1010, -342, 0], [-2923, 0, 2923, -73, 0, -87, -392, 0], [8999, 0, -8999, -2704, 0, -215, -38, 0], [-8298, 0, 8298, 1849, 0, -928, -387, 0], [2704, -1116, 773, 1116, -380, -773, 0, 773], [-2762, 0, 2762, 933, 0, -635, -561, 0], [-2274, 0, 2274, 1966, 0, 1183, -69, 0], [6580, 1984, -1190, -1984, 232, 1190, 0, -1190], [0, 689, -8837, 0, 357, 0, 357, -353], [0, 3300, 800, 0, -196, 0, -196, 1051], [0, -1325, -4700, 0, -146, 0, -146, -37], [0, 676, -4136, 0, 318, 0, 318, 1257], [0, 783, -1978, 0, -343, 0, -343, -954], [-3213, 223, 283, -223, 639, -283, 0, 283], [9541, 0, -9541, -777, 0, 1086, 424, 0], [2215, 0, -2215, 3247, 0, 1, -702, 0], [9491, 0, -9491, 1275, 0, 1061, -532, 0], [7388, 1292, 314, -1292, 1062, -314, 0, 314], [-9612, 0, 9612, -3339, 0, -439, -951, 0], [0, -2121, 2566, 0, -714, 0, -714, -219], [0, -1519, -8762, 0, -408, 0, -408, -1725], [5146, -644, 389, 644, -458, -389, 0, 389], [0, 187, 12334, 0, -652, 0, -652, -873], [533, -2834, 156, 2834, 741, -156, 0, 156], [2516, 0, -2516, -3018, 0, -1252, 385, 0], [-8567, 0, 8567, -1860, 0, -1682, -1412, 0], [-11507, -406, -283, 406, -1085, 283, 0, -283], [0, -4350, -5106, 0, 683, 0, 683, -934], [-460, -4252, 1048, 4252, -84, -1048, 0, 1048], [-5735, 0, 5735, 3471, 0, -1165, -1154, 0], [0, -813, -12766, 0, 891, 0, 891, -208], [0, 939, 8632, 0, 786, 0, 786, -201], [0, 2517, 9910, 0, 432, 0, 432, 1303], [-8920, 0, 8920, -3859, 0, -575, -551, 0], [0, -3581, -2088, 0, -402, 0, -402, -897], [12401, 0, -12401, 4639, 0, 167, -98, 0], [9782, 0, -9782, 3353, 0, -1837, 851, 0], [4144, 0, -4144, -3874, 0, 1154, -735, 0], [-15581, 451, 158, -451, -325, -158, 0, 158], [-20742, 1476, 409, -1476, 86, -409, 0, 409], [9435, 0, -9435, -2145, 0, 993, 114, 0], [3370, -2163, 1854, 2163, 46, -1854, 0, 1854], [0, 940, 1713, 0, 2012, 0, 2012, 2216], [0, 1019, -1459, 0, -522, 0, -522, 1504], [5607, 5102, 2242, -5102, -645, -2242, 0, 2242], [0, -1801, -1324, 0, 868, 0, 868, 1337], [-21531, 3914, 272, -3914, -1023, -272, 0, 272], [-191, -4154, -1138, 4154, 817, 1138, 0, -1138], [0, 2534, -13637, 0, 713, 0, 713, -291], [-10198, 0, 10198, 4430, 0, 1625, -521, 0], [2742, 0, -2742, 4462, 0, -102, -537, 0], [12193, 0, -12193, -1929, 0, -325, -1004, 0], [5958, 0, -5958, 2657, 0, -768, 189, 0], [0, 5787, 9942, 0, -686, 0, -686, -531], [17849, 0, -17849, -2161, 0, 2276, -196, 0], [3196, 0, -3196, 5869, 0, 850, -1265, 0], [-26575, 0, 26575, -4357, 0, 915, -928, 0], [-11337, 2118, 1584, -2118, -61, -1584, 0, 1584], [-13695, 0, 13695, -2617, 0, -165, 1694, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_74_c_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_74_4_c_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_74_4_c_a(:prec:=8)
    chi := MakeCharacter_74_c();
    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_c_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_74_4_c_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_74_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<3,R![48400, -7040, 9384, -984, 1384, -126, 63, 5, 1]>],Snew);
    return Vf;
end function;