
// Make newform 165.6.a.a in Magma, downloaded from the LMFDB on 23 December 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_165_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_165_6_a_a();".
// 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_165_6_a_a();".
// 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 := [48, -52, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-35, 0, 1]];
    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_165_a();"
function MakeCharacter_165_a()
    N := 165;
    order := 1;
    char_gens := [56, 67, 46];
    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_165_a_Hecke( : Kf := Kf)
    return MakeCharacter_165_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]];
    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 := [[-2, -1, 0], [9, 0, 0], [25, 0, 0], [-61, 11, 1], [-121, 0, 0], [-210, -24, -28], [-801, 37, 39], [-935, -67, -29], [684, 220, -20], [-2615, 107, 77], [146, 130, 38], [-2866, -528, 272], [-3245, 977, -473], [-4621, -809, 341], [-6538, 222, -422], [-1212, -962, 586], [-2200, -2748, 356], [-18926, -3300, 364], [-12108, -2144, 680], [-25548, 2612, 980], [-15750, 2808, 428], [-34233, -5417, -775], [-32042, 14234, 1474], [56494, -2140, -132], [56154, -8760, -1664], [-4931, -13977, -4487], [64870, 3238, -2918], [25842, -17362, -1410], [-31428, -14362, -870], [90888, 15854, -2718], [28691, 26403, 2753], [-177848, -28500, 1004], [136140, -40374, -1482], [-49283, 21961, -5761], [110247, -4687, 11087], [-163937, -28393, 7561], [32422, -3456, 11592], [-87930, 6626, -17090], [130382, -61970, 7862], [-55029, -31115, -20553], [-171794, -6766, -2610], [-246854, 59572, 5452], [76504, 114144, 1648], [-544664, 83630, 13494], [-168693, -20163, -35713], [-499830, -42718, -11250], [-135711, 66629, 8491], [36086, 135550, 6906], [417846, 86586, -21350], [-190566, 83988, 9596], [-432659, 76283, 4457], [-218002, -75778, 20394], [9752, 177526, -3262], [50346, 3078, -2382], [193170, 11240, -54576], [383334, 100614, 33318], [125840, -104814, -19730], [-1063567, 83473, 10303], [396914, -60828, 10952], [-230533, 70041, 4543], [-195165, -152697, 45973], [98989, 63247, -3387], [-110099, -163959, 17059], [374006, 309046, -41294], [267218, -315800, -18360], [-425314, 44416, 37744], [-839664, -112668, 36916], [-367002, 107484, -39288], [-332018, 244538, 37810], [848358, 157888, 107192], [703350, -2180, 37932], [-551916, 392812, 92764], [-127534, -167606, -84034], [2275104, 75410, 100098], [2025212, 316384, -83472], [-1150984, 27328, -103856], [3371462, -21680, 41872], [-178302, -409700, -136212], [1122860, 142826, -138234], [1400772, 265386, 104598], [-1501898, -585606, -16490], [1068870, -3024, -110112], [2668006, -538170, -21094], [2229790, -38612, -5060], [570657, 458969, -65201], [-2275486, 600710, 60954], [-1259038, -207328, 149424], [-1379606, 58776, 178308], [3667279, -19103, 94879], [1825550, 459238, -141230], [512206, -829686, 178670], [-1038918, 10506, -216594], [513300, -726076, 81604], [-782442, -271006, -15538], [-4218782, 790574, 167138], [-3565186, 32894, 87942], [56508, -173394, 40610], [8637688, -154690, 136850], [1661723, 47487, 172421], [3153124, -1008514, -17006], [-7497005, 50815, 28517], [-866267, -161201, 74733], [737924, 1917000, -64436], [423601, 1844239, -14207], [-1470417, 1375563, -39027], [4000862, -7764, -211236], [2365406, -565038, -211226], [9848801, 568423, 8261], [2032778, -224022, 431590], [-7398682, 17244, -269652], [-6586021, -847365, -178711], [6328316, 1473502, -240874], [5189388, -323638, 140726], [-5711976, -433908, 173548], [-4009942, -272750, -128338], [10655870, 223084, -48940], [1678942, -982966, 123766], [5419912, -1206968, -374936], [15373196, 30590, -22278], [17340, -611376, -295584], [3190598, 1189984, 489744], [10527144, -940402, -120554], [394383, 747537, 62899], [-3792472, -281236, 314940], [5100952, -2702460, -382004], [1473875, -627307, -431965], [10469242, -1252044, 291388], [-15471784, 120144, -376496], [-8147316, 808028, -475292], [-1954634, -2798048, -46684], [-7146525, -1639705, -209087], [-7140708, -1246740, 71056], [-21515394, -77362, 157618], [527102, -236096, 834808], [3885461, 2963251, 38669], [-9306678, 94024, -448480], [12580684, -624138, 51442], [-23344005, 497255, -194795], [-8250446, -1926940, -671796], [12131769, -2055705, 258657], [-4250207, 1635997, 294251], [-9427943, 3415491, -31435], [5449922, -64174, -948146], [-6895606, 1741974, 591478], [-9116818, 909040, -744352], [-7494534, 4295850, 192526], [12312628, -3371866, -694274], [-296557, 2253105, -151157], [-25080572, 321368, -186144], [-3948092, -4140692, 535860], [-6109604, 3897206, -128258], [-175340, -4340958, -420514], [21759344, -1075652, 424836], [16065736, -1159416, -88868], [-7192682, 439034, -988610], [-4976468, -570652, 1102876], [-33208363, -2103283, 54091], [4387684, 36466, 81486], [-4730208, -781362, 434334], [1450885, 3325975, 669129], [3021588, -6280144, 97320], [-21431121, -5302099, 784839], [14949467, -1161405, 470145], [-844320, -843284, -1462716], [5526072, -4180962, 1175794], [-10267660, 5853764, 306492], [4920070, -2501338, 1333186], [52072136, -470454, -276726], [10987640, -5277386, -1170030], [-5120832, -1937526, -171570], [-1153524, -1838280, -996680], [-2135042, 1752288, -392432], [-12534568, 1274192, -471832], [29648658, 1320384, -167956], [-37632252, -3416204, 87092], [-13996416, 3821542, 35098], [-39973357, -2220385, 121801], [13750908, -3125882, 1221018], [41003575, -1678177, 605941], [16080286, -5368, -505784], [36104256, 3061432, 94920], [-36631784, -2248756, -62892], [-9465770, 8879496, 711552], [7714163, -3935711, 1344979], [-3228230, -4306062, -1197322], [11441500, 81590, 73210], [-28681170, -4401448, 642828], [5874438, 5223618, -1116378], [-19021456, 2198342, 637034], [-12231266, 10850878, 43698], [10342554, 4580952, -950976], [39715234, -2004738, 1531790], [-23707230, -138274, -440126], [35530658, 427156, 626284], [-24370816, 3169476, 718448], [2908902, -2553260, 1367188], [-22197086, -9779680, 1266040], [16885390, 3398360, 1394584], [-1302409, 4130829, -978505], [-21326548, 1266316, -281824], [25930959, -5152207, 1073783], [48605811, 1212163, -166363], [-26477842, 9793920, 1359024], [-5841160, 4030390, 2367314], [-43902814, 1873710, 405538], [-20073446, -511172, 672804], [42643672, 1262520, 545272], [-13843864, -6084596, -1335112], [-15591179, -7205613, 1811429], [-55477378, 4459634, 1485542], [-28250016, 1271910, -3192042], [44800480, -1359878, 2098966], [-2490376, -10035800, -1714760], [-21833594, -3224758, 107566], [12096740, 203052, -471668], [8657118, 2035988, -326244], [89523309, 4821293, 70447], [78044735, -1746667, -893365], [30127014, 2535270, 3218058], [23808048, 9960178, -1395114], [42022516, 3150134, -2811598], [-7231105, 6634775, 369401], [14693008, -8739378, -2647598], [-67963590, 2336690, 1433710], [64217952, 5188004, 566552], [6991074, 5013604, 2066444], [4942864, -8553458, -1000398], [-53450406, -11243662, -375930], [57865153, 8032553, -648725], [-15268894, 4019982, -3950390], [-104765910, 3901444, -262348], [30685825, 3790709, -1762781], [21200271, -819489, 3310409], [1941517, 15442059, -823219], [31291004, 6396400, 3773928], [-56056100, -7275676, -69688], [-82275906, 9276812, 2191588], [85940561, -7737501, -394751], [-100157182, -1035890, 591642], [-49105262, -1071454, -2006482], [-18705610, -8975918, -1193506], [-1039601, 708747, 33909], [-8942040, -4693256, -3921592], [-1335866, -19057816, -1836568], [-91904047, 304471, 1430701], [19793052, -17190860, -2323356], [29255928, 6540768, 4591784], [44079462, 12182778, 3157758], [-139323909, 3224551, 869585], [-7070300, 2740220, -1914592], [4629258, 3374676, -2002504], [544791, -14220243, -954125], [-26542742, 14128602, 1597430], [-60959626, -11054804, 1587332], [-3994611, -192809, 3424389], [-54284846, 8248070, 4271354], [-118468586, -5454432, -276048], [-68045635, 14821153, -751133], [-50352794, -198208, -1446576], [37633216, -12873698, -845858], [-58477883, -2982107, -2302745], [-36139188, -2629776, 727476], [97921860, 16607222, -318254], [-147009996, -5549346, -1027490], [-172080466, 1729044, 1095476], [-55663846, -9832506, -1892854], [75477732, 6525446, -612150], [10470228, 25329834, 808438], [-36619131, -18982935, 3593347], [-52322425, -8143863, -1412645], [45362414, -21728544, 714192], [39601778, -8434898, 3218858], [-72317102, -5108680, -4869152], [-6034047, 9831617, 5338231], [-133882922, 4122140, 2919856], [94408484, -2116588, -4303084], [-34741648, -5833532, -7637052], [59254514, -1948964, -3345412], [31090546, 18264856, -1576336], [-50351628, 2153816, 144752], [-5914610, 20997110, -7411114], [-35598210, 4196582, -6670670], [-194952424, 2219704, -2490220], [127791546, -20970868, -3806924], [186158135, 4611195, 1043433], [-35876658, 20348998, 294666], [-121342190, 11975056, 4266968], [-55382921, 18932585, 5733307], [19236394, -16982494, -4222202], [-84272749, -11135255, -5773961], [-24763818, -20481032, 4517352], [19825530, -18416298, 1327562], [21552265, 10647431, -3177811], [-76498212, 9207000, 1416096], [15289780, -7975602, 4287534], [90327663, 7954417, 263167], [-10136322, -31172466, 6615234], [148541124, -2135810, 812794], [-105559566, -8080978, 2322770], [44786993, -14610963, -4248705], [-19588052, 21142586, -268830], [64422069, 9279711, -4590243], [144211071, 13797855, 3154505], [135890990, -4877462, -2801650], [162942794, -30840370, -3673478], [12938578, -19985968, -3605488], [-149499412, -2902400, 3750216], [-24104938, -25437992, -1324168], [121813258, 12642922, -594522], [-113554332, -15646682, -4603810], [150203542, -22828146, -1101290], [12373294, -2485432, -2258728], [7310855, -13923763, 1489395], [23331428, 6262768, 2315208], [47735570, -20738478, 8353282], [-100655072, -9214826, -12795214], [51992504, 25076764, -7105004], [1623244, -4905172, -3557028], [-182174590, 35347968, 2865768], [11609869, 31290659, 5337709], [-156974171, 3490409, 4776471], [-250884642, 848580, -5265388], [-325572345, 5539785, 1051551], [114676308, 27876876, -6503220], [-47132443, 9728115, 5354449], [-49810022, 16423752, 9609480], [85994378, -9075690, 14354130], [-140813724, 11927528, -4876664], [226988774, -20337202, -483954], [-20994565, -43050323, 26959], [87142168, -12821262, 448710], [26109854, 13340656, 10448624], [-168869717, 30084827, -3073547], [-259213194, -8931606, 299274], [-76383117, 7262319, -1626863], [-98144006, -6699106, -765966], [-66103154, 35368432, 1653536], [-57581311, -25773321, -7399987], [-213786558, 19831736, 3841752], [14417079, -24751865, 3607493], [19927810, 51047684, -1850252], [110093250, 41593792, -2230136], [-117410125, -4672195, 2318931], [-19324020, 731892, 4701252], [-32991316, 9152670, 2059786], [189488198, -2946550, -2719858], [158574810, 22790004, -1378740], [168995362, -25965626, -3296902], [-97932572, -3206860, 10700588], [-93456108, -14446866, 8684362], [-175610551, 3204909, -4507285], [-44423486, -3901320, 9890280], [252294924, 1992462, -7618014], [-97635257, 11087559, 11453661], [25377906, -17393372, 787172], [38283975, -40624635, 6779559], [342804812, -14676540, -2365868], [-108416298, -30661662, 3505798], [76776031, -31006523, -7727121], [167405042, -17577358, -752098], [-184922420, -16485586, -12896498], [205306643, -41299583, -9872657], [171568916, -32396292, -6285124], [-98267386, -30102974, -7227306], [-102173240, -21259068, 3930252], [-86257258, -68707428, 6655020], [-39276995, -38327769, -10529323], [-87948749, -11737909, 12425105], [-16077258, 36220028, -609012], [-21819480, 7349468, -5067796], [45639332, 11340360, 18963360], [307357244, 9161012, 5916824], [201405685, -36256145, -2434959], [335565, -66624283, -1455789], [169062126, -17778456, 12916992], [218775422, 11745906, 15315982], [-176754930, 6831678, -8109638], [29086744, -16048754, 910654], [127992357, 2435435, 14874741], [-6404190, 30788800, 6366476], [334307918, 9461664, 2303456], [372236314, 26859192, -7087504], [329625463, 43541679, -2958843], [-61854629, 62332209, 6117947], [319039327, 25929923, 10526317], [-219865318, -20637494, 13440326], [277318134, 36417030, -6047654], [-170366286, 10662324, -15797436], [-231170149, 6048127, -6069883], [-179249722, 72897950, 16827426], [-48718878, -5621504, -11370240], [67042808, 8338962, -10987370], [152875566, 7111626, -1571874], [2319756, 28623096, 2114640], [-104273314, -7329474, 9988954], [67817246, 65785980, -2445600], [88794919, -45169193, -4278367], [-242126246, 1926208, -15531888], [273895416, -57772772, 727860], [-48728255, 21476315, 12299213], [-202480574, 23162508, -15776652], [13525544, -8977938, 1285714], [31399543, 52541751, 8930229], [257013054, -68081940, -6198324], [-268844805, 23344197, -7540821], [-30060865, -11515353, -8033415], [-217363230, 80107596, 9936460], [-177817625, 15375933, 7120595], [-144137336, 18497412, -10396524], [222399022, 67605586, -13238378], [207739696, 46559222, -5063306], [-487659095, 1314939, 165785], [-473452128, 51581076, 2456828], [-333665293, 3512967, -5354575], [150513150, -12006468, -2256424], [62149134, -39285008, 6153232], [-92483626, -50710794, -2688518], [35487218, 53215986, 554286], [-161631318, -46243584, 1029624], [-225984178, 74360798, 8474966], [195586316, 33465598, 6659106], [-286919648, 23577890, -1906646], [-403906926, -27006342, -5345642], [-230662834, -13365222, -18400322], [62609714, 57147384, -21393432], [82899164, 44055166, 15065882], [-364540528, 20194060, 6601060], [-56103961, -85274523, 18344779], [23304, 103643196, -4567212], [320485266, -7591750, 19567518]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_165_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_165_6_a_a();".
// 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_165_6_a_a(:prec:=3)
    chi := MakeCharacter_165_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_165_6_a_a();".
// 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_165_6_a_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_165_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<2,R![-140, -36, 7, 1]>],Snew);
    return Vf;
end function;