
// Make newform 384.8.d.d in Magma, downloaded from the LMFDB on 20 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_384_d();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_384_d_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_384_8_d_d();".
// 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_384_8_d_d();".
// 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 := [18225, 0, 69129, 0, 50632, 0, 449, 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, 5063679, 0, 6584732, 0, 58684, 0, 131], [2486853, 0, 2829796, 0, 27156, 0, 65, 0], [-8497827, 0, 2496836, 0, 24308, 0, 57, 0], [20876013, 0, 28104132, 0, 249076, 0, 553, 0], [0, -40729437, 0, -36039416, 0, -320092, 0, -713], [0, 540861579, 0, 366814612, 0, 3248924, 0, 7231], [0, 338539158, 0, 455154004, 0, 4049168, 0, 9022]];
    Rf_basisdens := [1, 1626480, 9036, 9036, 4518, 101655, 101655, 101655];
    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_384_d();"
function MakeCharacter_384_d()
    N := 384;
    order := 2;
    char_gens := [127, 133, 257];
    v := [2, 1, 2];
    // 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_384_d_Hecke();"
function MakeCharacter_384_d_Hecke(Kf)
    N := 384;
    order := 2;
    char_gens := [127, 133, 257];
    char_values := [[1, 0, 0, 0, 0, 0, 0, 0], [-1, 0, 0, 0, 0, 0, 0, 0], [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 := 8;
    raw_aps := [[0, 0, 0, 0, 0, 0, 0, 0], [0, 27, 0, 0, 0, 0, 0, 0], [0, 28, 0, 0, 0, 1, 0, 0], [360, 0, 0, 1, 0, 0, 0, 0], [0, -36, 0, 0, 0, -3, -3, 1], [0, 540, 0, 0, 0, -17, -4, -1], [2862, 0, -33, -13, -11, 0, 0, 0], [0, -4068, 0, 0, 0, 39, 3, -5], [25920, 0, -156, -22, -24, 0, 0, 0], [0, 61972, 0, 0, 0, 59, -52, -58], [-2232, 0, -528, 59, 60, 0, 0, 0], [0, 115844, 0, 0, 0, 397, 228, -177], [85882, 0, -941, -313, 73, 0, 0, 0], [0, 205884, 0, 0, 0, 495, -189, -77], [-248400, 0, -720, -194, -288, 0, 0, 0], [0, 443276, 0, 0, 0, -1899, -276, 642], [0, -131364, 0, 0, 0, -3672, 720, -72], [0, 422460, 0, 0, 0, 3571, -332, 1213], [0, 902268, 0, 0, 0, 3444, -84, -2220], [-792000, 0, 4668, -1322, -312, 0, 0, 0], [1115094, 0, 3040, -1112, -700, 0, 0, 0], [156456, 0, 7716, 3815, 1680, 0, 0, 0], [0, 434844, 0, 0, 0, 4323, -357, 4207], [555926, 0, -17742, -1078, 2566, 0, 0, 0], [-1769698, 0, 4306, -4870, 3982, 0, 0, 0], [0, 5842044, 0, 0, 0, -12427, 328, -4418], [-3980808, 0, 18372, 4427, -6492, 0, 0, 0], [0, 8065836, 0, 0, 0, -20346, -5226, -2402], [0, -4914068, 0, 0, 0, 10275, -2652, -6585], [-4492878, 0, -27930, -11746, -8582, 0, 0, 0], [-16785288, 0, -72120, 3181, 7356, 0, 0, 0], [0, 6753276, 0, 0, 0, 12372, -1308, 16068], [780890, 0, -66183, 18677, -2933, 0, 0, 0], [0, 14964156, 0, 0, 0, 110436, 5964, 16100], [0, -9745588, 0, 0, 0, -101835, 6304, 15328], [-15624792, 0, -46476, -24663, -9036, 0, 0, 0], [0, -38617316, 0, 0, 0, 18563, 23796, 20097], [0, 24420204, 0, 0, 0, -176019, -6279, 2393], [-14200848, 0, -8556, 10968, -23016, 0, 0, 0], [0, -4049212, 0, 0, 0, 33891, 17884, -60356], [0, 63963756, 0, 0, 0, -191532, 1500, 41236], [0, 35215796, 0, 0, 0, 66285, -26028, 9657], [-111630240, 0, -4968, 12076, -11736, 0, 0, 0], [34894126, 0, 202744, 4256, -16340, 0, 0, 0], [0, 30995468, 0, 0, 0, -23595, -28508, -44378], [-94130568, 0, 71076, -13141, 70404, 0, 0, 0], [0, 105864876, 0, 0, 0, -98256, 36168, -3776], [-153565416, 0, -394884, -46171, -53928, 0, 0, 0], [0, 53714556, 0, 0, 0, 93021, 40677, 37969], [0, 21928836, 0, 0, 0, -426535, 70228, -64343], [88236870, 0, 391834, 43170, -35322, 0, 0, 0], [-225383328, 0, 259176, 43248, 62592, 0, 0, 0], [62690366, 0, 396270, 100270, 111974, 0, 0, 0], [0, 110881836, 0, 0, 0, -182559, -83775, 57717], [4153218, 0, 271016, -3864, 3720, 0, 0, 0], [122804496, 0, -968364, -35300, 46728, 0, 0, 0], [0, 138261220, 0, 0, 0, 363259, -34704, -116190], [-321276168, 0, 702372, 135309, -53544, 0, 0, 0], [0, -69373116, 0, 0, 0, -632495, -3772, 55901], [-166150474, 0, 922768, 152352, 18360, 0, 0, 0], [0, 124813260, 0, 0, 0, 42708, 231780, -327164], [0, -287287604, 0, 0, 0, -772067, -173676, -104718], [0, -43700292, 0, 0, 0, 540708, 219804, -207036], [410835024, 0, 890892, -133184, -13320, 0, 0, 0], [-21305158, 0, -520896, -57768, -242292, 0, 0, 0], [0, -74312812, 0, 0, 0, 375527, 154256, -171082], [0, -17306964, 0, 0, 0, -1052778, -464106, -108338], [-54337502, 0, 1033928, 275776, 409508, 0, 0, 0], [0, -612604116, 0, 0, 0, -557439, 281577, 261], [0, 152052620, 0, 0, 0, -672817, 228988, -149519], [-88223358, 0, 706070, 319342, -368422, 0, 0, 0], [1128330432, 0, 177108, 424806, 69024, 0, 0, 0], [-293266584, 0, 1267920, -100533, 607572, 0, 0, 0], [0, 437237972, 0, 0, 0, -1440463, -151124, 342199], [0, -457149348, 0, 0, 0, 1743021, -14895, 166825], [-4153248, 0, -2133552, 242252, -232800, 0, 0, 0], [0, -269243060, 0, 0, 0, -559551, -68100, 384132], [0, 273537212, 0, 0, 0, 594267, -421348, 857069], [53687726, 0, -3291787, 672209, -92057, 0, 0, 0], [127710538, 0, 3358210, -368502, 249774, 0, 0, 0], [0, 76005036, 0, 0, 0, 1542357, 88893, -1268887], [0, 1703100996, 0, 0, 0, -150455, 193724, 92261], [-160910064, 0, -1409592, 636978, 1704, 0, 0, 0], [1274110382, 0, -428724, -219348, -585108, 0, 0, 0], [1691163000, 0, -1676796, 279207, 881340, 0, 0, 0], [0, -415083204, 0, 0, 0, 3776097, -892743, 1113093], [-429808674, 0, -2287085, -958729, 1298689, 0, 0, 0], [2551454234, 0, -57370, -19746, 523098, 0, 0, 0], [0, -1063331564, 0, 0, 0, -2870233, 1761556, 47476], [-634915080, 0, 2042304, -1254271, -1563108, 0, 0, 0], [0, -1514034612, 0, 0, 0, 389121, -606423, 193029], [-1178363376, 0, -1487592, -1180850, 806400, 0, 0, 0], [2812998024, 0, -3851712, -1198459, -139392, 0, 0, 0], [0, -1220994756, 0, 0, 0, -5887086, 93738, -2437302], [0, -263582100, 0, 0, 0, 6129948, 2173836, -768980], [1319707296, 0, -630948, -2135658, 720048, 0, 0, 0], [0, 160374596, 0, 0, 0, 3368863, -35644, -2809198], [704827898, 0, -3700681, 1799275, 846173, 0, 0, 0], [0, -522602100, 0, 0, 0, -8638623, -1095003, 879725], [0, 604094316, 0, 0, 0, -7873117, 601732, 1316527], [0, 478068156, 0, 0, 0, -3248841, -1570197, -2227365], [0, -733132092, 0, 0, 0, 6333263, -2308128, 2879436], [0, 2264776812, 0, 0, 0, 6462651, -1222341, 1196055], [-4683951638, 0, 3145235, -1551193, -335591, 0, 0, 0], [0, 2831332716, 0, 0, 0, 152838, 1379934, -1504754], [2756065234, 0, -815792, 3167672, 3213124, 0, 0, 0], [0, 261582444, 0, 0, 0, 4387050, 1194786, 1158850], [-2859555694, 0, 11489166, 2126246, -667406, 0, 0, 0], [-2815742880, 0, -7020996, -1572378, -2706384, 0, 0, 0], [447158982, 0, -14807548, -323540, 3429608, 0, 0, 0], [-191894472, 0, 6090624, 1554173, -2000700, 0, 0, 0], [0, 3204087444, 0, 0, 0, 7474089, 17220, -1016457], [-2020718202, 0, 4196564, -3104748, -101052, 0, 0, 0], [0, 1027868076, 0, 0, 0, 9270060, -1508484, 373244], [-1567562328, 0, -13187208, 2163253, -423312, 0, 0, 0], [-178679810, 0, 11736495, 1936915, -1118611, 0, 0, 0], [0, 3758542524, 0, 0, 0, 7793007, 1124835, -73293], [-2524821984, 0, -5413260, 4084362, 2290080, 0, 0, 0], [0, 2048158900, 0, 0, 0, -11400465, -965892, 1157352], [0, -253551060, 0, 0, 0, -354150, 2022066, 4039794], [0, 5132845892, 0, 0, 0, -2762219, -2712468, 4082487], [6381846174, 0, 4342432, 378896, -3895400, 0, 0, 0], [0, -5250734580, 0, 0, 0, 8993701, -2205832, -1923292], [0, 2174129388, 0, 0, 0, 19531887, -2085177, -92117], [0, 4546861164, 0, 0, 0, -4597731, -2330631, 4590505], [0, 6037853988, 0, 0, 0, 18984099, 2350256, 1945142], [0, 7054849684, 0, 0, 0, -10408635, -1867860, 1273653], [793847952, 0, 9481200, 1693722, -5154288, 0, 0, 0], [-7008113016, 0, -15295668, -1044259, -4300068, 0, 0, 0], [0, 356964380, 0, 0, 0, -2444793, -265260, 15875871], [0, 3972427308, 0, 0, 0, -8859222, 3532914, 1277858], [-2099143152, 0, 1189812, 16402052, -293016, 0, 0, 0], [-1179070200, 0, -22536924, -3910285, 3755472, 0, 0, 0], [0, 5553382004, 0, 0, 0, 8903797, 8112644, -1497643], [2405621898, 0, 12443017, 3810933, -3244941, 0, 0, 0], [3956401198, 0, 19560324, -5702052, 1914240, 0, 0, 0], [0, -10774978980, 0, 0, 0, -7008955, 6832920, 6122658], [0, -7050498804, 0, 0, 0, -12825519, -2819355, 7599933], [0, 448589844, 0, 0, 0, 7108339, -3281688, 13346460], [-5231962438, 0, 21481265, -6665683, -6440573, 0, 0, 0], [0, -8561932884, 0, 0, 0, 10218519, 4474323, 2977963], [0, -4859387572, 0, 0, 0, -17716111, -9911760, 1433874], [-6640331256, 0, -10134288, 1696537, 1930392, 0, 0, 0], [0, -1510990740, 0, 0, 0, -9975426, 4100142, 7083574], [0, -2912060564, 0, 0, 0, -1621581, -4337868, -10071417], [-9711344736, 0, 10240092, -1826382, -7536600, 0, 0, 0], [0, 4493866676, 0, 0, 0, -40578127, 3362236, 7188259], [-6293826934, 0, -29528461, -5571289, -516695, 0, 0, 0], [0, 8653872636, 0, 0, 0, -19504275, -14564679, -6368551], [12322927008, 0, -8823960, -7260308, -6055992, 0, 0, 0], [0, -13852516612, 0, 0, 0, 29187339, -3434548, -4655251], [2998810450, 0, 8037924, 10475316, -3992868, 0, 0, 0], [0, -7408908900, 0, 0, 0, 38122149, -2819103, -10389295], [-5465769552, 0, 19971468, -1238076, -12875256, 0, 0, 0], [0, -9421799076, 0, 0, 0, 43396233, 3583221, -15911963], [14034493152, 0, 35377488, -11391816, 2271384, 0, 0, 0], [-1627667640, 0, -41816784, 14343105, 11552952, 0, 0, 0], [-9458164162, 0, 30650857, 14846293, 10161491, 0, 0, 0], [-16343506074, 0, 26034920, 3331144, 5834552, 0, 0, 0], [0, 12893544276, 0, 0, 0, -1025809, 10736220, 5114820], [0, -15893486532, 0, 0, 0, 17787804, -2056476, 16235388], [12256339274, 0, -149673, 20227211, 12891901, 0, 0, 0], [8408390616, 0, 20163168, 14486139, 11804904, 0, 0, 0], [0, -26364750804, 0, 0, 0, 6674607, -6264585, 9907595], [12970882478, 0, -17908063, 5135533, -18651781, 0, 0, 0], [6883899120, 0, -43353684, -22289692, -322920, 0, 0, 0], [24328650024, 0, -32170380, 401275, -9239448, 0, 0, 0], [0, 2037710948, 0, 0, 0, -33101099, 7334940, -8993949]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_384_d_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_384_8_d_d();".
// 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_384_8_d_d(:prec:=8)
    chi := MakeCharacter_384_d();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 8));
    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_384_8_d_d();".
// 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_384_8_d_d( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_384_d();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,8,sign)));
    Vf := Kernel([<5,R![2922622746624000000, 0, 791786461593600, 0, 41596678144, 0, 414848, 0, 1]>,<7,R![1275801663744, 1624601088, -1814176, -1440, 1]>],Snew);
    return Vf;
end function;