
// Make newform 19.7.b.b in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_19_b();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_19_b_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_7_b_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_7_b_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 := [71047680, 0, 4242376, 0, 75582, 0, 483, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0], [0, -25301016, 0, -753578, 0, -5377, 0, -11], [-6097944, 0, -603554, 0, -5377, 0, -11, 0], [-24250848, 0, -753578, 0, -5377, 0, -11, 0], [0, 53934168, 0, 925034, 0, 5377, 0, 11], [91462416, 0, 3811514, 0, 38665, 0, 107, 0], [0, 1407625608, 0, 50838718, 0, 454499, 0, 1153]];
    Rf_basisdens := [1, 1, 1200192, 150024, 150024, 171456, 150024, 1200192];
    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_b();"
function MakeCharacter_19_b()
    N := 19;
    order := 2;
    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_b_Hecke();"
function MakeCharacter_19_b_Hecke(Kf)
    N := 19;
    order := 2;
    char_gens := [2];
    char_values := [[-1, 0, 0, 0, 0, 0, 0, 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 := 7;
    raw_aps := [[0, 1, 0, 0, 0, 0, 0, 0], [0, 0, -1, 0, 0, 0, 0, 0], [14, 0, 0, 0, 0, 0, -1, 0], [-16, 0, 0, -3, 2, 0, -1, 0], [-259, 0, 0, 13, -2, 0, 0, 0], [0, 42, 9, 0, 0, -1, 0, 1], [771, 0, 0, 28, -112, 0, -12, 0], [2607, -118, -35, -41, -94, 5, 12, -1], [-6185, 0, 0, -10, -392, 0, 13, 0], [0, 588, 437, 0, 0, 8, 0, 12], [0, 1622, 302, 0, 0, -1, 0, -11], [0, -2294, 1218, 0, 0, -7, 0, -13], [0, -1858, 274, 0, 0, -109, 0, 1], [32595, 0, 0, -415, 806, 0, 22, 0], [-12179, 0, 0, 793, -2946, 0, -24, 0], [0, -2376, -1605, 0, 0, 6, 0, 54], [0, 12502, 861, 0, 0, -125, 0, -119], [-8614, 0, 0, 648, 7032, 0, -573, 0], [0, 20556, 4475, 0, 0, 298, 0, 102], [0, -6700, 3294, 0, 0, -266, 0, 154], [62485, 0, 0, 1720, -8912, 0, -2242, 0], [0, -52694, 2046, 0, 0, -75, 0, 79], [64654, 0, 0, -3238, -8396, 0, -1112, 0], [0, 6838, 13272, 0, 0, 515, 0, -295], [0, -29696, -8078, 0, 0, 1432, 0, 152], [287490, 0, 0, 10220, 6120, 0, 2848, 0], [0, 34236, 2688, 0, 0, -1582, 0, -2], [0, 27602, -21219, 0, 0, -815, 0, 499], [0, -1936, 7273, 0, 0, 218, 0, -574], [0, -5054, -7626, 0, 0, -275, 0, 703], [0, -31726, 47028, 0, 0, -2267, 0, 343], [1119531, 0, 0, 12557, 10110, 0, -218, 0], [-1229183, 0, 0, 9656, 64240, 0, -4478, 0], [2685841, 0, 0, -10547, -19698, 0, 7996, 0], [1062572, 0, 0, 29016, 30480, 0, -8107, 0], [0, -33768, 90298, 0, 0, 4748, 0, -348], [-2501698, 0, 0, -38004, 78800, 0, 11012, 0], [60236, 0, 0, 21498, -38924, 0, 16630, 0], [0, -249218, -115430, 0, 0, 3063, 0, 293], [0, 134968, 43358, 0, 0, -980, 0, -1660], [0, 268418, -207550, 0, 0, 3173, 0, -537], [0, 115320, -68802, 0, 0, -2124, 0, -660], [-1675170, 0, 0, -64159, 117666, 0, -16715, 0], [0, 156062, 157010, 0, 0, 1151, 0, 1405], [-3162990, 0, 0, 65200, 33944, 0, -19152, 0], [3461912, 0, 0, 76557, 155914, 0, 6439, 0], [0, 343154, -22761, 0, 0, 2853, 0, -1417], [0, 417710, 166960, 0, 0, -10281, 0, 2773], [0, -377090, -4753, 0, 0, -4049, 0, -3139], [3359190, 0, 0, -46180, -260832, 0, 4751, 0], [3794020, 0, 0, 420, -27136, 0, 8141, 0], [-5819722, 0, 0, 135253, -232718, 0, -4827, 0], [0, -425706, 284694, 0, 0, -5681, 0, -4843], [7536981, 0, 0, -22811, 156086, 0, 6648, 0], [0, 1480544, 166348, 0, 0, 8204, 0, 2332], [-12277011, 0, 0, 14837, 378870, 0, 91936, 0], [0, -734250, -101706, 0, 0, -17601, 0, 6789], [1617005, 0, 0, -27870, 116728, 0, -74573, 0], [-8975688, 0, 0, -88204, -48976, 0, -54311, 0], [0, -2021604, 10656, 0, 0, 13510, 0, 514], [-15963541, 0, 0, 190317, -283090, 0, -56554, 0], [0, -96674, 102987, 0, 0, -35543, 0, 511], [0, -547550, -937926, 0, 0, -34003, 0, -6481], [-16216896, 0, 0, 280437, -476774, 0, 78263, 0], [5521323, 0, 0, -41296, 522312, 0, -139591, 0], [0, -702870, 533577, 0, 0, 3499, 0, 5533], [0, 704476, 781929, 0, 0, 40890, 0, 14950], [0, 682996, -803904, 0, 0, -27698, 0, 210], [-7751553, 0, 0, 155841, 763198, 0, -110494, 0], [13464256, 0, 0, -178136, -483744, 0, -137543, 0], [-17391223, 0, 0, -469944, 98064, 0, -259153, 0], [-195216, 0, 0, -120383, 1480874, 0, -35169, 0], [-28718972, 0, 0, -115286, -1195332, 0, -165506, 0], [0, -951630, 427775, 0, 0, -68861, 0, 13293], [0, 3688374, 1001841, 0, 0, -82953, 0, -1107], [0, 2617962, -283920, 0, 0, 45413, 0, 15359], [14072812, 0, 0, -432820, -358016, 0, 64141, 0], [-21102780, 0, 0, 234320, 328408, 0, 213165, 0], [0, -1406738, -25208, 0, 0, 30243, 0, -32575], [0, 2839226, 1611374, 0, 0, -55099, 0, -5441], [37325526, 0, 0, -318838, -193884, 0, 63904, 0], [0, 1664100, -71537, 0, 0, -19396, 0, 14232], [0, 1392632, -2010456, 0, 0, -24956, 0, -31652], [0, -353306, 832812, 0, 0, 142691, 0, -16951], [0, -818374, -880748, 0, 0, 28737, 0, 8059], [34130209, 0, 0, -107543, 1705830, 0, 111996, 0], [0, -5320952, -1836122, 0, 0, 41872, 0, -14040], [19570101, 0, 0, -216052, 4046888, 0, 156958, 0], [-48890722, 0, 0, -423672, -414168, 0, 457199, 0], [-76011119, 0, 0, -36587, 4934, 0, 438204, 0], [-88607423, 0, 0, -144839, 603294, 0, 558564, 0], [40687104, 0, 0, 516642, -3236708, 0, -677830, 0], [0, 3357496, 1536624, 0, 0, 114272, 0, 21416], [14630470, 0, 0, 1273546, -1746996, 0, 389784, 0], [-58217245, 0, 0, -1163295, -2723322, 0, -599514, 0], [111199655, 0, 0, -501250, -123616, 0, 247381, 0], [0, 4463924, -987690, 0, 0, -184182, 0, 49950], [0, -8799038, 1025602, 0, 0, -97403, 0, -33609], [0, 5373990, -581031, 0, 0, 138039, 0, -45699], [14773502, 0, 0, -632364, -2232200, 0, -11801, 0], [0, 13252224, -208614, 0, 0, 100432, 0, -26800], [53799738, 0, 0, -186156, -7221896, 0, -506413, 0], [0, 19175418, 2502394, 0, 0, -139751, 0, -28173], [0, 7671936, -648774, 0, 0, -296672, 0, 93376], [107872596, 0, 0, 365138, -1830900, 0, -1834, 0], [-125952349, 0, 0, 631488, 4835656, 0, -511388, 0], [23020783, 0, 0, 1428929, -3642098, 0, -631334, 0], [102123738, 0, 0, -1092236, -2223736, 0, 1366560, 0], [0, -8118546, 1544628, 0, 0, -65269, 0, 1433], [0, 14427636, 1376970, 0, 0, 227014, 0, -43702], [0, -9429020, 5309966, 0, 0, -1098, 0, -78262], [-31261158, 0, 0, -2733784, -1637552, 0, -142101, 0], [102610764, 0, 0, 1609772, 194256, 0, -264179, 0], [-65110218, 0, 0, -1734094, 3486636, 0, 778376, 0], [54898269, 0, 0, -318043, -306698, 0, -966024, 0], [0, 5466952, -7169292, 0, 0, -4464, 0, -92856], [101799717, 0, 0, 266801, 422190, 0, 643040, 0], [71196108, 0, 0, -1128431, 9851666, 0, -780717, 0], [76172044, 0, 0, 265772, -2781296, 0, 1242733, 0], [0, 10974858, -4907985, 0, 0, 110929, 0, 116347], [0, 25078834, -2607441, 0, 0, -56597, 0, 84213], [0, 26479992, -2348042, 0, 0, 115796, 0, 26892], [0, 3153092, -3877869, 0, 0, -135520, 0, -13972], [0, 11242628, 7344462, 0, 0, 143578, 0, -41186], [-303085657, 0, 0, 1442109, -4049946, 0, -812046, 0], [-39856636, 0, 0, 1412012, 3016760, 0, 1338130, 0], [27153260, 0, 0, -4276644, 9465656, 0, -447286, 0], [-32291014, 0, 0, -3299947, 11607770, 0, 942985, 0], [-16684776, 0, 0, 3079817, 10597602, 0, -302521, 0], [-244379536, 0, 0, 3341052, -15882688, 0, 303062, 0], [-114583501, 0, 0, 1836993, 8508366, 0, 1289766, 0], [0, -24259954, -12681242, 0, 0, 209267, 0, 78913], [0, -1279724, -2264694, 0, 0, 137014, 0, 335130], [-93161502, 0, 0, -3907996, -3435776, 0, -2086533, 0], [121327033, 0, 0, -5008156, 131224, 0, -604286, 0], [-69310197, 0, 0, 120884, -3253288, 0, 364492, 0], [0, 12266882, 21175871, 0, 0, -105589, 0, -36027], [0, 19001642, -3217557, 0, 0, 357957, 0, -199585], [0, -29470452, -4197491, 0, 0, 754888, 0, 53388], [8475477, 0, 0, -7252848, 2890168, 0, 1679606, 0], [0, 15143002, -3298203, 0, 0, -584215, 0, 138083], [189770296, 0, 0, 4679792, -10922072, 0, 132361, 0], [-259304404, 0, 0, -432747, -2231230, 0, 3309827, 0], [0, -26935976, -13997103, 0, 0, -54652, 0, -77764], [0, 12311634, -14797899, 0, 0, -39993, 0, 83073], [0, -1111960, -4221120, 0, 0, 87248, 0, -124888], [-325330976, 0, 0, -4160708, 216128, 0, -1285770, 0], [0, 10045200, 14826572, 0, 0, 83648, 0, 123888], [165367003, 0, 0, -5623307, -11632354, 0, -1034730, 0], [0, -35539394, -2561148, 0, 0, 30851, 0, 74657], [0, -15991534, 14848149, 0, 0, 61491, 0, -366499], [297196952, 0, 0, 2356676, 112592, 0, 2353705, 0], [423747779, 0, 0, -4033083, 25052710, 0, -1175954, 0], [0, -17799760, -18929652, 0, 0, 487848, 0, -154344], [0, -45786468, 4869709, 0, 0, 334910, 0, 27450], [0, 27508196, 10543964, 0, 0, -642114, 0, 65074], [-50826949, 0, 0, -8546658, 9649360, 0, 2823961, 0], [491932377, 0, 0, 2233832, -7522440, 0, -2868713, 0], [-93863635, 0, 0, 250200, -313400, 0, 850246, 0], [0, 68886362, 2384121, 0, 0, 552111, 0, -116415], [-515865830, 0, 0, 192910, 19850748, 0, 279420, 0], [0, -29694026, 11343036, 0, 0, -198109, 0, -379399], [-2112340, 0, 0, 124830, 5724548, 0, 4679390, 0], [0, -29811328, 2413902, 0, 0, 679912, 0, 27976], [0, -29733198, -444770, 0, 0, -261911, 0, 60603], [0, -23911292, -4767168, 0, 0, 666282, 0, 136686], [0, -29345794, -6962712, 0, 0, -947273, 0, 127141], [-893106112, 0, 0, -480636, 3246320, 0, -3755455, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_19_b_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_19_7_b_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_7_b_b(:prec:=8)
    chi := MakeCharacter_19_b();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 7));
    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_7_b_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_7_b_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_19_b();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,7,sign)));
    Vf := Kernel([<2,R![71047680, 0, 4242376, 0, 75582, 0, 483, 0, 1]>],Snew);
    return Vf;
end function;