
// Make newform 230.4.a.j in Magma, downloaded from the LMFDB on 20 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_230_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_230_4_a_j();".
// 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_230_4_a_j();".
// 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 := [108, -45, -60, -2, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 1, 0, 0], [54, -45, -5, 1], [-153, -126, -1, 2]];
    Rf_basisdens := [1, 1, 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_230_a();"
function MakeCharacter_230_a()
    N := 230;
    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_230_a_Hecke(Kf)
    return MakeCharacter_230_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 := [[2, 0, 0, 0], [4, -1, 0, 0], [5, 0, 0, 0], [1, 1, 2, 0], [6, 1, -1, -2], [15, 4, 0, 1], [18, -2, -6, -3], [39, 8, -5, 3], [-23, 0, 0, 0], [-34, 9, 10, -5], [-17, 27, 15, 8], [-96, 3, 33, 1], [28, 32, -15, -11], [-32, 52, -18, -4], [106, -16, -33, 4], [-114, 37, 7, 11], [-76, -79, 7, 1], [-66, -47, 31, 0], [-140, 43, 33, -7], [68, -72, 21, 23], [-140, -44, -17, 16], [-220, -92, -20, -28], [-290, 13, -47, -9], [-512, -92, 30, 16], [-198, -13, 55, 30], [266, 17, -29, 13], [54, 89, -157, 32], [194, 187, -69, -49], [-637, 162, -81, 15], [-270, -11, -41, 47], [784, 2, 5, 66], [-38, 30, 163, -12], [643, -166, 97, 3], [-292, -149, -50, -7], [-1707, 84, 55, -1], [1628, -17, 14, 112], [1478, -287, -125, -55], [551, -298, 68, -59], [1864, -180, 124, -24], [-704, -107, 155, -142], [614, 112, -209, 124], [1007, -132, 79, 101], [688, 158, -120, -80], [1272, 334, -47, -114], [2680, 33, -20, -18], [1394, -112, -170, 44], [1122, -299, 241, -105], [1308, 186, 322, -114], [3102, -424, 212, -62], [-278, -346, 114, 50], [1672, 334, 15, 118], [-12, -261, 292, -97], [-612, 98, 116, 122], [193, -608, -487, -163], [1480, -370, -193, -22], [66, 408, 520, 47], [-2130, -233, 16, -79], [1043, 737, -142, -116], [-626, -420, 149, -114], [-5114, 2, -82, 116], [2718, -105, 229, 165], [-1202, 243, -417, -71], [-1304, 259, 443, 228], [-3196, 224, 539, 210], [1337, -667, -508, -74], [-2757, 82, 531, 33], [1760, -103, 680, -41], [187, -530, -705, -253], [-3492, 859, -37, -26], [-1154, 775, 508, 331], [-3768, 316, -549, -18], [-1546, -1362, 248, 210], [1504, -1183, -537, -121], [-2764, -200, -638, 182], [3486, -167, 223, -12], [-2832, -11, 349, -133], [-4058, 129, -253, 134], [3612, -1061, 236, 56], [-4200, -144, 330, -438], [8611, 277, -261, 176], [-6936, -766, -264, -138], [2407, 822, 387, -265], [-118, 1852, 108, -94], [1199, 251, 126, -78], [7191, 176, -600, 7], [6093, -604, 126, -363], [-3143, -141, 228, -446], [7858, -945, 363, -271], [-4148, 976, -371, 240], [6874, -384, 546, 416], [1456, -2211, 25, 321], [-1850, 1034, -520, -238], [-4896, 522, 545, 410], [-4122, 321, -438, -129], [6996, -595, 642, -467], [4353, 1067, -864, -306], [-502, 646, -311, 82], [-2378, -1072, 1286, 596], [-1150, -426, 734, -14], [1168, 494, -893, -392], [5473, 220, -1628, -167], [-10500, -425, -921, 9], [3104, -1391, -241, -105], [882, -2052, 360, -12], [-2846, 2023, 181, -128], [2338, 514, -81, 380], [-9400, 293, -726, -94], [7144, 2290, 932, 68], [-15540, -1663, 317, 346], [907, -65, 1689, 38], [-13152, 1820, 332, 224], [-7570, -2172, -1458, -408], [3470, -812, 1036, 367], [-2899, 38, 27, -681], [-1256, -2038, 148, 748], [-1244, 3154, -384, -182], [-2506, 755, -139, -329], [4346, -700, -2381, -818], [507, 1608, 1564, 701], [-3364, 1238, 694, 334], [-1406, -537, 891, 998], [-1466, 1330, 961, 700], [606, -2981, -471, -423], [11955, 176, -406, -389], [-5250, 968, -1858, 182], [-4887, -936, 1875, -153], [2026, -1669, 2967, -868], [8237, -185, -930, 20], [10922, -882, -360, -105], [-18806, 2705, -1147, 195], [7816, -577, -850, -561], [8881, 1230, 1655, -529], [-2604, -1336, -286, -850], [-8188, 2741, -1325, 323], [-12649, 2149, -385, -1068], [-786, 1114, 42, 742], [8940, 146, -484, -374], [-6800, -3003, 2087, 645], [-5208, 2719, 981, 1203], [6628, 4288, 68, -739], [-25210, 1735, 726, -75], [-6078, -72, -616, -416], [-10458, -3626, 221, 80], [14784, -2041, 1417, -745], [-10218, -1503, -513, 415], [6946, -4290, 1622, -400], [-20015, 2228, -1301, 409], [4606, 2920, 2063, -826], [-13862, -1077, -1926, -667], [33100, 424, 815, 476], [16364, 61, 2487, 24], [8208, 80, -660, 1152], [-21771, -84, -1639, -1045], [-2704, -4994, 2067, 1124], [3526, -1421, -3329, -161], [23726, 2488, 534, -226], [8548, -2084, -1366, -504], [-5202, -1125, -1062, -1053], [25495, -1578, -3171, -829], [-16662, -1315, -869, 452], [16065, 4412, 130, -595], [17166, 1611, 3095, 82], [4020, -1922, -2891, 366], [-19426, -243, 2437, 1132], [4797, 2825, -580, 934], [4398, -4632, 2922, -351], [-17416, -3592, 3418, 167], [-4170, -1774, 1562, 290]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_230_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_230_4_a_j();".
// 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_230_4_a_j(:prec:=4)
    chi := MakeCharacter_230_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_230_4_a_j();".
// 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_230_4_a_j( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_230_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<3,R![-904, 365, 12, -14, 1]>],Snew);
    return Vf;
end function;