
// Make newform 722.4.a.k in Magma, downloaded from the LMFDB on 20 May 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_722_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_722_4_a_k();".
// 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_722_4_a_k();".
// 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 := [15, -63, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-43, 0, 1]];
    Rf_basisdens := [1, 1, 2];
    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_722_a();"
function MakeCharacter_722_a()
    N := 722;
    order := 1;
    char_gens := [363];
    v := [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_722_a_Hecke(Kf)
    return MakeCharacter_722_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 := [[2, 0, 0], [-2, 1, 0], [1, -1, 1], [9, -1, 0], [2, 1, 3], [44, -4, -1], [18, 0, 3], [0, 0, 0], [-17, 5, 1], [-35, -25, -5], [11, 23, 6], [59, 5, -6], [147, 30, -4], [8, 42, -7], [85, -19, -5], [0, 24, -5], [-358, 1, -8], [337, -29, 1], [320, -67, 16], [710, 22, 17], [-221, -14, -10], [570, -68, -29], [168, 105, 21], [262, -88, 5], [-247, -202, 42], [-75, 87, -43], [-616, 14, -98], [310, 50, -60], [-626, 48, -31], [-913, 16, 41], [-462, -38, -9], [-276, -3, 72], [1745, -44, 50], [58, 115, 62], [-193, 163, -113], [-1901, -261, 78], [1254, -40, 79], [-352, -51, -27], [46, 140, -151], [-1436, -244, -1], [148, -31, 173], [-425, 171, -155], [1900, -100, 120], [-230, 588, -7], [-827, -445, -26], [962, -126, -171], [2162, 182, -35], [-3031, 131, -115], [1002, -507, -121], [-376, -216, -186], [-2769, -6, 150], [-1604, 584, -40], [1057, -432, -116], [1078, -373, -38], [1957, 242, 198], [135, 495, -27], [2842, -100, -31], [577, 493, -51], [2153, -243, 356], [-4851, 186, -226], [638, 111, 316], [3453, -759, -192], [532, -723, -10], [1627, 47, 78], [-2951, -182, 88], [5564, -260, -17], [4332, -347, -215], [-3629, 726, -20], [-8076, 249, 40], [332, -240, -118], [6087, -1038, -273], [-4179, -81, -117], [2249, -57, 497], [-1728, -752, -170], [-5500, 386, -326], [-1645, -341, 339], [-958, -980, -245], [389, 21, 3], [-3581, -1132, 202], [-2271, 88, 128], [2536, 1268, -424], [749, 17, -523], [-9962, 98, -133], [8048, -94, 29], [6059, 749, -67], [-5234, 431, -114], [-787, 562, -687], [6759, 1094, -1], [-5056, 988, -567], [6636, -406, -350], [1302, 903, -203], [2914, 272, 147], [2865, 253, 710], [2084, -110, 489], [9928, -149, 750], [1621, -49, -655], [10314, 1680, -423], [8547, 1554, -581], [-4708, -802, -79], [5462, 516, 603], [2276, 1358, -483], [11470, 1448, -381], [10478, -1439, -257], [8044, 704, 82], [2800, -749, -749], [-599, -212, 547], [-740, -1786, 245], [5511, 2922, -554], [-4005, 2001, -297], [9301, -1548, 739], [-14735, 987, -252], [16772, -192, -415], [-1571, 2498, -1060], [-2438, -638, 984], [-13531, -1011, 579], [-5045, 2174, -16], [13750, 1735, -840], [7908, -2262, 326], [1764, 3360, 42], [14226, -1248, -503], [1073, 2915, -309], [-614, -222, 1266], [-8698, -212, 540], [8544, 540, -844], [20488, 2236, -376], [8485, 743, -599], [2961, 4169, -513], [-2126, 62, -441], [7766, -648, -1003], [-1221, -2455, -1086], [4596, 125, 1292], [-11981, -1483, 129], [-11998, 542, 779], [560, 1704, 401], [-13655, 2210, -1111], [4036, 1306, 387], [-1367, 515, -265], [-10896, 3589, -307], [26083, -955, 26], [-10567, 1936, 607], [-10092, 34, -987], [1076, -4268, -575], [-1146, -4510, 785], [-7388, -505, -150], [18104, 1160, -194], [-14043, 309, 1147], [25000, -1736, 977], [-11313, 1944, -618], [-5834, 2611, -1866], [24631, 83, -346], [-13225, 689, 1395], [-17907, 2082, -1755], [-9148, -5019, 434], [-994, -2648, 2013], [-2150, 5271, 294], [-11057, 4499, 890], [2884, 190, 850], [-10547, 2204, 490], [37395, -1426, -502], [9872, -3620, 399], [-8678, 2216, -2431], [-8197, 3070, -184], [-10822, -3882, 163], [-7338, 687, -182], [-18537, 5574, 1063], [-14562, -3912, 315], [-4426, -1012, 471], [-13137, -883, -1967], [40116, 154, -763], [-7972, -1748, 877], [8242, 3029, -937], [-31527, -803, -1055], [-19651, -1145, -677], [-6853, 6720, -231], [27557, -3181, 43], [-20115, 2814, 228], [6184, -5417, 1732], [174, 1176, 315], [-11808, -2828, -484], [-305, -2009, -1781], [-19622, 2170, -2835], [11346, -462, 176], [-19698, -1256, -2347], [-143, 98, 1606], [-7748, -5380, -208], [-11365, 1531, 400], [6914, -4204, 2669], [27796, -1122, 2791], [-1185, 2764, -227], [8040, -1062, 1602], [20439, 4642, -652], [18842, 1858, 1857], [17848, 951, 655], [-18178, 1696, 289], [-23590, -2615, 1220], [5636, -6326, -2063], [16873, -3842, 304], [1813, 4987, 1241], [11747, -164, 2133], [12657, 2769, 138], [-17956, 5956, -101], [-35010, 2272, -2203], [8340, -368, 2399], [-17207, -2130, -2214], [-9220, -1241, 2826], [2421, -4083, 1895], [33623, 237, 3381], [-69262, 1, 430], [-70675, -3278, 736], [-8482, -4927, 2579], [43323, 3608, -40], [4583, 4327, 735], [-10440, -2308, 2568], [-31748, 1841, -1432], [-26240, 4250, 2522], [3276, 2452, 2943], [29742, -2674, 1995], [-16862, 938, -2374], [-33963, -4335, 1478], [-36225, -3321, 1083], [19925, -1867, 1777], [48340, 5994, -786], [8611, 6818, -3444], [16430, 7008, -1971], [-9916, -665, 368], [6980, 2352, 553], [12777, 1170, -1859], [-46394, 8048, 1415], [-24423, 3313, -1481], [10864, -4060, -1624], [-6959, -7637, 581], [-4096, 3305, 3632], [-37787, -1851, 1202], [10105, 8654, 1441], [-17398, 9165, 1539], [8018, 2506, -437], [32117, -3552, 3547], [26554, 2624, -248], [22290, 915, -1000], [-36525, 5217, -5157], [53292, 435, 2432], [-2306, 6085, -813], [52454, -3084, -961], [18937, -5259, 2073], [50124, -2646, -2559], [39195, -2817, -1830], [47781, -2263, 4555], [-20084, -8059, 2028], [31030, 5613, -3384], [1802, 5644, -3557], [41775, -5485, -2336], [-4234, 8164, -2721], [3091, -11737, 2050], [44489, -6076, 3356], [11579, -7649, -2637], [22636, -10294, -117], [616, 2524, -1843], [278, -2689, -2803], [-16968, -3852, 963], [28034, -3912, 1511], [76054, -714, -1589], [-15190, 235, -2354], [-68669, -1055, 1829], [7815, -4043, -5385], [5335, 632, 44], [18446, -4045, 2433], [-48644, 2768, 2186], [-53111, 1178, -5539], [14560, -318, -2235], [-40244, 644, -6307], [-24473, -3963, 3734], [-16300, -16, -552], [20087, -6072, -4436], [-24175, -15045, 4740], [32356, 5316, -2325], [34123, 337, 959], [-55436, 8465, 125], [64837, -4269, -305], [14529, -10340, -136], [-9706, 3808, -1025], [-18187, -707, 1534], [24119, 6519, -22], [-98086, -6656, 2275], [54022, -3264, 1352], [62718, -2530, -1889], [-90750, 4188, -3165], [31249, 9742, -979], [-41038, 2536, 1525], [-19062, -5536, -4523], [67620, 2184, -1022], [70706, -5660, -2000], [-73616, -7348, 2156], [-10357, -3008, -4586], [-68978, 350, 3696], [51735, 6169, -4985], [774, 13824, -1444], [64638, -1958, 2383], [128385, -3405, -1399], [-26502, 54, 4169], [31602, -11611, 1287], [45811, -9884, 2748], [-25067, -8887, 3285], [-78971, -7895, 3867], [82548, 849, 3877], [-76190, 7261, -4222], [-49985, -318, 1944], [-18640, 6343, 4714], [-95278, 5888, 1133], [110003, -5849, -2105], [-87592, -10140, 618], [38440, 17246, -5718], [21299, -8705, 5707], [-5993, -7624, -6170], [-31176, 10213, 357], [-20930, -7318, -2641], [55490, -3118, 3442], [66826, 539, -2902], [21227, 7309, 2649], [48887, -10632, -6252], [42868, -3472, 8022], [40836, 16297, 434], [-61783, -4998, -896], [-28159, -4187, -1883], [11081, 3245, 3617], [-65308, 11842, -2225], [64650, 988, 273], [51114, -3371, -3274], [68242, 4371, 373], [66405, -909, -3007], [-83720, 1508, 205], [-66487, 14049, -3829], [-25062, -4044, 3009], [-13430, -12068, 2545], [-11968, 652, 752], [-11888, -16013, 2816], [35438, 3784, 1815], [-64263, 4741, -7848], [-69797, 11186, -3829], [-25508, 10696, -4802], [3452, 4638, 1202], [17999, -4147, 9231], [47135, -11936, -2264], [23393, 14113, 1105], [-90972, -3704, -3356], [-51227, 8021, -1179], [-41910, 13797, -5572], [87838, -5912, 6635], [-40874, 14916, 2573], [-62749, -4199, -1807], [20753, -13385, 6934], [74030, -4927, -3486], [-84341, 17364, 2490], [56477, 1813, -1365], [-10688, 14214, -5434], [-21425, -14451, -3453], [-59931, 3330, -3583], [3206, -26168, 2769], [98544, 6819, 882], [17131, -3706, 4758], [22217, 16723, -1505], [-81623, 1909, 183], [46673, 6538, -2748], [-50546, -4396, -8995], [-54196, -5741, 5723], [-6288, -23218, 2177], [-30478, -2524, -6487], [-15100, 16516, 1402], [82663, 4917, 485], [-20119, -1198, 8250], [39478, -2251, -5332], [71624, -19516, 448], [73458, -20016, -6631], [36540, -14976, -2809], [58181, 291, -8685], [39365, -13347, -8184], [-50662, -21140, 7787], [17972, -12392, -1980], [1151, 15690, 642], [69605, 10696, -4106], [26889, 4336, 2400], [13183, -11773, -11428], [83566, -3934, 994], [-44013, -20467, 577], [16941, 5880, -3570], [3156, 1459, 1563], [-15377, 12659, -2157], [-114699, -19525, 5608], [-109364, -8312, 4377], [92180, 1539, 7508], [28660, -16414, 7738], [-11311, -1876, -4564], [20824, 27980, 27], [112694, -8675, 1051], [96452, -2589, -5356], [55691, -6713, -5075], [75141, 10480, 7444], [-99198, -2984, -3145], [162105, 6534, -551], [-52648, -3871, -11886], [83464, 8324, -67], [53176, 10812, -6837], [45237, -6516, 11182], [-105685, -703, -1220], [-5048, 14684, -149], [-77646, 1716, -10059], [-39977, 19549, 1915], [13330, 24736, -1245], [-1123, -4514, -2923], [-27482, -4902, 8887], [-147234, -13431, 1259], [-144341, -5280, 838], [62338, -10156, -8929], [2950, -9907, 13903], [-116288, -21743, 6325], [61535, 2484, -10531], [22575, -27111, -2730], [91738, -8776, 4577], [98072, 6140, -2356], [-145930, 10036, -6029], [-83269, 28003, 6417], [-34475, 8249, 8717], [-61522, -23980, -1279], [90568, -2386, 14542], [48816, 19839, -1582], [58112, 14132, -5190], [161669, -5363, 9952], [-122432, 1805, 6213], [85726, -25516, -6765], [24488, -12708, -24], [-76978, -974, -9981]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_722_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_722_4_a_k();".
// 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_722_4_a_k(:prec:=3)
    chi := MakeCharacter_722_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_722_4_a_k();".
// 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_722_4_a_k( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_722_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<3,R![-107, -55, 5, 1]>,<5,R![1938, -356, -1, 1]>],Snew);
    return Vf;
end function;