
// Make newform 11.12.a.a in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_11_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_11_12_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_11_12_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 := [-2, -37, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [-52, 6, 2], [96, 12, -4]];
    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_11_a();"
function MakeCharacter_11_a()
    N := 11;
    order := 1;
    char_gens := [2];
    v := [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_11_a_Hecke(Kf)
    return MakeCharacter_11_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 := 12;
    raw_aps := [[0, -1, 0], [-131, -2, -4], [-2435, 100, 90], [-1694, 310, -440], [161051, 0, 0], [-811404, -4478, 5808], [4037374, 58778, -16280], [-2863520, -66050, 142340], [-1045471, -612722, -231814], [-125480608, -531012, 22616], [-104391631, -1160370, -257162], [-151427129, -1758996, 644254], [-12538152, 7125090, -10552256], [54054462, 4371400, 8336680], [-1060832728, 27651028, 2025932], [-1000251134, -17764276, 2437860], [-614406569, 74642142, -15367764], [-9364704228, -26400556, -3263656], [3438437499, -204548586, 45578896], [1234357219, -264479434, 104141754], [4672344996, -41847958, 197320288], [-2701527686, 353775960, -296828884], [8669675982, 725395500, 476487000], [-5781465017, -754367724, -788014172], [-2661515079, 612259096, 115608236], [106157272826, -1967189654, -243877348], [-4411327488, 1703357252, -631052328], [53321982758, -796339154, -319460196], [-15698668942, 1088152208, -700120740], [6573215177, -4183423356, -44041936], [-484634482728, -62597926, -978946452], [74030171754, -1332590446, -3785288188], [167737782945, 9880018292, -2723319872], [245127426126, 143359790, -3238772636], [-436453200194, 13971010718, 6678126092], [600966530846, -835030620, 13188884676], [-628630409395, 22188930740, 7710495206], [1355806232140, 10169178336, 5831557728], [373572775884, 5862413182, 1506301324], [-644577679262, -29565090440, 4698610004], [659550266739, 10644880002, 10621976988], [916394341419, -36522574824, -23238917326], [986220110407, 15564720306, 39381497106], [-1580713655004, -5679771928, -37721818112], [-942357489722, -58131227528, -21992936460], [2154795849296, 9125607128, -441024188], [-23885685340, -43295005920, -41951038888], [-3179901631147, 39844136858, 113923124982], [3586011674454, 69400042582, -111280561436], [-2575201565005, 199003697264, 77831814034], [-6078693418600, -119598636620, 65506459392], [1622563064078, -281950514764, 8826650668], [-8693255318792, 144491468220, 4926471264], [-14606013560493, 89249701990, -56938117240], [11405197327198, 179017269148, 60727016796], [2232130773906, 233340999958, 200219353224], [-20411002076414, -10887341816, -117069918612], [-7626678627172, 542034685766, 184432734860], [-2207572275546, -341851108292, -98191913820], [24993812886878, 198788687036, 296628675640], [-17200270413876, -204966724364, 358217128104], [33371526728760, 31508775542, -374496679216], [-27304711602344, -384818207994, 487116614996], [-22594886225372, 693775319884, -67797133012], [5062330606439, 478615108852, 13503621100], [2851510754177, -960708669252, -213251605758], [-46539162635315, -1097377722606, -1221816646644], [36080903731466, -593588156214, -512125603704], [57303389330484, 1158414481658, -137004339780], [8328266198230, 481977214746, 82348529956], [-4899883033461, 1154652865828, 411083831356], [-38867987133228, 370797214526, 908889868524], [-63177345328423, 806959779486, -940807096850], [81787872571086, 66889860114, -1158301417900], [-232098237511287, 880503953022, 110432765324], [-125324105296151, 1337721386890, -1058010555782], [-74047119476227, 2929574154928, -437010927930], [-4565749556762, 1846264706748, 1969042376796], [87292655184258, -41047762436, -2140781049372], [84284125799698, -4426028774256, -545206939904], [11531477370140, 3097983249548, -2079150953352], [73942102224750, -3453017787540, -17974916788], [-150345828320446, 2526829165794, 2229953823152], [-179796055615755, -3113872807504, 2935788636028], [8058401277784, 5661429181100, -1378716033904], [-14156920467689, -2786204407362, -450927421696], [330383525172291, 4723718528868, -168640464568], [112255111156628, 4490993869444, -330410383248], [-259076353005316, -5730449412468, -4701554554840], [23311160738835, -10462590619690, -3825020111858], [137339229509071, -2347302313938, 2455504527412], [338630576669484, -3628510195910, -3318173074524], [-25305583657111, 4426602783106, -7673485082102], [662418671631816, 1300401034616, 4268348818272], [330509213962844, -17175592121608, -5381249687632], [406562034163802, 6872229488536, 9315367599076], [-86842598933397, -60551984704, 11005788248198], [-354973269290955, -12312418069344, 2942437153728], [578992371732720, -2655969982958, 3803503265804], [-475376035349512, -9726137081090, -6779119437376], [363464430801560, 7007580756060, 4749213050736], [-57019864351626, -15184420736010, -5913053720948], [66373360932076, -18807271388324, -205763242608], [1947464171253216, 8812778577652, 13747845380896], [27452920613932, 8387962689832, -13089691852248], [-692948124577823, 15764171312572, 2943042913736], [-1302317398560812, 18014875531700, 5535511003468], [1575708038987148, -81814997616, 2331914996048], [-1265590707335640, 5649249900768, 12325788230428], [-86025011416366, 44264951375878, 1068736827136], [1001079090030822, -19815310589240, 2299167173204], [-1342928612618736, -28488244042968, -16124057755520], [-1050114795183870, -10164461673256, 28535751215180], [-667178205690435, -4424294568058, 10837439464452], [715742361802329, 10987479252830, 22913304884278], [-111281218618481, 20259022971240, 29196110931808], [-1887943776312873, -20737341255278, -39064433778808], [-2133002718195385, -15062084838462, 5026337449954], [-1659227539745629, 6277187456224, -30151336485770], [122031976147422, -30719600539408, -32877849781920], [847628747419137, -29101572535288, 36595024228642], [614379210789806, -39941690232016, -16128826687600], [-1450745725971938, 47036145678, -18193489216628], [-933013289183952, -32869746582244, 30769892787040], [438117519583587, -76549687188086, -51586499729296], [-596620572800406, -28725127272342, 37282372593356], [244239631957867, 49610860808048, -35720653028894], [325882502048569, 79070842362658, 7865921806694], [285383782812493, -68195374198006, -38405725061418], [-4997417098754740, -41728968480428, -26736936240696], [-950787431011594, -67867379782588, -7318503973264], [1834488226759804, 9694497828152, 7763088113440], [-3104509905326785, -92036520691810, -38649871474218], [-823220576868462, 20285090074632, 102154250233900], [1853906725146124, -36561941215570, 72544437099288], [-2502282639255212, 112950949430594, 51260026185016], [944053162037250, 135406104421960, 103568901670912], [-2003951006406272, -4973175440228, -43498573950920], [-3610632860113943, -37659559712136, -58488078749802], [5287432024843936, -73790768180366, -54661807756072], [-3702047048972866, -21680893228352, 139930487442416], [-4073267649065186, 127887937374584, 76017845433772], [10198624390683385, 148793559061794, -109300873094054], [10991578084272324, -51651962325910, -4069434779828], [-13671820007060387, -95578966533300, -25226051721678], [-12178656306698683, -82547467229702, 39745976792386], [-1469713269058474, -24317609359544, -11606736397388], [4230705498529576, 142603607097864, -110823629634696], [-3603068279798469, -61171302988070, -14248717690856], [4268264063422520, -86579359323368, 123924616884], [-521750133807100, 99611863396358, -151971131755256], [-2424392946724571, -127420835991988, -9920876119660], [10400319694749964, 74667825093068, 137737305880676], [-1230107088979978, -165761868547240, -23337623147916], [23036638153066204, -202075861778416, 31027244725776], [882793158850820, -209604476328348, 13605154245404], [5334688965016598, -27015830014960, -346837427814108], [8855407802517954, -150085546203196, 11491262833580], [11995040178292424, 43436428029378, 321310374306240], [-23078532194255758, -54551126687844, -98701192235404], [675812602304479, 226944862466762, -42104429878236], [14768371725698866, 16729353557578, -306519079028976], [8411547884987808, -96591636417628, 41515892517880], [-16799141543152891, -82169976706094, -222414990772396], [1571973454049061, 331251462331084, -273220133040716], [-4175980026938903, -181606868380990, 209893527277770], [-3499778279647912, 707241132355032, 22038593373676], [-20810220231582386, -221395258989122, 22705042998660]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_11_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_11_12_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_11_12_a_a(:prec:=3)
    chi := MakeCharacter_11_a();
    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_11_12_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_11_12_a_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_11_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,12,sign)));
    Vf := Kernel([<2,R![92224, -4500, 0, 1]>],Snew);
    return Vf;
end function;