
// Make newform 800.6.a.g in Magma, downloaded from the LMFDB on 25 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_g();".
// 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_g();".
// 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 := [-70, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [0, 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_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], [-4, 1], [0, 0], [-52, -1], [160, 10], [50, 40], [-290, 40], [360, 40], [-844, 97], [54, 80], [4920, -130], [-3270, -560], [-5310, 808], [-12836, -579], [-14148, 383], [-15670, 1080], [15400, 20], [12270, 1184], [-17292, 495], [-6200, 2990], [3590, 3720], [35920, 220], [15964, 2817], [-20374, 3280], [95070, -4840], [40782, 8560], [110244, -2395], [106452, -6837], [72030, 5776], [63230, -80], [99548, 15487], [-98240, -12810], [17510, 960], [103560, 14260], [-111610, -7632], [-148920, 19030], [-198430, 720], [269644, 7973], [-207172, 2363], [284050, -22000], [764120, -1340], [-172322, -10240], [80680, 32890], [-101490, -44600], [459530, -3720], [645040, 15000], [-63360, -48610], [474196, -31619], [-594348, -12489], [-303074, -17120], [-976970, -2600], [1498160, 9380], [-400070, -47224], [391040, -24790], [94030, 14800], [559604, 31769], [-103650, -48960], [-1349880, 410], [519290, -16240], [422370, 36664], [1781756, 36605], [1690490, 45280], [809108, 7791], [58520, -71590], [-2326810, 48400], [-1544110, -71160], [-1396400, 90790], [2385390, -43600], [-1229292, 171411], [2270326, -11520], [153310, 222320], [1255920, 113800], [1038092, -167741], [730970, 187440], [-12520, -301760], [-1310764, -174771], [802070, -71296], [-3492910, 7400], [-4080382, -85760], [-216510, -184072], [3989720, 172780], [2684790, 21808], [5628520, 34530], [-433490, -86280], [-1643760, 209320], [-4826036, 25697], [-2543750, 93160], [2353270, -99040], [4934518, 65840], [-1610956, -27907], [-4469692, 158731], [171760, -375220], [1398972, -4213], [1764960, 415930], [-6139160, 56040], [-7681436, 74077], [1741014, -242400], [-1099478, -511360], [1847836, -493251], [6842278, -329840], [4203892, 28479], [-2952830, -277040], [-6775044, 380985], [4242530, -159464], [-808240, -137730], [4197390, 82400], [-784508, -621785], [-10933970, -211360], [-6910560, 273900], [-1649790, 354712], [6400092, 240895], [3537130, -422040], [291510, -711720], [-12507560, 125160], [-1418360, 477590], [-611990, 467912], [-4662964, 337813], [-3917508, -23685], [8584290, 381240], [-8556200, 247060], [8997990, 406048], [1789470, 228200], [10160170, -188120], [-7857796, -825211], [11879120, -458750], [-9296850, 465360], [13396574, -676080], [4976880, -915100], [-11293172, 877623], [1210850, 1122400], [566360, 1385580], [-8396444, 547685], [12415160, 660390], [-11456070, -857920], [1305082, 636160], [-17396846, 72080], [-6524790, 1231480], [2374372, -405933], [6483090, -748680], [-10601526, -391680], [9643360, 517450], [1729030, -107984], [-4424044, 289705], [-4538892, -38885], [571630, -1280864], [-3649600, -271220], [-25759430, -324680], [8451990, 622320], [14245960, -70260], [11165156, -1000783], [-19481390, -135200], [29197770, -389576], [9815836, 812673], [20124908, -266049], [19116548, 1054119], [-23667560, 152350], [4193280, 184420], [-5231110, -1726232], [40102390, 435400], [-1529002, -2284000], [9503828, 1083903], [11427750, -370400], [15568972, -1985073], [-37438160, 44510], [-34004530, 143560], [41753844, -261215], [-335080, -1678650], [-3989670, 1257960], [20247746, 545520], [-17807910, -576760], [-3172520, 1346480], [-12449978, -204960], [-8556360, -18630], [36676070, -1187560], [19841920, -2082280], [22346154, 503280], [18142320, 1980790], [-10110578, 2105440], [19623636, 999889], [-40421570, 752256], [-21548948, -1597117], [-29280320, 185590], [-35650630, -67320], [-4078970, -1736920], [25544196, 1878321], [3811246, -2323280], [371410, 214160], [2857996, 1535861], [-3054350, -1999080], [-35115880, -2588810], [30670670, 1922880], [-2945236, 1364321], [56523920, -1013470], [-40173810, -1915872], [-249308, 2923019], [15811670, 2500520], [37662730, 2985496], [-19650830, 2079880], [-23265090, -344160], [11235364, -5439563], [-33932314, 1606000], [43115560, -1445390], [28628330, -2219160], [-50485854, 2491520], [-18071960, 1284940], [-5876830, -3123040], [-41817280, 818880], [3520396, 3501541], [32576026, 4225680], [34766000, -3116930], [-48259010, -1334440], [-38577690, 2974832], [8344564, -3289439], [36438852, -501409], [-54380480, -2934900], [-14313950, 3962280], [40491228, 1979063], [25546978, 5292160], [-35942852, 2600819], [-40180190, -631240], [6719350, -1934880], [-20707680, -4813460], [-106800046, -2188720], [-69831356, 1423793], [-25337148, -5847477], [8509510, -1993408], [-14042570, -962440], [-44559840, -1186040], [65598092, 1936399], [61782480, -4052010], [-39687950, -2074760], [-128760920, 1466840], [97514600, 1580010], [22520530, -7570184], [-77241044, 468897], [-46777892, 3109415], [-18095830, -2917816], [767370, -5230200], [-33800840, 3656120], [19822680, -5161230], [-69270436, -3777039], [33425600, -5610310], [-6550044, -4710763], [-33902426, 5227520], [45706990, -1728720], [16264880, -7738240], [64053308, 2629575], [36880080, -86310], [-86653880, 4419460], [-81333036, -4108299], [-107526750, 3475080], [-129433278, 2274240], [-93126148, -6496309], [59114850, -7675080], [21538930, -3477280], [50405960, -2400160], [8373118, -5663760], [39340948, -1053421], [76349610, 4199280], [13810150, 4155200], [2492196, 1589521], [-131217708, 296615], [-6187554, 11396320], [93935570, 2052320], [23426030, 6206360], [-114676280, -4767160], [32723526, -11183520], [93366122, -857760], [-37879156, 3604113], [10742010, 3963120], [23832182, -7623040], [172566148, -2063973], [-194932890, -419080], [-15126720, 2674320], [-176075650, 2806880], [167765156, -4200675], [-166461052, 5633599], [-142290154, -5064880], [6931250, 10461080], [-73496800, 2861270], [-7767964, 7956433], [76695160, -12155830], [-151499828, 5856327], [-64504722, 13630560], [129136452, -5084937], [46553880, -9093650], [-138051490, 6311560], [152422970, 7773640], [-99476640, -9124100], [-234632150, 283560], [117621790, 9718448], [87918372, 8611347], [-151609290, -2579400], [-57168640, 13329490], [258442290, -116000], [-103805810, 11934608], [101545400, -8141490], [-7779990, 13311040], [40112280, -3263280], [45730148, 1903019], [-88327770, 4607680], [-128324910, -4281360], [-127708880, -11235420], [20577036, 6608493], [203790240, -2749150], [-166600450, 9873960], [-99517052, -9046441], [-157131226, -8312880], [229970800, 5316160], [152788570, 7862320], [91233236, 8274709], [123798926, 13268480], [-146771502, -3644000], [41503356, 5311057], [-102222852, -8019573], [49439546, 5211120], [349012680, 1413520], [-39657160, -5905330], [-136453490, -10295600], [-106437190, -4639128], [134347440, 3248650], [244949590, 232160], [104211630, -15099104], [57545204, -8949931], [47632390, -14117200], [56624730, 12336616], [123852520, -3801120], [174654764, 6796041], [-200422308, -7961601], [-16304870, -16615800], [55299710, 5986352], [-172297150, 7626080], [194677040, 379660], [4325244, 4255713], [16661600, 4250250], [-216577548, -1830357], [-182517810, 15799408], [189255950, -9885120], [-58035150, -24706120], [262658508, -6224829], [-201215030, -12619200], [113752070, 22074880], [385196790, -4246992], [234107080, -8418050], [809490, 846160], [42740040, 13259720], [210968790, -6731872], [214218228, -13206317], [-130396680, 13084950], [-2397830, -2591880], [187305760, 4492990], [335060470, 1780240], [62954910, -11220288], [287312164, -172119], [150109326, -12090720], [41320950, -596280], [-15801520, -3836140], [-321010000, -11123410], [-247844050, -7841080], [5070756, 16313085], [-129926950, 24241320], [-133112198, -19932800], [44763052, 6838331], [56377320, -15914940], [537101252, -1390669], [46712630, 125000], [115636530, -15755880], [380697044, 9219953], [14405810, 12872392], [-339586080, -10271490], [-267978920, -10466600], [23976564, -26791203], [31002470, 14152624], [179155720, 27471510], [105314850, -9373880], [-92155160, 7907240], [-213390440, 7364390], [-336493250, 6787520], [-238249270, -20283704], [206553750, -9755120], [-216940218, 7601760], [28625670, 9554640], [68183852, 36045711], [-270539970, -10765440], [76763080, 12840520], [-23402764, 19757113], [170103080, 28622370], [-32593110, 13445840], [-136856596, -3396631], [39933052, -20881097], [283364810, 7924712], [-137423030, 15721520], [-45876760, -16394260], [54850628, 3993163], [225232680, 19235070], [81790070, 15571200], [-485122480, -2515100], [402522314, -14232000], [607495360, 2115330], [-106433530, -2990336], [-249981170, -11959504], [34464750, 42241080], [-499133748, 7789091], [-33680650, -2803840], [58100630, -10440544], [214087880, -30998690], [3787970, -6070440], [233381122, -7428960], [-223411556, 7581473], [-550275400, -2052860], [-114271090, 23715600], [820050250, -376720], [-450078404, 1883981], [657986880, -960570], [72642950, 8611400], [126451318, 21227440], [-48263680, 2105680], [78686748, -41231261], [-353436850, -29469160], [-234482364, 1782453], [322233710, -17027488], [-180765750, -21650360], [-261457828, 9154087], [-454828280, -26052660], [131296790, -20787680], [262795570, 29740880], [-81738804, -22087139], [-378122830, 24922904], [65780880, 23909950], [-507634480, 7940200]];
    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_g();".
// 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_g(:prec:=2)
    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_g();".
// 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_g( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_800_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<3,R![-264, 8, 1]>,<11,R![-2400, -320, 1]>,<13,R![-445500, -100, 1]>],Snew);
    return Vf;
end function;