
// Make newform 230.4.a.g in Magma, downloaded from the LMFDB on 24 December 2025.
// 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_g();".
// 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_g();".
// 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, -45, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-31, 1, 1]];
    Rf_basisdens := [1, 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_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 := 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]];
    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, -1, 0], [5, 0, 0], [1, 3, -1], [10, -5, -2], [27, -3, 3], [46, -11, 0], [-59, -9, -1], [23, 0, 0], [122, -18, 4], [125, 17, -5], [324, 8, 2], [-204, 47, 10], [256, 40, -4], [-106, 42, -6], [186, -60, -12], [40, 34, 12], [-30, 49, 8], [528, 20, -12], [-132, -67, 8], [-284, 30, -42], [-272, -28, 16], [-106, 52, 22], [-88, 200, 26], [462, -25, 40], [-154, 102, 16], [530, -169, -6], [-686, 2, -6], [157, 81, 17], [-426, 0, 36], [464, 38, 72], [-1074, 172, -66], [1551, -81, -21], [-224, 146, -28], [-1869, 51, -93], [1172, -327, 0], [214, 74, 120], [1063, -85, -3], [-1144, 144, -96], [-1804, -383, 54], [-494, -318, -110], [1457, 405, 21], [588, -114, 108], [928, 250, -110], [-516, 447, -2], [-1198, 172, 158], [-1682, 388, 158], [-832, 176, -64], [1418, 466, 90], [-2870, -8, -92], [-1028, -874, 110], [-2220, 140, -204], [1708, -556, -34], [-1909, 465, -63], [-2340, 358, 86], [-730, -275, 238], [-1734, -722, 132], [-1599, -19, 23], [1994, 308, -68], [-3662, 78, 64], [858, 228, -150], [2238, -192, 96], [396, -727, 108], [-6916, 136, -108], [-5595, 301, 149], [-561, -395, 15], [2592, -298, 356], [-1193, 447, 187], [1768, 1119, 32], [614, -880, 240], [1548, -756, -18], [-1126, 64, 262], [-176, -1060, 0], [3088, 246, -50], [1882, -831, -106], [3112, 1616, -296], [7210, 351, -80], [-824, 1087, 58], [8164, 214, 222], [333, -641, -3], [4584, 532, -204], [-1431, -579, -499], [530, 554, 462], [3307, 615, -105], [5085, 53, -237], [6445, -183, 511], [1519, 313, -397], [-5194, -56, 76], [-4104, 1002, -162], [-5702, -548, 318], [7084, -46, -112], [3922, -732, 134], [1884, -1034, -540], [3446, 2282, -58], [14284, 788, 40], [9905, -1101, -241], [-2834, 1454, 64], [-6902, -1932, 0], [1550, 2124, -378], [2004, 12, -310], [-7055, 769, 467], [932, 1668, 410], [-876, -1992, -64], [-3762, 1144, 492], [-11098, 1259, 418], [-4802, -812, -492], [-12212, -1033, 444], [-4272, -538, 130], [7364, -1929, 520], [8021, 1423, -203], [-16548, -620, -92], [14062, 1844, -400], [-9230, 2781, 244], [-4681, 2153, 325], [-904, 1198, -904], [3468, -2152, 894], [-8234, -2666, -114], [3030, 1496, -950], [5847, 1717, 23], [428, 1204, -432], [-10490, 681, 124], [-14870, -1584, -184], [1218, -936, -468], [-3485, 1051, 9], [11014, 702, 398], [5447, 2823, -473], [-5450, -3413, -348], [-12113, -2525, 425], [-3602, 2971, 510], [-10042, -844, -80], [-17972, 440, 296], [-1607, 3615, 855], [17400, -1518, 192], [22332, -588, 1018], [21417, -1269, -63], [-7594, 332, -1252], [-14852, -484, -502], [640, 4902, 204], [12392, 746, -274], [-8740, 45, -710], [11654, -1034, -986], [22410, 2376, -220], [-10322, 3848, -94], [2340, -1942, 928], [18702, -2608, 312], [7850, -4190, 1134], [10469, -1749, -79], [-24698, -652, -332], [5834, -5002, -686], [6116, 1946, 20], [3056, -5485, -350], [-3400, 5848, -238], [20237, -1563, -425], [-5188, 1848, 524], [36234, 2226, 194], [7370, -4630, 150], [15656, -640, 1312], [-27074, 4348, 548], [-9845, -6357, 559], [5718, -3671, -1228], [-16191, 1457, -957], [-150, -2493, 852], [7648, 6006, -240], [1106, 3225, -1426], [-1447, -5695, 361], [-7910, 5383, -302], [28568, -2065, -516], [-19694, 5492, 1076]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_230_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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