
// Make newform 140.6.a.a in Magma, downloaded from the LMFDB on 23 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_140_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_140_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_140_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 := [-252, -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_140_a();"
function MakeCharacter_140_a()
    N := 140;
    order := 1;
    char_gens := [71, 57, 101];
    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_140_a_Hecke(Kf)
    return MakeCharacter_140_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], [-11, -1], [-25, 0], [49, 0], [441, -9], [-103, 21], [-1041, 63], [-310, 6], [-606, -138], [-729, 459], [-4516, 12], [-4318, -396], [-9108, -114], [-2194, 414], [-10419, -921], [-12, 2178], [-14256, -192], [5216, 1962], [-50452, -984], [46608, -1584], [-16894, -2208], [-4525, -951], [39276, -444], [15516, 2406], [-43573, 1395], [28614, -11148], [-77623, -7581], [59742, -9690], [140837, -747], [28134, -5172], [-30784, 10968], [9618, 9582], [-48516, 12246], [128726, -10998], [-219558, -11124], [-186349, -15831], [-388306, -1188], [-33766, 14970], [-436047, 15627], [-462045, -17133], [-463284, -4776], [641036, -10578], [583269, -22641], [-505852, 5622], [438456, -22338], [-318400, 4224], [-569305, -27519], [-332671, 19611], [65361, 32811], [-260428, 38886], [1285680, 10002], [527055, 1605], [-354298, 65460], [287658, -5898], [-743634, 10764], [345582, 786], [309114, 74064], [255440, -86160], [-905146, -62760], [1485399, -3057], [-665329, 112173], [1088967, 52959], [1103447, -110019], [1017978, -67098], [22865, 110301], [238830, 2616], [982916, 40032], [-1965682, 93300], [2045718, 141462], [-1651702, 119184], [-1599429, -136581], [3038376, 53856], [-2525371, -85689], [-679372, -187950], [798644, 99072], [255804, 311628], [913257, 18441], [-458653, 78195], [-2631987, -63015], [-5312242, 5508], [1075572, -307620], [-110371, -296691], [812961, 111771], [645794, 368352], [-1823566, -329634], [1896870, -157026], [-27525, 228003], [-622672, 206562], [341952, 7938], [-1508416, 76896], [394827, -213927], [7307994, 55974], [1499774, 252426], [-8264109, -102579], [388925, -544317], [5274615, -7803], [-2182086, -334944], [-3666570, 27036], [-1528492, -33564], [-5522209, -125253], [3426008, -481260], [2687184, -430002], [-3486204, 289860], [-6808206, -71928], [-7462180, -184680], [-2226163, -557967], [-3530568, 648120], [3155805, -55791], [7877289, -257565], [-2054314, 195876], [4086575, -410235], [12246770, 370356], [-1827174, -489936], [9167282, 319398], [-13168519, 189507], [-5428830, -624288], [-5068819, 404487], [-5781048, 332136], [6391434, 608580], [-8052771, 632475], [7224152, 202938], [-11252980, -606402], [-1053519, 162165], [-5097288, 226644], [10589492, 799284], [1612203, -613689], [-3417529, -435933], [17129562, -235770], [10907816, 572088], [9827093, -453567], [-2290927, 332151], [-14384364, 237612], [-17825509, 463881], [16095512, 639558], [-14026866, -230796], [-861586, 697836], [21095385, -61659], [-412759, 831843], [9108267, -1126725], [-11327811, 1540785], [3132218, -682146], [8706321, -171303], [7654940, 425244], [-12482178, 1600710], [7652516, -135306], [2758974, 683850], [-1543786, 1884060], [-14575518, 1014600], [15179372, -872004], [-20038680, -361848], [-12227230, 1552140], [-10567848, 906450], [-14257516, 734496], [-9915288, -1272], [10616402, -215070], [-9832776, -1187448], [34103999, -792507], [-15031716, -29706], [6896315, 1263699], [3231192, -1498206], [-20080128, 849036], [12122664, -1014006], [-4401790, -1442874], [-16560864, 844416], [12588486, 1160652], [23799, 1397949], [-2654968, 2907888], [-34981321, 458127], [-25176703, -983163], [-23864118, 254712], [63912, -580284], [25966178, 18792], [1700733, -1585905], [50603522, -671688], [-7011526, -140442], [3899196, 3484758], [-18535915, 180867], [-34448439, 621177], [10103132, -2040612], [-18907072, 2332026], [-18284620, -2828748], [30276252, -2663196], [19939310, 3228360], [-63410250, -678516], [-61926900, 173628], [46346346, 28728], [31214504, 1187094], [60191285, -1230249], [26150477, 1100577], [-16122096, 3081576], [-48350110, -12648], [-20276202, 3267342], [31568699, -427347], [-33452952, 2275722], [15856164, -4513968], [-17604627, 490233], [14486339, 2125755], [54116852, -1664814], [36849615, 976647], [45127377, 536595], [-9243138, -350112], [-25313470, -432546], [50739650, 1014792], [8927330, -2395920], [78626958, -236742], [-54272433, 2140095], [13503674, 5257638], [-3212796, -3245496], [15028518, -4273788], [-102821824, -284280], [74637380, -1540026], [-45561726, 1941528], [-67904284, 1519212], [23901273, -1877349], [83295354, 73254], [11120300, 3626142], [-37286758, -2880162], [29327124, -1842354], [27176802, -583602], [14773686, -1440840], [-9199030, -2863788], [-45777070, 2041374], [93162393, -2076339], [62307578, -388026], [112753545, -2169309], [-7733146, 4530216], [1540755, -4560597], [-43897623, 4911939], [-31618255, -1652205], [18957444, 290832], [37128860, -164502], [-25833058, -6920982], [-14100088, 9024480], [-117848091, -2758407], [-94971199, -2513421], [-126928911, 2192715], [77850632, -5053014], [-36890280, 2939310], [-25656621, 1733661], [-5472414, 1972542], [-43551288, 7673748], [15004664, 4911624], [-19308379, 8813919], [59470742, -58488], [2897781, 2009193], [117933870, 3462378], [-25013512, -7796040], [-11047782, 6794550], [-52891777, 1268073], [-94435242, -1989198], [77828066, -5982012], [33285786, -2324904], [98494524, -5099556], [-83476288, 3749586], [6036774, -8500356], [94239333, -965973], [13068086, -4641384], [-110741212, -765300], [-41542935, -1138587], [-42911827, 1538001], [35985662, 4685442], [54473706, -1440726], [103273940, -1248114], [-91764259, 3015225], [44316594, -3221088], [-60871222, -8074434], [63975393, 7521777], [97427946, 5119536], [-60323860, -6593616], [-135090846, -3494988], [122434784, 3694482], [-31456708, -2798400], [34835363, -9699285], [-57061348, 5916516], [53091926, -7508268], [108092333, 3956967], [-194941332, 2149032], [8043218, -4479108], [-19944451, 99249], [94664154, -431274], [75190521, 308355], [197467283, 3940017], [86687664, -865056], [-143177050, -3197244], [11460689, 1430931], [-68529759, 11427627], [-26921962, 651900], [-36183366, -5947068], [15329348, 6438156], [-16152108, -15748938], [80440641, 2244945], [46767315, 11270385], [-155872848, 1846098], [-152267340, -7904724], [-133673206, 3684828], [82975656, -12358950], [156535346, -5793306], [-237793767, -2516163], [-37937748, -8287428], [-254225059, -320649], [209089367, 6804735], [-94863138, 14180688], [19719965, -8067177], [-9534816, -3127620], [99342539, -6333219], [33949778, 10186848], [-167358402, -5974530], [-203665864, -8069550], [116731872, 9258072], [184684424, -2333970], [-3750552, 11486232], [37023291, 7522959], [-142765218, -2787036], [183103694, -2918394], [22963470, 1526946], [-100289188, -9626346], [201425034, -1421154], [5589153, 6034371], [99143399, 1886991], [231910161, 8023365], [333996518, 5121042], [198452360, -1657302], [-49928118, -12587496], [-1518796, -12123156], [-64681362, -1588308], [-72320020, -6617898], [-94138693, 1341717], [274682732, 3577836], [6454680, 7181664], [-218027388, 2507082], [122698790, 16166472], [-53354868, 3545034], [-186776266, 672234], [96281703, -20896779], [154632404, 8026296], [-15625707, -8535105], [-115986499, 1031661], [-204158910, -10729848], [-68777266, -7426260], [39244493, -3379257], [368368634, -229020], [294792120, -4953558], [2609322, -12996792], [-273240787, 9268479], [231224478, 8140416], [276628644, 11159544], [-175210378, 9899148], [42686348, -15143688], [-28174854, 667614], [-98293389, -6144717], [51644528, 15711408], [258400136, -3491238], [-19832583, 30288345], [-90814243, 24219495], [156568241, -9302439], [-406436514, 8591460], [-353098962, -3064782], [-78099522, -3624102], [213188538, 7581960], [230864898, -2496330], [-167080504, 25802046], [-23905944, 741066], [-190439616, -1401144], [207044589, 11491323], [96725132, -18852540], [103335458, -5505336], [299039235, -1322829], [53506322, -1133466], [-199615111, -181995], [-546472467, 477123], [6058352, 28519560], [235226016, 18207360], [134769627, -13119609], [-319472242, -11612574], [83299346, 1692084], [-159620808, -796752], [-158096955, 869319], [-59232139, 11930457], [79358646, -18849996], [365056841, -2806971], [-170782074, 11149476], [-54807474, -31341396], [321564044, 1946940], [157194654, -27744588], [-125438968, -29228664], [-5414439, 29739195], [234627449, 4652139], [51583121, -5907891], [403182932, 11173032], [63082299, 15012177], [37986869, -36030351], [20960247, -4661217], [-505384161, 2346033], [-63585364, -6059556], [167741361, -33211533], [-249936688, 12088386], [-72070108, -8910924], [302148624, 12185130], [-288773719, -14564961], [-191528046, 2060076], [94785380, -18779562], [-164560092, -9277722], [436726538, 7983054], [210843579, 22375515], [-602916876, 7237734], [-158861854, 25202262], [113244026, 21142188], [42625251, 9600795], [-209526892, 5877924], [318745068, 11989524], [287890979, -21447981], [699622254, 8803368], [20762262, 29106390], [-179753404, -4041168], [-663466906, 9781092], [50403600, -30130638], [-241430463, -1381485], [-20331244, 10216284], [181884330, -32752296], [-20816079, -5824125], [-134761827, -22790931], [198453158, -38500956], [-253709238, 33001134], [429893412, -22464348], [-472661143, -6110091], [-343229853, 7359867], [-315484248, -29036988], [-236469558, 3085296], [35478848, 42849432], [297301488, 20908320]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_140_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_140_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_140_6_a_a(:prec:=2)
    chi := MakeCharacter_140_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_140_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_140_6_a_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_140_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<3,R![-120, 23, 1]>],Snew);
    return Vf;
end function;