
// Make newform 1080.6.a.g in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1080_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_1080_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_1080_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 := [-55, -29, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [232, 0, -12], [348, 66, -18]];
    Rf_basisdens := [1, 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_1080_a();"
function MakeCharacter_1080_a()
    N := 1080;
    order := 1;
    char_gens := [271, 541, 1001, 217];
    v := [1, 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_1080_a_Hecke(Kf)
    return MakeCharacter_1080_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], [25, 0, 0], [-10, 0, 1], [-220, -1, 3], [-426, 1, -3], [577, -2, -7], [337, 9, 3], [811, -21, -8], [1262, 32, 3], [1377, 16, -11], [-2374, -32, -68], [5784, 12, -77], [3852, -44, -1], [-6516, 37, -6], [-1655, -103, -151], [-10702, 45, -153], [-5439, 142, 126], [-17086, 84, 250], [-28024, 127, 273], [-53964, -75, -175], [12147, -135, 553], [-21527, -497, 112], [-20528, 194, 637], [4920, -92, 284], [-42732, -222, 772], [-49868, -216, -588], [83684, -119, -704], [103929, -55, 392], [10918, 587, 1090], [24994, 1442, 414], [-101094, 132, -260], [-53541, 655, -537], [52956, 264, 600], [-78704, -1694, 761], [-7192, 1005, -1136], [175728, -1733, -1407], [106558, -1614, -1220], [-362801, -130, -1096], [-424157, 550, -2559], [-195052, -846, -2950], [-88335, -2191, 1968], [-340270, 2016, -272], [-259918, 2855, 2593], [290147, 1715, -603], [127024, -1154, 122], [136143, -586, -3733], [132514, 3394, -4348], [-326083, -638, -1746], [304159, 5049, 1546], [-604298, -1714, 2912], [-549506, -5236, 4826], [229243, 151, -6282], [-263976, 1422, -7166], [-760281, 2859, -223], [-259624, -8471, -266], [-1053786, 6344, 6014], [-404919, -612, -12067], [405028, 1291, 6685], [-431334, -6452, -1963], [475216, 4228, 8277], [-1223369, -4551, -7517], [-825662, 10752, 5276], [-928634, -1397, 5019], [908216, -10164, 1482], [-2174531, -5236, 4347], [297388, 3662, -1754], [722198, 6647, 10881], [-1133428, 1890, 4812], [1593713, 9880, -2896], [-912166, 15564, 3646], [-1079570, -3070, -30710], [-1702026, -12880, 2765], [-160984, -18406, 14082], [-1820589, -8510, 18103], [943439, 14092, 4506], [-95868, -13464, 9515], [791826, -4517, -26879], [-486046, 8722, -2468], [2582633, -12925, -20384], [1620164, -4517, -23385], [2867247, 13170, -19388], [-1581590, 5131, -39681], [2814938, 19071, -9473], [-2028607, 19052, 5571], [-564735, -13035, -48098], [-2813154, -798, -7721], [-2189804, -3006, 19674], [-2362558, 22306, 35770], [-79454, 24902, -3770], [283477, 3028, 26638], [1038572, -8845, -26797], [-725888, -20298, -37781], [-3397042, -9308, 24026], [6071669, -18768, 3623], [-6372941, 25097, 35764], [691148, 6356, 35144], [-456544, 16076, -22021], [-8310746, 3720, 10131], [-1629906, -48479, 3796], [-5526700, 26022, -1077], [1405430, 23022, -24634], [-5379468, -29141, 23752], [-793602, -33388, 31229], [-6661295, -34722, -20073], [-321416, -25961, -10815], [-2161897, -3389, 73624], [5808691, -25627, 39333], [-4180498, -197, 49105], [4036245, -5501, 30898], [-7278892, 2188, -5605], [-884128, 43126, 54616], [1913981, -8051, 99509], [-3960600, -25006, -61206], [-9398077, 58139, 60853], [424720, -8194, 15576], [1857170, -38234, -87909], [1177251, -2826, -25366], [4511705, -5118, 82493], [4458070, 45491, -10981], [11891486, -4685, 71064], [2613102, 69873, 9293], [1588814, 31949, -54046], [6426049, -21472, 11120], [5212343, 22710, 125271], [100942, -43520, -69008], [15894850, -40307, -11432], [3399674, -52504, -33116], [-3816800, -55670, -5294], [17428312, -20326, -19868], [4332651, -4692, -84331], [4334056, -17578, -96588], [4114459, 63137, 17261], [-10516878, 64952, 49778], [3707626, -41590, 41897], [16758221, 33839, -83368], [8253657, 5916, 92793], [-13440, 22634, 156169], [1709851, -39487, -11821], [16538608, -11710, 41755], [-8715748, -24171, -109104], [1038926, -7264, 109192], [10197244, 7176, 243803], [-3698529, 48864, 110930], [-14639450, -20229, 43050], [9852960, -122074, -77738], [14273460, -27016, 10378], [2059889, 14068, 138231], [5148659, 84372, 3453], [5966595, 46185, 252974], [15225416, -82405, 31547], [9960378, 73398, 27821], [-17771082, 26594, 93545], [19891115, 63557, 65566], [-1856564, 62540, -127416], [-7324070, 10131, 170801], [1630672, -51290, 76732], [2970056, 90998, -215969], [-28671088, 29132, 103758], [-7391214, 126772, -22508], [-3299475, -112355, -17736], [1424902, 34820, -58072], [-19051514, -133198, 149092], [-9499094, -85430, -128380], [12830834, -38022, 419094], [16872855, 75753, 49174], [-9789529, -45015, -276499], [-1008896, -43219, -95665], [-3230661, -122527, -120414], [-813729, 205250, -219519], [14377964, 113514, -44084], [30599179, 81378, -152626], [-18929014, -180561, 24599], [-5619908, -100406, -130136], [23392863, -44317, 216265], [-26675882, -61804, -240243], [-17858115, -90947, 214987], [31604778, -14116, -37883], [-23275784, 221400, 118759], [39594250, -21873, 182420], [-24881388, 96452, -54123], [30819784, -8476, -119150], [-1326086, 213076, 436696], [13617114, -93461, 371774], [7553781, 46970, 410252], [11211508, 232678, 223844], [-51143298, -96517, 22003], [46937368, -52088, -19762], [29250489, -80359, -3134], [-12105850, -45145, -306485], [-33579114, -125320, -28440], [28447895, 45196, -231820], [-38852873, -114257, 130721], [-13075968, -242452, 144264], [-28532655, 127195, -224440], [-32976873, 68420, 182375], [3203133, -301293, -148842], [3655648, 130880, 37510], [575902, -77432, -205150], [-13538920, -267285, 153848], [33444544, -46720, -5537], [33931588, 215136, 208950], [-17960194, -58320, -299580], [50971579, 222350, -157236], [-73527214, -154247, -87727], [-35257326, 259598, 179808], [850940, -90640, 365142], [-16147367, 316476, 132286], [-69128916, -57738, -11548], [33023436, 562652, -121912], [-92519794, -55879, -28199], [-10766196, 383336, -50907], [21729864, -311128, -258964], [20116820, -129779, 400872], [-37481204, -326556, 91776], [939933, -295416, 155734], [11255008, 448734, 251767], [-70526032, 164562, -184432], [28382539, -133636, -290446], [16833873, -461060, -510049], [14561362, -290168, 528764], [53189385, -564287, -649387], [54404706, 240196, 112677], [64507416, -155034, 357937], [-28786083, 94167, 39816], [-2198645, -526485, -239100], [-76431297, 370553, 584267], [-62633704, -104697, 324133], [-126903902, 75472, -93518], [44343988, 232492, 599004], [51259532, -305125, -560669], [13772705, 554131, -197899], [36316672, -104720, 193360], [-73396886, -54366, 419452], [33845470, 519146, 174375], [4927209, 198300, -704718], [-35641327, -214535, 54662], [-14546573, -69742, -50567], [-36592270, -251986, -57644], [-19884188, -174841, -19947], [101103636, -137801, 309976], [41962709, 13913, 1088989], [91821674, -9406, 194558], [23181793, 121239, -169528], [-42785710, -122442, 435826], [12170562, -20344, -911558], [15869968, 22800, -928750], [-18596194, -425967, 284737], [74313972, 20230, 463488], [-9789499, 481644, -512444], [-61569638, -49240, -540778], [-60789882, 15022, -303658], [7878469, -651973, -284310], [-47745823, -78960, -438142], [-74560283, 712666, 493165], [-93851864, -225130, -538152], [-42630675, -634864, 367832], [-9506718, -159834, 6323], [71146357, 401027, 254397], [-121029158, -56389, -366301], [38674320, -45578, -492555], [7041179, -723330, -545942], [56709879, 748131, 372688], [124717188, -527866, -826760], [-72212185, 610515, 508113], [156396460, -23724, -264984], [25851376, 1136772, -84168], [13831450, -491884, -1254528], [94362882, -6882, 419876], [-19270602, -548900, 271470], [366147, 759326, 639888], [-52544198, 854262, 183918], [-4326824, 589199, 724449], [88222033, 499774, 386177], [-150499444, -93993, -178311], [92653834, -92762, -750405], [-14579301, 470557, 1474654], [49691721, 366650, 946792], [-112725815, 340729, 312736], [143620024, -118525, -209713], [47194712, -785885, -277748], [19890437, 486829, -465167], [35584191, 767984, 1166138], [181117575, -496388, -770128], [-56665956, -510950, 517636], [-10856954, 585381, 746347], [-12532990, 823920, -475602], [49604442, -775482, 184496], [160885695, -421866, -443715], [152461744, -129892, -188848], [-51769360, 1029242, 410584], [-6597685, -63227, 769506], [34698338, 564970, 144900], [-5472874, -352082, 363026], [-27105784, -1478011, -49921], [154176612, -225000, 241458], [-4076743, -317475, -1052483], [-121717546, -56618, 179928], [-161798504, -1055490, 233100], [-126594970, 340252, 9067], [-121214088, -1254189, -187115], [37591865, 1021696, -152077], [194054272, -197318, 379336], [216542745, 686789, -366624], [-139324269, 422835, -163247], [-57310872, 855769, -416689], [98348420, 507967, -208860], [87367151, -375619, 61314], [-104532772, -606053, -666751], [63964208, 609147, 309603], [107353317, -430232, 2070610], [189961012, -67456, 459894], [80494328, -196316, 833390], [9088982, 203408, -1359339], [-44289679, -167169, 327588], [215309827, -743940, -373326], [-66735648, 257932, 781116], [-60265216, -389489, -1706887], [-19998970, 983003, 77811], [114185394, 128014, 1004544], [77689475, 343923, -1063761], [-184493096, 1373860, 1231330], [186779444, -435200, -1184266], [178344112, -197442, 1532718], [-191124991, -371521, 426055], [95045038, -1739233, -1628672], [-65071029, -857171, -37263], [-69201184, -1418838, -39050], [220181064, -832708, -644720], [41451991, 179297, 1222273], [59794722, -1456336, -1467708], [335289810, -442730, -638812], [-32419936, 1134113, 1945268], [324959188, -430095, -967054], [222108184, 22122, -141410], [-65432004, 1225347, -535544], [205188763, 362845, -829690], [86789449, -770884, -740403], [-148408322, -606327, -1172422], [231323132, -253244, 1017339], [214529912, 655002, -411118], [-130700747, -419164, 756387], [13660754, -260674, 1371671], [-186968121, 687728, 1678583], [-1505754, -129539, -2828674], [-82864736, 1461999, 2449109], [210157547, 84626, -753176], [-168882500, -754656, 312418], [148405164, -1100694, 1468650], [111135143, -471020, -1225445], [-273485444, 548883, -1431972], [-14861594, -1595122, 665446], [-124643578, -1131322, -640117], [31093896, 1591346, 1603462], [107014130, 1444011, 235330], [11264649, -681968, 161289], [-346302206, -20731, 569695], [159743670, -302663, -622039], [79991926, 132504, 1829214], [197730527, 376749, 1238182], [129013662, 557981, 107223], [217519286, 1893524, -1425534], [-220986104, 455701, -2607226], [-185166958, 322000, 552426], [-176910484, -752000, 718422], [-59762346, -1601099, 2195937], [-109307247, 2159565, 2621399], [43817366, 521424, -2475252], [138416370, -164440, 562964], [178607694, 705894, -988754], [-18128607, 2075432, 1143691], [207602785, -603095, 1531218], [-124577852, 1301204, -481037], [66820713, -1545342, 2077793], [16146312, -1785844, -2904546], [-46389606, 197124, -487724], [-56086038, 148442, -3862984], [259356532, 101977, 1069151], [272742358, -1078312, 897570], [-37586106, 1691966, 201210], [-61836676, -2081706, -1007526], [-155288169, 436681, -4019369], [388298950, -773002, -497701], [-293122147, -664340, -1139139], [-266687508, -1331766, -483346], [-61408660, 818831, 483014], [27523515, -1824647, 10871], [235975982, -1245767, 1182845], [-107626620, 1339362, -3891293], [140902560, 1180336, 911392], [175760762, 9659, -3240068], [-162781027, 141118, -5246411], [-418486814, 895970, 631908], [-204366998, 1726542, -951536], [309267638, 1418670, 642254], [-248641648, -3137073, 1774271], [-145590809, 1389196, 1900203], [85215022, -827254, -986017], [-181739457, 1176695, -1382851], [-172863844, 2316754, -478602], [90268914, 922560, 2471020], [44182030, 2646968, 1842734], [-146231070, -825410, -2711773], [-216841194, 183804, 235936], [191308558, -505912, -957427], [-216909035, -852250, -1322455], [202217438, 2610242, -1359568], [-20225090, -3460192, 821142], [-207403108, 590582, 1213274], [-406636958, -1383385, -801959], [-471531338, 257562, -424048], [-375024173, -678076, 1862493], [-360154777, 1114797, 1631034], [-164107647, -1062260, -908351], [-213487758, 1010302, -1262850], [-231564006, 91332, -6083761], [-312436198, -1674772, -2893270], [114146880, -2001668, -3402672], [-449986409, -869797, -64505], [-219948607, 741118, -2534636], [-117191492, 759206, -1806262], [676127522, 12014, 807786], [-669177951, -165266, 1311984], [-206427842, 1414206, 2574494], [-209879274, -2487096, -1287338], [85640271, -384195, 5302463], [-185774021, 580238, -3709810], [355805662, 2343638, -1722264], [285424763, 1444413, 621159], [-358926504, -519859, -1276061]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1080_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1080_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_1080_6_a_g(:prec:=3)
    chi := MakeCharacter_1080_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_1080_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_1080_6_a_g( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1080_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<7,R![936424, -20832, 30, 1]>,<11,R![-16969720, -114084, 660, 1]>],Snew);
    return Vf;
end function;