
// Make newform 1089.6.a.p in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1089_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_1089_6_a_p();".
// 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_1089_6_a_p();".
// 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 := [-8, -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_1089_a();"
function MakeCharacter_1089_a()
    N := 1089;
    order := 1;
    char_gens := [848, 244];
    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_1089_a_Hecke(Kf)
    return MakeCharacter_1089_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 := [[7, -1], [0, 0], [-24, -10], [-42, -62], [0, 0], [28, 74], [-550, 372], [-12, 852], [-46, 330], [1094, -1492], [-6040, 1600], [454, -2816], [18246, -8], [-6440, 3112], [-22066, 390], [2536, 7102], [2384, -1980], [13664, -2026], [-13908, -12704], [-17870, 4354], [26174, -5568], [14138, -11426], [28740, 21960], [40454, -26704], [-125746, 9924], [21958, -17052], [-77588, 5252], [107572, -5432], [44508, -19958], [85966, 23752], [-224902, 19486], [-35612, 79408], [176258, -72492], [-319084, 6204], [216458, -39536], [-37070, -38706], [103938, -49580], [-34052, 80592], [311132, 52412], [-284346, 180972], [-654600, 56844], [33546, -2860], [155222, 121806], [233474, -96444], [256998, 67684], [-349524, 309036], [-331880, 229192], [1047216, 24944], [-299404, -154480], [-802902, -59340], [810190, -240032], [-190620, -258996], [1064570, -119484], [299632, -488772], [359454, 382736], [172928, -308720], [-15840, -75826], [-270090, 303314], [-761960, -14674], [-934470, -234108], [295480, -168568], [-137078, -170912], [55772, 777388], [315978, 286098], [-106502, 437264], [-2014772, 599730], [1049884, -27144], [-362498, -1104648], [-652364, 218432], [-1176388, 17138], [1374694, 700120], [1299172, 45740], [1836872, -537176], [-1391580, 924754], [-670668, -1074448], [-144942, -340430], [2343176, -1155226], [34138, 232908], [-1234478, -45988], [-393358, 1163684], [2296344, 1305772], [-3158106, -549520], [970304, -627976], [1364602, -740904], [501394, -2356954], [1880648, -2551940], [-3605718, 423388], [6266138, -753892], [3851066, 264200], [-1232948, -1066068], [-1867348, -1688824], [-3512056, 531712], [3414340, -1926172], [-2609588, 459776], [-3204420, 1621624], [-7723268, 21068], [-2618224, 631358], [940962, -683964], [4496656, 339024], [2074148, -3061278], [1191724, 1053780], [5323074, -689792], [2443284, -1879496], [2804114, -214348], [-13774740, 260636], [2468574, -357900], [3952696, 2554524], [-1478334, -844492], [-1872102, -3752398], [809750, -127232], [-6945158, 3539886], [-4045320, 311894], [-12520258, 1851104], [-3446372, 2197664], [1332208, -3249456], [8018666, -1725172], [9602732, 3099624], [-4874030, 1407098], [5505116, -2531702], [-17099420, 351752], [-2378486, 2635428], [13660194, -2372236], [-2425250, -3835652], [3993416, -1620300], [-13593340, 2946720], [-7367478, 639080], [-2410918, -3685308], [-7961286, -1716462], [10366868, -5507356], [-15429796, 998186], [2370648, 2331152], [7426964, 4973196], [14676552, -1086640], [-17841906, -899336], [14740370, 4101668], [-771086, 1139748], [-1014776, 9258526], [16856736, 1165000], [9641768, -500082], [-25936074, -1343280], [2576216, -4560816], [-5718994, 5065548], [-9780824, 5343040], [-2463644, 7285008], [13062142, -5527680], [11817782, 3421966], [-20726656, 3492622], [-21979562, 5915184], [-20548300, 389168], [-16678594, -996178], [-21410292, 463074], [7193374, 6571592], [22286324, 4813816], [7900332, -3139804], [1441028, -2735368], [12331426, -13008278], [-4596618, -11126534], [3933842, -3964612], [-16845674, -1465248], [22469390, -178396], [-11962796, -3638696], [50464950, 1525456], [30114938, -2728938], [-16464016, -105084], [15148282, 5752468], [-7828070, 12410386], [-37264360, -2218496], [35247564, -8712982], [-4995310, 10188172], [-35798516, 1195906], [-17533084, -9029144], [26938770, -12157804], [3667732, -2683380], [-16285106, 6019248], [-267560, -430072], [21225382, 530696], [-10882348, 7758244], [34863732, -1095398], [36763542, -444286], [24394012, 3925778], [32899904, 11110776], [4946676, 2794160], [6129694, 16082536], [-28377434, 2229856], [34079170, 1110106], [27448132, 2064010], [-21781040, -10031282], [-19761300, 555720], [38850, -230284], [-13620960, 7002968], [-26029002, 3220108], [-36933524, -13022296], [-21300892, 4798208], [31865368, -3643682], [-37942124, -7152728], [13535710, 12891544], [-25661834, 5456856], [9023210, -874820], [14201118, 546192], [-4786072, -2759360], [40513082, -5869624], [22106326, -15037286], [-39543110, -12280316], [-63552786, -4150232], [-68507584, 3454188], [-46543420, -19851110], [-73296820, -3660964], [38325900, 15047448], [-71784710, -3711140], [56995100, -16502936], [-14441414, 12530140], [-60552220, 350042], [33617760, -29864304], [-32692052, 10728720], [2823492, -459780], [41039830, 8541908], [-18016222, 1181614], [-29463022, -20092492], [-50736214, 27500282], [26271420, -18682038], [-43146832, 15584214], [62130338, -19008850], [-128375830, 2247956], [-33074008, 6606408], [75280220, -3469312], [10375468, 32593146], [-23545914, -10905480], [-78843738, 15342534], [17332650, -28161746], [-1733988, -3344720], [-64860610, -9871856], [-38170472, -24230200], [85745646, -14525678], [-76212038, 1277820], [35837932, -27462384], [2453896, 42566120], [-67559918, 4403344], [-79259350, 3304880], [9161880, -41030428], [-57990874, 29970190], [-72540564, 36185096], [-105381016, -1726136], [-121576512, 14559456], [4758106, 30141244], [16700082, 25277908], [-49179060, 44599764], [123240516, 2562172], [-52037980, -10815336], [-63239500, 39765716], [-94759420, 25117284], [48272456, 3956454], [-30865210, 48295744], [-43811618, -18487058], [-98396586, -21467084], [52536106, -56330120], [44043364, -59596792], [-72898762, 56420704], [-66178088, -19467056], [34033860, -45774606], [48754050, 30380812], [-44310490, 25566690], [-79795236, -21679080], [98965340, -8509742], [-8177044, -3615070], [-65410718, 35379028], [-19354356, -8989936], [-148141932, -121614], [33648798, -22711728], [39900708, -52332340], [-29331362, 54764476], [17455154, 11708820], [144398356, -7595888], [-120333010, 11262412], [26390530, 6808734], [-12372026, 58745472], [-207883932, -5699948], [-49622644, -36116920], [-11717992, 9780174], [-106287250, -5303256], [-197244836, -1136864], [41043776, 4216344], [32028132, 57041188], [-104985444, 26113412], [51836084, 70999954], [-33099764, -25740724], [103137362, -70659358], [84075470, 35638388], [173165750, -51018028], [-21579468, 25204772], [46912258, -27725068], [-107582856, -20136578], [-157113480, -1460924], [-54411526, 15403220], [-72628676, -92888], [50715212, -9303694], [152081442, 12935504], [-124335900, 34153436], [91605744, -4327690], [-38817740, -819248], [-37610680, -42377432], [49514554, -3407804], [111024258, 7997760], [180475270, 19403162], [157511500, 7283112], [176304180, 20131120], [229149322, -19521288], [-9905444, 74781160], [-215953986, 52521264], [-78706906, -1910194], [61398044, -17823190], [-18454996, -14649100], [100547652, -11175358], [127849230, -39508440], [-7864580, -43913032], [-64752968, 7420552], [212288270, -4636976], [86720164, -49807888], [-146001976, -71129016], [-127801598, 87548016], [-74731682, 93803472], [228162020, 10129236], [163403174, -79732460], [190659866, -25124648], [167867316, 45061468], [-60313830, 22156900], [-164309778, 9933796], [246009540, 43737288], [-94212540, -54401432], [68716780, 27778468], [763286, 32215908], [-76118328, -24228314], [77957296, -86725610], [-103625746, 43723954], [33470836, -61913968], [36830712, 60118296], [-131435452, 69780728], [179969562, -77233684], [-32639502, 57895972], [-90599622, 35152976], [-200746198, -32080898], [-313820326, 43028484], [-24118950, 6637140], [83743538, -98958088], [-95934856, -70118208], [-339385488, -37837250], [-23616572, -26436856], [-168193182, -37324564], [149158356, -57557264], [-19015156, -9455140], [154315448, -49090786], [148328936, -46717784], [21890530, -35287208], [236182624, -31612466], [-144606710, -11046290], [257357968, -26736226], [-39450698, -65397728], [-109396694, 105738178], [-99299812, -25271120], [482885518, -10357008], [-10196514, 64079038], [59381272, -143564154], [-9233926, 159054980], [-303862950, 45579114], [154124164, 62556104], [49895532, -193065360], [-174120262, 103762480], [4885842, 46888944], [195088450, 76839630], [412621698, -3363108], [216620920, -139432460], [-246415996, -508336], [-117343352, -53139976], [-92467074, 41228572], [-229026342, 53549662], [321816326, 14268232], [-146726124, 45283192], [240720844, 46922916], [192270510, 3660896], [-57901442, 43863568], [10739770, 115127260], [-416124984, -44615170], [-235139494, 93333380], [-328168542, -97639186], [142307842, -82766676], [228929240, -29341872], [-359585210, 14399206], [-264060304, 17646680], [-89852490, 141533776], [-225793584, -41923168], [234941742, -121684298], [183396550, -102999028], [-344656612, 89488930], [-309958088, 151216004], [5789956, -62762160], [-459888890, 3589966], [227500578, 102230692], [50749534, -50238894], [-53348158, -41970052], [-55214372, -42398232], [-141231290, 177441732], [326972752, -49907850], [222816346, -40304940], [183394766, -170232334], [136669210, -193434764], [444249394, 82035896], [314546838, 109400226], [-95109994, -114177352], [401551390, -150378232], [-7560564, 163954816], [303559788, 17753920], [-348159394, 13781792], [110622754, -96086056], [-42202444, -61355312], [442055116, -74713404], [35327278, 54618672], [-364113116, -16665590], [522662812, 17706948], [-27617596, 27021548], [652699546, -72045988], [-297339756, 50208948], [-114878804, 302210810], [-390510680, -112075066], [121791186, -21305046], [-505384428, -68255000], [147424854, 66972932], [-93206704, -148804786], [242058876, 159027888], [-471938690, 150426656], [-394285268, -43426824], [351847792, 45269504]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1089_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1089_6_a_p();".
// 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_1089_6_a_p(:prec:=2)
    chi := MakeCharacter_1089_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_1089_6_a_p();".
// 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_1089_6_a_p( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1089_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<2,R![34, -13, 1]>,<5,R![16, 58, 1]>,<7,R![-26384, 146, 1]>],Snew);
    return Vf;
end function;