
// Make newform 20.12.c.a in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_20_c();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_20_c_Hecke();"
// To make the coeffs of the qexp of the newform in the Hecke field type "qexpCoeffs();"
// To make the newform (type ModFrm), type "MakeNewformModFrm_20_12_c_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_20_12_c_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 := [4158054148149, 0, 7296096303, 0, 195547, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0], [0, 2, 0, 0, 0, 0], [9845359382133, 1135055801142, 1252445634, 28669366, 9108, 142], [895032671103, 689757655572, 113858694, 22262006, 828, 122], [216627052063851, -31806544423626, 27553803948, -802742248, 200376, -3976], [236811706393581, 2271777068394, 5835823488, 57338732, 18216, 284]];
    Rf_basisdens := [1, 1, 4163665275, 378515025, 4163665275, 832733055];
    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_20_c();"
function MakeCharacter_20_c()
    N := 20;
    order := 2;
    char_gens := [11, 17];
    v := [2, 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;

// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_20_c_Hecke();"
function MakeCharacter_20_c_Hecke(Kf)
    N := 20;
    order := 2;
    char_gens := [11, 17];
    char_values := [[1, 0, 0, 0, 0, 0], [-1, 0, 0, 0, 0, 0]];
    assert UnitGenerators(DirichletGroup(N)) eq char_gens;
    values := ConvertToHeckeField(char_values : pass_field := true, Kf := Kf); // the value of chi on the gens as elements in the Hecke field
    F := Universe(values);// the Hecke field
    chi := DirichletCharacterFromValuesOnUnitGenerators(DirichletGroup(N,F),values);
    return chi;
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 := 12;
    raw_aps := [[0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0], [-688, 2, -1, 0, 0, 0], [0, 28, -1, 1, 0, 0], [216368, 0, 2, 0, -1, -3], [21, -333, 78, -12, -3, 0], [154, -358, 364, 120, -22, 0], [-41220, -132, -1218, 0, -51, -21], [980, 37366, 3089, -9, -140, 0], [-23158506, -504, -4836, 0, -102, 198], [35742772, 276, 2856, 0, -48, -420], [-10731, -251069, -36478, 2752, 1533, 0], [17790137, 7383, 67970, 0, 2930, 1407], [-14112, 2023091, -32174, -12178, 2016, 0], [-2380, -367460, -23353, 15873, 340, 0], [16611, -648627, 10890, 41316, -2373, 0], [-2469811468, -66252, -611254, 0, -25633, -10647], [2210592635, -9231, -76440, 0, -7935, -14574], [181104, 6129851, 478942, 90242, -25872, 0], [163601676, -87636, -847980, 0, -14190, 45066], [-525504, -20553268, -1784432, 132848, 75072, 0], [-26400848028, 55332, 512640, 0, 20340, 5688], [81872, 10566547, 613790, -356478, -11696, 0], [-48111251846, 497784, 4730068, 0, 123886, -126126], [-505554, 4951262, -804452, -784432, 72222, 0], [23972941534, -572088, -5560604, 0, -80138, 331674], [2624076, 246696502, 6882449, 1364647, -374868, 0], [3960768, -252823431, 11104356, 1343772, -565824, 0], [-182343830965, 531945, 5189652, 0, 64899, -337248], [981372, -216822396, 8247096, -5162784, -140196, 0], [-10866240, -239082914, -30367303, -3783737, 1552320, 0], [182758020708, 2933412, 27494166, 0, 919977, -173481], [3630018, 1142329398, 16237452, -4828824, -518574, 0], [-160341041200, 9023232, 85038450, 0, 2596935, -1232427], [-218544035425, -10772883, -99671152, 0, -4028839, -1313634], [-230460835616, 3366816, 28938468, 0, 2364846, 3727722], [9277779, 1930388669, 15146278, 14012456, -1325397, 0], [-34053432, 2998709749, -103201276, -3823796, 4864776, 0], [16158492, -2223796302, 29127957, 21655875, -2308356, 0], [37929199, 1396610873, 127432150, -8226096, -5418457, 0], [1507430448632, 5760072, 48254990, 0, 4672865, 8258523], [-1021510206802, 23980056, 217423164, 0, 11188698, 9586038], [-2184979031976, -5973672, -60017520, 0, 140400, 6394872], [-128687622, 1828445402, -448529900, 44083088, 18383946, 0], [2080883, 5145995029, -24104662, 30644580, -297269, 0], [4861688345148, 36421788, 339511956, 0, 12352962, 637098], [-145705079628, 52884660, 513834702, 0, 7505949, -30366813], [118004208, -15490806646, 351536029, 19334339, -16857744, 0], [198093448, 11454551453, 675733660, -53154252, -28299064, 0], [2628212167150, 51559320, 468345444, 0, 23623878, 19312314], [25448248, -317749516, 810496, 79169712, -3635464, 0], [6030482319316, -95826828, -853711616, 0, -52278332, -61008168], [4651018660189, 140817987, 1318612554, 0, 44783658, -6467013], [-2616277516680, 70097640, 648089610, 0, 26443395, 9232545], [-276619224, -19811081616, -630102744, -239271960, 39517032, 0], [164635688, 18385000312, 288785003, 228641445, -23519384, 0], [-19262831092845, 53886393, 485300424, 0, 26781753, 26458866], [2897433444316, -29086116, -221381328, 0, -34739916, -75133632], [66001089, 7849628983, -390601894, 598033888, -9428727, 0], [8598463430001, -183630249, -1806346578, 0, -14977956, 138696381], [-217343784, -24691186583, -181555036, -501525428, 31049112, 0], [533969457, -27852451665, 876495210, 801694512, -76281351, 0], [-443492448, 93735261759, -1167424350, -226409058, 63356064, 0], [4017456815856, -12035760, 6977796, 0, -63667698, -178967334], [1215978582, -56971171966, 3094979428, 726667544, -173711226, 0], [-74761211, 115125957779, -862454714, 627490908, 10680173, 0], [-46670513802260, 566827020, 5097463938, 0, 285403131, 289382373], [946449504, 73228127392, 3161317688, -186762104, -135207072, 0], [-3389952888, 82360140723, -10726229262, 72091614, 484278984, 0], [-5291243186650, -545573208, -5021185596, 0, -217273242, -106246518], [-672919604, 37486980380, 384124504, -2499014688, 96131372, 0], [57125637404400, -437891568, -4104081492, 0, -137417094, 25640286], [5095963656, -125859728186, 16387759313, -371873537, -727994808, 0], [3439192449, -40168588425, 10328577258, 480313296, -491313207, 0], [112628192800600, -1015349592, -9638663622, 0, -257416149, 243101145], [4559970856, 39781550798, 16388541601, -2057204625, -651424408, 0], [97750633742023, 444002373, 4250769472, 0, 94627129, -160120986], [2088896985, 328292553919, 9006231470, -2441126660, -298413855, 0], [73131356416450, 1075807560, 9671633740, 0, 543220930, 553855230], [129214138015537, 404875119, 3894508842, 0, 77121174, -173511597], [175121044510528, 1238719152, 11073806422, 0, 656692549, 731358495], [69764468497303, 940963269, 8382410376, 0, 513611157, 599870202], [-199492290595444, -744429204, -6755907088, 0, -344192476, -288148224], [-3609081042, -58175853346, -10067673260, -1275152872, 515583006, 0], [69446158915296, -1665410688, -16567048764, 0, -43529058, 1534823514], [-2529213792, -365043693315, -9766824312, 1817866680, 361316256, 0], [-106080631877259, 333454155, 2864695050, 0, 234923250, 371315595], [518959686, -324043158950, -9180652, 1640196808, -74137098, 0], [389769382438422, -1212813336, -11170396524, 0, -478868418, -223791918], [714404124, 241889854164, 199251831, 2046018273, -102057732, 0], [5962023984, 297495145905, 13256503320, 5481286344, -851717712, 0], [-51473998550624, -2945293248, -26191291616, 0, -1630820432, -1947168048], [-8297589048, 96737883144, -27428890293, 1350753285, 1185369864, 0], [-125391398976108, -1979067468, -18913905918, 0, -438384381, 663914325], [-118717565621424, 9674365056, 90943163022, 0, 2900243769, -973633749], [-4810455300, 368244115446, -16163084103, 1044510303, 687207900, 0], [-823834915098378, -2312741688, -21895316772, 0, -616050054, 464591526], [845521734638314, -864964560, -8255782640, 0, -196931480, 274170120], [-29763930168, 1061987668717, -97404275416, 3860494888, 4251990024, 0], [162665688604678, 2771619864, 23021191884, 0, 2347503378, 4270890270], [-22265952408, 951413323777, -53107758520, -16870949048, 3180850344, 0], [13573311591, -2161512981831, 56323918494, -13664939208, -1939044513, 0], [39735634456, -1461539877379, 114732835492, 10150587084, -5676519208, 0], [-34650732002735, 2362238415, 26283534970, 0, -1330575410, -6353964645], [-659882677299920, -4202217408, -40117365078, 0, -952404501, 1345003905], [22125015276, -3308900120084, 54781230200, 14754532096, -3160716468, 0], [45237466344, -139015063749, 112867555218, 29307339006, -6462495192, 0], [7057589364, 1890976226724, 18398114928, 3782880216, -1008227052, 0], [338895372451596, -6518690868, -61479415812, 0, -1853746434, 957451566], [69047799597665, 8713486551, 86259077142, 0, 437894184, -7399803999], [-28081729116, -3868733703844, -75110307425, -13146555511, 4011675588, 0], [594421107, 596252391917, -4654561502, 6522742124, -84917301, 0], [-46703883716, -2125763845072, -91898519120, -54885115416, 6671983388, 0], [1661875802127604, -3798632460, -32151206094, 0, -2917559253, -4954045299], [-470222497634032, 28470216528, 268398664020, 0, 8151750630, -4014964638], [-87371617385899, 15104854011, 135165107378, 0, 7941716366, 8720295087], [3781379112, 628770264687, 10467893154, 1416441198, -540197016, 0], [-20797042392, -1005212547396, -111865241865, 46503108633, 2971006056, 0], [-92636995423, -2553583859729, -312381579658, 21236736900, 13233856489, 0], [762959898321536, -18374560752, -170530285234, 0, -6607661143, -1448422677], [-2296798803549001, -28573171971, -263414227188, 0, -11158746261, -4903066812], [86984108022, 7978685472198, 246860466540, 26518158672, -12426301146, 0], [15709249591, 1432709994497, 19425541306, 29946385980, -2244178513, 0], [89882167256, -2588732369993, 317987566886, -35500755510, -12840309608, 0], [-534425118649220, -44313071556, -411104364594, 0, -16013175483, -3726454893], [1407959163217427, 19168855329, 181480867316, 0, 5103842987, -3857326368], [642297839700894, -50200187688, -471362792004, 0, -15319542438, 4241560374], [-3703869363570188, 3599727924, 19809409312, 0, 8093934964, 20682076968], [-109567556280, -7017588617664, -238197450597, -106157726283, 15652508040, 0], [155439777591, -7916372260751, 463117359998, 25407655288, -22205682513, 0], [-1146641743517800, 27771382248, 273487696086, 0, 2113063197, -21432192657], [-136342487064, -8718313137324, -383644240881, -44860718463, 19477498152, 0], [1118479457292680, 88707920232, 814705647720, 0, 36186777300, 19852411668], [124715046813, -10256414737877, 336769010282, 55192565416, -17816435259, 0], [4976098409654106, 28302693384, 276432560124, 0, 3297186858, -18411132810], [-2247164747264430, -48039683664, -444053114736, 0, -18171860952, -6475899192], [17453709903, 18088107279729, 48242132994, 6612383844, -2493387129, 0], [4940236896, 5777614173547, -87421104970, 102947563786, -705748128, 0], [-60034844639, 9486746987279, -252301704530, 63620764236, 8576406377, 0], [-9022175582083638, -30181390992, -303017405712, 0, 601747896, 31986634680], [1353643310050456, 26099397384, 223723656786, 0, 18635158527, 29806078197], [6372449274302839, 34299265389, 320975978740, 0, 11008337575, -1274252664], [109589072124, 8205793128330, 456452795349, -112029997245, -15655581732, 0], [35634918760, -6367830261961, 224785510894, -112790051934, -5090702680, 0], [1387647903462219, -69990541215, -632643676392, 0, -33630867879, -30902062422], [-2716122541381456, -19354589904, -137914415380, 0, -27815741830, -64092635586], [-115843129605, -14284600977971, -545068981726, 180990574396, 16549018515, 0], [-94070019414, -21346423009962, -260702572548, -34946059896, 13438574202, 0], [-1297590183824012, 79485665940, 738113650218, 0, 28371504591, 5628847833], [-122467508100, -9093657773088, -595345463085, 210447580485, 17495358300, 0], [-639643149621, -4526828243035, -2005478344802, -4828696864, 91377592803, 0], [8663205874103805, 161381696715, 1501405446702, 0, 56205760224, 7235583957], [-587995634688, -12677070238287, -1846686202440, -1300078008, 83999376384, 0], [534018358440, 32442614414388, 1611066425607, 67276986633, -76288336920, 0], [-358110793656, -2387513750559, -1172687540412, 47196474636, 51158684808, 0], [8918734512779796, -210150608268, -2003844479280, 0, -48830801700, 63658203168], [13688061221268588, 148205408748, 1344742850172, 0, 68655618654, 57761447214], [13891944111771861, -141478142901, -1245206683350, 0, -84787372830, -112883975589], [-309496203408, 21489881423924, -1022984643032, 50282289464, 44213743344, 0], [9572911948279286, -190789993992, -1779962198308, 0, -63968870806, -1116618426], [-215597367720, 25776557341731, -170135415210, -507456311910, 30799623960, 0], [-144854443958, -23039320281418, -148078149236, -307178674632, 20693491994, 0], [-249562037004, 32331948763898, -926573313083, 142235482499, 35651719572, 0], [27618238059308484, 15469334244, 183790841010, 0, -14548749285, -59115582099], [749208241782, -14373826406730, 1862715066564, 491939407608, -107029748826, 0], [795386247712, -2338404441880, 2912052927931, -412267577979, -113626606816, 0], [-17768443872414608, 98517596400, 951712869744, 0, 16731547128, -48322955016], [709058327943, -11912056237959, 2826588678834, -598119648156, -101294046849, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_20_c_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_20_12_c_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_20_12_c_a(:prec:=6)
    chi := MakeCharacter_20_c();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 12));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(997) - 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_20_12_c_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_20_12_c_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_20_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,12,sign)));
    Vf := Kernel([],Snew);
    return Vf;
end function;