
// Make newform 448.6.a.x in Magma, downloaded from the LMFDB on 20 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_x();".
// 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_x();".
// 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 := [-48, -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], [-21, 5], [-49, 0], [358, -14], [357, -17], [-672, 54], [973, 93], [-896, -112], [600, -546], [-3402, 446], [-7320, -154], [3948, 442], [-262, 518], [-9198, 746], [-22566, 1008], [-11291, 365], [26411, 1117], [-4924, 224], [-420, -4060], [-61026, 1204], [15852, 1372], [-18487, 4185], [-105294, -1512], [-22120, -8882], [-88501, -795], [-93254, -2630], [-90056, -9268], [-92516, -7854], [-22460, 3906], [-124788, -13916], [104629, 14437], [235670, -4004], [302379, 1499], [-82938, -15204], [-157972, -12740], [209069, -4601], [-69814, 17710], [-317058, 19550], [-256207, 33259], [72784, 9100], [96901, -21257], [384228, -812], [-193936, 26558], [-642986, -17332], [164934, 44694], [209388, -70056], [363356, -40868], [-600355, -29347], [514129, -19421], [-689470, 51128], [-558832, 6104], [-881328, -59210], [726299, 6091], [1038618, 16408], [-2000548, 2884], [1388289, 7579], [606872, 45304], [-99030, 19376], [1668330, -26544], [515221, -10163], [-93961, -76031], [-1157835, -104683], [-142912, -90952], [2064188, 22682], [-1305890, 134540], [-13878, 62230], [3033832, 70630], [961714, 103502], [283745, 45739], [-330190, 101280], [-1469748, 16380], [1526868, 190468], [1280102, 31836], [108574, -132342], [-1775438, -113254], [974752, 303198], [239393, 76539], [431504, -141218], [-1759352, -84762], [-977165, 154171], [1363426, 15736], [896104, 374752], [-855932, 139434], [-3397800, -262752], [2876564, -40040], [-3565350, -135688], [1840456, 344526], [654717, -90777], [-47728, 266784], [-1760591, -278319], [1988070, 162894], [6479424, -85792], [2880972, 32928], [2847348, -386960], [-1481564, -321284], [3436097, -203893], [3108756, 520434], [6763897, 148225], [-2823258, 119140], [-1339442, -563710], [-1857818, -314300], [4583719, 76063], [-387904, -729946], [2806550, 324450], [-4520614, 517256], [-583737, -312441], [1778014, -494180], [6983040, -168168], [-1721902, -189480], [-3422160, -656752], [-6028192, 727342], [-7210544, -120554], [15848917, -215651], [1172036, -105140], [-2582600, -1214794], [1685159, -1058289], [9179478, -198010], [-6749428, -235438], [-17937642, 216090], [5803567, -320535], [3655206, 211540], [-7598675, -478897], [2040068, 403816], [-11771795, -150707], [-11426092, 994378], [16519248, -68754], [4260942, 1007350], [-9079854, 501394], [-6291341, 299589], [7781546, 21966], [-12647084, 54180], [-4707400, -996688], [1156152, -754474], [-31584, 578670], [3631740, 1197794], [-13321273, 751665], [24422377, -293079], [4065705, 1325235], [-2373552, 87766], [-6313503, 2086265], [-4019630, 463288], [1445104, -255304], [2610056, -1296372], [11945395, 823365], [7941570, 889698], [-11171279, -1608429], [-917672, -1594282], [-37491909, -76949], [6679692, 2304092], [11157040, 761558], [-6543138, 1077132], [-14287960, -1296204], [-12001990, -2172262], [10594096, -212268], [-19871892, -1400700], [31563152, 263256], [-18057032, 102718], [874510, 1427940], [17014739, -434411], [16106894, -1354990], [9104642, -1320536], [-12210248, -204008], [-15011507, -559867], [-34235202, -391076], [39947026, -880894], [4447816, 3124408], [42500255, 887433], [25724512, -959714], [-1776327, 1908987], [-10039588, 917056], [-8122835, 420007], [4855292, 1320676], [38523346, 1388296], [3805270, 3307038], [-13111154, 535076], [-52615008, 1241156], [-48187792, 842366], [-10745028, -1326732], [40260563, -1097227], [27316248, -3073280], [8331855, 2501367], [-36777540, -2184854], [-21768110, 455768], [-21735396, 1763188], [-36523907, -77905], [-44467814, -628936], [-4951667, 4523149], [-24026058, 798364], [20557474, 1148346], [-9728278, 1633368], [-1551796, 4636688], [44786744, -2865660], [-57700307, 1837703], [51440080, -663796], [3104934, -5197524], [-465336, -2109562], [41101512, -3495282], [-69904674, -1557476], [7198576, -4454104], [-908366, -430752], [5764962, -6004150], [17927007, 2205465], [-36332338, -3260372], [-63085855, -2272791], [-37082269, -4564843], [-48730878, -306342], [77096938, -2173346], [-63122852, 830018], [36272663, 5311015], [-65647080, 1425158], [-5785717, 4441333], [54252812, 3761436], [-39809147, -4077283], [12788384, 1612312], [6123376, -2746610], [11266112, -3605168], [1442980, 4366778], [36763008, -2001384], [-27546132, -2087582], [12044788, 4965618], [34526688, -1547384], [-13207158, -9016], [33647264, -7799960], [-36276835, 3823085], [62704324, 3000242], [33792346, 4688960], [-11252552, 2697744], [12079004, 5106980], [36104654, 8264186], [39438908, 6102530], [144360811, -228349], [11608648, 1366792], [-58882526, -3758216], [41856185, 5010705], [-93678928, -1656880], [31450832, 4100934], [-25216802, -5621420], [58062100, -1333192], [109549524, -2416340], [54357430, -3935414], [7332465, 6025], [-70859908, -39036], [87675874, -5268816], [-164776626, 409404], [-35456610, 8670], [24521112, -5925640], [75101117, 1477997], [-40376742, 3941462], [-2042408, -2681224], [-10256874, -482860], [129712506, -1589304], [94427212, -2385404], [107953594, -1198736], [42071659, 157229], [40571544, 5977524], [-11567492, -5802230], [-23442545, -4516161], [24778187, -6335835], [4623136, 4591070], [-6502448, 8440488], [57905922, -11967690], [35192059, -7412363], [44381491, 10544229], [-28862344, 2014062], [-12755085, 8687723], [-53063818, -3600828], [-146257678, 5762264], [-7096408, -13334804], [154318580, -2915934], [69386737, 6485899], [-73516426, 9811690], [1845606, 11384348], [1549652, -15578836], [33439042, 1550768], [75706932, -6651940], [-79653270, -2892778], [25937046, -10832668], [68878652, 3048290], [141668737, 1108817], [-9724820, -3526036], [-6323048, -13205808], [5633362, 8297938], [31814783, 7800713], [89758361, 10706257], [-11225828, 18480756], [16422090, 5773880], [42524318, 2351972], [71642354, -10207854], [-110096462, -3051008], [-119750, 10878728], [-249137455, -1143359], [-11630624, -12281738], [25229393, -1066871], [-164465158, 6826680], [76751801, -214717], [145959912, 11700472], [7149373, 1725743], [71922067, 10502659], [59203263, -2804105], [18830112, -13795026], [-233210396, -8334438], [-208389912, 7138040], [-77923110, 14467614], [-115165998, -3536834], [146087062, -8269884], [24595106, -530194], [-140726145, -12650095], [-178100952, -364056], [-61358454, 2935072], [191536380, 3417228], [-115640032, -10531570], [-140960322, 11359180], [-112054694, 13907950], [21979364, 19858972], [73941546, -5440064], [-99011353, -17964097], [-152240976, 448560], [-122499202, -18449572], [60093610, 4239480], [-321012237, 5582251], [-353234114, 2150484], [270625747, -1230651], [95196364, 7377804], [-182780696, -11739602], [119623924, -16551366], [113843310, -5905886], [-151724559, -2645351], [-288852700, 1952524], [-23676140, -2298254], [156663758, -4426324], [55236548, -2377606], [230749442, -7642966], [9392355, -21760453], [457841568, -800716], [-63546231, -22832735], [-109840028, -1381366], [172457138, 15982048], [29454362, 32744384], [356491002, -391390], [216840190, -8415708], [182282232, -12328386], [-381523443, 6324975], [70655780, -14807044], [-144182772, 12307330], [220138094, 215474], [133413021, -14249761], [8026966, -18551470], [413194964, 2861540], [43334039, -12467695], [-55874945, 17466071], [71015538, -13188504], [-299439886, -5274304], [231466914, -18924822], [111275886, 6014932], [29848966, -8626916], [228560038, -10233650], [81080629, 5303597], [138109170, -1629600], [12794408, 11515224], [197032710, -15061620], [18236414, 13426292], [-120856076, -12629540], [148004240, -10455228], [142157141, 25718517], [-156452824, 317422], [46606273, 34193915], [-315445280, 8563296], [-222112152, 13509342], [-141171672, 3359076], [564651955, 3487299], [-198810024, -3241000], [276748926, -7888972], [-116470312, 7355088], [-163016090, -20276508], [-171919531, 12758437], [75951232, 18474680], [145421934, 33611436], [-139941872, 25370390], [-144124904, -21250122], [138998097, -5999877], [533271936, 9392166], [-277665760, -18749528], [-110184582, 13906200], [-442230537, 11909247], [-42184744, -16818608], [26908876, 10628604], [-374432429, -7592611], [-517466652, -3687544], [31952242, 41008522], [-222793848, -12982858], [33553219, -7943075], [-365851056, 5707044], [-205933581, 8084011], [-69549532, 15590484], [-86332762, -8274980], [390403118, 1934550], [555757804, 947818], [210331344, -28532476], [-18596984, 15474886], [-52211677, 5951829], [484565898, 14516712], [-57052640, 33285392], [86548504, -17737898], [-209436927, -13570957], [72605386, 29903466], [22076826, 38099544], [352675856, -6471122], [-185324461, -14068725], [479455935, 11143911], [120375318, -347068], [-133091892, 34121178], [246261574, -14948206], [-61589660, 284144], [-647732886, -8591296], [416077837, -4676681], [-178427372, -8482124], [-227914806, 23589562], [-475336176, -2741034], [-524338332, 15418524], [144823004, 751618], [137165623, 47386945], [81827192, -28133000], [-510612081, -9357137], [37208780, 45957946], [-80117009, -47903135], [73952662, 25635946], [-53597502, -58929528], [-200060049, 33287439], [79834622, -17676914]];
    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_x();".
// 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_x(: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_x();".
// 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_x( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_448_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<3,R![-144, -14, 1]>,<5,R![-4384, 42, 1]>],Snew);
    return Vf;
end function;