
// Make newform 26.4.c.b in Magma, downloaded from the LMFDB on 15 May 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_26_c();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_26_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_26_4_c_b();".
// 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_26_4_c_b();".
// 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 := [2916, 54, 55, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 1, 0, 0], [2916, -55, 55, -1], [109, 0, 0, 1]];
    Rf_basisdens := [1, 1, 2970, 55];
    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_26_c();"
function MakeCharacter_26_c()
    N := 26;
    order := 3;
    char_gens := [15];
    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_26_c_Hecke();"
function MakeCharacter_26_c_Hecke(Kf)
    N := 26;
    order := 3;
    char_gens := [15];
    char_values := [[-1, 0, 1, 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, -2, 0], [0, 1, 1, 0], [-3, 0, 0, -1], [22, 1, -23, 1], [0, -7, 1, 0], [-10, 7, -6, 5], [69, -8, -61, -8], [-2, 1, 1, 1], [0, -3, -15, 0], [0, 12, 93, 0], [128, 0, 0, 24], [0, -4, 353, 0], [0, 20, -131, 0], [34, 25, -59, 25], [84, 0, 0, 56], [-267, 0, 0, -1], [198, -7, -191, -7], [-311, -32, 343, -32], [0, -63, 85, 0], [294, -19, -275, -19], [-319, 0, 0, 15], [404, 0, 0, -48], [-864, 0, 0, -36], [0, -31, 451, 0], [460, -41, -419, -41], [0, -32, 665, 0], [-196, 0, 0, -28], [0, 21, -279, 0], [590, 0, 0, -196], [-663, 180, 483, 180], [0, -107, 597, 0], [984, 0, 0, -92], [105, -320, 215, -320], [1690, -163, -1527, -163], [-1215, 192, 1023, 192], [-304, 0, 0, 304], [1289, 0, 0, -93], [1786, -63, -1723, -63], [0, 273, -639, 0], [2496, 115, -2611, 115], [0, -147, 561, 0], [1577, 0, 0, 171], [-1494, -307, 1801, -307], [0, -280, 197, 0], [0, 249, -1401, 0], [-2726, 409, 2317, 409], [0, 277, 2505, 0], [0, -51, 2785, 0], [78, -215, 137, -215], [-4426, 0, 0, -220], [-3822, 0, 0, 60], [972, 0, 0, -204], [-875, -80, 955, -80], [906, -247, -659, -247], [0, -252, -2235, 0], [0, -451, -2927, 0], [-24, -193, 217, -193], [0, 129, 2065, 0], [1537, -692, -845, -692], [-1695, 0, 0, 223], [0, 345, -2327, 0], [2613, 700, -3313, 700], [-4816, 0, 0, 476], [-1980, 0, 0, -324], [-142, 0, 0, -668], [4329, 0, 0, 495], [-2294, 369, 1925, 369], [1613, 0, 0, -1325], [-78, 921, -843, 921], [0, 37, 2139, 0], [0, -1360, 2617, 0], [8880, 0, 0, 24], [0, 341, -5503, 0], [6229, -976, -5253, -976], [0, -647, 7377, 0], [-9870, 333, 9537, 333], [-5139, 0, 0, -533], [-4568, 1559, 3009, 1559], [0, -48, -2187, 0], [-311, 108, 203, 108], [0, -263, -6643, 0], [-535, 0, 0, -109], [0, -71, -8395, 0], [-7619, -256, 7875, -256], [0, 665, 5213, 0], [12552, 0, 0, 548], [-10428, -261, 10689, -261], [0, 520, -8967, 0], [5625, -900, -4725, -900], [-5896, 0, 0, -160], [-9756, 0, 0, 500], [0, -1027, -9971, 0], [-4574, 1009, 3565, 1009], [0, 1281, -6075, 0], [-13156, 0, 0, -704], [-3054, -1483, 4537, -1483], [0, 2052, -1791, 0], [-2595, 0, 0, -893], [0, -1651, -979, 0], [893, 0, 0, 1683], [1220, 0, 0, 672], [0, -684, 13629, 0], [-16002, -1039, 17041, -1039], [0, 1089, -2157, 0], [1532, 0, 0, -1240], [-16819, 0, 0, 1123], [0, 1585, 3437, 0], [-6075, 0, 0, -93], [14040, 0, 0, 1044], [0, -1344, 11989, 0], [15550, 285, -15835, 285], [0, 428, 13913, 0], [2589, 60, -2649, 60], [5204, 0, 0, -1728], [16450, 1241, -17691, 1241], [14517, 1264, -15781, 1264], [-4418, -3123, 7541, -3123], [0, -2079, -5427, 0], [0, 629, -21989, 0], [-14886, 2313, 12573, 2313], [0, -2128, 8993, 0], [0, -100, 3089, 0], [-13818, 0, 0, 308], [-9966, 1237, 8729, 1237], [0, -919, -15751, 0], [4542, 0, 0, -596], [18757, -1000, -17757, -1000], [-15450, 2841, 12609, 2841], [-6508, 0, 0, 2460], [-14011, 0, 0, -1525], [0, 1457, 27773, 0], [0, -4551, -2403, 0], [0, -459, 5281, 0], [0, 5221, -3117, 0], [16428, -3109, -13319, -3109], [0, 2421, -5969, 0], [32496, 1071, -33567, 1071], [-17510, 241, 17269, 241], [-23808, 755, 23053, 755], [0, 596, 12205, 0], [-11920, 0, 0, 4408], [0, 849, 11823, 0], [30814, 429, -31243, 429], [19788, 0, 0, 2512], [0, -364, -26707, 0], [-27450, -851, 28301, -851], [-9259, 0, 0, 2831], [-11691, 0, 0, -2973], [-2272, 0, 0, -76], [-5148, 0, 0, 4420], [21265, -752, -20513, -752], [0, 380, -3755, 0], [-11548, 0, 0, -2632], [0, 213, -27027, 0], [0, 1133, 593, 0], [16020, 0, 0, 1396], [-17858, -423, 18281, -423], [9117, -4216, -4901, -4216], [10721, 0, 0, -561], [17910, 0, 0, -2080], [0, 3761, 12649, 0], [-8700, -2457, 11157, -2457], [25796, 0, 0, -3820], [8574, -491, -8083, -491], [0, -4884, 19425, 0], [-30216, 0, 0, 2472], [0, 3133, 6117, 0], [-27143, 3232, 23911, 3232]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_26_c_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_26_4_c_b();".
// 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_26_4_c_b(:prec:=4)
    chi := MakeCharacter_26_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_26_4_c_b();".
// 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_26_4_c_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_26_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<3,R![2704, 156, 61, -3, 1]>],Snew);
    return Vf;
end function;