
// Make newform 450.6.a.ba in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_450_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_450_6_a_ba();".
// 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_450_6_a_ba();".
// 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 := [-1020, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [-3, 6]];
    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_450_a();"
function MakeCharacter_450_a()
    N := 450;
    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_450_a_Hecke(Kf)
    return MakeCharacter_450_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 := [[-4, 0], [0, 0], [0, 0], [50, -1], [270, -2], [-445, 2], [246, -10], [296, -5], [1830, -10], [2850, 2], [-2854, -5], [-5650, -24], [7710, 30], [-3160, 41], [-3900, 100], [-13914, 70], [25260, -52], [-14563, -90], [-48700, -3], [3090, -126], [-16450, -120], [3956, 360], [-81732, -100], [82320, 336], [-26215, 364], [45750, 22], [45980, 24], [101478, 470], [84947, -70], [-86736, -400], [144740, -576], [141930, 1082], [170844, 540], [-70840, 120], [383940, -252], [40274, 1545], [220205, 842], [212000, 1915], [230274, -1870], [-339618, -770], [248760, 3128], [-25393, -2870], [22650, -214], [533495, -960], [329628, 220], [472094, -895], [-407164, 2435], [577310, 1507], [305850, 2250], [74159, 4030], [-196914, 4110], [-736350, -4526], [-791695, 2320], [37740, -2996], [-1204356, 2300], [304686, 190], [-848670, 514], [-517732, -5880], [-894145, -794], [-184290, 1246], [147500, -1553], [1999968, -2400], [270260, 3363], [313800, -9976], [-337285, 14200], [-1260372, -3860], [-1805584, 1680], [329465, -14372], [-2658180, 7260], [1024718, 7920], [-31530, 6870], [-1257510, -15158], [579290, 2877], [-1246495, 8134], [-249880, -10175], [1652700, 11900], [-531270, -19174], [1751285, 3358], [-1002990, -17838], [543773, -16460], [-2235510, 6362], [564674, 28200], [-1288890, 22230], [2883335, 10796], [-2572882, 7575], [-3563076, 4700], [-390540, 22324], [1093550, -18888], [801930, -28374], [-141940, -18168], [-1502538, -11610], [753300, 31988], [5155370, 17921], [4392240, -15248], [-5214604, 10875], [-688170, -8410], [6989460, -9516], [6477630, 25086], [1002920, 20127], [-6547597, 6830], [3944480, -35640], [-2171112, 28440], [-2459766, 9370], [4503750, -7802], [9979964, 4055], [-9712345, -29604], [14144646, -12810], [-6641502, 22690], [10172820, 29748], [2190275, -72220], [-4343860, -26424], [2658350, -62424], [2152170, -12630], [-6300820, -8745], [-3710110, 34735], [-8761620, -21588], [-10274320, 5592], [5613048, -28360], [-6280512, -25600], [-7575990, 27290], [-1921618, -9480], [-12083350, 31128], [9746814, -16930], [4905048, 46040], [5260424, 43680], [8702970, -56294], [2098991, 53410], [-4332090, 37398], [16516010, -23865], [-23563630, -8016], [-7135360, 28560], [-3448920, 12840], [6333740, 93360], [-9233185, 90090], [4998360, 18008], [-2624161, -74320], [6048594, 92210], [891560, 110739], [-4094748, 11620], [-9125850, 48678], [26380208, -19025], [-25383240, -1160], [7541330, -2257], [-20323434, -34490], [6350186, 117960], [-21616290, 10734], [3973145, -111654], [1726308, -115100], [-10258840, -8880], [38936196, -1180], [-7068115, -159526], [21082860, -125268], [9718640, 152917], [-1031148, -55180], [24418040, 71040], [-43295460, -22980], [-836542, -155535], [-39073230, -15502], [-15644365, -27904], [2480760, -68296], [-4365594, 162070], [16138200, 55640], [8886860, 132744], [8099040, 32672], [6070836, 28980], [-19233672, 116600], [-19759198, -18645], [-40496170, -68112], [14546057, 241140], [8672796, 170780], [-8227230, 20018], [-29621083, 101610], [14885040, -202448], [7856285, 71192], [34877066, 82325], [30269100, -69268], [6765764, -155465], [47775390, 102206], [21272750, -16273], [31854365, 55250], [28080170, 177115], [-16281360, -96976], [6638855, 52410], [-2385216, -261760], [-15861324, 130580], [22367880, 106952], [-36537685, 104310], [28415420, 33979], [67000685, 19360], [60722550, 139270], [6099065, -303392], [-31386174, 22610], [36729956, 65885], [-6470730, -340650], [33397458, -170910], [-29910984, 105400], [-80091478, 26760], [678290, 202032], [38918940, 308060], [27305874, -49790], [52264110, -222514], [14051516, 292680], [-9989470, -171720], [-31373626, 70680], [86021760, 75648], [-19730598, 492410], [-48316114, -237875], [-17426994, 280510], [-8906820, 298812], [-52357984, 135145], [-38566705, 324232], [6256080, 163792], [87639350, -26433], [103113912, 72120], [11527380, 155188], [74018930, -99960], [70815530, -213229], [-70941030, 17690], [-49684350, -163150], [70468986, -202470], [-35036185, -415250], [-46962850, 321945], [-41756160, 173248], [16540220, 271992], [46666398, -424050], [-18249775, -226570], [7279110, -159930], [44645040, 119664], [33401870, 99865], [-58601790, -191854], [15105995, 71558], [-37240072, 105120], [15013550, 541445], [26489520, 60080], [-56890120, 210816], [-40083456, 339200], [56084102, 422280], [52915134, 387870], [-51929100, -473772], [42482430, 129614], [33371838, 68590], [77921660, -234855], [29549090, -399111], [-50922331, -152490], [-38823048, 150520], [-126185580, 216180], [18620810, -483299], [34842570, -50150], [24598556, 157585], [44450988, 443980], [-152890390, -193176], [102138150, -378650], [1817508, 715780], [27954869, 618360], [50477202, -217870], [-96424440, 15368], [77404055, 64590], [19449680, -52416], [-34118982, -316390], [-109025350, 346656], [52660550, 219019], [-14896098, -1001010], [7693298, -511560], [-133676395, 423374], [-95081424, -267280], [-159346048, -125760], [-103418460, -43612], [-22647060, -684372], [-71846920, -701568], [15851124, -658380], [-2670355, -306010], [23979440, -550368], [-27201730, 399816], [128189618, 197355], [-64823455, -138512], [-121796410, 41391], [-65372868, -618340], [59010629, -606890], [-2674141, 647380], [-64559220, 220396], [141466398, -320530], [-94316500, -551880], [51040362, -175910], [86129177, 679650], [-149518720, 570639], [53178540, 1090508], [-25489495, 119288], [27161406, 1387870], [-76255348, 66720], [147890430, -722306], [-85078380, 431124], [213887772, -282820], [-30171612, 423460], [31421940, 796628], [-34775755, -191034], [177951870, 411614], [-19445002, 375475], [119989254, 345510], [64790970, 79050], [-109844680, 608064], [-115849990, 461472], [-59505072, -880880], [-85285894, 795275], [-168404064, 102240], [34885448, -780480], [45346505, 181904], [57126396, 401820], [12235115, 67350], [85878330, -100182], [127892990, 162744], [-24040134, -283670], [205819740, -561188], [80196240, 832336], [-175432360, 434101], [101213418, -1171110], [148758773, -305200], [114718050, 1395442], [37722000, -1273520], [11572385, 302644], [14281050, 1846042], [99592016, 263280], [27940595, -1443016], [-35488770, 1312350], [-51204310, 1747387], [-239525604, -262500], [115406390, 187800], [162486800, -166485], [-334823560, -115593], [106273506, 1263890], [-1533426, -1447250], [86367227, -376470], [54978504, 399240], [193495094, 265435], [-40032546, -1151730], [-224968852, -503025], [-74937432, 1799400], [-163571971, 1362450], [206670306, 817890], [-68281387, -665260], [-119868100, -1790856], [392580065, -401954], [-200426814, 357570], [-57023790, 200178], [-189603274, -621775], [22040730, 749050], [-140605440, -849280], [-228736729, -2550], [-27923500, 600335], [162232470, -346010], [203246844, 513020], [76065344, 2148995], [169066190, 474072], [125532390, -1016570], [154795070, 1814517], [180050345, 795810], [-110959116, -1967500], [66716790, -1349306], [219461550, -815458], [-209217678, -1312910], [468966966, 371910], [402190985, -502046], [117356820, -1258284], [-180612882, -1497090], [22545180, 1147708], [10779680, -2066352], [382131635, -538516], [86418648, -1647720], [477520580, 379032], [148408163, -345460], [215731080, 940616], [-226980376, 1880585], [36428670, -1035890], [-166433100, -112204], [-245604268, -1143240], [348409115, 1300654], [-252267810, -105458], [-387296100, 2428], [504103895, 568448], [-199740240, -594256], [448681085, 223944], [482829660, 589852], [151648626, -2185550], [170295140, 2073912], [342487038, -977410], [-235692280, -80400], [162302616, 2411480], [-273214438, 1639755], [98199890, 1992744], [93879200, 309456], [-97507002, 1045590], [74430473, -1721840], [-212039706, 1020230], [-326739630, -1154974], [28848320, -3203387], [325126860, -85524], [91599365, 1479708], [493721222, 862795], [92008110, -2752146], [114582728, -1993735], [-524987100, 274340], [-481665178, 1284840], [-310892622, 1329970], [-230308210, -2740259], [-34012962, -629410], [-55248510, 1384034], [-15662140, -2608680], [259589675, 934954], [-140517690, 3468038], [-396709480, 1654443], [-109968900, 1774428], [-165102385, -118148], [-124645896, -2580680], [-665618316, 755860], [-214516408, 2635635], [108129725, -1225756], [-292608480, 1818976], [-270396300, 1724692], [-278223190, 2367049], [-110262726, -88390], [-380867922, -2198210], [-108957900, 3939956], [14016785, 1486274], [361756452, 554820], [-102730200, 621608], [-125876230, 2435232], [212707950, -373170], [407059350, -168570], [18033990, 1148806], [1239560, -2160855], [664811730, -1336510]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_450_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_450_6_a_ba();".
// 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_450_6_a_ba(:prec:=2)
    chi := MakeCharacter_450_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_450_6_a_ba();".
// 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_450_6_a_ba( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_450_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<7,R![-34229, -100, 1]>,<11,R![-74016, -540, 1]>,<17,R![-3612384, -492, 1]>],Snew);
    return Vf;
end function;