
// Make newform 1872.4.a.bo in Magma, downloaded from the LMFDB on 10 May 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1872_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_1872_4_a_bo();".
// 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_1872_4_a_bo();".
// 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 := [81, -9, -40, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [9, 98, 2, -2], [18, 62, 2, -2], [-171, 22, 10, -1]];
    Rf_basisdens := [1, 9, 9, 9];
    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_1872_a();"
function MakeCharacter_1872_a()
    N := 1872;
    order := 1;
    char_gens := [703, 469, 209, 145];
    v := [1, 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_1872_a_Hecke(Kf)
    return MakeCharacter_1872_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, 0], [0, 0, 0, 0], [0, 0, 0, 1], [-9, -1, 0, 0], [0, 0, -1, -1], [-13, 0, 0, 0], [0, 0, -4, 0], [-21, 7, 0, 0], [0, 0, 16, -2], [0, 0, -10, -10], [151, -1, 0, 0], [46, 16, 0, 0], [0, 0, 2, -9], [-220, -4, 0, 0], [0, 0, -27, -5], [0, 0, -26, -8], [0, 0, -23, -15], [164, 22, 0, 0], [-763, 17, 0, 0], [0, 0, 49, -29], [-78, -68, 0, 0], [180, -56, 0, 0], [0, 0, -1, -5], [0, 0, 102, -7], [-86, -52, 0, 0], [0, 0, -46, -54], [-848, 44, 0, 0], [0, 0, 36, 86], [846, -44, 0, 0], [0, 0, 108, 70], [-1110, 46, 0, 0], [0, 0, -88, 86], [0, 0, -98, -25], [86, 94, 0, 0], [0, 0, 168, -13], [-675, 45, 0, 0], [728, 42, 0, 0], [-811, -55, 0, 0], [0, 0, 109, 23], [0, 0, -18, 38], [0, 0, -6, 104], [-2572, 90, 0, 0], [0, 0, 86, -108], [-1902, -176, 0, 0], [0, 0, -212, 109], [794, -146, 0, 0], [-804, 156, 0, 0], [1063, 135, 0, 0], [0, 0, 465, 149], [-818, -100, 0, 0], [0, 0, 572, 26], [0, 0, 1, -17], [-414, 100, 0, 0], [0, 0, -126, 150], [0, 0, 92, -258], [0, 0, 426, -18], [0, 0, 30, 114], [215, 151, 0, 0], [-2462, 0, 0, 0], [0, 0, 54, -317], [-4086, 66, 0, 0], [0, 0, 456, -257], [3011, -233, 0, 0], [0, 0, -432, -122], [-7518, -168, 0, 0], [0, 0, -624, 117], [-8703, -83, 0, 0], [3118, -416, 0, 0], [0, 0, -484, 48], [-3686, -412, 0, 0], [0, 0, 1042, 43], [0, 0, -651, -201], [-3270, -474, 0, 0], [2206, 240, 0, 0], [2267, 279, 0, 0], [0, 0, 535, -83], [0, 0, -562, 296], [-6550, -60, 0, 0], [0, 0, -354, -47], [3966, 552, 0, 0], [0, 0, 608, -482], [-4678, -104, 0, 0], [0, 0, -89, 605], [5888, -58, 0, 0], [-4140, -624, 0, 0], [0, 0, -692, 226], [0, 0, -1242, -119], [-350, -116, 0, 0], [0, 0, -1012, 309], [-4121, 951, 0, 0], [0, 0, -322, 590], [0, 0, 1195, 17], [627, 283, 0, 0], [0, 0, 718, -462], [-6831, 541, 0, 0], [0, 0, -706, 730], [0, 0, -1304, -483], [0, 0, -1024, 718], [9766, -842, 0, 0], [-8990, 456, 0, 0], [-10086, -790, 0, 0], [0, 0, -528, 1231], [0, 0, -814, -352], [0, 0, 1384, -758], [5318, 126, 0, 0], [7874, 240, 0, 0], [0, 0, 663, -633], [0, 0, 1506, 117], [0, 0, -510, 1130], [-13742, 856, 0, 0], [4198, 522, 0, 0], [-10038, -836, 0, 0], [0, 0, -422, -445], [11411, -457, 0, 0], [21477, -251, 0, 0], [0, 0, 332, 364], [-14651, 329, 0, 0], [0, 0, 384, -836], [0, 0, -1094, 590], [0, 0, 60, 1580], [330, 12, 0, 0], [4260, 506, 0, 0], [0, 0, 1346, -504], [0, 0, -821, -821], [-4843, 1321, 0, 0], [0, 0, 1186, 964], [-342, -440, 0, 0], [0, 0, -1996, -514], [-10010, -1694, 0, 0], [18598, 604, 0, 0], [-2897, 659, 0, 0], [0, 0, 1489, 271], [-9748, 96, 0, 0], [-10596, -750, 0, 0], [0, 0, -1902, -1077], [6594, 672, 0, 0], [0, 0, -820, -597], [379, -1241, 0, 0], [0, 0, 150, 488], [0, 0, -192, -782], [24343, -589, 0, 0], [0, 0, -148, -1029], [-1796, 144, 0, 0], [0, 0, 1847, -1597], [7992, -2026, 0, 0], [0, 0, 1451, -1887], [1510, 2552, 0, 0], [0, 0, -3952, -314], [-5832, 800, 0, 0], [0, 0, -1661, 1101], [34778, 532, 0, 0], [0, 0, 500, 514], [-28770, -290, 0, 0], [0, 0, -2014, 560], [-28018, 222, 0, 0], [0, 0, 2398, 1348], [-10396, 776, 0, 0], [0, 0, 1102, 399], [14540, -646, 0, 0], [0, 0, -1036, 2535], [0, 0, 1565, 917], [0, 0, -2720, -390], [8687, -1313, 0, 0], [0, 0, 1384, 864], [0, 0, -1454, 1793], [0, 0, -2729, -595], [27134, 490, 0, 0], [19254, 104, 0, 0], [41578, -804, 0, 0], [0, 0, 3094, 918], [0, 0, -2131, 1361], [27918, -760, 0, 0], [0, 0, 4032, 1174], [44850, 716, 0, 0], [26608, 2420, 0, 0], [0, 0, 2176, 1868], [-29425, 963, 0, 0], [0, 0, -4108, -273], [24832, 876, 0, 0], [1614, 440, 0, 0], [28051, 139, 0, 0], [0, 0, -838, 1752], [-13980, 2890, 0, 0], [0, 0, 2494, 385], [0, 0, -787, 1575], [0, 0, -2498, 260], [2820, 1762, 0, 0], [-39977, -21, 0, 0], [3526, 1520, 0, 0], [0, 0, -2311, -2465], [-44216, 946, 0, 0], [0, 0, -4629, -345], [-35110, -574, 0, 0], [0, 0, 3812, 723], [0, 0, 3734, 1988], [0, 0, 3308, -1842], [-40366, -976, 0, 0], [1818, -1280, 0, 0], [0, 0, -1662, -91], [0, 0, 578, 100], [0, 0, -1916, 2741], [-322, -3822, 0, 0], [-19442, -1716, 0, 0], [-19392, 186, 0, 0], [0, 0, -2075, 2537], [0, 0, 870, -3292], [21735, 1575, 0, 0], [0, 0, -4788, 978], [0, 0, -1050, 1157], [-866, -1810, 0, 0], [18912, 1814, 0, 0], [0, 0, -5382, -748], [28568, 1332, 0, 0], [0, 0, -3245, 2623], [0, 0, 551, 1689], [-50066, 228, 0, 0], [-29412, -784, 0, 0], [0, 0, -5572, -2392], [0, 0, 6209, -801], [0, 0, -7172, -209], [-6950, -664, 0, 0], [46675, -285, 0, 0], [0, 0, 7390, 1505], [-41597, -2237, 0, 0], [0, 0, 8630, 1622], [72158, -1632, 0, 0], [0, 0, 1216, 244], [0, 0, -1874, -3218], [-61158, 3134, 0, 0], [0, 0, 2473, 525], [-83364, 586, 0, 0], [-46198, 1242, 0, 0], [10549, -1235, 0, 0], [0, 0, 1680, 348], [-37746, -2866, 0, 0], [0, 0, 2029, -2665], [5150, 256, 0, 0], [0, 0, 3476, -33], [0, 0, -370, -100], [0, 0, -9302, -1588], [0, 0, -545, 2395], [-4490, 286, 0, 0], [41896, 796, 0, 0], [5130, -5980, 0, 0], [0, 0, 3150, 2149], [0, 0, 3728, -1938], [-84681, -2481, 0, 0], [0, 0, -6379, -3507], [14739, -3561, 0, 0], [0, 0, 5476, 622], [29658, 2336, 0, 0], [0, 0, -5470, -1321], [0, 0, -2469, 5669], [-7746, 2584, 0, 0], [0, 0, -1842, -154], [0, 0, -4601, 1767], [6578, -3296, 0, 0], [-39249, -3661, 0, 0], [0, 0, -3286, 1132], [43590, 236, 0, 0], [-7254, -2786, 0, 0], [0, 0, -732, 3988], [44470, 5476, 0, 0], [19358, 1576, 0, 0], [0, 0, 7218, 1425], [-70200, -1112, 0, 0], [0, 0, -4080, 693], [0, 0, 2130, -3301], [-7765, 2359, 0, 0], [0, 0, 3390, -2658], [-29136, 6178, 0, 0], [3937, -5987, 0, 0], [-126118, 740, 0, 0], [-8360, 4572, 0, 0], [-32618, -4904, 0, 0], [-53695, 857, 0, 0], [0, 0, 101, -6843], [4674, -2324, 0, 0], [-3478, 4432, 0, 0], [0, 0, 2578, 4038], [0, 0, 2554, -2412], [-47589, 5259, 0, 0], [0, 0, -6494, 5548], [-86818, 64, 0, 0], [-41493, -4969, 0, 0], [0, 0, -728, -4592], [-740, 1462, 0, 0], [0, 0, 1248, 3467], [-48667, -4747, 0, 0], [0, 0, -5324, -1710], [0, 0, 506, 5212], [0, 0, -11508, -888], [0, 0, 66, 2053], [0, 0, -839, 6433], [-123560, -102, 0, 0], [0, 0, -2050, -5112], [-51414, -1122, 0, 0], [0, 0, -4350, 3528], [0, 0, 15008, 1604], [-50833, -2389, 0, 0], [-88462, -4600, 0, 0], [0, 0, -2284, 3533], [22864, -5804, 0, 0], [0, 0, 4264, -7696], [-24562, -6082, 0, 0], [82614, -3336, 0, 0], [0, 0, -2282, -3712], [38962, -6440, 0, 0], [0, 0, -65, 4197], [88654, 880, 0, 0], [0, 0, 1294, -4850], [0, 0, -2488, 5981], [0, 0, 10208, -1306], [-46092, 6620, 0, 0], [0, 0, -2379, -1881], [-72394, 4592, 0, 0], [0, 0, -2327, -2243], [0, 0, 10767, 1285], [84362, -52, 0, 0], [0, 0, 3000, 4740], [54964, 4116, 0, 0], [50222, -124, 0, 0], [0, 0, 3422, -6632], [-71743, -2271, 0, 0], [0, 0, -4682, 153], [26524, -5658, 0, 0], [90821, 473, 0, 0], [55853, -6559, 0, 0], [0, 0, -2692, 1080], [0, 0, -10782, -522], [-38290, 5652, 0, 0], [0, 0, 2778, -5070], [-122788, -1496, 0, 0], [0, 0, 20639, 2479], [11587, 6103, 0, 0], [0, 0, -11385, -3593], [-43638, -2124, 0, 0], [0, 0, -11182, -5737], [44558, -7608, 0, 0], [24564, 10848, 0, 0], [-47654, 3612, 0, 0], [0, 0, -1320, 3254], [0, 0, 12432, -309], [31848, 6532, 0, 0], [0, 0, 9232, -575], [0, 0, -5298, -352], [-1022, 11424, 0, 0], [96989, 3769, 0, 0], [0, 0, -2179, -297], [0, 0, 7354, 36], [170893, 1809, 0, 0], [-83494, -7868, 0, 0], [0, 0, -3216, 2983], [-47358, -3914, 0, 0], [85464, -782, 0, 0], [0, 0, 1148, 3358], [0, 0, -2207, -217], [0, 0, 12893, -2791], [0, 0, 4192, -7018], [0, 0, -877, -7291], [127450, -2868, 0, 0], [0, 0, -4064, 3276], [0, 0, 3478, 10110], [0, 0, -9299, -5915], [-8120, 4424, 0, 0], [-9560, -6042, 0, 0], [0, 0, -1692, 501], [57877, -251, 0, 0], [3236, -2430, 0, 0], [0, 0, 6576, 5542], [72612, -3460, 0, 0], [0, 0, -5687, 3379], [0, 0, 12590, 2604], [45760, 1748, 0, 0], [-22638, 2888, 0, 0], [0, 0, 14507, -3605], [0, 0, -10200, 628], [-98810, -3308, 0, 0], [0, 0, 12916, -820], [6340, 6934, 0, 0], [0, 0, 7584, -5933], [0, 0, -5334, 10887], [-105121, 1863, 0, 0], [0, 0, -2026, 6281], [-118195, -2191, 0, 0], [0, 0, -861, 4437], [44177, -14367, 0, 0], [71000, -5346, 0, 0], [-114085, 8079, 0, 0], [0, 0, -5362, -10818], [107314, -5436, 0, 0], [0, 0, 2272, 5791], [0, 0, -14577, -2953], [74256, 8232, 0, 0], [0, 0, 4949, -6053], [5092, 8726, 0, 0], [110201, 4977, 0, 0], [0, 0, 3644, -5776], [-109036, 2748, 0, 0], [0, 0, 10288, 1389], [-6646, 4948, 0, 0], [0, 0, -4020, -1700], [-144893, 8963, 0, 0], [0, 0, 10546, 6897], [0, 0, 960, 6025], [54536, 9004, 0, 0], [94294, -7396, 0, 0], [0, 0, 10274, 3397], [63875, -12257, 0, 0], [0, 0, -9789, -2593], [31858, -1808, 0, 0], [0, 0, -12782, 2696], [0, 0, -4748, 11176], [54624, -8024, 0, 0], [30470, -2752, 0, 0], [0, 0, 12006, 3544], [0, 0, -139, 5435], [-225528, 3532, 0, 0], [0, 0, -6722, -7055], [0, 0, 6820, -13086], [0, 0, -2506, -4590], [182054, 6920, 0, 0], [0, 0, -24939, 39], [0, 0, 516, -8838], [-51026, 17044, 0, 0], [0, 0, -5116, -9445], [0, 0, -8778, -782], [0, 0, -3066, 1553], [45725, 481, 0, 0], [0, 0, -2282, -9920]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1872_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1872_4_a_bo();".
// 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_1872_4_a_bo(:prec:=4)
    chi := MakeCharacter_1872_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_1872_4_a_bo();".
// 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_1872_4_a_bo( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1872_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<5,R![75712, 0, -580, 0, 1]>,<7,R![-152, 18, 1]>],Snew);
    return Vf;
end function;