
// Make newform 33.5.c.a in Magma, downloaded from the LMFDB on 18 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_33_c();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_33_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_33_5_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_33_5_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 := [41364, 0, 23292, 0, 2913, 0, 102, 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, 1, 0, 0, 0, 0, 0, 0], [-38034, 0, -9669, 0, -444, 0, -5, 0], [0, -44466, 0, -9669, 0, -444, 0, -5], [31182, 0, 8535, 0, 320, 0, 3, 0], [107946, 0, 10617, 0, 196, 0, 1, 0], [0, -16500, 0, -4551, 0, -191, 0, -2], [0, 95502, 0, 10143, 0, 320, 0, 3]];
    Rf_basisdens := [1, 1, 3216, 3216, 1608, 3216, 402, 1608];
    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_33_c();"
function MakeCharacter_33_c()
    N := 33;
    order := 2;
    char_gens := [23, 13];
    v := [2, 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_33_c_Hecke();"
function MakeCharacter_33_c_Hecke(Kf)
    N := 33;
    order := 2;
    char_gens := [23, 13];
    char_values := [[1, 0, 0, 0, 0, 0, 0, 0], [-1, 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 := 5;
    raw_aps := [[0, 1, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0, 0], [-5, 0, 1, 0, 0, 1, 0, 0], [0, 6, 0, 1, 0, 0, -1, 1], [4, 3, 4, -1, 7, 1, 2, -1], [0, 9, 0, 2, 0, 0, -2, -1], [0, 23, 0, -8, 0, 0, 1, -5], [0, -3, 0, -9, 0, 0, -5, -2], [77, 0, 29, 0, 2, -25, 0, 0], [0, -105, 0, 16, 0, 0, 13, -11], [338, 0, -96, 0, 18, 12, 0, 0], [670, 0, 76, 0, 34, -16, 0, 0], [0, -103, 0, -84, 0, 0, -3, 3], [0, -99, 0, 31, 0, 0, 27, -10], [43, 0, 19, 0, 156, 19, 0, 0], [489, 0, -453, 0, 100, -93, 0, 0], [-2156, 0, 112, 0, 90, 154, 0, 0], [0, 603, 0, -38, 0, 0, 28, -63], [-544, 0, 510, 0, -342, 174, 0, 0], [-1737, 0, 747, 0, -320, 171, 0, 0], [0, 588, 0, 0, 0, 0, 62, -16], [0, 324, 0, -191, 0, 0, 95, 91], [0, -302, 0, 240, 0, 0, -48, 150], [2044, 0, 946, 0, -156, -206, 0, 0], [938, 0, -1098, 0, 492, 30, 0, 0], [0, 15, 0, -92, 0, 0, -41, -167], [3098, 0, -756, 0, -438, -60, 0, 0], [0, 552, 0, 192, 0, 0, 186, -42], [0, -1341, 0, -582, 0, 0, -130, 5], [-9032, 0, 286, 0, 360, -338, 0, 0], [0, -774, 0, 177, 0, 0, 199, 85], [0, -428, 0, -446, 0, 0, -170, 94], [11170, 0, -1256, 0, -540, -128, 0, 0], [0, 3273, 0, 329, 0, 0, -7, 288], [0, 247, 0, 532, 0, 0, -365, 97], [0, 1578, 0, -281, 0, 0, -27, -373], [10178, 0, 4008, 0, 744, -24, 0, 0], [-8852, 0, -764, 0, -1568, -316, 0, 0], [0, -2404, 0, -78, 0, 0, -570, 510], [0, -1061, 0, -1176, 0, 0, -3, -147], [-14178, 0, 3894, 0, -596, -582, 0, 0], [-1580, 0, -3062, 0, 2068, -766, 0, 0], [-35195, 0, -2279, 0, 816, -1463, 0, 0], [0, 2724, 0, -100, 0, 0, -272, -148], [0, -1271, 0, -700, 0, 0, 773, 335], [14584, 0, 886, 0, 1726, 1094, 0, 0], [0, -3411, 0, -739, 0, 0, -375, 796], [18192, 0, 3038, 0, -2326, 514, 0, 0], [0, -3036, 0, -20, 0, 0, 454, 826], [-36420, 0, 698, 0, 1190, 2470, 0, 0], [0, -2549, 0, -1276, 0, 0, 1427, -463], [0, -5068, 0, 690, 0, 0, -330, 54], [0, -5646, 0, 1204, 0, 0, -1190, 654], [20356, 0, -5156, 0, -3492, -752, 0, 0], [-31348, 0, -3862, 0, 1592, -70, 0, 0], [0, 5476, 0, -1002, 0, 0, -90, -1986], [57093, 0, -7533, 0, -6176, 1947, 0, 0], [0, -10758, 0, -1797, 0, 0, 529, -1817], [0, 3, 0, 1858, 0, 0, -1726, 265], [0, 4175, 0, 392, 0, 0, 101, 251], [0, 14157, 0, -367, 0, 0, 1893, -1160], [0, 12267, 0, 200, 0, 0, -1099, 881], [0, -4743, 0, -2379, 0, 0, 669, 1068], [-971, 0, 6181, 0, 6330, -2897, 0, 0], [17856, 0, 7118, 0, -766, -2366, 0, 0], [3947, 0, -15979, 0, -964, 1469, 0, 0], [-26968, 0, 8604, 0, -5748, 180, 0, 0], [0, -19200, 0, -1432, 0, 0, -706, 984], [0, -27442, 0, -756, 0, 0, 900, -1458], [0, 26607, 0, 454, 0, 0, 324, -55], [-47038, 0, 2540, 0, -7660, -916, 0, 0], [0, 6964, 0, -1000, 0, 0, -1360, -1000], [-33868, 0, -5550, 0, -4122, -5142, 0, 0], [0, -16479, 0, 1082, 0, 0, 1792, -1369], [-95548, 0, 7116, 0, -7752, 3948, 0, 0], [-14153, 0, -26537, 0, 6534, -2963, 0, 0], [3187, 0, -16043, 0, -9468, -5243, 0, 0], [-61010, 0, 3076, 0, -3806, -2104, 0, 0], [47644, 0, 27466, 0, -2244, 2722, 0, 0], [0, 3120, 0, 3644, 0, 0, -2850, 3256], [97768, 0, 31396, 0, 3072, 11584, 0, 0], [-19288, 0, 7050, 0, 576, 9354, 0, 0], [0, 24040, 0, -490, 0, 0, -2050, 230], [11948, 0, -2082, 0, 2094, 5226, 0, 0], [0, 9558, 0, 7393, 0, 0, -37, -1235], [-71078, 0, -8822, 0, -4890, 6436, 0, 0], [-159654, 0, -10572, 0, 4120, 6300, 0, 0], [0, 20400, 0, -164, 0, 0, -2110, -2324], [0, 20385, 0, 6112, 0, 0, 2263, -317], [128718, 0, 12824, 0, -6574, -12704, 0, 0], [-117468, 0, -16272, 0, -698, -2250, 0, 0], [0, -39844, 0, -6070, 0, 0, 2702, -2182], [-61808, 0, -7586, 0, -830, -9814, 0, 0], [0, -148, 0, -3276, 0, 0, 450, 2874], [-106504, 0, -924, 0, -11652, 8772, 0, 0], [0, -28552, 0, -686, 0, 0, -5702, 3514], [-55429, 0, 30449, 0, 3668, -2095, 0, 0], [345888, 0, -24270, 0, 5800, -1182, 0, 0], [0, 39807, 0, -3051, 0, 0, 5761, -2006], [0, 32187, 0, -4278, 0, 0, -1490, 2725], [0, -20727, 0, 11479, 0, 0, 2199, 230], [0, -50181, 0, -1992, 0, 0, -3051, -1023], [0, -4954, 0, 13578, 0, 0, -3888, 2946], [0, -7787, 0, -408, 0, 0, 7623, -5235], [0, -73539, 0, -319, 0, 0, -2299, 3120], [30880, 0, -7352, 0, 29782, -5164, 0, 0], [19888, 0, 184, 0, -28806, 7942, 0, 0], [0, 31577, 0, -8000, 0, 0, -5501, -1595], [145967, 0, -38101, 0, 17462, -6019, 0, 0], [0, 31194, 0, -3824, 0, 0, -7012, 1678], [0, 24342, 0, -3985, 0, 0, 1061, -3897], [0, 13689, 0, -3354, 0, 0, -56, -5789], [225448, 0, -32354, 0, 12804, -10346, 0, 0], [7640, 0, -26298, 0, 342, 12882, 0, 0], [-85034, 0, 10792, 0, 23098, -14080, 0, 0], [-27772, 0, -16006, 0, -38932, 1514, 0, 0], [-107472, 0, -47362, 0, 1718, 17362, 0, 0], [-327065, 0, 24571, 0, -14046, -8951, 0, 0], [250195, 0, 7777, 0, 7236, 17113, 0, 0], [0, -638, 0, -11370, 0, 0, 3600, 7986], [-74050, 0, -73680, 0, 11568, -5328, 0, 0], [0, -17886, 0, 3148, 0, 0, 3432, 2258], [0, 41087, 0, 4724, 0, 0, -2557, 2381], [341964, 0, 2268, 0, -10724, -6072, 0, 0], [150068, 0, 62046, 0, 9582, 1998, 0, 0], [0, -80155, 0, 10768, 0, 0, 451, -1109], [193304, 0, -2730, 0, -17130, 5010, 0, 0], [20193, 0, 56493, 0, -6824, 27429, 0, 0], [-425032, 0, 38130, 0, 7062, -114, 0, 0], [0, 56499, 0, 7850, 0, 0, 10870, -8875], [0, 17943, 0, -7257, 0, 0, -6721, 6200], [0, -78612, 0, -6508, 0, 0, -7456, 2708], [-23686, 0, -124344, 0, 22458, -12252, 0, 0], [345292, 0, -11078, 0, -24512, -2038, 0, 0], [0, -54933, 0, -11128, 0, 0, -6235, -5809], [0, -70548, 0, -3028, 0, 0, 8832, -848], [73303, 0, 39097, 0, 35280, -8687, 0, 0], [0, 65265, 0, 1079, 0, 0, -7457, -5002], [75343, 0, 79393, 0, 22680, 11425, 0, 0], [0, 64315, 0, -14932, 0, 0, 8087, 5609], [0, 70767, 0, 2829, 0, 0, 2361, -15438], [0, 109709, 0, -6628, 0, 0, -3187, 1355], [469200, 0, 38330, 0, 45794, 15778, 0, 0], [0, 11898, 0, -28920, 0, 0, 8340, -786], [-119780, 0, -10334, 0, -65402, 10046, 0, 0], [-132199, 0, -132199, 0, -6154, -3217, 0, 0], [0, 13599, 0, -2954, 0, 0, 16684, -13731], [0, -17735, 0, -11940, 0, 0, 3573, -4437], [-176560, 0, 88320, 0, -15756, -6972, 0, 0], [709273, 0, 613, 0, -15222, -16829, 0, 0], [0, 59511, 0, 11978, 0, 0, -2380, 20061], [112566, 0, -66132, 0, -28088, 8964, 0, 0], [100468, 0, -164942, 0, 14878, -30586, 0, 0], [0, 124980, 0, -11092, 0, 0, -9616, 9068], [-262404, 0, -32578, 0, 17774, 7198, 0, 0], [-322067, 0, 2929, 0, 8760, -21095, 0, 0], [0, -114840, 0, 22593, 0, 0, -8749, 15227], [555274, 0, 117604, 0, -10188, 24100, 0, 0], [0, 64476, 0, 17856, 0, 0, -17004, -648], [0, -104711, 0, 21196, 0, 0, -17147, -1181], [124144, 0, 121252, 0, -22488, -21992, 0, 0], [0, -117327, 0, 29460, 0, 0, 9249, -9861], [0, 16368, 0, -8107, 0, 0, 4027, -5653], [155566, 0, -179090, 0, 9258, -22652, 0, 0], [102068, 0, 89798, 0, 65132, 42854, 0, 0], [-303623, 0, 88345, 0, -2574, -9029, 0, 0], [228650, 0, 64320, 0, 8862, 25224, 0, 0], [0, -38109, 0, -22226, 0, 0, 9496, -1263]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_33_c_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_33_5_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_33_5_c_a(:prec:=8)
    chi := MakeCharacter_33_c();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 5));
    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_33_5_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_33_5_c_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_33_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,5,sign)));
    Vf := Kernel([],Snew);
    return Vf;
end function;