
// Make newform 400.8.c.s in Magma, downloaded from the LMFDB on 26 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_s();".
// 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_s();".
// 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 := [26244, 0, 325, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 487, 0, 1], [0, -815, 0, -5], [1625, 0, 10, 0]];
    Rf_basisdens := [1, 162, 162, 1];
    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], [1, 0, 0, 0], [-1, 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, -1, 4, 0], [0, 0, 0, 0], [0, -42, 60, 0], [-2172, 0, 0, 25], [0, -204, -1768, 0], [0, 352, 687, 0], [9100, 0, 0, 111], [0, -3366, 2112, 0], [-27900, 0, 0, 1316], [150888, 0, 0, 450], [0, -5628, 60986, 0], [-54243, 0, 0, -200], [0, 10044, 96640, 0], [0, -6832, -178788, 0], [0, -22024, -13074, 0], [1033800, 0, 0, -8752], [291022, 0, 0, 22500], [0, 36723, -25572, 0], [2364108, 0, 0, 5000], [0, 42216, 133943, 0], [-3593100, 0, 0, -8826], [0, 34689, 1204956, 0], [2995425, 0, 0, 44208], [0, -61368, -1712002, 0], [-1491798, 0, 0, 53700], [0, -291576, -65956, 0], [0, -372267, 123540, 0], [-174050, 0, 0, 10812], [0, 343496, 1856067, 0], [0, 763938, 83936, 0], [-19668312, 0, 0, -200100], [0, 1442472, 317031, 0], [-38578300, 0, 0, -19593], [-24844500, 0, 0, -233620], [-20916052, 0, 0, 224550], [0, -23808, -1047730, 0], [0, -70971, 3956228, 0], [0, -394752, -9437892, 0], [0, 3337416, 4848528, 0], [25179900, 0, 0, 42179], [-109335838, 0, 0, -69000], [-52419432, 0, 0, -232450], [0, -3867744, 20091025, 0], [0, 1277232, -10469982, 0], [-77684000, 0, 0, 285660], [3002428, 0, 0, 98175], [0, 3692484, 19646192, 0], [0, 4402588, 9606216, 0], [-125913900, 0, 0, 563256], [0, -1485264, 47403534, 0], [-258555300, 0, 0, 569612], [-65239343, 0, 0, 2379000], [-351279252, 0, 0, 180375], [0, -6977208, -55862910, 0], [0, -2574046, 26661768, 0], [-133521600, 0, 0, -874736], [-15622792, 0, 0, 3192450], [0, 13891212, -31003356, 0], [116285862, 0, 0, -2134200], [0, 3618789, 41352036, 0], [0, 13057956, -101937390, 0], [0, -3962967, -24953500, 0], [41292228, 0, 0, -6068550], [0, -19384104, 85551562, 0], [0, 2844152, -1215828, 0], [90160788, 0, 0, -3682275], [0, -30566328, 60323521, 0], [0, 6430493, -142728948, 0], [-40164250, 0, 0, -2290380], [0, 3609576, -179277594, 0], [762750300, 0, 0, 5094438], [0, 10423548, -98293032, 0], [0, -10262184, -111538702, 0], [571435900, 0, 0, 5949189], [0, 44630214, 60282276, 0], [419167050, 0, 0, -4589232], [0, -21725568, -70343492, 0], [907114677, 0, 0, -9044400], [218635075, 0, 0, -3071328], [62261100, 0, 0, -21228269], [1115156092, 0, 0, 37800], [2059401588, 0, 0, 3988650], [0, 42413136, 22968929, 0], [1195230700, 0, 0, 11591172], [0, -58949631, -115206900, 0], [2586228375, 0, 0, 6700240], [0, -26449008, -222931445, 0], [1289485572, 0, 0, 13198200], [0, 10689804, -265483752, 0], [0, 2128948, 336235248, 0], [-73833600, 0, 0, -2511606], [0, -108105822, 30631024, 0], [-2340343032, 0, 0, 6649100], [-378965000, 0, 0, 21212700], [0, -47287876, 675644304, 0], [2501788950, 0, 0, 4604992], [1638328917, 0, 0, 18188800], [0, -173291241, -287436188, 0], [-2764171368, 0, 0, -15641400], [0, 193280793, 68588612, 0], [0, -40774908, 190185600, 0], [0, 40096104, -97848312, 0], [3688268775, 0, 0, -30334176], [1386620608, 0, 0, -9144900], [0, 256201512, -197666671, 0], [0, -202323297, 83573004, 0], [0, 16310056, -372822285, 0], [2474860500, 0, 0, 11252830], [-4737500173, 0, 0, 20274000], [0, -21478392, -1123147960, 0], [0, -135015504, 624240542, 0], [0, -142242048, -702374118, 0], [-4239315400, 0, 0, 44935116], [-642109312, 0, 0, -43846950], [2270606082, 0, 0, 34942200], [0, 291230844, 257848080, 0], [0, 127089068, -1562751408, 0], [0, 143808676, 1113477186, 0], [-3569720700, 0, 0, 37153253], [235225972, 0, 0, -19184700], [0, -11611584, 1786697778, 0], [0, -47610888, -1392820776, 0], [0, -133126761, -85328604, 0], [-13692827932, 0, 0, 1304925], [2256976152, 0, 0, 52126300], [4746481700, 0, 0, -5643768], [-8237259900, 0, 0, -7771254], [0, -138350412, -2529113684, 0], [0, -467146764, 1060416184, 0], [-8921652800, 0, 0, -66486588], [0, 489486394, 1569052320, 0], [-208000252, 0, 0, 108407700], [0, -693629208, 34533640, 0], [-3214063203, 0, 0, -85627800], [6919910275, 0, 0, 474864], [0, 284776116, 335378388, 0], [0, -145791372, 1784168264, 0], [0, 566368832, 1036510038, 0], [-11863555050, 0, 0, 63493352], [3030253728, 0, 0, 40907100], [-8604116358, 0, 0, 130954200], [0, 20206284, 3634061432, 0], [0, 90198863, 980229996, 0], [-13746764400, 0, 0, 36005076], [24687745200, 0, 0, 3546592], [0, -900464424, -1840259694, 0], [0, -287592608, 3362479935, 0], [-19790764700, 0, 0, -50390937], [0, -94264996, 2758843308, 0], [0, 38844312, 2712262164, 0], [-19769788938, 0, 0, -112334200], [0, 163249839, -4747215124, 0], [0, 381248028, -4655570256, 0], [0, -175960692, 2423618880, 0], [11554383528, 0, 0, -68713100], [5703943600, 0, 0, -107391294], [16136168850, 0, 0, 218766896], [0, -641047728, 444114441, 0], [9717408432, 0, 0, -79415900], [0, 732630768, 6192159432, 0], [0, 243657776, 5248038141, 0], [0, 268913448, -2656742552, 0], [21121789308, 0, 0, 228617025], [0, 118906912, -5466420141, 0], [0, 312565014, -5693634684, 0], [33672703468, 0, 0, -44638950], [0, 1028716032, -880361172, 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_s();".
// 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_s(:prec:=4)
    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_s();".
// 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_s( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_400_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,8,sign)));
    Vf := Kernel([<3,R![62001, 0, 2098, 0, 1]>],Snew);
    return Vf;
end function;