
// Make newform 1296.4.a.j in Magma, downloaded from the LMFDB on 15 November 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1296_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_1296_4_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_1296_4_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 := [-3, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [0, 3]];
    Rf_basisdens := [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_1296_a();"
function MakeCharacter_1296_a()
    N := 1296;
    order := 1;
    char_gens := [1135, 325, 1217];
    v := [1, 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_1296_a_Hecke(Kf)
    return MakeCharacter_1296_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]];
    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, 0], [0, 0], [-6, 1], [-8, 2], [18, 8], [5, 14], [-60, 11], [4, 22], [90, 4], [-162, 7], [124, -36], [-217, -2], [-96, -44], [304, -6], [-192, 36], [204, 76], [-504, -32], [371, 18], [52, 138], [-570, -8], [425, 96], [220, -50], [132, 60], [-384, 89], [-382, 56], [708, 176], [1060, -60], [84, 260], [821, -174], [384, -261], [412, 174], [402, -292], [-1620, 193], [-764, -268], [-2070, -289], [952, 252], [551, 246], [64, -64], [-438, -696], [-1950, 39], [-3264, 236], [2114, 136], [606, -32], [1595, -396], [-1842, 155], [-140, 256], [1696, 622], [1564, -18], [294, 348], [1649, -510], [2472, 733], [-3948, 564], [305, -236], [1722, 104], [-4584, -39], [-2904, -20], [1878, 901], [5740, -114], [-70, -192], [-2664, -293], [-4484, -168], [-2610, -55], [-4412, 492], [6756, 80], [539, -356], [1086, -919], [-860, 790], [602, 712], [2370, -1092], [1682, 544], [-7344, 88], [-594, -180], [5056, 996], [-1714, 512], [-116, 1700], [6234, 1160], [7620, 1076], [-5929, 138], [-492, -95], [-3439, 532], [-8628, 216], [-5707, 838], [-1380, 1036], [-313, 1980], [-2396, -2880], [-840, 1812], [4392, 60], [-4615, -468], [1260, 868], [-2696, 3136], [588, -1216], [-3594, -2112], [796, -1532], [10674, -224], [-15032, -1242], [3996, 1464], [-60, 1732], [2712, -1948], [-13016, -1146], [-16543, 982], [-9380, -168], [-7350, -1537], [10632, -564], [19428, -325], [352, -2728], [-14965, -72], [16554, -344], [-22992, 1037], [-540, 4492], [9263, -1416], [2080, 98], [5582, 2184], [-9888, -563], [-6464, -732], [21160, 140], [-21636, 853], [-16868, 828], [5922, -456], [-15228, 1820], [-6738, 4468], [-4345, -42], [-19741, 1268], [-10740, -796], [-5688, -3540], [1420, -2754], [6270, 1081], [-9535, 2954], [12906, -1620], [-15608, -1458], [3890, -4728], [12004, 192], [6960, 444], [24040, 1286], [2738, 504], [-588, -1815], [-7429, -1948], [486, -3393], [-11576, 3882], [3714, -4725], [18012, -4723], [-11432, -3528], [3606, 4997], [-3452, -512], [9870, -2528], [-17374, -376], [4326, -8076], [34886, 1344], [13260, 3813], [-10124, 4760], [-5502, 1036], [-17137, 2074], [-21648, -2108], [-2372, 172], [27330, 3452], [-10400, 604], [9186, -5508], [-3332, 5262], [-34836, -1293], [24335, -1448], [6498, 815], [12282, 3708], [-29196, -531], [-19136, -3702], [23562, 4404], [-19080, -5548], [18516, 4240], [5632, 966], [2099, -4014], [36209, -2532], [-20868, 1996], [-32832, 5060], [10847, 2130], [-30540, 1004], [8261, -9728], [54796, -1898], [-5328, -2404], [-14024, -4926], [-9990, 3237], [27688, 2764], [10703, 9234], [41752, 3284], [-7062, 1444], [-3031, -2082], [35640, -2436], [-26688, -4288], [-2622, 4277], [12917, 3186], [15832, -1822], [20246, -1456], [-53202, 4432], [1805, -4216], [24252, 4488], [42112, -5626], [27978, -1909], [-56298, -1748], [41760, 4568], [-68737, 560], [-6286, 248], [15864, -4861], [29310, -6884], [2058, -8871], [23620, 262], [-22666, -9376], [11009, -6120], [4170, -10756], [-19068, 7580], [55696, -986], [16476, -10024], [-24744, 68], [18100, -8950], [-34138, -200], [-23886, -3829], [-8984, -10386], [56910, 232], [-19212, -4968], [-21058, 13608], [-5420, -8682], [38388, 2775], [21684, 12044], [-53478, -3847], [63041, 4190], [33136, 678], [2748, 3655], [-8984, -2268], [-24, -648], [-8185, -12790], [-60792, 6684], [25302, -6616], [36280, -14032], [26460, -13156], [-3367, 6946], [-61076, -3198], [-61580, 3294], [37416, -3419], [-37052, -2668], [1296, 5048], [49649, -1852], [3564, -20088], [444, 13704], [-60018, -8680], [-44142, 2392], [5416, 16794], [-40880, -1356], [-31066, 17352], [6624, -28], [-28314, 548], [-61808, 5758], [-53094, -3112], [-62120, 8268], [-105516, 1680], [11405, -8586], [-9432, -9885], [-6840, -7592], [30377, 6240], [-31938, -9777], [6738, -8996], [-12823, 4530], [34252, 11214], [53550, -1923], [6734, 10200], [6232, -5024], [-5196, -17880], [7157, -2106], [-55918, -2528], [-23352, 7576], [-2540, -14556], [36858, 5303], [-15072, -243], [-50312, 5508], [57858, -147], [-31969, -10538], [8704, -1414], [-111670, -2784], [10492, -9528], [-92887, -4200], [-48404, 13836], [134016, 2120], [-11689, -9786], [64199, -15024], [-19500, -18704], [-112800, 2024], [-18848, 924], [-15840, 3644], [-59569, -2250], [58264, -10548], [-33876, -5508], [53645, -12196], [25452, 14876], [-23744, 9510], [-75960, 15159], [75108, -14412], [-43926, 8012], [39312, 22547], [-11436, 26340], [18011, 4986], [-147366, 2375], [-26312, 21760], [65094, -12913], [-1710, -7968], [26320, 1660], [74687, 4436], [-45972, 5376], [-31376, -6306], [89142, 10856], [-67832, -7348], [-98566, 7728], [-73422, -10384], [17282, -21984], [-20016, -14084], [-40909, -7882], [-28026, -256], [-83484, -13908], [-63708, -5217], [72508, 5290], [-55164, -2396], [127802, -2184], [121932, -6544], [-26820, -7208], [29477, 22992], [-12432, 3900], [1240, 2076], [19670, -28576], [49398, 19357], [-53912, 3420], [-7896, 31268], [-148159, 2140], [109744, -12558], [24352, -8010], [-93342, 6768], [-1092, -13940], [-112030, -12720], [9738, -22561], [-79928, -7312], [-131070, 1632], [-18668, -15906], [15888, 25856], [87131, 450], [23520, 5143], [114410, -6888], [-153848, -6804], [68423, 22778], [-14112, 21148], [145230, 9603], [49924, -15004], [40758, -9259], [13566, 14516], [89597, 25410], [-62624, 5436], [-90636, 14764], [74094, -3179], [46432, 4574], [-25843, -17932], [-29106, -4207], [-75764, -8214], [115067, -5358], [-90840, -8273], [-47940, -13860], [94110, 11872], [35784, -26452], [41850, 25064], [135995, -2938], [112680, -6599], [16470, -8052], [116904, 3088], [87736, 14176], [-39025, 15016], [71628, -23284], [-25196, 16888], [50666, -6064], [95130, -6688], [153928, 2042], [26844, -24304], [-81930, 22217], [-58136, -23336], [11993, -41518], [97482, -20400], [4356, 1152], [18815, 23552], [173928, 224], [106445, -28116], [-88614, -11159], [103140, -20857], [54964, -28708], [-76584, -13525], [-53168, -33722], [63006, 18580], [-77492, 9768], [72125, 12514], [166612, -15758], [-19644, -6192], [-14443, 20112], [101850, 21653], [654, -4952], [-47024, 7370], [6792, 34920], [40997, -9780], [136288, -8710], [34644, 7947], [138544, 13242], [-155238, 10171], [-93337, 5382], [-86208, 17204], [36160, 27954], [69828, -28893], [8334, -28329], [197044, -5442], [-122143, 13838], [-13572, -29489], [49336, 21282], [-63960, 24532], [-238129, -2952], [91170, -2981], [-57138, -5476], [-97112, -28944], [1637, 32104], [18318, 33203], [-122676, -16396], [-199184, -17012], [-2748, 42961], [-8544, -12760], [7308, 12376], [91514, 24768], [112548, 1624], [95160, -26136], [120251, 35220], [-36810, -14581], [-110916, 3596], [109440, -20169], [19600, 26316], [-100140, 24784]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1296_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1296_4_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_1296_4_a_j(:prec:=2)
    chi := MakeCharacter_1296_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_1296_4_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_1296_4_a_j( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1296_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<5,R![9, 12, 1]>],Snew);
    return Vf;
end function;