
// Make newform 225.6.a.j in Magma, downloaded from the LMFDB on 25 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_j();".
// 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_j();".
// 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 := [-31, 0, 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], [51, -24], [6, -88], [527, -96], [858, 40], [2107, 168], [222, -648], [-2034, -56], [-1299, 936], [2206, 1776], [-5616, -296], [-4225, 216], [-1230, 3328], [32532, -248], [31962, 3008], [3655, -1008], [30867, 5160], [-49152, -6200], [-13282, 3408], [42000, -1920], [32886, 768], [-51552, -3168], [34687, -22080], [-58884, -5448], [63940, -9744], [-64860, 22248], [100997, -2832], [-17124, 23488], [-4888, 54000], [11340, 42888], [-194178, -13584], [-233212, -5328], [-125946, -944], [-51353, 40680], [-163427, 20784], [175621, -27480], [-264396, -13416], [96126, -65592], [-113910, -14320], [229361, -11424], [436866, 15352], [171109, 73392], [577086, -48], [-239909, -45576], [-295549, -15864], [-46013, 66024], [580704, -44776], [247953, 131472], [163680, 26184], [45348, 265832], [166729, -168672], [667908, -47760], [593820, -19632], [1403304, -76120], [-591582, 285032], [-910856, 171888], [891219, -8352], [-74118, 94776], [-1352823, -183336], [-77466, 322560], [2219945, 120792], [-19374, 234192], [1420981, 162960], [1521000, 241328], [989052, -171600], [-985801, -35472], [2016018, -185600], [1598074, 407136], [-1357122, -310104], [79512, -264792], [69669, 23688], [-1936675, -279744], [-3101015, -47880], [4139124, -109200], [-4606248, 198888], [-646135, -633888], [-117780, 181608], [2735093, -402288], [1280268, 662632], [3019318, -709776], [714714, 198024], [1419101, 214800], [-2816915, -38520], [1768728, 306576], [-1495716, -724624], [-707734, 383136], [1740108, 444840], [-2395560, -321264], [-546030, -147592], [1859250, 28320], [7792717, 51480], [-1623480, 95008], [2845147, 72408], [-8044152, 511976], [-5225958, 49328], [4130034, 234904], [6748865, 411816], [6655581, -121344], [-8184904, -241104], [-4335702, 94560], [-4014834, -1840152], [4981578, -701928], [-2187181, -1286712], [-5661443, 1670880], [9415140, -314232], [1553880, -951496], [8830404, -956144], [-8858461, -1342032], [5550392, 799200], [4652414, 600672], [1145172, 2589336], [718823, -1826808], [-4308263, 138840], [2683524, -2621136], [-9251700, 104016], [11489988, 119680], [-9823566, 1678880], [11722080, 1409960], [-8181398, -751200], [-8370582, 1837008], [-9583614, -1809528], [10939464, -157440], [-4956056, 1957488], [-3649950, -1103672], [4219657, -46992], [-14133366, 442056], [-5968997, -826776], [-24836270, -579744], [7175308, 2617152], [-856740, -2881376], [-1325576, -423792], [609863, 2736144], [7101492, 671616], [-11396269, 2866704], [-2901936, -1982760], [-41335, -2939448], [-23040540, 1046288], [-4967940, 3840280], [6324987, 1991640], [-4319598, 4189056], [-21056441, -277368], [-3685572, 3741160], [-19691310, -1834560], [9384030, 755080], [-15957939, 1167600], [-19430220, -3890192], [23646520, -347760], [4451520, 2056304], [22620981, -2192784], [33560112, 1228496], [6360295, -2260584], [12012030, -3598272], [-3202860, 6255072], [12883338, -2398240], [8881255, -3881160], [5866218, -5062328], [1850049, -8536272], [-15943446, 4105984], [28476102, -3834024], [-4343112, -4040864], [4178512, 1081440], [-8577066, 2177904], [-23974062, 4322800], [-12662748, -1639008], [20281937, -3763560], [-7617402, 1297824], [16771925, -4160640], [43905186, -517072], [-25561002, 810552], [-14137685, 5567232], [-3853998, -8726544], [6943371, -3082320], [21861739, 1455336], [-35066832, 5783952], [-25633749, -216264], [-23365254, -375528], [5216995, 3385656], [2308555, -4778160], [1195951, 2971656], [-17486904, 2299072], [4311359, 3381792], [-11088390, 4445888], [41029050, 3045504], [36053130, -1395040], [11241087, 9457440], [34711997, -239736], [-31898491, 2056656], [-25501818, 7435976], [-3508465, -12638064], [37439016, -121352], [-27843075, 7536072], [34577826, -9910408], [-25494222, 786600], [-37081554, 4910528], [-3602906, 1400688], [-64172886, -1304928], [25152570, -3205392], [40651734, -187480], [-76074456, 1439736], [157740, 1574832], [45217734, -1295232], [-61006598, 3240528], [20400324, 257376], [-63164046, 177624], [-18641293, 5843928], [-18619086, -12191240], [-14178156, -13776624], [14538293, -14048376], [-57742067, 8573664], [-11344122, -2168480], [28107783, -6888792], [-502812, 9567520], [7750062, -2979552], [64305590, 4195632], [24051083, 12390744], [86161230, -1652952], [-50700384, 2018552], [-11988210, 5544504], [99833653, 5067264], [-43310041, -3786024], [-10475010, 15410400], [-80041456, -7786128], [-33771600, -5631832], [-6131005, -15169440], [-66552126, 11584200], [65017878, 10299952], [91997045, -7448568], [-7949298, -25099944], [-32519637, -4320672], [-4381028, 19069968], [-229681, 2994888], [-35675430, -2168992], [-46925036, 19142832], [22001928, 8239200], [-7269486, -5366064], [23243724, -22893880], [42971598, 6012672], [30662460, 15730968], [6934266, -4575432], [-40321827, 7091544], [-10061299, 7533480], [89042031, -8669616], [-69929946, 6843360], [54460602, 14120768], [2191849, 3270408], [-4891146, 13038584], [-11717227, 24324552], [94864014, -13999040], [18779066, 8755776], [3616038, -3530440], [88601724, 7090224], [-22478067, 7367472], [-37550886, 1973720], [-2192964, 7214784], [85215877, 4772400], [20020012, 4962000], [-62989644, 23045592], [-154289246, -6810432], [-95921905, 19798056], [80379054, -7447816], [69949574, 21613056], [-36244011, -24523488], [17346858, 8940960], [-67403144, -22908816], [14228598, -17551888], [98398680, 18776848], [134948548, -2647872], [-61986294, -16507952], [-27005437, -15088896], [33146840, -34897488], [77106406, 15360480], [12516609, -16249464], [127731495, -18811488], [2764711, -1639560], [-139997634, 14070432], [-15241605, 43657920], [-90512721, -18489072], [99446304, 8569584], [-99057528, -22282648], [-107020952, 2737344], [-31350846, -39410296], [34938879, 7958928], [-22091535, -11908968], [99984414, -28171776], [-94479169, -14280960], [-74251128, 7799976], [-200123656, -2957904], [-71161080, 24304440], [-112687074, 30996592], [-109331580, 5510768], [-114812676, 7653360], [-57135288, 15469296], [-170889479, 11852880], [-164015160, -10164840], [64851437, 22308840], [-16669152, 21563016], [-46838250, -23880], [-265829252, 3960864], [140567994, -655968], [21267012, 36579616], [170870809, -13786824], [-24639414, -40861392], [53912500, 11479872], [-197659013, -8042160], [-74452740, -41571792], [145507637, 2966448], [-119897412, -28889208], [215352810, -9452064], [214314930, -17396856], [87091668, 14986032], [-67186956, 4870944], [-79861229, 6035880], [15369150, -44745592], [-145537223, 3191568], [-171725514, 9108504], [107348148, -3235200], [-81656937, 266208], [113684826, -35709816], [244190576, -16960464], [287694781, 18542976], [-149923164, -48404968], [95576195, -12132504], [-98951790, -56169456], [-57902486, -11215632], [-57494725, -6642120], [95740781, -35902920], [-83539398, 29053416], [111596976, 56060488], [-77454243, -20622480], [23906718, -24568640], [69972785, 18814680], [179508678, 8301176], [-66493405, -38407848], [93043572, 38457536], [-287296249, -7247616], [223976316, -1929832], [190001525, -42524928], [186436032, 47504640], [4744625, -28983984], [173885664, -26706856], [354009942, 5283528], [348594867, 12201960], [51916446, 34828408], [-341261310, 12679920], [230149325, -5485728], [-447496891, -10686072], [-55029636, 32517624], [175531596, -10928368], [-291184341, 19377048], [96973494, 28342848], [-67448526, 55066264], [49281737, 11992104], [297891507, 7863888], [342229206, -17429232], [-491354112, 2082232], [-195715818, -53942424], [271408146, 23050872], [286779126, 14066008], [201405557, 30621840], [60992202, 22527056], [366410946, 5763192], [-97834368, 21403088], [-105308300, 13566672], [148879733, -76572432], [158111688, 19466400], [468857844, 4822512], [252950879, 41894928], [113847252, 47545056], [-127202763, -34078392], [-257285358, 492472], [-338108652, 50382672], [-204736392, -35181216], [-92258089, -12523584], [-111342312, 54979352], [189087750, 58576128], [-99263423, -21134256], [-37278276, -20711424], [254172875, -45916128], [314905818, -26528720], [201942990, 26397624], [-96397096, 25999008], [67716528, 13620680], [-4556676, 62810496], [257735010, -48322736], [-54234907, -24070776], [39405130, 18521952], [-159939540, 45364176], [-472728630, -28062312], [-126982227, -19027488], [300851256, 22691368], [94882596, -2453656], [-214193789, 41383416], [271272750, 35107328], [-170376449, 25601040], [-126945115, -61499640], [64908612, -93013512], [27376621, -53163384], [91425732, 112734576], [165086506, -11744016], [108714828, -46223304], [-158664979, -103445784], [-13248396, 74877224], [-37520052, 30033832], [369489736, 50213376], [-618024353, -30709440], [-719360304, -11632328], [-85664139, -6303000], [383877492, -56386032], [-69948663, -2919696], [122019660, 85292448], [-342097878, 29687392], [337182459, -16816152], [289661635, 82451952], [381983172, 31588736], [-647615322, -27608288], [250864445, -4352328], [621043344, -25971336], [659745228, 26119496], [49230024, 2532976], [267509369, -658512], [56921886, 103512672], [-233525658, -49568752], [363052642, -72366816], [95360280, -49429592], [-261098808, -62630488], [279864300, -38929320], [-37217011, -23330232], [289868742, -8554312]];
    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_j();".
// 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_j(: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_j();".
// 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_j( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_225_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<2,R![-22, 6, 1]>,<7,R![-15255, -102, 1]>],Snew);
    return Vf;
end function;