
// Make newform 400.10.c.q in Magma, downloaded from the LMFDB on 19 April 2024.
// 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_10_c_q();".
// 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_10_c_q();".
// 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 := [16000000, 0, 433104, 0, 1305, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0], [0, 2178896, 0, 2695, 0, -1], [0, -30762448, 0, -240035, 0, -187], [2247682, 0, -17275, 0, -35, 0], [6099304, 0, 68525, 0, 85, 0], [0, -697834256, 0, -2624395, 0, -2339]];
    Rf_basisdens := [1, 107136, 4464000, 1674, 2232, 13392000];
    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)
    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 := true, 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+1)]];
    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 := 10;
    raw_aps := [[0, 0, 0, 0, 0, 0], [0, 0, -1, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, -27, -26, 0, 0, -23], [18227, 0, 0, -1, 17, 0], [0, -623, -460, 0, 0, 209], [0, 686, 168, 0, 0, -835], [272886, 0, 0, 164, 351, 0], [0, 9822, 3426, 0, 0, -1338], [-724835, 0, 0, 1483, 508, 0], [-1424710, 0, 0, -598, -534, 0], [0, -19697, 37572, 0, 0, -3831], [1977665, 0, 0, 11588, 4904, 0], [0, -58561, -2732, 0, 0, 24439], [0, -205331, -9384, 0, 0, -83831], [0, -216242, 314856, 0, 0, 211780], [1902007, 0, 0, 13381, -21680, 0], [41757807, 0, 0, -56485, -22980, 0], [0, 153369, 322747, 0, 0, 1059625], [-99224327, 0, 0, -74345, 48040, 0], [0, -876806, 56864, 0, 0, -1374247], [-103381487, 0, 0, -194525, -75234, 0], [0, -2207037, 165897, 0, 0, -1002837], [368000190, 0, 0, 136359, -4176, 0], [0, -2129372, -62616, 0, 0, -4150494], [-152815191, 0, 0, 244197, 455676, 0], [0, 10995313, 1867344, 0, 0, 4036845], [0, -13465401, -1573851, 0, 0, -2354073], [-708930881, 0, 0, 45195, -244572, 0], [0, -2484623, 8818680, 0, 0, 6724924], [0, 15798124, 17044970, 0, 0, -3561052], [-1309030413, 0, 0, -768111, 478812, 0], [0, 3703551, -14711448, 0, 0, 1615974], [216410309, 0, 0, 923265, 1765503, 0], [1731721099, 0, 0, 1087069, -941228, 0], [6442057851, 0, 0, -1478087, -436146, 0], [0, -32637920, 7935216, 0, 0, 22906038], [0, -3992543, -9685395, 0, 0, -42576639], [0, -68908833, -47474088, 0, 0, 8795115], [0, -30987768, -31481736, 0, 0, 15503928], [-2568989000, 0, 0, 2098642, -2047853, 0], [-9227204218, 0, 0, 6623460, 2212680, 0], [-10762623704, 0, 0, 1212268, -342506, 0], [0, 81418658, -47913768, 0, 0, -69758589], [0, 26722536, -115434336, 0, 0, -66724014], [-3038383692, 0, 0, 8293748, -542676, 0], [-1937481569, 0, 0, -1537017, -8897361, 0], [0, 83794606, 74300676, 0, 0, -126459138], [0, -324314935, -30066780, 0, 0, 57030473], [24492248654, 0, 0, -4731778, -9806520, 0], [0, -144135846, -217386672, 0, 0, -67052088], [18630806251, 0, 0, 7321237, 16099324, 0], [22367181552, 0, 0, 1344965, -24092280, 0], [54656327388, 0, 0, -9417210, -2435505, 0], [0, 231651336, 90358056, 0, 0, 219716778], [0, -39153218, -24514710, 0, 0, -481153154], [36677314022, 0, 0, 35763554, 28891568, 0], [-7941372120, 0, 0, 35313652, 38171466, 0], [0, -669137793, 150608780, 0, 0, -405809173], [42794899320, 0, 0, 12824358, -6898536, 0], [0, 842714376, 239457677, 0, 0, 725664368], [0, 871558737, -172220748, 0, 0, -405616269], [0, -337540364, 818439449, 0, 0, 4684652], [93056064825, 0, 0, 25210707, 41047506, 0], [0, 632581544, 788727000, 0, 0, -22711806], [0, -1412046152, -867139032, 0, 0, 264749140], [190769328359, 0, 0, -54457549, -8040267, 0], [0, 600690263, 1033441432, 0, 0, 917673904], [0, 1071065911, -162014979, 0, 0, -164452001], [64092862767, 0, 0, -59429933, -155188884, 0], [0, 1238082720, 1316615016, 0, 0, -656872410], [274881790353, 0, 0, -71636133, 64647918, 0], [0, 389707668, -1085078708, 0, 0, 1214783020], [0, 2149039444, 55573784, 0, 0, -885923602], [-374347081146, 0, 0, 127357856, 123103149, 0], [0, 1095701397, -1090108218, 0, 0, 843470673], [-291718012854, 0, 0, 203840040, 92667312, 0], [0, 913351880, -1653413216, 0, 0, 517367956], [-179370187782, 0, 0, -143628489, -259712112, 0], [230782978585, 0, 0, -57129414, 194568096, 0], [-285604525450, 0, 0, -54461332, 243982163, 0], [-374823250770, 0, 0, 12817958, 213675864, 0], [-10368072813, 0, 0, 113794689, -393757038, 0], [0, -3039830528, 1093785368, 0, 0, -964263823], [350182839411, 0, 0, 4538477, 283231284, 0], [0, 2206765986, 2678596473, 0, 0, -2420244606], [-377080194964, 0, 0, -304985449, 47997968, 0], [0, -6401843629, -316899104, 0, 0, -4855826882], [956340768864, 0, 0, 247612212, 93436296, 0], [0, -2001030474, -2588987860, 0, 0, 2125723646], [0, -5877891145, -4680223188, 0, 0, -3477554785], [-782278751346, 0, 0, -429029154, -358826286, 0], [0, 5426916872, -1304110662, 0, 0, 1664153616], [-104072655071, 0, 0, -548696789, -809357012, 0], [1029160881177, 0, 0, 191099267, -247446564, 0], [0, -745229534, -1419621156, 0, 0, -4443971630], [249114547670, 0, 0, -649373944, -466761664, 0], [-1253101318975, 0, 0, -213945172, -723304576, 0], [0, -3212942173, 5659344151, 0, 0, 5538649387], [-310152350252, 0, 0, -1148454044, 11819448, 0], [0, 12367486984, -783284359, 0, 0, -6366245056], [0, 14194881261, 1660867716, 0, 0, -81542187], [0, 17786136375, 211766880, 0, 0, 16766413911], [-1449722486205, 0, 0, 1081969692, 1034860512, 0], [689097939079, 0, 0, -168944619, -285402852, 0], [0, -3957528365, -9299495400, 0, 0, 1971000972], [0, -6123108600, 14902301703, 0, 0, 86353056], [0, -21305761645, -6974742168, 0, 0, -9449148514], [-2092881051577, 0, 0, 1205561573, 1536460454, 0], [-971795836948, 0, 0, 807110475, 898256400, 0], [0, 6243443248, 16256544104, 0, 0, -4093987768], [0, 11036823370, 2032153040, 0, 0, 9554267984], [0, -7772028186, 12278523648, 0, 0, -8898797280], [-1803396282085, 0, 0, -1823101287, 41470188, 0], [-1382182848354, 0, 0, -1629132722, -245077326, 0], [-1160240345916, 0, 0, -707722938, 56709096, 0], [0, -11167520763, -1260149212, 0, 0, -13790188291], [0, -8794427894, -6879413364, 0, 0, 14858725114], [0, -48196059595, -7166780364, 0, 0, -4815869065], [4178359328929, 0, 0, -639221567, -1305494219, 0], [-471938747505, 0, 0, 1798378913, -1232979396, 0], [0, -63312366, 24805671904, 0, 0, 24143442868], [0, 325588326, -23336647560, 0, 0, -1869791538], [0, 22398227769, 19208637927, 0, 0, 10555125393], [-2288693670444, 0, 0, 1613786578, -1849108851, 0], [-5797117547725, 0, 0, 687989633, -213146236, 0], [756076781154, 0, 0, -311977910, 3921301368, 0], [3333297073155, 0, 0, -2250879807, 234437298, 0], [0, -75046784827, 14404371180, 0, 0, -1958558367], [0, 1020664925, -21638262252, 0, 0, -22461092643], [-2353958352693, 0, 0, -4153749487, -1917441468, 0], [0, 59878836050, 15128673858, 0, 0, 64853572154], [-5634361384095, 0, 0, 3339533647, 2342115876, 0], [0, -66806964076, 10303756216, 0, 0, -28535420612], [-12652640531991, 0, 0, 2807543532, 2310793656, 0], [-416194112468, 0, 0, 1728045939, 958872048, 0], [0, 13189264011, 65434575684, 0, 0, 41324242023], [0, 10108796173, -4311519652, 0, 0, 670405901], [0, -22162661150, 23998467264, 0, 0, -72444982064], [-2346919049984, 0, 0, -2487531698, -509739656, 0], [2739676583039, 0, 0, 1344790301, 2998602108, 0], [-4306483019976, 0, 0, 350985282, -892182744, 0], [0, 47445304558, 33266451276, 0, 0, -39483712938], [0, 83301794680, 25747225575, 0, 0, -27432710672], [3884348679821, 0, 0, -826237561, 5283614796, 0], [375766450418, 0, 0, -11226965866, -4949560480, 0], [0, 50936578056, 6107722936, 0, 0, -3907362590], [0, 73129843409, 39073736736, 0, 0, 69114467408], [9951019316577, 0, 0, 642334421, 3781960575, 0], [0, 27100593535, 60675810660, 0, 0, -18071321909], [0, -58725520716, 18657136040, 0, 0, 70010427512], [20226922425460, 0, 0, -2180931302, 2780498584, 0], [0, -126180317444, -9583757313, 0, 0, 16484497428], [0, -2039124024, 74287428588, 0, 0, 102836826216], [0, 19010158617, 87037687924, 0, 0, 7418947777], [1283276515292, 0, 0, 11900187764, 6093913412, 0], [8544436381428, 0, 0, 8578763456, 7161613242, 0], [-13603359660218, 0, 0, 10179116380, 14043881104, 0], [0, 59401577172, 3437352632, 0, 0, -69583042171], [-4122143836837, 0, 0, 6051315521, 6189939068, 0], [0, -56652853647, 20981493816, 0, 0, -60824456031], [0, -21614025077, 98228052816, 0, 0, -5389103960], [0, -91245260608, -90905925048, 0, 0, 34269644280], [461545599747, 0, 0, -4479422841, 6829242297, 0], [0, 134740349612, 129978955320, 0, 0, -110046463633], [0, 160169458869, -33235684218, 0, 0, -86251475727], [-19527112770599, 0, 0, -3205198677, 7999985634, 0], [0, 26354897646, 172953131024, 0, 0, 10794448346]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_400_c_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_400_10_c_q();".
// 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_10_c_q(:prec:=6)
    chi := MakeCharacter_400_c();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 10));
    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_10_c_q();".
// 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_10_c_q( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_400_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,10,sign)));
    Vf := Kernel([<3,R![2967381766881, 0, 3296636163, 0, 117283, 0, 1]>],Snew);
    return Vf;
end function;