
// Make newform 400.8.c.u in Magma, downloaded from the LMFDB on 11 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_400_c();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_400_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_400_8_c_u();".
// 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_400_8_c_u();".
// 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 := [16, 0, 1164, 0, 69, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0], [0, 1024, 0, 65, 0, 1], [0, 15872, 0, 925, 0, 13], [-697, 0, 40, 0, 2, 0], [0, 359936, 0, 20055, 0, 279], [15883, 0, 4640, 0, 112, 0]];
    Rf_basisdens := [1, 120, 40, 15, 40, 15];
    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_400_c();"
function MakeCharacter_400_c()
    N := 400;
    order := 2;
    char_gens := [351, 101, 177];
    v := [2, 2, 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_400_c_Hecke();"
function MakeCharacter_400_c_Hecke( : Kf := false)
    N := 400;
    order := 2;
    char_gens := [351, 101, 177];
    char_values := [[1, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0], [-1, 0, 0, 0, 0, 0]];
    assert UnitGenerators(DirichletGroup(N)) eq char_gens;
    values := ConvertToHeckeField(char_values : pass_field := ISA(Type(Kf), Fld), 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]];
    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, -32, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, -543, 2, 0, -1, 0], [931, 0, 0, -133, 0, 1], [0, 1061, -124, 0, -1, 0], [0, 8100, -200, 0, 19, 0], [18694, 0, 0, -315, 0, 18], [0, -18754, 630, 0, 18, 0], [-20819, 0, 0, -2956, 0, 115], [47290, 0, 0, 2630, 0, -98], [0, -68745, -1548, 0, -9, 0], [96977, 0, 0, 8840, 0, 28], [0, 39483, 9740, 0, 89, 0], [0, 224913, 4360, 0, -425, 0], [0, -433030, -9752, 0, -452, 0], [332503, 0, 0, -14584, 0, -443], [1898159, 0, 0, 15604, 0, -37], [0, 1804373, -23355, 0, 207, 0], [-626847, 0, 0, -54144, 0, -729], [0, -3308176, -3440, 0, 127, 0], [1909337, 0, 0, -139702, 0, -2369], [0, 3979439, 66215, 0, -1819, 0], [-7451914, 0, 0, 21080, 0, -953], [0, 704088, 99560, 0, 10070, 0], [-2429815, 0, 0, -117436, 0, -12539], [0, 6030221, -146448, 0, 10827, 0], [0, 10575683, 4147, 0, -503, 0], [-5054489, 0, 0, 84732, 0, 10803], [0, -6059829, -299688, 0, 11316, 0], [0, 11330860, 620798, 0, 1100, 0], [-1973357, 0, 0, -250964, 0, -3127], [0, -16259183, -25688, 0, -8774, 0], [18221637, 0, 0, 84981, 0, -26913], [20996003, 0, 0, 545980, 0, -17107], [-107125, 0, 0, -338438, 0, 3005], [0, 35253044, -68016, 0, 12858, 0], [0, -13174683, -840973, 0, 32879, 0], [0, -32964661, -212408, 0, -24971, 0], [0, -59019104, 641848, 0, -6320, 0], [6134504, 0, 0, -643215, 0, 24744], [19524830, 0, 0, 808968, 0, 12084], [55187488, 0, 0, 171018, 0, -46080], [0, -52177420, -420088, 0, 29621, 0], [0, 116512004, 256320, 0, -40482, 0], [-2029052, 0, 0, 2245460, 0, 17116], [146489807, 0, 0, 2107741, 0, -33019], [0, -183273490, -1676788, 0, 30842, 0], [0, -31209123, -846756, 0, -78057, 0], [154216846, 0, 0, -471688, 0, -88802], [0, -96391082, -1873840, 0, -154384, 0], [52538307, 0, 0, 1641276, 0, 42525], [-15314920, 0, 0, 551232, 0, -169011], [157066156, 0, 0, -1058579, 0, -116428], [0, 45177084, -2832024, 0, -132474, 0], [0, -137005866, 1428846, 0, -116670, 0], [207803438, 0, 0, -1695776, 0, -123334], [134096144, 0, 0, -3171082, 0, 61792], [0, 266535915, -7762916, 0, -96947, 0], [-41688720, 0, 0, 4623272, 0, -241394], [0, -104911848, -6765989, 0, -240032, 0], [0, -236074295, -4100796, 0, -33579, 0], [0, 157277308, 3347703, 0, 295740, 0], [-280740567, 0, 0, -3206458, 0, -376529], [0, -293612436, 2673560, 0, 358046, 0], [0, 133485992, -6969176, 0, 171364, 0], [-224425049, 0, 0, -2815481, 0, 607661], [0, -44259451, -19839432, 0, 542112, 0], [0, 72016867, 7783147, 0, -368447, 0], [-659869697, 0, 0, 2252836, 0, -293629], [0, -260161748, 19676008, 0, -73958, 0], [356407417, 0, 0, 8472874, 0, -688345], [0, -104266164, -12101596, 0, 485324, 0], [0, 503756184, -804104, 0, -155030, 0], [107178358, 0, 0, 40023, 0, -1162278], [0, 598942577, 10037650, 0, -312041, 0], [-820785654, 0, 0, 27753456, 0, 279168], [0, -420097824, -26429344, 0, -693316, 0], [-164228358, 0, 0, -29283144, 0, 766167], [-515618575, 0, 0, 3699216, 0, 279738], [-295802258, 0, 0, -3370031, 0, 1158170], [331152894, 0, 0, 43881096, 0, -182154], [1029172323, 0, 0, 24765734, 0, 1137565], [0, 1279289346, -7035736, 0, -449377, 0], [-203719949, 0, 0, 57763812, 0, -394851], [0, 948087690, -51583377, 0, -664482, 0], [82493132, 0, 0, 19973816, 0, -1175513], [0, 1879066757, 14646336, 0, 899034, 0], [-935085032, 0, 0, 3234376, 0, -199876], [0, 2176359982, 3439556, 0, 1478210, 0], [0, 1570748571, 473108, 0, 1405001, 0], [-240962218, 0, 0, 35132734, 0, 1455530], [0, -2016636952, -65403874, 0, 892400, 0], [-428314111, 0, 0, 3848300, 0, 944995], [-2205716119, 0, 0, -18049188, 0, 1211979], [0, 922210290, 29322612, 0, -1205082, 0], [2000916310, 0, 0, -39726784, 0, 713920], [-1462192247, 0, 0, 68732448, 0, 558012], [0, -2859133577, 22592977, 0, -395747, 0], [1112248956, 0, 0, 30231608, 0, 231532], [0, 573613080, -7036633, 0, -1987312, 0], [0, 746579025, 13120276, 0, 3487435, 0], [0, -1219698221, -25972448, 0, 2344921, 0], [3463042299, 0, 0, 85135232, 0, -2707748], [-5466702433, 0, 0, 18502572, 0, 1922757], [0, 345071025, 135009016, 0, -3041324, 0], [0, 5655549600, -33903519, 0, 353928, 0], [0, -2433835435, -13804568, 0, -2755310, 0], [426031087, 0, 0, -92533118, 0, -4577551], [1100224740, 0, 0, -115215208, 0, -3584069], [0, -4038411672, 90180792, 0, 2833056, 0], [0, 704014174, 104037776, 0, 4470872, 0], [0, -2838756302, -69112192, 0, -2989168, 0], [1541976011, 0, 0, 158373180, 0, -144063], [-534713002, 0, 0, -40588242, 0, -713622], [712914684, 0, 0, 29978040, 0, 1246686], [0, -5756144847, 4040028, 0, -4532805, 0], [0, 1429811850, -60566076, 0, -330066, 0], [0, -5531501003, -56294684, 0, 4135081, 0], [-913119263, 0, 0, -183329489, 0, 4517243], [5301638159, 0, 0, -3329500, 0, -4304999], [0, 1333523278, -165452896, 0, 6433052, 0], [0, 1612963102, -7997288, 0, 5845570, 0], [0, 15552189, 56069985, 0, 897951, 0], [-6931013100, 0, 0, -13361329, 0, 1521292], [2058949251, 0, 0, -65228756, 0, -4759063], [-2415315054, 0, 0, 105879944, 0, -6603110], [7787593235, 0, 0, -93318074, 0, -3010819], [0, -3469542127, -271636572, 0, -791049, 0], [0, 1766493985, -266227612, 0, -485389, 0], [8539370027, 0, 0, 117512804, 0, -812375], [0, -404804718, -49336842, 0, -7468914, 0], [-2884472727, 0, 0, -196246908, 0, 2415015], [0, 1402666508, -211349512, 0, -6090196, 0], [-3438308207, 0, 0, -133689704, 0, 4426652], [890918284, 0, 0, 224889656, 0, 2793283], [0, -515678065, -246485420, 0, 2732521, 0], [0, 13791906073, 35502628, 0, 3414283, 0], [0, -3911154458, 64436864, 0, -13267096, 0], [-1330628352, 0, 0, 171974280, 0, -15015954], [-10292620969, 0, 0, -1721780, 0, 6486413], [-9445243608, 0, 0, 46993400, 0, -17631590], [0, 2271779478, 151274948, 0, 8348186, 0], [0, 8619644696, 163398385, 0, -7496240, 0], [-1574696307, 0, 0, -74033372, 0, -4797361], [9931678106, 0, 0, 128714160, 0, 16322766], [0, 12759888876, 473056088, 0, -8513242, 0], [0, 12727187363, 49576288, 0, 11132152, 0], [-7044817823, 0, 0, -256851547, 0, 13213747], [0, -3688716077, 30221228, 0, -1976275, 0], [0, 11610449300, -86557848, 0, -1850064, 0], [-19640507132, 0, 0, 178357768, 0, 1344122], [0, -1090886028, -423104207, 0, 5975620, 0], [0, 11984456, -8069980, 0, 21456056, 0], [0, -13646232739, 275303788, 0, 17176591, 0], [6297010436, 0, 0, -776734116, 0, 434148], [-10635002460, 0, 0, -244946474, 0, -4864684], [-15770280074, 0, 0, -242630992, 0, -11437556], [0, 8496051654, -220404664, 0, 8097395, 0], [-29083560653, 0, 0, 156184068, 0, 5509905], [0, 18930453733, -2117688, 0, -19777857, 0], [0, -5177246943, 534785616, 0, -12935088, 0], [0, -39002556344, -206366056, 0, -1271584, 0], [-22226188101, 0, 0, -40604557, 0, 4926913], [0, -21333566118, 94589224, 0, -35102231, 0], [0, 30583178169, -157259262, 0, 491343, 0], [-9265418903, 0, 0, -274299930, 0, 17096247], [0, 25444601574, -24589200, 0, 3841710, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_400_c_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_400_8_c_u();".
// 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_400_8_c_u(:prec:=6)
    chi := MakeCharacter_400_c();
    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_400_8_c_u();".
// 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_400_8_c_u( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_400_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,8,sign)));
    Vf := Kernel([<3,R![814817025, 0, 5660931, 0, 8707, 0, 1]>],Snew);
    return Vf;
end function;