
// Make newform 129.4.a.f in Magma, downloaded from the LMFDB on 05 May 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_129_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_129_4_a_f();".
// 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_129_4_a_f();".
// 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 := [6912, 864, -6880, -514, 1106, 43, -59, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0], [-15, 0, 1, 0, 0, 0, 0, 0], [-144, 74, 92, -27, -4, 1, 0, 0], [3648, -776, -138, 526, -81, -47, 3, 1], [-4032, 5144, 2302, -1834, -253, 141, 7, -3], [-768, 5608, -790, -1150, 113, 63, -3, -1], [16704, -4744, -7594, 782, 607, -47, -13, 1]];
    Rf_basisdens := [1, 1, 1, 24, 384, 384, 192, 384];
    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_129_a();"
function MakeCharacter_129_a()
    N := 129;
    order := 1;
    char_gens := [44, 46];
    v := [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_129_a_Hecke(Kf)
    return MakeCharacter_129_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, 1, 0, 0, 0, 0, 0, 0], [3, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, -1, 0, 0], [6, -2, -1, -1, 0, 0, 1, 0], [8, 5, -2, 0, 2, 0, 0, -1], [12, 1, -1, 3, 0, 1, 1, 1], [-6, -5, -4, -6, 0, -1, 0, -1], [8, -12, 1, 1, -6, 4, -3, 4], [24, -15, -2, 0, 0, -5, 0, -5], [24, -6, 8, -2, -4, 9, -8, 4], [72, -21, 8, 0, 4, -1, 0, 5], [68, 0, -10, 0, 6, 12, 0, 0], [-24, -7, -4, -2, 2, -1, 10, -5], [43, 0, 0, 0, 0, 0, 0, 0], [-112, 22, 4, 4, -2, -5, -14, -8], [-60, -17, 20, 2, -14, 17, 2, 9], [-154, 4, 28, 8, -6, -4, -4, 12], [206, 42, 16, 0, 0, 24, 0, -6], [10, 51, 22, 0, -10, 7, 0, 25], [110, -36, 28, 12, 26, -26, 6, -22], [104, 60, -10, 12, -6, 6, 12, -12], [294, -46, 32, -18, -34, -18, -22, -18], [4, 1, -38, 26, 38, -16, 20, -11], [12, -168, 34, 14, -38, -6, -22, 8], [266, 87, 3, -41, 6, -11, -9, 1], [266, -19, 72, 50, -24, 19, -64, 29], [22, 103, -90, -56, 22, -53, 28, -23], [-206, 36, -80, -14, -48, 47, -8, -10], [188, 125, 7, 5, -8, 33, -43, 39], [-50, 88, -36, 32, -46, -5, 2, -42], [378, 31, 8, 14, -66, 51, -14, 33], [330, 82, 52, -28, -86, 22, -70, -28], [-138, -46, -88, -76, 10, -57, 26, -36], [420, -29, 120, 52, -36, 11, -20, 29], [104, 106, -82, -54, 38, -32, 54, -78], [336, -2, -80, -32, -60, 110, 16, -34], [-92, -190, 38, -64, 78, -62, -16, -50], [224, 10, 37, 43, 26, 42, -23, 72], [58, 147, -94, 30, -8, 86, 90, 25], [-1650, 200, -252, -24, 24, 36, 36, -36], [-848, -142, 2, 10, 24, -100, -98, -90], [-290, -66, 111, 181, 50, -76, -81, -52], [452, -116, 242, 122, -60, 48, -70, -32], [-2572, 171, 54, -60, -162, 105, 0, 45], [-690, -332, 98, 154, 8, -42, -50, 64], [1040, -118, -16, 28, 184, -22, 104, 2], [-120, 452, 89, 51, 74, -36, -91, -6], [-50, 402, 201, 91, -184, 140, -117, 158], [-1136, 92, -146, 98, 188, -40, 98, 160], [-1284, -339, 110, 72, -38, -61, -84, 131], [-1658, -310, 184, 14, -46, -125, 98, 34], [1260, -178, -216, -86, 170, 39, 94, -34], [-1200, -96, -368, -126, -50, 146, -18, 44], [1260, -249, 258, -142, -62, -192, 32, -5], [186, 270, -120, -30, 30, 105, -6, -66], [474, 348, 178, -54, 102, -74, -48, -206], [-1892, -417, -90, 12, -182, 107, -108, 89], [660, 103, -306, 94, -84, -49, 106, 53], [-782, 644, -258, -230, 84, 126, 254, -24], [-202, -163, -394, -204, 176, -59, 114, -267], [64, -563, -10, -94, 76, -7, -62, 59], [-1244, -274, 258, -14, -42, -24, 160, 124], [1498, 763, 200, 182, -14, -109, -2, -55], [2970, 107, -318, 34, 212, -84, 142, -247], [-968, -376, 194, 68, 198, -206, -76, -20], [-520, -387, 330, -76, 30, -75, -184, -145], [320, -526, -13, -161, -134, -178, -121, 62], [-1298, 669, -107, -255, 86, 43, 117, -137], [82, 672, -4, 60, 46, 194, 438, 178], [-2886, -998, 34, -242, 0, -82, -2, 110], [-5188, -395, -58, -80, 262, 37, 112, -61], [112, 409, -374, -252, -296, 23, 96, 63], [2080, -708, 54, -254, -412, 8, -210, -16], [-666, 846, -400, -48, -32, 374, 360, 2], [4788, -505, 72, -132, -40, 141, -232, 117], [192, 1816, -38, -290, -28, -102, 154, -120], [572, -812, -528, -222, -76, 277, -72, -170], [2474, 50, 159, -229, -242, -492, -145, 90], [-224, 1289, 136, 402, 382, -163, 198, -93], [236, -562, 204, 486, 142, -38, 62, -14], [3382, -524, 98, 486, 238, -264, -180, 94], [3826, 264, -498, 82, 464, -172, -42, -76], [2998, 1283, -690, -572, -132, 66, 118, 7], [1364, -2042, -164, 94, 74, 144, 130, 126], [-2890, -1097, 816, 694, -370, 177, -170, 261], [1610, -736, 476, -232, -156, 401, 284, 184], [-1062, 1232, 324, 118, 230, -153, -2, 92], [-5100, 780, -922, -96, 46, -184, 384, -328], [848, -758, 364, 148, -98, 252, -110, 184], [650, -286, -467, -193, -56, 144, -277, -378], [3364, -938, -156, 184, 420, -472, 4, -362], [-50, -199, -366, -36, -140, 64, 306, 533], [944, 748, 590, -154, -280, 274, -14, 640], [4306, -546, 246, 362, -562, 200, -508, 264], [1640, -736, 337, 377, 178, 384, 101, -144], [3208, -634, -634, -218, 708, -532, 106, -150], [34, 1239, -190, -152, -132, -19, 238, -429], [1450, -372, 1160, 366, -470, 47, 90, 304], [280, -1532, 405, -431, -62, -344, 169, -512], [1092, 489, -914, -44, 226, -285, 48, -273], [-6472, 1423, -240, 724, 20, 969, -20, 201], [-2618, -409, -1258, -208, 464, 221, 278, -205], [-5608, 1311, 170, 532, 196, 1125, -44, 77], [-5902, 121, -1134, -352, -84, 65, 146, 557], [1484, 606, 1195, 485, -150, 86, -93, 332], [816, -182, -470, -376, 462, 90, 124, -246], [-12240, 14, -446, 98, 352, -676, -46, -34], [1624, -1000, 1102, -110, -186, -30, 502, 200], [9646, -981, -122, -30, 100, -78, 450, 69], [1916, 588, 1402, 420, -582, -12, -432, 552], [-10062, 868, 985, 823, 252, -562, -41, -148], [1454, 2876, -108, -240, 328, 148, 104, 364], [2028, -961, -584, -222, -66, -483, -522, -179], [-736, -376, 754, -70, 112, 24, 542, 36], [6312, 2290, -712, 68, -84, 546, 424, -258], [6828, 512, 278, 330, -582, -350, -18, -184], [-10478, -1682, 288, -62, 190, -134, 358, -278], [4252, -804, -156, 488, -448, 682, -280, 876], [7028, -1984, 984, -342, -148, -131, -96, 538], [2012, 1279, -222, -608, 736, -483, 244, -447], [7560, -407, -643, -413, -744, 833, -281, 623], [-2238, -2270, 1432, 1300, -564, 320, -464, 890], [676, -952, 382, 282, -398, 514, -210, -12], [-48, 2517, -806, 560, 244, -105, -148, -493], [-7388, -1698, 628, 384, -364, 298, -876, 730], [-2518, 2872, -142, -554, 232, -440, 346, -580], [-9136, -263, 1135, -289, 68, 61, 325, 121], [9758, 680, 368, -300, -130, -236, 300, -444], [2442, 1324, 83, 559, 984, -274, 73, -154], [10974, 1062, -202, 618, 1048, -142, -606, -466], [2664, 864, -1805, -255, 898, -304, 231, -490], [4416, 1344, -1356, -756, -744, -58, 228, 12], [-1286, 620, -451, -73, 912, -26, -157, -284], [1890, -778, -254, -550, -220, -940, -70, 170], [3760, -102, 738, 818, 614, -316, 182, 438], [4004, -204, -141, -983, 336, 172, 693, 76], [4664, 2884, -252, -534, 416, 7, 540, -218], [-8550, 554, 1118, -144, -1138, 240, -988, 510], [-916, -1662, 618, 1354, 274, 238, -332, 996], [11030, 480, -1210, -262, -1236, 550, -178, -68], [-6560, -608, -1140, -776, 616, -860, 1528, -572], [-18438, -3989, 750, -1344, -300, -183, -174, -453], [11162, 401, 1142, 768, -1154, -5, -580, 295], [1082, 628, 480, 1292, -72, 923, -676, 536], [8760, -640, 1164, 2094, -418, -834, -1186, 204], [876, 1266, -1164, 692, -632, -220, -484, -314], [-8588, 1493, 201, 625, 108, -315, 515, 729], [2876, -1062, 636, 888, 590, -288, 90, -380], [-12928, 3266, -725, -547, -326, 66, 143, 528], [4152, 1630, 404, 136, 20, 316, -1448, -278], [-304, -2571, -162, -200, -114, -1433, -348, -437], [-6684, -531, 50, -28, 574, 873, -28, 123], [1512, -1245, -816, 480, 1000, -649, 528, 389], [5082, -5232, -54, -78, 270, -618, 744, -690], [-4932, -3029, 1014, 550, 1080, 311, 22, -403], [12056, 3268, 88, 604, -176, -398, 232, 1228], [826, -3659, -1866, -764, 394, -1367, 76, -545], [-1270, 2762, 1208, -188, -62, 67, -578, 20], [-1830, -1380, -2070, -1246, 64, -824, 570, -1040], [-8506, 283, -14, 392, -756, -677, -406, -333], [-2336, -5731, 582, 666, -194, 242, 288, -883], [7554, -1836, 756, 392, -206, -1185, 134, 274], [-13194, -305, -962, 532, 918, -313, 844, -547], [-3376, 3421, 3090, 1276, -812, 267, -1040, 1035], [3352, 3398, -1892, -652, -154, 1082, 302, -8], [3574, -1140, -1696, -1032, 910, 176, 834, -254], [26510, 700, -65, 605, 560, 166, 865, 28], [17434, -2896, 564, -680, -828, 744, -1288, 288]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_129_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_129_4_a_f();".
// 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_129_4_a_f(:prec:=8)
    chi := MakeCharacter_129_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(997) - 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_129_4_a_f();".
// 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_129_4_a_f( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_129_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![6912, 864, -6880, -514, 1106, 43, -59, -1, 1]>],Snew);
    return Vf;
end function;