
// Make newform 115.4.a.d in Magma, downloaded from the LMFDB on 01 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_115_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_115_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_115_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 := [60, 260, -9, -34, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0], [0, 1, 0, 0, 0], [78, -237, -30, 14, 1], [50, -19, 14, 2, -1], [-158, -35, 30, 2, -1]];
    Rf_basisdens := [1, 1, 64, 16, 16];
    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_115_a();"
function MakeCharacter_115_a()
    N := 115;
    order := 1;
    char_gens := [47, 51];
    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_115_a_Hecke( : Kf := Kf)
    return MakeCharacter_115_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]];
    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 := [[-1, 1, 0, 0, 0], [-1, 0, -1, -1, -1], [-5, 0, 0, 0, 0], [-2, -2, 3, 3, -1], [-32, -3, 1, 5, 6], [5, -1, -7, 5, 4], [-68, 3, 9, -3, -2], [-4, 12, -1, -5, 9], [23, 0, 0, 0, 0], [-119, 35, -22, -6, 3], [129, -31, 35, -1, 8], [-24, -50, 28, 52, 0], [79, 10, 1, -39, -45], [-54, 76, -64, -28, 6], [-53, -87, 54, 82, 5], [-166, 0, -24, -16, -64], [-252, 42, -26, 18, 56], [116, 9, -51, 29, -26], [-184, -14, 32, -108, -80], [-11, -14, -67, -31, 5], [-61, -99, 110, 18, 47], [12, 126, -20, -52, -100], [-24, -50, 28, -108, -30], [-42, 64, 64, -180, -30], [-358, -19, -61, 7, 16], [-66, 114, 62, 114, 96], [-48, -277, 37, 193, -30], [-424, 138, -50, -126, 22], [-266, 96, -25, -121, -87], [-1126, -90, -96, -176, 28], [-23, -127, 66, -174, -171], [405, 3, -300, 40, 271], [-588, -172, -31, -67, 161], [103, 425, 78, 202, 275], [-758, -390, 349, 329, 107], [1025, 326, 57, 201, 209], [-658, 0, -158, 354, 24], [1101, 31, 97, 73, -282], [2164, 88, -236, -120, -40], [-1850, -43, -349, -337, -350], [811, -193, -126, 162, -299], [-808, 226, -469, -261, 111], [-1486, -728, 330, 578, 298], [879, 489, -122, -258, -301], [191, 368, 273, -43, -393], [1380, 416, 184, 128, -282], [264, 238, -36, -772, 34], [-1644, 1028, 12, -152, 396], [402, 316, -686, -674, -436], [-410, 974, -424, -716, -60], [-175, 135, -46, 358, 137], [-423, 913, 160, 148, 81], [662, -10, 200, 136, 630], [84, -142, -431, -419, -509], [-1035, 555, 418, -390, 189], [-476, -945, -529, 135, 678], [-411, -881, 790, 790, 195], [-172, -656, -109, 919, 459], [-1029, 213, 640, -484, 293], [-3334, -500, -78, 342, 112], [-2310, 1148, 40, 16, -416], [848, -406, 0, 352, 542], [152, 861, -899, -67, -188], [-3887, -243, 636, 156, -79], [-532, -1432, 1155, 807, 459], [-966, -552, 1173, 433, 257], [731, -635, -446, 270, -1109], [-2594, -152, -455, -91, 287], [1696, 523, -725, 51, -440], [-1035, -999, 544, -400, -717], [-2577, -1885, 904, 1212, 75], [-892, -428, -196, 108, 538], [-2580, 792, 92, -596, 580], [-3874, 988, -718, -798, -286], [1664, -507, 1203, 631, -366], [1778, -608, 1240, -524, -250], [-752, -1383, -597, -521, 318], [85, 482, 441, 1389, 2073], [74, 2592, -406, 530, 750], [-6019, 485, -557, 279, -318], [-5474, 16, 420, -372, -54], [2886, 32, 43, 35, -867], [-270, -2004, -26, -442, -820], [-4638, 1710, 1, -1587, 259], [5403, 1347, 47, 267, 970], [4847, 793, -941, -409, -1038], [-1446, 16, -1159, 321, -655], [-2480, -1002, 1840, 704, 110], [-3499, 105, 1222, 1274, -111], [-224, -50, 228, -1336, 1294], [-2586, 424, -1042, -482, 338], [-3156, -2858, 612, -652, 710], [-2699, -1147, -766, -902, -1195], [51, 2283, -662, 134, -639], [233, -2039, 688, 1656, 1325], [2158, 1180, -141, 1175, 155], [681, -2901, -418, -834, -2029], [5796, 1022, -108, 700, 494], [-2574, -582, -1300, -696, -2744], [12421, -689, 164, -1500, -835], [1921, -693, -205, 363, 1056], [-4958, 2644, 632, -440, 1818], [4232, 3900, -3184, -2264, -688], [4650, -1148, 2916, 1596, 252], [-4296, -1817, 1737, 1541, 598], [4659, 2497, -2268, -3160, -1379], [6387, 1332, -601, -2161, -73], [782, -1180, 362, 934, -594], [3772, 2091, -829, -1581, -960], [6345, -851, 187, 2595, 710], [7876, -2076, 1704, 412, -980], [-4540, 874, -660, 1540, 606], [-6220, -543, -191, 2029, 1814], [612, -1422, -1191, 1973, 367], [-3834, -4078, -422, -518, 1394], [4562, -3872, -408, -76, 1014], [-6534, 142, 2310, -410, 2272], [-4017, -1245, 1540, -864, -3139], [3661, -1629, 1777, 1433, 752], [-964, -5012, 1004, -204, -1392], [-770, 585, -2523, -1263, -2184], [7273, -1093, 208, 12, 1955], [-6886, -3608, 1944, 2720, -1368], [6813, -6761, 1993, 93, -414], [-10528, 428, 74, 1490, 418], [-1130, 1884, 465, 121, 655], [-14, -2935, -161, 175, 1192], [-2732, -48, 293, 1953, -3211], [650, -403, -767, -1299, -4104], [-4596, 462, -1176, 3992, -2522], [4631, -521, 2248, -920, 855], [-11304, -3310, -785, -3653, -2379], [2694, 6190, -4154, -4282, 606], [12080, -3002, 2596, -1508, 516], [-13759, 5445, -1017, -817, 2274], [9342, 6704, -2724, -2372, 432], [9162, -4296, -532, 2276, -814], [-80, 1242, 3202, 1282, 3316], [-256, 2152, 2630, 998, -344], [-3522, 3685, -4425, -5177, -694], [7449, 201, -6414, -946, 647], [-6786, 3252, -3844, -968, -3908], [-113, 919, -1912, -4740, -2543], [9028, 2098, 2054, 5790, 2968], [31130, -1132, 1904, 2476, 1076], [-6326, -7948, 3874, 3434, -2308], [13022, -2180, 2267, 559, -2869], [-1259, -4301, 2832, 4636, 2927], [1117, 2601, 2902, 1538, -2113], [-7647, -3815, 2298, -786, -4979], [-1558, 2551, -2351, -603, 778], [12304, -368, 1612, -5076, -1940], [-8776, -8616, 4811, 4619, 2123], [12763, -2935, -2836, -972, -829], [-8008, 234, -18, 4146, 5902], [-17784, 4414, -4546, -3298, -1982], [18130, -2364, -2532, -1036, 134], [-89, -1033, 3776, 1212, 3585], [8716, 3702, 1037, -2031, 1193], [14504, 3507, 549, 3017, 4642], [10583, -11, 795, 1351, 854], [-14270, 991, 4519, -1733, -2800], [-1295, -5039, 990, -786, 2869], [-13874, 2943, 491, -1873, -488], [-4328, -826, 391, -637, 39], [-11978, -2571, 461, 6793, 6144], [-2720, -6457, 3379, -1881, 2008], [-18614, -408, -4828, 428, 640]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_115_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_115_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_115_4_a_d(:prec:=5)
    chi := MakeCharacter_115_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_115_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_115_4_a_d( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_115_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![278, 145, -101, -24, 5, 1]>],Snew);
    return Vf;
end function;