
// Make newform 74.4.b.a in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_74_b();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_74_b_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_b_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_b_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 := [2985984, 0, 2690496, 0, 392769, 0, 15052, 0, 212, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 0, 0, 0, 0, 0, 0, 0], [4950720, 0, -1042479, 0, 73924, 0, 5060, 0, 49, 0], [-277495956, 0, -20315457, 0, 744424, 0, 31808, 0, 247, 0], [-170771814, 0, -69411501, 0, -2996984, 0, -43018, 0, -203, 0], [0, 3169891584, 0, 332514171, 0, 11460100, 0, 174236, 0, 955], [414195120, 0, 126844389, 0, 6738392, 0, 117844, 0, 653, 0], [0, 9887785344, 0, 2086850637, 0, 81458780, 0, 1100164, 0, 4877], [0, 13178567808, 0, 2049826869, 0, 85626172, 0, 1283300, 0, 6325], [0, 4155048576, 0, 2281437891, 0, 118682980, 0, 2019260, 0, 11011]];
    Rf_basisdens := [1, 1, 5557896, 8336844, 4168422, 1600674048, 8336844, 533558016, 400168512, 533558016];
    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_b();"
function MakeCharacter_74_b()
    N := 74;
    order := 2;
    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;

// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_74_b_Hecke();"
function MakeCharacter_74_b_Hecke(Kf)
    N := 74;
    order := 2;
    char_gens := [39];
    char_values := [[-1, 0, 0, 0, 0, 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 := [[0, 0, 0, 0, 0, -1, 0, 0, 0, 0], [1, 0, -1, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 2, 0, 1, 0, 0], [0, 0, 1, 1, 0, 0, 0, 0, 0, 0], [-5, 0, 1, -1, -1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 12, 0, 0, 1, 1], [0, 5, 0, 0, 0, -12, 0, 0, 0, 1], [0, 2, 0, 0, 0, 10, 0, -4, -2, 1], [0, -4, 0, 0, 0, 0, 0, 6, 1, 0], [0, -1, 0, 0, 0, 30, 0, 0, -3, 6], [0, 2, 0, 0, 0, -44, 0, -1, 4, -1], [15, 0, 16, -3, 1, 28, 4, 5, -5, 4], [-125, 0, -18, 2, 4, 0, -3, 0, 0, 0], [0, -16, 0, 0, 0, 24, 0, 12, 8, -9], [58, 0, 27, 1, 2, 0, -2, 0, 0, 0], [-74, 0, -8, -9, -4, 0, 5, 0, 0, 0], [0, 25, 0, 0, 0, 70, 0, -4, -4, 2], [0, 11, 0, 0, 0, 46, 0, 5, 10, 9], [123, 0, 44, -6, -15, 0, 10, 0, 0, 0], [-136, 0, 17, -1, 8, 0, 2, 0, 0, 0], [215, 0, 32, 23, -15, 0, -9, 0, 0, 0], [0, 37, 0, 0, 0, 60, 0, 18, -1, -5], [-144, 0, -33, -3, 14, 0, 36, 0, 0, 0], [0, -51, 0, 0, 0, -250, 0, 22, -8, 7], [0, -14, 0, 0, 0, 70, 0, 26, -8, -16], [366, 0, -110, 17, 10, 0, -29, 0, 0, 0], [0, 47, 0, 0, 0, -236, 0, -73, -6, -14], [-207, 0, 32, -39, 22, 0, 6, 0, 0, 0], [0, -63, 0, 0, 0, -30, 0, 90, 28, -7], [0, -10, 0, 0, 0, 26, 0, 22, 8, -8], [368, 0, -117, -11, -22, 0, -16, 0, 0, 0], [0, -96, 0, 0, 0, -332, 0, 44, -2, 9], [1079, 0, 78, 22, -29, 0, -24, 0, 0, 0], [-1279, 0, 28, 13, -10, 0, -2, 0, 0, 0], [-1354, 0, -196, 3, -14, 0, -29, 0, 0, 0], [534, 0, -30, 46, 12, 0, 22, 0, 0, 0], [-584, 0, 116, 47, -28, 0, -53, 0, 0, 0], [0, -128, 0, 0, 0, -246, 0, 42, 24, 21], [0, 95, 0, 0, 0, 414, 0, -3, 10, -52], [-52, 0, 212, 21, -10, 0, 67, 0, 0, 0], [0, -69, 0, 0, 0, 706, 0, -4, 8, 16], [2378, 0, 122, -9, -52, 0, -37, 0, 0, 0], [0, -80, 0, 0, 0, -190, 0, -11, -68, -61], [0, -55, 0, 0, 0, 886, 0, -52, 78, -47], [1166, 0, -6, -31, 52, 0, 5, 0, 0, 0], [0, -57, 0, 0, 0, -862, 0, -86, 24, 34], [55, 0, 115, -19, 71, 0, -16, 0, 0, 0], [-1960, 0, -263, 65, 48, 0, 88, 0, 0, 0], [0, -27, 0, 0, 0, -56, 0, 122, 46, 98], [2438, 0, -14, -81, 50, 0, 45, 0, 0, 0], [1619, 0, -372, 63, -16, 0, -62, 0, 0, 0], [0, 38, 0, 0, 0, -1678, 0, -83, -24, -19], [0, 64, 0, 0, 0, 1786, 0, -220, -82, 28], [0, 80, 0, 0, 0, -542, 0, -46, 20, 173], [0, -104, 0, 0, 0, -298, 0, -86, -128, -10], [444, 0, 79, -3, -186, 0, -36, 0, 0, 0], [1464, 0, -256, -98, -36, 0, 56, 0, 0, 0], [-2264, 0, 323, 3, 52, 0, -60, 0, 0, 0], [0, -223, 0, 0, 0, 216, 0, 111, 206, -111], [0, 106, 0, 0, 0, -804, 0, 96, 60, 70], [0, 5, 0, 0, 0, -1442, 0, 326, -60, 30], [1158, 0, 156, 184, -100, 0, 32, 0, 0, 0], [-1969, 0, -61, -96, 40, 0, 18, 0, 0, 0], [0, 259, 0, 0, 0, -1142, 0, 98, -71, 97], [0, -405, 0, 0, 0, 180, 0, 90, -60, 55], [1888, 0, -442, 26, 96, 0, -18, 0, 0, 0], [0, 349, 0, 0, 0, -2332, 0, -32, -204, 124], [-3673, 0, 338, -57, 85, 0, -27, 0, 0, 0], [0, -237, 0, 0, 0, -1582, 0, -146, -110, 18], [-2114, 0, -524, -188, -20, 0, 44, 0, 0, 0], [0, 251, 0, 0, 0, -1952, 0, 446, 142, 93], [1800, 0, 985, -207, 46, 0, -42, 0, 0, 0], [1950, 0, 316, -154, 28, 0, -120, 0, 0, 0], [1010, 0, 534, -219, 148, 0, 161, 0, 0, 0], [-2927, 0, 7, -212, 4, 0, 152, 0, 0, 0], [0, 133, 0, 0, 0, -1684, 0, 94, 156, -158], [0, -259, 0, 0, 0, 2668, 0, 176, 123, -192], [1082, 0, -438, 249, -62, 0, -145, 0, 0, 0], [0, 427, 0, 0, 0, 2696, 0, -314, -182, -7], [0, 318, 0, 0, 0, 1698, 0, 300, 84, -200], [5963, 0, 141, 138, -252, 0, 202, 0, 0, 0], [0, -800, 0, 0, 0, -370, 0, 448, 77, 107], [0, -338, 0, 0, 0, -2372, 0, -142, 14, -215], [-4477, 0, 584, -62, -128, 0, 235, 0, 0, 0], [0, -86, 0, 0, 0, 874, 0, 62, 243, 134], [-3355, 0, 609, 113, -167, 0, -334, 0, 0, 0], [0, -383, 0, 0, 0, -1810, 0, -242, 332, 59], [0, 491, 0, 0, 0, 626, 0, 304, -118, -25], [0, 101, 0, 0, 0, -2104, 0, 10, -60, 267], [0, 182, 0, 0, 0, 2246, 0, 178, -27, -144], [0, -209, 0, 0, 0, 1588, 0, -634, 46, -112], [0, -76, 0, 0, 0, -2806, 0, -626, 235, -260], [0, 412, 0, 0, 0, 4872, 0, 42, 158, 183], [-2769, 0, -672, -209, -94, 0, -94, 0, 0, 0], [0, -329, 0, 0, 0, 224, 0, -614, 22, -172], [0, -353, 0, 0, 0, -1530, 0, -345, 30, -248], [6354, 0, 424, 319, 66, 0, 23, 0, 0, 0], [300, 0, -680, -435, 48, 0, -315, 0, 0, 0], [0, -26, 0, 0, 0, -18, 0, 78, -526, 129], [0, 15, 0, 0, 0, 1120, 0, 371, 290, 151], [0, -361, 0, 0, 0, 1664, 0, 538, -262, 16], [0, 3, 0, 0, 0, 92, 0, -251, -162, -21], [0, -584, 0, 0, 0, 1208, 0, 490, 476, -233], [0, -244, 0, 0, 0, -3174, 0, -6, -330, 100], [227, 0, -425, 566, 16, 0, -12, 0, 0, 0], [0, -133, 0, 0, 0, 3014, 0, 634, -6, -337], [0, 822, 0, 0, 0, 778, 0, 176, 426, 101], [2981, 0, -1046, -263, 175, 0, -453, 0, 0, 0], [-1520, 0, 969, 173, -450, 0, -78, 0, 0, 0], [1491, 0, -642, 142, -245, 0, -36, 0, 0, 0], [0, -193, 0, 0, 0, -7358, 0, 710, 647, 59], [72, 0, 660, -169, 122, 0, 273, 0, 0, 0], [-341, 0, 226, 16, -276, 0, 187, 0, 0, 0], [-1089, 0, -917, -269, -25, 0, 274, 0, 0, 0], [0, 295, 0, 0, 0, 3578, 0, -170, -515, 169], [1973, 0, -128, 362, -68, 0, 281, 0, 0, 0], [0, -99, 0, 0, 0, -2950, 0, 568, 682, -392], [0, 875, 0, 0, 0, -2108, 0, -802, -157, -303], [0, 1197, 0, 0, 0, -4752, 0, -780, -135, -6], [4859, 0, 959, -14, 352, 0, -96, 0, 0, 0], [0, 440, 0, 0, 0, -2750, 0, -796, -83, -497], [141, 0, 1352, 10, 296, 0, 117, 0, 0, 0], [-2292, 0, 912, -321, -16, 0, 351, 0, 0, 0], [0, 270, 0, 0, 0, 44, 0, -746, -100, 157], [-7460, 0, -2170, -508, -340, 0, -2, 0, 0, 0], [0, -1103, 0, 0, 0, 2530, 0, 797, 218, 563], [0, -140, 0, 0, 0, -2440, 0, -449, 680, -318], [256, 0, 899, -491, 152, 0, -50, 0, 0, 0], [0, 755, 0, 0, 0, -3072, 0, 1197, 246, 134], [10264, 0, -1760, 209, 728, 0, 113, 0, 0, 0], [-3569, 0, 1435, -617, 15, 0, 366, 0, 0, 0], [4452, 0, -3119, -697, 158, 0, 292, 0, 0, 0], [7940, 0, -191, 231, -198, 0, -760, 0, 0, 0], [0, 1509, 0, 0, 0, 3354, 0, -1299, -602, -81], [1981, 0, 1444, 314, -628, 0, -1059, 0, 0, 0], [0, 634, 0, 0, 0, 6170, 0, -482, -406, 306], [5054, 0, 392, -439, 72, 0, 383, 0, 0, 0], [8636, 0, 993, 279, -558, 0, -372, 0, 0, 0], [0, -141, 0, 0, 0, 3246, 0, 1104, 155, -500], [0, 180, 0, 0, 0, 3120, 0, 288, 62, 410], [-3163, 0, 1107, -475, 257, 0, 264, 0, 0, 0], [6116, 0, 1334, -385, -546, 0, 347, 0, 0, 0], [-6084, 0, -210, 436, -156, 0, -590, 0, 0, 0], [0, -865, 0, 0, 0, -9136, 0, -1028, 650, 12], [0, -1429, 0, 0, 0, -2450, 0, 92, 159, 64], [-2880, 0, -1138, 678, -410, 0, 126, 0, 0, 0], [0, -965, 0, 0, 0, -6504, 0, -777, 482, 151], [0, 665, 0, 0, 0, -4888, 0, -518, -952, -27], [0, -614, 0, 0, 0, 4708, 0, -172, -740, 273], [2698, 0, 846, 148, 438, 0, 778, 0, 0, 0], [-6120, 0, -1782, 802, 640, 0, 210, 0, 0, 0], [-8285, 0, -2526, -126, 127, 0, -40, 0, 0, 0], [0, 949, 0, 0, 0, -7954, 0, 316, -564, 562], [-13808, 0, 967, 901, 472, 0, 154, 0, 0, 0], [0, 235, 0, 0, 0, -1054, 0, 454, -216, -500], [0, -138, 0, 0, 0, -3476, 0, 1034, 842, 669], [0, -1366, 0, 0, 0, -2526, 0, -330, -738, 839], [-11077, 0, 1560, 506, -693, 0, 98, 0, 0, 0], [-8275, 0, -2950, -696, -80, 0, 273, 0, 0, 0], [5278, 0, -1462, 934, -578, 0, -38, 0, 0, 0], [0, 104, 0, 0, 0, -1306, 0, -1706, -248, -351], [-6441, 0, 2576, 389, 489, 0, 265, 0, 0, 0], [0, -1214, 0, 0, 0, -4822, 0, 781, 912, 685], [-29553, 0, -2682, 606, 177, 0, 12, 0, 0, 0], [0, -94, 0, 0, 0, 17828, 0, 700, 258, 12], [24104, 0, -819, 239, 410, 0, 200, 0, 0, 0], [0, 221, 0, 0, 0, 5566, 0, 878, -95, 91], [0, -2344, 0, 0, 0, 5446, 0, -1798, 42, -630]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_74_b_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_74_4_b_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_b_a(:prec:=10)
    chi := MakeCharacter_74_b();
    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_b_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_b_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_74_b();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([],Snew);
    return Vf;
end function;