
// Make newform 648.4.a.g in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_648_a();"
// To make the coeffs of the qexp of the newform in the Hecke field type "qexpCoeffs();"
// To make the newform (type ModFrm), type "MakeNewformModFrm_648_4_a_g();".
// 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_648_4_a_g();".
// 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 := [13, 0, -8, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [4, -14, -1, 2], [-4, -16, 1, 4], [-12, 0, 3, 0]];
    Rf_basisdens := [1, 1, 1, 1];
    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_648_a();"
function MakeCharacter_648_a()
    N := 648;
    order := 1;
    char_gens := [487, 325, 569];
    v := [1, 1, 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;

function MakeCharacter_648_a_Hecke(Kf)
    return MakeCharacter_648_a();
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, 0], [-2, -1, 0, 0], [0, 1, -1, 0], [-2, -1, 2, -1], [1, 3, -1, 2], [-4, 2, 4, -1], [20, 3, 5, 0], [-50, -5, -6, 7], [-54, 9, -4, 4], [20, -2, 2, 16], [-69, -1, -17, 22], [-96, 12, 4, -20], [40, -19, 3, -56], [-192, -16, 0, -12], [-236, 10, -24, 34], [-248, 12, 24, 28], [-137, -3, 1, -114], [116, -19, -21, 96], [-430, -27, 6, -43], [-191, -44, 40, 36], [172, 23, -23, -160], [-532, 38, -20, -6], [-528, -40, 56, 55], [-454, -40, 4, -204], [-420, -54, 60, 26], [556, 98, 46, 112], [-276, 94, -4, -134], [-287, 121, -7, 74], [-912, -72, -40, -171], [172, -57, -103, 128], [-418, 87, -86, 243], [-828, 70, -84, 125], [828, -110, -42, 120], [110, -13, 52, -342], [440, -178, 66, -128], [-797, 79, -29, 34], [1440, 48, 96, -32], [-450, 3, 90, 419], [102, -21, -64, 174], [-192, -72, 8, -308], [-1278, -244, 36, -80], [-438, -247, 46, -367], [-1549, -166, 58, -156], [-6, -95, 44, 296], [748, -128, 112, -128], [1576, 71, -183, -88], [268, 87, -199, 560], [1482, 125, -34, 201], [-851, 9, -47, -334], [1192, 336, -68, 327], [1148, -186, -92, 698], [-207, 6, 290, 416], [1382, 187, 58, -437], [2696, 40, -196, -269], [2776, 124, -248, -504], [4082, 45, 172, 50], [-772, 263, -119, -256], [-278, 72, 240, 680], [2984, -144, 148, -15], [2036, -124, 196, -584], [1722, -55, -188, -166], [2652, -146, -70, -184], [4428, -98, 4, 606], [-1413, 82, -458, 912], [3258, 29, -216, 178], [2612, -189, 133, 464], [-126, -40, -420, -388], [1710, -209, 554, -901], [42, -364, -232, 708], [-2608, -112, 72, 48], [-918, 529, -290, 645], [-2672, -30, 206, 304], [590, -576, 0, -192], [-172, -742, -34, 152], [-2898, 987, -246, 411], [-1124, -514, -408, 6], [1619, 229, 133, 178], [1644, -370, 464, 385], [345, 130, -6, 28], [1716, 26, -452, -1390], [2537, 11, 611, -922], [6452, 258, 428, 814], [2167, -342, -186, 152], [-4644, -304, 272, -800], [-616, 204, -368, 1912], [-4856, 104, 260, -1112], [5921, -362, 38, -900], [-7100, 546, 144, -214], [-4216, 32, -256, 688], [-6684, 266, 300, -230], [1970, 493, -42, -1467], [-9932, 226, 462, 448], [-9570, -609, -206, -2297], [960, 755, -147, 664], [-7692, 450, -100, 1578], [-3636, 478, -392, 1798], [-6472, 504, 60, -552], [6688, 291, 221, 600], [4965, -981, 267, 142], [1460, -524, -444, -1352], [-9650, 759, 96, -1238], [-5048, -444, -64, -3000], [-13604, 334, -248, -561], [6816, 892, -108, 2112], [-1933, -1072, 292, 972], [-938, -477, 234, 3123], [6880, -536, 400, -1861], [-12228, 494, 964, -374], [1111, -1456, 100, -1620], [-16552, -271, -241, 128], [5678, 28, -316, 448], [-3024, 1100, -620, 1379], [-3728, -1390, 494, -1232], [-7160, -298, -262, -64], [5236, -506, -1436, 849], [1572, -730, 146, 552], [6182, 487, -862, 1863], [-11844, 214, 592, 1150], [1746, 297, 150, 3037], [7979, -453, -725, 2206], [8011, -206, 954, -1060], [-18524, -1182, -256, -1286], [-8312, 1300, -336, 40], [12236, 1031, -367, -640], [17802, 717, -856, -1358], [2237, 837, 5, 82], [-4082, 1523, -54, 1895], [-18432, -537, 537, 1552], [-8062, 1604, -684, -664], [16748, 24, 48, -328], [13888, -1048, -416, 1780], [-9216, 1699, 29, 896], [13970, 708, 380, 608], [-3700, -742, 212, -7], [563, -1070, 34, -1356], [-5838, -1023, 608, 544], [13744, -1163, 491, -3080], [8998, -809, -828, 778], [22148, 706, 872, 489], [5512, 92, 644, -3776], [17682, -351, -808, -158], [-13444, 2288, 80, -1968], [-2734, 545, -146, -2407], [-4622, -924, 916, -1208], [-14526, 373, 246, -4207], [-4810, -824, 1648, 3112], [17892, 26, 1256, -1671], [9564, 116, -1628, -2184], [24358, -105, -206, 859], [3003, -827, 861, -4966], [224, -492, -1756, -44], [10436, 254, 378, -376], [8822, 327, 1154, 3147], [18160, -850, -238, 4304], [28150, 375, -414, -3781], [-13076, 2119, -1079, 1120], [11924, -778, 140, 2107], [-3321, -2184, -1788, -316], [20790, 867, -104, -2058], [-14490, 2115, -1262, 3551], [-2292, 1062, -1080, 3845], [-3592, 853, 1755, -5840], [37062, 475, -702, -2609], [-15720, 2536, 668, -2984], [5148, -2154, 612, -4922], [-1112, -1469, 765, -4688], [21103, 1617, 681, 2658], [-34063, -638, -138, 1536], [15988, -766, 712, -3830], [8832, -1688, -1896, 1956], [-8901, -623, 1849, 3042], [-4516, 694, -2044, 5922], [-3323, 2880, 576, 1536], [-11908, -309, 1029, -2768], [-7552, -2372, 1148, -3940], [-5344, 1057, -2049, -344], [8286, 979, 1068, 3756], [18088, -698, 730, -2032], [-32965, -1367, 905, 218], [5240, 282, -138, 768], [16598, 651, 2754, 79], [5541, 155, -2105, 514], [-20184, -464, 740, 6848], [48, -112, 1328, 4864], [-29178, 159, 380, 320], [-22511, 2737, -775, 2066], [30336, -2255, 1039, -936], [4822, 3736, -1752, -1344], [7146, 3681, -1634, -455], [-16907, 904, 140, 1388], [-11676, 818, 4284, -982], [38344, 1475, -547, -184], [16414, -837, -2228, 3326], [-13398, 693, -482, -4383], [-26560, 632, -744, -3912], [271, -112, 600, 8392], [9730, 684, 140, -4664], [-40744, -1452, 80, 1561], [-14502, -695, -850, -627], [-9154, 563, -812, -1776], [8708, -1533, 1741, -5040], [16382, -196, 2312, -3444], [-34463, -2380, -116, -3136], [-37338, -1269, 338, 23], [-41652, -698, -1040, -722], [28280, 483, 109, 4720], [14580, 3266, 1660, 106], [-3256, 3032, -1748, -856], [5140, 1021, 2251, 8512], [9534, 1128, -1372, 8260], [-13338, 1651, 0, -3710], [22816, -1193, 809, -7344], [-26158, 1793, -3410, 4289], [-19684, 3414, 20, 1054], [32342, -1520, 4060, -9564], [25460, 1675, -1595, -1056], [7132, 3262, 2144, 2827], [-18372, 3014, -236, -2974], [-10578, -189, 2396, 2424], [-4723, 1555, 951, 9530], [-3432, -1117, -3379, 2912], [-13644, -278, -448, 2895], [20552, 3890, 718, 3664], [-34152, -3844, 1656, 420], [31739, -1079, -291, -4746], [-19560, -2904, -924, -3736], [-35358, -1443, 950, 3101], [3144, 3704, -2040, -880], [21940, -5302, 3156, -4178], [-11763, 1821, -2791, 4150], [-18308, -1607, 751, 2640], [-25420, -241, 2753, 9024], [8824, 2520, -1692, 303], [-44388, 1938, -2234, 3032], [-30688, 152, 2736, 3824], [-40495, 3294, 3258, -3568], [-3980, 1014, -308, 3462], [-20476, -2670, 604, -2006], [2410, 3345, 318, 1073], [-20514, -913, -1038, -3153], [-14032, 6845, -813, -4840], [45760, 5098, -1946, 320], [-52154, -324, -3164, 5440], [-18480, 1516, -2156, 7788], [1346, 3397, 4550, 2401], [-38216, 2271, 2017, -1136], [26646, -3733, 250, -501], [-14216, -282, 4378, -6048], [1820, -938, -668, 2822], [-29079, -2257, -1357, -10494], [44664, -1380, 3840, -11199], [-36952, -548, -3832, -3308], [17377, 6084, 2664, 6036], [-870, 3177, -3108, 6524], [-1650, 1031, -2214, 9235], [52805, 3153, -3111, -10350], [-29204, -1377, -951, 6960], [-23430, 1693, -2496, 9382], [13702, 2984, 1812, 8084], [16552, 3952, 912, 7968], [-4884, -6794, 2516, -242], [26857, -6405, 1875, -7402], [-4758, 2004, -3240, -6140], [-8552, 2876, 1424, 4828], [-60916, -2310, 1246, 3896], [23534, -1449, -2216, -12550], [-1600, -7820, 3260, -8589], [-30664, 2178, 1726, -8848], [34406, -129, 3100, 2376], [-101, 1263, -2109, 7026], [-70888, 109, -605, -1400], [60898, -1372, -1480, 10996], [57316, -3372, 2092, -13072], [19945, 836, 1996, -12592], [-19516, -6106, 1706, -1264], [33312, 608, 3296, 392], [-24397, -1257, 3275, 8402], [40975, -4156, -1488, -4980], [74428, 3750, -3596, -826], [-24944, -5936, 2464, -11464], [-6608, -3762, 1202, 6144], [-44816, 1360, -144, 15164], [63827, -4725, -2645, 11230], [-35464, -1466, -934, -17088], [87700, -3062, -340, 3670], [-37003, -2882, 4414, -8452], [4548, 4634, -1000, 594], [13544, 3155, -499, 11904], [-52888, -1064, -124, -17923], [33532, -6146, 792, 8470], [-22170, -4853, 3810, -1257], [31696, -3004, -4332, 3237], [18348, 2110, 2364, 58], [-51777, -535, 4693, 1806], [5038, -2417, -2416, 15130], [58088, 2960, 2048, -1488], [2898, 2233, -3720, -5664], [47790, 7919, 2898, 9751], [7328, 3918, 2466, 11952], [34535, -3982, 6778, -9940], [-54412, -1154, 3204, -5842], [-31048, -2913, -5999, -1120], [37498, 157, -4090, 941], [-45912, 2486, -6246, 13408], [13250, 8356, 1488, 8188], [27774, -3777, 5906, -10537], [-64846, 1464, 4640, -5176], [-31648, -4920, 176, -11580], [76607, 4263, 1395, 10202], [19938, -107, 3222, 11293], [-5364, 8310, -784, 3630], [104396, 4518, 2144, 8155], [-25460, -5011, 635, 2128], [-12980, -5122, -476, -11150], [-19822, 2216, -9596, 6756], [-88092, -1222, -388, -14454], [57876, -4398, 1020, -8230], [-69283, 2716, -8080, 12548], [2400, 3948, 4876, 6780], [-72488, 1822, 1074, -4752], [22558, -756, -2712, -12676], [31394, -6483, 4332, -18278], [62152, 1790, -4782, 9008], [-34424, 7280, 5180, -5984], [-35679, -766, -8666, 2368], [-41688, -4679, 9063, 7640], [17544, -181, -4443, -6184], [-61946, -345, 770, 15455], [-25260, -1246, 8296, 5514], [-57998, -208, -1064, -17704], [-40338, 1791, 7640, -1110], [42648, -5304, 328, 4144], [12414, -8057, 1202, -17377], [24228, -5977, 8865, -14960], [-131520, 104, 1280, -8616], [-25841, -99, 4601, 12614], [47520, 6436, -1588, 6697], [57026, 7096, 916, 25412], [43176, -4730, 970, 18016], [26971, -1583, -2555, -4554], [-17472, -6988, 924, -14844], [-139254, 3097, 4292, -4976], [29868, -4030, -546, -17584], [-53198, 4725, 2836, 12690], [6706, -11167, 614, 7701], [35793, 4749, -5095, -14730], [-113264, -18, 1634, -10176], [44172, -5338, 1876, 12066], [10298, 3453, 1024, 31534], [-5400, -801, -1359, 22520], [75629, -9658, -878, 5200], [123370, -2763, -2840, -4430], [70476, 5317, -6821, -6464], [12791, -2607, 7529, -2046], [-77560, -780, 152, 15205], [-27308, -2894, -9140, -3794], [-574, 3817, -9234, 4241], [-73880, -1528, -2924, -6648], [-70914, -4085, -5910, 9387], [39959, 7639, -1365, -10254], [49464, 996, 6136, -14325], [-1806, 2205, 3462, -20943], [12584, 3148, -4632, -21508], [7624, 9616, -8752, 9616], [3879, -1872, 5628, -15676], [-138732, 858, -2408, 5026], [84364, -4436, -5100, 1104], [-11606, 6008, 7144, -5984], [-66106, 9435, 3498, -23821], [42768, 4653, 451, 10600], [71540, 4018, -4948, 7490], [22306, -683, 6148, -6322], [-2408, -1892, 4084, 23104], [-21667, 2701, -4207, 29566], [-78666, 355, -1638, 16043], [24444, 4014, 5636, -11202], [-47393, 9040, 6400, -3824], [40152, -9356, 8680, -22108], [45053, -750, -7074, 16504], [42318, -7533, -3828, 20104], [-72196, 12250, -2500, -10093], [-20484, 2126, -6430, 33392], [-113448, 5116, 2136, 9313], [75832, 227, 285, 1416], [-11910, 1401, 7406, -9451], [52884, 3908, 4604, -720], [47297, 3717, 345, -8706], [29044, -9567, 3447, 15568], [-122196, 6542, -316, 7726], [-132659, -2548, -6720, -3020], [-95234, -7725, -1860, -11732], [-126750, -1999, 1726, 10689], [-37272, -3163, -4133, 600], [110376, 5356, -1224, 1828], [-13307, -5862, -3698, 2480], [130200, -9715, 4355, -10208], [-51732, 5870, -1840, -265], [6056, 2413, 7139, 13784], [-42146, -9881, -1336, -20042], [-78397, 6375, -1093, -14334], [9216, -12324, 1444, -19172], [-92072, -9431, 167, -24480], [-54244, -13850, 3616, -14505], [-5942, 4157, -2912, 9292], [49684, -9329, 1809, -7152], [-70667, -2265, -6873, 16774], [85140, -1286, -3280, 11143], [2720, 3025, -1393, -5144], [-47784, -17452, 4864, -12736], [-89281, -3812, 460, -552], [124102, -2485, -1184, -9286], [112802, -13207, -1114, 5941], [33304, -1224, -5144, 1296], [66117, -276, 20, -16416], [40714, 12453, -11080, 592], [25140, -1574, -10068, 13566], [8768, -682, 1562, 15120], [-67236, 5302, 9360, 425], [43952, 12992, 752, -648], [11924, 6662, 7852, 20806], [23282, -5388, -9848, 13620], [26492, 3454, -6780, 21574], [-75064, 5284, -712, 428], [-43637, -5826, -11342, -15912], [-97198, 12785, 3992, -22324], [43300, -8102, 4052, -14002], [-30288, 3416, 8952, 3481], [10848, -10986, 4954, -28192], [112012, 4326, -8556, -5242]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_648_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_648_4_a_g();".
// 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_648_4_a_g(:prec:=4)
    chi := MakeCharacter_648_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 4));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(2999) - 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_648_4_a_g();".
// 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_648_4_a_g( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_648_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<5,R![6961, -376, -222, 8, 1]>],Snew);
    return Vf;
end function;