
// Make newform 245.4.a.o in Magma, downloaded from the LMFDB on 16 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_245_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_245_4_a_o();".
// 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_245_4_a_o();".
// 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 := [28, 152, 154, 12, -23, -2, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0], [-64, -86, 8, 23, 0, -1], [-144, 60, 18, -23, 0, 1], [-164, -638, -298, 89, 26, -5], [-428, -476, 8, 49, 0, -1], [264, 800, 240, -155, -26, 9]];
    Rf_basisdens := [1, 26, 26, 26, 26, 26];
    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_245_a();"
function MakeCharacter_245_a()
    N := 245;
    order := 1;
    char_gens := [197, 101];
    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_245_a_Hecke(Kf)
    return MakeCharacter_245_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], [-3, 0, 0, 0, 0, 1], [5, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [-7, 5, -5, -1, -5, -2], [-27, -2, -4, 8, 5, 0], [-1, 16, 10, -4, 2, 1], [-52, 6, 10, -4, -3, 3], [-56, 3, -11, -9, 8, -6], [21, 39, 7, 13, -1, -8], [-68, -11, -29, 17, 0, -10], [-8, -33, -11, -9, 28, 4], [-86, -11, 7, 3, 15, -37], [-74, 0, 8, -16, -34, 2], [-81, -50, 14, -32, 9, 2], [-146, 73, 35, -19, -60, 2], [-162, -49, 33, -47, -59, 11], [-84, -132, -48, 4, 10, -24], [330, -51, 31, -35, 12, -12], [26, -116, 60, -92, 0, -14], [-414, -64, -60, -46, 85, 11], [237, 67, 25, 65, -55, 10], [-70, 32, -80, 154, 41, 69], [378, -74, 62, 80, 79, 33], [-63, -134, -72, -14, 84, 77], [-330, 26, 14, 182, -76, 108], [-267, -110, 46, -56, -157, 70], [-606, -148, -12, 152, -54, 268], [-75, -105, -93, -59, 19, 28], [-44, -139, -101, -127, 138, -52], [-318, 219, 193, -145, 26, 74], [196, -57, -79, -3, 209, -19], [724, 280, 236, 68, -128, -96], [-856, -239, -201, 183, -5, 3], [208, 228, -136, 176, 158, 124], [-215, -297, -199, 9, 187, 256], [-482, 390, 138, -222, -350, -130], [-1796, 41, 287, -51, -166, -126], [-905, 2, -342, 188, 277, -142], [191, 504, 306, 230, -297, 216], [-434, -512, 96, 188, 42, 344], [-600, -29, 169, -293, 14, -242], [1293, -555, 19, 51, 273, 234], [-416, 188, 40, 328, 200, -204], [-194, 259, 189, -365, -172, -298], [-568, 241, 487, -31, -32, -398], [237, -743, -245, 547, 95, 244], [-309, 898, 594, -128, -189, -412], [-1545, -164, -556, 436, -32, 195], [-148, 713, 571, -555, -578, -402], [-1504, 386, 190, -382, 240, -144], [2151, 81, 451, -249, -203, -200], [-2052, 749, 211, 551, -51, 355], [-428, 699, -315, -351, -277, -133], [3300, -178, -314, -40, 421, -139], [-1570, 594, -418, 174, 134, -296], [1822, 1127, -351, 219, 12, -74], [-3228, 20, 652, 136, 84, 92], [888, -745, -575, 215, 490, -10], [195, 815, 459, -567, -227, -362], [-2819, 764, -72, -292, -36, -127], [1787, -1424, -122, -62, 41, 178], [-1563, -1012, 136, 672, -26, 799], [710, -1026, -510, -2, -318, -12], [171, 350, 48, 374, 416, 27], [1054, 288, 512, 180, 234, -434], [550, 1274, 222, 494, -286, 294], [-3716, -625, -1143, 843, 224, -168], [-3320, 2417, 403, -599, 206, 86], [114, -8, 200, -560, 2, 754], [5387, -1870, -68, 190, 138, 169], [-2536, -1160, -1492, 1160, -4, 464], [73, 1016, -620, 50, -139, -560], [-1400, 352, 288, -260, -164, 1254], [4038, 420, 812, 136, -686, 718], [-2196, -938, -626, 210, -422, 390], [-1401, 707, 223, -299, -819, 1256], [-3647, 516, -338, -954, -315, 376], [-3919, 169, 1309, -965, -307, -318], [2224, -914, -1190, -448, -227, 129], [-586, 495, 1513, -595, -953, 289], [-3215, -929, -829, 729, -323, 966], [-2033, -1903, -517, -97, 621, -1240], [-1064, 1960, -296, 278, 559, -537], [-7402, 851, 285, 1227, 168, 656], [2750, -2744, -1524, -208, 362, 812], [4317, 169, 233, 539, 341, 942], [-550, 391, -475, -737, 620, -1724], [2256, 2070, 2182, -1282, -1324, -1030], [-2744, 54, 502, 1122, -676, 1820], [-381, -450, -730, -134, 26, -1675], [-998, -555, -5, -643, 662, -718], [776, 1491, -231, -1373, -352, -1354], [3027, -541, 1329, 601, -507, -16], [4015, 387, 405, 217, 1465, -716], [4025, -2468, -1036, -586, 817, -1020], [-1650, -1213, -43, 1063, 708, 1774], [1968, -2108, 396, -1966, -335, 537], [-6278, -2250, 194, -260, 451, -1673], [-10897, 781, -123, -1597, 1199, 562], [-3200, -108, 684, -520, -1912, 662], [-10404, -256, -204, 2416, 1192, 1290], [-1604, 178, -990, 1480, -477, -619], [12200, 888, -224, 556, 1362, -1040], [-2234, 2006, 910, -2062, -730, -174], [6115, -1734, 4, -254, 688, -1505], [810, -1398, -214, -36, -915, -2127], [2335, -332, -902, -1360, -690, -835], [5053, 4183, -215, -203, 1445, -586], [3420, 2264, -1536, -1138, -1033, -1089], [-2165, 3636, 1148, -2014, 939, -1564], [1378, -1964, 1780, 52, -600, 2684], [-4696, 2387, 1629, -2905, -112, -2128], [-5084, 3719, 889, -971, -1671, -1275], [5219, 2505, -1093, -365, -201, -2154], [-7468, -1858, -214, 714, 42, 2216], [-165, -3202, -1234, 674, 2346, -1451], [4508, 134, 102, 530, 42, 46], [4714, -1152, -284, 988, -768, 1884], [8595, 1821, 711, -1845, -1383, -162], [5360, 3704, 540, 4, 1078, 416], [2080, 922, -2062, -250, 1136, -656], [3605, 1920, 2918, -2054, -267, 1080], [6192, -2150, -1390, 1094, 2800, -1132], [-12438, -1382, -2658, 900, 521, 677], [3041, 2009, -555, -305, 755, -1440], [2673, -905, -2041, -883, -757, -824], [-1362, -3399, 55, 641, 302, 1298], [3154, 4262, -322, 494, -1952, 18], [7175, -4608, -594, 1802, 393, 3342], [-9795, -149, -215, 1077, -1385, 1074], [-938, 3219, -1695, -185, 1930, -770], [-819, 5043, -1195, 3165, 475, -1520], [-852, -2408, 1572, 252, 2914, 240], [9324, 3149, -1789, 179, 1027, -1663], [2100, 2090, 542, 768, 2531, 707], [277, -282, -848, 1156, 2527, -2570], [-4675, -200, 3072, -2232, -2544, -583], [5211, -1884, 1370, -958, 2903, -880], [17067, -5009, -2137, 1001, 2421, 646], [-23472, -1115, -581, 1667, 363, 931], [14593, -6091, 1641, 375, 1377, 2938], [-2190, -3047, 3231, -435, -2068, -92], [-5256, 2319, 2789, -701, -3222, -2440], [-7376, 2787, -87, -1069, 80, 604], [5542, 4821, 4907, -1451, -5162, 862], [-14618, -1824, 1060, -20, -2154, -1938], [-10640, -374, 3102, 3732, -2439, 3845], [2074, -5282, 970, -2040, -1907, -55], [-22794, 3421, 1547, 3225, 604, 4396], [-10474, -2008, -388, -1940, 3504, 1636], [-2422, -434, -834, -336, 1989, -3649], [-5100, -3774, -830, 2150, 1900, 580], [-14970, 1530, -926, -2174, -1388, -1946], [9064, -2153, -207, 4703, -654, 740], [11008, 3764, 816, -3940, -1908, -1192], [13255, -7251, -2697, -2713, -249, -42], [-5810, 1091, -4103, 2289, 593, 21], [-8981, -5634, 852, -3526, -3782, 2253], [-10692, 934, 118, 502, -5642, 696], [2290, -5809, -187, 1803, 4756, -430], [7578, 1639, 5089, -805, -2962, 672], [9342, -808, -2264, 2480, 3472, -2482], [-17450, 1087, -1967, 1493, 1857, 623], [-19166, 44, -1780, 388, -2450, -2564], [-9607, -610, 54, -6308, 883, 626], [17502, 3286, 2806, 222, -3468, 2582], [16745, -4200, -4390, 3734, -241, 182]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_245_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_245_4_a_o();".
// 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_245_4_a_o(:prec:=6)
    chi := MakeCharacter_245_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_245_4_a_o();".
// 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_245_4_a_o( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_245_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![-28, -24, 134, -28, -29, 2, 1]>,<3,R![-1486, 4644, -355, -564, 12, 16, 1]>],Snew);
    return Vf;
end function;