
// Make newform 190.4.a.h in Magma, downloaded from the LMFDB on 13 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_190_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_190_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_190_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 := [-40, -23, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-15, -3, 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_190_a();"
function MakeCharacter_190_a()
    N := 190;
    order := 1;
    char_gens := [77, 21];
    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_190_a_Hecke( : Kf := Kf)
    return MakeCharacter_190_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], [-3, -1, 0], [-5, 0, 0], [-4, 7, 1], [-18, -10, -14], [-43, 1, 8], [-44, -3, 29], [-19, 0, 0], [-58, -25, -29], [40, -13, -29], [-68, 14, 50], [-89, 40, -37], [92, 4, 6], [-88, -18, 50], [-384, -16, 8], [277, -67, -36], [-210, -83, 21], [282, -28, -54], [-239, -21, -148], [-108, 88, 12], [32, -205, -17], [570, 46, 96], [42, -154, -160], [-320, 260, -50], [-359, -8, -43], [722, 244, 218], [-523, 176, 251], [-29, 61, -120], [-430, 17, 27], [547, 318, 157], [-939, 438, 209], [-428, -128, -144], [-4, 293, -199], [350, -358, -306], [-270, 476, 586], [662, 418, 112], [-1004, 148, 454], [-1808, -182, -118], [-2129, 290, 259], [-953, -452, -561], [-1430, -132, 542], [-298, -280, -584], [-908, 753, -225], [-1103, -400, 557], [-1114, 368, 192], [-1820, -79, -585], [442, -51, 477], [2787, 14, -941], [-989, -597, -758], [1790, 246, 784], [-2738, 300, 684], [-2620, -827, -21], [2072, -1454, -140], [1172, -296, 312], [1231, -556, 91], [-658, -104, -974], [1590, 932, -872], [1762, -329, 925], [-3584, -166, 788], [-1348, -828, 546], [-218, 834, 268], [-483, 943, -942], [1011, -1048, 1041], [-518, -1797, -1647], [4542, 1239, 717], [-1179, 187, -778], [102, 719, -129], [7071, -172, 67], [-2474, 46, -316], [-890, 2464, 1228], [-3888, -213, -13], [-2690, 653, 1779], [-544, -128, 48], [2877, 291, 742], [-640, 949, -1509], [7507, 192, -547], [3510, 1230, -830], [816, -1554, -2828], [-9298, -484, 428], [6750, -1464, -1668], [-7780, 874, 1534], [792, -913, 423], [-11358, 376, 1130], [2707, -3086, -295], [-3430, 1766, 1340], [9422, 1196, 746], [-570, -3740, -2032], [-954, -3305, -2455], [-5578, 1112, -360], [-5378, 68, 1866], [386, 904, -1434], [6970, -1654, -890], [1041, 54, -1519], [52, 442, -210], [1430, -804, 720], [-8158, -917, 779], [5800, -3348, 86], [4082, -2966, -330], [-4853, -1643, -364], [6602, 1448, -286], [-2059, -1276, -3033], [4676, -2618, -2556], [-893, -124, 2513], [-5710, 3190, 1950], [7922, -1904, 1980], [-6354, 405, 2799], [-3454, 1974, 624], [-7278, 452, -756], [290, 2754, -992], [6472, 3328, 2894], [4521, -1786, 1529], [-11148, 1558, -1612], [5696, -1208, -2658], [-3850, 1622, 586], [2542, -190, 3242], [7112, 498, 1028], [-13658, -1210, 2412], [-4594, 4427, 3855], [3952, 682, 828], [2710, -1745, -513], [13732, 1101, -4475], [-10003, 914, -2297], [-6099, -133, 566], [16847, -1748, -91], [-2678, -760, 1124], [-15618, 3604, 3226], [-13850, -1156, 2968], [-20130, 1619, -415], [16, -3429, 1305], [-9078, 1922, -306], [6660, -1602, -2518], [-2963, 2030, 3857], [-26018, -278, -2372], [-13694, -5848, -6204], [13242, -6299, 385], [-3110, 1335, 5927], [3617, 3399, 1934], [7281, 1147, -360], [6821, -4527, -5656], [-1690, -2239, 3], [-3888, 3339, 4177], [842, -2762, -1210], [-7728, -3207, -4301], [-8409, 6847, -698], [450, -2039, -1765], [-7430, 1392, 8150], [-17438, -404, 3920], [33471, 1254, 2433], [34140, 2156, -1644], [1177, -4052, 1743], [4001, 1595, -6150], [15662, -506, -7884], [-14368, -1294, 830], [511, -3068, -3491], [10611, 6785, 5492], [13222, 100, 5530], [-9380, -1445, -75], [20230, -11, -5345], [20016, 3575, 275], [24522, 1007, 4329], [28066, 1128, 3866], [12167, -4166, 3125], [-6414, 4028, 9210], [-17888, -904, -4852], [17161, -6696, -7491], [-15133, -10962, -11633], [-8818, 322, -1728], [-38844, 4228, 314]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_190_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_190_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_190_4_a_h(:prec:=3)
    chi := MakeCharacter_190_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_190_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_190_4_a_h( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_190_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<3,R![-2, 4, 9, 1]>],Snew);
    return Vf;
end function;