
// Make newform 38.6.c.b in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_38_c();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_38_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_38_6_c_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_38_6_c_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 := [211527936, -19430784, 7340704, 568528, 128708, 3436, 386, -2, 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], [21387024882252864, 2817558974024672, 696497843562920, 58739407749004, 2734091869688, 128794858006, 3142267604, 390471533], [136296431422848, -47812199501856, 80490049760, -783009643316, -13997685940, -2297742050, 36183422, -6473945], [2039876809757088, -8478177668352, 233201485664, -2506296549812, -40555089316, -6657181370, 22066664, -18756773], [-797723005586315328, -185235881908387744, -25978945468588840, -2190944142716108, -120891129109120, -4803969780662, -117204668308, -14831978953], [-1269287639998959744, 277537020774601760, -63493741971665976, 1829783642565108, -330296195845968, 26507480732490, -1347014053248, 35647275847], [1908794478180000960, -229139449183464992, 62162514196183800, 5242499028273060, 561804417935112, 11494956177090, 280447752060, 71425529135]];
    Rf_basisdens := [1, 1, 27200877355486656, 44885936230176, 22442968115088, 13600438677743328, 9066959118495552, 9066959118495552];
    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_38_c();"
function MakeCharacter_38_c()
    N := 38;
    order := 3;
    char_gens := [21];
    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_38_c_Hecke();"
function MakeCharacter_38_c_Hecke(Kf)
    N := 38;
    order := 3;
    char_gens := [21];
    char_values := [[0, 0, -1, 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 := 6;
    raw_aps := [[-4, 0, 4, 0, 0, 0, 0, 0], [-3, 0, 3, -1, 0, 0, 0, 0], [-9, 0, 9, 0, 1, 1, 0, 0], [9, 1, 0, 1, 0, 0, -1, -1], [8, 20, 0, 20, 3, 0, -2, -2], [0, -25, -156, 0, 0, -1, 0, -5], [132, 0, -132, -3, 15, 15, 3, 0], [23, 21, 44, -41, 17, 3, -10, -6], [0, -78, -12, 0, 0, -19, 0, 21], [0, 330, -1593, 0, 0, 43, 0, 0], [-221, -139, 0, -139, -6, 0, -11, -11], [-3035, -307, 0, -307, 114, 0, 25, 25], [-659, 0, 659, -422, -164, -164, 32, 0], [423, 0, -423, 1187, 95, 95, -20, 0], [0, -12, -11436, 0, 0, -241, 0, -27], [0, -121, 11474, 0, 0, 91, 0, -23], [-21017, 0, 21017, 31, -256, -256, 2, 0], [0, 1772, -4389, 0, 0, 311, 0, 16], [0, 939, -5231, 0, 0, 112, 0, 54], [-13293, 0, 13293, -51, 13, 13, 300, 0], [-9347, 0, 9347, -1848, -274, -274, -312, 0], [-12109, 0, 12109, -2867, -193, -193, -304, 0], [4764, 3570, 0, 3570, 21, 0, -390, -390], [0, 2117, -35524, 0, 0, 881, 0, 91], [-71281, 0, 71281, -3632, 486, 486, -214, 0], [0, 1940, 5525, 0, 0, -1805, 0, 10], [4328, -2820, 0, -2820, 1882, 0, -444, -444], [19526, 3326, 0, 3326, -84, 0, -458, -458], [-13834, 0, 13834, 3541, 415, 415, -583, 0], [84111, -3465, 0, -3465, -547, 0, -483, -483], [0, 1379, -174291, 0, 0, 765, 0, -68], [-63237, 0, 63237, -8067, -1800, -1800, 114, 0], [0, 1626, -95127, 0, 0, 1582, 0, 1368], [0, 11865, -31223, 0, 0, 694, 0, 798], [125759, 0, -125759, -8410, 151, 151, 1144, 0], [237089, 3657, 0, 3657, 1242, 0, 1827, 1827], [-122624, 0, 122624, 7149, -2633, -2633, -165, 0], [-133714, 9246, 0, 9246, -2595, 0, -588, -588], [0, 14663, 361319, 0, 0, -1789, 0, 490], [-433498, 0, 433498, 5735, 2425, 2425, 697, 0], [135562, -31298, 0, -31298, -2053, 0, 308, 308], [0, -9424, -52689, 0, 0, -2219, 0, -3752], [-56780, 19756, 0, 19756, -5064, 0, 140, 140], [234962, 0, -234962, 28885, -1445, -1445, -4399, 0], [663033, -13899, 0, -13899, -2494, 0, -387, -387], [0, 4227, -569897, 0, 0, -663, 0, -66], [-584657, 0, 584657, 24813, -3547, -3547, 1596, 0], [728532, 0, -728532, -2188, 361, 361, 3199, 0], [-342076, -15772, 0, -15772, -5743, 0, 1942, 1942], [-432010, 1062, 0, 1062, 2130, 0, 168, 168], [-307005, 0, 307005, -30048, 438, 438, -4266, 0], [-368338, -30784, 0, -30784, -10400, 0, 1918, 1918], [0, -436, 226671, 0, 0, -7196, 0, -6362], [0, 26397, 395097, 0, 0, -8926, 0, 5166], [0, 23704, -24947, 0, 0, 17022, 0, 1400], [514812, 0, -514812, -17640, -13017, -13017, -5157, 0], [-540058, 0, 540058, -18415, 21871, 21871, 5137, 0], [-856006, 0, 856006, 50206, -8745, -8745, 3989, 0], [59421, 19261, 0, 19261, 15124, 0, -4387, -4387], [0, -38264, 213613, 0, 0, -13066, 0, -6712], [-556975, 0, 556975, -1949, -11756, -11756, 9116, 0], [-28281, 31419, 0, 31419, 14280, 0, 8883, 8883], [176405, 0, -176405, -4187, -14594, -14594, -736, 0], [913561, 131395, 0, 131395, 9966, 0, 1295, 1295], [0, -29698, -992331, 0, 0, 12752, 0, 11392], [0, -23897, -77012, 0, 0, 18463, 0, -637], [-981938, 13742, 0, 13742, -8249, 0, -11912, -11912], [580353, 0, -580353, -154126, 21644, 21644, -7652, 0], [-204419, 0, 204419, -72527, 44272, 44272, 3716, 0], [-633582, 59314, 0, 59314, -14018, 0, -772, -772], [415713, 52209, 0, 52209, -1419, 0, -5061, -5061], [-124026, 0, 124026, 38862, 34809, 34809, -6555, 0], [0, -139276, -1112124, 0, 0, 13933, 0, -20399], [-36536, 45890, 0, 45890, -14378, 0, 6754, 6754], [-599500, 73548, 0, 73548, 28630, 0, -14652, -14652], [-1848904, 0, 1848904, 112742, -35217, -35217, -5213, 0], [0, 40133, -655780, 0, 0, -44587, 0, -2741], [2048695, 0, -2048695, -58872, 18891, 18891, -7788, 0], [130401, 0, -130401, -151938, 20630, 20630, 3600, 0], [0, -12360, 1760473, 0, 0, 64400, 0, 14472], [1307612, 42116, 0, 42116, -62168, 0, -4880, -4880], [-928995, 0, 928995, 230558, 1099, 1099, -2570, 0], [0, 90119, -1156243, 0, 0, -1879, 0, -8420], [0, 240143, 139368, 0, 0, 40409, 0, 27163], [2590440, 0, -2590440, 140522, -42023, -42023, -15233, 0], [0, 79637, 2694413, 0, 0, -4506, 0, 23338], [1876969, 62845, 0, 62845, -16155, 0, -5365, -5365], [1433347, -394579, 0, -394579, 32245, 0, 14245, 14245], [-567140, 0, 567140, 139639, -35991, -35991, 13991, 0], [-2285038, -41724, 0, -41724, 26306, 0, 17622, 17622], [4488404, -50836, 0, -50836, -18019, 0, 3118, 3118], [0, 43271, 2906819, 0, 0, -35769, 0, -3794], [221783, -101133, 0, -101133, 2450, 0, -22347, -22347], [1654285, 0, -1654285, 153499, -27561, -27561, 10322, 0], [146561, 0, -146561, -280415, -16902, -16902, -4228, 0], [0, -237140, -1210082, 0, 0, 9085, 0, 11531], [0, 342477, 12042, 0, 0, -63687, 0, -14967], [-2734055, 14875, 0, 14875, 108343, 0, -33973, -33973], [0, -168991, 3140127, 0, 0, 15647, 0, 28822], [0, -63963, 2049322, 0, 0, 30117, 0, -25839], [0, -208403, -1476931, 0, 0, -15165, 0, -42556], [0, 168569, 6210812, 0, 0, -55611, 0, -67997], [2289764, -536728, 0, -536728, 31993, 0, 9502, 9502], [-3552294, -248754, 0, -248754, -66926, 0, 11784, 11784], [-1147890, 652810, 0, 652810, -39421, 0, 15272, 15272], [-1569069, 501007, 0, 501007, -27391, 0, -44647, -44647], [-1067579, 0, 1067579, -529733, -23221, -23221, 4514, 0], [0, -577088, 3930271, 0, 0, -6406, 0, -15430], [0, 73572, -1097646, 0, 0, 53349, 0, 14127], [-2634159, -223151, 0, -223151, 55687, 0, 49871, 49871], [-3776197, 623895, 0, 623895, -84516, 0, 15141, 15141], [725568, 0, -725568, 547043, 22985, 22985, 31291, 0], [0, 4210, 2261077, 0, 0, -77108, 0, -58192], [3324346, -153394, 0, -153394, -7656, 0, 34786, 34786], [0, 46284, 5212852, 0, 0, 9711, 0, -43227], [3105539, 0, -3105539, 36014, -94976, -94976, -5978, 0], [-1172821, 0, 1172821, -123521, 33552, 33552, 6974, 0], [-5322692, -273056, 0, -273056, 149710, 0, 22088, 22088], [259638, 613218, 0, 613218, 138990, 0, 25776, 25776], [0, 144647, 1289897, 0, 0, -19985, 0, -43724], [0, 122086, -10748977, 0, 0, 18243, 0, -50944], [-2862604, 360012, 0, 360012, 62034, 0, -43074, -43074], [1452052, 908536, 0, 908536, 36612, 0, -60130, -60130], [-4338034, -417520, 0, -417520, 74948, 0, -31094, -31094], [3367280, 441708, 0, 441708, 2440, 0, 34260, 34260], [-5831715, 0, 5831715, -160992, 168793, 168793, -29322, 0], [0, 354200, -2688621, 0, 0, 80145, 0, 94372], [8363189, 0, -8363189, -697567, 22149, 22149, 30286, 0], [-3031791, 0, 3031791, 474305, -120553, -120553, -80834, 0], [-3392529, -861833, 0, -861833, 47238, 0, 63599, 63599], [-8554699, 0, 8554699, 287521, 89660, 89660, 47756, 0], [5464402, 0, -5464402, 298366, -72507, -72507, -54199, 0], [0, -699493, 1153221, 0, 0, 158345, 0, 41980], [-8158458, 0, 8158458, -183781, 9329, 9329, -12455, 0], [-16605673, 499811, 0, 499811, -63653, 0, 48073, 48073], [0, 505123, -1347412, 0, 0, 25833, 0, -71017], [0, -702718, -2725759, 0, 0, 81047, 0, 48394], [-1891522, -299406, 0, -299406, 367931, 0, -8736, -8736], [7059421, 49765, 0, 49765, -160318, 0, 104297, 104297], [-1550693, 1639831, 0, 1639831, 16637, 0, -26383, -26383], [0, -272791, 10574379, 0, 0, -1989, 0, 51514], [0, -986305, -11346904, 0, 0, 94775, 0, -5729], [0, 97039, -19719625, 0, 0, -143819, 0, -25042], [0, -1029377, -10830401, 0, 0, 77454, 0, -119368], [-14692600, -402222, 0, -402222, -111890, 0, -31590, -31590], [10448, 0, -10448, 252308, 338279, 338279, -40841, 0], [-3890006, 0, 3890006, -493653, -13759, -13759, -182787, 0], [-5263773, 0, 5263773, 366126, -292014, -292014, 173994, 0], [0, -832367, -2351017, 0, 0, 103494, 0, -102868], [14145211, -1508303, 0, -1508303, -99094, 0, -4363, -4363], [2831837, 0, -2831837, 813700, 81789, 81789, -103498, 0], [18816123, -218793, 0, -218793, 224823, 0, -21675, -21675], [0, 318095, -5608353, 0, 0, 187882, 0, -106400], [0, 695591, -3137317, 0, 0, -80193, 0, 80134], [-6173813, 0, 6173813, -1915221, -29010, -29010, 67554, 0], [12066901, 61525, 0, 61525, -199090, 0, 33599, 33599], [6579384, -621824, 0, -621824, -53350, 0, -66292, -66292], [-4479273, 0, 4479273, -14406, -166862, -166862, 175902, 0], [0, -1092296, 3110213, 0, 0, 177934, 0, -71824], [0, -88969, -7953898, 0, 0, -317481, 0, 115813], [8173249, 0, -8173249, -616967, 227903, 227903, -175150, 0], [-8576337, 0, 8576337, -31578, -265112, -265112, -30726, 0], [-25259929, 0, 25259929, 1108237, 423865, 423865, -53608, 0], [-21189553, 0, 21189553, -304033, 187346, 187346, -187658, 0], [16561471, 28147, 0, 28147, -579341, 0, 108905, 108905], [-2920269, 0, 2920269, 1842561, 245247, 245247, -2496, 0], [25518107, 0, -25518107, 289465, 182787, 182787, 100472, 0], [0, 558762, -2015831, 0, 0, -2065, 0, 203634]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_38_c_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_38_6_c_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_38_6_c_b(:prec:=8)
    chi := MakeCharacter_38_c();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 6));
    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_38_6_c_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_38_6_c_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_38_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<3,R![232532001, -12107706, 5357626, -180832, 91967, -2752, 506, 14, 1]>],Snew);
    return Vf;
end function;