
// Make newform 130.6.a.e in Magma, downloaded from the LMFDB on 03 January 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_130_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_130_6_a_e();".
// 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_130_6_a_e();".
// 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 := [-14, 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_130_a();"
function MakeCharacter_130_a()
    N := 130;
    order := 1;
    char_gens := [27, 41];
    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_130_a_Hecke(Kf)
    return MakeCharacter_130_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 := [[4, 0], [-8, 3], [25, 0], [-126, -20], [-18, -137], [-169, 0], [-1190, 314], [-546, 41], [-588, 861], [-2436, -1256], [-1130, 2127], [-8880, -1174], [-4610, 2090], [-11828, 199], [6430, 756], [5534, -538], [45202, -1301], [-34500, -2604], [25398, -4898], [-14334, -5863], [-31344, -2598], [42032, -16438], [-6414, 19772], [46310, -3472], [-37842, 9524], [1946, -25556], [73732, 11423], [3368, -53097], [1206, 46064], [-67154, 18966], [33052, -14159], [-15376, 75440], [-33006, 11392], [-13308, -19210], [-61022, 75892], [-175506, -50229], [-370038, 12464], [-293406, -18250], [-315230, -58980], [-172630, -21350], [-136568, -97128], [41860, -173620], [-144504, 52412], [-713094, -62340], [273202, -134228], [1011436, 13532], [373680, -168476], [589826, 58820], [-639278, -4554], [761066, 115702], [95402, -308808], [235342, 59121], [640854, 154802], [690752, 202394], [-744218, -126596], [196808, 351405], [676170, -72432], [-762658, 367703], [-1241830, 26574], [470294, -314170], [119796, -86845], [-1022748, -395902], [1191854, -347944], [-1449336, 79062], [1396570, 161598], [-1323844, 377966], [-1852518, -531063], [952950, 359826], [-1118944, -189631], [1701454, 224254], [-2321940, -361882], [-1897338, 261061], [2542568, -69329], [1169290, 448472], [1888898, 497679], [-3195798, 368948], [-2638498, -463176], [-40816, -599746], [2204870, 889632], [-638842, -439402], [2142520, 163798], [-1947514, -1135108], [1449950, 1087959], [-2679486, -558108], [-2792568, 819868], [-2201400, -987973], [-590510, 878162], [5733750, -195760], [-2975626, 1145490], [4814542, -374], [-4032412, -1139689], [941238, -619043], [1915070, -1496982], [-2443632, -531214], [6058174, 728277], [-5812448, -628089], [-2950562, 1261318], [-4290200, 844692], [78888, 956519], [-5547486, 326394], [-2187840, 2613439], [5442400, 1335586], [-6662796, 876895], [-2437972, -2266556], [3212404, 2229582], [-1793680, 937506], [3202666, -1620074], [-8730, 1328176], [-10984088, -385782], [173298, 911576], [-6973176, 852165], [8879766, 1754624], [188330, 1764012], [-13437902, 75643], [3016682, 1722449], [-2324790, -3828436], [-6533790, -1756772], [-7167564, -997479], [813358, -3394556], [-8035264, 3658746], [5591454, 658988], [-10755998, 504118], [-18443298, -56578], [927214, 4548550], [7946890, 1598581], [23389714, -122048], [7142522, 3753398], [9316812, 2951288], [4023852, -243189], [20779338, 339280], [9286326, -1867627], [9352714, -2309336], [3641412, -1840414], [15852538, 2147742], [-3432830, 918088], [6310666, -1784268], [26910240, 191302], [6241014, 984372], [12773010, -3813284], [-4998556, 572336], [-22179334, 3409573], [5132466, 2746352], [4498380, -95877], [3441154, -3634532], [5914260, 7648696], [-19844142, -932361], [-11277908, -1803778], [-8502234, 7140004], [-17430752, 4853286], [34459098, 1753504], [-1273842, -2157512], [-6308664, 9066700], [-4681852, -3338953], [-10904216, 4285647], [-4334924, -10965601], [9407228, 7019364], [16289744, -3998970], [-6967230, 6880802], [9095274, -9689636], [-41934238, 703074], [4249002, -3959632], [12089406, 2101648], [-18735922, 4358382], [11012136, 892752], [-10421312, 9630106], [6532150, -2342822], [-7237624, 392172], [-14489338, 6868874], [-11100750, -11174404], [16593334, -155326], [-1895678, -986329], [5980962, -11671878], [-35974108, 1660738], [-44677436, 5161518], [13372976, 6319416], [-17259758, -6063960], [973994, -4339075], [14085702, -672542], [-12816364, 11703913], [-30095346, 4864768], [25080342, 5423332], [34300460, 4982134], [11117322, 5012542], [36014682, -2541840], [15143834, 5317130], [-40450160, -4871292], [61264210, -3357004], [-18801134, -14233352], [-23308394, 2265170], [43633750, -5925657], [-49558282, 2808102], [66714314, -2466816], [24958752, -7901704], [4713786, -3403472], [-37854980, 5378949], [2505474, -7292476], [-19388338, -10516234], [-1362422, -2177028], [14363988, -13586910], [23949216, -4857425], [-62088754, 7914030], [53253700, -10420084], [33206038, -18163312], [-8193284, 9895952], [-24940210, -6461763], [-86306182, 1232382], [-14509946, -9730747], [13876096, 13023667], [-40063886, 1630896], [23433248, 13139902], [41838290, -106244], [-33209476, -8869596], [5559336, -15191505], [-84258066, -8174044], [22889898, -18587657], [-69949878, -1390850], [-70079040, -8179833], [-6844562, -29697960], [7347490, 3119554], [46385810, -3558912], [-20298836, 222164], [3103746, 10486855], [-72798570, 13723280], [-10322314, -4914416], [-34057596, 9892455], [-11891172, -23402168], [78506798, -7837276], [-59239492, 7380250], [149946876, 707067], [-128545734, -1669027], [22612142, 25382160], [-62074024, 7669794], [113536322, -5074555], [-84264050, -8998148], [-54877440, 8232691], [-26997826, -29570674], [-98031946, 14459118], [-69395636, 27308726], [-79127840, -1019164], [59702880, -9960440], [-127687898, 8917164], [49809668, 1077774], [87991008, 21538903], [6198018, -1874098], [-41197478, 6507772], [118975640, -4555976], [56365286, 24442952], [-69983946, -25754125], [86241202, -11158193], [57545380, 13551067], [119278896, 2698550], [123735266, 9018096], [-112827206, -3717544], [-7976670, -28419512], [73818342, -616068], [74388330, -25541725], [-128297512, -1146248], [-55082538, 9095274], [60203902, -12129996], [-112364224, -6312690], [-60983796, -8994655], [-98227344, 16673601], [-7314418, 1114918], [-89900354, -13049578], [-15796540, 6431962], [45415100, -23799930], [86275018, 5154986], [-12245486, 608964], [11300154, 35449894], [-57419290, -32189026], [29782130, 8422516], [-63363198, -30205010], [10105714, 57787684], [4082284, 58318796], [-7874070, -59223362], [-286062, -22733568], [-53036302, -36344978], [76971226, -32685298], [51067426, 57029978], [-156910012, 18633638], [-4168248, 3443863], [29921154, 44190133], [7482104, -26278707], [159495970, 16846802], [-21202426, 16203676], [-114687236, -41031862], [-130616158, 40764456], [40790966, 42285084], [37155190, -24528223], [243020676, -8767228], [9705660, 41330396], [-9037848, -9976689], [-48580682, 54604744], [-5130914, -5483741], [54153646, -11543060], [-228810490, 15905160], [68831580, 19598168], [-76274182, -56827680], [-101287076, 745722], [10530362, -83301628], [93269762, -29328268], [266381750, -15697332], [-7298316, 14506088], [41767688, -38674261], [173368980, 45340972], [-197145080, 8436230], [-164513180, 30505943], [-152563590, -25085972], [19155698, -63839213], [-122336026, 29022448], [21111464, -53434691], [83348746, 13981902], [300119928, 1538788], [-165110896, -5994735], [-24098670, -2965464], [65820980, -30958776], [-170011298, -46666427], [-192461582, -22354307], [136580600, 7761862], [125315174, -22494064], [-76778800, -21354786], [-23734848, -45233190], [-129576060, 34290340], [-228950946, 8096766], [36818432, -69115118], [275273044, 13236120], [171170722, -32153413], [46349450, 16288856], [-270529916, -19496071], [-61193938, -56125568], [38165566, 6554312], [-37378666, -8551864], [-112112704, -77184742], [-40200830, 4156422], [-72977786, -14529605], [203774158, -20117062], [-82795166, -77899756], [138118718, 2326716], [-333752266, 37394618], [99003684, 11280437], [-120947054, -1959516], [234962262, -54163634], [339653778, 33392492], [17568032, 45723898], [266439658, 34238892], [-121142472, 83505884], [-178168758, -44932368], [274611842, -9401476], [-286930938, -14150793], [199600518, -20692012], [171789714, 50618933], [-94732190, 22638276], [-229241214, 75632308], [433078972, 20625343], [-91946274, -3771720], [47073542, 87978238], [40983338, 12252607], [-159698646, -42748295], [-93320026, -19358876], [-100034106, 20874692], [-96522564, -78086390], [-64107348, 9580492], [-92266728, -106173709], [-63678926, -79572529], [-144061660, -17028699], [80693426, -36141858], [-323153066, -27266620], [-188555898, -109123066], [141893202, 32776276], [449813768, -24541552], [288205028, -2269620], [112078514, 66018002], [-262018280, -40898920], [279420284, 69766816], [129758650, 73888394], [249180230, 74562069], [-32046816, 89926626], [-60603418, -3399200], [53325584, 112540632], [295697190, -15651450], [237820214, 42772162], [-11449368, 145145526], [449226890, -5698584], [-494583184, -24507194], [159850566, 14032069], [-421750802, -7030630], [-46773794, 95697639], [124721418, -69038190], [10470762, -25098268], [96109088, 67829705], [66537938, 48290194], [-79975648, 46256850], [137587946, -112044481], [336747488, 70568859], [5987302, 3654387], [79617646, 127230076], [-71669578, -78588491], [-585795440, 1709352], [453922556, 24556616], [-258339614, -10780268], [126244626, 138599700], [-179147190, -79174642], [-194471690, 2909924], [-130176908, 35886418], [-218463890, 72035296], [55647224, 77063352], [60563548, -145151910], [296712086, -78854492], [-615533022, -21316182], [11066906, 143867431], [-125912326, 106907396], [-439517874, -79321594], [-210578464, -147297279], [174033152, -34735530], [-479320098, 24889604], [677420662, -23983984], [-163025146, 7026289], [-371308624, -9798727], [117827132, 49012718], [68225892, -58887269], [-37853260, -41293616], [-52548198, -14083576], [-460642738, 25871318], [333270408, -97259026], [-260847554, 158061736], [344215748, 8317398], [-420248796, 42873203], [304978990, -75218594], [336709682, -102676527], [-389007992, -17650546]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_130_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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