
// Make newform 1089.4.a.t in Magma, downloaded from the LMFDB on 29 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_4_a_t();".
// 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_4_a_t();".
// 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 := 4;
    raw_aps := [[0, 1], [0, 0], [-10, 4], [-2, 2], [0, 0], [42, -8], [-28, 30], [18, 18], [-112, 0], [88, 46], [-72, 104], [-46, 44], [-248, 2], [-10, 86], [8, 48], [-22, 128], [-196, 0], [526, 52], [388, 152], [-136, -184], [170, 252], [78, 74], [336, -324], [-482, -8], [-802, 420], [16, -306], [684, 124], [1472, -28], [-590, 80], [1562, 20], [-2298, 2], [-1660, 152], [-1390, 36], [1154, -198], [324, 602], [-1514, 618], [814, -856], [208, 732], [-716, -140], [1920, -330], [2436, -144], [-1906, 880], [-1408, -216], [-2410, -456], [472, 134], [576, -312], [3050, 554], [1844, 76], [-3080, 244], [-1062, -1260], [-616, 914], [1308, 36], [1586, -180], [1108, 1608], [-3490, -1376], [-732, -1132], [218, -56], [-3334, -1298], [-534, -176], [4056, -1758], [-1794, -98], [4196, -2230], [5658, -1174], [-5472, -432], [2334, -1748], [598, -276], [2008, -756], [2866, -1092], [96, 1828], [10246, 748], [518, 632], [-3096, -32], [1620, -2980], [742, 2564], [-6832, -2204], [-5072, -2488], [1414, -140], [-6230, 1596], [-9870, -692], [3610, -3668], [-3164, 4256], [-9442, -1376], [-1340, -1268], [2542, 1380], [8322, -2498], [-2148, -832], [406, 3320], [-3686, 2140], [7324, 1258], [2188, 2580], [508, -3320], [6564, -1252], [5400, 400], [-2688, 2980], [76, 3056], [-1260, 6052], [-1478, -4328], [138, 5580], [-8042, 3702], [-11974, 2904], [3814, -3570], [-16124, -2686], [-3884, -184], [-7532, -1754], [10382, -2306], [3426, 864], [19036, -1680], [7568, 2002], [12776, -2072], [4494, -8440], [7198, 4842], [4262, -1628], [12826, -884], [-576, -1772], [-3536, -6792], [15814, 3592], [-14512, -660], [-16128, 2464], [7986, -8224], [6276, 472], [7222, -888], [-25162, -1256], [-5560, 3350], [-1828, -8976], [-18520, 612], [2924, 7210], [21194, 2244], [14808, 3696], [23512, -5792], [-7454, -560], [15014, 4126], [6152, -384], [-6256, 6112], [10990, -8512], [15532, -6962], [-12578, -4368], [4682, 4208], [-14186, 8510], [-29554, 132], [-10548, 2238], [-23782, 5202], [21296, -1890], [-23620, -628], [21904, 1524], [-24566, 4380], [-3408, -7552], [45390, 524], [-25916, 9174], [-5048, -5300], [-18848, 11368], [23550, -4476], [4722, 1948], [5892, 7688], [-14704, 9544], [10432, 52], [30296, 3248], [-22286, 10718], [-14918, -1772], [7318, -3120], [10408, 2830], [-5596, 12992], [-7484, -11914], [-41170, 6594], [32324, 2472], [21626, 260], [7160, -808], [4584, 824], [51686, 532], [7938, -14788], [17210, 6848], [-15060, 7352], [12602, 1948], [17656, -15984], [-14150, 7884], [5100, -10844], [-22974, 2260], [-27522, -3538], [-10070, -2272], [34670, 3346], [-9714, 2740], [26960, 1392], [28796, -5792], [-12562, -5680], [-42484, -226], [-21760, 3368], [-8446, -712], [-5734, -9208], [-17664, 17820], [27914, 3724], [25220, 1372], [-22598, 9032], [17544, 10156], [23884, -8240], [-68698, 2540], [24332, -6688], [10430, -6136], [-26594, -11856], [-53562, 10832], [-33972, 9030], [-8568, -7888], [-7004, 10786], [20966, 8162], [-35602, 2096], [3130, 16580], [35828, -10248], [-31290, -3556], [71164, -4364], [33084, -672], [-24988, -2746], [36180, -3328], [7286, -10744], [42250, -13904], [-13176, 21792], [23812, -17400], [2400, -8760], [10398, 8380], [-36030, 6806], [-2912, 12898], [-38264, -2168], [-27870, 6720], [25802, 2784], [45406, 2434], [-62750, -3380], [31124, -14820], [-58580, -8624], [36550, -24348], [-61470, 2004], [-46608, 2616], [21370, -18250], [-64136, 18668], [-28086, 6764], [38514, -27134], [14566, -23182], [14836, -9738], [-17420, -6384], [-55944, 17080], [-17206, 4136], [1276, -12638], [-63148, 18472], [33840, -29440], [7028, 12592], [55998, 10334], [36792, -34752], [5342, 12200], [11752, -7366], [43632, -21912], [5272, -232], [60500, -20640], [-60386, 7102], [33512, 12792], [-32326, 14568], [86880, 146], [-37816, -19192], [-92282, -6988], [-27532, 22418], [82824, -6620], [-8046, -26020], [-52510, 16250], [18774, -32844], [-35762, -18568], [-70678, 15438], [-71028, 240], [-30942, -11080], [-52154, 25900], [-50050, 16784], [79052, -16496], [11514, -15720], [-31038, 26772], [41858, -11030], [-37672, -18490], [-26710, 10236], [69320, 3044], [-30990, -26728], [-51830, -27042], [-57254, -15948], [46696, -20656], [-5852, -14360], [9974, 12588], [-16762, 8256], [24188, -7168], [19388, 32868], [-20552, 4688], [77720, -9536], [-20514, -33124], [-49866, 23974], [-39008, 20680], [-22034, 47524], [-44696, -27866], [-21112, 10768], [-12744, -30182], [28246, -11572], [-29300, -664], [-107984, 5098], [-133924, -2008], [9382, -16004], [-91828, 16138], [30968, 7096], [-32878, -5960], [27248, -8428], [118122, -15718], [-109018, 18704], [-22572, -8430], [12102, -14558], [11956, 6576], [-70100, 44504], [-99218, 4788], [26708, 3848], [14454, -50496], [-23648, 44704], [-85394, -11924], [-99164, -18596], [-31546, 29428], [134688, -3054], [-27804, -20120], [42284, -34132], [-58902, -31972], [-79500, 21232], [50624, -47040], [59914, 4344], [-56732, 43038], [30986, 18426], [26634, -24160], [121284, 8498], [113824, -14992], [100936, -20734], [-52382, -42928], [-119028, 13968], [22156, 30248], [212, 15836], [-186472, 870], [76186, -5896], [18998, 45212], [93654, 2402], [-64080, 46012], [47190, 22614], [-17420, 25816], [57146, -11396], [95992, -17830], [-36838, 23776], [68214, -22270], [-14542, 32268], [139014, -14208], [-93524, -8510], [-64684, 1860], [-102566, 39512], [-11784, 19588], [138878, 4816], [-33416, -5332], [-116960, 36064], [682, -16832], [-19254, 9626], [-110086, -1408], [-64390, 4904], [39374, -41878], [654, 39820], [-39844, -12034], [51056, -63352], [58776, 46316], [-102836, 46998], [10288, 41264], [30478, -11364], [93856, 20650], [-40176, 40824], [-47928, -48116], [-70932, -15984], [26442, -59920], [-58716, -5118], [99550, -26286], [88230, -25728], [22172, -40696], [80128, -56060], [134520, 25816], [65632, 46574], [57562, -26266], [166614, 25520], [-133940, -25000], [-6764, -16836], [-77170, 2704], [-156892, -15874], [-67150, -13804], [-112258, 1588], [-115562, 23008], [17246, 1762], [77212, 44694], [74702, -32970], [32192, 47504], [76168, -43256], [50914, -20212], [-105082, -4490], [71800, 26480], [-65970, -44], [-145902, 3512], [121116, -16112], [47908, 38520], [84152, -6136], [-105302, -19012], [-26594, 71898], [-49802, -5120], [-23912, 47628], [-118208, -43698], [-31226, -61188], [157642, -7836], [53710, -54374], [-94882, 60872], [91644, -32174], [-24738, -1950], [15994, -5828], [-72048, -18350], [-187148, 25688], [21844, 48512], [-105770, -23240], [-132132, -10142], [-179844, 33104], [-94274, 52950], [99706, 45612], [-17290, 32156], [-194564, -876], [39292, 4108], [-107994, -488], [-52116, -9684], [-36990, -14432], [-27882, 29044], [20520, 31776], [75664, 53636], [-61798, -23744], [-33806, 4336], [-13284, -34104], [-104616, 57058], [67816, 47148], [84444, -35060]];
    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_4_a_t();".
// 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_4_a_t(:prec:=2)
    chi := MakeCharacter_1089_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 4));
    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_4_a_t();".
// 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_4_a_t( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1089_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![-8, -1, 1]>,<5,R![-68, 16, 1]>,<7,R![-32, 2, 1]>],Snew);
    return Vf;
end function;