
// Make newform 26.3.f.b in Magma, downloaded from the LMFDB on 23 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_26_f();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_26_f_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_3_f_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_3_f_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 := [121801, 0, -25778, 0, 2067, 0, -74, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0, 0], [349, 4, -37, 0, 1, 0, 0, 0], [-349, 4, 37, 0, -1, 0, 0, 0], [1396, -12865, 0, 1718, 0, -74, 0, 1], [2024898, -296126, -345859, 44290, 19195, -2262, -349, 40], [2024898, 296126, -345859, -44290, 19195, 2262, -349, -40], [-6980, 0, 1053, 0, -55, 0, 1, 0], [-4828764, 1626083, 734994, -292601, -38390, 16901, 698, -318]];
    Rf_basisdens := [1, 8, 8, 2792, 86552, 86552, 62, 86552];
    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_f();"
function MakeCharacter_26_f()
    N := 26;
    order := 12;
    char_gens := [15];
    v := [11];
    // 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_f_Hecke();"
function MakeCharacter_26_f_Hecke(Kf)
    N := 26;
    order := 12;
    char_gens := [15];
    char_values := [[0, 0, 0, 0, 0, 1, 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 := 3;
    raw_aps := [[0, 0, 0, -1, -1, 0, 0, 0], [0, 0, -1, 0, 1, -1, 0, 0], [2, 0, 1, -1, 1, 0, 1, -1], [-1, 1, 1, 1, 0, -1, 0, 1], [0, -1, -1, -6, 6, -1, -1, 1], [3, 0, 1, 1, 6, -9, -1, 2], [-4, -1, -2, -4, 1, 7, -1, 1], [3, 3, 1, 9, -10, 9, 2, -3], [-6, -2, -1, 2, -13, -1, 0, 2], [1, 0, 5, -1, -4, 3, 2, -1], [3, -3, -3, -1, 6, -5, -3, 0], [-12, 6, 1, 4, -4, 18, 6, -1], [17, 8, 2, -10, -10, 25, -8, 2], [-6, 1, 2, -6, -1, -16, 6, -6], [11, -1, 1, -9, -12, 3, -1, 2], [-14, -2, -2, 5, 26, 24, 5, -10], [-21, 7, 1, 37, 22, -37, -6, 7], [7, -2, 0, -7, 6, -4, -4, -4], [-8, -11, 1, 8, 8, -19, 11, 1], [-31, 5, 11, 15, 10, 15, -6, -5], [36, -2, -3, -27, -33, 6, 3, -1], [-12, -16, -16, 0, -24, -40, 0, 0], [-47, -3, 5, 43, -52, 9, 5, -8], [66, -1, -7, -63, 63, -67, -1, 7], [-22, -3, 7, 18, -6, 18, -10, 3], [-76, -16, -8, 37, 28, -8, 0, 2], [18, 4, -4, -40, 62, -58, -4, 0], [-14, 0, 1, -10, 23, -47, -28, 14], [-15, 8, 10, 24, -25, 1, 10, -2], [26, 3, 0, -26, 77, -37, 1, 1], [80, -26, -13, -52, 27, -13, 0, 24], [98, -2, -2, -8, 2, 0, -8, 16], [32, -21, -8, -21, -2, 21, 13, -21], [2, 21, 0, -2, -151, 86, -4, -4], [64, 21, -4, -25, -14, -25, 25, -21], [-63, 5, 5, 81, 58, 23, -5, 0], [-82, 27, 27, 8, -73, -46, 8, -16], [73, 1, 7, 19, 86, -19, 6, 1], [96, 25, 17, 2, -2, -71, 25, -17], [-122, -4, -8, -122, 4, -38, -25, 25], [-148, 6, 3, 90, -63, 3, 0, -32], [-50, 5, -5, 120, 55, -50, 20, 0], [-56, 1, 0, 56, 121, -60, -16, -16], [-95, -26, -18, 108, -108, 69, -26, 18], [32, -47, -23, -37, -37, -15, 47, -23], [-60, 5, 10, -60, -5, 138, -18, 18], [2, 0, -35, -170, -53, 141, 4, -2], [-94, 17, -17, -10, -10, -77, -17, -17], [-1, -23, 13, -95, 60, -95, -36, 23], [-17, -48, -18, -136, 35, -171, 18, 30], [4, -18, 18, 16, -192, 174, 24, 0], [37, 29, 1, 87, 36, -123, 1, 28], [220, -13, -12, -159, 60, 159, 1, -13], [-56, 25, 50, -56, -25, -10, -30, 30], [-116, 36, 18, 35, 18, 18, 0, 46], [22, 0, 19, 92, -77, 135, 44, -22], [-56, 22, 0, 56, 138, -58, 35, 35], [-30, 21, 23, -36, 36, 51, 21, -23], [-37, -26, -52, -37, 26, 260, 6, -6], [16, 21, 16, -86, -32, -54, -16, -5], [380, -42, -21, -178, -139, -21, 0, -24], [-3, 12, 6, 54, 57, -54, -6, 12], [-45, 47, -5, 27, 50, -23, 5, -52], [-170, -8, 8, 340, -106, 98, 0, 0], [-12, -20, -20, -36, -104, -124, -36, 72], [-204, 11, -26, 26, -178, 152, -26, 37], [-173, -25, -37, 201, -16, 201, 12, 25], [112, -51, 51, -182, 97, -148, 42, 0], [292, -31, 0, -292, -335, 152, -10, -10], [18, -3, 31, 63, -63, -21, -3, -31], [-76, -12, -11, 204, 204, -88, 12, -11], [21, 11, -41, 31, 20, 11, 41, -52], [-8, 0, -87, -212, -5, 97, -16, 8], [-74, 61, 0, 74, -61, 61, -55, -55], [-112, -5, 7, 280, 280, -117, 5, 7], [129, -45, -43, -365, 234, -365, -2, 45], [-2, -15, 15, -40, -87, 72, -44, 0], [282, 11, 43, -82, 168, 82, 32, 11], [-100, -48, -15, 32, -32, 52, -48, 15], [-189, 62, 50, 206, -5, 206, 12, -62], [38, 0, 51, 58, 65, -181, 76, -38], [24, 85, 60, 62, -36, -26, 60, 25], [-134, -9, -31, -12, -12, -143, 9, -31], [39, 30, 60, 39, -30, -236, -18, 18], [14, -6, -3, 8, -9, -3, 0, -30], [-30, 28, 28, -30, -44, -16, -30, 60], [-50, -13, -45, 250, 232, -250, -32, -13], [-9, 48, 6, 26, 26, 39, -48, 6], [460, 1, -64, -163, -232, -163, 65, -1], [119, 25, 81, -87, -200, 113, -81, 56], [-48, 38, -38, 64, -176, 214, -32, 0], [382, 15, 5, -310, 310, -367, 15, -5], [-25, 15, 7, 345, -312, 345, 8, -15], [-304, -78, -39, 154, 63, -39, 0, -4], [69, -33, -105, -43, 174, -131, -105, 72], [54, 49, 0, -54, -171, 110, 0, 0], [1, 50, 38, -200, -200, 51, -50, 38], [438, 37, 37, 36, -99, -62, 36, -72], [-36, 0, -27, 74, 241, -455, -72, 36], [70, -97, -48, -48, -22, -26, 48, 49], [-60, -84, -84, 14, 282, 198, 14, -28], [-129, -40, -50, 334, -334, 89, -40, 50], [-154, -7, -14, -154, 7, 256, 100, -100], [113, 112, 56, -67, 98, 56, 0, 21], [-46, 30, -30, 158, 152, -122, 66, 0], [244, 22, 49, -329, 195, 134, 49, -27], [310, -19, 7, 60, 60, 291, 19, 7], [16, 30, -1, -89, -15, -74, 1, -31], [88, -126, -126, -34, 86, -40, -34, 68], [1, 0, 9, -241, -62, 115, 2, -1], [60, 21, 0, -60, -171, 96, -58, -58], [552, 4, -21, -200, -200, 556, -4, -21], [144, 29, 36, -309, 158, -309, -7, -29], [-101, 101, 113, 129, -12, 141, -113, 12], [281, 37, 7, -617, -306, 617, -30, 37], [-288, 13, 26, -288, -13, -643, 7, -7], [127, -17, -1, -303, 160, -303, -16, 17], [314, 114, 57, -78, 297, 57, 0, -158], [-35, 0, -2, -115, -128, 258, -70, 35], [-222, -63, 0, 222, -555, 246, 54, 54], [16, -40, -151, -180, 180, -56, -40, 151], [-515, -34, -17, 207, -314, -17, 0, 101], [144, -60, -60, -6, 84, 24, -6, 12], [397, -83, 37, -85, 192, 85, 120, -83], [-178, -1, -23, 432, 432, -179, 1, -23], [-342, -14, 14, 598, 314, -328, -86, 0], [-382, -37, -82, 309, -28, -309, -45, -37], [-94, -29, -58, -94, 29, 704, 26, -26], [-160, 20, -20, 92, 272, -252, -228, 0], [-218, -76, -23, 317, -195, -122, -23, -53], [354, 121, 59, 204, -204, -233, 121, -59], [-214, 3, 65, 64, 64, -211, -3, 65], [-270, -122, -61, 88, 185, -61, 0, 94], [23, 0, 58, 937, -136, 214, 46, -23], [156, -59, 75, 36, 58, -36, 134, -59], [146, -33, 49, -199, -199, 113, 33, 49], [-336, 49, -23, 116, 292, 116, 72, -49], [-357, 133, 79, 441, 138, -441, -54, 133], [-150, 24, 48, -150, -24, 84, -23, 23], [-49, 0, 27, -359, 40, -107, -98, 49], [55, -71, -37, -465, 92, 373, -37, -34], [-456, 5, 85, 377, 377, -451, -5, 85], [310, -11, -22, 310, 11, -16, 34, -34], [453, -25, 111, -665, -564, -101, -111, 136], [148, 64, 32, -101, 244, 32, 0, 54], [507, 43, -17, -635, -68, 635, -60, 43], [-106, 60, -25, 247, 131, 116, 25, -85], [372, 20, -20, -731, -350, 370, 13, 0], [310, 98, 98, 20, 46, 144, 20, -40], [391, 27, 123, 25, 268, -293, 123, -96], [-483, 42, 32, -504, 997, -504, 10, -42], [-254, 268, 134, 147, -190, 134, 0, -40], [162, 20, -20, -264, -990, 1010, 60, 0], [126, 0, 57, -12, 349, -755, 252, -126], [218, -6, -3, -16, 451, -3, 0, -186], [-20, 106, 106, 116, -352, -246, 116, -232], [240, -99, 0, -240, 1205, -652, 0, 0], [-229, -126, 44, 108, -49, 108, -170, 126], [-94, -98, -98, 97, -110, -208, 97, -194], [373, -86, -126, 14, 499, -513, -126, 40], [252, -97, -157, -900, 900, -349, -97, 157], [110, -142, -284, 110, 142, 142, 17, -17], [-501, 113, 65, -165, -566, 731, 65, 48], [-1352, -45, 0, 1352, 27, -36, 20, 20], [-35, -72, -196, 252, 252, -107, 72, -196], [-495, 133, 65, 569, 430, 139, -65, -68], [-54, 0, -99, 250, 107, -115, -108, 54], [1, 222, 0, -1, -850, 536, 22, 22]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_26_f_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_26_3_f_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_3_f_b(:prec:=8)
    chi := MakeCharacter_26_f();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 3));
    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_3_f_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_3_f_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_26_f();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<3,R![97344, 3744, 12312, -468, 1209, -24, 39, 0, 1]>],Snew);
    return Vf;
end function;