
// Make newform 1089.6.a.j in Magma, downloaded from the LMFDB on 24 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_j();".
// 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_j();".
// 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 := [-44, -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 := [[-2, -1], [0, 0], [-24, -10], [138, 10], [0, 0], [64, 38], [-370, -60], [744, -12], [1502, 366], [3506, -412], [-3592, -344], [-15026, 136], [-3246, 712], [9076, -1496], [-2662, -2526], [-8192, 2206], [-7912, -1476], [308, 2330], [17268, -3200], [18454, -3098], [-34090, 7536], [3806, -9482], [-27852, -2592], [-53722, 15056], [-7090, 21300], [-16022, -8556], [-24812, -11380], [508, 4648], [35760, 310], [-201386, -5336], [140030, -31994], [109180, 31384], [280298, 13620], [27416, 47244], [-43786, 47728], [-62378, -35754], [-13062, -2996], [-291668, 34368], [-179692, 65804], [-94302, -6300], [161592, 61236], [427098, -41452], [-108190, -32166], [-201046, 74124], [626538, -15260], [-170028, -50532], [-129380, -39224], [-362688, 88448], [-1201924, 25232], [-107166, 38652], [-644678, 87280], [-820692, -15780], [390362, 127548], [-375296, 182628], [287022, -36592], [-700000, -138872], [-1437912, 135422], [845730, 187034], [514420, -60142], [1391814, -103788], [-1427804, -16936], [-1379906, 183112], [-1131184, -42260], [-572394, 111894], [-158918, -78976], [-61844, -167646], [1309372, -122472], [-220298, -501288], [93124, 393896], [1401896, 382142], [874006, -192104], [-1972004, -138652], [2323880, -288920], [2498832, -170114], [3187380, -7408], [1596846, -345722], [1445480, 70934], [-986678, -100740], [-2739350, -248452], [164210, 77852], [-5023032, 157156], [-3289938, -14920], [-5201968, 6992], [1432138, -652488], [513742, -954178], [-2546272, -45980], [-76710, 646012], [1441706, -590956], [-2976370, 135824], [1066372, -802620], [2429756, -141256], [1490072, -711800], [-2050676, -492796], [2358628, -582784], [797412, -942728], [-1023884, 1062188], [-3332392, 218942], [-4804566, -690300], [-4996148, -182400], [8118440, 437022], [430648, -68700], [1641750, 90328], [768132, -859544], [-1046842, -826060], [1156728, 285116], [3377358, -115692], [70240, 265284], [-8662818, 34772], [8493270, 214838], [9154118, 708400], [-2451458, -1778538], [3562812, 1639466], [-5621002, 1040384], [13699420, 37520], [-13462640, -424536], [-304246, -1563316], [4602044, -1458696], [12254158, 63614], [-2890012, 1524202], [9363460, 772664], [-10956206, -78900], [10651386, 865100], [-2092718, -625748], [12337496, -305508], [-17604748, 1044336], [1525710, 1067552], [5920706, -2082948], [-8959746, 144486], [-1260052, 2667380], [887168, -2665930], [9222852, 644048], [-363076, -938076], [-8370072, 1078904], [15629238, 1621312], [7749638, -1841068], [-24649238, -697908], [-3686768, -2109698], [207564, 2125768], [-14483992, -919410], [9391914, 1422528], [-13028164, 4704], [-37150, -4900692], [16904680, -427184], [14359444, 1222536], [3356254, -648384], [11691530, -4407782], [18268868, 1152226], [-21515990, 256272], [-14962252, -344656], [18823490, -1789222], [23352648, -2466066], [8606662, -3672856], [6640076, 2848360], [29394276, -2290276], [-297484, 1417592], [170950, -1060994], [115314, -1636574], [-9210406, -350212], [-5120618, -567984], [-13206862, 2300852], [-39252740, 581944], [-55110, -4570208], [35502734, 557358], [-33137848, 2620332], [27838066, 2470996], [11939206, 3001030], [31906616, 1465672], [-5875416, -3919834], [14885906, -2914460], [-16579484, 5564722], [20949836, 673072], [-23273886, 2675780], [11192812, -2140284], [16598374, 6808080], [-25528616, -554632], [27934, -5631352], [10980272, -1555964], [-22460004, 3236986], [2314458, -9223030], [-10509464, -3570034], [6155792, 317040], [-4878660, 8968376], [-20223674, -6300752], [-25825574, 7121104], [-1579946, 3326014], [-12032708, -5217494], [52995100, 2052514], [-13523076, -2397000], [-36461262, -5516884], [69824592, -2544880], [16839222, -8158772], [12439324, -4445872], [-4072228, 1324640], [26324392, 25870], [22727524, -3137576], [-5967650, -5361608], [-55395530, 6374568], [-40840534, -686612], [-59723694, -5393232], [-4361416, -1224032], [-13020394, -9042808], [12880138, -2479694], [6094378, 1829956], [-40947882, 6365224], [42940784, -4200780], [-25888492, -6432758], [-4944556, 11356868], [-76930908, 3168528], [56533870, 164188], [-62510428, 821416], [-74743646, -1135244], [-7056868, -9490198], [-41183904, 4621320], [37570156, 4704624], [22074204, -10076748], [9743734, 10410740], [10692446, 14781046], [-73313362, -7505740], [-13008754, 17066366], [-1630956, -419670], [-73447060, 7232538], [28301750, -4733770], [-25701022, -3284812], [-36324664, -10836456], [13726556, -6897808], [25446040, -2665146], [-56026626, 9050328], [-53492646, 9232434], [-79160634, 4651318], [-81820668, 6688768], [43157102, 13766464], [5331388, 1866920], [-113354910, 7428922], [-1726274, 8375436], [-69036044, -4667328], [-94151240, -6972904], [71629906, 12286048], [-158570482, -837928], [-107352984, 133916], [2030234, 10555354], [-19627044, -18647080], [18585524, -3842216], [-21611136, -2745960], [3102178, 14094820], [60551358, -9312044], [-79861644, -8419812], [86540172, 5357356], [24226364, -17668872], [-29005696, -7206220], [-85279396, 10022124], [-85469596, -12673494], [-94472350, 14681536], [-164317622, -464054], [137660166, -2734556], [56371510, 20700808], [-138021884, 2747360], [60802646, -3176000], [-149104196, -6750128], [-97301628, 2032386], [53079882, 14093476], [102186002, -6866934], [-3714060, 14297232], [112017248, -7087778], [124910168, -686578], [26555314, -2595500], [-210046572, -3808240], [-119078340, -3307902], [131181510, 12185520], [16835832, -22161316], [-21256310, 5858404], [-229418878, -181692], [-8875676, -21529472], [120998606, 15826060], [85820302, 1089990], [-47767154, -11199936], [27203196, 2378740], [89282276, 10539656], [227199644, 925218], [203725742, -9331368], [189925084, -1735184], [12050240, -32569680], [23483244, -736940], [-123189276, -10154212], [11446496, -25311458], [-31942904, -21617860], [-34407010, -26294218], [-68396626, 18096740], [101314610, 25608044], [-134384100, -14827948], [-215654930, 10090772], [-37207032, -31054370], [24557280, 3239308], [60228854, 3436964], [63734716, -11733704], [107920472, 23105918], [-74357298, -4379920], [30302028, -21357268], [-176884344, 16860326], [-25307948, -21927416], [190004828, -9991688], [-27134, 11370700], [-74689338, 5329224], [-72506342, -4072078], [15666316, 22366680], [122055420, -21449888], [-61205078, -6529752], [29293876, -6427208], [-27829146, -18041256], [-118266838, 15652442], [224547560, -22061146], [33381908, -33235900], [177512628, 7149218], [237025098, 8679144], [70269892, -346264], [154642264, -18929360], [-158582650, -8455136], [-146782892, -24687520], [-118400200, 27889128], [-78955502, 20083440], [-138796382, 41794416], [-266774584, 23887716], [-69669178, -23142620], [106114694, -45379544], [-16293348, -6178196], [159185334, 7603396], [135509886, -2789468], [-6845460, 11341896], [326102076, 2567560], [-291568124, 17961700], [133083698, -3450372], [119721204, -11830742], [203021584, -19591370], [106076882, 16981498], [168590572, 8284592], [-144584124, -20687592], [-28159660, -56310136], [-42369174, 21752636], [-86848050, -11420300], [133615290, -54115504], [49568894, 48481846], [-186410566, 11892228], [-249956454, 822420], [-4750474, 10325888], [-115952440, -48297744], [50511000, 19585630], [-139814492, 13866656], [154617522, 45111980], [-178951692, 23462320], [93145508, -12303244], [-324565984, -13377346], [-229204900, 12038536], [170446402, -34085960], [-69754520, -41771234], [-193328498, 8539222], [216884356, 41653730], [60415786, 3513040], [32658190, -41163818], [162232196, -59183984], [-246206318, 44516352], [217773306, -32665958], [-217366964, 5684250], [74564966, 30850052], [301582710, -7261074], [-137684996, -19092184], [178111476, -32110368], [63447770, 38116336], [-51479682, 3267744], [506825446, 11105430], [-313756710, 45557652], [-93881312, 30722332], [-111577132, -10989088], [-205406840, -24900280], [34525842, -59998820], [-149725866, -23517482], [229026254, -28983248], [154313868, -77067848], [13793332, -24351900], [59758974, -754144], [396861826, 34128880], [-438975110, -5177180], [88526328, 50919326], [185825354, -15024028], [285698742, -28483114], [-149024714, -48573012], [395738804, -21785184], [-242503022, 44771794], [-39169888, 51578768], [81034182, 63166816], [1189548, 62092496], [-145654326, -448718], [-427393850, -40002052], [-343873180, -4935326], [150010312, -3986548], [100234444, 30495120], [-341160998, 50087386], [-219592782, 34214668], [-428596190, 17928474], [-173407582, -21439396], [-287468084, 6706776], [315164722, -15963012], [220131844, -61961334], [126727522, 57797364], [534611666, 1441658], [207497626, 1658740], [11192326, 69399536], [-23441430, -47027334], [267312950, -12077032], [-27594134, 98656952], [-72397068, 102487264], [-399740316, 42072208], [-497778130, -24652096], [630550126, 18879368], [-27371956, 70095376], [169793272, 20049396], [-242167994, 42653712], [549879508, -30737702], [-169483772, -21377820], [-263754340, 83832068], [142284058, -41483140], [83982252, -31416300], [-150533276, -11695078], [-654679076, -9561142], [689197590, 19078782], [-172855668, 30937096], [179276070, -94393756], [-522257944, 58594526], [-480580716, -45960432], [554453530, -9140032], [2740444, 56032680], [-459275408, -28378504]];
    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_j();".
// 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_j(: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_j();".
// 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_j( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1089_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<2,R![-38, 5, 1]>,<5,R![-3584, 58, 1]>,<7,R![16024, -286, 1]>],Snew);
    return Vf;
end function;