
// Make newform 21.5.b.a in Magma, downloaded from the LMFDB on 18 January 2026.
// To make the character of type GrpDrchElt, type "MakeCharacter_21_b();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_21_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_21_5_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_21_5_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 := [756, 0, 13020, 0, 2017, 0, 82, 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], [21, 0, 1, 0, 0, 0, 0, 0], [198, 1560, -285, 188, -44, 4, -1, 0], [322, 0, 441, 0, 48, 0, 1, 0], [182, -1576, -285, -188, -44, -4, -1, 0], [0, 6114, 0, 1177, 0, 64, 0, 1], [198, -6264, -285, -892, -44, -20, -1, 0]];
    Rf_basisdens := [1, 1, 1, 48, 16, 16, 48, 48];
    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_21_b();"
function MakeCharacter_21_b()
    N := 21;
    order := 2;
    char_gens := [8, 10];
    v := [1, 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_21_b_Hecke();"
function MakeCharacter_21_b_Hecke( : Kf := false)
    N := 21;
    order := 2;
    char_gens := [8, 10];
    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 := ISA(Type(Kf), Fld), 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]];
    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, 0, -1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, -1, 0], [0, 0, 0, 0, 1, 0, 0, 0], [1, 2, 0, 2, 0, 1, -2, -5], [57, 1, -10, 3, 6, 1, 0, 0], [-5, -19, 0, 9, 0, -5, 11, 6], [-55, 7, 10, 21, -2, 7, 0, 0], [7, -46, 0, -16, 0, 7, -22, -5], [-30, 54, 0, 92, 0, -30, 2, -2], [-330, -16, -18, -48, -14, -16, 0, 0], [-332, 18, 6, 54, -44, 18, 0, 0], [23, 209, 0, -23, 0, 23, -23, -46], [592, -30, 26, -90, -80, -30, 0, 0], [2, 368, 0, -68, 0, 2, -24, 62], [30, -266, 0, -120, 0, 30, 80, 30], [-21, -147, 0, 17, 0, -21, 48, 46], [191, -1, -138, -3, -22, -1, 0, 0], [1142, 80, 186, 240, -4, 80, 0, 0], [89, 56, 0, -264, 0, 89, 66, -3], [-3868, -6, -260, -18, 180, -6, 0, 0], [-2912, 8, 24, 24, -276, 8, 0, 0], [-171, 397, 0, 445, 0, -171, 20, 68], [1, -529, 0, 67, 0, 1, 139, -70], [3662, -160, -136, -480, -328, -160, 0, 0], [16, 112, 0, 12, 0, 16, 211, -60], [192, -2, -174, -6, 18, -2, 0, 0], [85, 512, 0, -188, 0, 85, -62, -67], [5836, 174, -504, 522, 244, 174, 0, 0], [-76, -2016, 0, 294, 0, -76, -44, -66], [2906, -244, 806, -732, 68, -244, 0, 0], [199, -3017, 0, -681, 0, 199, -244, 84], [154, 3270, 0, -710, 0, 154, -266, 248], [7101, 69, -208, 207, 392, 69, 0, 0], [-30, 154, 0, -364, 0, -30, 740, 454], [-6566, 200, 810, 600, -336, 200, 0, 0], [-3989, -333, 190, -999, 922, -333, 0, 0], [7396, 382, -1590, 1146, 476, 382, 0, 0], [204, 2194, 0, -798, 0, 204, 1108, 186], [740, -444, 0, -1428, 0, 740, -393, -792], [185, 1456, 0, 428, 0, 185, -70, -983], [-8959, -307, 690, -921, 1526, -307, 0, 0], [283, -7788, 0, -1264, 0, 283, -426, 415], [-17302, 534, 1452, 1602, -492, 534, 0, 0], [-218, -3126, 0, 328, 0, -218, -1572, 326], [10372, -36, 144, -108, -1064, -36, 0, 0], [-4974, 580, -1366, 1740, -756, 580, 0, 0], [-10602, -246, -684, -738, -1300, -246, 0, 0], [87, -12403, 0, -83, 0, 87, 196, -178], [27079, -457, -846, -1371, 18, -457, 0, 0], [-1046, -5190, 0, 2502, 0, -1046, 1258, 636], [1555, -2010, 0, -4312, 0, 1555, -470, -353], [13078, 884, 2772, 2652, 936, 884, 0, 0], [547, 8301, 0, -263, 0, 547, 372, -1378], [-463, 7399, 0, 523, 0, -463, 2081, 866], [-541, 4980, 0, 800, 0, -541, -1922, 823], [1758, 7426, 0, -4602, 0, 1758, -1987, -672], [28662, -1116, 4578, -3348, 698, -1116, 0, 0], [-37818, -216, -978, -648, 1016, -216, 0, 0], [-118, 9346, 0, -90, 0, -118, -322, 444], [37579, -251, -666, -753, -1582, -251, 0, 0], [-1278, -7506, 0, 1990, 0, -1278, -845, 1844], [-41003, 1511, 86, 4533, -2778, 1511, 0, 0], [-1124, 17674, 0, 1622, 0, -1124, 2520, 1750], [69060, 1158, -2108, 3474, 188, 1158, 0, 0], [-358, -1702, 0, 5476, 0, -358, -2076, -4402], [-10500, 2262, 2194, 6786, -508, 2262, 0, 0], [-14474, -1778, -2478, -5334, -3940, -1778, 0, 0], [-2857, -10638, 0, 6682, 0, -2857, 834, 1889], [-93, 2167, 2114, 6501, -6, 2167, 0, 0], [-115, -31533, 0, -373, 0, -115, -887, 718], [1195, 19102, 0, -6172, 0, 1195, -422, 2587], [-65250, -1862, 124, -5586, 1716, -1862, 0, 0], [-94574, -2060, -5348, -6180, 1256, -2060, 0, 0], [104036, 518, -406, 1554, 140, 518, 0, 0], [1276, 1232, 0, -1732, 0, 1276, 3164, -2096], [-2706, 18002, 0, 7252, 0, -2706, 5914, 866], [76419, 239, -4266, 717, 6226, 239, 0, 0], [-3682, 6738, 0, 8324, 0, -3682, -2758, 2722], [-58792, 4938, 1128, 14814, -5196, 4938, 0, 0], [2477, -26225, 0, -8257, 0, 2477, 784, 826], [83502, 388, 2922, 1164, 5904, 388, 0, 0], [-691, -5346, 0, 1668, 0, -691, -8026, 405], [9322, -3832, -5824, -11496, 5472, -3832, 0, 0], [55784, -3612, 6772, -10836, -2304, -3612, 0, 0], [3807, -11448, 0, -12572, 0, 3807, 9246, 1151], [1872, -2580, 0, -8124, 0, 1872, 2520, 2508], [-83102, -3326, 4026, -9978, -8812, -3326, 0, 0], [-4752, 18392, 0, 8604, 0, -4752, 7985, 5652], [11528, 2516, 3468, 7548, 2360, 2516, 0, 0], [-4057, 14605, 0, 13629, 0, -4057, -11084, -1458], [3810, -57024, 0, -5976, 0, 3810, -4640, -5454], [-91258, 976, 6934, 2928, -1304, 976, 0, 0], [1187, -22552, 0, -8360, 0, 1187, -4538, 4799], [-135750, 1092, -13830, 3276, 5672, 1092, 0, 0], [-4362, -30282, 0, 10542, 0, -4362, 11748, 2544], [-3198, 52358, 0, 10606, 0, -3198, 1325, -1012], [-1193, 12689, 0, 6465, 0, -1193, -8383, -2886], [209125, 421, -14304, 1263, 4580, 421, 0, 0], [-598, -4168, 2890, -12504, 7256, -4168, 0, 0], [135028, -94, 662, -282, -10272, -94, 0, 0], [3382, -32402, 0, -16748, 0, 3382, -796, 6602], [-6973, 18373, 0, 29001, 0, -6973, -1224, -8082], [-4838, -39702, 0, 8960, 0, -4838, 5370, 5554], [103840, 1906, -5870, 5718, 13232, 1906, 0, 0], [-73482, 1428, 12444, 4284, -5872, 1428, 0, 0], [-921, -30711, 0, 2369, 0, -921, -8332, 394], [10107, -739, 0, -32235, 0, 10107, -485, 1914], [-7555, -54484, 0, 19376, 0, -7555, 8130, 3289], [-52152, -2838, 5684, -8514, -22324, -2838, 0, 0], [-86070, -1758, -8720, -5274, 18380, -1758, 0, 0], [-214056, 10122, 15576, 30366, 11564, 10122, 0, 0], [-10574, 22278, 0, 33044, 0, -10574, -3890, -1322], [-97523, -4463, 10620, -13389, -11260, -4463, 0, 0], [194052, -6604, -13240, -19812, 8320, -6604, 0, 0], [5194, 50238, 0, -17348, 0, 5194, -8738, 1766], [169963, 993, 19994, 2979, -3614, 993, 0, 0], [-10404, -3718, 0, 17558, 0, -10404, 8324, 13654], [-2042, 31046, 0, 8672, 0, -2042, -8134, -2546], [543, 41758, 0, -1958, 0, 543, 2018, 329], [289875, -3193, 11050, -9579, 946, -3193, 0, 0], [-138138, -9420, 7422, -28260, -17776, -9420, 0, 0], [10314, 10350, 0, -22250, 0, 10314, -4839, -8692], [13695, 58168, 0, -30672, 0, 13695, 1454, -10413], [39729, 277, 18228, 831, -9096, 277, 0, 0], [5482, -69734, 0, -11220, 0, 5482, 7806, -5226], [-57932, -8994, 20940, -26982, -14108, -8994, 0, 0], [-3424, -78332, 0, 7032, 0, -3424, 24340, 3240], [-367024, -3722, -27862, -11166, 5806, -3722, 0, 0], [-199799, 3513, -8118, 10539, 13750, 3513, 0, 0], [-373972, -10226, -5094, -30678, 7492, -10226, 0, 0], [4529, -23942, 0, -9172, 0, 4529, -5282, -4415], [-55106, 6240, 7054, 18720, -14036, 6240, 0, 0], [-94760, 8802, -8068, 26406, 13468, 8802, 0, 0], [3011, -50811, 0, -391, 0, 3011, -7387, -8642], [608326, 8852, 28476, 26556, -15288, 8852, 0, 0], [11266, 45054, 0, -20758, 0, 11266, -4087, -13040], [353591, -5617, 17040, -16851, 19256, -5617, 0, 0], [-17036, -33028, 0, 55356, 0, -17036, -7331, -4248], [-18460, 4584, 0, 41370, 0, -18460, 23960, 14010], [-786541, -6501, -744, -19503, -7368, -6501, 0, 0], [-622, -80382, 0, 4560, 0, -622, -7824, -2694], [83488, 5892, 2652, 17676, 27052, 5892, 0, 0], [1775, -8956, 0, -9240, 0, 1775, -15090, 3915], [59431, 16999, 10018, 50997, 27722, 16999, 0, 0], [23276, 56510, 0, -47326, 0, 23276, -15748, -22502], [5315, -3549, 1746, -10647, 44010, -3549, 0, 0], [3503, 70497, 0, 12713, 0, 3503, 19741, -23222], [-79725, -6983, -10830, -20949, -29862, -6983, 0, 0], [-5219, -104688, 0, 7356, 0, -5219, -15062, 8301], [-207888, -5562, -43164, -16686, 32852, -5562, 0, 0], [377, 144455, 0, -14445, 0, 377, -867, 13314], [361366, -5092, 14550, -15276, -2640, -5092, 0, 0], [7056, 141050, 0, 1138, 0, 7056, 3140, -22306], [-53034, -2192, 51786, -6576, -3168, -2192, 0, 0], [-8097, -45122, 0, 14704, 0, -8097, 42890, 9587], [585024, -572, -6156, -1716, -40428, -572, 0, 0], [9085, 190259, 0, -28869, 0, 9085, -16731, 1614], [-72200, 22642, -22204, 67926, 2516, 22642, 0, 0], [-7820, -102148, 0, 6928, 0, -7820, 39603, 16532], [-7883, 24146, 0, 1242, 0, -7883, 50262, 22407], [-25292, 28508, 0, 71744, 0, -25292, 6672, 4132], [-287670, -14336, -40726, -43008, 5700, -14336, 0, 0], [21449, -120215, 0, -39903, 0, 21449, -45872, -24444], [-10054, -57646, 0, 44354, 0, -10054, -30198, -14192], [-18486, 69506, 0, 40822, 0, -18486, 784, 14636], [193664, -3288, -57264, -9864, -18444, -3288, 0, 0], [-428201, 13231, 24618, 39693, 41642, 13231, 0, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_21_b_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_21_5_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_21_5_b_a(:prec:=8)
    chi := MakeCharacter_21_b();
    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_21_5_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_21_5_b_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_21_b();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,5,sign)));
    Vf := Kernel([],Snew);
    return Vf;
end function;