
// Make newform 400.8.c.m in Magma, downloaded from the LMFDB on 07 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_m();".
// 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_m();".
// 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 := [25, 0, -9, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, -8, 0, 2], [0, 448, 0, -32], [-144, 0, 32, 0]];
    Rf_basisdens := [1, 1, 1, 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, 0, -1], [0, 0, 0, 0], [0, 5, 0, -7], [-2272, 0, -5, 0], [0, -177, 0, 76], [0, -1367, 0, -148], [19380, 0, -4, 0], [0, -6207, 0, -51], [36130, 0, -244, 0], [-153412, 0, 35, 0], [0, -6151, 0, 3192], [132182, 0, -710, 0], [0, 21165, 0, 5399], [0, 5273, 0, -5687], [0, 119579, 0, 6676], [-560060, 0, -2842, 0], [1128522, 0, 2000, 0], [0, -225823, 0, 9923], [-310892, 0, 875, 0], [0, -228453, 0, 28276], [2166520, 0, -5906, 0], [0, -489651, 0, 61299], [-3012810, 0, -3972, 0], [0, 230477, 0, 70212], [385902, 0, -4740, 0], [0, 631421, 0, -33951], [0, -569595, 0, 136443], [5215510, 0, 5172, 0], [0, 253463, 0, -340424], [0, 2238429, 0, 45853], [-21882912, 0, 12645, 0], [0, -514131, 0, 380592], [30411860, 0, 13842, 0], [15076750, 0, 63860, 0], [-20394252, 0, 36715, 0], [0, 414005, 0, -217368], [0, 2340197, 0, -2301], [0, 1826637, 0, 575673], [0, 4752147, 0, -698424], [106656220, 0, 31514, 0], [21897662, 0, 169800, 0], [92322868, 0, -77635, 0], [0, 11062135, 0, 362676], [0, 10320897, 0, -596388], [-85845000, 0, -141280, 0], [-38220272, 0, -190635, 0], [0, 1922993, 0, 3552849], [0, 15010429, 0, -2157697], [164885930, 0, 85376, 0], [0, -24118449, 0, 1233276], [-8286440, 0, 70262, 0], [-11107218, 0, -423550, 0], [78649248, 0, 74175, 0], [0, -261735, 0, 4676232], [0, 10478957, 0, -1158551], [-48631930, 0, 318664, 0], [-369610092, 0, -199115, 0], [0, -22949579, 0, -5327528], [-375787338, 0, -373410, 0], [0, 13634929, 0, -1171901], [0, -14495145, 0, 3834576], [0, -35808495, 0, -2869157], [39856428, 0, -185415, 0], [0, 39900583, 0, -1765224], [0, 1641533, 0, -6550748], [-40245112, 0, -183295, 0], [0, 26726589, 0, 8192792], [0, 42296393, 0, 10586263], [680449650, 0, 225160, 0], [0, -17379861, 0, -8427624], [35480040, 0, 407568, 0], [0, -79212943, 0, 9559673], [0, -117208533, 0, -7785224], [-10915380, 0, -138196, 0], [0, -71690391, 0, 565449], [-1688366610, 0, -372792, 0], [0, -64233423, 0, -6813388], [1966830402, 0, -507120, 0], [405724210, 0, -600798, 0], [382321580, 0, -633254, 0], [-1572761358, 0, -1951060, 0], [-273858012, 0, 674145, 0], [0, 135199491, 0, -8369924], [-1352981640, 0, 2672, 0], [0, 163470645, 0, 8242599], [-729958150, 0, -3488090, 0], [0, -158349375, 0, 31269632], [786404022, 0, -4021140, 0], [0, -5669243, 0, 2709349], [0, 201258337, 0, 23050523], [702170520, 0, -4991466, 0], [0, -255886559, 0, 9922533], [-845774432, 0, -6049945, 0], [1596453300, 0, -3087160, 0], [0, -193626979, 0, 16585849], [-122556190, 0, 1786672, 0], [-2558843158, 0, 2746240, 0], [0, 164434593, 0, 66878699], [-236657018, 0, -4984220, 0], [0, -422491827, 0, 466063], [0, -156539295, 0, 58685832], [0, 12431097, 0, -60950001], [-1099652430, 0, 821034, 0], [1270515208, 0, 2739105, 0], [0, 487716401, 0, 88272], [0, 72865701, 0, -22875717], [0, -141684965, 0, 40921376], [5502017600, 0, 2865790, 0], [4021505702, 0, 1480950, 0], [0, 415680225, 0, -45341207], [0, 337258023, 0, -71053124], [0, -561767247, 0, -39188748], [-575819620, 0, 2432256, 0], [-1846974012, 0, -2689985, 0], [-2106835218, 0, 1461810, 0], [0, 589203385, 0, 48906199], [0, 32776553, 0, 49160413], [0, -371876741, 0, -39486124], [306092140, 0, 11480078, 0], [5817663522, 0, -10391560, 0], [0, -1010469013, 0, 44054276], [0, -187841439, 0, 18684372], [0, 366877629, 0, 57381399], [411967368, 0, -5793485, 0], [-9525667798, 0, -10914260, 0], [-7396260390, 0, -8616308, 0], [1714880280, 0, -11061714, 0], [0, 1071251869, 0, 110673753], [0, -208018229, 0, 130349376], [-1691841540, 0, 7560182, 0], [0, -148093295, 0, -39467251], [6568173948, 0, -15068165, 0], [0, 649603005, 0, -104631568], [6644776122, 0, -15043440, 0], [4755070, 0, -6324036, 0], [0, 801622167, 0, 106519476], [0, 2352000381, 0, 7356583], [0, 1935750197, 0, -80225588], [3987079510, 0, -12888448, 0], [6169525328, 0, -20531545, 0], [2553211842, 0, 15096660, 0], [0, -1282612207, 0, -264842451], [0, 378494249, 0, 230556103], [3333051830, 0, -20004064, 0], [-339700240, 0, 6504082, 0], [0, -425322241, 0, -301214524], [0, -189746915, 0, 180984632], [-2926762860, 0, -39197902, 0], [0, -1715453623, 0, 46411249], [0, -2785598339, 0, 138879472], [-10425017138, 0, -30125410, 0], [0, 667035689, 0, -399220401], [0, -2707277859, 0, -146314167], [0, 72624305, 0, -154068457], [-23919731572, 0, -11025005, 0], [-21453756720, 0, 31791506, 0], [-192331670, 0, 23784326, 0], [0, 484727689, 0, -210003908], [-16149044218, 0, 47321680, 0], [0, -2743975527, 0, 38961363], [0, 1152949439, 0, -102693824], [0, 884754697, 0, 17697573], [30115391208, 0, -26108655, 0], [0, 1069237381, 0, 132881372], [0, 817408509, 0, -579180351], [15594654268, 0, -1920585, 0], [0, -182392763, 0, -365757788]];
    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_m();".
// 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_m(: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_m();".
// 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_m( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_400_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,8,sign)));
    Vf := Kernel([<3,R![22695696, 0, 9928, 0, 1]>],Snew);
    return Vf;
end function;