
// Make newform 900.6.a.t in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_900_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_900_6_a_t();".
// 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_900_6_a_t();".
// 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 := [-60, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [-6, 12]];
    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_900_a();"
function MakeCharacter_900_a()
    N := 900;
    order := 1;
    char_gens := [451, 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_900_a_Hecke(Kf)
    return MakeCharacter_900_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, 0], [0, 0], [40, -1], [-120, -5], [340, 8], [270, -20], [548, 20], [1740, 10], [-4710, -40], [1496, -70], [3760, -60], [-13560, 60], [-2360, -88], [19140, 110], [26790, -40], [-23400, 275], [10754, 120], [5440, -54], [-22920, -330], [-4790, 240], [45536, 150], [-7080, -170], [-17580, -420], [49390, 1096], [20250, 1000], [-6920, -105], [-147960, -290], [67202, 280], [-17550, 1300], [132280, -1305], [238440, -1315], [-58590, -660], [142964, -3000], [-5610, 3360], [114056, -780], [453100, -964], [-101000, -2798], [-142140, 2890], [280590, 1160], [385080, -205], [-17134, -7840], [101040, 6710], [-179750, 4248], [454530, 2720], [988592, 640], [216884, 8140], [-490760, 3883], [-53160, -11340], [883838, -3520], [579630, -7380], [-630600, -650], [102614, 5360], [620520, -7895], [1395810, -5060], [352380, 14870], [-40350, 1600], [-389248, 2100], [1577440, 1324], [-593460, 4960], [-1305200, -8702], [678930, -16680], [2087080, -8844], [-72360, 15110], [-109670, 18472], [-141150, 22400], [372452, -24300], [2773090, 5224], [-773040, -9960], [1413914, 19200], [-871290, 24540], [2345400, -10400], [1655080, -28941], [274900, -26348], [306308, -24640], [2212140, -20390], [954990, 22760], [2562880, 15784], [-859020, -7980], [965258, -41440], [-2947560, -40315], [1988798, -2400], [-960840, 14340], [1617130, -43432], [-834448, 30780], [1387560, -45560], [3275460, 18040], [-3466490, 25440], [-896610, 39360], [-442520, 50745], [-471360, 58110], [-7708680, 4430], [657400, 60461], [-6393720, 14845], [-1243468, 21900], [3978420, 11830], [-2894910, 50160], [4626780, -26280], [370480, -24078], [4154474, -60200], [-2141960, 74760], [-7188330, -58920], [3765360, 99140], [34860, -153860], [-3469996, -20780], [-11767370, 14256], [-5046360, -16890], [-8969190, 4940], [-10081080, 58080], [3416726, -17600], [-6209720, -72555], [8537560, 38640], [-5173530, 18780], [-9156988, -65280], [-3064336, 35210], [3800520, 21480], [-73160, 97710], [-3061140, 11890], [-5928270, -29480], [12867960, -11335], [6868898, -28200], [18609250, 21000], [-1045830, 101080], [-14346720, 33970], [-11187652, -16800], [6248970, -155720], [-3958882, 95000], [-2822880, 7380], [-18154760, 25221], [9357400, -75900], [-4780636, 99600], [11669460, -21210], [-17051752, 21750], [-14167040, -396], [-4594620, 35120], [-11134258, -131360], [8459850, 96400], [6427600, 12414], [5101470, -58720], [-21227880, -60120], [-18439924, -131800], [-20347230, 115480], [-18895160, -164863], [-9071280, 122780], [-11147686, 27000], [-10846680, -53820], [20868280, 19968], [15763710, 14540], [1221236, 309000], [18522660, -226910], [-1756700, 117164], [-21362940, -51060], [-14612840, 58942], [14882100, -70850], [20741440, 1860], [348360, -49860], [-4340392, 239010], [-15394140, 292640], [7681030, -425416], [16633830, 87920], [-30726600, -33400], [9479610, -318860], [44780680, 89295], [9937800, -484675], [-62370, 439620], [-15287340, 410590], [-7393216, 197040], [-925340, -3960], [24112742, 79440], [-21969930, -402320], [39937800, 194075], [-2194426, 45000], [10272720, 361780], [42971890, -179992], [-2984272, -171410], [52461780, -118780], [7245116, 440960], [-26539890, 79640], [-51714680, 53753], [37292582, -242000], [32767960, -261371], [60685560, 66065], [-27520280, -293568], [12918450, -4700], [13484700, 276550], [-694170, -284080], [45490420, 386316], [-26469320, -343382], [32388278, -99760], [-25805040, 122290], [18599410, 402688], [-25650840, -262160], [-28101724, 130900], [-17254770, -708480], [49347840, -418590], [-56031510, 33260], [-1199998, -324000], [38424100, 242400], [23987370, 290380], [75120900, -232150], [14304750, 719000], [-8358952, -514950], [18092620, -726720], [31024814, 706800], [-24343800, 135675], [20742570, 512680], [32227712, 30470], [54130560, 583940], [7515060, -54060], [-48736684, -551140], [20266450, -494264], [43518870, 381880], [-2388440, 900867], [32874240, 646260], [-23286960, 442210], [85254098, -427200], [34912120, -232381], [-6802620, -689380], [53718540, -496790], [-95462730, 180480], [-35122666, 133640], [-5050432, 505500], [44088720, 100780], [9056680, -724455], [-19329840, -971910], [-37986058, 51640], [-11314470, -930780], [-65760480, -130020], [-82438520, -134819], [10396440, -293065], [-11684780, 1249328], [28663436, -1102200], [-84005536, 370060], [80888340, 403160], [28791040, 831510], [-72716100, 122350], [-12441214, 876000], [15409050, 592200], [-24825720, -354405], [46534920, -809170], [1873920, 105080], [-38410444, 442920], [-59879000, 664377], [6354602, 772680], [-96290010, 234260], [55161840, 493410], [-96051320, 503131], [8615400, 1633975], [-103404148, -610720], [-109637100, -851650], [-48147200, 1321200], [-13782720, 1210720], [98153700, 262550], [-75533038, 46320], [-65593890, 84640], [6627960, 1338665], [-47880814, -693960], [-38103080, 140730], [-41431290, 1317040], [-84271430, -1345920], [90750040, -103913], [-16527720, 1256220], [-52006186, 273600], [19399480, -1467628], [-40178670, -1726580], [-89726764, -561600], [60807030, 1454720], [13390320, -890820], [-150166160, -215790], [181537770, -707520], [-80508394, 582520], [-90233480, -1234620], [130060210, -605760], [-148386352, -375630], [-24444830, -272984], [63177160, 1598763], [181341600, 393400], [-108649342, -257440], [24758474, -871600], [-149452200, 847825], [48253860, -865610], [-49059352, -403800], [-194516820, -678430], [76589246, 845880], [-3674480, 5544], [106844880, 634370], [65562070, 1671632], [142549290, 929960], [-104365264, 2110200], [-80056680, -568820], [-159688530, 1514280], [-156726240, -313010], [5147670, 907580], [-118441080, 424955], [73484320, -1147572], [98003190, 39560], [49568024, -661150], [107795910, 639840], [44722680, 409695], [-50889560, 2836860], [-162726830, 999480], [5965410, 1067840], [-114657112, -1139720], [82660680, 606570], [-38729548, -1341900], [-73230290, 52904], [161560920, -1153170], [-107953018, -1267200], [12312480, 3091770], [-112711340, -2420460], [-195919260, 331010], [-54072150, -281600], [-169356060, 355060], [-196177280, 834028], [-317735940, 531690], [-96283162, 603280], [204528840, 1644535], [-131843760, -283490], [177225490, 1079512], [57924480, -1308980], [234619052, -224400], [126522970, 1392416], [278646690, 883560], [254056360, 1502713], [157965630, -28380], [78448502, 880800], [142516172, 1020060], [247430920, -793668], [-193004940, 1525690], [-57840090, 245840], [43561406, -2797080], [-74659530, -2847720], [42484208, -1698490], [44349960, 148290], [209914364, -1889040], [-73875480, -1906770], [130603838, 2557680], [257442030, 1520220], [-177780694, -2040080], [69975880, 4396095], [46212460, -824012], [-14691090, -360660], [-59838030, 1901280], [269526344, -2122520], [61641390, 965360], [55730520, 1505855], [13878254, -2560080], [349390960, 1018304], [-34911840, -3798410], [307077270, 55480], [-175923244, 1968820], [230253910, -645960], [240067650, -1051400], [261497560, -2273637], [-55461262, 1991880], [-293371290, 1894540], [-186385440, 2186440], [-25036440, -330685], [367203210, 917540], [-118484100, -3004650], [52638820, -2856656], [17489160, 2354340], [158470740, 1541010], [-417576360, -842765], [205349920, -1146270], [-98303090, 3751592], [-279468210, 2919960], [131871400, -2322525], [-377067514, -577760], [-408992760, -198865], [216769268, 2287000], [165169980, -485230], [-53351430, 909680], [-133536952, -1780800], [242986960, -389624], [-108277800, -3767825], [-154712760, 4881760], [-215742650, 1164152], [29175540, 1580960], [-19112210, 1694424], [97602270, -4666520], [-428419110, 2535860], [-309323000, -2038125], [314844270, 3230980], [513895436, 930300], [-108474180, 1149430], [84014744, -3573570], [452530720, -1418820], [-17301080, 2823480], [-64574580, -2800170], [-86936338, 194720], [6948030, 3031720], [-420616680, 1528055], [413491360, -1679774], [340559280, -2051280], [-476058530, -1519368], [131502872, 1363160], [354216840, 1547160], [-97103596, -1608080], [-185417250, -2119000], [-88963786, -459600], [285860010, -3839260], [-75431000, -1304789], [-715448190, -671060], [41824290, 3170960], [254220752, -4304550], [55102840, -196976], [48828180, -2140180], [-95464040, -758862], [-68709720, 3595845], [-27016730, -1575968], [292466730, 835520], [-206905920, 5365670], [314241644, 4298580], [63817570, -126784], [11306970, 7071280], [-232349040, -292460], [-668878040, -1621121], [234047730, 5312020], [365536620, 3278630], [317312070, 1368680], [-72771020, 6320456], [-312514620, 3074370], [824887320, 547805], [33817570, -4603920], [-353961030, 5456280], [-205416360, -3001890], [-120402720, -4054280], [-182038444, -5925480], [-113138280, 4757780]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_900_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_900_6_a_t();".
// 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_900_6_a_t(:prec:=2)
    chi := MakeCharacter_900_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_900_6_a_t();".
// 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_900_6_a_t( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_900_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<7,R![-7076, -80, 1]>,<11,R![-202500, 240, 1]>],Snew);
    return Vf;
end function;