
// Make newform 189.4.a.l in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_189_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_189_4_a_l();".
// 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_189_4_a_l();".
// 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, 0, -9, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, -5, 0, 1], [0, -11, 0, 1], [-14, 0, 3, 0]];
    Rf_basisdens := [1, 2, 2, 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_189_a();"
function MakeCharacter_189_a()
    N := 189;
    order := 1;
    char_gens := [29, 136];
    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_189_a_Hecke(Kf)
    return MakeCharacter_189_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 := [[0, -1, -1, 0], [0, 0, 0, 0], [0, -4, -3, 0], [-7, 0, 0, 0], [0, -6, 11, 0], [-14, 0, 0, 6], [0, -4, -2, 0], [45, 0, 0, 4], [0, -8, -43, 0], [0, 22, 28, 0], [107, 0, 0, 10], [327, 0, 0, -6], [0, 22, 111, 0], [28, 0, 0, -2], [0, 114, -6, 0], [0, 148, 20, 0], [0, -94, -74, 0], [-672, 0, 0, -8], [342, 0, 0, -38], [0, -136, 61, 0], [-104, 0, 0, -10], [292, 0, 0, -26], [0, 158, 4, 0], [0, 110, 87, 0], [-152, 0, 0, 8], [0, 8, -178, 0], [291, 0, 0, -70], [0, -256, -168, 0], [165, 0, 0, -30], [0, -184, -306, 0], [-38, 0, 0, 182], [0, 30, 50, 0], [0, 370, 368, 0], [1556, 0, 0, -32], [0, -156, -354, 0], [502, 0, 0, 184], [-1078, 0, 0, 62], [1802, 0, 0, 74], [0, -156, -418, 0], [0, -116, 39, 0], [0, 844, 372, 0], [1410, 0, 0, -104], [0, -80, -1169, 0], [-1138, 0, 0, -168], [0, 636, 158, 0], [-1677, 0, 0, -270], [3562, 0, 0, 180], [2161, 0, 0, 210], [0, 876, 738, 0], [436, 0, 0, -368], [0, 324, 1086, 0], [0, 956, 484, 0], [100, 0, 0, 130], [0, 480, -256, 0], [0, -954, -497, 0], [0, 40, 1297, 0], [0, 388, -283, 0], [-932, 0, 0, -492], [211, 0, 0, -210], [0, -382, -2218, 0], [1364, 0, 0, -184], [0, -1072, -82, 0], [-3607, 0, 0, 164], [0, -1266, 192, 0], [-7110, 0, 0, -178], [0, -642, -618, 0], [1632, 0, 0, -292], [3539, 0, 0, 464], [0, 1790, 671, 0], [490, 0, 0, 756], [0, 2518, 1381, 0], [0, -980, 432, 0], [2555, 0, 0, -62], [-623, 0, 0, -362], [4600, 0, 0, 182], [0, 2164, -118, 0], [0, 2256, 1140, 0], [-3766, 0, 0, 40], [0, 2702, 1924, 0], [1100, 0, 0, -486], [0, 2256, 3642, 0], [-2745, 0, 0, -166], [0, -1332, 1419, 0], [-5050, 0, 0, -274], [-11864, 0, 0, 320], [0, -782, 2045, 0], [0, -936, -2022, 0], [-8791, 0, 0, -652], [0, -720, -233, 0], [5442, 0, 0, -212], [0, 2710, -1510, 0], [0, -56, -5136, 0], [9312, 0, 0, 670], [0, -710, -1317, 0], [9256, 0, 0, 822], [0, -2574, -276, 0], [0, 2692, 3510, 0], [0, 38, 3541, 0], [-5695, 0, 0, -184], [-649, 0, 0, -438], [-736, 0, 0, -604], [0, 3952, 3790, 0], [0, -4770, 116, 0], [0, 2260, -26, 0], [11026, 0, 0, -764], [8254, 0, 0, -372], [0, -4160, -2102, 0], [0, -2026, -5603, 0], [0, -5636, -3625, 0], [8390, 0, 0, 586], [8916, 0, 0, 848], [-113, 0, 0, -30], [0, -1378, 5566, 0], [6059, 0, 0, 2036], [11052, 0, 0, -202], [0, -716, 2978, 0], [-731, 0, 0, -2168], [0, 5186, 6014, 0], [0, 4798, 2594, 0], [0, 4838, -1505, 0], [3298, 0, 0, 786], [1930, 0, 0, 1872], [0, 1060, -553, 0], [0, 3370, 2657, 0], [12864, 0, 0, -700], [0, -2810, -196, 0], [-7839, 0, 0, 726], [0, 1666, 8006, 0], [22184, 0, 0, 576], [-780, 0, 0, -2190], [6442, 0, 0, -1276], [0, 6636, 3741, 0], [3572, 0, 0, 818], [24118, 0, 0, -836], [0, -4372, -4802, 0], [-23138, 0, 0, 394], [0, 2088, -3521, 0], [5268, 0, 0, 1756], [0, 7180, 6883, 0], [0, -870, -3420, 0], [8855, 0, 0, -108], [0, -6470, -1170, 0], [-26514, 0, 0, 384], [0, 230, 1597, 0], [20908, 0, 0, -914], [0, 7170, 9308, 0], [1520, 0, 0, 912], [0, -6506, 403, 0], [6585, 0, 0, -712], [0, 6876, 10284, 0], [-25718, 0, 0, 972], [0, -10798, -4319, 0], [18592, 0, 0, -728], [0, 7702, 5772, 0], [-23994, 0, 0, 1484], [0, 14288, 7756, 0], [-6180, 0, 0, 2192], [0, 852, 13738, 0], [-3684, 0, 0, 0], [0, 4732, 5913, 0], [0, -3786, -7211, 0], [0, -646, 1196, 0], [2854, 0, 0, 240], [0, -3746, -8836, 0], [0, -10724, -2788, 0], [0, 7446, -2898, 0], [-8638, 0, 0, -1998], [-946, 0, 0, -1504]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_189_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_189_4_a_l();".
// 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_189_4_a_l(:prec:=4)
    chi := MakeCharacter_189_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_189_4_a_l();".
// 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_189_4_a_l( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_189_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![64, 0, -29, 0, 1]>,<5,R![27889, 0, -386, 0, 1]>],Snew);
    return Vf;
end function;