
// Make newform 400.8.a.k in Magma, downloaded from the LMFDB on 11 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_400_a();"
// 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_a_k();".
// 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_a_k();".
// 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
        Kf := Rationals();
    end if;
    return [Kf!elt[1] : elt in input];
end function;


// To make the character of type GrpDrchElt, type "MakeCharacter_400_a();"
function MakeCharacter_400_a()
    N := 400;
    order := 1;
    char_gens := [351, 101, 177];
    v := [1, 1, 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;

function MakeCharacter_400_a_Hecke( : Kf := Kf)
    return MakeCharacter_400_a();
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], [9], [0], [-694], [-4901], [-7228], [-15925], [-8749], [-53554], [-98752], [65030], [323958], [170277], [226228], [399932], [217218], [2733128], [-1410230], [-3163693], [3458532], [-4113051], [34386], [1798039], [-12630321], [7118942], [-11113914], [20344108], [-505275], [-22923394], [-3116727], [-15361158], [1995852], [31993291], [-1298781], [-50592608], [59942278], [-60941818], [87858139], [22573644], [90511304], [-142293769], [75253802], [-79785670], [102462347], [83100826], [-152676548], [122586061], [-150826468], [191982804], [57548836], [362214858], [-257156016], [374808473], [-163995], [-426299790], [448264830], [-35540144], [171237846], [473554096], [-264247522], [-174731557], [-21327566], [501499609], [318134666], [-197523626], [-121932876], [-773046873], [408518573], [-810056699], [-1489906962], [-553197190], [371131722], [-677911420], [-119631730], [1639960985], [-976534338], [-60773370], [-1486208212], [370720101], [2183024221], [1682304087], [-1982033772], [-2965791286], [-2241308405], [1182226616], [241284903], [-9258951], [-511861753], [-214562868], [-3865328532], [3083046676], [-4121067158], [-809882294], [-487427076], [-3718067804], [-3808194588], [3863176106], [2477178965], [-1469550095], [2600860048], [2847467753], [2507413844], [-4612493104], [3147060793], [-1987085500], [-6239775971], [7135179519], [6152882937], [-2751424950], [-5521939037], [-2463168240], [6066452730], [7803601794], [3429699604], [8874432710], [776201034], [509295396], [-9307593204], [-4969166782], [7298155569], [6107831184], [83334342], [-42529904], [14266271409], [6532032439], [4042037212], [-17759650012], [-5517522554], [-9083281696], [19336047588], [19436291652], [8045449230], [20070425616], [5575161904], [19125179637], [2941245037], [3519705240], [25390025804], [14882570094], [428868882], [1440223876], [3948225122], [-27347299124], [22626435279], [-3506517020], [-8577552976], [5556612334], [-24575912421], [-5987515469], [-16868448744], [-19570721572], [2461551150], [-4356163375], [-23138632036], [43293878556], [-29881781708], [-38744179214], [31866405662], [-13175200195], [-19734215956], [24136913240], [33687729183], [19156199760], [-50474977429], [2361458879], [-1759654578], [29150546962], [-40530367524], [570033581], [-36384314728], [41429664545], [-6441106550], [4929255914], [-13162153835], [29793679144], [54760703871], [-13970641267], [-11553888938], [-63732531272], [-24128568854], [-84091968844], [-63998965953], [-14210207414], [34127980753], [-22866994748], [-21802500380], [-20291911658], [-11189060203], [-75481329103], [21960290560], [-8730941999], [45718800867], [90085985821], [60714959734], [53544109541], [-30140246266], [458740035], [68979516318], [-3049696123], [55421282590], [93766100922], [-21156090436], [-4430965136], [-62349341133], [-20550428316], [9274534382], [-23223806602], [39098083820], [45433390350], [54055353352], [-57825384994], [-96301490558], [-39905667568], [26790365841], [26661347830], [62092435593], [119381536234], [61966195525], [115232803062], [141699913030], [108726236246], [-55358813140], [119444894825], [188329407798], [108904195809], [89717461150], [78180137897], [-142945298704], [146231541092], [31045766225], [-129615044578], [-52213940055], [83023729750], [-117086424673], [-2218881288], [209862941526], [5216648445], [67343424120], [-29015690435], [-6044651292], [-140738586511], [89279379521], [120341074402], [179695071556], [-92125740499], [196968767744], [-88649476994], [-88415043028], [19358344745], [226825824088], [183980878224], [-72602344165], [112766668950], [-145619566333], [-42069133144], [39204003345], [176358551600], [-58715286825], [311242787718], [-118295612877], [-26859285578], [-163641579989], [-52009954152], [-220939827884], [185594587451], [-287061583393], [84370520390], [-320216050050], [-36647501007], [-187480549778], [-143303905324], [-297712725761], [-159892063719], [274645053304], [-117574563746], [73474740092], [-304184960431], [-59945973880], [463323514766], [268342744503], [-176650939500], [-185966466270], [435276548824], [441832327924], [-534706646045], [-219688899032], [-113029166654], [-448995970848], [-293470921440], [427551445410], [-491159616766], [460702260564], [493155247413], [116590026501], [-587051197756], [364967059158], [-510796455002], [338690352936], [173026965964], [-581054089161], [-398038831617], [7748405658], [-93034528736], [-482610849395], [-337798321923], [36547367831], [510571189284], [97680478414], [158749278246], [311135502634], [-228237675682], [-106128568806], [-432920581911], [348587715784], [70044656908], [501236583526], [-360465628301], [187925337288], [205108004465], [-192706764061], [463003014196], [475021838971], [170774457516], [884289425266], [723109834726], [275650356258], [-41575908595], [520598984660], [61424760130], [593790840972], [129827918324], [358718934574], [545509377794], [975387110477], [260507058071], [315488244552], [-19208328040], [-488414543682], [-51567709505], [-243340462950], [387654821944], [800273899815], [-682352944618], [-40459743980], [-995041005230], [405236483452], [165037491748], [-1765913357], [945777334032], [927039398586], [-796127994151], [18235322766], [565477619990], [633257417516], [-803121362374], [717056487421], [489388967964], [891274209799], [865505052082], [-370480463492], [833328919942], [152609193347], [-806148626378], [-832967777652], [-956651785953], [333083470997], [-1419370041432], [-363531260248], [57556930205], [72855682572], [804820673395], [44249794972], [674477394876], [-439638452448], [-1111565037758], [1658144404731], [25543185326], [-768417376571], [1225941542553], [1228753957966], [-844421906270], [99012199975], [-1631095660824], [-255065352711], [-1266487583712], [-1333625074054], [1499387317232], [-825834175200], [-282458490288], [815157678098], [1012343195515], [886718750892], [-678402634611], [585933614647], [-756117997570], [1964882573371], [-645944428532], [83669551017], [-1039128903149], [627824657850], [449970164904], [-1468069915605], [-1456485562244], [-1106150214273], [-361942413456], [1926024027288], [-629133350794], [-449612934486], [-2024403383132], [1109406284181], [-2146840774975], [1738814354736], [1372600810903], [-1009764933580], [-1561310702263], [-519937071810], [175613164234], [-1969282282070], [-1649785949073], [-331028798514], [1938148575936], [512442655274], [-1388305389286], [1006709954353], [1982601429747], [262826871072], [722165976168], [982780054347], [1606653466327], [346202454458]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_400_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_400_8_a_k();".
// 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_a_k(:prec:=1)
    chi := MakeCharacter_400_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 8));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(2999) - 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_a_k();".
// 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_a_k( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_400_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,8,sign)));
    Vf := Kernel([<3,R![-9, 1]>],Snew);
    return Vf;
end function;