
// Make newform 800.6.a.n in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_800_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_800_6_a_n();".
// 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_800_6_a_n();".
// 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 := [-24, -36, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [-1, 4, 0], [-189, -16, 8]];
    Rf_basisdens := [1, 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_800_a();"
function MakeCharacter_800_a()
    N := 800;
    order := 1;
    char_gens := [351, 101, 577];
    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_800_a_Hecke(Kf)
    return MakeCharacter_800_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, 0], [-3, -1, 0], [0, 0, 0], [2, 1, -1], [-131, 0, -3], [124, -20, 2], [-368, -60, 6], [1047, 50, 1], [-2054, 43, -7], [138, -40, 52], [1196, -270, -42], [3762, 200, 76], [4120, 68, 22], [-8713, -221, 14], [-12288, 77, 25], [6712, 1140, -114], [11765, -70, -185], [-8718, 1984, 32], [2381, 2345, 82], [29002, 1030, 56], [-23080, 2340, 150], [-31272, 700, 164], [-10935, 2923, -376], [57774, -600, -36], [-57300, 1420, -430], [-39726, -440, -4], [31678, -2785, 481], [20391, 237, -288], [-97314, -4744, 52], [-67326, 7800, -108], [34224, -1287, -1467], [8451, 7840, -1117], [86822, 1360, 2456], [-285019, 5170, 143], [-70010, -2472, -828], [10250, -9770, 1160], [-49310, -520, -620], [-238211, 6187, 1532], [-145994, -18463, 3475], [240794, -5560, 652], [-135485, -21770, 3425], [67822, -33920, -688], [617544, -7690, -1178], [-94448, -3900, 4806], [-159912, 28100, 1894], [-246374, 23340, -1002], [476351, 600, -1737], [-663792, -8621, 1943], [-580723, 15629, -3482], [777950, 9360, 72], [208132, -27540, -1374], [-115832, 45020, 4084], [-269448, 13716, 3630], [399465, -43280, -1255], [-197774, -42600, -2172], [-1088262, 631, 5525], [-320182, 13520, -2696], [-283168, 7350, -8514], [-848822, -21240, 2124], [-1424820, 12844, -814], [-34429, 58615, -6754], [-224202, 47280, -11736], [1526097, -25031, 4646], [1017002, 31050, 14796], [-805326, 73560, 2052], [-196948, -56420, 4586], [-938519, -66580, 15013], [-710974, -50520, 9468], [-413453, 67849, 3416], [-1813762, 640, 176], [-2460070, 35000, 7060], [828374, -47820, -4038], [625908, 9981, -6531], [2604050, 600, 19140], [209841, -34770, 19623], [-2992416, -18469, -9521], [1158386, 24144, -14856], [1696476, -118420, -16382], [-450382, 104960, -6560], [52484, 30828, -19086], [3361535, -86290, 14005], [1604230, -56232, 21252], [1850040, 8110, -8530], [-6310692, 11180, 7234], [866866, -102180, -24162], [-2503037, 145123, 11738], [1378152, -149020, -22394], [-1521546, -83040, -36048], [-366694, -204760, -32756], [1274168, 223207, -22141], [-4380519, -44031, -33642], [6746736, 42300, -8772], [-285718, 49293, -37821], [3815545, 265040, -22775], [2726715, -294910, -12875], [2293074, -61297, 25381], [2088422, -40720, 53464], [-6846086, 18880, 6176], [3184183, -278649, -35934], [-80670, -150440, -34924], [5202909, 117821, 61222], [-7802566, -104840, -23308], [5777265, -14025, -43572], [-5262308, -92324, 51290], [-7478319, 6460, 4253], [-1105298, -234160, 55576], [-983785, -275195, -74104], [-213362, 84160, -37216], [4663414, -19280, 12902], [-1047116, -161508, 74490], [197372, -120155, -45043], [4552788, 528380, -63686], [6629500, 220060, -48790], [4208937, 431990, -44729], [-8881286, -65570, -95008], [-5346488, -295628, 8414], [3975085, -399953, 13856], [2998402, -306875, 31667], [1038360, 300660, 48750], [6055491, -747250, -54887], [2812370, 492208, -91768], [-5036640, 638260, -35890], [-1698804, -459700, -24782], [2194959, -163229, -43162], [-637377, 501420, 104379], [6894398, 197240, 51124], [-3313150, -86760, 6228], [1851200, 308860, -96820], [-2669098, 224137, 63803], [9002134, 317440, -44128], [3765959, -329370, 9237], [-2538902, 164755, -40783], [5310476, -479310, 45558], [10792990, -310480, -19640], [3240090, 727520, -43376], [6975830, -205720, 108988], [1632992, -124620, 15246], [-11132191, -460667, 36050], [2669800, 110740, 210590], [2041594, -1286720, -29920], [-116275, 446520, -45915], [-7410098, 67656, 104940], [-6901294, 1115, -81599], [14288235, 535465, -16], [-8830238, 284576, 127600], [-9938474, -423320, -11362], [12093800, 265380, -169290], [-283742, -856280, 35804], [-14726099, -336510, 6183], [7410516, 321523, 166523], [-8549570, -895120, -75320], [249924, -654356, 205778], [-12839943, -465193, -192908], [9095502, -662791, -144029], [-14270737, -271959, -89868], [-9185712, -790, -55406], [272294, 681880, 135902], [5593976, 397988, 49510], [-19766136, -422540, 50222], [10501998, 485200, 57800], [12387673, 52017, 6726], [2725078, -1292320, -19376], [-13970962, 42013, 121367], [-12778671, -1081140, 155757], [14073952, 439540, 19886], [12075446, 468615, 99105], [-4415136, 386530, 10682], [34559308, -706820, -34726], [-21084210, -1841480, 133172], [-13702484, -206580, 79698], [-29113199, 1402990, 31943], [2057694, -323920, 309016], [13561318, 2248090, -75496], [-28124084, -526740, -133182], [7119740, -563080, 362260], [-9696554, 39640, -219484], [15040673, 770380, 145469], [-6082650, -68560, -128936], [-43182602, 915411, 59901], [-33479614, -769664, -128128], [-32290200, 1794957, 81729], [23428395, -618280, 5155], [-11621532, -8180, 20594], [-3587208, 11940, 115926], [2640432, 2548779, -6225], [24023962, -359160, -112452], [-5763310, 32840, 304300], [-27977859, 734079, 227712], [40640476, 95580, 205338], [10718464, 115690, -185278], [1455262, -431440, -121304], [-16262529, 139819, -403714], [-7259161, -2216300, -208213], [-18589814, 88048, -349720], [6264645, 563541, -181050], [32748576, 380740, -78682], [-10170036, 1170556, 260906], [-27086636, 596780, 76162], [-49365970, -813280, 107440], [32711734, -1486857, -63279], [-18059870, -2344760, 87452], [-12109692, -2295410, -48166], [25658684, -46980, -218598], [-8260686, 986560, -403936], [-10472647, -2296430, -154621], [-3842770, 2890320, 83160], [-34719196, -402000, -485868], [8301109, 2913879, 309936], [19919230, -1434040, -132788], [-48236943, 489300, 58101], [7712028, 1065660, -208326], [17796422, 2231992, 69524], [-15548194, -570921, -362919], [51775643, -347291, 445676], [-14331334, 2255400, -87102], [45264360, -1730620, 140950], [-21116668, -2431503, 147633], [-20331006, 876800, -358112], [25024530, -2521839, 341343], [-10288976, -845420, -498178], [-25563022, -3119600, 97304], [34186714, 2883840, -471078], [30983830, -3131320, -141812], [65449948, 422407, 92999], [13448809, -1937843, -78334], [-20146374, 782592, -775104], [10052724, -1523460, -194598], [18727844, -1530000, 377172], [-18301978, 1670381, -408929], [50633369, 1637660, 262597], [15406192, -2832940, -281954], [21507579, 1858410, -304323], [-64032880, 279390, -110730], [64602044, -688724, 238226], [11693623, -3029337, 106434], [64520852, 1394585, -112055], [-51212208, 677684, 281662], [-13822804, 1825820, -21302], [50707589, -4167010, -389333], [56559790, -3735710, -137080], [58736921, 636979, 709376], [-97598303, 2651280, 137841], [46110754, 3298283, -95903], [-11855026, 2869280, 937120], [9142266, -3092840, -507292], [55627042, 3355220, -128474], [-92837440, 106305, -6531], [25214135, 523220, 223675], [76959641, -4807710, 109683], [-58133624, -5490761, 780131], [-69781604, 4616140, 33938], [105776418, -710880, -205392], [570498, 3004909, -317509], [25181812, -2420660, -430174], [70730062, -2780720, 260696], [145123303, 551210, -284951], [24483170, 3205480, -329044], [-59831685, 712401, -1135992], [21328234, -2840600, 344732], [104964614, -2839360, 106912], [50068844, -2565101, 677171], [23824181, 2218165, 804374], [87043022, 2814640, -323272], [16902310, -2691120, 59640], [-146198996, 2319740, 36442], [31451631, -2315190, -416367], [-51819418, 7514480, 143128], [-79889358, 3110960, -210200], [-16992829, -1332333, 378378], [-40732622, -5530520, -231556], [119998102, 3551040, -44880], [15256793, -695087, 1038950], [-42785692, -1921620, -1112766], [153568220, -1943560, -316940], [72491846, -3925760, -510112], [96177494, 2692275, 164925], [-32020693, -1264999, 448864], [-56715094, 4740280, -629500], [-51851948, 2360700, -903414], [65000659, -1639480, 924667], [76361404, 5236267, -377797], [-145878382, 2148530, -230276], [-49516718, -3082147, -1363781], [108385190, 3670160, -379544], [-20242649, -7522163, -68608], [177556876, -4015630, -12362], [151112800, 2639140, 577430], [74144492, 3471020, 1097026], [-73508210, 1560120, 141030], [-62413080, -3699740, 995750], [46108526, 7538168, -123020], [-17190335, -6141587, -178822], [-14247188, 8615500, -188014], [117154345, 6857080, -622015], [-59149242, 1438400, -1405376], [-33966810, 3888168, 1260732], [-239973424, 2259450, -356382], [-79055386, -5647440, 25512], [-46525411, -3197170, 502387], [-99570683, -9281319, 846714], [-147615298, 3063040, -1138144], [-28594278, 1322280, 1501596], [-110315148, -5387620, 685216], [-203673327, -941553, 899940], [60230049, -4730480, 179057], [42099048, 1352740, 1037174], [62521943, -8302399, -778988], [48462234, 1099480, 192500], [108183514, 11035380, -376578], [182926954, -2166280, -156908], [-52991452, 2422691, 509371], [50825238, 3579040, -421024], [62741130, -7732880, 1438856], [-155149131, -656137, 40912], [-20531834, 13777993, -541141], [135683798, -148200, 636036], [-50172145, -1612110, 479865], [230796364, 7211450, -401378], [-22222382, 6033560, -1873916], [-101521768, 9904132, -228586], [-177898129, -1385060, -358117], [209150742, 3939600, 455736], [-69532078, -7198464, -50880], [-13260012, 5648831, 412375], [-187641574, 4156280, 390868], [-148202672, -1797084, 1401798], [81470095, 759210, -1356015], [-64771621, 6310779, -161430], [-152808924, 8880021, 1111653], [41479308, -2764580, -1614166], [103714078, -11487528, 232452], [65470278, 859360, -339856], [34510848, -960300, 567684], [-5544083, -9807773, -243004], [-198835007, 7392680, 765769], [-77215621, 4707437, -281804], [95548998, 16628648, -1772804], [-117362586, -1658080, 662032], [33518092, -1712500, -587294], [-10536608, -3934511, -798739], [111592190, -7043840, -1741600], [-25866554, 3023200, -2723632], [80971454, -16442392, 172444], [18903166, 8621270, -882692], [112441098, -5500040, 912884], [-91995761, 3625050, 202497], [52645706, -8401152, 815040], [-397029121, 5794897, 497804], [-69482676, -11747070, -2007738], [404589824, -4697580, 329502], [-166664089, 10548840, -416337], [-99735022, 2576280, -1097436], [11644978, -13369568, -859408], [-102542700, 9304199, -32897], [-39256034, -1608080, 1573400], [-86928800, -596780, -150370], [-192329244, 5831260, 1435088], [-217506151, 1833300, 195357], [-327176456, -6549340, 502582], [81013454, -9825685, -1074035], [205700124, 1331260, 2064122], [-27995398, -1659200, -846400], [148849052, -17085091, -692987], [-120824871, -1978830, -1732413], [23076837, -1660891, -3139082], [-191647208, 9048660, 267006], [116724776, 3238820, 1331158], [195246554, 1099807, -826243], [216528896, 3509492, 1615006], [19830255, 9425880, -308505], [-45258795, -6537890, 2055995], [134005936, -10701497, 585947], [121459886, 10628264, -1012676], [-147433630, -10184570, -934960], [-406242492, -8299300, 132394], [-143731129, -16658950, 3277273], [141593080, 12916330, 1973690], [326159982, 2677440, -1484064], [-193709712, -17985804, 1407198], [30906066, -13471960, -2263652], [122003806, 8544880, -1960648], [294431778, 8061480, 235164], [-108935662, -18111411, 2453931], [-217431162, 5413680, -2572536], [381796175, -3085710, -1789575], [120519478, -7883573, -1660075], [7259612, 11406510, 1326546], [-16618918, -19189320, -1067724], [-267830661, 9247091, -408542], [106738412, 3873157, -2952355], [-370134648, 9292772, 96934], [34986074, 19998920, 1951852], [-171823275, -4408910, -1863745], [-388836407, -9549143, 2000846], [87089902, -17888690, 2336516], [-258099442, -9915360, 1248144], [-127859448, 4531260, -2177964], [-281724742, -5341760, -2014048], [-77319411, -5257120, -1995923], [-434990398, -853936, -1706888], [72723006, 5242776, -2262108], [56862868, -21520340, -1435486], [-453348948, 6966349, -1616827], [-115555602, -21827360, 2245424], [451254730, 11446976, -226976], [-576245998, -349930, -1738544], [-124063888, 407940, -3392634], [150227322, 23754160, -51160], [-339225679, -13741093, 1513888], [203893307, 7529630, 3786721], [44176138, -10387240, -744956], [140247538, -15554840, -3180676], [408631979, 5531639, -1152314], [-37295285, -15534320, 1651355], [-15089824, 6981460, -1055842], [-171268310, 1214280, 1985916], [138401908, -17988560, 974564], [-400196002, 4885321, -2365693], [-484100020, -8887860, 1643250], [354182270, 75107, 3849301], [-101709894, -2440688, -2799784], [22787308, -16826580, -302526], [192825720, -7596627, 1765233], [224638285, 15068450, 218215], [34814166, 8592000, -445632], [65865794, -18521320, 1482052], [147846321, 4282879, 1331252], [-370553508, -3505796, -1076758], [-554798663, 5566380, -157899], [-203171906, -631220, -419878]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_800_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_800_6_a_n();".
// 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_800_6_a_n(:prec:=3)
    chi := MakeCharacter_800_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_800_6_a_n();".
// 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_800_6_a_n( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_800_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<3,R![408, -548, 10, 1]>,<11,R![-59934400, -155280, 396, 1]>,<13,R![-28863000, -268500, -354, 1]>],Snew);
    return Vf;
end function;