
// Make newform 384.10.d.b in Magma, downloaded from the LMFDB on 25 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_10_d_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_384_10_d_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 := [852972309225, 0, 45928424926, 0, 45211107, 0, 13062, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0, 0], [-43229725983072, 0, 88099997114, 0, 51851374, 0, 4766, 0], [-1771419698208576, 0, 1426285970446, 0, 1579828010, 0, 169786, 0], [1439961094183104, 0, 5124570485866, 0, 2241395438, 0, 199366, 0], [0, 1137344409469551, 0, 1264029013547, 0, 372522607, 0, 28496], [0, -22780987632578534232, 0, -29157793972297394, 0, -9758638510954, 0, -797877302], [0, -96437550563928427332, 0, -70850434762666054, 0, -15512580206174, 0, -1012635742], [0, 18573275336880625944, 0, 21095692147663558, 0, 7049643741998, 0, 575969794]];
    Rf_basisdens := [1, 34840779813, 243885458691, 243885458691, 4843958573246310, 75081357885317805, 75081357885317805, 10725908269331115];
    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 := 10;
    raw_aps := [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, -81, 0, 0, 0], [0, 0, 0, 0, 140, -1, 0, 0], [1704, 2, 0, -1, 0, 0, 0, 0], [0, 0, 0, 0, -9588, -5, -8, -5], [0, 0, 0, 0, 35820, -5, -15, 4], [1038, 99, -7, 60, 0, 0, 0, 0], [0, 0, 0, 0, 58860, 33, -100, 61], [576576, 24, -56, 110, 0, 0, 0, 0], [0, 0, 0, 0, -653500, -167, 366, -652], [937416, -1138, 172, -95, 0, 0, 0, 0], [0, 0, 0, 0, 3851156, 5173, 513, 828], [-5439862, -10817, -235, 1860, 0, 0, 0, 0], [0, 0, 0, 0, 447468, -7247, -1564, 1509], [-6172752, -16820, -672, -3950, 0, 0, 0, 0], [0, 0, 0, 0, -2656004, -897, 15570, 4020], [0, 0, 0, 0, 19616076, -30648, -7944, -5328], [0, 0, 0, 0, -5818932, -7253, -9309, -628], [0, 0, 0, 0, 53533068, -117668, -5112, 7700], [92718912, -38296, -24920, -1406, 0, 0, 0, 0], [-188487930, -33352, 21044, -8796, 0, 0, 0, 0], [-126046680, -120814, 2512, 76033, 0, 0, 0, 0], [0, 0, 0, 0, 31850604, -195603, -37712, -20443], [-167129306, 98298, -31186, 106728, 0, 0, 0, 0], [-113102242, 91610, -2234, -135600, 0, 0, 0, 0], [0, 0, 0, 0, -631943700, -237905, -43422, -23816], [-99048264, 212786, -43244, 98305, 0, 0, 0, 0], [0, 0, 0, 0, -163176804, 1244202, -45824, -16582], [0, 0, 0, 0, -223280516, 5895, 340497, 39132], [-1076631150, 850974, 16130, -109776, 0, 0, 0, 0], [-1073484552, 100426, 173228, 524159, 0, 0, 0, 0], [0, 0, 0, 0, 1332463116, -183220, 588816, 220], [-496484822, 766269, 161231, 199356, 0, 0, 0, 0], [0, 0, 0, 0, 1478653164, 2010540, -952808, 165716], [0, 0, 0, 0, -1428653252, -3835461, 181056, -92576], [-3484792728, -1632930, -313308, -1027581, 0, 0, 0, 0], [0, 0, 0, 0, 1656632236, 1010963, -868689, -578868], [0, 0, 0, 0, -754440132, -5905013, -670724, -301289], [-2666160528, -3634108, 1005752, 692976, 0, 0, 0, 0], [0, 0, 0, 0, 7248811636, -8527227, 176304, -723548], [0, 0, 0, 0, 10971938940, -61412, 943864, 934180], [0, 0, 0, 0, -2404630588, -1337151, -410049, 934668], [-9802418592, -6073568, -647736, 201772, 0, 0, 0, 0], [8005651630, -6481552, -1784036, -2039100, 0, 0, 0, 0], [0, 0, 0, 0, -1681421252, -3916425, -207978, 815356], [3906758712, 931154, -2636684, 1471585, 0, 0, 0, 0], [0, 0, 0, 0, 26487771708, 12114080, -762232, 35384], [-36909009768, 1653718, 1907640, -1738469, 0, 0, 0, 0], [0, 0, 0, 0, 16630392588, 25328611, 2273296, -2721173], [0, 0, 0, 0, -9268154220, 4515941, 3009183, -4712884], [-14559776586, -10335278, 2845326, 6811920, 0, 0, 0, 0], [-48287101344, 21437864, -2865280, -38640, 0, 0, 0, 0], [-8969013922, -18468930, 5471006, 1200516, 0, 0, 0, 0], [0, 0, 0, 0, 39404176860, -19179673, -12272136, -2897081], [14076734850, 29667560, -6722136, -414288, 0, 0, 0, 0], [-43224817008, 11917036, -7489176, 4036348, 0, 0, 0, 0], [0, 0, 0, 0, 8521944212, 17070425, 8639334, -1031280], [-45888844296, 55054222, -3188552, -4030749, 0, 0, 0, 0], [0, 0, 0, 0, -45856214508, 4480309, -4992837, 9411868], [-35515386938, -35757440, 297048, -17850744, 0, 0, 0, 0], [0, 0, 0, 0, 102413769084, 19255212, -315184, 2630716], [0, 0, 0, 0, -33222686596, 4983287, 12286314, 2975244], [0, 0, 0, 0, 118871674764, -70978580, -6340152, -8363164], [-43303949616, -3416468, -8836968, 15915304, 0, 0, 0, 0], [-26046087574, 122053896, 4453788, -4643316, 0, 0, 0, 0], [0, 0, 0, 0, -103359430844, -3828683, -35986494, 864368], [0, 0, 0, 0, 118655412636, -13499782, 21561104, -11594758], [-31335587390, -24505424, -17387980, 46956300, 0, 0, 0, 0], [0, 0, 0, 0, 140677800540, 13584151, 55821072, -13214017], [0, 0, 0, 0, -109578148516, -127683625, -19039161, 2764484], [-97306990014, -55306738, 17150146, 49240704, 0, 0, 0, 0], [-94186989120, -123369296, 36111136, -53358150, 0, 0, 0, 0], [-433436018328, 84610782, -1780764, 2370633, 0, 0, 0, 0], [0, 0, 0, 0, 121860732260, -29910175, -27145263, -11269900], [0, 0, 0, 0, 178337726412, 115470643, -80078620, 17082231], [-297863314848, -88860120, -31055840, 59195444, 0, 0, 0, 0], [0, 0, 0, 0, 280950903932, 217282479, 35284392, -10567068], [0, 0, 0, 0, 31542096140, 35369955, 79633227, 20593636], [225894605710, 12719009, -45675373, -42739500, 0, 0, 0, 0], [21001268026, 313434074, -2307786, -14686560, 0, 0, 0, 0], [0, 0, 0, 0, -145713749124, 8051947, 13486832, -80473005], [0, 0, 0, 0, 269106832212, -69097043, -9885957, 26037796], [-318047714544, 556855228, -26962232, -66293034, 0, 0, 0, 0], [269747281742, -49264884, -11340708, -47709288, 0, 0, 0, 0], [210512940216, 187871674, 41619724, -21526179, 0, 0, 0, 0], [0, 0, 0, 0, -122926204884, 46775863, 129605472, -72951217], [186139748958, 317671159, 58349285, -54704676, 0, 0, 0, 0], [-186689152918, 366949294, -76578798, 100309392, 0, 0, 0, 0], [0, 0, 0, 0, 332239838468, -351722303, -119304240, 19656940], [-394876186632, 570736746, -11636788, 57611899, 0, 0, 0, 0], [0, 0, 0, 0, -487419780516, 111592175, -189213744, 62716567], [-520356369648, -713021132, 2234880, -194450174, 0, 0, 0, 0], [1439482409160, -292359542, -75326592, -57986981, 0, 0, 0, 0], [0, 0, 0, 0, -161670380052, -544538450, -30310536, -21106810], [0, 0, 0, 0, -599647392900, 178388484, -26432848, -177420044], [1161137959584, -193171880, 97417456, -81514470, 0, 0, 0, 0], [0, 0, 0, 0, 298046356276, 35964461, 168553770, -9492100], [-234300962870, 572058179, -254379527, 86706588, 0, 0, 0, 0], [0, 0, 0, 0, -301871030532, -675397201, 124583332, 26684499], [0, 0, 0, 0, -376758261828, -54484153, 389324121, 76664636], [0, 0, 0, 0, -868775720628, 388269457, 548345700, 148529093], [0, 0, 0, 0, 324228230772, -617834111, 54584100, 60241440], [0, 0, 0, 0, -2126605180548, -538296155, 212386440, 57271589], [-52990209766, 1243362383, 154301045, -177615084, 0, 0, 0, 0], [0, 0, 0, 0, -1693969954788, -54208262, -514863016, -157968750], [-2420078990510, -512220472, -46549868, -362249484, 0, 0, 0, 0], [0, 0, 0, 0, -1811104865700, 680881430, 378294040, -48601458], [1165684219954, -427837722, 240361370, 605898384, 0, 0, 0, 0], [3757431188064, 829286744, -9883792, 13581450, 0, 0, 0, 0], [512243672022, 375511036, -213375352, -342048756, 0, 0, 0, 0], [-489608002632, -65242478, -199743660, -627218009, 0, 0, 0, 0], [0, 0, 0, 0, -3113887853340, -715672695, -727738983, -161498148], [-383081629194, 949174484, 335190132, -452636424, 0, 0, 0, 0], [0, 0, 0, 0, -734140847844, 2007508692, 135565840, 378095780], [3835545741672, 821859010, 18118064, 684276683, 0, 0, 0, 0], [1317256220414, -338408973, -389643071, -799663740, 0, 0, 0, 0], [0, 0, 0, 0, -627365451828, -552858119, -215592540, 21769325], [4186609495584, 142747672, 102855712, -181394346, 0, 0, 0, 0], [0, 0, 0, 0, 431459157284, -2437605375, -598335948, -354004476], [0, 0, 0, 0, -257864965956, 141305910, 493043832, 23139534], [0, 0, 0, 0, -2428996794604, 320287837, 217579185, 499257012], [-3116325920418, 3748690928, 118551160, -32886024, 0, 0, 0, 0], [0, 0, 0, 0, 3464194359228, -560212285, 588869988, 291859016], [0, 0, 0, 0, -3426819282084, 174168937, 262105264, -545373695], [0, 0, 0, 0, 519656252028, -2186671925, -726986452, 179641191], [0, 0, 0, 0, 2504499084948, 2632440729, 1738567266, -225157552], [0, 0, 0, 0, -2792389555868, -1350576111, 855038907, -147278028], [-1556776482672, -915562268, -538951856, -68013978, 0, 0, 0, 0], [3150731937864, -4192946098, 736699180, 1720979143, 0, 0, 0, 0], [0, 0, 0, 0, -4953209292628, -2447165949, -51156423, -782967828], [0, 0, 0, 0, -1346776649988, -3615081754, 962026696, 274687278], [2044262936976, -3937483556, -164264248, 138409652, 0, 0, 0, 0], [-4778023205112, -4421458006, -142162928, -1672808075, 0, 0, 0, 0], [0, 0, 0, 0, -4368969070972, -3083903, 853030659, -294251300], [7136224944186, -1550673011, -79721049, 1194580404, 0, 0, 0, 0], [-4820159053010, 3337946604, -1139138496, 893172420, 0, 0, 0, 0], [0, 0, 0, 0, 3485028426444, 2620053175, -2191598370, -138550104], [0, 0, 0, 0, -1565419356132, -1193701369, -2029717452, -1052013605], [0, 0, 0, 0, -3092107344828, 926899805, 31631580, 491687064], [-725389950518, -639529387, -179203129, 1956307308, 0, 0, 0, 0], [0, 0, 0, 0, 6273331994652, -1145246471, -364943908, 871602261], [0, 0, 0, 0, 5579586382780, -2740953365, 224423334, -545764272], [-2421778660152, -229770190, -826070856, -2270570785, 0, 0, 0, 0], [0, 0, 0, 0, 5469870549276, -3840977646, 1073032864, -5839678], [0, 0, 0, 0, -8685017422532, 2623663239, 380487537, 1108082700], [-10601382098016, 2168629632, 342540936, 1096708806, 0, 0, 0, 0], [0, 0, 0, 0, -9771869091772, -7972859287, -3280509435, 1378816484], [10419561210874, 281409839, -107253403, -2858491452, 0, 0, 0, 0], [0, 0, 0, 0, 10971155182956, -432300797, -415799780, -1320042065], [-12558374034528, 8947724656, -203451672, -1166458292, 0, 0, 0, 0], [0, 0, 0, 0, -16649802629428, 3494259123, 627047067, -1252774220], [8752922246450, 3129782388, -2214878964, 323683488, 0, 0, 0, 0], [0, 0, 0, 0, 11188940385516, 7018605763, -92751284, -728183489], [-8124192129744, 76534932, 896036712, -416281836, 0, 0, 0, 0], [0, 0, 0, 0, 2600140025100, -931486729, 4316346332, -618745981], [47012469984, -1992469968, -356734344, 943195152, 0, 0, 0, 0], [-13836546855672, -2692276414, -1928074408, 1372238967, 0, 0, 0, 0], [-4743218138882, -5333423435, 2202346591, 5776547988, 0, 0, 0, 0], [-16341373736874, 2408717704, -1354689832, 3784337376, 0, 0, 0, 0], [0, 0, 0, 0, 4641427384260, -3393417911, 1664706312, 506060580], [0, 0, 0, 0, 13821784897548, -726365740, -2002236936, 1233666844], [11717968491130, 8815786995, 2035027913, -1849516644, 0, 0, 0, 0], [-2540993260392, 9685688742, -3114421176, 1169587965, 0, 0, 0, 0], [0, 0, 0, 0, 15801349439004, 2068483753, -78751360, -534426447], [12627444326158, 8238755069, 1124583031, -652528140, 0, 0, 0, 0], [-14494331141520, -5976496108, 802916280, -8261837788, 0, 0, 0, 0], [-7514023983192, -5037168870, 4352504584, -4963644667, 0, 0, 0, 0], [0, 0, 0, 0, -18283798045708, 7882340821, 4953660597, 1085432004]];
    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_10_d_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_384_10_d_b(:prec:=8)
    chi := MakeCharacter_384_d();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 10));
    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_10_d_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_384_10_d_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_384_d();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,10,sign)));
    Vf := Kernel([<5,R![6903383511575235133440000, 0, 37796298115527475200, 0, 33495402213376, 0, 10189952, 0, 1]>,<7,R![-139519152670464, 267125408256, -38951584, -6816, 1]>],Snew);
    return Vf;
end function;