
// Make newform 1872.4.a.bi in Magma, downloaded from the LMFDB on 28 January 2025.
// 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_bi();".
// 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_bi();".
// 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 := [-4, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [-1, 2]];
    Rf_basisdens := [1, 1];
    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]];
    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], [9, -1], [5, 5], [2, 14], [13, 0], [26, 12], [71, 11], [-140, 12], [212, -6], [89, 33], [68, 54], [113, 19], [36, -88], [88, -120], [394, 8], [364, -8], [-368, -38], [-527, -107], [-330, 78], [12, -222], [-20, -276], [672, 68], [-157, -219], [-132, 10], [612, -158], [-660, 52], [256, -324], [-90, -112], [500, 406], [110, 206], [136, -484], [929, 163], [-858, -102], [739, -647], [-3049, 55], [192, -214], [-2819, -191], [-360, -160], [12, 578], [1680, 468], [-2500, 158], [-3552, 288], [2418, 432], [1925, -261], [14, -154], [1576, 324], [3269, 525], [-2150, -642], [1906, -236], [2008, -446], [718, -530], [-2220, 626], [3020, -424], [-2580, 830], [360, 880], [1920, -1642], [621, -635], [-418, -48], [-2455, -453], [4654, -878], [6887, 365], [3735, 155], [4728, 304], [-1182, 568], [913, 143], [765, -71], [1610, -2408], [-2952, -1980], [1844, 1022], [4161, -1173], [5256, -1360], [10130, -830], [4746, 604], [1807, -1429], [3988, 916], [-794, 660], [-6788, 1014], [-1309, 1261], [7640, -418], [-5164, 1672], [-10742, 1260], [-2196, -2180], [480, 926], [-416, 3128], [-3912, -2204], [-5273, -2271], [-6552, -546], [7901, 1291], [9333, 1165], [6708, 472], [7622, -970], [-14347, -1579], [-9612, 1104], [981, 41], [8432, -312], [1653, -2157], [-1924, -186], [-9850, 2266], [-3406, 1068], [5106, 2446], [-11541, 3145], [14512, -108], [7132, 3126], [6658, -154], [6962, -3344], [-11296, -3236], [-3985, 2105], [7916, 516], [-20150, -128], [3198, -1986], [-22008, -1446], [14461, -2785], [-25825, -917], [3943, -729], [13398, -1096], [-1075, 2225], [-14552, -368], [-5064, 110], [-28440, 844], [10460, 3390], [-15348, 4378], [2386, -3264], [-10962, -198], [-24683, -1463], [-12962, 2964], [-3786, -4968], [19128, -856], [32226, 42], [15290, -1804], [-8545, -1165], [-16618, 1774], [12776, -728], [28508, -962], [-5031, 4715], [4806, -92], [-805, 1313], [6595, -2265], [1650, 200], [-18696, 1282], [-11393, -3093], [17423, -2875], [-6584, -2560], [-7582, 2750], [7184, -5510], [4586, -8862], [21920, 4770], [-4264, 2994], [-9868, -5816], [6576, -8144], [11520, 8250], [20716, -5234], [19258, -4410], [-16616, -4848], [-24894, 1270], [-17184, 2160], [-7804, -3140], [2297, 6211], [-7740, 2298], [4555, -5655], [-17480, -612], [8348, 1526], [1885, 6589], [-3996, -6528], [-4253, 9389], [-6202, 11534], [11686, -3962], [-19034, -6328], [33956, 1346], [-3660, -318], [-36158, 30], [-29432, 2322], [6952, 9904], [-16644, 9042], [37396, -4588], [-22426, 7024], [-14117, 4759], [-29209, -6899], [-14484, -1164], [47410, -2276], [-2283, -9635], [-12956, 6456], [7004, 11214], [10287, -13663], [-43232, 464], [17306, 856], [-32900, -9754], [54567, 59], [-63620, 1906], [55816, -2520], [35952, -1986], [-26020, 3320], [26530, 3054], [39887, 6493], [-59948, -2200], [12336, 11482], [-42782, -7344], [-3482, 1568], [52635, 4117], [-4376, -912], [-4639, -14225], [57358, 6942], [-10890, 1128], [-24096, -11378], [33432, -2988], [-70814, 184], [1225, 6673], [-27940, 2800], [42383, 1409], [-48822, -8258], [9040, 17774], [-14238, -6112], [-8888, 4672], [43206, 5794], [50888, -5328], [-35794, -6316], [2524, -11652], [1606, 5144], [70142, -4026], [-14177, 15917], [84558, -3632], [9829, 17813], [24487, 13281], [9193, -2719], [23652, -16632], [-6286, 16868], [13990, -17808], [-22640, 7568], [-4322, 9366], [-8660, -24], [78108, 2774], [2610, -17858], [-40741, -1453], [11526, -5856], [-17530, -2150], [31534, 9102], [35424, -7682], [-26585, 9821], [47312, 8668], [12628, 10108], [15960, -6052], [-43630, 5686], [39792, -6248], [71284, -11538], [80283, -8955], [74824, -384], [53881, -511], [-11652, -20624], [26391, 7011], [-7724, -14300], [330, 23972], [20313, 16995], [-31362, 9750], [-53294, 10360], [11484, 13138], [16582, -10022], [598, -7480], [-9057, -3589], [17306, 5736], [47118, -8764], [100454, -7546], [9436, 8528], [22326, -4712], [18942, -18504], [40383, -10471], [-105876, 6488], [119473, 1439], [7505, 4099], [9547, 22279], [77080, 6326], [-84096, 538], [50665, -4995], [-10536, -29474], [49116, 11148], [26774, 24356], [10239, -9249], [60166, 20962], [14024, 20242], [43898, -6368], [-96144, 4180], [-39548, -11420], [5837, -24691], [-2200, -11264], [35484, -16466], [55087, -20677], [12752, 34912], [49784, -6826], [-7013, 20849], [22795, -3253], [37252, -5130], [-42970, -3380], [-120520, -9796], [-88197, -17059], [-3100, 11264], [52768, 24250], [5118, 20660], [-68494, 2898], [32526, -12692], [-13204, 15544], [31479, 14987], [55562, -14352], [62645, -7197], [5764, 15172], [-51640, 1580], [-57794, 16066], [-90128, -5026], [36360, -23004], [2694, -37584], [-108426, 10046], [18510, -432], [-32684, 15108], [9077, -31333], [-102768, 4034], [-73520, 2620], [57044, 2556], [13374, -668], [-76646, -6226], [18932, 7956], [-23820, 32226], [-54054, 10284], [48412, 13016], [-58298, 12700], [-22922, -27636], [163, -31525], [140631, 11081], [28824, 21270], [15593, 16429], [-95115, -5887], [128444, 10236], [48540, 9914], [-25618, -38696], [-51520, 8966], [-127204, 16652], [36622, -26030], [13183, -44373], [11852, -42344], [-86840, 17330], [-81611, -23233], [104440, -12338], [-46928, -21936], [140088, -3174], [-60920, -34878], [96055, 17373], [7188, 3260], [-107959, 4647], [35324, 2032], [-55106, 17472], [-105415, -9995], [-120168, 6344], [34758, 26020], [76105, -1843], [-131640, -13890], [-74097, -10483], [-20722, -15714], [45616, 11570], [-6056, -5038], [55432, -7864], [163606, 2882], [-107532, -522], [122884, 14780], [-102400, 16754], [-84530, -12760], [130044, 17516], [-122282, 338], [-11752, 27236], [117000, -14818], [-69931, -4285], [23187, -7837], [2044, 9698], [-51024, 4804], [-86084, 21632], [62716, -33940], [12338, 35888], [79976, -18208], [-54474, 2224], [-176116, -2288], [27336, 4776], [126290, -10128], [79826, -32988], [-143384, -18162], [-97173, -32199], [-199475, 6191], [14525, 17837], [115719, 7937], [134481, -12043], [-84298, 3086], [-17769, 47135], [-46424, 41066], [7123, -7889], [-90156, -7788], [-150996, 15642], [-141397, 5777], [33970, -866], [-89748, 9992], [28048, -4792], [-32824, -26162], [-14121, -14385], [-47630, -23252], [-27176, 32060], [-91003, 10667], [-44484, 23974], [-96302, -38700], [74765, 42021], [99187, 2389], [-507, -35557], [-161184, -21144], [46318, 7320], [66027, 8661], [96971, -39473], [56158, -18750], [-121078, -19176], [-123686, -31656], [73320, -17548], [-206848, -4884], [-46714, -20116], [9682, 376], [-202058, 1702], [-9944, 35088], [-35265, 12201], [-129180, 32252], [100504, 20094], [-53376, -16814], [107418, 14810], [-149752, -6348], [-161034, 3004], [-53977, 25189], [28148, 34904], [13691, -16195], [92141, 31545], [-118000, 37800]];
    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_bi();".
// 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_bi(:prec:=2)
    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_bi();".
// 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_bi( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1872_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<5,R![64, -18, 1]>,<7,R![-400, -10, 1]>],Snew);
    return Vf;
end function;