
// Make newform 448.6.a.y in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_448_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_448_6_a_y();".
// 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_448_6_a_y();".
// 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 := [-15, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [-1, 2]];
    Rf_basisdens := [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_448_a();"
function MakeCharacter_448_a()
    N := 448;
    order := 1;
    char_gens := [127, 197, 129];
    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_448_a_Hecke(Kf)
    return MakeCharacter_448_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+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 := 6;
    raw_aps := [[0, 0], [7, -1], [-17, -7], [-49, 0], [-210, -46], [245, -49], [-528, 14], [-623, -247], [-252, 16], [1952, -546], [1022, -642], [3744, 14], [3916, -1134], [-5166, -1090], [20986, 850], [-16406, -2688], [-24199, -1639], [359, 441], [-6412, 3696], [51996, 396], [-27050, -5404], [32284, 1108], [23905, -527], [-8694, 14448], [-48648, -6146], [-49981, 2989], [58842, -15502], [58912, -21812], [-62644, -12894], [-65152, -14798], [-20776, 18228], [133357, -1747], [262, -644], [173551, -9], [-58170, 37716], [96824, -48372], [-131803, -27041], [599018, 4134], [-181930, 45590], [285993, 13251], [548800, 35660], [-321103, 8995], [-161532, 41988], [105972, -65842], [-140370, -96684], [91966, 10950], [-215180, -95808], [-290500, -28556], [-119007, 47465], [372025, 95515], [-836830, -32984], [-726012, -114168], [471112, -13202], [-403725, 68675], [-259678, -49840], [433580, -127156], [-1062767, -7189], [-355656, -191632], [-1025110, 150584], [-149190, -65184], [-1993859, 14341], [-1760153, 91105], [-2289595, 22245], [-141848, 221648], [-165716, 40530], [403598, -49476], [-3010910, 68702], [-2858644, 119014], [459746, 13678], [-1672891, -30961], [762882, 383544], [535472, -437524], [-2840180, -149132], [2087750, -199724], [-2501842, 221610], [-2804270, 168090], [-1717264, -400610], [1876173, -271145], [-2529204, -102802], [283464, -602714], [3040947, 258171], [3173474, 421456], [-2412844, -321616], [3529340, -67942], [1659280, 439904], [427252, -392584], [412650, 588840], [-7025812, 178766], [-6603903, 305515], [-1391488, -51344], [5502525, 8037], [-170394, 1043958], [4834004, -376592], [2505076, -412232], [1059828, 703256], [3340652, -300964], [6592549, -201761], [-2740884, 325738], [-818587, 721317], [-1664258, -104188], [59822, 756762], [-5551362, -261492], [7111923, 520147], [-7573428, -546714], [-12194154, 276370], [30810, 1432144], [2846403, -769269], [-1270602, -804636], [8406720, 929064], [13355082, -337792], [12076792, 42680], [-2828192, 1504566], [-5056988, 1347430], [-8662731, 577981], [15309700, 169564], [2268516, -2269610], [-1480101, -1634357], [8223838, 199286], [838732, -419286], [6838118, -428654], [-11118465, -349671], [2575558, -2213596], [12691905, 938931], [3298372, 1939376], [-11731195, 794837], [4828572, -1273734], [-447800, -324954], [-639506, -240202], [11504010, 511738], [20541543, -215159], [-8996694, 802022], [-2818984, 374772], [-6160588, 2602576], [2209928, -110082], [15983160, -552930], [15371140, 585914], [-8258205, -901299], [-12674627, -2654811], [11527633, 2520763], [-9994572, 2292374], [162729, 611825], [-16395206, 1575672], [-9950416, 2441472], [2018632, 793892], [9753463, 1830857], [-2547846, -256478], [5246817, 1790691], [-12747168, -1492050], [-18964757, 117259], [-18076660, -355172], [-23523696, 1493030], [-3148034, -1740956], [2979648, 71284], [-14658910, -2990622], [-20827912, -539044], [15741712, 1018468], [4407200, -4065600], [38921744, -959378], [-33572178, -922516], [-5221805, -1104635], [-13457682, 3591482], [29027522, -155176], [11840892, 2296024], [-9397367, -3927319], [-26695602, -1280468], [-12032790, 3005154], [-3878056, -3631536], [-7343829, -1850891], [35344692, -857906], [46790257, 2309923], [-11821740, 742776], [33746169, -2388477], [55543964, 739516], [-30411070, -137144], [16936878, 3679606], [-19828322, -4556748], [-32462136, -1367180], [26836944, 2263590], [-30051756, -5509748], [8659195, -4904963], [8965236, -3159632], [-15040893, 7984035], [3120108, -773206], [38348658, -2986816], [52842944, 386164], [-12965091, -4473441], [-6448182, 5770520], [32445497, -3701567], [3233318, -7248388], [41537090, -2036462], [46286642, -4488120], [60969636, -3205440], [-50460536, -617684], [32329061, 1701791], [-3662848, -7379580], [5839846, 3557372], [-31674772, 4953046], [-35012640, -5502098], [-24639394, 2740612], [-12715920, 802832], [7239018, 2212392], [-25270238, 4264834], [-14943037, 7073997], [-33372690, 1805972], [80418933, -2562123], [-5634229, 607901], [-8164142, -11727678], [70795074, 2874726], [37582824, 5968914], [16088359, 625591], [-61232876, -3552906], [86402183, 2468865], [-95304888, -768004], [46185573, 6223677], [-14789992, -1017912], [30370536, 5710558], [29253168, -7689872], [-17046868, 553378], [5175184, -9803272], [4407964, 3023034], [-13495060, -6554590], [-15559320, 11024440], [29646954, 949704], [-88326140, -379816], [-30994327, -1497663], [-20061292, 7294266], [-5686246, -360976], [72296140, -5773280], [18518444, 12012124], [41765038, -7680638], [26179844, -1336622], [5612971, 12959843], [-23970968, 9613720], [15407954, 4830056], [87349185, -482807], [110678512, 339640], [112546712, 3095302], [-58789802, 5824196], [-18199468, 905720], [-24018540, -15102772], [267470, 8096386], [-100749579, -3018027], [-125191668, -5406516], [61644378, -3382232], [42602678, -12327028], [57173438, -12132490], [-12554752, 13302224], [-90924155, -7467259], [-1622614, -423554], [-45462984, -16376880], [53823686, -8063076], [-62918254, 7099512], [-2914436, -15492732], [-31815366, -5278336], [12679439, -11854927], [-124781440, 6575036], [-20743108, -9211902], [-88809357, -264869], [-55185409, 11199545], [-33613408, 9731470], [-64739276, 9737960], [-61712798, 662710], [5314655, 17301081], [-137685753, -10947559], [17507728, -6026762], [-5117777, 8834223], [5632566, -4472020], [25958514, 22672776], [-15138872, -4275484], [-102330868, -1507142], [-53875991, 12650435], [-46324250, -2912486], [-45443762, 19436676], [63553616, 17702412], [110504826, -3379880], [-155883196, -5020692], [-60827046, -24948546], [22101062, 16295412], [-48330664, -28593502], [-111165327, -548047], [-101225068, 2936588], [-63262136, -3673896], [84738626, -2086974], [-77047329, 8621753], [87006241, -8077191], [-36985984, -30325004], [151754394, 3789800], [-27417770, 21940828], [-40365822, -2399134], [181617890, 13784680], [-44947582, 33905648], [26584089, -18075399], [49911476, 31867990], [38246257, -21451367], [-3855742, -19100760], [-85290843, -17669057], [-3131240, -13193360], [-11085667, -10837169], [-95413213, -21729501], [210593719, -9582497], [-34083192, -88298], [196778316, -5101950], [-37416792, 11259592], [104698370, -6486106], [-279393030, 7491646], [-172130570, -7861308], [142916522, 25362278], [-203963213, 3436405], [89798660, 4317240], [125902570, 12151160], [-14990556, 4416828], [-17508648, -15336762], [-72529298, 6481132], [145975018, 4402350], [249015508, -1575780], [47232394, 38179792], [12279659, -794629], [-82591712, 921344], [148881214, -11694956], [-283320774, 3506552], [-119758317, -17065605], [43256878, -9460444], [-347517157, 8587005], [-37021796, 19858756], [194500620, -13127394], [-62344988, -4515630], [-17555818, -12849486], [-171787455, 831161], [119234024, 13883420], [23677212, 27951266], [177244566, 7700756], [66701444, -9664382], [213315746, -5619734], [26717831, 32527655], [-280441448, -1220220], [-67019771, 2570373], [-65348084, 20988450], [-344160366, 10299912], [-13846534, -30097480], [219515002, 33028410], [128817374, -6468028], [10815540, 8000622], [-18113063, -23715461], [38184916, -26918596], [232093444, 15229858], [54486390, -39536166], [87394625, 1140867], [-17974474, -19324526], [80159716, 17034908], [57636523, -50980811], [-89029913, -1118273], [-111067230, 50506904], [-9797342, 27660752], [158700738, 27142866], [130561734, -17277764], [-385642450, 19719028], [-57841602, -28843026], [3286745, 21254713], [50829330, -23439696], [-262195444, 11353288], [-10672386, -11732644], [-143045746, 37298380], [-157605616, -39830804], [-60629856, 55315236], [-53577671, 47983969], [-40209604, -49718578], [-104093071, -47759061], [100181620, -32995536], [393830796, 11302942], [-118187272, 1506668], [-67180393, -53658225], [-274299032, 19481488], [-24224578, -2312772], [-15310064, -31818808], [404479374, -18846268], [121661057, 8887977], [-332050460, 28478200], [229949398, -18200532], [-281379712, -12163242], [-278881920, -22983954], [-82984147, -20718537], [-128657052, -21981050], [254517536, 16306496], [185150218, -27675704], [170019339, 40071035], [-297819984, 2101392], [11655420, 54419204], [-23375609, -82453455], [-247764244, -40982592], [-185964758, 8799130], [-4088660, 18541894], [-270287729, 31742697], [236708304, -45123492], [224473907, 4928955], [-387520896, 21299892], [-385297242, -30998996], [-92596826, 60047110], [-669165588, 9069018], [-25121656, 62877684], [540626176, 15722854], [-186857917, -6381515], [168510666, -14845320], [362950112, 49703296], [65058368, -43508626], [44856393, -43344581], [-53160422, -30251294], [325092850, -2962680], [-256883884, -13631618], [-3260789, 50441763], [-187102237, 6154179], [417622814, 44694244], [-183948636, 31366538], [-194704426, -35355198], [139099044, 27534232], [110698362, -55888672], [220918617, -7621677], [151288452, -83362884], [137168626, -49710622], [-25916288, 49056518], [-235339188, -53461668], [-369970444, -24012198], [-522540661, -17515435], [795418008, -11754048], [-61238289, 70484991], [-690557404, -10498838], [35872043, 24415629], [-527840418, -16417214], [-64696478, -30719192], [-531647361, -44129313], [-27559154, 17164334]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_448_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_448_6_a_y();".
// 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_448_6_a_y(:prec:=2)
    chi := MakeCharacter_448_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 6));
    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_448_6_a_y();".
// 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_448_6_a_y( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_448_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<3,R![-12, -14, 1]>,<5,R![-2700, 34, 1]>],Snew);
    return Vf;
end function;