
// Make newform 1764.4.a.o in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1764_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_1764_4_a_o();".
// 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_1764_4_a_o();".
// 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 := [-48, -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_1764_a();"
function MakeCharacter_1764_a()
    N := 1764;
    order := 1;
    char_gens := [883, 785, 1081];
    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_1764_a_Hecke(Kf)
    return MakeCharacter_1764_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, 0], [0, 0], [-5, -1], [0, 0], [-1, 7], [0, 5], [-52, 4], [32, 3], [-28, -20], [-143, 11], [171, 20], [20, -45], [72, 18], [362, -3], [126, -36], [-243, -9], [-113, 53], [-246, -40], [94, -77], [-778, -44], [634, -53], [699, 62], [755, -101], [966, 42], [295, -29], [-2, -184], [-568, 111], [-279, 207], [46, 31], [-872, 110], [1233, -106], [-341, 335], [-278, 2], [-182, 181], [2346, -78], [451, 301], [1052, -402], [1388, 96], [2374, -4], [178, -490], [-876, 246], [2664, 209], [3384, 18], [-2203, -378], [1334, 202], [-628, 132], [-2062, 378], [1457, -609], [5793, 57], [1300, -107], [3500, -434], [588, 618], [-553, 903], [543, -327], [4038, 336], [-5778, 54], [6061, -379], [1767, -55], [-5488, 393], [3590, -722], [-158, -971], [825, -177], [76, -143], [8152, 194], [-2951, 526], [3513, 735], [236, -543], [-2871, 164], [-2940, -372], [1042, -200], [6312, 582], [6670, 326], [-967, 840], [-680, 883], [2584, 169], [-7054, 274], [106, -1516], [-540, -385], [-4104, 540], [5807, -450], [-1968, 726], [3774, -1225], [444, -174], [6686, -1359], [1215, -1471], [-4045, -791], [2896, 626], [9559, 598], [4246, -346], [6736, 1081], [-1580, -406], [-7126, 490], [7829, -468], [-6837, 249], [12370, 397], [4152, -354], [9789, -1671], [-4158, 2322], [-3064, -3], [-2730, 491], [6252, -760], [4747, 1007], [-12949, -221], [-12144, -1446], [-30, 797], [-3473, 1744], [5225, 2359], [9372, 1194], [-3786, -426], [3467, -156], [-17043, 116], [7212, 1790], [6902, -1856], [-9206, 151], [-13555, -1845], [-7714, -1550], [-8626, -1527], [-9030, 264], [-1749, 2091], [-2056, 1324], [5266, 1417], [7277, -582], [-8601, 1581], [22197, 303], [-6304, 2001], [21841, -49], [-20866, 984], [-17994, 552], [-19529, 166], [17202, -397], [17274, -2503], [9306, -4176], [-15627, 1814], [7770, 2744], [-2152, -1208], [4573, -1166], [1150, -2020], [-18114, 1178], [14607, 1305], [-32504, -262], [19186, -3698], [14717, 553], [-19592, 3928], [11355, 1263], [-11960, -491], [-24364, 3328], [-20338, -615], [23034, 2886], [-8554, -2094], [5206, 2852], [-17408, -686], [-24462, 1926], [-22960, 297], [-14196, -1518], [13644, 3245], [28026, -3330], [-19088, -2183], [12630, -6132], [17435, 5004], [-5729, 3221], [-6320, 14], [9470, -2426], [9683, -3606], [11373, -3129], [-35394, 2868], [-28572, 1104], [-7129, -3408], [-2218, -3039], [11063, -666], [-6297, 1833], [17017, 3623], [-38438, 700], [4416, -3012], [37077, -3496], [20757, 4502], [-2828, 5468], [1206, 8147], [13943, 967], [37304, -576], [23102, 4221], [42027, 2192], [-7471, -3233], [52774, -2225], [6886, -826], [-2990, -3928], [-2157, -5151], [20538, 92], [18578, 411], [47451, -970], [-30912, -2838], [31345, -4736], [-47607, -2631], [-28472, 6688], [50906, 2794], [747, -5319], [17498, -1922], [-18970, 5613], [-29942, 1516], [21354, -7692], [-40962, -546], [-35469, -4041], [6288, -4015], [38606, 1632], [-462, -8032], [54096, 2766], [22809, 4101], [536, 4512], [-10623, 237], [-42060, -1392], [19454, 894], [27122, -6699], [20095, -4279], [-6381, 137], [21073, -1693], [-2304, 6012], [-4126, 6045], [-4559, -5225], [37940, -8576], [37634, -5462], [-9946, -5024], [14320, -7967], [-38504, 6379], [3846, -5160], [42247, 5785], [31749, 4917], [-7432, -3414], [5642, -866], [-18692, -5434], [11871, -8062], [41916, -2154], [-44106, 4067], [-8216, 1924], [-6461, -698], [20238, -1068], [-22522, 5973], [26520, -7062], [-52277, -5678], [63375, -5181], [-37812, 7752], [9556, 8006], [14060, 4954], [35888, -6765], [-62671, 786], [-73134, -1276], [15416, 3040], [-34188, -2712], [78003, -6214], [59876, -2954], [-22192, -6984], [-47280, -24], [-17126, 7447], [78846, 426], [-65706, 1140], [-1694, -13445], [6917, 13195], [49775, 6265], [-23410, 5367], [-21012, 593], [24253, -11047], [113573, -2871], [-5480, 661], [-50645, -1219], [51526, -3701], [90004, 1723], [108342, -1188], [35650, -4775], [55887, -1185], [-77912, 4574], [-1676, 1000], [71727, 6483], [-51840, -1249], [129998, 870], [-25563, 3128], [45701, 5844], [-33587, 9997], [22752, 7868], [-11791, -5519], [-11220, 10079], [-25562, -4835], [40032, 13176], [-50922, -7614], [-122265, 362], [-2496, -4542], [71564, 8223], [22986, 2162], [-7300, 12346], [71127, -1390], [21407, -7757], [-50803, 6462], [-65988, 4194], [107394, -2166], [23505, -19077], [11772, 7758], [39748, -5464], [-19000, -18297], [23415, -3885], [-40120, -1305], [70386, 10794], [57132, -3366], [49902, -13825], [-117530, 6232], [-32073, -6825], [83701, -785], [-28605, -6279], [-22234, -3207], [-24334, 20499], [-119765, -6025], [-137578, 3711], [-25666, -5198], [-70378, 2769], [-1266, 6342], [35686, 9848], [-72800, -6010], [-7168, -20688], [33820, 4460], [-16474, 12747], [108663, -8709], [-76700, 9500], [-87307, -1596], [-27096, -2802], [-4648, 4575], [31114, -13019], [-26895, -4623], [70240, -2663], [50704, -11830], [-83821, -6402], [-44902, -1269], [5674, -6371], [-76318, 7978], [-84805, 14431], [-8194, -6033], [-8833, 4843], [-143424, -5641], [-53752, -1646], [41062, 4771], [101668, 12878], [61920, -20014], [-20654, -24334], [-10639, -11916], [100921, -9782], [-72790, 4041], [-93240, 5544], [-10359, -11097], [46905, -7870], [17001, -13167], [28101, -14439], [65918, -20361], [65426, -3270], [-116478, -4500], [-26775, -4203], [-150016, -9564], [130739, -5001], [114510, 4776], [-939, 12203], [94642, 14545], [-8218, -5096], [574, 25376], [-136857, 9165], [-61996, -2276], [37382, 8704], [89518, 7156], [20168, 178], [-94934, 5828], [-151564, 4150], [-75068, -9929], [-107197, 6531], [-111570, 11850], [64872, 4919], [-130247, -8843], [83273, -20069], [93760, 8695], [-80658, 10188], [-40343, -27127], [-82448, 13873], [-73340, -9119], [158808, 9024], [167384, -4496], [-103493, -18893], [-108622, 20554], [-6178, 6915], [98634, -17130], [-47006, 13250], [-40256, -4568], [-108120, 16140], [-155906, -11498], [-27578, -29794], [-122080, -16719], [-159068, -5150], [27808, -5303], [-16432, 9094], [-28879, -23736], [-201750, 6648], [124667, 12841], [169394, -9741], [56830, -18964], [-17265, 33899], [-104579, -15089], [21986, -12548], [74148, 12785], [84743, -20117], [-126016, -8298], [203628, 11256], [-34364, 23644], [-110318, 9476], [-17739, -639], [113177, 9798], [117934, 808], [160566, -10698], [-23386, 3561], [-85933, -19127], [-22409, -20693], [-93445, -13991], [13829, 18523], [-39810, 22622], [-57118, -26697], [163829, 7033], [63116, -10298], [6640, -23105], [-66276, -19944], [-165194, -15910], [-108901, 7837], [210326, 8805], [89870, 9946], [-15645, 903], [-93862, 300], [21598, 11768], [-97079, 3113], [28260, -29052], [93846, 15590], [-48892, 10612]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1764_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1764_4_a_o();".
// 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_1764_4_a_o(:prec:=2)
    chi := MakeCharacter_1764_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_1764_4_a_o();".
// 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_1764_4_a_o( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1764_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<5,R![-18, 11, 1]>,<11,R![-2358, -5, 1]>,<13,R![-1200, -5, 1]>],Snew);
    return Vf;
end function;