
// Make newform 19.4.a.b in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_19_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_19_4_a_b();".
// 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_19_4_a_b();".
// 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 := [-8, -16, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-10, -1, 1]];
    Rf_basisdens := [1, 1, 2];
    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_19_a();"
function MakeCharacter_19_a()
    N := 19;
    order := 1;
    char_gens := [2];
    v := [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_19_a_Hecke(Kf)
    return MakeCharacter_19_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 := [[1, 1, -1], [0, -1, 2], [5, -3, 2], [-13, 4, 0], [5, 3, -2], [22, 5, -6], [1, 22, 4], [-19, 0, 0], [-42, 11, 14], [144, -25, -30], [-32, -56, 12], [-122, 32, 44], [314, 6, 8], [-163, 29, -110], [39, -33, -18], [266, 29, -10], [128, -53, -66], [285, 23, 110], [-94, 29, 46], [270, -28, 64], [265, -176, 8], [56, 206, 8], [-232, -130, 60], [-40, 168, -220], [-852, -90, 196], [62, -292, 256], [174, -208, 24], [248, 381, -190], [642, -57, 26], [-806, 176, 108], [190, -272, -100], [-597, 443, -186], [129, -526, 244], [-255, -91, -190], [1467, 99, 366], [830, 712, -512], [-754, 340, 232], [1612, 432, -56], [1334, -794, -264], [790, 416, 104], [214, -254, 792], [426, 488, -744], [-1257, -156, -360], [52, 570, -816], [-1898, 174, -564], [1631, -276, -280], [-620, -1205, 606], [-262, 284, 1140], [-2922, -175, 490], [-1537, 861, -542], [1433, -361, -258], [723, -1064, -208], [-818, -1406, 1552], [-1237, 645, -1694], [-3936, -348, -208], [-893, 75, -850], [4400, -398, 1008], [-3714, 155, 118], [403, 1395, -1002], [-1734, 1914, 212], [2517, -1133, -138], [5058, 179, -706], [2808, -744, 1308], [-2515, -678, 1412], [1356, -281, -26], [3424, 213, -1318], [-1202, -65, 130], [1800, 484, -1880], [-9461, -831, 506], [-2845, 2341, -998], [-384, 463, -314], [3175, 1266, -324], [1320, -1692, 1160], [-8622, -9, -346], [-2668, 2023, 1710], [-1660, -218, 2048], [453, 1107, -1578], [-4497, 1811, -2250], [5032, -180, 2452], [2248, -1124, -28], [2316, -1416, 3080], [710, -1787, -346], [-3668, -706, -780], [494, -1696, -156], [-3042, 782, -1624], [8219, 181, -846], [3908, 94, -92], [2951, 1310, 428], [1575, 1067, 1366], [12371, -1329, 1086], [2059, -2471, 1418], [-7108, 248, -1520], [3554, 3920, -1256], [-4540, -736, 936], [4767, 1331, 470], [1778, -473, -882], [148, -2042, -2748], [6436, 3100, 156], [8432, 1129, -2686], [10525, -2605, -970], [-5516, -232, 1600], [59, -925, 1718], [3166, 366, 1864], [1272, -3320, 4928], [-2036, -3096, 2032], [-2949, 5480, -3704], [-201, -2453, 4294], [3846, 4732, -4384], [14232, 2068, -2092], [-7282, -5414, 2068], [8740, -5118, 740], [-3921, 653, 3298], [2779, 1153, 2922], [-23448, -270, -244], [-7375, -5919, 4106], [6868, -4066, 3044], [2021, -1373, 3014], [1647, 7116, -3048], [3487, -4745, 5238], [2716, 1437, 354], [-7986, 1663, 4718], [1762, -2114, -84], [2196, -3299, -1658], [7548, 3392, -3032], [4319, 1225, 1442], [15106, 5534, -3660], [-12566, -2772, -1304], [-23317, 2508, 128], [-8475, -6390, 1676], [-13514, -122, 404], [15161, 1913, -4390], [596, 1740, 340], [-9736, 6480, -808], [-387, -4221, 3086], [-4955, -574, 4916], [-3653, 3046, -884], [4948, -2891, 3034], [6606, 865, -4622], [-9334, 265, -8706], [-13285, -3422, 3596], [-7698, 7719, -3106], [14487, 2031, -1842], [16735, -218, 1892], [20338, -4271, 126], [-17946, 3471, -6058], [-4386, -322, -668], [-14774, -2320, -152], [-4162, 1298, -6388], [-6575, -6085, 7430], [-14658, 8460, -3700], [20284, -3695, 6978], [-15753, -3079, -3574], [7969, -1093, -3666], [-350, -4836, 2968], [8482, -313, -9662], [526, 5606, 3884], [20006, 7901, -4118], [-13076, -4997, 1118], [-3839, -440, 2520], [-18836, 51, 6478], [7188, 4460, 344], [-35448, 1102, 1840], [208, 2592, 1008], [-5028, -8944, 3808], [10548, -7116, 3684], [7096, -4618, 1228], [13038, -2130, -9488], [28815, 2543, -690]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_19_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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