
// Make newform 225.6.a.s in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_225_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_225_6_a_s();".
// 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_225_6_a_s();".
// 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;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    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_225_a();"
function MakeCharacter_225_a()
    N := 225;
    order := 1;
    char_gens := [101, 127];
    v := [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_225_a_Hecke(Kf)
    return MakeCharacter_225_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 := [[3, -1], [0, 0], [0, 0], [-98, -4], [123, -50], [196, -32], [813, -136], [-1555, -70], [774, 12], [1920, 80], [2, -1100], [-818, -384], [-13677, -400], [436, 2128], [12108, 1544], [-13866, 752], [-6960, 1960], [-13198, 2000], [19237, 1586], [44148, -1000], [35701, -1112], [30230, 5020], [46719, -858], [31185, 10440], [68542, -10944], [-43902, 14400], [-122684, 9048], [79173, 1554], [-121690, 13440], [-2121, 10832], [-178178, -2324], [158148, -4800], [-8307, -35616], [-42835, 24210], [-225600, -36400], [-81598, 10100], [22702, -44304], [-69779, 40818], [190188, -8136], [102024, 22512], [-438105, 23230], [284402, 18000], [230898, 56900], [-46589, -20472], [-543042, -19056], [-78700, 12200], [180827, 88350], [514276, -78312], [53628, -49376], [-59020, 51520], [883494, 16992], [-35040, -140960], [-235423, 17000], [257373, -81750], [916398, 136704], [1402854, 28732], [-210720, 112720], [1663202, -63100], [-1161728, 94976], [240498, 45600], [1080781, 20858], [1834614, -122928], [1285927, -139154], [-1753902, -105900], [-997754, 147168], [19788, -154736], [-1396423, -220550], [505357, 136816], [-1177467, 364994], [-413050, -257200], [467334, 171552], [988290, -156540], [-2526788, 217736], [184726, -600512], [419855, -135730], [595494, -557508], [204210, 515040], [3149692, 26656], [1831923, 142200], [11285, -122160], [-3821145, -207730], [3288452, -157600], [-3237102, 377700], [1035331, 426808], [-810760, 451760], [720639, -280578], [549375, -443000], [-3283073, -385904], [154548, 644400], [-5039804, 324968], [-1150212, -412736], [2503170, -75420], [-4667618, 359916], [2819748, -521200], [5912900, 143600], [3702084, 670552], [7746990, 45760], [-1936077, -378400], [-469649, 633238], [-542848, -285200], [9245767, -423794], [-5585652, -206496], [3125304, 427032], [-10264545, 541920], [-6118348, -736800], [5623597, 565776], [-758457, 1671534], [-5902761, -64928], [2626050, 901700], [-2271373, 465000], [2282752, -1161104], [3999346, 1113568], [-8960562, -155136], [11509220, -114720], [8212802, 1312100], [-7498602, -129600], [-5896364, -1459072], [15888108, -646456], [-2889066, 1563952], [11410665, -292790], [-5822848, 994400], [-9718874, -682912], [-2629872, 1722624], [-18089631, 733242], [-6206023, 1378850], [7280148, -1608400], [2828660, 371840], [19262430, -678180], [5493472, 685776], [-1602044, 2039808], [948740, -1468240], [561414, 865772], [-4339648, -2185600], [-16629248, -1101104], [8815923, 728400], [4869845, -1263720], [5624424, -2595888], [8473132, 566416], [-17778342, -976256], [-13220610, -564640], [-3843148, -1248800], [11404998, 2810400], [4860676, -3170712], [-4283097, 324974], [-327820, -3033680], [-3899040, -1930960], [-15262634, -86752], [-6214227, -95296], [-5016115, -274510], [-8079096, 3112432], [-9829028, -2066224], [10884498, -4366400], [24226831, 966558], [5542668, 413784], [-11164148, 2055296], [1481748, 2198200], [24494870, -2975620], [-7420830, -3521920], [7254157, 3463016], [16575348, 1863200], [38949408, 996744], [6196809, -550048], [32202112, 12336], [-17656677, 733950], [-1049847, 3261224], [45833094, -1359108], [-21027898, -1950900], [-20559908, 5482256], [-34087915, 3344040], [3520104, 765232], [19891305, 4011570], [30850802, 102800], [-6059502, -3501900], [9828181, -898792], [25846040, -1683040], [-20386575, -2761800], [9159227, -349850], [42889698, -1506000], [25849096, -672432], [-33032830, 636080], [8503132, 907416], [-43534977, 575150], [40567186, 3524128], [-893217, -2029256], [16782084, -1439448], [-2430660, 3714160], [-1941938, -4294864], [-30849749, -635162], [17694905, 5184720], [18487248, -8288000], [18173041, -827552], [35991579, -574618], [-6728773, 2176750], [17497698, 7908400], [48049893, -2086566], [23355114, -820928], [36207827, -3239200], [19283446, 8427968], [-66320037, 1054464], [37169574, 1679212], [-51522930, -4570320], [12192452, 3638200], [-2096768, -1491184], [-23172925, 2106800], [32476140, -3320640], [21650778, -4999776], [30031730, 7204020], [11122644, -4279408], [-32249790, 10883040], [-35656048, 3171000], [-27320258, 3233856], [17112198, -1709200], [54320416, -415552], [47833473, -5596246], [-27875970, -7677780], [-23357023, 12732000], [71262622, 4138876], [8988723, 6180600], [30613038, -4005236], [-66697326, -477888], [-45707698, 5387600], [-37425100, -10217400], [45411615, 620760], [21194626, -5686412], [93892353, 5238274], [30053030, -3983280], [114546519, -1506408], [64184160, -3036160], [-7573508, -14531144], [-90636327, 2556450], [97698166, 3910448], [108408335, 5380790], [40620002, -885900], [47060673, -3408200], [19779856, -2525592], [-23350482, 13254684], [87146165, -8212040], [47748264, -11581328], [11557125, -13017750], [-9853452, -9996600], [-95249151, 1952562], [45071927, -11565650], [32226886, 13526428], [-35389900, -2489600], [-17400141, 12211152], [-6620160, 14088160], [4411162, 16032036], [52943748, -6569600], [-5390545, -3501330], [-50152056, 8015792], [87232192, -1479344], [-15369627, -4064000], [-6902802, -940596], [20100035, -20179160], [-38275896, -11528768], [118689705, -1591830], [-122486848, -3836800], [-74639903, 13579026], [65451618, 2215584], [-9156773, 12277296], [-69542654, -1161932], [3363, 9684814], [30101720, -6372720], [-21675164, -24848272], [-68327667, 9229944], [58850225, -15224350], [124747890, 4273360], [21298098, 4308800], [51317551, -5491962], [1670394, -16453408], [153739652, -10849200], [-26756183, -7501094], [-206577959, -906552], [61495160, 12409840], [131471422, 3464576], [-55652444, -11658792], [-125319807, -2673366], [-132969160, 13950160], [42707102, 6750400], [67928823, 16176750], [172543524, -186488], [-106479898, 446300], [77783208, -11577056], [98352452, -14314400], [44918437, 11535386], [212361048, -3830400], [135177826, -8410112], [-18016272, -28118976], [-115432720, 756720], [129886110, -12975360], [-117542202, -13916800], [-169278852, -2187296], [-47986821, 541032], [-13480227, -12008550], [98473156, -6493392], [137581650, 9285600], [175464002, 1894500], [-76837176, -6000288], [-113088780, 14483280], [-21198143, -21722934], [7547911, 35882528], [-174317442, 5655344], [-70838800, -20009200], [-147192291, 27461802], [-259364773, 9876950], [190359487, 9465336], [-246620772, 4815024], [26316230, -25530480], [113801310, 22142940], [-161269934, 23450048], [141793254, 262332], [-7193970, -6557280], [-92604177, 21851400], [-68979344, -23908392], [42898668, -10616216], [7543190, 14754560], [-47958525, -14363850], [150167448, 13056000], [89273521, -25083232], [-102520755, 26318880], [58352852, 5338800], [-19659293, -27572784], [-159114252, 27320800], [57098086, 34627228], [133070634, -28381248], [99000002, 16368800], [-135735445, 27911070], [-99961484, 4544848], [294272298, -1109196], [226073604, 8449232], [40608452, 40536400], [310758618, 9861584], [-279537610, 10690860], [-399323811, -8331878], [83801177, -5522550], [-83315712, 36574264], [-45507880, 22844880], [264407874, 1678912], [-320190673, 1582200], [-267383618, 18241916], [-240280664, 29519728], [351111633, -12415856], [15939090, -11289840], [152885852, -4467800], [129771894, 22192592], [11055060, 29713440], [-71939548, 8856000], [87437317, 19684906], [194193648, 29043600], [137427198, 27651904], [-72821473, -16629050], [186870622, -18310624], [40878498, 809600], [57298756, -20937992], [393528290, -13105040], [329412339, 1958472], [-185230500, -2953000], [121799223, 41587350], [-119732562, -2939136], [309902124, 16625912], [4431982, -48067184], [-83029827, -38909000], [-217453842, -37818756], [-76549260, 42267760], [-56965463, 20019786], [-277709099, -22454312], [-25246872, -3761376], [83391016, -605152], [24459077, -7329600], [283521348, -46608000], [-495582835, -529790], [142121964, -6415528], [48442500, -2022000], [79681952, 15032800], [-151706198, -7813904], [30184395, -62307770], [489481398, -788100], [445584661, 1824528], [215007615, -42303240], [-145170338, 39869536], [-160094202, -1356400], [19155969, -20482608], [-66597608, 58663456], [105277623, -64950896], [336944360, 303640], [68090754, -42602668], [398692352, -510000], [223749472, 8683776], [-157674344, -30908392], [88428618, 18060084], [-295663285, 3402160], [21959364, 49511072], [-153752475, 15207850], [-405441023, 15807546], [251192598, -63446900], [-112044029, -59112432], [46504820, -64105320], [-71074305, 14491680], [132423677, -39415150], [-643573602, -10827600], [-114872200, 53475200], [-241746291, -15155448], [294724612, -10036664], [98538153, 82772224], [25606560, 44991440], [-21889048, 69644000], [-171302258, 34925856], [374048598, 9718400], [-513536684, -3681952], [151227405, -59748030], [213169681, 3502208], [466415568, 1968384], [60147039, -43852978], [192215252, -11066000], [530323177, -8972904], [-265986102, 14042800], [-101863230, 45210980], [-194176418, -33771284], [73806633, 63657144], [486822534, 26245852], [584077440, 26172560], [298358962, 54396736], [-214957422, -29534076], [269794185, -12445310], [267666091, 42213648], [119419248, -29552896], [-548876496, 1545832], [-122197995, 4026120], [-441467623, -50370150], [-482325150, 59764900]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_225_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_225_6_a_s();".
// 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_225_6_a_s(:prec:=2)
    chi := MakeCharacter_225_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_225_6_a_s();".
// 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_225_6_a_s( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_225_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<2,R![-54, -5, 1]>,<7,R![9036, 200, 1]>],Snew);
    return Vf;
end function;