
// Make newform 245.6.a.c in Magma, downloaded from the LMFDB on 23 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_245_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_245_6_a_c();".
// 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_245_6_a_c();".
// 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 := [-16, -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_245_a();"
function MakeCharacter_245_a()
    N := 245;
    order := 1;
    char_gens := [197, 101];
    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_245_a_Hecke(Kf)
    return MakeCharacter_245_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, 1], [-3, 3], [25, 0], [0, 0], [-349, 97], [315, -53], [105, -251], [-358, 86], [230, -902], [3415, -945], [660, -924], [-3822, -1260], [-2796, 3818], [-14022, 922], [9857, 1575], [-27564, -454], [-27208, -5184], [28776, -5706], [-20388, -4568], [37720, 5304], [4670, 4192], [-34715, 17635], [-56876, 3924], [15964, 5722], [55141, -13943], [-29046, -21172], [-16611, 20579], [-502, 29970], [-115379, -18567], [32798, 19812], [-8600, 10736], [-307398, 21062], [16884, 5318], [70078, 76994], [-290486, 49772], [97661, 62267], [354098, -16012], [-123434, -57194], [506141, -25933], [204329, 40909], [281044, -95088], [380548, 97210], [309179, -4979], [285820, 156198], [-307784, 59494], [-236376, -109048], [89277, 23175], [-564379, -126085], [281521, -30393], [-410068, 91346], [-1226952, -28478], [224537, -155129], [-214374, 336604], [772306, -245506], [151474, -20444], [167730, -37322], [-463922, -93336], [-921920, 286656], [-285770, -131224], [1953627, 28975], [-1651265, 211617], [-2401555, 27657], [-565017, 709953], [-1499982, -237530], [749503, -720569], [-649562, -365120], [-334596, 227736], [-117754, -227476], [-1770806, -147062], [1386598, -503936], [-530539, -839455], [-2770304, -181272], [1589281, -430593], [-3121828, 8514], [-2016020, -667880], [-709828, 845068], [433153, -458771], [-350479, -745243], [3989785, 189449], [-1572022, 1015924], [1995820, -808820], [-4226083, 544185], [1713295, -521311], [-1430434, 395360], [-3078798, 443286], [-3808542, 664602], [4866343, 338699], [2105280, 841546], [4933048, 862990], [-7736144, 213536], [-568277, 356573], [1472650, 1744510], [1317722, -928538], [3261913, -951277], [252751, 1353413], [-2747757, 307381], [-988882, -1201736], [-2094302, -898500], [-3349844, -832940], [2236631, -2592713], [-1288216, 611828], [-6022264, -375106], [-1181140, -493548], [1856546, -944072], [-1908172, 933008], [-6017333, 761595], [1529696, -800728], [4056995, 234227], [-5215465, 573305], [1843922, -2503388], [-4073789, -441363], [-3913142, -1168788], [5938274, 1717928], [9947738, -693906], [-4533161, 380521], [-3141566, -153024], [-14370371, -349981], [158920, 1615784], [-7562910, 2247548], [-5926937, -460331], [2675328, 1001750], [5741252, 1896014], [10518947, -1229525], [-5453112, 2919012], [-5608892, 2935340], [-3731429, 4203227], [-1536577, 4408319], [7965130, -1735810], [-18083672, 1227928], [12058231, 1142295], [-1550653, -3715079], [14374132, 2996284], [2349173, 3236363], [-21498528, 516102], [898802, 4356892], [-13854278, 591356], [15359131, 3397915], [305313, -845017], [2981593, 130893], [19847577, 3089521], [-30997662, -244570], [-16958471, 4413741], [1349132, 523564], [-6453262, -513270], [14457260, -4650670], [-8828338, 2979266], [33234170, 746052], [2417422, -3083000], [-8321860, -5973340], [12460512, -378976], [5767098, -261340], [-3286272, -2983970], [-16698180, 2519368], [-6300840, -8388616], [3564430, -9517554], [-26848768, 607040], [-10542359, -2631497], [1226868, 2295474], [-1732259, 5700097], [-1024096, 351278], [-9855400, 4171236], [19350376, -7538014], [-38658834, 4067074], [30658728, -6709920], [19945206, 2563564], [42181291, 2256405], [18713632, 4104200], [-14202467, 8164473], [11203229, 8757877], [-681898, 123528], [-25814696, 5599172], [-29453538, 1314872], [-3314013, 4494685], [-9271206, -2642880], [14733682, 7810966], [-2673940, -4032390], [9271063, -11105707], [1951001, -10791963], [-8294228, -2655492], [17781240, -582730], [-2243508, 3639852], [6063564, -837412], [33114470, 6301648], [-25346070, 14555204], [-4893900, -13166972], [-19396866, 6994752], [-23038856, 3372558], [-34450955, -1649533], [-20299623, -5621199], [17136528, 4837320], [56119918, -7392744], [6767698, -8703638], [-3141583, -10135165], [40971736, -82786], [-3399556, -8519032], [-29788773, -5394237], [15307767, 307515], [-37577628, 5138554], [19563033, -9853587], [-8713283, 505883], [94851134, -529568], [-26231910, -7124434], [-3549954, -8188328], [-25456522, 18573304], [-57341986, 5359562], [-86449739, -234663], [-16750550, -7279170], [-63539716, 1267120], [34167318, 13534404], [-10493728, -12104208], [-52259212, 6049790], [84115190, 7264656], [-2553132, -13929428], [-34844175, -1669681], [7581714, 5192902], [17586508, 6113890], [32936654, -6566462], [40545852, 3378362], [33685390, -6877094], [-40318682, 11020232], [-67702454, -2739068], [30616474, 15038862], [29494821, -17141267], [2670358, -8929518], [-25140151, -23671009], [21514166, 3369848], [38221421, 6571425], [92363503, -5112911], [130117, -2291565], [9438236, 14601352], [82091108, -16830758], [101222126, -2478422], [82217680, -181336], [25879593, -30299087], [-76713879, -6246345], [-49606347, -23582197], [100580984, 6749662], [54343072, -1898866], [-13322519, -5944077], [76627138, 7785110], [99253448, -17319388], [-19429720, -5833344], [-1396367, 11082391], [-106664234, 10027048], [-27664509, -6862525], [-38059514, 10782138], [29999944, 3522296], [48126122, 5952582], [-20429115, 18758575], [-124623750, 8896758], [10164874, 33893228], [-44000322, -14430800], [-117934292, 6782380], [134162344, 1954542], [-41958598, 24938068], [104230255, 15252405], [-109180298, -10531400], [-171924084, -6549108], [-5343861, 25282011], [131619939, -13739869], [5841346, -5897674], [35352086, -33985866], [-7422708, -31980534], [-121200489, 17077015], [41741550, 4432384], [45424770, -13094490], [46272809, -5715003], [-5107538, -43740008], [110743084, 7424960], [-35622838, 36194204], [49553952, -15103178], [-121591524, -23686976], [17487261, 13115105], [109445388, -12066396], [29875002, 21975820], [117379201, 25750615], [-93227516, 28487088], [-134467038, 6054716], [56459073, -41689527], [8029738, -6796730], [78356173, 18062611], [-122540747, 38801243], [35229104, -17738784], [72806258, -62913100], [97860609, 10623791], [77787607, 7664265], [28213174, -23518100], [-22126206, 32790028], [49107868, -9537516], [32002716, -33493582], [84040545, -2043251], [265883211, -6544323], [73592432, -23488246], [-89155540, 54771116], [100092834, 24127540], [93346104, 52597422], [22693458, 15849550], [-157400581, 39513859], [125181916, 19198468], [61444677, -8335525], [-34919047, -32486099], [10794094, 8191968], [137277219, -36178683], [-187164912, -7976068], [-42319191, -32119589], [33227706, -42176136], [-92858934, 22382074], [47972704, 28853982], [-6239384, -14814512], [51458328, 35056262], [19868200, -41675928], [11619155, 76894555], [205201358, -31245212], [-238165094, 34618946], [-65170510, -67001434], [181584332, 13677946], [-111653078, 7393406], [229689799, -502559], [-72536687, -45474699], [-147176035, -40911995], [-88331418, -1757598], [106135240, -14741374], [-164641970, 57323376], [37854420, 37496588], [15726718, 45168812], [951348, 30832130], [-32592143, -49075269], [-263340268, 32257548], [87404928, -80069160], [69236980, -38791662], [-90124858, -30505400], [-15118628, 63822322], [-141025594, -1304622], [35875231, 3111345], [74430924, -7975104], [-109648939, 1615867], [107313213, 31676889], [171370366, 8746680], [-272802726, -43935492], [256416633, -46252017], [-130907958, -31043676], [55646344, -53927822], [172939934, -31460208], [-182085509, -65756123], [2218142, 58111264], [125088220, 12374640], [169262850, 19812716], [59144356, 61150144], [54041210, -30357594], [-98178559, -36013563], [273309848, 57409920], [-205355968, 67802042], [-172332943, -23278115], [-46231855, -44776633], [-61614983, -44770099], [380127314, -3079236], [-1855498, 31972866], [-133669770, 45196386], [-391822486, 11288888], [-30074794, 26782506], [-99494448, -15376098], [-268495592, 61190590], [118309768, -80011840], [161516927, 14861661], [-179343292, -65057852], [195877538, 52206632], [-291678303, 64151445], [-274074626, 78990050], [-158233339, 28806037], [-88775161, 61956701], [-174008864, -72574912], [-59426680, -89290232], [-96105645, -16310125], [-230800074, -21572926], [199426506, -79017076], [-117461160, -26610680], [-4886373, -13495275], [203091531, 2311115], [248302202, -62589684], [-215302641, -33843529], [97344730, 37509836], [-99266394, 51645796], [141616460, -50246404], [-237988058, 65506012], [3268784, -118172648], [-24009123, 60862923], [330682999, 37846001], [69727075, -95060141], [163089068, -281088], [77195791, -74900503], [-587717223, -3487319], [-52325923, -76024087], [290649085, -28952785], [125891924, -143574164], [90753271, -138379263], [-10227576, 65212610], [-318620700, 31627140], [182657520, 42613630], [158342619, 93154481], [-2883918, -58516580], [-138775260, 27725050], [444709364, -86129730], [46656446, 30903794], [-449102171, 100063921], [37854164, -80089558], [-9106694, -83506826], [390844490, -38728244], [151296527, -7639325], [-285115108, 106482708], [125753244, 62423532], [-617144667, 26294641], [-182583146, 52827968], [-46852374, 101026506], [112387228, -23498152], [-290218562, 106742460], [254283256, 123327694], [146213359, 32912937], [515024660, 79074124], [-527875610, 57137784], [-181695419, -2325245], [228634301, -63834247], [185565738, -145886372], [284508486, 74877834], [102169508, 92945084], [-219663809, 9938295], [-108249575, 201281749], [-558628656, 20961100], [-361625286, 70515072], [380859704, -26219832], [-80952384, -143969312]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_245_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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