
// Make newform 464.4.a.d in Magma, downloaded from the LMFDB on 23 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_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_464_4_a_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 := [-3, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [-1, 2]];
    Rf_basisdens := [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], [-5, -2], [10, 4], [16, 1], [-27, 6], [-22, 22], [16, -12], [18, 10], [-29, 0], [-10, 3], [-72, -48], [48, 2], [-120, 9], [-298, -49], [-17, -54], [-362, -70], [-306, -102], [-264, -204], [52, 166], [-436, -168], [410, 165], [114, 90], [-16, 382], [-948, 42], [-456, -216], [696, -290], [-142, 116], [-793, 54], [-242, -204], [260, -112], [-1024, 120], [752, -532], [390, 374], [1637, 318], [-366, -656], [612, -338], [-876, 557], [-368, 358], [2190, -204], [664, -978], [-2031, -474], [352, -156], [1548, 722], [2194, 456], [3966, -72], [480, -59], [4564, 194], [548, -794], [-3020, -90], [-117, -1372], [3362, -418], [-3039, 16], [-1924, 79], [-223, -208], [4442, -125], [-1406, 926], [2754, -1507], [-34, 1368], [-2385, -684], [-3350, -870], [-4010, 648], [-5128, 141], [-1360, -540], [2745, 1108], [7050, 618], [-8356, -19], [8490, -394], [-10252, -118], [587, 2226], [-9486, -28], [1926, 2385], [-10596, 496], [-4151, 282], [216, 2112], [-4886, -2260], [-5416, 112], [-2739, 1370], [-5077, -1096], [-8606, 924], [6816, -2570], [2418, -1242], [9870, 66], [-2400, -2512], [-954, 4214], [4764, -428], [-3906, 1968], [6234, 1380], [-7750, -80], [-12150, -1222], [8728, 2353], [-1110, -1523], [-8198, 2088], [-7168, 2771], [-11694, 2722], [13906, -2299], [-1825, -3770], [8447, 8], [-9284, -1628], [18336, 816], [2134, 3240], [5966, -3800], [-2620, 2921], [16754, -88], [240, -2908], [-1578, 2530], [14838, 1302], [-5701, -320], [-5286, 5889], [-2868, -2162], [-16302, 29], [3631, 2370], [13760, 3868], [11364, 3265], [-7788, 2278], [-18258, -574], [19142, -1500], [2710, 2018], [17060, 1130], [10276, -3253], [-15034, -1232], [6661, 1884], [-4094, 3140], [27188, 204], [14332, -1664], [801, 3918], [-8811, 6758], [-2752, 2798], [13448, -2820], [-7028, -8508], [6488, -3309], [-1684, 4804], [1468, 7656], [-13722, 1642], [11558, -6876], [-20322, -4266], [16116, 5730], [3232, 6034], [11318, 458], [16276, 2092], [-1218, 3568], [-10167, 1546], [3204, 296], [-11688, -2419], [174, 7970], [-3022, -3517], [-14154, -2344], [-14011, -796], [-672, -4493], [-18440, 202], [4263, 10482], [-23038, -5896], [-7326, 11100], [-29994, 855], [10516, 3700], [-13206, 7877], [-21624, -5826], [-16806, -2184], [-11034, 7384], [-6849, -13874], [21708, -4231], [19919, -3544], [654, 1471], [7844, 9812], [-22359, -1632], [5462, 8995], [11732, 5010], [-48140, 1380], [-11507, -2232], [-15304, 5620], [12406, -1424], [-27825, 4406], [-11808, -3726], [7746, -7084], [10914, -442], [17106, -3876], [-18852, -6684], [-6222, 15466], [29610, -7395], [28134, -6052], [18754, -807], [48196, 3873], [4962, -6584], [27397, 3872], [-11360, -3688], [-17787, -10298], [-24270, -6774], [15000, 6520], [-390, -8834], [-51054, 2276], [8197, 9480], [6028, -1809], [-29696, 12153], [17704, -6040], [39224, 8], [10222, -8308], [-4732, 804], [62318, -2508], [-59019, 3012], [-33492, -13392], [41316, 8958], [-5166, -3790], [-35780, 2274], [38544, 990], [1096, 4888], [-37211, 8078], [-37038, 4193], [-42984, -7606], [26275, 8996], [-1980, -15265], [3600, 4078], [64194, 2928], [58674, 977], [43776, 681], [2952, -20188], [27569, -11592], [-5796, -12460], [-71332, 1024], [19344, -13728], [61470, 1980], [-10282, -870], [-6714, 16160], [-2830, -18220], [12126, -5627], [25164, 20484], [8386, 13880], [-27756, 16188], [85592, -388], [42462, -545], [29230, -8992], [59388, -4348], [-63472, 1504], [70348, -4860], [42300, 17916], [-6384, -10826], [-30644, -2168], [56166, 2354], [-3396, -24410], [-103406, 2164], [-43730, -6029], [68644, -6165], [-28996, 9646], [-12192, 19294], [-45852, -13992], [41370, -20760], [9792, -8226], [4302, -20882], [-49754, 11750], [-99120, -1054], [-346, -5719], [50862, -19330], [-80405, -2008], [-27718, -5287], [90776, 9816], [21508, 16962], [-52024, 12052], [-15624, -4522], [-38208, 9991], [-47702, 17444], [-41515, -19788], [-25368, 9700], [17292, -24579], [71038, 11220], [-35666, -21450], [10570, 20518], [-24288, -23299], [-45128, 18536], [754, -16646], [-23812, 300], [-23281, 12638], [-31313, 14886], [-10164, 17158], [-15159, 1692], [98436, -1376], [9036, -1284], [109034, -2157], [72408, 12552], [-4455, 26718], [35164, 18096], [11018, 14850], [-13948, 11834], [82672, 16914], [-68372, 17196], [23122, -13392], [-36992, -7832], [5836, 14948], [45954, 4810], [47920, 15886], [106, -14376], [-24415, -7328], [-23519, 14090], [9814, -6650], [-90363, 4296], [-124488, 1731], [5826, -7360], [-56079, 13770], [1146, -5649], [27235, 9782], [-41250, -9204], [6812, 8364], [65538, 3482], [54686, -32432], [-18752, -42396], [44344, -10351], [4620, -14180], [10449, -2924], [-73208, -11099], [-26687, -10866], [-41518, -27656], [19869, -8162], [57338, 9070], [-33020, 7898], [-11358, 8160], [49050, -5302], [-67806, 28512], [-10833, -30692], [-86340, -22460], [-49624, 5758], [63621, -1224], [-17430, -41666], [48416, 13935], [-103547, -14184], [32158, -24872], [152398, 9849], [62303, 11428], [-26504, 35942], [16420, -34434], [-52200, 3628], [-2714, -16043], [-29549, -38014], [-127660, 14952], [97001, -10030], [35512, 4452], [86016, -15416], [86508, 24415], [40680, -44840], [-61978, 22112], [-44142, 16488], [40110, 21092], [148816, -1980], [94518, -21714], [-67194, 15972], [137374, 802], [164100, 3884], [-103098, 8220], [10764, -23471], [-62946, -34830], [-102144, 8208], [26554, -24599], [6270, 39492], [19638, 30258], [109794, 31972], [-141294, 10044], [31866, -19262], [-57790, 29958], [57642, -1818], [20898, 49635], [-111086, 13136], [-62594, -21878], [77672, -7170], [77993, -32970], [-69707, -35500], [-158302, 3665], [120228, 14262], [-41320, -38595], [-18784, 4902], [88232, -2608], [-56624, 15018], [14118, -4636], [-43892, 12941], [27352, -14154], [-159050, -14288], [148334, -6488], [-139330, -10974], [-52449, 51910], [-16612, -4052], [40178, -54419], [37890, -23158], [39319, 22076], [-97339, 5340], [25132, -35980], [-16031, 15284], [56002, 25559], [205050, 12390], [-9702, 35648], [33926, 14896], [-22432, -59028], [-67623, -17066], [-68020, -23295], [-201292, 19860], [-44206, -53228], [-65977, -44686], [-1152, -12033], [112752, 22411], [129194, 28763], [857, -37824], [-89860, 31848], [-154232, 3660], [56352, 10954], [136174, 3376], [-51846, 756], [-106446, -6168], [-138972, 19740], [-95559, 32436], [-181563, 14054], [102770, -22482], [-55201, 17166], [168506, -9646], [-140040, 3409], [-15668, 40232], [-99930, 41736], [-50901, -8346], [40514, -15544], [66146, 25914], [-12840, -52178], [77854, -9392], [22614, -42279], [-129360, -8210], [50432, -9212], [211442, -14459], [-13270, 11504], [25782, 31428], [140478, 16685], [66980, 34763], [-3713, 49248], [-16609, -1646], [254334, 14562], [-24476, -35468], [-140418, -14982], [-105174, -7599]];
    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_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_464_4_a_d(:prec:=2)
    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_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_464_4_a_d( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_464_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<3,R![-13, 0, 1]>],Snew);
    return Vf;
end function;