
// Make newform 400.8.a.p in Magma, downloaded from the LMFDB on 23 November 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_p();".
// 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_p();".
// 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], [44], [0], [-1224], [3164], [-6118], [16270], [5476], [1576], [122838], [-251360], [52338], [-319398], [710788], [284112], [-296062], [897548], [-884810], [4659692], [2710792], [5670854], [5124176], [-1563556], [11605674], [-10931618], [-14790834], [8761048], [-4295100], [3744646], [-3907602], [42332032], [27209812], [50123526], [12207324], [-46647778], [30435928], [-6240598], [-2740596], [42768024], [-72141126], [72111876], [14488062], [-110502720], [-3433538], [37755666], [137979272], [-105441244], [132419872], [-223501236], [358523086], [-205337242], [127880944], [213448338], [281046220], [411662590], [-101817800], [-5305114], [-251185904], [119651426], [621695978], [341726228], [-3713166], [-32327556], [826997496], [-353026506], [-930187446], [321754012], [247705038], [-223075884], [-557087082], [-564509090], [-1660046808], [-700411760], [-433444670], [-1384210100], [-470821248], [15281710], [-1026007142], [-218348814], [750778986], [-238283148], [-1236397042], [-2240296016], [1190401070], [1388219256], [2857884788], [29686594], [-1830148538], [-813408218], [-1013025232], [-3802514724], [867385312], [1300432216], [-1886520516], [3817865796], [-447974328], [4505191926], [427300730], [814705060], [5174891478], [-6458301172], [4835623994], [1165078396], [2792011978], [7140691980], [-44489666], [-421422236], [4605467342], [596438040], [2189247658], [988184480], [-318993230], [-3837978906], [-2968337476], [-8107877320], [-11035662206], [6765319596], [6762422456], [9172112538], [5622986724], [3399655454], [-11407258978], [-3100862734], [6430671364], [4538845444], [-7843959498], [4053867758], [-7849375024], [6443180904], [-9487141142], [20790660532], [-5870681000], [-7084130064], [11202792514], [20800717322], [19460367362], [-18134190], [3489803164], [-9601009366], [12805436762], [-14185998724], [-18860999298], [-7982161144], [-16937914636], [-19363581770], [9162889224], [-21633509726], [13457390934], [21034688556], [-31566641504], [-30932282502], [25994746130], [27729474620], [-6180681016], [-9476372444], [-26383282288], [23453678936], [-40428696478], [10960993830], [-1879376826], [-19769540100], [-2810491722], [-20658591880], [45390007836], [21452856654], [38921302632], [32705657312], [9210648626], [-28673598574], [16951552322], [-43046018100], [-11941122570], [-44328103736], [-56931496570], [-16158738416], [1635633386], [3164222188], [-33615166578], [27606041368], [22515623366], [44786995136], [49805399572], [8768227986], [-17236281402], [-59883117648], [75477019230], [761284202], [69992168652], [-3201017318], [87261863040], [-32114436994], [32031004452], [50073613796], [-77272544426], [8446614156], [83746931494], [-101156514350], [26842464458], [4449541822], [66691038840], [-15363184858], [-52686664496], [111759897634], [9543218722], [-50438739396], [24852968202], [-72527612672], [-90451145940], [72828511610], [-45947016868], [51066481806], [129667581342], [-13056784088], [-19768387564], [111129869800], [-34960075942], [24852822224], [-47834602190], [-146640178968], [179502051690], [110152414286], [151796264760], [85563772290], [-171680151952], [124846336284], [8800459550], [-30202656618], [114012659616], [222709377432], [-22654983940], [68119409082], [180838230020], [-156494235200], [178938743482], [-199542824988], [-75895762384], [-22588663630], [218048310050], [-73128801620], [141121318568], [271995095484], [187439349196], [164927810872], [72931272166], [-828722034], [86302582744], [-87412273184], [-184992635148], [-8821508740], [272810264528], [177385001034], [90937075650], [-15100597000], [-69624823238], [204541802586], [83910666660], [-153401913250], [52619107540], [-195330219342], [-75094280842], [123124154752], [-187473001044], [261738515758], [79217199786], [-246200965474], [-222759595148], [-351310749370], [253184061770], [-326377751692], [-302154695918], [-324401373914], [127331724764], [-226456256554], [41686932704], [-251496116626], [242643541832], [198984534324], [256249463030], [347584435066], [127848690788], [309388791520], [286092191720], [31557691144], [-36311594386], [-503496035740], [-165376004272], [306138997966], [-198167477598], [-370302228200], [-229398998110], [415948206214], [-186670995396], [539988809078], [-21500418084], [114608257434], [-269460740522], [-287463343712], [358954488066], [153169379724], [-440157458836], [-372505439162], [204977734618], [105644603344], [313498030300], [-642427294548], [384169694686], [120083276484], [377803816454], [155322792376], [170744881234], [577474130928], [234229797534], [-100457460766], [-235953252596], [-298786816232], [42942269786], [578086236804], [725733377088], [150726768190], [-227235696846], [-226503007324], [192248793686], [600445304726], [-190013163104], [-13924986394], [209225122578], [-859005625260], [-599088037740], [746129999200], [446884196082], [-432484528826], [645047086794], [-72724128576], [674676866412], [279206697756], [-803559854508], [78029568790], [-1054430924322], [-474317463910], [755925618960], [-322568069566], [-606072826890], [808885728942], [176063346120], [100246539050], [-741929714188], [-346247302002], [-4364520572], [-478073738448], [718070555266], [277304990484], [597690335686], [245843034790], [247342220976], [716273243486], [-349564357034], [161050343264], [-405898760516], [-608002408978], [-843111037752], [902665276882], [459615030522], [144544094832], [-768914140052], [-299872799348], [-680745476058], [-1329259983942], [9591392632], [-463972124630], [502046236852], [471696510780], [1482762244112], [-435663726914], [-837147360328], [890736970762], [1031800353636], [-763238951904], [596387181854], [117248796498], [1378451130166], [1030973333430], [-422008606010], [-336348933144], [-1223818865826], [-527942614732], [-1584355814184], [-1402202920848], [-1672931332670], [1364098323892], [-955293889152], [-202402364030], [542615470802], [-513860363556], [-1313554579428], [-1352850408360], [815870813846], [-949840448352], [56747932122], [-1846658398724], [784234900990], [-1893709446346], [398672795070], [-2058344444624], [1347529095382], [-132255595826], [1259105934248], [331489233146], [-550789102446], [1199743810748], [-1387571687724], [230368366990], [2034975472226], [268663807508], [529694922740], [-751088214618], [679525192390], [176674400064], [399430064120], [-1408961490738], [-1605293774104], [-2032586842474], [264238123954], [297551504], [268522543948], [-1309457273338], [-2776564299878], [-2362335540452], [-1166157209238], [1420480049772], [-2000205482632]];
    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_p();".
// 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_p(: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_p();".
// 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_p( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_400_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,8,sign)));
    Vf := Kernel([<3,R![-44, 1]>],Snew);
    return Vf;
end function;