
// Make newform 231.4.a.h in Magma, downloaded from the LMFDB on 15 April 2026.
// To make the character of type GrpDrchElt, type "MakeCharacter_231_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_231_4_a_h();".
// 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_231_4_a_h();".
// 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;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    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_231_a();"
function MakeCharacter_231_a()
    N := 231;
    order := 1;
    char_gens := [155, 199, 211];
    v := [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_231_a_Hecke( : Kf := Kf)
    return MakeCharacter_231_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 := [[1, 1], [-3, 0], [2, -3], [7, 0], [-11, 0], [-6, -13], [-54, -4], [-24, -23], [-32, 8], [-38, 65], [-168, 26], [-86, 107], [-22, 86], [-76, 120], [132, -163], [54, 58], [-32, 53], [-178, -80], [-16, -95], [496, -56], [-322, 317], [-176, 124], [-116, -30], [130, -216], [-1142, 18], [-562, -476], [-128, 54], [712, 315], [-778, -340], [-158, -12], [-488, -746], [772, 308], [1754, -364], [-308, -332], [-110, 525], [992, -838], [-2282, -214], [-416, 1497], [-1816, 1324], [-578, 1630], [1700, 44], [318, 750], [256, -1646], [-278, -1742], [-226, -1920], [-4312, 812], [-204, -1138], [24, -454], [3404, -2014], [-1330, 638], [-3878, -12], [-2356, 853], [-3650, -1173], [520, 195], [366, -2775], [5148, -1509], [-1914, 384], [7124, 473], [1398, 818], [-1874, 329], [-416, -767], [4070, 1218], [6100, -2696], [-3576, 1992], [6170, -184], [2926, -2718], [4644, -772], [6858, -1874], [9100, -212], [-1078, -3209], [-1674, 3119], [8496, -1612], [-4632, 1986], [-642, -1836], [2992, 2647], [-3072, 1520], [3094, -2626], [2414, 1004], [506, -2378], [-6998, 660], [-2432, 5731], [-4174, -1087], [-3660, 3867], [-5894, 5438], [3580, 2809], [4236, -328], [-8438, -854], [4066, -342], [8894, 1150], [612, -6035], [-1992, -1439], [-1400, 634], [-12856, 2560], [13560, -2181], [-17176, 647], [2888, 2160], [-13258, -3640], [-4570, 2593], [2648, -5145], [-3618, 8334], [-3236, -5796], [-1798, 8021], [4276, -5196], [9562, -1448], [-13756, 7916], [11362, -320], [8072, 4935], [-7998, 5934], [-7568, -4812], [5806, 1785], [180, 5873], [-20322, -2204], [5146, -11964], [324, -7854], [360, 7644], [-14126, -3280], [7812, -7608], [12180, -8561], [10750, -2854], [24928, -3329], [-6050, -594], [3514, -3666], [-11346, 576], [-5612, -1538], [5916, -6342], [-21050, -4888], [-7118, 11533], [-1684, -4213], [25896, 3796], [-11394, -4760], [-11124, 12704], [3708, 8651], [-6780, -8419], [13562, -3317], [-28630, 1690], [3454, -1965], [-14334, 8465], [-17136, 9375], [-14686, 7619], [-19714, -9691], [8056, 12759], [15258, 5679], [-20740, 9445], [-4200, -2365], [1462, 12546], [-11732, -4931], [17590, -1820], [1890, -16640], [7468, 9888], [-28616, 10828], [21742, -1614], [-13714, -4335], [-248, 7231], [-8464, -5254], [-16508, 2656], [6432, 13322], [3640, -5396], [-19914, 21615], [30090, 2224], [-44882, -3286], [10652, -5094], [-10066, 23341], [8256, -16678], [-28440, -441], [16394, 13066], [23272, 8632], [11396, -25851], [438, 11404]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_231_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_231_4_a_h();".
// 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_231_4_a_h(:prec:=2)
    chi := MakeCharacter_231_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_231_4_a_h();".
// 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_231_4_a_h( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_231_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![-2, -3, 1]>,<5,R![-38, -1, 1]>],Snew);
    return Vf;
end function;