
// Make newform 464.4.a.g in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_464_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_464_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_464_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 := [-1, -4, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [-3, 1, 1], [-3, -1, 1]];
    Rf_basisdens := [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_464_a();"
function MakeCharacter_464_a()
    N := 464;
    order := 1;
    char_gens := [175, 117, 321];
    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_464_a_Hecke(Kf)
    return MakeCharacter_464_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], [-1, 0, 3], [1, 3, -4], [-2, -2, 12], [1, -4, 5], [19, 13, 16], [-16, 8, 10], [36, 26, 16], [-52, 10, 10], [-29, 0, 0], [41, -74, 7], [184, 34, 76], [402, 2, 42], [33, 52, 77], [261, -14, 59], [49, -53, -112], [-32, 10, -62], [120, 180, 126], [76, 124, -12], [378, 16, -82], [-396, 102, -172], [831, 14, 217], [540, 166, -350], [398, 74, -458], [406, -394, 162], [-336, -390, -68], [54, 24, -466], [-138, 202, -428], [-411, 63, 428], [-670, 212, 156], [436, -346, 156], [-1640, 118, -276], [524, 258, 472], [-20, 258, 518], [-181, 757, 328], [1586, 514, 376], [-2030, -234, 142], [-2623, -340, -663], [-1642, 516, -730], [1538, -612, 180], [-762, -152, 166], [111, 325, -1376], [-1596, -46, -272], [1310, -738, 986], [1338, 860, -592], [-26, 450, -1720], [-1595, 552, -495], [598, 700, -1334], [-2806, -232, 526], [410, -378, -522], [3479, -1153, 614], [1136, -582, 1766], [-1655, -1039, 1062], [-5621, 52, -413], [-3335, -1203, -642], [-4371, 18, 855], [-400, 1504, -878], [2511, -1230, 985], [1558, 1092, -3216], [4203, 43, -1666], [2420, -1222, -1038], [1566, -2052, 632], [2421, 2228, 1921], [-4268, 258, 640], [565, 285, -822], [-1884, -888, -514], [3017, 980, -663], [-1168, 1432, 1514], [-642, -1804, 1050], [-3691, -1369, -3424], [-1386, -556, 3876], [471, 562, -427], [2668, -1162, 2396], [-3173, 1613, 876], [2488, -238, -340], [486, -1982, -1404], [-360, -622, 3668], [4063, 1153, -1676], [-85, 759, -3758], [4574, 1008, 4892], [-5738, 336, 1246], [392, 1200, -2334], [6784, -1874, 2274], [-704, 874, 1156], [-276, 3554, 190], [-1168, 3786, -1576], [-274, 964, 424], [8830, -588, 1268], [7402, -704, 3160], [-7212, -274, 570], [-14375, -236, -347], [-1881, 2882, 57], [4914, -314, 3136], [-1853, 1444, 1823], [4804, -2886, -1942], [-11961, -2102, -5423], [12445, 1859, 1316], [5631, 1423, -3726], [-2400, -732, 5092], [17312, 1842, 556], [270, -4810, 256], [3830, 2928, -6600], [10349, -4996, 405], [-5574, 3104, -512], [-2764, 6296, -404], [-5816, -2852, 7726], [11868, 1578, -4194], [-1037, 5851, 1794], [4731, -3786, 2741], [16026, 4214, 5350], [7711, 4682, 3993], [-6247, -1633, -512], [4620, -8350, 2840], [-59, 3100, 1085], [3034, 1200, -6026], [-5472, 804, -4578], [-11142, -4550, 252], [14152, 282, 6706], [-16242, 766, -5886], [-4785, 604, -1089], [6806, -4388, 4936], [10649, 893, -3886], [2374, -6216, -980], [-5216, -1788, -2636], [-3460, 4236, -10704], [-4265, 7681, -5584], [-509, -811, -432], [-12242, -4424, -1426], [-5500, -3982, -6344], [9120, -1050, -8760], [-12757, 192, 807], [-16432, -1590, -1400], [-9212, -7142, -5796], [19392, -620, 6742], [-15894, 336, -4708], [-1980, -8076, 3714], [790, -5338, -726], [13938, 1864, 7490], [-7408, 7612, -1938], [-2832, -2714, 10312], [-9154, 11890, -6832], [-7429, -1423, -2380], [-21684, -6026, -1468], [8677, -2088, -935], [256, 1652, -9170], [24597, 3390, -4561], [718, 7212, -14880], [7985, 1217, 16466], [-14621, -5564, 5151], [-9022, 8140, -4006], [8913, 3211, -12632], [29498, 4040, -4448], [-10066, -58, -5068], [-2179, -3786, 5355], [19912, 6506, 11144], [9759, 3970, 7489], [10086, -15944, 3310], [-35086, -1164, 6368], [24894, 3496, -2696], [2517, -2409, 11220], [13685, -520, -11363], [-19201, -1973, 4250], [-47635, -1870, 1787], [7288, -10706, 13392], [17361, -2747, 4910], [-19591, 8986, 3631], [29702, 3416, -5422], [29704, 2878, 12680], [5053, -3343, 8830], [-14564, 2002, 1616], [-9738, -10918, 3816], [43821, -1241, -1156], [6802, 6792, -11878], [-18218, -4808, -11460], [30232, 6746, -11274], [-19154, -7476, 6540], [27968, 7948, -9388], [1932, -12064, 502], [-505, -7946, 8017], [-3934, -13216, 7828], [-19685, 6414, -13251], [-27035, -9172, -6675], [17738, 6076, 9712], [9773, 6017, -13226], [-11880, 6996, -21464], [-33373, -1135, -10024], [-11828, -1816, 8398], [-52944, 1794, -316], [-16280, 5824, -10950], [25574, -7106, 4756], [-22075, 7789, -6250], [-12741, -13612, 16099], [28969, 92, -12131], [49152, 5026, -8036], [48928, -4122, 2764], [-1734, -10212, -11892], [39160, -3618, 11600], [-3710, -11400, 24716], [-20431, -275, -24614], [-21796, -7948, -17240], [27330, -10874, -794], [26036, 7582, -11870], [-23138, 4614, 850], [-6802, -7334, 14694], [32320, 9958, -2484], [4043, -12935, 6544], [-2957, 2294, -24123], [-3230, -9148, 12698], [-1537, -6341, 24558], [-13965, -3648, 1963], [-20322, -5398, -26642], [-33550, -7024, 20272], [1075, 2170, 5421], [-53319, -6604, -12403], [-27476, -2638, 12480], [30417, 8053, -1962], [28272, -5788, 4492], [10444, -5298, -14732], [-6320, -9280, -8424], [52250, 252, 15652], [14208, -26372, 15830], [-26634, -7462, -9200], [-3354, 464, 10660], [9891, 18706, -18903], [-29616, -6760, 9260], [-7014, 29400, -3544], [11552, 1142, 9912], [4948, -11138, -21520], [-46115, 6738, 4459], [-18338, -16978, -12504], [-16240, 518, 17640], [22800, 10028, -12704], [-27920, 1542, 18960], [-23256, 27918, -12600], [-27386, -11440, -31226], [46772, 4482, -1492], [15016, 2932, -3426], [-13150, -11514, 9662], [2422, 15786, -6412], [23889, 8422, -1465], [-17217, 14912, -16553], [-31414, -20464, -25890], [29438, -15700, 8446], [-500, 1598, -8332], [-11454, -15160, -104], [6142, 19652, -17786], [40844, -11722, 430], [-932, -20330, 15462], [-5006, -11280, 7314], [-21329, -18270, -4035], [-3972, -13772, -6678], [21803, 8779, 2362], [47843, 13770, -23771], [-62848, -13878, -27684], [-52826, 12646, -8006], [-15780, -7008, 27604], [-42418, -5918, -14762], [263, -16552, -15253], [51342, 7932, -1708], [-32927, -8747, 522], [31436, 19286, -3144], [-42311, -19424, 31169], [-45134, 21184, -22740], [-10988, -17812, 4730], [11968, 12536, -29950], [-68691, 8948, -17567], [28720, 14082, -13484], [-20196, -18296, 40182], [-34264, -6086, -14304], [-49931, -19217, 32756], [65421, 11923, 7156], [42482, 16368, 13350], [-10659, 30673, 7978], [-3068, -2610, 13436], [-2728, -13658, 26104], [70381, 17106, -377], [-22784, 7854, -3220], [101135, 1909, 18296], [18972, 3318, -7900], [7100, -16854, 41994], [-56322, -7892, 27282], [-22430, 23692, -39966], [-2056, -25504, -1044], [-4798, 9680, -44096], [-42040, 31146, -2636], [44944, -5086, 17592], [-82788, 6176, 230], [13310, -11062, -3698], [54226, 17918, 24944], [43769, 36353, 26134], [11907, 12125, 15180], [84620, 254, -15122], [6693, -3915, -51770], [44187, -32896, 23127], [-26750, 9464, -1160], [85891, -511, 14772], [63913, 17958, -2581], [-12687, -14505, 18572], [-12422, -34434, 36820], [-29624, -21166, 27920], [34572, -37736, 22558], [-818, 12780, 36504], [-8476, 7854, 25096], [-23559, -34124, -31243], [-39704, -8918, -47088], [-83219, -19827, -7990], [-54163, 6184, -43423], [-42889, 7905, 26192], [43066, -8558, -29920], [-20589, 12377, -42544], [-30472, 49494, -11282], [-34210, -17602, 39770], [-12862, -37904, -4192], [-54860, 16390, 9922], [-8174, -3614, -4384], [48435, 7691, 29670], [38464, -6314, 9648], [50950, -10368, -13058], [-49819, 21689, -15346], [52120, 24408, -438], [-1873, -13336, -31805], [-20379, 7377, 21086], [-6986, -45048, 24536], [-34761, -33986, -683], [-25365, 6587, -40338], [31550, -6294, 16214], [59106, 8956, -23914], [10852, -33844, 24420], [-57797, 27906, -13991], [-12003, -34597, 63448], [27884, 33510, -61060], [-96733, 6121, -28484], [79836, 17856, 52692], [57960, 19862, 47212], [-77669, 10552, -17589], [25152, 7220, 66616], [-65914, 12304, -35136], [-1478, -23200, -41656], [-79566, -17092, -42860], [-51724, -23580, -16604], [-43596, -18364, 62754], [-98646, 2020, -5004], [52624, -13356, -9842], [57872, 17448, 50980], [2914, -37036, 10684], [34925, 5616, -41131], [-100416, -6132, 1798], [-31824, 3030, 42020], [-54525, -186, 7469], [102114, -19708, 33924], [128856, 5654, 27370], [-32762, 21308, -4156], [-26610, 7904, 45108], [-73492, -15930, -40590], [49784, 32816, 49978], [-58112, -33648, -22638], [16053, -38494, 30311], [87890, 25718, -61096], [-115368, -7412, 13350], [-23962, -1536, 20046], [-12745, -5555, -8336], [-6847, -22699, 60858], [21939, -30658, 5637], [45018, -12896, -16762], [62853, 9660, 37057], [-33850, 4394, -53850], [86696, -7198, 42340], [6650, -3860, -22854], [91306, -9596, 29916], [19321, 32692, -7719], [-42258, -55412, -3882], [35126, 42306, 12168], [-45322, -15196, 38320], [-752, 36090, -64302], [-141203, 6759, 2908], [-83832, -5958, -5536], [26735, -25190, 47369], [72316, -20328, -3034], [149611, -8529, 24734], [37161, 55601, -41958], [112528, 22302, 42368], [36765, 8261, -46774], [-11495, 9302, 17155], [-99152, -27520, -17350], [45130, -47150, 10952], [-14458, -12958, 31568], [-78068, 38042, 3608], [106583, -1295, -19464], [72493, 18884, -7651], [-109016, 61646, -15488], [56486, -7448, 9028], [31729, 58067, 4744], [38143, -21584, -8077], [67275, 9260, 69639], [96181, 40218, 41567], [-85375, 16221, 32270], [120836, 17964, 56608], [-8124, -22806, -28624], [-10646, 34416, -66998], [-45026, 1324, 5080], [136846, -24816, 42684], [116538, -19888, -20440], [-144864, 40866, -16704], [52165, 26209, -87886], [87827, 15397, 32000], [11856, -8710, -87362], [-19307, -28185, 22452], [-41316, -11120, 50398], [-27783, 7780, -55099], [-92844, -12768, -15600], [136046, -35224, 8280], [-3639, -8129, 32412], [122394, -22126, -34048], [-23700, -38070, 68538], [156134, 25658, 14974], [-144114, 468, -59976], [-14369, -10962, -7307], [53534, -8616, 13814], [-62700, -22726, 33016], [36919, -2914, 94057], [-58182, 18900, -2136], [81594, 14828, -10844], [51067, -61706, 4793], [50143, -27648, -32121], [1415, -10373, -34302], [124377, 9799, 75552], [114704, 22526, 40250], [-142008, 32606, -10736], [-38392, 46830, -84270], [-205941, -20798, -43763]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_464_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_464_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_464_4_a_g(:prec:=3)
    chi := MakeCharacter_464_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_464_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_464_4_a_g( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_464_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<3,R![-158, -45, 6, 1]>],Snew);
    return Vf;
end function;