
// Make newform 19.4.c.a in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_19_c();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_19_c_Hecke();"
// 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_c_a();".
// 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_c_a();".
// 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 := [3025, 0, 55, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]];
    Rf_basisdens := [1, 1, 55, 55];
    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_c();"
function MakeCharacter_19_c()
    N := 19;
    order := 3;
    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;

// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_19_c_Hecke();"
function MakeCharacter_19_c_Hecke(Kf)
    N := 19;
    order := 3;
    char_gens := [2];
    char_values := [[-1, 0, -1, 0]];
    assert UnitGenerators(DirichletGroup(N)) eq char_gens;
    values := ConvertToHeckeField(char_values : pass_field := true, Kf := Kf); // the value of chi on the gens as elements in the Hecke field
    F := Universe(values);// the Hecke field
    chi := DirichletCharacterFromValuesOnUnitGenerators(DirichletGroup(N,F),values);
    return chi;
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, 0, 1, 0], [0, 1, 0, 1], [0, -1, -7, -1], [-7, 0, 0, -1], [14, 0, 0, -7], [14, -8, 14, 0], [0, 8, -56, 8], [-70, 7, -42, 8], [-57, -7, -57, 0], [-111, 7, -111, 0], [133, 0, 0, -7], [91, 0, 0, -7], [0, -34, 77, -34], [0, 42, 134, 42], [-63, -15, -63, 0], [442, -28, 442, 0], [0, 13, 56, 13], [-273, 29, -273, 0], [370, 63, 370, 0], [0, 42, 216, 42], [0, 6, 175, 6], [0, -56, -76, -56], [-952, 0, 0, -35], [-56, -104, -56, 0], [0, -62, -273, -62], [595, -111, 595, 0], [672, 0, 0, -14], [-70, 0, 0, 70], [0, 140, 540, 140], [91, 0, 0, -140], [608, -126, 608, 0], [0, -85, 882, -85], [99, 252, 99, 0], [-840, 239, -840, 0], [0, -21, -309, -21], [-931, 0, 0, 133], [0, 260, -1288, 260], [1108, 0, 0, 245], [-1484, 8, -1484, 0], [0, 160, -1358, 160], [700, 0, 0, 35], [1911, -197, 1911, 0], [-2268, 0, 0, 84], [0, -84, -2948, -84], [931, 0, 0, -231], [1708, 358, 1708, 0], [0, 406, -440, 406], [0, -169, 2261, -169], [2982, 0, 0, 231], [1988, 0, 0, -448], [0, 14, 1499, 14], [-2436, 0, 0, -504], [-3451, -428, -3451, 0], [-728, -253, -728, 0], [-567, -50, -567, 0], [0, -595, -3515, -595], [0, 496, 4592, 496], [0, -489, 1743, -489], [-3689, 0, 0, 63], [4185, 238, 4185, 0], [0, 265, -3612, 265], [5733, 0, 0, -187], [0, -351, -2562, -351], [1715, 0, 0, 343], [735, -566, 735, 0], [-2554, 952, -2554, 0], [-6860, 0, 0, -161], [0, 266, 4857, 266], [0, 35, -4346, 35], [-5824, 0, 0, 616], [1029, 0, 0, 1090], [0, -1491, -125, -1491], [4053, 307, 4053, 0], [-84, 0, 0, 112], [1904, 0, 0, 938], [0, 15, 14147, 15], [-8268, 336, -8268, 0], [0, 533, -3339, 533], [0, -308, -7727, -308], [2765, 636, 2765, 0], [-10584, 0, 0, 28], [0, 399, -8905, 399], [-10396, -686, -10396, 0], [238, 1450, 238, 0], [0, -1751, -1197, -1751], [2512, -1561, 2512, 0], [10829, 0, 0, 490], [3017, 0, 0, -742], [0, 384, 8190, 384], [5852, 0, 0, -630], [3850, 0, 0, -609], [14140, -204, 14140, 0], [-10969, 0, 0, 315], [0, 266, 2738, 266], [0, -1043, -8898, -1043], [-8183, -1765, -8183, 0], [2408, -1996, 2408, 0], [-4865, 0, 0, -826], [15778, 1086, 15778, 0], [8072, -1792, 8072, 0], [-4486, -714, -4486, 0], [7288, 1652, 7288, 0], [5362, 0, 0, -133], [-2940, 0, 0, 2436], [-3752, 0, 0, -385], [-2037, 0, 0, 2688], [0, -706, 2898, -706], [6909, 162, 6909, 0], [-18087, -189, -18087, 0], [-4123, 0, 0, -140], [-16457, 0, 0, -371], [0, 756, 258, 756], [-12529, -154, -12529, 0], [8946, 0, 0, 994], [11929, 1561, 11929, 0], [0, -434, 12781, -434], [0, 57, 7868, 57], [2772, 0, 0, -1470], [-14840, 0, 0, -2128], [-22240, 756, -22240, 0], [17325, 195, 17325, 0], [8290, 0, 0, -2842], [6090, 0, 0, 1540], [14040, 0, 0, -1764], [8288, 0, 0, -756], [0, -385, -13259, -385], [-11185, 1295, -11185, 0], [0, -538, 20216, -538], [0, -1084, -15036, -1084], [-18347, 0, 0, 147], [0, 2023, -22786, 2023], [0, -287, -3445, -287], [904, -4130, 904, 0], [0, -1876, 1758, -1876], [2107, 0, 0, 3698], [-5950, 526, -5950, 0], [-15043, -1973, -15043, 0], [-37464, 0, 0, 679], [5747, 0, 0, 2177], [8423, 0, 0, 1176], [-10374, 2458, -10374, 0], [18654, 0, 18654, 0], [30080, 1134, 30080, 0], [-9598, -847, -9598, 0], [29988, 0, 0, -1640], [0, -2367, 24297, -2367], [0, -3732, -1442, -3732], [0, 1408, -12019, 1408], [-10024, 3779, -10024, 0], [-13335, 0, 0, 1309], [0, -2513, 3361, -2513], [-7413, 0, 0, 1526], [13586, -203, 13586, 0], [15428, 596, 15428, 0], [0, 1491, 20896, 1491], [14161, 0, 0, -3115], [-11356, 0, 0, -4410], [0, 372, 10129, 372], [-12607, 734, -12607, 0], [770, 7400, 770, 0], [0, 4900, -7776, 4900], [0, -3514, -23883, -3514], [0, 1134, 27616, 1134], [0, -2589, 20076, -2589], [-14037, 0, 0, -2646], [0, 3228, -18368, 3228], [0, -728, -1896, -728], [9597, -29, 9597, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_19_c_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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