
// Make newform 1344.4.c.d in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1344_c();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_1344_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_1344_4_c_d();".
// 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_1344_4_c_d();".
// 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 := [127008, 54936, 11881, 722, 2, -2, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0], [-172672164, -64680643, -2684972, -85196, 25724, -5869], [-7048478, -55944, -40071, -12321, 583, -111], [918082116, 357126139, 7733918, 1637642, -99182, 19855], [78246822, -867384, -621281, -191031, 29445, -1721], [-5879361852, -2162653733, -206179030, 653126, 988654, -233885]];
    Rf_basisdens := [1, 142698276, 1132526, 142698276, 1132526, 47566092];
    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_1344_c();"
function MakeCharacter_1344_c()
    N := 1344;
    order := 2;
    char_gens := [127, 1093, 449, 577];
    v := [2, 1, 2, 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_1344_c_Hecke();"
function MakeCharacter_1344_c_Hecke(Kf)
    N := 1344;
    order := 2;
    char_gens := [127, 1093, 449, 577];
    char_values := [[1, 0, 0, 0, 0, 0], [-1, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0], [1, 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, 0], [0, -3, 0, 0, 0, 0], [0, 1, 0, -1, 0, 0], [7, 0, 0, 0, 0, 0], [0, 9, 0, -2, 0, -1], [0, -2, 0, -1, 0, -1], [-3, 0, -2, 0, -1, 0], [0, 22, 0, -5, 0, 1], [-9, 0, 0, 0, -3, 0], [0, -18, 0, 1, 0, -1], [-92, 0, 3, 0, 3, 0], [0, -40, 0, 1, 0, 1], [-53, 0, -18, 0, 5, 0], [0, 46, 0, -10, 0, 2], [-260, 0, 8, 0, 0, 0], [0, -70, 0, 5, 0, 11], [0, -164, 0, 2, 0, -6], [0, 164, 0, -11, 0, -5], [0, 92, 0, -42, 0, 0], [-435, 0, -26, 0, 5, 0], [88, 0, 28, 0, -14, 0], [-582, 0, 16, 0, -2, 0], [0, -238, 0, 2, 0, 8], [5, 0, -14, 0, -21, 0], [280, 0, 62, 0, -4, 0], [0, 1, 0, 65, 0, -6], [-360, 0, 25, 0, -23, 0], [0, -445, 0, 122, 0, 5], [0, 880, 0, -34, 0, 2], [356, 0, -6, 0, 4, 0], [-406, 0, -110, 0, -32, 0], [0, 866, 0, 8, 0, -10], [-824, 0, -2, 0, -8, 0], [0, 28, 0, 72, 0, 36], [0, 826, 0, 9, 0, -25], [-380, 0, -58, 0, 50, 0], [0, 2036, 0, 135, 0, 33], [0, -136, 0, -114, 0, 48], [-1286, 0, -2, 0, 28, 0], [0, 1567, 0, 31, 0, 10], [0, 317, 0, -74, 0, -9], [0, 1710, 0, 3, 0, 39], [-2543, 0, 126, 0, -31, 0], [-804, 0, -67, 0, -37, 0], [0, 748, 0, -155, 0, 25], [-844, 0, 306, 0, -30, 0], [0, -570, 0, -212, 0, -92], [-544, 0, -262, 0, -82, 0], [0, 262, 0, -242, 0, 40], [0, 2334, 0, 71, 0, -85], [422, 0, -232, 0, -4, 0], [-3899, 0, -46, 0, 57, 0], [948, 0, -338, 0, -8, 0], [0, 574, 0, -140, 0, -98], [1779, 0, 78, 0, -3, 0], [-1763, 0, -372, 0, -133, 0], [0, -629, 0, 373, 0, -20], [-2308, 0, 237, 0, 33, 0], [0, 1856, 0, -365, 0, 7], [3910, 0, 26, 0, 6, 0], [0, -3578, 0, 123, 0, 93], [0, -1905, 0, -185, 0, -118], [0, 666, 0, 233, 0, 155], [-2380, 0, 420, 0, 28, 0], [1638, 0, 204, 0, 144, 0], [0, -3054, 0, 253, 0, 107], [0, 1478, 0, 14, 0, -238], [3206, 0, -334, 0, 50, 0], [0, -5199, 0, -42, 0, 63], [0, 2916, 0, -55, 0, -157], [-855, 0, 750, 0, 39, 0], [-3965, 0, 334, 0, 31, 0], [-2108, 0, 526, 0, 70, 0], [0, -88, 0, 446, 0, -58], [0, 686, 0, 64, 0, 4], [-7050, 0, -18, 0, -60, 0], [0, -6698, 0, -65, 0, 205], [0, 316, 0, -387, 0, 135], [-4476, 0, -118, 0, -164, 0], [-4228, 0, 312, 0, 30, 0], [0, 7912, 0, 116, 0, -96], [0, -4808, 0, 373, 0, 169], [-8771, 0, -96, 0, -25, 0], [-30, 0, -854, 0, -98, 0], [9256, 0, 220, 0, 4, 0], [0, -767, 0, -602, 0, -77], [5284, 0, -114, 0, -148, 0], [-1422, 0, 248, 0, 68, 0], [0, -11815, 0, -371, 0, 54], [1282, 0, -552, 0, -18, 0], [0, 4334, 0, 508, 0, 198], [-5760, 0, -346, 0, -38, 0], [11584, 0, 12, 0, -36, 0], [0, -7841, 0, -386, 0, 325], [0, -3370, 0, -332, 0, -68], [5158, 0, 436, 0, -86, 0], [0, -10631, 0, -485, 0, -140], [2067, 0, -798, 0, 105, 0], [0, 11592, 0, -892, 0, -40], [0, -6452, 0, 1227, 0, 27], [0, -3384, 0, -380, 0, -218], [0, -14966, 0, 807, 0, -67], [0, -5376, 0, -210, 0, -126], [-3802, 0, 244, 0, -60, 0], [0, -9660, 0, -786, 0, 132], [6542, 0, -206, 0, -194, 0], [0, 4098, 0, -922, 0, -20], [3827, 0, -1134, 0, 49, 0], [10357, 0, -74, 0, 301, 0], [-2618, 0, 300, 0, -228, 0], [7920, 0, 750, 0, 258, 0], [0, -1348, 0, -384, 0, 48], [8920, 0, -966, 0, 224, 0], [0, -6668, 0, -628, 0, 260], [19106, 0, 58, 0, -80, 0], [-1452, 0, 628, 0, -274, 0], [0, 8694, 0, 7, 0, 49], [8822, 0, -1174, 0, 188, 0], [0, -10828, 0, -883, 0, -259], [0, -12807, 0, -118, 0, -269], [0, 4884, 0, -1983, 0, -69], [19808, 0, 935, 0, 317, 0], [0, -6779, 0, 889, 0, -302], [0, -9623, 0, 782, 0, -141], [0, 14476, 0, -940, 0, -64], [0, -22316, 0, 97, 0, 121], [0, 4552, 0, 26, 0, -490], [-8570, 0, -1026, 0, -436, 0], [23932, 0, -435, 0, -87, 0], [0, 5582, 0, -2163, 0, 57], [0, 3420, 0, -278, 0, 64], [-6877, 0, 1122, 0, 163, 0], [-3540, 0, -1800, 0, 180, 0], [0, 5492, 0, 1030, 0, -626], [-4803, 0, 342, 0, 3, 0], [-15170, 0, 1230, 0, 174, 0], [0, 1165, 0, -1259, 0, 34], [0, -10964, 0, -1384, 0, -244], [0, -20305, 0, 175, 0, 234], [3860, 0, -1696, 0, -22, 0], [0, 1816, 0, 16, 0, -356], [0, 438, 0, -1719, 0, 315], [11342, 0, 1534, 0, -272, 0], [0, -22643, 0, 1234, 0, -125], [0, -162, 0, -2409, 0, -213], [-2870, 0, -68, 0, -326, 0], [0, 6164, 0, 1679, 0, 29], [22189, 0, 158, 0, -453, 0], [0, 10150, 0, 245, 0, -469], [-20705, 0, 202, 0, 511, 0], [0, 5472, 0, 1828, 0, 688], [-5849, 0, -2366, 0, -35, 0], [0, -30942, 0, -888, 0, 396], [10850, 0, -802, 0, 260, 0], [0, 3374, 0, 450, 0, -678], [-26627, 0, 2040, 0, -1, 0], [7684, 0, -2644, 0, 392, 0], [-24311, 0, 906, 0, 383, 0], [-9506, 0, -660, 0, 804, 0], [0, -11039, 0, -273, 0, -532], [0, 9483, 0, -1810, 0, -275], [30406, 0, -1562, 0, 178, 0], [2190, 0, 1430, 0, -352, 0], [0, 21728, 0, 998, 0, 170], [-4506, 0, -1830, 0, 30, 0], [-2980, 0, -1802, 0, 282, 0], [-24596, 0, 150, 0, -150, 0], [0, 1072, 0, -2523, 0, 459], [29512, 0, -2013, 0, 285, 0], [0, 28451, 0, 2171, 0, 230], [0, -8173, 0, -1922, 0, 705], [0, 8144, 0, 449, 0, -841], [-11147, 0, 706, 0, -503, 0], [31508, 0, -1587, 0, 15, 0], [-10892, 0, -144, 0, -468, 0], [-24535, 0, 110, 0, -421, 0], [0, -20952, 0, -50, 0, 556], [0, 8172, 0, -941, 0, -805], [-20460, 0, -1727, 0, 1, 0], [0, 30280, 0, -2613, 0, -195], [-6802, 0, -2224, 0, -694, 0], [0, 17180, 0, -3184, 0, 32], [0, 7712, 0, 1891, 0, 499], [-32547, 0, -698, 0, -769, 0], [-16995, 0, -1158, 0, 585, 0], [0, 36695, 0, -217, 0, 614], [0, 9520, 0, 720, 0, -96], [0, -17032, 0, 1412, 0, 188], [-5200, 0, -2333, 0, -575, 0], [-13542, 0, -484, 0, -746, 0], [-44644, 0, -1194, 0, 12, 0], [0, -38351, 0, -1938, 0, -829], [0, 20050, 0, 152, 0, -484], [0, -7407, 0, -2395, 0, 46], [0, -9857, 0, 14, 0, -483], [27337, 0, 106, 0, 151, 0], [-344, 0, 961, 0, 1219, 0], [0, 26712, 0, 2917, 0, -227], [-27111, 0, -654, 0, -621, 0], [-9116, 0, 2056, 0, 568, 0], [0, 11268, 0, 2469, 0, 393], [-19052, 0, 176, 0, -748, 0], [0, 27234, 0, 901, 0, -935], [19000, 0, 396, 0, -474, 0], [0, -8240, 0, 2048, 0, 156], [0, 12761, 0, 1921, 0, 78], [-16936, 0, 2068, 0, 196, 0], [0, 16343, 0, 722, 0, -955], [7230, 0, 3510, 0, 54, 0], [0, -29690, 0, 797, 0, -109], [-2362, 0, 2052, 0, -1284, 0], [0, 31323, 0, -363, 0, 828], [-7188, 0, -230, 0, 598, 0], [0, 13008, 0, -1652, 0, 1232], [13896, 0, 210, 0, -1290, 0], [-24002, 0, -2212, 0, 224, 0], [4548, 0, -2154, 0, 546, 0], [54127, 0, 2874, 0, 737, 0], [33041, 0, 372, 0, -473, 0], [0, 18114, 0, -1423, 0, 715], [0, -49148, 0, -42, 0, -138], [13064, 0, 327, 0, 1155, 0], [20584, 0, -3602, 0, 376, 0], [-31996, 0, 1212, 0, -816, 0], [0, 32234, 0, 2370, 0, -488], [0, 1292, 0, -839, 0, -1403], [-25977, 0, 2010, 0, 1089, 0], [22559, 0, -2108, 0, -855, 0], [-9812, 0, 253, 0, 421, 0], [0, 45261, 0, -1754, 0, -37], [0, 43420, 0, 718, 0, 526], [0, -22186, 0, -2311, 0, -277], [16120, 0, -4888, 0, -904, 0], [37304, 0, 76, 0, -1530, 0], [0, 13966, 0, -1645, 0, 1253], [33080, 0, 3488, 0, 1904, 0], [-54504, 0, 4452, 0, -294, 0], [0, 60216, 0, 565, 0, -259], [0, -37519, 0, -1582, 0, -889], [1922, 0, -1088, 0, 1314, 0], [0, -1665, 0, 1318, 0, 617], [0, 6160, 0, -5972, 0, 472], [-17764, 0, 2492, 0, -1096, 0], [0, 116, 0, -527, 0, -1607], [-10485, 0, -1750, 0, -119, 0], [22362, 0, 1532, 0, -734, 0], [1128, 0, 965, 0, -427, 0], [0, 43170, 0, 1470, 0, 1260], [0, -16632, 0, -4434, 0, -264], [22281, 0, 1004, 0, 295, 0], [0, 9848, 0, -2640, 0, 648], [-29961, 0, -6918, 0, -1779, 0], [39115, 0, -5420, 0, -323, 0], [-62032, 0, 2808, 0, -66, 0], [0, 10919, 0, 2807, 0, -418], [0, 44377, 0, 1390, 0, 835], [0, -76744, 0, -2573, 0, -77], [0, -14482, 0, -4595, 0, -845], [0, -3853, 0, -421, 0, -118], [-48430, 0, 672, 0, 1344, 0], [9234, 0, -2214, 0, -768, 0], [0, -93275, 0, -1402, 0, 195], [0, -61122, 0, 3409, 0, 73], [0, -47852, 0, -21, 0, 1617], [65595, 0, -2142, 0, -315, 0], [0, -16144, 0, 1380, 0, -1704], [0, -21912, 0, -3429, 0, -621], [-53509, 0, 726, 0, -407, 0], [0, 10700, 0, -5896, 0, -1030], [0, 8076, 0, 351, 0, 2151], [0, -22620, 0, 2013, 0, -513], [0, 49166, 0, -4662, 0, 462], [-38604, 0, 2266, 0, -1604, 0], [45876, 0, 3566, 0, 362, 0], [23636, 0, 1994, 0, 1088, 0], [-50128, 0, -5085, 0, 15, 0], [0, 12411, 0, 3458, 0, 2401], [0, -33636, 0, -623, 0, -887], [-22764, 0, 6545, 0, -49, 0], [0, 36894, 0, 642, 0, -1380], [46064, 0, 4594, 0, -2406, 0], [32658, 0, -4916, 0, -1262, 0], [62208, 0, 1030, 0, -2170, 0], [0, -91140, 0, -1657, 0, -487], [0, 53084, 0, 1132, 0, 412], [96161, 0, -724, 0, 695, 0], [-43634, 0, 8966, 0, -886, 0], [0, 56724, 0, -2257, 0, 1099], [1276, 0, 3255, 0, -2013, 0], [-20777, 0, 4282, 0, 685, 0], [0, -41800, 0, -1775, 0, -735], [0, 47166, 0, 2312, 0, -3254], [16564, 0, 3470, 0, -120, 0], [0, -19828, 0, -2626, 0, -634], [0, 42520, 0, -4102, 0, -1222], [0, -30569, 0, -4253, 0, -1994], [36988, 0, 2550, 0, 1494, 0], [0, 109489, 0, 1123, 0, -1256], [0, 25058, 0, 7494, 0, 2116], [0, 37340, 0, 2628, 0, 1692], [16838, 0, 4782, 0, -1158, 0], [0, -5902, 0, 1679, 0, 2153], [9690, 0, -1194, 0, 2244, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1344_c_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1344_4_c_d();".
// 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_1344_4_c_d(:prec:=6)
    chi := MakeCharacter_1344_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(1999) - 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_1344_4_c_d();".
// 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_1344_4_c_d( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1344_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<5,R![2085136, 0, 57348, 0, 444, 0, 1]>,<23,R![470448, -21186, 30, 1]>],Snew);
    return Vf;
end function;